Combine non-moveable with moveable pool, define both head->move and head->move_up...
authorNick Downing <nick@ndcode.org>
Mon, 22 Apr 2019 07:22:10 +0000 (17:22 +1000)
committerNick Downing <nick@ndcode.org>
Mon, 22 Apr 2019 07:25:33 +0000 (17:25 +1000)
core.h
gen.sh
pool.c
pool.h
pool_test_run.c
process.c
swap.h

diff --git a/core.h b/core.h
index d7edcdf..f3a7ac9 100644 (file)
--- a/core.h
+++ b/core.h
@@ -8,23 +8,6 @@
 //#define INDIRECT_CORE 1
 #define MOVEABLE_CORE 1
 
-#ifdef MOVEABLE_CORE
-#define core_table_alloc(item, size) \
-  pool_alloc_moveable(&core_table, item, size)
-#define core_table_realloc(item, size) \
-  pool_realloc_moveable(&core_table, item, size)
-#define core_table_realloc_base(item, size) \
-  pool_realloc_base_moveable(&core_table, item, size)
-#else
-#define core_table_alloc(item, size) \
-  pool_alloc(&core_table, item, size)
-#define core_table_realloc(item, size) \
-  pool_realloc(&core_table, item, size)
-#define core_table_realloc_base(item, size) \
-  pool_realloc_base(&core_table, item, size)
-#endif
-#define core_table_free(item) pool_free(&core_table, item)
-
 #ifdef INDIRECT_CORE
 #define CORE_AVAIL core_block_avail
 #else
diff --git a/gen.sh b/gen.sh
index f614f99..e04fc64 100755 (executable)
--- a/gen.sh
+++ b/gen.sh
@@ -1,6 +1,5 @@
 #!/bin/sh -e
 
-sed -e 's/^\/\/#define CLASSIC_POOL 1/#define CLASSIC_POOL 1/' -i pool.h
 sed -e 's/^#define MOVEABLE_POOL 1/\/\/#define MOVEABLE_POOL 1/' -i pool.h
 
 # we will only use non-moveable swap, so it must be preallocated,
@@ -41,12 +40,7 @@ sed -e 's/^\/\/#define INDIRECT_SWAP 1/#define INDIRECT_SWAP 1/' -i swap.h
 ./pp.sh moveable_core_indirect_swap
 cp rassert.h moveable_core_indirect_swap
 
-sed -e 's/^#define CLASSIC_POOL 1/\/\/#define CLASSIC_POOL 1/' -i pool.h
-
 sed -e 's/^\/\/#define INODE_SWAP 1/#define INODE_SWAP 1/' -i process.h
 ./pp.sh moveable_core_inode_swap
 rm moveable_core_inode_swap/swap.[ch]
 cp rassert.h fuzix_fs.[ch] util.[ch] moveable_core_inode_swap
-
-# must leave in a fit state for compiling the pool test
-sed -e 's/^\/\/#define CLASSIC_POOL 1/#define CLASSIC_POOL 1/' -i pool.h
diff --git a/pool.c b/pool.c
index e89184e..445e0d2 100644 (file)
--- a/pool.c
+++ b/pool.c
@@ -4,8 +4,9 @@
 #include <stdlib.h>
 #include "pool.h"
 
+// can only define TRY_BLOCKER if MOVEABLE_POOL also defined
+#define MOVEABLE_POOL 1
 #define TRY_BLOCKER 1
