#include "lib/lib.h"
#include "lib/fastbuf.h"
#include "lib/mempool.h"
+#include "lib/stkstring.h"
#include "lib/sorter/common.h"
#include <fcntl.h>
{
if (b->flags & SBF_SWAPPED_OUT)
{
- b->fb = bopen(b->filename, O_RDWR, sorter_stream_bufsize);
+ if (sorter_stream_bufsize) /* FIXME: Needs better configuration, probably semi-automatic one */
+ b->fb = bopen(b->filename, O_RDWR, sorter_stream_bufsize);
+ else
+ b->fb = fbdir_open(b->filename, O_RDWR, NULL);
if (b->flags & SBF_OPEN_WRITE)
bseek(b->fb, 0, SEEK_END);
bconfig(b->fb, BCONFIG_IS_TEMP_FILE, 1);
else
{
ASSERT(!(b->flags & (SBF_OPEN_READ | SBF_DESTROYED)));
- b->fb = bopen_tmp(sorter_stream_bufsize);
+ if (sorter_stream_bufsize)
+ b->fb = bopen_tmp(sorter_stream_bufsize);
+ else
+ b->fb = fbdir_open_tmp(NULL);
if (sorter_debug & SORT_DEBUG_KEEP_BUCKETS)
bconfig(b->fb, BCONFIG_IS_TEMP_FILE, 0);
b->flags |= SBF_OPEN_WRITE;
ctx->big_buf_size = 2*bs;
ctx->big_buf_half = ((byte*) ctx->big_buf) + bs;
ctx->big_buf_half_size = bs;
- SORT_XTRACE(2, "Allocated sorting buffer (%jd bytes)", (uintmax_t) bs);
+ SORT_XTRACE(2, "Allocated sorting buffer (2*%s)", stk_fsize(bs));
}
void
ctx->big_buf = NULL;
SORT_XTRACE(2, "Freed sorting buffer");
}
-
-void
-format_size(byte *buf, u64 x)
-{
- if (x < 10<<10)
- sprintf(buf, "%.1fK", (double)x/(1<<10));
- else if (x < 1<<20)
- sprintf(buf, "%dK", (int)(x/(1<<10)));
- else if (x < 10<<20)
- sprintf(buf, "%.1fM", (double)x/(1<<20));
- else if (x < 1<<30)
- sprintf(buf, "%dM", (int)(x/(1<<20)));
- else if (x < (u64)10<<30)
- sprintf(buf, "%.1fG", (double)x/(1<<30));
- else
- sprintf(buf, "%dG", (int)(x/(1<<30)));
-}