X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;ds=inline;f=lib%2Fsorter%2Fsbuck.c;h=287827ee3359f5a08b4162afee5c0eced00ce09e;hb=9d9c5f728fc131aff8b450da6bce4a0d4414b8ff;hp=aecf0dade9bc6c7acb3fbd2b215d1d27fe8c4b20;hpb=6652d8d95e5f89eeb4c16163e708583e2f8f9799;p=libucw.git diff --git a/lib/sorter/sbuck.c b/lib/sorter/sbuck.c index aecf0dad..287827ee 100644 --- a/lib/sorter/sbuck.c +++ b/lib/sorter/sbuck.c @@ -68,12 +68,15 @@ sbuck_swap_in(struct sort_bucket *b) { 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); } } @@ -103,7 +106,10 @@ sbuck_write(struct sort_bucket *b) 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; @@ -115,7 +121,7 @@ sbuck_write(struct sort_bucket *b) 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); @@ -123,7 +129,7 @@ sbuck_swap_out(struct sort_bucket *b) 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); } } @@ -138,7 +144,7 @@ sorter_alloc_buf(struct sort_context *ctx) 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); + SORT_XTRACE(2, "Allocated sorting buffer (2*%jd bytes)", (uintmax_t) bs); } void @@ -148,5 +154,24 @@ sorter_free_buf(struct sort_context *ctx) 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"); +} + +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 if (x != ~(u64)0) + sprintf(buf, "%dG", (int)(x/(1<<30))); + else + strcpy(buf, "unknown"); }