-#define TRY_REALLOC 1
 
 #if 1
 void check_invariants(struct pool_head *head) {
@@ -39,7 +40,6 @@ void pool_init(
  check_invariants(head);
 }
  
-#ifdef CLASSIC_POOL
 bool pool_alloc(
   struct pool_head *head,
   struct pool_item *item,
@@ -51,218 +51,6 @@ bool pool_alloc(
   // item must not be allocated yet
   assert(item->prev == NULL && item->next == NULL);
 
-  // check size, disregarding fragmentation
-  avail = head->avail - size;
-  if (avail < 0)
-    return false;
-
-  // first-fit algorithm
-  q = &head->item;
-  do {
-    p = q;
-    q = p->next;
-    gap = q->base - p->limit;
-    if (size <= gap)
-      goto found;
-    if (q == &head->item)
-      break;
-    avail -= gap;
-  } while (avail >= 0);
-  return false;
-
-found:
-  item->base = p->limit;
-  item->limit = p->limit + size;
-
-  // insert into list at found position
-  item->prev = p;
-  p->next = item;
-  item->next = q;
-  q->prev = item;
-
-  // keep track of total allocation
-  head->avail -= size;
- check_invariants(head);
-  return true;
-}
-
-bool pool_realloc(
-  struct pool_head *head,
-  struct pool_item *item,
-  int size
-) {
-  struct pool_item *p, *q;
-  int size_change, avail, gap;
-
-  // item must be already allocated
-  assert(item->prev && item->next);
-
-  // try to change current block size without copying
-  size_change = size + item->base - item->limit;
-  if (item->base + size <= item->next->base)
-    goto resize;
-
-  // check size, disregarding fragmentation
-  avail = head->avail - size_change;
-  if (avail < 0)
-    return false;
-
-  // first-fit algorithm, until our own list entry
-  q = &head->item;
-  do {
-    p = q;
-    q = p->next;
-    if (q == item)
-      goto ourself;
-    gap = q->base - p->limit;
-    if (size <= gap)
-      goto found;
-    assert(q != &head->item);
-    avail -= gap;
-  } while (avail >= 0);
-  return false;
-
-ourself:
-  // first-fit algorithm, including and after our own list entry,
-  // the first iteration (ours) is different because q != p->next,
-  // this causes us to ignore our own entry in the gap calculation
-  q = q->next;
-  goto loop_entry;
-  do {
-    p = q;
-    q = p->next;
-  loop_entry:
-    gap = q->base - p->limit;
-    if (size <= gap)
-      goto found;
-    if (q == &head->item)
-      break;
-    avail -= gap;
-  } while (avail >= 0);
-  return false;
-
-found:
-  // if realloc is used, then user must provide move routine
-  // (when called from here, it is always non-overlapping or downwards)
-  assert(head->move);
-  head->move(item, p->limit);
-  //item->limit += p->limit - item->base;
-  item->base = p->limit;
-  // remove from list
-  item->prev->next = item->next;
-  item->next->prev = item->prev;
-
-  // insert into list at found position
-  item->prev = p;
-  p->next = item;
-  item->next = q;
-  q->prev = item;
-
-resize:
-  item->limit = item->base + size;
-
-  // keep track of total allocation
-  head->avail -= size_change;
- check_invariants(head);
-  return true;
-}
-
-bool pool_realloc_base(
-  struct pool_head *head,
-  struct pool_item *item,
-  int size
-) {
-  struct pool_item *p, *q;
-  int size_change, avail, gap;
-
-  // item must be already allocated
-  assert(item->prev && item->next);
-
-  // try to change current block size without copying
-  size_change = size + item->base - item->limit;
-  if (item->limit - size >= item->prev->limit)
-    goto resize;
-
-  // check size, disregarding fragmentation
-  avail = head->avail - size_change;
-  if (avail < 0)
-    return false;
-
-  // last-fit algorithm, until our own list entry
-  p = &head->item;
-  do {
-    q = p;
-    p = q->prev;
-    if (p == item)
-      goto ourself;
-    gap = q->base - p->limit;
-    if (size <= gap)
-      goto found;
-    assert(p != &head->item);
-    avail -= gap;
-  } while (avail >= 0);
-  return false;
-
-ourself:
-  // first-fit algorithm, including and after our own list entry,
-  // the first iteration (ours) is different because p != q->prev,
-  // this causes us to ignore our own entry in the gap calculation
-  p = p->prev;
-  goto loop_entry;
-  do {
-    q = p;
-    p = q->prev;
-  loop_entry:
-    gap = q->base - p->limit;
-    if (size <= gap)
-      goto found;
-    if (p == &head->item)
-      break;
-    avail -= gap;
-  } while (avail >= 0);
-  return false;
-
-found:
-  // if realloc is used, then user must provide move_up routine
-  // (when called from here, it is always non-overlapping or upwards)
-  assert(head->move_up);
-  head->move_up(item, q->base);
-  //item->base += q->base - item->limit;
-  item->limit = q->base;
-  // remove from list
-  item->prev->next = item->next;
-  item->next->prev = item->prev;
-
-  // insert into list at found position
-  item->prev = p;
-  p->next = item;
-  item->next = q;
-  q->prev = item;
-
-resize:
-  item->base = item->limit - size;
-
-  // keep track of total allocation
-  head->avail -= size_change;
- check_invariants(head);
-  return true;
-}
-#endif
-
-#ifdef MOVEABLE_POOL
-bool pool_alloc_moveable(
-  struct pool_head *head,
-  struct pool_item *item,
-  int size
-) {
-  struct pool_item *p, *q;
-  int avail, gap;
-
-  // item must not be allocated yet
-  assert(item->prev == NULL && item->next == NULL);
-
   // check size, disregarding fragmentation
   avail = head->avail - size;
   if (avail < 0)
@@ -282,16 +70,21 @@ bool pool_alloc_moveable(
     if (size <= gap)
       goto found;
 
-    // if gap is too large, move block after gap down into gap
+    // see if gap can be left alone
     avail -= gap;
     if (avail < 0) {
+#ifdef MOVEABLE_POOL
+      // move block after gap down into gap
+      if (head->move == NULL || head->move_up == NULL)
+        return false;
       avail += gap;
 
-      // if moveable alloc is used, then user must provide move routine
-      assert(head->move);
       head->move(q, p->limit);
       q->limit += p->limit - q->base;
       q->base = p->limit;
+#else
+      return false;
+#endif
     }
 
     assert(q != &head->item);
@@ -313,7 +106,7 @@ found:
   return true;
 }
 
-bool pool_realloc_moveable(
+bool pool_realloc(
   struct pool_head *head,
   struct pool_item *item,
   int size
@@ -324,13 +117,17 @@ bool pool_realloc_moveable(
   struct pool_item *blocker;
   int blocker_size;
 #endif
-#ifdef TRY_REALLOC
+#ifdef MOVEABLE_POOL
   int avail_save;
 #endif
 
   // item must be already allocated
   assert(item->prev && item->next);
 
+  // realloc requires at least the move-down routine
+  // (even though some requests succeed without move)
+  assert(head->move);
+
   // try to change current block size without copying
   size_change = size + item->base - item->limit;
 #ifndef TRY_BLOCKER
@@ -375,9 +172,8 @@ blocker_test:
 
 #ifdef TRY_BLOCKER
     // see if blocker fits in gap
-    if (blocker_size <= gap) {
-      // if moveable realloc is used, then user must provide move routine
-      assert(head->move);
+    if (blocker_size <= gap && head->move_up) {
+      // move blocker down into gap
       head->move(blocker, p->limit);
       blocker->limit += p->limit - blocker->base;
       blocker->base = p->limit;
@@ -398,13 +194,14 @@ blocker_test:
     }
 #endif
 
-    // if gap is too large, move block after gap down into gap
+    // see if gap can be left alone
     avail -= gap;
     if (avail < 0) {
+      // move block after gap down into gap
+      if (head->move_up == NULL)
+        return false;
       avail += gap;
 
-      // if moveable realloc is used, then user must provide move routine
-      assert(head->move);
       head->move(q, p->limit);
       q->limit += p->limit - q->base;
       q->base = p->limit;
@@ -413,11 +210,12 @@ blocker_test:
     assert(q != &head->item);
   }
 
-#ifdef TRY_REALLOC
+#ifdef MOVEABLE_POOL
   // optional step: try an ordinary realloc in rest of list
   // this is because if the pool consists of a tightly packed region
   // followed by a mainly free region, it's best to move us to there
   avail_save = avail;
+#endif
 
   // first-fit algorithm, including and after our own list entry,
   // the first iteration (ours) is different because q != p->next,
@@ -435,29 +233,29 @@ blocker_test:
       break;
     avail -= gap;
   } while (avail >= 0);
+#ifdef MOVEABLE_POOL
+  if (head->move_up == NULL)
+    return false;
 
   avail = avail_save;
   p = item->prev;
-#endif
 
-  // calculate gap that would be left if we didn't move ourself,
-  // if too large, move block after gap (ourself) down into gap
+  // calculate gap that would be left if we didn't move ourself
   gap = item->base - p->limit;
+
+  // see if gap can be left alone
   avail -= gap;
   if (avail < 0) {
+    // move block after gap (ourself) down into gap
     avail += gap;
 
-    // if moveable realloc is used, then user must provide move routine
-    assert(head->move);
     head->move(item, p->limit);
     item->limit += p->limit - item->base;
     item->base = p->limit;
 
-#ifndef TRY_REALLOC
     // if didn't do ordinary realloc above, see if we now fit
-    if (item->base + size <= item->next->base)
-      goto resize;
-#endif
+    //if (item->base + size <= item->next->base)
+    //  goto resize;
   }
 
   // at this point we will not move our own block anymore (because
@@ -523,10 +321,12 @@ blocker_test:
 
     assert(p != &head->item);
   }
+#else
+  return false;
+#endif
 
 found:
-  // if moveable realloc is used, then user must provide move routine
-  // (when called from here, it is always non-overlapping or downwards)
+  // move ourself into found spot, always non-overlapping or downwards
   assert(head->move);
   head->move(item, p->limit);
   //item->limit += p->limit - item->base;
@@ -543,6 +343,7 @@ found:
   q->prev = item;
 
 resize:
+  // resize in place (or do the commented code above if moved ourself)
   item->limit = item->base + size;
 
   // keep track of total allocation
@@ -551,7 +352,7 @@ resize:
   return true;
 }
 
-bool pool_realloc_base_moveable(
+bool pool_realloc_base(
   struct pool_head *head,
   struct pool_item *item,
   int size
@@ -562,13 +363,17 @@ bool pool_realloc_base_moveable(
   struct pool_item *blocker;
   int blocker_size;
 #endif
-#ifdef TRY_REALLOC
+#ifdef MOVEABLE_POOL
   int avail_save;
 #endif
 
   // item must be already allocated
   assert(item->prev && item->next);
 
+  // realloc_base requires at least the move-up routine
+  // (even though some requests succeed without move)
+  assert(head->move_up);
   // try to change current block size without copying
   size_change = size + item->base - item->limit;
 #ifndef TRY_BLOCKER
@@ -613,9 +418,8 @@ blocker_test:
 
 #ifdef TRY_BLOCKER
     // see if blocker fits in gap
-    if (blocker_size <= gap) {
-      // if moveable realloc is used, then user must provide move_up routine
-      assert(head->move_up);
+    if (blocker_size <= gap && head->move) {
+      // move blocker up into gap
       head->move_up(blocker, q->base);
       blocker->base += q->base - blocker->limit;
       blocker->limit = q->base;
@@ -636,13 +440,15 @@ blocker_test:
     }
 #endif
 
-    // if gap is too large, move block before gap up into gap
+    // see if gap can be left alone
     avail -= gap;
     if (avail < 0) {
+      // move block before gap up into gap
+      if (head->move == NULL)
+        return false;
       avail += gap;
 
-      // if moveable realloc is used, then user must provide move_up routine
-      assert(head->move_up);
       head->move_up(p, q->base);
       p->base += q->base - p->limit;
       p->limit = q->base;
@@ -651,11 +457,12 @@ blocker_test:
     assert(p != &head->item);
   }
 
-#ifdef TRY_REALLOC
+#ifdef MOVEABLE_POOL
   // optional step: try an ordinary realloc in rest of list
   // this is because if the pool consists of a tightly packed region
   // preceded by a mainly free region, it's best to move us to there
   avail_save = avail;
+#endif
 
   // last-fit algorithm, including and before our own list entry,
   // the first iteration (ours) is different because p != q->prev,
@@ -673,29 +480,29 @@ blocker_test:
       break;
     avail -= gap;
   } while (avail >= 0);
-
+#ifdef MOVEABLE_POOL
+  if (head->move == NULL)
+    return false;
   avail = avail_save;
   q = item->next;
-#endif
 
-  // calculate gap that would be left if we didn't move ourself,
-  // if too large, move block before gap (ourself) up into gap
+  // calculate gap that would be left if we didn't move ourself
   gap = q->base - item->limit;
+
+  // see if gap can be left alone
   avail -= gap;
   if (avail < 0) {
+    // move block before gap (ourself) up into gap
     avail += gap;
 
-    // if moveable realloc is used, then user must provide move_up routine
-    assert(head->move_up);
     head->move_up(item, q->base);
     item->base += q->base - item->limit;
     item->limit = q->base;
 
-#ifndef TRY_REALLOC
     // if didn't do ordinary realloc above, see if we now fit
-    if (item->limit - size >= item->prev->limit)
-      goto resize;
-#endif
+    //if (item->limit - size >= item->prev->limit)
+    //  goto resize;
   }
 
   // at this point we will not move our own block anymore (because
@@ -761,10 +568,12 @@ blocker_test:
 
     assert(q != &head->item);
   }
+#else
+  return false;
+#endif
 
 found:
-  // if moveable realloc is used, then user must provide move_up routine
-  // (when called from here, it is always non-overlapping or upwards)
+  // move ourself into found spot, always non-overlapping or downwards
   assert(head->move_up);
   head->move_up(item, q->base);
   //item->base += q->base - item->limit;
@@ -781,6 +590,7 @@ found:
   q->prev = item;
 
 resize:
+  // resize in place (or do the commented code above if moved ourself)
   item->base = item->limit - size;
 
   // keep track of total allocation
@@ -788,7 +598,6 @@ resize:
  check_invariants(head);
   return true;
 }
-#endif
 
 void pool_free(struct pool_head *head, struct pool_item *item) {
   // item must be already allocated
diff --git a/pool.h b/pool.h
index 82c706c..7d59675 100644 (file)
--- a/pool.h
+++ b/pool.h
@@ -3,9 +3,6 @@
 
 #include <stdbool.h>
 
-#define CLASSIC_POOL 1
-#define MOVEABLE_POOL 1
-
 struct pool_item {
   struct pool_item *prev;
   struct pool_item *next;
@@ -27,7 +24,6 @@ void pool_init(
   void (*move)(struct pool_item *item, int new_base),
   void (*move_up)(struct pool_item *item, int new_limit)
 );
-#ifdef CLASSIC_POOL
 bool pool_alloc(
   struct pool_head *head,
   struct pool_item *item,
@@ -43,24 +39,6 @@ bool pool_realloc_base(
   struct pool_item *item,
   int size
 );
-#endif
-#ifdef MOVEABLE_POOL
-bool pool_alloc_moveable(
-  struct pool_head *head,
-  struct pool_item *item,
-  int size
-);
-bool pool_realloc_moveable(
-  struct pool_head *head,
-  struct pool_item *item,
-  int size
-);
-bool pool_realloc_base_moveable(
-  struct pool_head *head,
-  struct pool_item *item,
-  int size
-);
-#endif
 void pool_free(struct pool_head *head, struct pool_item *item);
 
 #endif
index 07bf41c..37d069f 100644 (file)
@@ -72,7 +72,7 @@ int main(int argc, char **argv) {
   bool moveable = argc >= 4 ? strcmp(argv[3], "false") != 0 : false;
 
   struct pool_head head;
-  pool_init(&head, 0, pool_size, move, move_up);
+  pool_init(&head, 0, pool_size, move, moveable ? move_up : NULL);
 
   struct pool_item *items = malloc(n_items * sizeof(struct pool_item));
   rassert(items);
@@ -111,10 +111,7 @@ int main(int argc, char **argv) {
         success ? "true" : "false"
       );
       rassert(items[item].prev == NULL);
-      bool result =
-        moveable ?
-          pool_alloc_moveable(&head, items + item, size) :
-          pool_alloc(&head, items + item, size);
+      bool result = pool_alloc(&head, items + item, size);
       printf(
         "... %s\n",
         result == success ?
@@ -175,10 +172,7 @@ int main(int argc, char **argv) {
           actual_old_size - size,
           size
         );
-        bool result =
-          moveable ?
-            pool_realloc_moveable(&head, items + item, size) :
-            pool_realloc(&head, items + item, size);
+        bool result = pool_realloc(&head, items + item, size);
         printf(
           "... %s\n",
           result == success ?
@@ -239,10 +233,7 @@ 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 =
-          moveable ?
-            pool_realloc_base_moveable(&head, items + item, size) :
-            pool_realloc_base(&head, items + item, size);
+        bool result = pool_realloc_base(&head, items + item, size);
         printf(
           "... %s\n",
           result == success ?
index e11bb09..9461fbb 100644 (file)
--- a/process.c
+++ b/process.c
@@ -172,7 +172,7 @@ static bool do_swap_out(int swap_out) {
 #endif
 #if !defined(INODE_SWAP) && !defined(PREALLOCATE_SWAP)
       rassert(
-        swap_table_realloc(&victim->swap_item, victim_swap_blocks + blocks)
+        pool_realloc(&swap_table, &victim->swap_item, victim_swap_blocks + blocks)
       );
 #endif
       goto loop_entry;
@@ -207,7 +207,7 @@ static bool do_swap_out(int swap_out) {
       // add to swap pool
       victim_swap_blocks = 0;
 #if !defined(INODE_SWAP) && !defined(PREALLOCATE_SWAP)
-      rassert(swap_table_alloc(&victim->swap_item, blocks));
+      rassert(pool_alloc(&swap_table, &victim->swap_item, blocks));
 #endif
 
       // remove from LRU list
@@ -338,7 +338,7 @@ static bool do_swap_out(int swap_out) {
 #ifndef PREALLOCATE_CORE
         // no, reduce core allocation
         rassert(
-          core_table_realloc_base(&victim->core_item, victim_core_blocks)
+          pool_realloc_base(&core_table, &victim->core_item, victim_core_blocks)
         );
 #endif
 
@@ -350,7 +350,7 @@ static bool do_swap_out(int swap_out) {
 
 #ifndef PREALLOCATE_CORE
       // remove from core pool
-      core_table_free(&victim->core_item);
+      pool_free(&core_table, &victim->core_item);
 #endif
       victim = NULL;
 
@@ -397,7 +397,7 @@ bool process_alloc(struct process *process, long size) {
   if (
     process_avail < blocks
 #if defined(PREALLOCATE_SWAP) && !defined(MOVEABLE_SWAP)
-    || !swap_table_alloc(&process->swap_item, blocks)
+    || !pool_alloc(&swap_table, &process->swap_item, blocks)
 #endif
   )
     return false;
@@ -408,20 +408,20 @@ bool process_alloc(struct process *process, long size) {
 
   // allocate core and possible swap
 #ifdef MOVEABLE_CORE
-  rassert(core_table_alloc(&process->core_item, blocks));
+  rassert(pool_alloc(&core_table, &process->core_item, blocks));
 #else
-  if (!core_table_alloc(&process->core_item, blocks)) {
+  if (!pool_alloc(&core_table, &process->core_item, blocks)) {
 #ifdef INODE_SWAP
  //printf("deref inode %d\n", process->swap_inode->c_num);
     i_deref(process->swap_inode);
 #elif defined(PREALLOCATE_SWAP) && !defined(MOVEABLE_SWAP)
-    swap_table_free(&process->swap_item);
+    pool_free(&swap_table, &process->swap_item);
 #endif
     return false;
   }
 #endif
 #if defined(PREALLOCATE_SWAP) && defined(MOVEABLE_SWAP)
-  rassert(swap_table_alloc(&process->swap_item, blocks));
+  rassert(pool_alloc(&swap_table, &process->swap_item, blocks));
 #endif
 
 #ifdef INDIRECT_CORE
@@ -482,9 +482,9 @@ bool process_realloc(struct process *process, long size) {
 #endif
  
 #if defined(PREALLOCATE_SWAP) && !defined(MOVEABLE_SWAP)
-  swap_table_free(&process->swap_item);
-  if (!swap_table_alloc(&process->swap_item, blocks)) {
-    rassert(swap_table_alloc(&process->swap_item, old_blocks));
+  pool_free(&swap_table, &process->swap_item);
+  if (!pool_alloc(&swap_table, &process->swap_item, blocks)) {
+    rassert(pool_alloc(&swap_table, &process->swap_item, old_blocks));
     return false;
   }
 #endif
@@ -494,19 +494,19 @@ bool process_realloc(struct process *process, long size) {
 
   // reallocate core and possible swap
 #ifdef MOVEABLE_CORE
-  rassert(core_table_realloc(&process->core_item, blocks));
+  rassert(pool_realloc(&core_table, &process->core_item, blocks));
 #else
-  if (!core_table_realloc(&process->core_item, blocks)) {
+  if (!pool_realloc(&core_table, &process->core_item, blocks)) {
 #if defined(PREALLOCATE_SWAP) && !defined(MOVEABLE_SWAP)
-    swap_table_free(&process->swap_item);
-    rassert(swap_table_alloc(&process->swap_item, old_blocks));
+    pool_free(&swap_table, &process->swap_item);
+    rassert(pool_alloc(&swap_table, &process->swap_item, old_blocks));
 #endif
     return false;
   }
 #endif
 #if defined(PREALLOCATE_SWAP) && defined(MOVEABLE_SWAP)
-  swap_table_free(&process->swap_item);
-  rassert(swap_table_alloc(&process->swap_item, blocks));
+  pool_free(&swap_table, &process->swap_item);
+  rassert(pool_alloc(&swap_table, &process->swap_item, blocks));
 #endif
 
 #ifdef INDIRECT_CORE
@@ -582,7 +582,7 @@ void process_run(struct process *process) {
       // add to core pool
       process_core_blocks = 0;
 #ifndef PREALLOCATE_CORE
-      rassert(core_table_alloc(&process->core_item, blocks));
+      rassert(pool_alloc(&core_table, &process->core_item, blocks));
 #endif
       goto loop_entry_full;
     }
@@ -617,7 +617,7 @@ void process_run(struct process *process) {
       udata.u_offset = (long)process_swap_blocks << BLOCK_SHIFT;
       f_trunc(process->swap_inode);
 #else
-      rassert(swap_table_realloc(&process->swap_item, process_swap_blocks));
+      rassert(pool_realloc(&swap_table, &process->swap_item, process_swap_blocks));
 #endif
 
     loop_entry_partial:
@@ -631,7 +631,7 @@ void process_run(struct process *process) {
       // increase core allocation
 #ifndef PREALLOCATE_CORE
       rassert(
-        core_table_realloc_base(
+        pool_realloc_base(&core_table, 
           &process->core_item,
           process_core_blocks + blocks
         )
@@ -763,7 +763,7 @@ void process_run(struct process *process) {
     f_trunc(process->swap_inode);
 #elif !defined(PREALLOCATE_SWAP)
     // remove from swap pool
-    swap_table_free(&process->swap_item);
+    pool_free(&swap_table, &process->swap_item);
 #endif
   }
 
@@ -807,7 +807,7 @@ void process_free(struct process *process) {
     );
 #endif
 #ifndef PREALLOCATE_CORE
-    core_table_free(&process->core_item);
+    pool_free(&core_table, &process->core_item);
 #endif
   }
   else if (process == victim) {
@@ -820,7 +820,7 @@ void process_free(struct process *process) {
     swap_block_free(swap_table_mem + swap_base, victim_swap_blocks);
 #endif
 #if !defined(INODE_SWAP) && !defined(PREALLOCATE_SWAP)
-    swap_table_free(&victim->swap_item);
+    pool_free(&swap_table, &victim->swap_item);
 #endif
 #ifdef INDIRECT_CORE
 #ifdef PREALLOCATE_CORE
@@ -843,7 +843,7 @@ void process_free(struct process *process) {
     core_block_free(core_table_mem + core_base, victim_core_blocks);
 #endif
 #ifndef PREALLOCATE_CORE
-    core_table_free(&victim->core_item);
+    pool_free(&core_table, &victim->core_item);
 #endif
     victim = NULL;
   }
@@ -857,16 +857,16 @@ void process_free(struct process *process) {
     );
 #endif
 #if !defined(INODE_SWAP) && !defined(PREALLOCATE_SWAP)
-    swap_table_free(&process->swap_item);
+    pool_free(&swap_table, &process->swap_item);
 #endif
   }
 
   // free the per-process table entries
 #ifdef PREALLOCATE_CORE
-  core_table_free(&process->core_item);
+  pool_free(&core_table, &process->core_item);
 #endif
 #ifdef PREALLOCATE_SWAP
-  swap_table_free(&process->swap_item);
+  pool_free(&swap_table, &process->swap_item);
 #elif defined(INODE_SWAP)
  //printf("deref inode %d\n", process->swap_inode->c_num);
   i_deref(process->swap_inode);
diff --git a/swap.h b/swap.h
index 0505c60..104e425 100644 (file)
--- a/swap.h
+++ b/swap.h
@@ -8,23 +8,6 @@
 #define INDIRECT_SWAP 1
 //#define MOVEABLE_SWAP 1
 
-#ifdef MOVEABLE_SWAP
-#define swap_table_alloc(item, size) \
-  pool_alloc_moveable(&swap_table, item, size)
-#define swap_table_realloc(item, size) \
-  pool_realloc_moveable(&swap_table, item, size)
-#define swap_table_realloc_base(item, size) \
-  pool_realloc_base_moveable(&swap_table, item, size)
-#else
-#define swap_table_alloc(item, size) \
-  pool_alloc(&swap_table, item, size)
-#define swap_table_realloc(item, size) \
-  pool_realloc(&swap_table, item, size)
-#define swap_table_realloc_base(item, size) \
-  pool_realloc_base(&swap_table, item, size)
-#endif
-#define swap_table_free(item) pool_free(&swap_table, item)
-
 #ifdef INDIRECT_SWAP
 #define SWAP_AVAIL swap_block_avail
 #else