X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=lib%2Fsorter%2Fsbuck.c;h=4d9bb91b64cf55493ed0273dad15987683a73e3e;hb=66b0f5843d272887ceb09b0d2d339f3cec10eca7;hp=53dfed3133c52c7a2fc0cb7a685f1684f08e3b1b;hpb=2ee3df97a48340eea72f09c118c03c1e6d2d436c;p=libucw.git diff --git a/lib/sorter/sbuck.c b/lib/sorter/sbuck.c index 53dfed31..4d9bb91b 100644 --- a/lib/sorter/sbuck.c +++ b/lib/sorter/sbuck.c @@ -10,6 +10,7 @@ #include "lib/lib.h" #include "lib/fastbuf.h" #include "lib/mempool.h" +#include "lib/stkstring.h" #include "lib/sorter/common.h" #include @@ -133,18 +134,22 @@ sbuck_swap_out(struct sort_bucket *b) } } +void +sorter_prepare_buf(struct sort_context *ctx) +{ + u64 bs = sorter_bufsize; + bs = ALIGN_TO(bs, (u64)CPU_PAGE_SIZE); + bs = MAX(bs, 2*(u64)CPU_PAGE_SIZE); + ctx->big_buf_size = bs; +} + void sorter_alloc_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(2, "Allocated sorting buffer (%jd bytes)", (uintmax_t) bs); + ctx->big_buf = big_alloc(ctx->big_buf_size); + SORT_XTRACE(2, "Allocated sorting buffer (%s)", stk_fsize(ctx->big_buf_size)); } void @@ -156,20 +161,3 @@ sorter_free_buf(struct sort_context *ctx) 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))); -}