#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); /* FIXME: Was it always so? */
+ bconfig(b->fb, BCONFIG_IS_TEMP_FILE, 1);
b->flags &= ~SBF_SWAPPED_OUT;
- SORT_XTRACE("Swapped in %s", b->filename);
+ SORT_XTRACE(2, "Swapped in %s", b->filename);
}
}
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;
void
sbuck_swap_out(struct sort_bucket *b)
{
- if ((b->flags & (SBF_OPEN_READ | SBF_OPEN_WRITE)) && b->fb)
+ if ((b->flags & (SBF_OPEN_READ | SBF_OPEN_WRITE)) && b->fb && !(b->flags & SBF_SOURCE))
{
if (b->flags & SBF_OPEN_WRITE)
b->size = btell(b->fb);
bclose(b->fb);
b->fb = NULL;
b->flags |= SBF_SWAPPED_OUT;
- SORT_XTRACE("Swapped out %s", b->filename);
+ SORT_XTRACE(2, "Swapped out %s", b->filename);
}
}
void
-sorter_alloc_buf(struct sort_context *ctx)
+sorter_prepare_buf(struct sort_context *ctx)
{
- if (ctx->big_buf)
- return;
u64 bs = MAX(sorter_bufsize/2, 1);
bs = ALIGN_TO(bs, (u64)CPU_PAGE_SIZE);
- ctx->big_buf = big_alloc(2*bs);
ctx->big_buf_size = 2*bs;
- ctx->big_buf_half = ((byte*) ctx->big_buf) + bs;
ctx->big_buf_half_size = bs;
- SORT_XTRACE("Allocated sorting buffer (%jd bytes)", (uintmax_t) bs);
+}
+
+void
+sorter_alloc_buf(struct sort_context *ctx)
+{
+ if (ctx->big_buf)
+ return;
+ ctx->big_buf = big_alloc(ctx->big_buf_size);
+ ctx->big_buf_half = ((byte*) ctx->big_buf) + ctx->big_buf_half_size;
+ SORT_XTRACE(2, "Allocated sorting buffer (2*%s)", stk_fsize(ctx->big_buf_half_size));
}
void
return;
big_free(ctx->big_buf, ctx->big_buf_size);
ctx->big_buf = NULL;
- SORT_XTRACE("Freed sorting buffer");
+ SORT_XTRACE(2, "Freed sorting buffer");
}