Rename pool_realloc() to pool_alloc() with a mode argument instead of ad-hoc schemes...
authorNick Downing <nick@ndcode.org>
Sun, 5 May 2019 11:55:47 +0000 (21:55 +1000)
committerNick Downing <nick@ndcode.org>
Sun, 5 May 2019 11:55:47 +0000 (21:55 +1000)
gen.sh
pool.c
pool.h
pool_test_run.c
pp.sh
process.c

diff --git a/gen.sh b/gen.sh
index b644249..8c84b68 100755 (executable)
--- a/gen.sh
+++ b/gen.sh
@@ -3,7 +3,7 @@
 # call with -DNDEBUG to generate a release build of the expanded source
 # (note that we cannot preserve #ifndef NDEBUG type constructs in output)
 
-sed -e 's/^#define MOVEABLE_POOL 1/\/\/#define MOVEABLE_POOL 1/' -i pool.h
+sed -e 's/^#define MOVEABLE_POOL 1/\/\/#define MOVEABLE_POOL 1/' -i pool.c
 
 # we will only use non-moveable swap, so it must be preallocated,
 # this is because the swap-move routines are too hard to implement
@@ -28,7 +28,7 @@ sed -e 's/^\/\/#define INODE_SWAP 1/#define INODE_SWAP 1/' -i process.h
 rm indirect_core_inode_swap/swap.[ch]
 cp rassert.h fuzix_fs.[ch] util.[ch] indirect_core_inode_swap
 
-sed -e 's/^\/\/#define MOVEABLE_POOL 1/#define MOVEABLE_POOL 1/' -i pool.h
+sed -e 's/^\/\/#define MOVEABLE_POOL 1/#define MOVEABLE_POOL 1/' -i pool.c
 
 sed -e 's/^#define PREALLOCATE_CORE 1/\/\/#define PREALLOCATE_CORE 1/' -i core.h
 sed -e 's/^#define INDIRECT_CORE 1/\/\/#define INDIRECT_CORE 1/' -i core.h
diff --git a/pool.c b/pool.c
index c680420..79e995f 100644 (file)
--- a/pool.c
+++ b/pool.c
@@ -1,9 +1,9 @@
 #include <assert.h>
-#include <stdio.h> // temporary
+#include <stdarg.h>
+//#include <stdio.h> // temporary
 #include <stdlib.h>
 #include "pool.h"
 
-// can only define TRY_BLOCKER if MOVEABLE_POOL also defined
 #define MOVEABLE_POOL 1
 #define TRY_BLOCKER 1
 
@@ -40,38 +40,48 @@ void pool_init(
  check_invariants(head);
 #endif
 }
