]> mj.ucw.cz Git - libucw.git/blobdiff - lib/sorter/sbuck.c
XML: Small bugfix in xml_merge_chars.
[libucw.git] / lib / sorter / sbuck.c
index ff9e9efa47a0fd7753203736689796866c878e0f..c6ebdeef3252af50f31d14b7100a81430225bcef 100644 (file)
@@ -10,6 +10,7 @@
 #include "lib/lib.h"
 #include "lib/fastbuf.h"
 #include "lib/mempool.h"
 #include "lib/lib.h"
 #include "lib/fastbuf.h"
 #include "lib/mempool.h"
+#include "lib/stkstring.h"
 #include "lib/sorter/common.h"
 
 #include <fcntl.h>
 #include "lib/sorter/common.h"
 
 #include <fcntl.h>
@@ -68,12 +69,13 @@ sbuck_swap_in(struct sort_bucket *b)
 {
   if (b->flags & SBF_SWAPPED_OUT)
     {
 {
   if (b->flags & SBF_SWAPPED_OUT)
     {
-      b->fb = bopen(b->filename, O_RDWR, sorter_stream_bufsize);
+      b->fb = bopen_file(b->filename, O_RDWR, b->ctx->fb_params);
       if (b->flags & SBF_OPEN_WRITE)
        bseek(b->fb, 0, SEEK_END);
       if (b->flags & SBF_OPEN_WRITE)
        bseek(b->fb, 0, SEEK_END);
-      bconfig(b->fb, BCONFIG_IS_TEMP_FILE, 1);
+      if (!(sorter_debug & SORT_DEBUG_KEEP_BUCKETS))
+       bconfig(b->fb, BCONFIG_IS_TEMP_FILE, 1);
       b->flags &= ~SBF_SWAPPED_OUT;
       b->flags &= ~SBF_SWAPPED_OUT;
-      SORT_XTRACE(2, "Swapped in %s", b->filename);
+      SORT_XTRACE(3, "Swapped in %s", b->filename);
     }
 }
 
     }
 }
 
@@ -103,7 +105,7 @@ sbuck_write(struct sort_bucket *b)
   else
     {
       ASSERT(!(b->flags & (SBF_OPEN_READ | SBF_DESTROYED)));
   else
     {
       ASSERT(!(b->flags & (SBF_OPEN_READ | SBF_DESTROYED)));
-      b->fb = bopen_tmp(sorter_stream_bufsize);
+      b->fb = bopen_tmp_file(b->ctx->fb_params);
       if (sorter_debug & SORT_DEBUG_KEEP_BUCKETS)
        bconfig(b->fb, BCONFIG_IS_TEMP_FILE, 0);
       b->flags |= SBF_OPEN_WRITE;
       if (sorter_debug & SORT_DEBUG_KEEP_BUCKETS)
        bconfig(b->fb, BCONFIG_IS_TEMP_FILE, 0);
       b->flags |= SBF_OPEN_WRITE;
@@ -123,22 +125,26 @@ sbuck_swap_out(struct sort_bucket *b)
       bclose(b->fb);
       b->fb = NULL;
       b->flags |= SBF_SWAPPED_OUT;
       bclose(b->fb);
       b->fb = NULL;
       b->flags |= SBF_SWAPPED_OUT;
-      SORT_XTRACE(2, "Swapped out %s", b->filename);
+      SORT_XTRACE(3, "Swapped out %s", b->filename);
     }
 }
 
     }
 }
 
+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;
 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(3, "Allocated sorting buffer (%s)", stk_fsize(ctx->big_buf_size));
 }
 
 void
 }
 
 void
@@ -148,22 +154,5 @@ sorter_free_buf(struct sort_context *ctx)
     return;
   big_free(ctx->big_buf, ctx->big_buf_size);
   ctx->big_buf = NULL;
     return;
   big_free(ctx->big_buf, ctx->big_buf_size);
   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)));
+  SORT_XTRACE(3, "Freed sorting buffer");
 }
 }