]> mj.ucw.cz Git - libucw.git/blobdiff - lib/sorter/sbuck.c
Convert the most important users of arraysort.h to sorter/array.h.
[libucw.git] / lib / sorter / sbuck.c
index b1297c156e49be82d210141cd750860038c5d544..bff52d6616ca9b0bfec6cd1908da4374984b4f71 100644 (file)
@@ -69,15 +69,12 @@ sbuck_swap_in(struct sort_bucket *b)
 {
   if (b->flags & SBF_SWAPPED_OUT)
     {
-      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);
+      b->fb = bopen_file(b->filename, O_RDWR, &sorter_fb_params);      /* FIXME: Something different for small buckets? */
       if (b->flags & SBF_OPEN_WRITE)
        bseek(b->fb, 0, SEEK_END);
       bconfig(b->fb, BCONFIG_IS_TEMP_FILE, 1);
       b->flags &= ~SBF_SWAPPED_OUT;
-      SORT_XTRACE(2, "Swapped in %s", b->filename);
+      SORT_XTRACE(3, "Swapped in %s", b->filename);
     }
 }
 
@@ -107,10 +104,7 @@ sbuck_write(struct sort_bucket *b)
   else
     {
       ASSERT(!(b->flags & (SBF_OPEN_READ | SBF_DESTROYED)));
-      if (sorter_stream_bufsize)
-       b->fb = bopen_tmp(sorter_stream_bufsize);
-      else
-       b->fb = fbdir_open_tmp(NULL);
+      b->fb = bopen_tmp_file(&sorter_fb_params);
       if (sorter_debug & SORT_DEBUG_KEEP_BUCKETS)
        bconfig(b->fb, BCONFIG_IS_TEMP_FILE, 0);
       b->flags |= SBF_OPEN_WRITE;
@@ -130,22 +124,26 @@ sbuck_swap_out(struct sort_bucket *b)
       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;
-  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 (2*%s)", stk_fsize(bs));
+  ctx->big_buf = big_alloc(ctx->big_buf_size);
+  SORT_XTRACE(2, "Allocated sorting buffer (%s)", stk_fsize(ctx->big_buf_size));
 }
 
 void