-bool pool_realloc(
+
+bool pool_alloc(
   struct pool_head *head,
   struct pool_item *item,
   int size,
-  int offset,
-  bool dir
+  int mode,
+  ...
 ) {
-  int old_size, new_base, new_limit;
-  int end_offset;
-  int size_change, avail, gap;
-  bool orig_dir;
+  int size_change, gap;
+  va_list ap;
+  int new_base, new_limit, avail;
+  bool dir;
   struct pool_item *p, *q;
-#ifdef TRY_BLOCKER
+#if defined(MOVEABLE_POOL) && defined(TRY_BLOCKER)
   struct pool_item *r, *target_item;
   int target_size;
-  bool prev_next;
 #endif
-  int old_base_truncated, new_base_offset;
-  int old_limit_truncated, new_limit_offset;
+  int base_offset, limit_offset;
 
   // see if request is for "alloc" or "realloc"
-  old_size = 0;
-  if (offset != INT_MIN) {
+  size_change = size;
+  if (mode & POOL_ALLOC_MODE_REALLOC) {
     // realloc, item must be already allocated
     assert(item->prev && item->next);
-    old_size = item->limit - item->base;
+    size_change += item->base - item->limit;
 
     // calculate new spot if block is extended not moved
-    new_base = item->base - offset;
-    new_limit = new_base + size;
-#ifndef TRY_BLOCKER
+    gap = 0;
+    if (mode & POOL_ALLOC_MODE_REALLOC_OFFSET) {
+      va_start(ap, mode);
+      gap = va_arg(ap, int);
+      va_end(ap);
+    }
+    if ((mode & POOL_ALLOC_MODE_LAST_FIT) == 0) {
+      new_base = item->base - gap;
+      new_limit = new_base + size;
+    }
+    else {
+      new_limit = item->limit - gap;
+      new_base = new_limit - size;
+    }
+#if !defined(MOVEABLE_POOL) || !defined(TRY_BLOCKER)
     if (new_base >= item->prev->limit && new_limit <= item->next->base)
       goto resize;
 #endif
@@ -84,30 +94,29 @@ bool pool_realloc(
 #endif
 
   // check size, disregarding fragmentation
-  size_change = size - old_size;
   avail = head->avail - size_change;
   if (avail < 0)
     return false;
  
   // work in specified direction, then reverse
-  orig_dir = dir;
+  dir = (mode & POOL_ALLOC_MODE_LAST_FIT) != 0;
   while (true) {
     p = &head->item;
     q = &head->item;
 
-#ifdef TRY_BLOCKER
+#if defined(MOVEABLE_POOL) && defined(TRY_BLOCKER)
 blocker_test:
     // enter here when either blocker has changed
     target_item = item;
     target_size = size;
  //printf("a target_size %d\n", target_size);
-    if (offset != INT_MIN) {
+    if (mode & POOL_ALLOC_MODE_REALLOC) {
       if (new_base >= item->prev->limit && new_limit <= item->next->base)
         goto resize;
 
-      r = item->prev;
-      prev_next = false;
-      do {
+      if (mode & POOL_ALLOC_MODE_MOVEABLE) {
+        // check both blockers to see if smaller than item
+        r = item->prev;
         if (new_base < r->limit && r != &head->item) {
           gap = r->limit - r->base;
           if (gap < target_size) {
@@ -116,9 +125,17 @@ blocker_test:
  //printf("b target_size %d\n", target_size);
           }
         }
+
         r = item->next;
-        prev_next = !prev_next;
-      } while (prev_next);
+        if (new_limit > r->base && r != &head->item) {
+          gap = r->limit - r->base;
+          if (gap < target_size) {
+            target_item = r;
+            target_size = gap;
+ //printf("c target_size %d\n", target_size);
+          }
+        }
+      }
     }
 #endif
 
@@ -128,47 +145,51 @@ blocker_test:
       if (!dir) {
         p = q;
         q = p->next;
-//#ifdef TRY_BLOCKER
-//        if (q == item || q == target_item) {
-//#else
         if (q == item) {
-//#endif
+          // skip our own item for gap calculation
           q = q->next;
-          break;
+
+#ifdef MOVEABLE_POOL
+          // if non-moveable, do our own item specially then reverse direction
+          if (mode & POOL_ALLOC_MODE_MOVEABLE)
+            break;
+#endif
         }
  //printf("forw %p(%d)->%p(%d)\n", p, p->limit, q, q->base);
       }
       else {
         q = p;
         p = q->prev;
-//#ifdef TRY_BLOCKER
-//        if (p == item || p == target_item) {
-//#else
         if (p == item) {
-//#endif
+          // skip our own item for gap calculation
           p = p->prev;
-          break;
+
+#ifdef MOVEABLE_POOL
+          // if non-moveable, do our own item specially then reverse direction
+          if (mode & POOL_ALLOC_MODE_MOVEABLE)
+            break;
+#endif
         }
  //printf("back %p(%d)->%p(%d)\n", p, p->limit, q, q->base);
       }
 
       // see if target fits in current gap 
       gap = q->base - p->limit;
-#ifdef TRY_BLOCKER
+#if defined(MOVEABLE_POOL) && defined(TRY_BLOCKER)
       if (target_size <= gap) {
  //printf("target\n");
         if (target_item == item)
           goto found;
+
+        assert(mode & POOL_ALLOC_MODE_MOVEABLE);
         if (!dir) {
-          if (!head->move)
-            goto no_blocker;
+          assert(head->move);
           head->move(target_item, p->limit);
           target_item->limit += p->limit - target_item->base;
           target_item->base = p->limit;
         }
         else {
-          if (!head->move_up)
-            goto no_blocker;
+          assert(head->move_up);
           head->move_up(target_item, q->base);
           target_item->base += q->base - target_item->limit;
           target_item->limit = q->base;
@@ -191,9 +212,6 @@ blocker_test:
         p = target_item;
         q = target_item;
         goto blocker_test;
-
-      no_blocker:
-        ;
       }
 #else
       if (size <= gap)
@@ -204,36 +222,23 @@ blocker_test:
       avail -= gap;
       if (avail < 0) {
 #ifdef MOVEABLE_POOL
+        if (!(mode & POOL_ALLOC_MODE_MOVEABLE))
+          return false;
+        avail += gap;
+
  //printf("compact\n");
         if (!dir) {
-          if (!head->move)
-#ifndef NDEBUG
- {
-  check_invariants(head);
-#endif
-            return false;
-#ifndef NDEBUG
- }
-#endif
+          assert(head->move);
           head->move(q, p->limit);
           q->limit += p->limit - q->base;
           q->base = p->limit;
         }
         else {
-          if (!head->move_up)
-#ifndef NDEBUG
- {
-  check_invariants(head);
-#endif
-            return false;
-#ifndef NDEBUG
- }
-#endif
+          assert(head->move_up);
           head->move_up(p, q->base);
           p->base += q->base - p->limit;
           p->limit = q->base;
         }
-        avail += gap;
 
         // if we have just moved the target, then the target is
         // no longer valid and we should go to blocker_test, but
@@ -257,14 +262,20 @@ blocker_test:
 
     dir = !dir;
  //printf("dir changed to %d\n", dir);
-    assert(dir != orig_dir);
+    assert(dir != ((mode & POOL_ALLOC_MODE_LAST_FIT) != 0));
   }
 
 found:
  //printf("found\n");
+  // before clobbering the in-place position calculation,
+  // figure out how much each end is truncated or extended
+  // (if non-zero, one of these was passed as a parameter)
+  base_offset = item->base - new_base;
+  limit_offset = item->limit - new_limit;
+
   // align ourself in found spot
   // (try to allow future extension in desired direction)
-  if (orig_dir == false) {
+  if ((mode & POOL_ALLOC_MODE_LAST_FIT) == 0) {
     new_base = p->limit;
     new_limit = new_base + size;
   }
@@ -273,64 +284,38 @@ found:
     new_base = new_limit - size;
   }
 
-  if (offset != INT_MIN) {
+  if (mode & POOL_ALLOC_MODE_REALLOC) {
     // move ourself into found spot
-
-    // we have "offset", which is position of start of existing data
-    // relative to start of new block, now calculate symmetric one:
-    // position of end of existing data relative to end of new block
-    //   (new_limit + end_offset) - (new_base + offset) = old_size
-    //   (new_limit - new_base) + (end_offset - offset) = old_size
-    //   size + end_offset - offset = old_size
-    //   end_offset = offset - (size - old_size)
-    end_offset = offset - size_change;
-
-    old_base_truncated = item->base;
-    new_base_offset = new_base;
-    if (offset < 0)
-      // copy truncated start of old block to base of new block
-      old_base_truncated -= offset;
-    else
-      // copy original start of old block to offset in new block
-      new_base_offset += offset;
-
-    old_limit_truncated = item->limit;
-    new_limit_offset = new_limit;
-    if (end_offset >= 0)
-      // copy truncated end of old block to limit of new block
-      old_limit_truncated -= end_offset;
-    else
-      // copy original end of old block to offset in new block
-      new_limit_offset += end_offset;
-
-    offset = new_base_offset - old_base_truncated; // amount to move by
-    if (offset < 0) {
-      if (!head->move)
-#ifndef NDEBUG
- {
-  check_invariants(head);
-#endif
-        return false;
-#ifndef NDEBUG
- }
-#endif
-      item->base = old_base_truncated;
-      item->limit = old_limit_truncated;
-      head->move(item, new_base_offset);
-    }
-    else if (offset > 0) {
-      if (!head->move_up)
-#ifndef NDEBUG
- {
-  check_invariants(head);
-#endif
-        return false;
-#ifndef NDEBUG
- }
-#endif
-      item->base = old_base_truncated;
-      item->limit = old_limit_truncated;
-      head->move_up(item, new_limit_offset);
+    // (throw away truncated parts before calling move routine)
+
+    // in certain cases there can't be truncation, and we can also
+    // guarantee the overlap direction, so prefer the move routine
+    // for given direction (user doesn't need to provide other one)
+    switch (mode) {
+    case POOL_ALLOC_MODE_REALLOC:
+      assert(head->move);
+      head->move(item, new_base);
+      break;
+    case POOL_ALLOC_MODE_LAST_FIT | POOL_ALLOC_MODE_REALLOC:
+      assert(head->move_up);
+      head->move_up(item, new_limit);
+      break;
+    default:
+      assert(head->move && head->move_up);
+      if (base_offset < 0) {
+        item->base -= base_offset;
+        base_offset = 0;
+      }
+      if (limit_offset > 0) {
+        item->limit -= limit_offset;
+        limit_offset = 0;
+      }
+      base_offset += new_base;
+      gap = base_offset - item->base; // amount to move by
+      if (gap < 0)
+        head->move(item, base_offset);
+      else if (gap > 0)
+        head->move_up(item, limit_offset + new_limit);
     }
 
     // remove from list
@@ -346,7 +331,6 @@ found:
 
 resize:
  //printf("fits %p(%d)->%p(%d) [%d,%d)\n", item->prev, item->prev->limit, item->next, item->next->base, new_base, new_limit);
-  // resize in place
   item->base = new_base;
   item->limit = new_limit;
 
diff --git a/pool.h b/pool.h
index 8561feb..dd90100 100644 (file)
--- a/pool.h
+++ b/pool.h
@@ -1,7 +1,6 @@
 #ifndef _POOL_H
 #define _POOL_H 1
 
-#include <limits.h>
 #include <stdbool.h>
 
 struct pool_item {
@@ -18,8 +17,10 @@ struct pool_head {
   void (*move_up)(struct pool_item *item, int new_limit);
 };
 
-#define pool_alloc(head, item, size, dir) \
-  pool_realloc(head, item, size, INT_MIN, dir)
+#define POOL_ALLOC_MODE_LAST_FIT 1
+#define POOL_ALLOC_MODE_MOVEABLE 2
+#define POOL_ALLOC_MODE_REALLOC 4
+#define POOL_ALLOC_MODE_REALLOC_OFFSET 8
 
 void pool_init(
   struct pool_head *head,
@@ -28,12 +29,12 @@ void pool_init(
   void (*move)(struct pool_item *item, int new_base),
   void (*move_up)(struct pool_item *item, int new_limit)
 );
-bool pool_realloc(
+bool pool_alloc(
   struct pool_head *head,
   struct pool_item *item,
   int size,
-  int offset,
-  bool dir
+  int mode,
+  ...
 );
 void pool_free(struct pool_head *head, struct pool_item *item);
 
index fef6a75..49ef7fd 100644 (file)
@@ -68,18 +68,14 @@ int main(int argc, char **argv) {
   }
   int n_items = atoi(argv[1]);
   int pool_size = atoi(argv[2]);
-  bool dir = argc >= 4 ? strcmp(argv[3], "false") != 0 : false;
-  bool moveable = argc >= 5 ? strcmp(argv[4], "false") != 0 : false;
- printf("dir %d moveable %d\n", dir, moveable);
+  int mode = 0;
+  if (argc >= 4 && strcmp(argv[3], "false") != 0)
+    mode |= POOL_ALLOC_MODE_LAST_FIT;
+  if (argc >= 5 && strcmp(argv[4], "false") != 0)
+    mode |= POOL_ALLOC_MODE_MOVEABLE;
 
   struct pool_head head;
-  pool_init(
-    &head,
-    0,
-    pool_size,
-    moveable || !dir ? move : NULL,
-    moveable || dir ? move_up : NULL
-  );
+  pool_init(&head, 0, pool_size, move, move_up);
 
   struct pool_item *items = malloc(n_items * sizeof(struct pool_item));
   rassert(items);
@@ -118,7 +114,7 @@ int main(int argc, char **argv) {
         success ? "true" : "false"
       );
       rassert(items[item].prev == NULL);
-      bool result = pool_alloc(&head, items + item, size, dir);
+      bool result = pool_alloc(&head, items + item, size, mode);
       printf(
         "... %s\n",
         result == success ?
@@ -179,7 +175,12 @@ int main(int argc, char **argv) {
           actual_old_size - size,
           size
         );
-        bool result = pool_realloc(&head, items + item, size, 0, dir);
+        bool result = pool_alloc(
+          &head,
+          items + item,
+          size,
+          mode | POOL_ALLOC_MODE_REALLOC
+        );
         printf(
           "... %s\n",
           result == success ?
@@ -189,7 +190,14 @@ int main(int argc, char **argv) {
         if (result) {
           if (!success) {
             printf("... undo\n");
-            rassert(pool_realloc(&head, items + item, actual_old_size, 0, dir));
+            rassert(
+              pool_alloc(
+                &head,
+                items + item,
+                actual_old_size,
+                mode | POOL_ALLOC_MODE_REALLOC
+              )
+            );
           }
           else {
             base = items[item].base;
@@ -240,12 +248,14 @@ int main(int argc, char **argv) {
         }
  printf("old region [%d,%d)\n", base, base + actual_old_size);
         hash_verify(item, base, actual_old_size - size, 0);
-        bool result = pool_realloc(
+        bool result = pool_alloc(
           &head,
           items + item,
           size,
-          size - actual_old_size,
-          !dir
+          mode ^ (
+            POOL_ALLOC_MODE_LAST_FIT |
+            POOL_ALLOC_MODE_REALLOC
+          )
         );
         printf(
           "... %s\n",
@@ -257,12 +267,14 @@ int main(int argc, char **argv) {
           if (!success) {
             printf("... undo\n");
             rassert(
-              pool_realloc(
+              pool_alloc(
                 &head,
                 items + item,
                 actual_old_size,
-                actual_old_size - size,
-                !dir
+                mode ^ (
+                  POOL_ALLOC_MODE_LAST_FIT |
+                  POOL_ALLOC_MODE_REALLOC
+                )
               )
             );
           }
diff --git a/pp.sh b/pp.sh
index 10ea60a..9cd2b57 100755 (executable)
--- a/pp.sh
+++ b/pp.sh
@@ -1,6 +1,6 @@
 #!/bin/sh -e
 mkdir --parents $1
-sed -e 's/^#include </$include </; s/^#include "rassert\.h"/$include "rassert.h"/; s/^#define DISK_/$define DISK_/; s/^#define BLOCK_/$define BLOCK_/; s/^#define UCP/$define UCP/;s/^#define TRANSFER_/$define TRANSFER_/' -i *.[ch]
+sed -e 's/^#include </$include </; s/^#include "rassert\.h"/$include "rassert.h"/; s/^#define DISK_/$define DISK_/; s/^#define BLOCK_/$define BLOCK_/; s/^#define UCP/$define UCP/; s/^#define TRANSFER_/$define TRANSFER_/; s/^#define POOL_ALLOC_MODE_/$define POOL_ALLOC_MODE_/' -i *.[ch]
 for i in \
 core.c \
 core.h \
index b9ffefb..f5f9943 100644 (file)
--- a/process.c
+++ b/process.c
@@ -172,12 +172,16 @@ static bool do_swap_out(int swap_out) {
 #endif
 #if !defined(INODE_SWAP) && !defined(PREALLOCATE_SWAP)
       rassert(
-        pool_realloc(
+        pool_alloc(
           &swap_table,
           &victim->swap_item,
           victim_swap_blocks + blocks,
-          0,
-          false
+#ifdef MOVEABLE_SWAP
+          POOL_ALLOC_MODE_MOVEABLE |
+            POOL_ALLOC_MODE_REALLOC
+#else
+          POOL_ALLOC_MODE_REALLOC
+#endif
         )
       );
 #endif
@@ -213,7 +217,18 @@ static bool do_swap_out(int swap_out) {
       // add to swap pool
       victim_swap_blocks = 0;
 #if !defined(INODE_SWAP) && !defined(PREALLOCATE_SWAP)
-      rassert(pool_alloc(&swap_table, &victim->swap_item, blocks, false));
+      rassert(
+        pool_alloc(
+          &swap_table,
+          &victim->swap_item,
+          blocks,
+#ifdef MOVEABLE_SWAP
+          POOL_ALLOC_MODE_MOVEABLE
+#else
+          0
+#endif
+        )
+      );
 #endif
 
       // remove from LRU list
@@ -344,12 +359,15 @@ static bool do_swap_out(int swap_out) {
 #ifndef PREALLOCATE_CORE
         // no, reduce core allocation
         rassert(
-          pool_realloc(
+          pool_alloc(
             &core_table,
             &victim->core_item,
             victim_core_blocks,
-            -blocks,
-            true
+            POOL_ALLOC_MODE_LAST_FIT |
+#ifdef MOVEABLE_CORE
+              POOL_ALLOC_MODE_MOVEABLE |
+#endif
+              POOL_ALLOC_MODE_REALLOC
           )
         );
 #endif
@@ -407,9 +425,16 @@ bool process_alloc(struct process *process, long size) {
 #else
   blocks = (int)((size + (BLOCK_SIZE - 1)) >> BLOCK_SHIFT);
   if (
-    process_avail < blocks
 #if defined(PREALLOCATE_SWAP) && !defined(MOVEABLE_SWAP)
-    || !pool_alloc(&swap_table, &process->swap_item, blocks, false)
+    process_avail < blocks ||
+    !pool_alloc(
+      &swap_table,
+      &process->swap_item,
+      blocks,
+      0
+    )
+#else
+    process_avail < blocks
 #endif
   )
     return false;
@@ -420,9 +445,23 @@ bool process_alloc(struct process *process, long size) {
 
   // allocate core and possible swap
 #ifdef MOVEABLE_CORE
-  rassert(pool_alloc(&core_table, &process->core_item, blocks, false));
+  rassert(
+    pool_alloc(
+      &core_table,
+      &process->core_item,
+      blocks,
+      POOL_ALLOC_MODE_MOVEABLE
+    )
+  );
 #else
-  if (!pool_alloc(&core_table, &process->core_item, blocks, false)) {
+  if (
+    !pool_alloc(
+      &core_table,
+      &process->core_item,
+      blocks,
+      0
+    )
+  ) {
 #ifdef INODE_SWAP
  //printf("deref inode %d\n", process->swap_inode->c_num);
     i_deref(process->swap_inode);
@@ -433,7 +472,14 @@ bool process_alloc(struct process *process, long size) {
   }
 #endif
 #if defined(PREALLOCATE_SWAP) && defined(MOVEABLE_SWAP)
-  rassert(pool_alloc(&swap_table, &process->swap_item, blocks, false));
+  rassert(
+    pool_alloc(
+      &swap_table,
+      &process->swap_item,
+      blocks,
+      POOL_ALLOC_MODE_MOVEABLE
+    )
+  );
 #endif
 
 #ifdef INDIRECT_CORE
@@ -494,9 +540,25 @@ bool process_realloc(struct process *process, long size) {
 #endif
  
 #if defined(PREALLOCATE_SWAP) && !defined(MOVEABLE_SWAP)
+  // this is a bit clunky, we want realloc without copying old contents,
+  // so we free, try to allocate larger, if that fails, allocate original
   pool_free(&swap_table, &process->swap_item);
-  if (!pool_alloc(&swap_table, &process->swap_item, blocks, false)) {
-    rassert(pool_alloc(&swap_table, &process->swap_item, old_blocks, false));
+  if (
+    !pool_alloc(
+      &swap_table,
+      &process->swap_item,
+      blocks,
+      0
+    )
+  ) {
+    rassert(
+      pool_alloc(
+        &swap_table,
+        &process->swap_item,
+        old_blocks,
+        0
+      )
+    );
     return false;
   }
 #endif
@@ -506,19 +568,48 @@ bool process_realloc(struct process *process, long size) {
 
   // reallocate core and possible swap
 #ifdef MOVEABLE_CORE
-  rassert(pool_realloc(&core_table, &process->core_item, blocks, 0, false));
+  rassert(
+    pool_alloc(
+      &core_table,
+      &process->core_item,
+      blocks,
+      POOL_ALLOC_MODE_MOVEABLE |
+        POOL_ALLOC_MODE_REALLOC
+    )
+  );
 #else
-  if (!pool_realloc(&core_table, &process->core_item, blocks, 0, false)) {
+  if (
+    !pool_alloc(
+      &core_table,
+      &process->core_item,
+      blocks,
+      POOL_ALLOC_MODE_REALLOC
+    )
+  ) {
 #if defined(PREALLOCATE_SWAP) && !defined(MOVEABLE_SWAP)
     pool_free(&swap_table, &process->swap_item);
-    rassert(pool_alloc(&swap_table, &process->swap_item, old_blocks, false));
+    rassert(
+      pool_alloc(
+        &swap_table,
+        &process->swap_item,
+        old_blocks,
+        0
+      )
+    );
 #endif
     return false;
   }
 #endif
 #if defined(PREALLOCATE_SWAP) && defined(MOVEABLE_SWAP)
   pool_free(&swap_table, &process->swap_item);
-  rassert(pool_alloc(&swap_table, &process->swap_item, blocks, false));
+  rassert(
+    pool_alloc(
+      &swap_table,
+      &process->swap_item,
+      blocks,
+      POOL_ALLOC_MOVEABLE
+    )
+  );
 #endif
 
 #ifdef INDIRECT_CORE
@@ -594,7 +685,18 @@ void process_run(struct process *process) {
       // add to core pool
       process_core_blocks = 0;
 #ifndef PREALLOCATE_CORE
-      rassert(pool_alloc(&core_table, &process->core_item, blocks, false));
+      rassert(
+        pool_alloc(
+          &core_table,
+          &process->core_item,
+          blocks,
+#ifdef MOVEABLE_CORE
+          POOL_ALLOC_MODE_MOVEABLE
+#else
+          0
+#endif
+        )
+      );
 #endif
       goto loop_entry_full;
     }
@@ -630,11 +732,16 @@ void process_run(struct process *process) {
       f_trunc(process->swap_inode);
 #else
       rassert(
-        pool_realloc(
+        pool_alloc(
           &swap_table,
           &process->swap_item,
           process_swap_blocks,
-          false
+#ifdef MOVEABLE_SWAP
+          POOL_ALLOC_MODE_MOVEABLE |
+            POOL_ALLOC_MODE_REALLOC
+#else
+          POOL_ALLOC_MODE_REALLOC
+#endif
         )
       );
 #endif
@@ -650,12 +757,15 @@ void process_run(struct process *process) {
       // increase core allocation
 #ifndef PREALLOCATE_CORE
       rassert(
-        pool_realloc(
+        pool_alloc(
           &core_table, 
           &process->core_item,
           process_core_blocks + blocks,
-          blocks,
-          true
+          POOL_ALLOC_MODE_LAST_FIT |
+#ifdef MOVEABLE_CORE
+            POOL_ALLOC_MODE_MOVEABLE |
+#endif
+            POOL_ALLOC_MODE_REALLOC
         )
       );
 #endif