Remove support for INODE_SWAP, make PREALLOCATE_SWAP always, make PREALLOCATE_CORE...
authorNick Downing <nick@ndcode.org>
Wed, 29 May 2019 13:32:00 +0000 (23:32 +1000)
committerNick Downing <nick@ndcode.org>
Fri, 31 May 2019 11:05:11 +0000 (21:05 +1000)
27 files changed:
.gitignore
Makefile
block_pool.c
core.c
core.h
fuzix_fs_or_swap.c [deleted file]
gen.sh
ifdef.py [new file with mode: 0755]
ifdef.sh [new file with mode: 0755]
indirect_core_contiguous_swap/Makefile [moved from indirect_core_preallocate_swap/Makefile with 100% similarity]
indirect_core_contiguous_swap/o.sh [moved from indirect_core_preallocate_swap/o.sh with 100% similarity]
indirect_core_inode_swap/Makefile [deleted file]
indirect_core_inode_swap/o.sh [deleted file]
merge.sh [new file with mode: 0755]
moveable_core_contiguous_swap/Makefile [moved from moveable_core_preallocate_swap/Makefile with 100% similarity]
moveable_core_contiguous_swap/o.sh [moved from moveable_core_preallocate_swap/o.sh with 100% similarity]
moveable_core_inode_swap/Makefile [deleted file]
moveable_core_inode_swap/o.sh [deleted file]
pool.c
process.c
process.h
process_test.h
process_test_gen.c
process_test_run.c
q.sh
swap.c
swap.h

index be6eef0..9b6c443 100644 (file)
@@ -6,17 +6,11 @@
 /indirect_core_indirect_swap/process_test.txt
 /indirect_core_indirect_swap/process_test_gen
 /indirect_core_indirect_swap/process_test_run
-/indirect_core_inode_swap/*.c
-/indirect_core_inode_swap/*.h
-/indirect_core_inode_swap/fs.bin
-/indirect_core_inode_swap/process_test.txt
-/indirect_core_inode_swap/process_test_gen
-/indirect_core_inode_swap/process_test_run
-/indirect_core_preallocate_swap/*.c
-/indirect_core_preallocate_swap/*.h
-/indirect_core_preallocate_swap/process_test.txt
-/indirect_core_preallocate_swap/process_test_gen
-/indirect_core_preallocate_swap/process_test_run
+/indirect_core_contiguous_swap/*.c
+/indirect_core_contiguous_swap/*.h
+/indirect_core_contiguous_swap/process_test.txt
+/indirect_core_contiguous_swap/process_test_gen
+/indirect_core_contiguous_swap/process_test_run
 /inode_test.txt
 /inode_test_gen
 /inode_test_run
 /moveable_core_indirect_swap/process_test.txt
 /moveable_core_indirect_swap/process_test_gen
 /moveable_core_indirect_swap/process_test_run
-/moveable_core_inode_swap/*.c
-/moveable_core_inode_swap/*.h
-/moveable_core_inode_swap/fs.bin
-/moveable_core_inode_swap/process_test.txt
-/moveable_core_inode_swap/process_test_gen
-/moveable_core_inode_swap/process_test_run
-/moveable_core_preallocate_swap/*.c
-/moveable_core_preallocate_swap/*.h
-/moveable_core_preallocate_swap/process_test.txt
-/moveable_core_preallocate_swap/process_test_gen
-/moveable_core_preallocate_swap/process_test_run
+/moveable_core_contiguous_swap/*.c
+/moveable_core_contiguous_swap/*.h
+/moveable_core_contiguous_swap/process_test.txt
+/moveable_core_contiguous_swap/process_test_gen
+/moveable_core_contiguous_swap/process_test_run
 /pool_test.txt
 /pool_test_gen
 /pool_test_run
index c09dc7b..04a7e44 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -20,13 +20,13 @@ process_test_gen: process_test_gen.o
 
 process_test_gen.o: process_test_gen.c process_test.h
 
-process_test_run: process_test_run.o process.o process_test.h core.o fuzix_fs_or_swap.o block_pool.o pool.o
+process_test_run: process_test_run.o process.o process_test.h core.o swap.o block_pool.o pool.o
        ${CC} ${CFLAGS} -o $@ $^
 
 process_test_run.o: process_test_run.c process.h core.h swap.h pool.h fuzix_fs.h util.h
 process.o: process.c process.h core.h swap.h pool.h fuzix_fs.h
 core.o: core.c core.h pool.h
-fuzix_fs_or_swap.o: fuzix_fs_or_swap.c fuzix_fs.c swap.h core.h pool.h fuzix_fs.h
+swap.o: swap.c fuzix_fs.c swap.h core.h pool.h fuzix_fs.h
 block_pool.o: block_pool.c block_pool.h
 
 # ucp no longer compiles because many fs routines commented to save space
index 37031b0..3c61d68 100644 (file)
@@ -36,21 +36,11 @@ bool block_pool_alloc(struct block_pool *block_pool, int *table, int size) {
     loop_entry:
       if (c) goto found;
     }
-#if 1
     for (j = 0; ; ++j) {
       assert(j <= block_pool->next >> 3);
       c = block_pool->bitmap[j];
       if (c) goto found;
     }
-#else
-    k = (block_pool->next >> 3) + 1;
-    for (j = 0; j < k; ++j) {
-      c = block_pool->bitmap[j];
-      if (c) goto found;
-    }
-    core_block_free(table, i);
-    return false;
-#endif
 
   found:
     for (k = 0; (c & 1) == 0; ++k)
@@ -58,9 +48,7 @@ bool block_pool_alloc(struct block_pool *block_pool, int *table, int size) {
     block_pool->bitmap[j] &= ~bits[k];
     block_pool->next = (j << 3) | k;
 
-#ifndef NDEBUG // makes us remove the following line in gen.sh as appropriate
     assert(table[i] == 0x55555555);
-#endif
     table[i] = block_pool->next++;
     if (block_pool->next >= block_pool->n_blocks)
       block_pool->next = 0;
@@ -80,9 +68,7 @@ void block_pool_free(struct block_pool *block_pool, int *table, int size) {
     j >>= 3;
     assert((block_pool->bitmap[j] & bits[k]) == 0);
     block_pool->bitmap[j] |= bits[k];
-#ifndef NDEBUG
     table[i] = 0x55555555;
-#endif
   }
 
   block_pool->avail += size;
diff --git a/core.c b/core.c
index 4285051..48fe5d9 100644 (file)
--- a/core.c
+++ b/core.c
@@ -2,9 +2,7 @@
 #include <stddef.h>
 //#include <stdio.h>
 #include <stdlib.h>
-#ifndef NDEBUG
 #include <string.h>
-#endif
 #include "core.h"
 #include "process.h"
 #include "rassert.h"
@@ -13,20 +11,18 @@ struct pool_head core_table;
 #ifdef INDIRECT_CORE
 int *core_table_mem;
 struct block_pool core_block_pool;
-#endif
 
-#ifdef PREALLOCATE_CORE
 int victim_core_blocks;
-#endif
+#endif /* INDIRECT_CORE */
 
 static void core_move(struct pool_item *item, int new_base) {
   int base, blocks;
-#ifdef INDIRECT_CORE
-  int i;
-#else
+#ifndef INDIRECT_CORE
   struct process *process;
   long size;
-#endif
+#else /* INDIRECT_CORE */
+  int i;
+#endif /* INDIRECT_CORE */
 
   base = item->base;
   blocks = item->limit - base;
@@ -38,14 +34,7 @@ static void core_move(struct pool_item *item, int new_base) {
   //  new_base + blocks
   //);
   assert(new_base <= base || new_base >= base + blocks);
-#ifdef INDIRECT_CORE
-  for (i = 0; i < blocks; ++i) {
-    core_table_mem[new_base + i] = core_table_mem[base + i];
-#ifndef NDEBUG
-    core_table_mem[base + i] = 0x55555555;
-#endif
-  }
-#else
+#ifndef INDIRECT_CORE
   // see if incomplete last block, if so don't copy extra part
   process =
     (struct process *)((char *)item - offsetof(struct process, core_item));
@@ -55,19 +44,13 @@ static void core_move(struct pool_item *item, int new_base) {
 
   // copy by abstract routine
   core_copy((long)base << BLOCK_SHIFT, (long)new_base << BLOCK_SHIFT, size);
-#endif
 }
 
-#ifdef MOVEABLE_CORE
 static void core_move_up(struct pool_item *item, int new_limit) {
   int limit, blocks;
-#ifdef INDIRECT_CORE
-  int i;
-#else
   long limit1, new_limit1, size;
   struct process *process;
   long trim;
-#endif
 
   limit = item->limit;
   blocks = limit - item->base;
@@ -79,15 +62,6 @@ static void core_move_up(struct pool_item *item, int new_limit) {
   //  new_limit
   //);
   assert(new_limit >= limit || new_limit <= limit - blocks);
-#ifdef INDIRECT_CORE
-  blocks = -blocks;
-  for (i = -1; i >= blocks; --i) {
-    core_table_mem[new_limit + i] = core_table_mem[limit + i];
-#ifndef NDEBUG
-    core_table_mem[limit + i] = 0x55555555;
-#endif
-  }
-#else
   // set up transfer parameters
   limit1 = (long)limit << BLOCK_SHIFT;
   new_limit1 = (long)new_limit << BLOCK_SHIFT;
@@ -101,43 +75,46 @@ static void core_move_up(struct pool_item *item, int new_limit) {
     limit1 -= trim;
     new_limit1 -= trim;
     size = process->size;
+#else /* INDIRECT_CORE */
+  for (i = 0; i < blocks; ++i) {
+    core_table_mem[new_base + i] = core_table_mem[base + i];
+    core_table_mem[base + i] = 0x55555555;
+#endif /* INDIRECT_CORE */
   }
 
+#ifndef INDIRECT_CORE
   // copy by abstract routine
   core_copy_up(limit1, new_limit1, size);
-#endif
+#endif /* ! INDIRECT_CORE */
 }
-#endif
 
-#ifdef INDIRECT_CORE
-void core_init(int n_blocks, int table_size)
-#else
+#ifndef INDIRECT_CORE
 void core_init(int n_blocks)
-#endif
+#else /* INDIRECT_CORE */
+void core_init(int n_blocks, int table_size)
+#endif /* INDIRECT_CORE */
 {
   pool_init(
     &core_table,
     0,
-#ifdef INDIRECT_CORE
-    table_size,
-#else
+#ifndef INDIRECT_CORE
     n_blocks,
-#endif
+#else /* INDIRECT_CORE */
+    table_size,
+#endif /* INDIRECT_CORE */
     core_move,
-#ifdef MOVEABLE_CORE
+#ifndef INDIRECT_CORE
     core_move_up
-#else
+#else /* INDIRECT_CORE */
     NULL
-#endif
+#endif /* INDIRECT_CORE */
   );
 
 #ifdef INDIRECT_CORE
   core_table_mem = malloc(table_size * sizeof(int));
   rassert(core_table_mem);
-#ifndef NDEBUG
   memset(core_table_mem, 0x55, table_size * sizeof(int));
-#endif
 
   block_pool_init(&core_block_pool, n_blocks);
-#endif
+#endif /* INDIRECT_CORE */
 }
diff --git a/core.h b/core.h
index da3128a..c0960be 100644 (file)
--- a/core.h
+++ b/core.h
@@ -1,40 +1,32 @@
 #ifndef _CORE_H
 #define _CORE_H 1
 
-//#define PREALLOCATE_CORE 1
 //#define INDIRECT_CORE 1
-#define MOVEABLE_CORE 1
 
 #include <stdint.h>
 #ifdef INDIRECT_CORE
 #include "block_pool.h"
-#endif
+#endif /* INDIRECT_CORE */
 #include "pool.h"
 
-#ifdef INDIRECT_CORE
-#define CORE_AVAIL core_block_pool.avail
-#else
-#define CORE_AVAIL core_table.avail
-#endif
-
 extern struct pool_head core_table;
 #ifdef INDIRECT_CORE
 extern int *core_table_mem;
 extern struct block_pool core_block_pool;
-#endif
+#endif /* INDIRECT_CORE */
 
-#ifdef PREALLOCATE_CORE
-extern int victim_core_blocks;
-#endif
-
-#ifdef INDIRECT_CORE
-void core_init(int n_table, int n_blocks);
-#else
+#ifndef INDIRECT_CORE
 void core_init(int n_table);
+#else /* INDIRECT_CORE */
+extern int victim_core_blocks;
+#endif /* INDIRECT_CORE */
 
+#ifndef INDIRECT_CORE
 // abstract
 void core_copy(long src_base, long dest_base, long size);
 void core_copy_up(long src_limit, long dest_limit, long size);
-#endif
+#else /* INDIRECT_CORE */
+void core_init(int n_table, int n_blocks);
+#endif /* INDIRECT_CORE */
 
 #endif
diff --git a/fuzix_fs_or_swap.c b/fuzix_fs_or_swap.c
deleted file mode 100644 (file)
index 419f22d..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-#include "process.h"
-#ifdef INODE_SWAP
-#include "fuzix_fs.c"
-#include "util.c"
-#else
-#include "swap.c"
-#endif
diff --git a/gen.sh b/gen.sh
index ca5fc90..e6cd3e9 100755 (executable)
--- a/gen.sh
+++ b/gen.sh
@@ -8,48 +8,23 @@
 
 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
-sed -e 's/^\/\/#define PREALLOCATE_SWAP 1/#define PREALLOCATE_SWAP 1/' -i swap.h
-sed -e 's/^#define MOVEABLE_SWAP 1/\/\/#define MOVEABLE_SWAP 1/' -i swap.h
-
-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
-sed -e 's/^#define MOVEABLE_CORE 1/\/\/#define MOVEABLE_CORE 1/' -i core.h
-
-sed -e 's/^#define INODE_SWAP 1/\/\/#define INODE_SWAP 1/' -i process.h
 sed -e 's/^#define INDIRECT_SWAP 1/\/\/#define INDIRECT_SWAP 1/' -i swap.h
-./cpp.sh indirect_core_preallocate_swap "$@"
-cp rassert.h indirect_core_preallocate_swap
+./cpp.sh indirect_core_contiguous_swap "$@"
+cp rassert.h indirect_core_contiguous_swap
 
 sed -e 's/^\/\/#define INDIRECT_SWAP 1/#define INDIRECT_SWAP 1/' -i swap.h
 ./cpp.sh indirect_core_indirect_swap "$@"
 cp rassert.h indirect_core_indirect_swap
 
-sed -e 's/^\/\/#define INODE_SWAP 1/#define INODE_SWAP 1/' -i process.h
-./cpp.sh indirect_core_inode_swap "$@"
-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.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
-sed -e 's/^\/\/#define MOVEABLE_CORE 1/#define MOVEABLE_CORE 1/' -i core.h
-
-sed -e 's/^#define INODE_SWAP 1/\/\/#define INODE_SWAP 1/' -i process.h
 sed -e 's/^#define INDIRECT_SWAP 1/\/\/#define INDIRECT_SWAP 1/' -i swap.h
-./cpp.sh moveable_core_preallocate_swap "$@"
-rm moveable_core_preallocate_swap/block_pool.[ch]
-cp rassert.h moveable_core_preallocate_swap
+./cpp.sh moveable_core_contiguous_swap "$@"
+rm moveable_core_contiguous_swap/block_pool.[ch]
+cp rassert.h moveable_core_contiguous_swap
 
 sed -e 's/^\/\/#define INDIRECT_SWAP 1/#define INDIRECT_SWAP 1/' -i swap.h
 ./cpp.sh moveable_core_indirect_swap "$@"
 cp rassert.h moveable_core_indirect_swap
-
-sed -e 's/^\/\/#define INODE_SWAP 1/#define INODE_SWAP 1/' -i process.h
-./cpp.sh moveable_core_inode_swap "$@"
-rm moveable_core_inode_swap/block_pool.[ch] moveable_core_inode_swap/swap.[ch]
-cp rassert.h fuzix_fs.[ch] util.[ch] moveable_core_inode_swap
-
-sed -e 's/^#define INODE_SWAP 1/\/\/#define INODE_SWAP 1/' -i process.h
diff --git a/ifdef.py b/ifdef.py
new file mode 100755 (executable)
index 0000000..c9bc485
--- /dev/null
+++ b/ifdef.py
@@ -0,0 +1,11 @@
+#!/usr/bin/env python3
+
+import sys
+
+nest = 0
+for line in sys.stdin:
+  if line[:3] == '#if':
+    nest += 1
+  elif line[:6] == '#endif':
+    nest -= 1
+  sys.stdout.write(line.rstrip() + ('@' if nest else '\n'))
diff --git a/ifdef.sh b/ifdef.sh
new file mode 100755 (executable)
index 0000000..2e8ae33
--- /dev/null
+++ b/ifdef.sh
@@ -0,0 +1,22 @@
+#!/bin/sh
+mkdir $4
+for i in $2/*.[ch]
+do
+  f=`basename $i`
+  if test -f $3/$f
+  then
+    sed -e 's/^#/##/' <$2/$f >a
+    sed -e 's/^#/##/' <$3/$f >b
+    diff --ifdef=$1 a b |./ifdef.py |sed -e 's/^#if\([^@]*\)@@/@#if\1@/; s/@@#else\([^@]*\)/@#else\1@/; s/@@#endif\([^@]*\)/@#endif\1@/' >$4/$f
+  else
+    sed -e 's/^#/##/' <$2/$f >$4/$f
+  fi
+done
+for i in $3/*.[ch]
+do
+  f=`basename $i`
+  if ! test -f $2/$f
+  then
+    sed -e 's/^#/##/' <$3/$f >$4/$f
+  fi
+done
diff --git a/indirect_core_inode_swap/Makefile b/indirect_core_inode_swap/Makefile
deleted file mode 100644 (file)
index 5bef8a8..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-CFLAGS=-g -Wall
-
-all: process_test_gen process_test_run
-
-process_test_gen: process_test_gen.o
-       ${CC} ${CFLAGS} -o $@ $^
-
-process_test_gen.o: process_test_gen.c process_test.h
-
-process_test_run: process_test_run.o process.o core.o fuzix_fs.o util.o block_pool.o pool.o
-       ${CC} ${CFLAGS} -o $@ $^
-
-process_test_run.o: process_test_run.c process.h core.h fuzix_fs.h util.h pool.h
-process.o: process.c process.h core.h fuzix_fs.h util.h pool.h
-core.o: core.c core.h pool.h
-fuzix_fs.o: fuzix_fs.c fuzix_fs.h
-block_pool.o: block_pool.c block_pool.h
-pool.o: pool.c pool.h
-
-clean:
-       rm -f *.o process_test_run
diff --git a/indirect_core_inode_swap/o.sh b/indirect_core_inode_swap/o.sh
deleted file mode 100755 (executable)
index ed5ff21..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-#!/bin/sh
-
-echo "generate test script"
-./process_test_gen 16 248 1024 32 >process_test.txt
-
-echo "run test script"
-rm -f fs.bin
-# need 1536 x 0.5 kbyte for 192 x 4 = 768 kbytes, plus 1 x 0.5 kbyte root dir
-../mkfs fs.bin 63 1600
-./process_test_run 16 64 fs.bin 8 384 <process_test.txt
diff --git a/merge.sh b/merge.sh
new file mode 100755 (executable)
index 0000000..874fa27
--- /dev/null
+++ b/merge.sh
@@ -0,0 +1,6 @@
+#!/bin/sh
+./ifdef.sh INDIRECT_SWAP indirect_core_preallocate_swap indirect_core_indirect_swap indirect_core
+./ifdef.sh INDIRECT_SWAP moveable_core_preallocate_swap moveable_core_indirect_swap moveable_core
+./ifdef.sh INDIRECT_CORE moveable_core indirect_core new
+sed -e 's/@/\n/g' -i new/*.[ch]
+sed -e 's/^#\+/#/' -i new/*.[ch]
diff --git a/moveable_core_inode_swap/Makefile b/moveable_core_inode_swap/Makefile
deleted file mode 100644 (file)
index 47ea5eb..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-CFLAGS=-g -Wall
-
-all: process_test_gen process_test_run
-
-process_test_gen: process_test_gen.o
-       ${CC} ${CFLAGS} -o $@ $^
-
-process_test_gen.o: process_test_gen.c process_test.h
-
-process_test_run: process_test_run.o process.o core.o fuzix_fs.o util.o pool.o
-       ${CC} ${CFLAGS} -o $@ $^
-
-process_test_run.o: process_test_run.c process.h core.h fuzix_fs.h util.h pool.h
-process.o: process.c process.h core.h fuzix_fs.h util.h pool.h
-core.o: core.c core.h pool.h
-fuzix_fs.o: fuzix_fs.c fuzix_fs.h
-pool.c: pool.o pool.h
-
-clean:
-       rm -f *.o process_test_run
diff --git a/moveable_core_inode_swap/o.sh b/moveable_core_inode_swap/o.sh
deleted file mode 100755 (executable)
index fee23ce..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-#!/bin/sh
-
-echo "generate test script"
-./process_test_gen 16 248 1024 32 >process_test.txt
-
-echo "run test script"
-rm -f fs.bin
-# need 1536 x 0.5 kbyte for 192 x 4 = 768 kbytes, plus 1 x 0.5 kbyte root dir
-../mkfs fs.bin 63 1600
-./process_test_run 16 64 fs.bin 8 <process_test.txt
diff --git a/pool.c b/pool.c
index ad6ac18..36aa53d 100644 (file)
--- a/pool.c
+++ b/pool.c
@@ -99,7 +99,7 @@ bool pool_alloc(
   avail = head->avail - size_change;
   if (avail < 0)
     return false;
+
   // work in specified direction, then reverse
   dir = (mode & POOL_ALLOC_MODE_LAST_FIT) != 0;
   while (true) {
@@ -175,7 +175,7 @@ blocker_test:
  //printf("back %p(%d)->%p(%d)\n", p, p->limit, q, q->base);
       }
 
-      // see if target fits in current gap 
+      // see if target fits in current gap
       gap = q->base - p->limit;
 #ifdef TRY_BLOCKER
       if (target_size <= gap) {
index 5fc8baf..c893eb3 100644 (file)
--- a/process.c
+++ b/process.c
 #include "process.h"
 #include "rassert.h"
 
-#ifdef INODE_SWAP
-#define UCP 1
-#include "fuzix_fs.h"
-#else
 #include "swap.h"
-#endif
 
 struct process *processes;
 int n_processes;
 
-#ifdef INODE_SWAP
-long process_avail, process_spare;
-#else
 int process_avail;
-#endif
 
 struct lru_item lru_head;
 
 struct process *victim;
 
-#ifdef INODE_SWAP
-// adds indirect and double indirect block(s) to estimate disk size of file
-// also does another estimation based on the internal fragmentation of core
-// returns the larger of the two estimates
-static long estimate_size(long size) {
-  long core_size;
-  int blocks, disk_blocks;
-  long disk_size;
-
-  core_size = (size + (BLOCK_SIZE - 1)) & ~(BLOCK_SIZE - 1);
-  assert(size < (long)DISK_BLOCK_SIZE << 16);
-  blocks = (int)((size + (DISK_BLOCK_SIZE - 1)) >> DISK_BLOCK_SHIFT);
-  disk_blocks = blocks;
-  if (blocks > 18) {
-    // has indirect blocks
-    blocks = (blocks + (DISK_INDIRECT_SIZE - 1 - 18)) >> DISK_INDIRECT_SHIFT;
-    disk_blocks += blocks;
-    if (blocks > 1) {
-      // has double indirect disk_blocks
-      blocks = (blocks + (DISK_INDIRECT_SIZE - 1 - 1)) >> DISK_INDIRECT_SHIFT;
-      assert(blocks == 1);
-      disk_blocks += blocks;
-    }
-  }
-  disk_size = (long)disk_blocks << DISK_BLOCK_SHIFT;
-  return core_size >= disk_size ? core_size : disk_size;
-}
-
-// basically the inverse of the above, estimates size of files that could be
-// created if space is divided into at most n files, but a bit conservatively
-static long estimate_free(void) {/*int n) {*/
-  int blocks;
-
-  // at most one partial indirect and double indirect block per file
-  blocks = fs_tab[0].s_tfree - 2;/*(n << 1);*/
-  // max number of FULL indirect blocks (ignore the 18 direct blocks)
-  blocks -= blocks / (DISK_INDIRECT_SIZE + 1);
-  return (long)blocks << DISK_BLOCK_SHIFT;
-}
-#endif
-
 void process_init(int n, int spare) {
-#ifndef NDEBUG
   int i;
-#endif
-#if defined(INODE_SWAP) && defined(PREALLOCATE_CORE)
-  long core_table_avail;
-#endif
+
   processes = calloc(n, sizeof(struct process));
   rassert(processes);
   n_processes = n;
-#ifndef NDEBUG
   for (i = 0; i < n_processes; ++i)
     processes[i].size = -1L;
-#endif
 
-#ifdef INODE_SWAP
-  process_avail =
-    ((long)(CORE_AVAIL - spare) << BLOCK_SHIFT) +
-    ((long)fs_tab[0].s_tfree << DISK_BLOCK_SHIFT);
-#ifdef PREALLOCATE_CORE
-  core_table_avail = (long)core_table.avail << BLOCK_SHIFT;
-  if (process_avail > core_table_avail)
-    process_avail = core_table_avail;
-#endif
- //printf("process_avail %ld\n", process_avail);
-#else
-  process_avail = CORE_AVAIL + SWAP_AVAIL - spare;
-#ifdef PREALLOCATE_CORE
+#ifndef INDIRECT_CORE
+#ifndef INDIRECT_SWAP
+  process_avail = core_table.avail + swap_table.avail - spare;
+#else /* INDIRECT_SWAP */
+  process_avail = core_table.avail + swap_block_pool.avail - spare;
+#endif /* INDIRECT_SWAP */
+#else /* INDIRECT_CORE */
+#ifndef INDIRECT_SWAP
+  process_avail = core_block_pool.avail + swap_table.avail - spare;
+#else /* INDIRECT_SWAP */
+  process_avail = core_block_pool.avail + swap_block_pool.avail - spare;
+#endif /* INDIRECT_SWAP */
   if (process_avail > core_table.avail)
     process_avail = core_table.avail;
-#endif
-#ifdef PREALLOCATE_SWAP
+#endif /* INDIRECT_CORE */
   if (process_avail > swap_table.avail)
     process_avail = swap_table.avail;
-#endif
  //printf("process_avail %d\n", process_avail);
-#endif
 
   lru_head.prev = &lru_head;
   lru_head.next = &lru_head;
@@ -112,122 +51,82 @@ void process_init(int n, int spare) {
 }
 
 static bool do_swap_out(int swap_out) {
-#ifndef PREALLOCATE_CORE
+#ifndef INDIRECT_CORE
   int victim_core_blocks;
-#endif
-#ifndef PREALLOCATE_SWAP
-  int victim_swap_blocks;
-#endif
-#ifdef INODE_SWAP
-  int blocks, core_base;
-#else
+#endif /* ! INDIRECT_CORE */
   int blocks, swap_base, core_base;
-#endif
   long size;
-#ifdef INODE_SWAP
-#ifdef INDIRECT_CORE
-  int i, j, core_block;
-#endif
-#elif defined(INDIRECT_CORE) || defined(INDIRECT_SWAP)
+#ifndef INDIRECT_CORE
+#ifdef INDIRECT_SWAP
+  int i, j, core_block, swap_block;
+#endif /* INDIRECT_SWAP */
+#else /* INDIRECT_CORE */
   int i, j, core_block, swap_block;
-#endif
+#endif /* INDIRECT_CORE */
 
   // loop entry code for the case of an existing victim
   if (swap_out > 0) {
     if (victim) {
       // calculate amount to swap out
-#if !defined(PREALLOCATE_SWAP) || defined(INDIRECT_SWAP)
-#ifdef INODE_SWAP
-      blocks = (int)(estimate_free(/*1*/) >> BLOCK_SHIFT);
-#else
-      blocks = SWAP_AVAIL;
-#endif
+#ifndef INDIRECT_CORE
+#ifdef INDIRECT_SWAP
+      blocks = swap_block_pool.avail;
       if (blocks == 0)
         return false;
       if (blocks > swap_out)
         blocks = swap_out;
-#endif
-#ifndef PREALLOCATE_CORE
+#endif /* INDIRECT_SWAP */
       victim_core_blocks =
         victim->core_item.limit - victim->core_item.base;
-#endif
-#if defined(PREALLOCATE_SWAP) && !defined(INDIRECT_SWAP)
+#ifndef INDIRECT_SWAP
       blocks = swap_out < victim_core_blocks ? swap_out : victim_core_blocks;
-#else
+#else /* INDIRECT_SWAP */
       if (blocks > victim_core_blocks)
         blocks = victim_core_blocks;
-#endif
+#endif /* INDIRECT_SWAP */
+#else /* INDIRECT_CORE */
+#ifndef INDIRECT_SWAP
+      blocks = swap_out < victim_core_blocks ? swap_out : victim_core_blocks;
+#else /* INDIRECT_SWAP */
+      blocks = swap_block_pool.avail;
+      if (blocks == 0)
+        return false;
+      if (blocks > swap_out)
+        blocks = swap_out;
+      if (blocks > victim_core_blocks)
+        blocks = victim_core_blocks;
+#endif /* INDIRECT_SWAP */
+#endif /* INDIRECT_CORE */
  //printf("existing victim %d, swap out %d of %d\n", (int)(victim - processes), blocks, victim_core_blocks);
 
       // increase swap allocation
-#ifndef PREALLOCATE_SWAP
-      victim_swap_blocks =
-#ifdef INODE_SWAP
-        (int)(victim->swap_inode->c_node.i_size >> BLOCK_SHIFT);
-#else
-        victim->swap_item.limit - victim->swap_item.base;
-#endif
-#endif
-#if !defined(INODE_SWAP) && !defined(PREALLOCATE_SWAP)
-      rassert(
-        pool_alloc(
-          &swap_table,
-          &victim->swap_item,
-          victim_swap_blocks + blocks,
-#ifdef MOVEABLE_SWAP
-          POOL_ALLOC_MODE_MOVEABLE |
-            POOL_ALLOC_MODE_REALLOC
-#else
-          POOL_ALLOC_MODE_REALLOC
-#endif
-        )
-      );
-#endif
       goto loop_entry;
     }
 
     // loop for the case of no existing victim
     do {
       // calculate amount to swap out
-#if !defined(PREALLOCATE_SWAP) || defined(INDIRECT_SWAP)
-#ifdef INODE_SWAP
-      blocks = (int)(estimate_free(/*1*/) >> BLOCK_SHIFT);
-#else
-      blocks = SWAP_AVAIL;
-#endif
+#ifdef INDIRECT_SWAP
+      blocks = swap_block_pool.avail;
       if (blocks == 0)
         return false;
       if (blocks > swap_out)
         blocks = swap_out;
-#endif
+#endif /* INDIRECT_SWAP */
       assert(lru_head.prev != &lru_head);
       victim = (struct process *)lru_head.prev;
       victim_core_blocks =
         victim->core_item.limit - victim->core_item.base;
-#if defined(PREALLOCATE_SWAP) && !defined(INDIRECT_SWAP)
+#ifndef INDIRECT_SWAP
       blocks = swap_out < victim_core_blocks ? swap_out : victim_core_blocks;
-#else
+#else /* INDIRECT_SWAP */
       if (blocks > victim_core_blocks)
         blocks = victim_core_blocks;
-#endif
+#endif /* INDIRECT_SWAP */
  //printf("new victim %d, swap out %d of %d\n", (int)(victim - processes), blocks, victim_core_blocks);
 
       // add to swap pool
       victim_swap_blocks = 0;
-#if !defined(INODE_SWAP) && !defined(PREALLOCATE_SWAP)
-      rassert(
-        pool_alloc(
-          &swap_table,
-          &victim->swap_item,
-          blocks,
-#ifdef MOVEABLE_SWAP
-          POOL_ALLOC_MODE_MOVEABLE
-#else
-          0
-#endif
-        )
-      );
-#endif
 
       // remove from LRU list
       victim->lru_item.prev->next = victim->lru_item.next;
@@ -236,18 +135,12 @@ static bool do_swap_out(int swap_out) {
 
     loop_entry:
       // calculate transfer parameters
-#ifndef INODE_SWAP
-#ifdef PREALLOCATE_SWAP
       swap_base = victim->swap_item.base + victim_swap_blocks;
-#else
-      swap_base = victim->swap_item.limit - blocks;
-#endif
-#endif
-#ifdef PREALLOCATE_CORE
-      core_base = victim->core_item.base + victim_swap_blocks;
-#else
+#ifndef INDIRECT_CORE
       core_base = victim->core_item.base;
-#endif
+#else /* INDIRECT_CORE */
+      core_base = victim->core_item.base + victim_swap_blocks;
+#endif /* INDIRECT_CORE */
       size = (long)blocks << BLOCK_SHIFT;
 
       // see if last transfer for victim
@@ -257,106 +150,97 @@ static bool do_swap_out(int swap_out) {
         size += ((victim->size - 1L) | -BLOCK_SIZE) + 1L;
 
       // transfer data to swap
-#ifdef INDIRECT_SWAP
-      rassert(
-        block_pool_alloc(&swap_block_pool, swap_table_mem + swap_base, blocks)
-      );
-#endif
-#ifdef INODE_SWAP
- //printf("write core [%d,%d) to swap [%d,%d)\n", core_base, core_base + blocks, victim_swap_blocks, victim_swap_blocks + blocks);
-#else
+#ifndef INDIRECT_CORE
+#ifndef INDIRECT_SWAP
  //printf("write core [%d,%d) to swap [%d,%d)\n", core_base, core_base + blocks, swap_base, swap_base + blocks);
-#endif
-#if !defined(INDIRECT_CORE) && !defined(INDIRECT_SWAP)
-#ifdef INODE_SWAP
-      swap_write(
-        victim->swap_inode,
-        (long)victim_swap_blocks << BLOCK_SHIFT,
-        (long)core_base << BLOCK_SHIFT,
-        size
-      );
-#else
       core_to_swap_copy(
         (long)core_base << BLOCK_SHIFT,
         (long)swap_base << BLOCK_SHIFT,
         size
+#else /* INDIRECT_SWAP */
+      rassert(
+        block_pool_alloc(&swap_block_pool, swap_table_mem + swap_base, blocks)
+#endif /* INDIRECT_SWAP */
       );
-#endif
-#else
+#ifdef INDIRECT_SWAP
+ //printf("write core [%d,%d) to swap [%d,%d)\n", core_base, core_base + blocks, swap_base, swap_base + blocks);
       j = (int)(size >> BLOCK_SHIFT);
  //printf("blocks");
       for (i = 0; i < j; ++i) {
         core_block = core_base + i;
-#ifdef INDIRECT_CORE
-        core_block = core_table_mem[core_block];
- //printf(" %d", core_block);
-#endif
-#ifdef INODE_SWAP
-        swap_write(
-          victim->swap_inode,
-          (long)(victim_swap_blocks + i) << BLOCK_SHIFT,
+        swap_block = swap_base + i;
+        swap_block = swap_table_mem[swap_block];
+ //printf(" %d", swap_block);
+        core_to_swap_copy(
           (long)core_block << BLOCK_SHIFT,
+          (long)swap_block << BLOCK_SHIFT,
           BLOCK_SIZE
         );
-#else
+      }
+      j = (int)size & (BLOCK_SIZE - 1);
+      if (j) {
+        core_block = core_base + i;
+        swap_block = swap_base + i;
+        swap_block = swap_table_mem[swap_block];
+ //printf(" %d", swap_block);
+ //putchar('*');
+        core_to_swap_copy(
+          (long)core_block << BLOCK_SHIFT,
+          (long)swap_block << BLOCK_SHIFT,
+          j
+        );
+      }
+ //printf("\n");
+#endif /* INDIRECT_SWAP */
+#else /* INDIRECT_CORE */
+#ifdef INDIRECT_SWAP
+      rassert(
+        block_pool_alloc(&swap_block_pool, swap_table_mem + swap_base, blocks)
+      );
+#endif /* INDIRECT_SWAP */
+ //printf("write core [%d,%d) to swap [%d,%d)\n", core_base, core_base + blocks, swap_base, swap_base + blocks);
+      j = (int)(size >> BLOCK_SHIFT);
+ //printf("blocks");
+      for (i = 0; i < j; ++i) {
+        core_block = core_base + i;
+        core_block = core_table_mem[core_block];
+ //printf(" %d", core_block);
         swap_block = swap_base + i;
 #ifdef INDIRECT_SWAP
         swap_block = swap_table_mem[swap_block];
-#ifdef INDIRECT_CORE
  //printf(",%d", swap_block);
-#else
- //printf(" %d", swap_block);
-#endif
-#endif
+#endif /* INDIRECT_SWAP */
         core_to_swap_copy(
           (long)core_block << BLOCK_SHIFT,
           (long)swap_block << BLOCK_SHIFT,
           BLOCK_SIZE
         );
-#endif
       }
       j = (int)size & (BLOCK_SIZE - 1);
       if (j) {
         core_block = core_base + i;
-#ifdef INDIRECT_CORE
         core_block = core_table_mem[core_block];
  //printf(" %d", core_block);
-#endif
-#ifdef INODE_SWAP
-        swap_write(
-          victim->swap_inode,
-          (long)(victim_swap_blocks + i) << BLOCK_SHIFT,
-          (long)core_block << BLOCK_SHIFT,
-          j
-        );
-#else
         swap_block = swap_base + i;
 #ifdef INDIRECT_SWAP
         swap_block = swap_table_mem[swap_block];
-#ifdef INDIRECT_CORE
  //printf(",%d", swap_block);
-#else
- //printf(" %d", swap_block);
-#endif
-#endif
+#endif /* INDIRECT_SWAP */
  //putchar('*');
         core_to_swap_copy(
           (long)core_block << BLOCK_SHIFT,
           (long)swap_block << BLOCK_SHIFT,
           j
         );
-#endif
       }
  //printf("\n");
-#endif
-#ifdef INDIRECT_CORE
       block_pool_free(&core_block_pool, core_table_mem + core_base, blocks);
-#endif
+#endif /* INDIRECT_CORE */
       victim_swap_blocks += blocks;
 
       // see if victim fully swapped out
       if (victim_core_blocks) {
-#ifndef PREALLOCATE_CORE
+#ifndef INDIRECT_CORE
         // no, reduce core allocation
         rassert(
           pool_alloc(
@@ -364,13 +248,11 @@ static bool do_swap_out(int swap_out) {
             &victim->core_item,
             victim_core_blocks,
             POOL_ALLOC_MODE_LAST_FIT |
-#ifdef MOVEABLE_CORE
               POOL_ALLOC_MODE_MOVEABLE |
-#endif
               POOL_ALLOC_MODE_REALLOC
           )
         );
-#endif
+#endif /* ! INDIRECT_CORE */
 
         // in this case there can't be any further victim to swap
         // report whether aborted due to swap space or user request
@@ -378,10 +260,10 @@ static bool do_swap_out(int swap_out) {
       }
  //printf("victimized %d\n", (int)(victim - processes));
 
-#ifndef PREALLOCATE_CORE
+#ifndef INDIRECT_CORE
       // remove from core pool
       pool_free(&core_table, &victim->core_item);
-#endif
+#endif /* ! INDIRECT_CORE */
       victim = NULL;
 
       swap_out -= blocks;
@@ -391,41 +273,14 @@ static bool do_swap_out(int swap_out) {
 }
 
 bool process_alloc(struct process *process, long size) {
-#ifdef INODE_SWAP
-  long estimated_size;
-  int i;
-#endif
   int blocks;
 
   // must not be already allocated
   assert(process->size == -1L);
 
   // check blocks
-#ifdef INODE_SWAP
-  estimated_size = estimate_size(size);
-  if (
-    process_avail < estimated_size ||
-    (process->swap_inode = i_open(0, 0)) == NULL
-  )
-    return false;
- //printf("open inode %d\n", process->swap_inode->c_num);
-
-  // initialize swap inode
-  process->swap_inode->c_node.i_uid = udata.u_euid;
-  process->swap_inode->c_node.i_gid = udata.u_egid;
-
-  process->swap_inode->c_node.i_mode = F_REG;   /* For the time being */
-  process->swap_inode->c_node.i_nlink = 0;
-  process->swap_inode->c_node.i_size = 0;
-  for (i = 0; i < 20; ++i)
-    process->swap_inode->c_node.i_addr[i] = 0;
-  wr_inode(process->swap_inode);
-
-  blocks = (int)((size + (BLOCK_SIZE - 1)) >> BLOCK_SHIFT);
-#else
   blocks = (int)((size + (BLOCK_SIZE - 1)) >> BLOCK_SHIFT);
   if (
-#if defined(PREALLOCATE_SWAP) && !defined(MOVEABLE_SWAP)
     process_avail < blocks ||
     !pool_alloc(
       &swap_table,
@@ -433,66 +288,47 @@ bool process_alloc(struct process *process, long size) {
       blocks,
       0
     )
-#else
-    process_avail < blocks
-#endif
   )
     return false;
-#endif
 
   // free up as much core as we need to
-  rassert(do_swap_out(blocks - CORE_AVAIL));
+#ifndef INDIRECT_CORE
+  rassert(do_swap_out(blocks - core_table.avail));
+#else /* INDIRECT_CORE */
+  rassert(do_swap_out(blocks - core_block_pool.avail));
+#endif /* INDIRECT_CORE */
 
   // allocate core and possible swap
-#ifdef MOVEABLE_CORE
+#ifndef INDIRECT_CORE
   rassert(
     pool_alloc(
-      &core_table,
-      &process->core_item,
-      blocks,
-      POOL_ALLOC_MODE_MOVEABLE
-    )
-  );
-#else
+#else /* INDIRECT_CORE */
   if (
     !pool_alloc(
+#endif /* INDIRECT_CORE */
       &core_table,
       &process->core_item,
       blocks,
+#ifndef INDIRECT_CORE
+      POOL_ALLOC_MODE_MOVEABLE
+#else /* INDIRECT_CORE */
       0
     )
   ) {
-#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)
     pool_free(&swap_table, &process->swap_item);
-#endif
     return false;
   }
-#endif
-#if defined(PREALLOCATE_SWAP) && defined(MOVEABLE_SWAP)
-  rassert(
-    pool_alloc(
-      &swap_table,
-      &process->swap_item,
-      blocks,
-      POOL_ALLOC_MODE_MOVEABLE
-    )
-  );
-#endif
 
-#ifdef INDIRECT_CORE
   // populate new table with physical blocks
   rassert(
     block_pool_alloc(
       &core_block_pool,
       core_table_mem + process->core_item.base,
       blocks
+#endif /* INDIRECT_CORE */
     )
   );
-#endif
+
   // insert at head of LRU list
   process->lru_item.prev = &lru_head;
   process->lru_item.next = lru_head.next;
@@ -501,18 +337,11 @@ bool process_alloc(struct process *process, long size) {
 
   // track total allocation
   process->size = size;
-#ifdef INODE_SWAP
-  process_avail -= estimated_size;
-#else
   process_avail -= blocks;
-#endif
   return true;
 }
 
 bool process_realloc(struct process *process, long size) {
-#ifdef INODE_SWAP
-  long estimated_size, old_estimated_size, estimated_size_change;
-#endif
   int blocks, old_blocks, blocks_change;
 
   // must be already allocated
@@ -522,25 +351,12 @@ bool process_realloc(struct process *process, long size) {
   assert(process->lru_item.prev != NULL);
 
   // check blocks
-#ifdef INODE_SWAP
-  estimated_size = estimate_size(size);
-  old_estimated_size = estimate_size(process->size);
-  estimated_size_change = estimated_size - old_estimated_size;
-  if (process_avail < estimated_size_change)
-    return false;
-
-  blocks = (int)((size + (BLOCK_SIZE - 1)) >> BLOCK_SHIFT);
-  old_blocks = (int)((process->size + (BLOCK_SIZE - 1)) >> BLOCK_SHIFT);
-  blocks_change = blocks - old_blocks;
-#else 
   blocks = (int)((size + (BLOCK_SIZE - 1)) >> BLOCK_SHIFT);
   old_blocks = (int)((process->size + (BLOCK_SIZE - 1)) >> BLOCK_SHIFT);
   blocks_change = blocks - old_blocks;
   if (process_avail < blocks_change)
     return false;
-#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);
@@ -562,32 +378,36 @@ bool process_realloc(struct process *process, long size) {
     );
     return false;
   }
-#endif
 
   // free up as much core as we need to
-  rassert(do_swap_out(blocks_change - CORE_AVAIL));
+#ifndef INDIRECT_CORE
+  rassert(do_swap_out(blocks_change - core_table.avail));
+#else /* INDIRECT_CORE */
+  rassert(do_swap_out(blocks_change - core_block_pool.avail));
+#endif /* INDIRECT_CORE */
 
   // reallocate core and possible swap
-#ifdef MOVEABLE_CORE
+#ifndef INDIRECT_CORE
   rassert(
     pool_alloc(
-      &core_table,
-      &process->core_item,
-      blocks,
-      POOL_ALLOC_MODE_MOVEABLE |
-        POOL_ALLOC_MODE_REALLOC
-    )
-  );
-#else
+#else /* INDIRECT_CORE */
   if (
     !pool_alloc(
+#endif /* INDIRECT_CORE */
       &core_table,
       &process->core_item,
       blocks,
+#ifndef INDIRECT_CORE
+      POOL_ALLOC_MODE_MOVEABLE |
+        POOL_ALLOC_MODE_REALLOC
+#else /* INDIRECT_CORE */
       POOL_ALLOC_MODE_REALLOC
+#endif /* INDIRECT_CORE */
     )
+#ifndef INDIRECT_CORE
+  );
+#else /* INDIRECT_CORE */
   ) {
-#if defined(PREALLOCATE_SWAP) && !defined(MOVEABLE_SWAP)
     pool_free(&swap_table, &process->swap_item);
     rassert(
       pool_alloc(
@@ -597,23 +417,9 @@ bool process_realloc(struct process *process, long size) {
         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,
-      POOL_ALLOC_MOVEABLE
-    )
-  );
-#endif
 
-#ifdef INDIRECT_CORE
   // populate new table with physical blocks or discard them
   if (blocks_change >= 0)
     rassert(
@@ -629,29 +435,25 @@ bool process_realloc(struct process *process, long size) {
       core_table_mem + process->core_item.limit,
       -blocks_change
     );
-#endif
+#endif /* INDIRECT_CORE */
+
   // track total allocation
   process->size = size;
-#ifdef INODE_SWAP
-  process_avail -= estimated_size_change;
-#else
   process_avail -= blocks_change;
-#endif
   return true;
 }
 
 void process_run(struct process *process) {
   int blocks, process_core_blocks, process_swap_blocks;
-#ifdef INODE_SWAP
-  int core_base;
-#else
   int swap_base, core_base;
-#endif
   long size;
-#if defined(INDIRECT_CORE) || defined(INDIRECT_SWAP)
+#ifndef INDIRECT_CORE
+#ifdef INDIRECT_SWAP
+  int i, j;
+#endif /* INDIRECT_SWAP */
+#else /* INDIRECT_CORE */
   int i, j;
-#endif
+#endif /* INDIRECT_CORE */
 
   // must be already allocated
   assert(process->size != -1L);
@@ -670,124 +472,80 @@ void process_run(struct process *process) {
     if (process != victim) {
       // fully in swap, only the swap item is meaningful
       process_swap_blocks =
-#ifdef INODE_SWAP
-        (int)(
-          ((long)process->swap_inode->c_node.i_size + (BLOCK_SIZE - 1)) >>
-          BLOCK_SHIFT
-        );
-#else
         process->swap_item.limit - process->swap_item.base;
-#endif
 
       // free up as much core as we can
-      do_swap_out(process_swap_blocks - CORE_AVAIL);
-      blocks = CORE_AVAIL;
+#ifndef INDIRECT_CORE
+      do_swap_out(process_swap_blocks - core_table.avail);
+      blocks = core_table.avail;
+#else /* INDIRECT_CORE */
+      do_swap_out(process_swap_blocks - core_block_pool.avail);
+      blocks = core_block_pool.avail;
+#endif /* INDIRECT_CORE */
       if (blocks > process_swap_blocks)
         blocks = process_swap_blocks;
 
       // add to core pool
       process_core_blocks = 0;
-#ifndef PREALLOCATE_CORE
+#ifndef INDIRECT_CORE
       rassert(
         pool_alloc(
           &core_table,
           &process->core_item,
           blocks,
-#ifdef MOVEABLE_CORE
           POOL_ALLOC_MODE_MOVEABLE
-#else
-          0
-#endif
         )
       );
-#endif
+#endif /* ! INDIRECT_CORE */
       goto loop_entry_full;
     }
 
     // victim, take over the dedicated pool items
-#ifdef PREALLOCATE_CORE
-    process_core_blocks = victim_core_blocks;
-#else
+#ifndef INDIRECT_CORE
     process_core_blocks =
       victim->core_item.limit - victim->core_item.base;
-#endif
-#ifdef PREALLOCATE_SWAP
+#else /* INDIRECT_CORE */
+    process_core_blocks = victim_core_blocks;
+#endif /* INDIRECT_CORE */
     process_swap_blocks = victim_swap_blocks;
-#else
-    process_swap_blocks =
-#ifdef INODE_SWAP
-      (int)(victim->swap_inode->c_node.i_size >> BLOCK_SHIFT);
-#else
-      victim->swap_item.limit - victim->swap_item.base;
-#endif
-#endif
     victim = NULL;
-#ifndef PREALLOCATE_SWAP
-    goto loop_entry_partial;
-#endif
 
     // loop for case of partially in core, partially in swap
     do {
-#ifndef PREALLOCATE_SWAP
-      // reduce swap allocation
-#ifdef INODE_SWAP
-      udata.u_offset = (long)process_swap_blocks << BLOCK_SHIFT;
-      f_trunc(process->swap_inode);
-#else
-      rassert(
-        pool_alloc(
-          &swap_table,
-          &process->swap_item,
-          process_swap_blocks,
-#ifdef MOVEABLE_SWAP
-          POOL_ALLOC_MODE_MOVEABLE |
-            POOL_ALLOC_MODE_REALLOC
-#else
-          POOL_ALLOC_MODE_REALLOC
-#endif
-        )
-      );
-#endif
-
-    loop_entry_partial:
-#endif
       // free up as much core as we can
-      do_swap_out(process_swap_blocks - CORE_AVAIL);
-      blocks = CORE_AVAIL;
+#ifndef INDIRECT_CORE
+      do_swap_out(process_swap_blocks - core_table.avail);
+      blocks = core_table.avail;
+#else /* INDIRECT_CORE */
+      do_swap_out(process_swap_blocks - core_block_pool.avail);
+      blocks = core_block_pool.avail;
+#endif /* INDIRECT_CORE */
       if (blocks > process_swap_blocks)
         blocks = process_swap_blocks;
 
       // increase core allocation
-#ifndef PREALLOCATE_CORE
+#ifndef INDIRECT_CORE
       rassert(
         pool_alloc(
-          &core_table, 
+          &core_table,
           &process->core_item,
           process_core_blocks + blocks,
           POOL_ALLOC_MODE_LAST_FIT |
-#ifdef MOVEABLE_CORE
             POOL_ALLOC_MODE_MOVEABLE |
-#endif
             POOL_ALLOC_MODE_REALLOC
         )
       );
-#endif
+#endif /* ! INDIRECT_CORE */
 
     loop_entry_full:
       // calculate transfer parameters
       process_swap_blocks -= blocks;
-#ifndef INODE_SWAP
-#ifdef PREALLOCATE_SWAP
       swap_base = process->swap_item.base + process_swap_blocks;
-#else
-      swap_base = process->swap_item.limit - blocks;
-#endif
-#endif
-#ifdef PREALLOCATE_CORE
-      core_base = process->core_item.base + process_swap_blocks;
-#else
+#ifndef INDIRECT_CORE
       core_base = process->core_item.base;
-#endif
+#else /* INDIRECT_CORE */
+      core_base = process->core_item.base + process_swap_blocks;
+#endif /* INDIRECT_CORE */
 
       size = (long)blocks << BLOCK_SHIFT;
 
@@ -800,106 +558,84 @@ void process_run(struct process *process) {
       // transfer data to core
 #ifdef INDIRECT_CORE
       block_pool_alloc(&core_block_pool, core_table_mem + core_base, blocks);
-#endif
-#ifdef INODE_SWAP
- //printf("read swap [%d,%d) to core [%d,%d)\n", process_swap_blocks, process_swap_blocks + blocks, core_base, core_base + blocks);
-#else
+#endif /* INDIRECT_CORE */
  //printf("read swap [%d,%d) to core [%d,%d)\n", swap_base, swap_base + blocks, core_base, core_base + blocks);
-#endif
-#if !defined(INDIRECT_CORE) && !defined(INDIRECT_SWAP)
-#ifdef INODE_SWAP
-      swap_read(
-        process->swap_inode,
-        (long)process_swap_blocks << BLOCK_SHIFT,
-        (long)core_base << BLOCK_SHIFT,
-        size
-      );
-#else
+#ifndef INDIRECT_CORE
+#ifndef INDIRECT_SWAP
       swap_to_core_copy(
         (long)swap_base << BLOCK_SHIFT,
         (long)core_base << BLOCK_SHIFT,
         size
       );
-#endif
-#else
+#else /* INDIRECT_SWAP */
       j = (int)(size >> BLOCK_SHIFT);
  //printf("blocks");
       for (i = 0; i < j; ++i) {
         int core_block = core_base + i;
-#ifdef INDIRECT_CORE
-        core_block = core_table_mem[core_block];
- //printf(" %d", core_block);
-#endif
-#ifdef INODE_SWAP
-        swap_read(
-          process->swap_inode,
-          (long)(process_swap_blocks + i) << BLOCK_SHIFT,
+        int swap_block = swap_base + i;
+        swap_block = swap_table_mem[swap_block];
+ //printf(",%d", swap_block);
+        swap_to_core_copy(
+          (long)swap_block << BLOCK_SHIFT,
           (long)core_block << BLOCK_SHIFT,
           BLOCK_SIZE
         );
-#else
+      }
+      j = (int)size & (BLOCK_SIZE - 1);
+      if (j) {
+        int core_block = core_base + i;
         int swap_block = swap_base + i;
-#ifdef INDIRECT_SWAP
         swap_block = swap_table_mem[swap_block];
+ //printf(",%d", swap_block);
+        swap_to_core_copy(
+          (long)swap_block << BLOCK_SHIFT,
+          (long)core_block << BLOCK_SHIFT,
+          j
+        );
+      }
+ //printf("\n");
+      block_pool_free(&swap_block_pool, swap_table_mem + swap_base, blocks);
+#endif /* INDIRECT_SWAP */
+#else /* INDIRECT_CORE */
+      j = (int)(size >> BLOCK_SHIFT);
+ //printf("blocks");
+      for (i = 0; i < j; ++i) {
+        int core_block = core_base + i;
+        core_block = core_table_mem[core_block];
+ //printf(" %d", core_block);
+        int swap_block = swap_base + i;
 #ifdef INDIRECT_SWAP
+        swap_block = swap_table_mem[swap_block];
  //printf(",%d", swap_block);
-#else
- //printf(" %d", swap_block);
-#endif
-#endif
+#endif /* INDIRECT_SWAP */
         swap_to_core_copy(
           (long)swap_block << BLOCK_SHIFT,
           (long)core_block << BLOCK_SHIFT,
           BLOCK_SIZE
         );
-#endif
       }
       j = (int)size & (BLOCK_SIZE - 1);
       if (j) {
         int core_block = core_base + i;
-#ifdef INDIRECT_CORE
         core_block = core_table_mem[core_block];
  //printf(" %d", core_block);
-#endif
-#ifdef INODE_SWAP
-        swap_read(
-          process->swap_inode,
-          (long)(process_swap_blocks + i) << BLOCK_SHIFT,
-          (long)core_block << BLOCK_SHIFT,
-          j
-        );
-#else
         int swap_block = swap_base + i;
 #ifdef INDIRECT_SWAP
         swap_block = swap_table_mem[swap_block];
-#ifdef INDIRECT_SWAP
  //printf(",%d", swap_block);
-#else
- //printf(" %d", swap_block);
-#endif
-#endif
+#endif /* INDIRECT_SWAP */
         swap_to_core_copy(
           (long)swap_block << BLOCK_SHIFT,
           (long)core_block << BLOCK_SHIFT,
-          j 
+          j
         );
-#endif
       }
  //printf("\n");
-#endif
 #ifdef INDIRECT_SWAP
       block_pool_free(&swap_block_pool, swap_table_mem + swap_base, blocks);
-#endif
+#endif /* INDIRECT_SWAP */
+#endif /* INDIRECT_CORE */
     } while (process_swap_blocks);
-
-#ifdef INODE_SWAP
-    // delete swap data, retain swap inode
-    udata.u_offset = 0;
-    f_trunc(process->swap_inode);
-#elif !defined(PREALLOCATE_SWAP)
-    // remove from swap pool
-    pool_free(&swap_table, &process->swap_item);
-#endif
   }
 
   // insert at head of LRU list
@@ -910,18 +646,17 @@ void process_run(struct process *process) {
 }
 
 void process_free(struct process *process) {
+#ifndef INDIRECT_CORE
 #ifdef INDIRECT_SWAP
   int swap_base;
-#ifndef PREALLOCATE_SWAP
-  int victim_swap_blocks;
-#endif
-#endif
-#ifdef INDIRECT_CORE
+#endif /* INDIRECT_SWAP */
+#else /* INDIRECT_CORE */
+
+#ifdef INDIRECT_SWAP
+  int swap_base;
+#endif /* INDIRECT_SWAP */
   int core_base;
-#ifndef PREALLOCATE_CORE
-  int victim_core_blocks;
-#endif
-#endif
+#endif /* INDIRECT_CORE */
 
   // must be already allocated
   assert(process->size != -1L);
@@ -934,61 +669,37 @@ void process_free(struct process *process) {
     process->lru_item.prev->next = process->lru_item.next;
     process->lru_item.next->prev = process->lru_item.prev;
 
-#ifdef INDIRECT_CORE
+#ifndef INDIRECT_CORE
+    pool_free(&core_table, &process->core_item);
+#else /* INDIRECT_CORE */
     int core_base = process->core_item.base;
     block_pool_free(
       &core_block_pool,
       core_table_mem + core_base,
       process->core_item.limit - core_base
     );
-#endif
-#ifndef PREALLOCATE_CORE
-    pool_free(&core_table, &process->core_item);
-#endif
+#endif /* INDIRECT_CORE */
   }
   else if (process == victim) {
     // victim, remove from core and swap pools
 #ifdef INDIRECT_SWAP
     swap_base = victim->swap_item.base;
-#ifndef PREALLOCATE_SWAP
-    victim_swap_blocks = victim->swap_item.limit - swap_base;
-#endif
     block_pool_free(
       &swap_block_pool,
       swap_table_mem + swap_base,
       victim_swap_blocks
     );
-#endif
-#if !defined(INODE_SWAP) && !defined(PREALLOCATE_SWAP)
-    pool_free(&swap_table, &victim->swap_item);
-#endif
-#ifdef INDIRECT_CORE
-#ifdef PREALLOCATE_CORE
-#if defined(PREALLOCATE_SWAP) || defined(INDIRECT_SWAP)
+#endif /* INDIRECT_SWAP */
+#ifndef INDIRECT_CORE
+    pool_free(&core_table, &victim->core_item);
+#else /* INDIRECT_CORE */
     core_base = victim->core_item.base + victim_swap_blocks;
-#elif defined(INODE_SWAP)
-    core_base =
-      victim->core_item.base +
-      (int)(victim->swap_inode->c_node.i_size >> BLOCK_SHIFT);
-#else
-    core_base =
-      victim->core_item.base +
-      victim->swap_item.limit -
-      victim->swap_item.base;
-#endif
-#else
-    core_base = victim->core_item.base;
-    victim_core_blocks = victim->core_item.limit - core_base;
-#endif
     block_pool_free(
       &core_block_pool,
       core_table_mem + core_base,
       victim_core_blocks
     );
-#endif
-#ifndef PREALLOCATE_CORE
-    pool_free(&core_table, &victim->core_item);
-#endif
+#endif /* INDIRECT_CORE */
     victim = NULL;
   }
   else {
@@ -1000,30 +711,16 @@ void process_free(struct process *process) {
       swap_table_mem + swap_base,
       process->swap_item.limit - swap_base
     );
-#endif
-#if !defined(INODE_SWAP) && !defined(PREALLOCATE_SWAP)
-    pool_free(&swap_table, &process->swap_item);
-#endif
+#endif /* INDIRECT_SWAP */
   }
 
   // free the per-process table entries
-#ifdef PREALLOCATE_CORE
+#ifdef INDIRECT_CORE
   pool_free(&core_table, &process->core_item);
-#endif
-#ifdef PREALLOCATE_SWAP
+#endif /* INDIRECT_CORE */
   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);
-#endif
+
   // track total allocation
-#ifdef INODE_SWAP
-  process_avail += estimate_size(process->size);
-#else
   process_avail += (int)((process->size + (BLOCK_SIZE - 1)) >> BLOCK_SHIFT);
-#endif
-#ifndef NDEBUG
   process->size = -1L;
-#endif
 }
index 2bdd0c2..6ac77f7 100644 (file)
--- a/process.h
+++ b/process.h
@@ -1,21 +1,8 @@
 #ifndef _PROCESS_H
 #define _PROCESS_H 1
 
-#ifdef __FUZIX__
-#define BLOCK_SIZE 0x10
-#define BLOCK_SHIFT 4
-#else
 #define BLOCK_SIZE 0x1000
 #define BLOCK_SHIFT 12
-#endif
-
-//#define INODE_SWAP 1
-#ifdef INODE_SWAP
-#define DISK_BLOCK_SIZE 0x200
-#define DISK_BLOCK_SHIFT 9
-#define DISK_INDIRECT_SIZE 0x100
-#define DISK_INDIRECT_SHIFT 8
-#endif
 
 #include "pool.h"
 
@@ -27,20 +14,12 @@ struct lru_item {
 extern struct process {
   struct lru_item lru_item; // must be first
   struct pool_item core_item;
-#ifdef INODE_SWAP
-  struct cinode *swap_inode;
-#else
   struct pool_item swap_item;
-#endif
   long size; // brk level
 } *processes;
 int n_processes;
 
-#ifdef INODE_SWAP
-extern long process_avail;
-#else
 extern int process_avail;
-#endif
 
 extern struct lru_item lru_head;
 
@@ -51,24 +30,9 @@ bool process_alloc(struct process *process, long size);
 bool process_realloc(struct process *process, long size);
 void process_run(struct process *process);
 void process_free(struct process *process);
+
 // abstract
-#ifdef INODE_SWAP
-void swap_read(
-  struct cinode *inode,
-  long offset,
-  long core_base,
-  long size
-);
-void swap_write(
-  struct cinode *inode,
-  long offset,
-  long core_base,
-  long size
-);
-#else
 void core_to_swap_copy(long src_base, long dest_base, long size);
 void swap_to_core_copy(long src_base, long dest_base, long size);
-#endif
 
 #endif
index 5adbfd1..0f62080 100644 (file)
@@ -3,11 +3,6 @@
 
 #include <stdbool.h>
 
-#define PROCESS_TEST_TYPE_ALLOC 0
-#define PROCESS_TEST_TYPE_REALLOC 1
-#define PROCESS_TEST_TYPE_RUN 2
-#define PROCESS_TEST_TYPE_FREE 3
-
 struct process_test {
   int type;
   int process;
index ea3baaa..9b04ed7 100644 (file)
@@ -2,19 +2,11 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#ifdef __FUZIX__
-#include <unistd.h>
-#endif
 #include "process_test.h"
 #include "rassert.h"
 
-#ifdef __FUZIX__
-#define BLOCK_SIZE 0x10
-#define BLOCK_SHIFT 4
-#else
 #define BLOCK_SIZE 0x1000
 #define BLOCK_SHIFT 12
-#endif
 
 int rand_int(int n) {
   return (int)((long long)rand() * n / (RAND_MAX + 1LL));
@@ -45,9 +37,6 @@ int main(int argc, char **argv) {
   int pool_used = 0;
   for (int i = 0; i < n_events; ++i) {
     struct process_test test;
-#ifdef __FUZIX__
-    memset(&test, 0, sizeof(test));
-#endif
 
     test.process = rand_int(n_processes);
     test.old_size = processes[test.process];
@@ -56,17 +45,12 @@ int main(int argc, char **argv) {
       int blocks = (int)((test.size + (BLOCK_SIZE - 1)) >> BLOCK_SHIFT);
       test.success = pool_used + blocks <= pool_blocks;
 
-#ifdef __FUZIX__
-      test.type = PROCESS_TEST_TYPE_ALLOC;
-      write(1, &test, sizeof(test));
-#else
       printf(
         "alloc %d %ld %s\n",
         test.process,
         test.size,
         test.success ? "true" : "false"
       );
-#endif
 
       if (test.success) {
         processes[test.process] = test.size;
@@ -76,22 +60,13 @@ int main(int argc, char **argv) {
     else {
       int old_blocks = (int)((test.old_size + (BLOCK_SIZE - 1)) >> BLOCK_SHIFT);
       if (rand_int(64)) {
-#ifdef __FUZIX__
-        test.type = PROCESS_TEST_TYPE_RUN;
-        write(1, &test, sizeof(test));
-#else
         printf("run %d\n", test.process);
-#endif
 
         if (rand_int(8) == 0) {
           test.size = rand_long(process_size + 1);
           int blocks = (int)((test.size + (BLOCK_SIZE - 1)) >> BLOCK_SHIFT);
           test.success = pool_used + blocks - old_blocks <= pool_blocks;
 
-#ifdef __FUZIX__
-          test.type = PROCESS_TEST_TYPE_REALLOC;
-          write(1, &test, sizeof(test));
-#else
           printf(
             "realloc %d %ld %ld %s\n",
             test.process,
@@ -99,7 +74,6 @@ int main(int argc, char **argv) {
             test.size,
             test.success ? "true" : "false"
           );
-#endif
 
           if (test.success) {
             processes[test.process] = test.size;
@@ -108,12 +82,7 @@ int main(int argc, char **argv) {
         }
       }
       else {
-#ifdef __FUZIX__
-        test.type = PROCESS_TEST_TYPE_FREE;
-        write(1, &test, sizeof(test));
-#else
         printf("free %d %ld\n", test.process, test.old_size);
-#endif
         processes[test.process] = -1;
         pool_used -= old_blocks;
       }
index 228261b..bff1c5f 100644 (file)
@@ -3,40 +3,21 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#ifdef __FUZIX__
-#include <unistd.h>
-#endif
 #include "core.h"
 #include "process.h"
 #include "process_test.h"
 #include "rassert.h"
 
-#ifdef INODE_SWAP
-#define UCP 1
-#include "fuzix_fs.h"
-#include "util.h"
-#else
 #include "swap.h"
-#endif
 
-#ifdef __FUZIX__
-#define TRANSFER_SIZE 0x400
-#else
 #define TRANSFER_SIZE 0x8000
-#endif
 
 uint8_t *core_block_mem;
-#ifndef INODE_SWAP
 uint8_t *swap_block_mem;
-#endif
 
 void core_hash_init(int process, long base, long size, long offset) {
   long i, addr;
-#ifdef __FUZIX__
-  int hash;
-#else 
   long long hash;
-#endif
 
  //printf("core_hash_init %d %ld(%d) %ld(%d) %ld(%d)\n", process, base, (int)(base >> BLOCK_SHIFT), size, (int)((size + (BLOCK_SIZE - 1)) >> BLOCK_SHIFT), offset, (int)(offset >> BLOCK_SHIFT));
   for (i = 0L; i < size; ++i) {
@@ -45,16 +26,12 @@ void core_hash_init(int process, long base, long size, long offset) {
     addr =
       (core_table_mem[addr >> BLOCK_SHIFT] << BLOCK_SHIFT) |
       (addr & (BLOCK_SIZE - 1));
-#endif
-#ifdef __FUZIX__
-    hash = process * 17 + ((int)i + (int)offset) * 29;
-#else
+#endif /* INDIRECT_CORE */
     hash = process * 17 + (i + offset) * 29;
     hash = (hash & 0xffffffffLL) + (hash >> 32);
     hash = (hash & 0xffffLL) + (hash >> 16);
     hash = (hash & 0xffLL) + (hash >> 8);
     hash = (hash & 0xffLL) + (hash >> 8);
-#endif
     rassert(core_block_mem[addr] == 0xaa);
     core_block_mem[addr] = (uint8_t)hash;
   }
@@ -62,11 +39,7 @@ void core_hash_init(int process, long base, long size, long offset) {
 
 void core_hash_verify(int process, long base, long size, long offset) {
   long i, addr;
-#ifdef __FUZIX__
-  int hash;
-#else 
   long long hash;
-#endif
 
  //printf("core_hash_verify %d %ld(%d) %ld(%d) %ld(%d)\n", process, base, (int)(base >> BLOCK_SHIFT), size, (int)((size + (BLOCK_SIZE - 1)) >> BLOCK_SHIFT), offset, (int)(offset >> BLOCK_SHIFT));
   for (i = 0L; i < size; ++i) {
@@ -75,68 +48,20 @@ void core_hash_verify(int process, long base, long size, long offset) {
     addr =
       (core_table_mem[addr >> BLOCK_SHIFT] << BLOCK_SHIFT) |
       (addr & (BLOCK_SIZE - 1));
-#endif
-#ifdef __FUZIX__
-    hash = process * 17 + ((int)i + (int)offset) * 29;
-#else
+#endif /* INDIRECT_CORE */
     hash = process * 17 + (i + offset) * 29;
     hash = (hash & 0xffffffffLL) + (hash >> 32);
     hash = (hash & 0xffffLL) + (hash >> 16);
     hash = (hash & 0xffLL) + (hash >> 8);
     hash = (hash & 0xffLL) + (hash >> 8);
-#endif
     rassert(core_block_mem[addr] == (uint8_t)hash);
     core_block_mem[addr] = 0xaa;
   }
 }
 
-#ifdef INODE_SWAP
-void swap_hash_verify(int process, struct cinode *inode) {
-  long offset, count;
-  uint8_t buf[TRANSFER_SIZE];
-  long i;
-#ifdef __FUZIX__
-  int hash;
-#else 
-  long long hash;
-#endif
-
-  for (
-    offset = 0;
-    (count = (long)inode->c_node.i_size - offset) > 0;
-    offset += count
-  ) {
-    if (count > TRANSFER_SIZE)
-      count = TRANSFER_SIZE;
-
-    udata.u_base = (char *)buf;
-    udata.u_count = count;
-    udata.u_offset = offset;
-    udata.u_error = 0;
-    rassert(readi(inode) == count && udata.u_error == 0);
-
-    for (i = 0; i < count; ++i) {
-#ifdef __FUZIX__
-      hash = process * 17 + ((int)i + (int)offset) * 29;
-#else
-      hash = process * 17 + (i + offset) * 29;
-      hash = (hash & 0xffffffffLL) + (hash >> 32);
-      hash = (hash & 0xffffLL) + (hash >> 16);
-      hash = (hash & 0xffLL) + (hash >> 8);
-      hash = (hash & 0xffLL) + (hash >> 8);
-#endif
-      rassert(buf[i] == (uint8_t)hash);
-    }
-  }
-}
-#else
 void swap_hash_verify(int process, long base, long size) {
   long i, addr;
-#ifdef __FUZIX__
-  int hash;
-#else
   long long hash;
-#endif
 
  //printf("swap_hash_verify %d %ld(%d) %ld(%d)\n", process, base, (int)(base >> BLOCK_SHIFT), size, (int)((size + (BLOCK_SIZE - 1)) >> BLOCK_SHIFT));
   for (i = 0L; i < size; ++i) {
@@ -145,21 +70,16 @@ void swap_hash_verify(int process, long base, long size) {
     addr =
       (swap_table_mem[addr >> BLOCK_SHIFT] << BLOCK_SHIFT) |
       (addr & (BLOCK_SIZE - 1));
-#endif
-#ifdef __FUZIX__
-    hash = process * 17 + (int)i * 29;
-#else
+#endif /* INDIRECT_SWAP */
     hash = process * 17 + i * 29;
     hash = (hash & 0xffffffffLL) + (hash >> 32);
     hash = (hash & 0xffffLL) + (hash >> 16);
     hash = (hash & 0xffLL) + (hash >> 8);
     hash = (hash & 0xffLL) + (hash >> 8);
-#endif
     rassert(swap_block_mem[addr] == (uint8_t)hash);
     swap_block_mem[addr] = 0xaa;
   }
 }
-#endif
 
 #ifndef INDIRECT_CORE
 void core_copy(long src_base, long dest_base, long size) {
@@ -182,56 +102,8 @@ void core_copy_up(long src_limit, long dest_limit, long size) {
     core_block_mem[src_limit + i] = 0xaa;
   }
 }
-#endif
+#endif /* ! INDIRECT_CORE */
 
-#ifdef INODE_SWAP
-void swap_read(
-  struct cinode *inode,
-  long offset,
-  long core_base,
-  long size
-) {
-  long i, count;
-
- //printf("swap_read %d %ld %ld %ld\n", inode->c_num, offset, core_base, size);
-  for (i = 0; i < size; ++i)
-    rassert(core_block_mem[core_base + i] == 0xaa);
-
-  for (i = 0; (count = size - i) > 0; i += count) {
-    if (count > TRANSFER_SIZE)
-      count = TRANSFER_SIZE;
-    udata.u_base = (char *)(core_block_mem + core_base + i);
-    udata.u_count = (int)count;
-    udata.u_offset = (uint32_t)(offset + i);
-    udata.u_error = 0;
-    rassert(readi(inode) == (int)count && udata.u_error == 0);
-  }
-}
-
-void swap_write(
-  struct cinode *inode,
-  long offset,
-  long core_base,
-  long size
-) {
-  long i, count;
-
- //printf("swap_write %d %ld %ld %ld\n", inode->c_num, offset, core_base, size);
-  for (i = 0; (count = size - i) > 0; i += count) {
-    if (count > TRANSFER_SIZE)
-      count = TRANSFER_SIZE;
-    udata.u_base = (char *)(core_block_mem + core_base + i);
-    udata.u_count = (int)count;
-    udata.u_offset = (uint32_t)(offset + i);
-    udata.u_error = 0;
-    rassert(writei(inode) == (int)count && udata.u_error == 0);
-  }
-
-  memset(core_block_mem + core_base, 0xaa, size);
-}
-#else
 #ifndef INDIRECT_SWAP
 void swap_copy(long src_base, long dest_base, long size) {
   long i;
@@ -253,7 +125,7 @@ void swap_copy_up(long src_limit, long dest_limit, long size) {
     swap_block_mem[src_limit + i] = 0xaa;
   }
 }
-#endif
+#endif /* ! INDIRECT_SWAP */
 
 void core_to_swap_copy(long src_base, long dest_base, long size) {
   long i;
@@ -274,32 +146,28 @@ void swap_to_core_copy(long src_base, long dest_base, long size) {
   memcpy(core_block_mem + dest_base, swap_block_mem + src_base, size);
   memset(swap_block_mem + src_base, 0xaa, size);
 }
-#endif
 
 int main(int argc, char **argv) {
   int n_processes;
   int n_core_blocks;
-#ifdef INODE_SWAP
-  char *fs_path;
-#else
   int n_swap_blocks;
-#endif
   int spare;
-#ifdef INDIRECT_CORE
+#ifndef INDIRECT_CORE
+#ifndef INDIRECT_SWAP
+  int i, j;
+#else /* INDIRECT_SWAP */
+  int swap_table_blocks;
+  int i, j, k;
+#endif /* INDIRECT_SWAP */
+#else /* INDIRECT_CORE */
   int core_table_blocks;
-#endif
 #ifdef INDIRECT_SWAP
   int swap_table_blocks;
-#endif
-#if defined(INDIRECT_CORE) || defined(INDIRECT_SWAP)
+#endif /* INDIRECT_SWAP */
   int i, j, k;
-#else
-  int i, j;
-#endif
+#endif /* INDIRECT_CORE */
   struct process_test test;
-#ifndef __FUZIX__
   char buf[256];
-#endif
   bool result;
   long actual_old_size;
   int old_blocks, blocks, actual_old_blocks;
@@ -311,19 +179,19 @@ int main(int argc, char **argv) {
   if (argc < 5) {
     printf(
       "usage: %s n_processes n_core_blocks "
-#ifdef INODE_SWAP
-      "fs_path "
-#else
       "n_swap_blocks "
-#endif
       "spare"
-#if defined(INDIRECT_CORE) && defined(INDIRECT_SWAP)
-      "[core_table_blocks [swap_table_blocks]]"
-#elif defined(INDIRECT_CORE)
-      "[core_table_blocks]"
-#elif defined(INDIRECT_SWAP)
+#ifndef INDIRECT_CORE
+#ifdef INDIRECT_SWAP
       "[swap_table_blocks]"
-#endif
+#endif /* INDIRECT_SWAP */
+#else /* INDIRECT_CORE */
+#ifndef INDIRECT_SWAP
+      "[core_table_blocks]"
+#else /* INDIRECT_SWAP */
+      "[core_table_blocks [swap_table_blocks]]"
+#endif /* INDIRECT_SWAP */
+#endif /* INDIRECT_CORE */
       "\n",
       argv[0]
     );
@@ -331,44 +199,36 @@ int main(int argc, char **argv) {
   }
   n_processes = atoi(argv[1]);
   n_core_blocks = atoi(argv[2]);
-#ifdef INODE_SWAP
-  fs_path = argv[3];
-#else
   n_swap_blocks = atoi(argv[3]);
-#endif
   spare = atoi(argv[4]);
-#if defined(INDIRECT_CORE) && defined(INDIRECT_SWAP)
+#ifndef INDIRECT_CORE
+#ifdef INDIRECT_SWAP
+  swap_table_blocks = argc >= 6 ? atoi(argv[5]) : n_swap_blocks;
+#endif /* INDIRECT_SWAP */
+#else /* INDIRECT_CORE */
   core_table_blocks = argc >= 6 ? atoi(argv[5]) : n_core_blocks;
+#ifdef INDIRECT_SWAP
   swap_table_blocks = argc >= 7 ? atoi(argv[6]) : n_swap_blocks;
-#elif defined(INDIRECT_CORE)
-  core_table_blocks = argc >= 6 ? atoi(argv[5]) : n_core_blocks;
-#elif defined(INDIRECT_SWAP)
-  swap_table_blocks = argc >= 6 ? atoi(argv[5]) : n_swap_blocks;
-#endif
+#endif /* INDIRECT_SWAP */
+#endif /* INDIRECT_CORE */
 
-#ifdef INDIRECT_CORE
-  core_init(n_core_blocks, core_table_blocks);
-#else
+#ifndef INDIRECT_CORE
   core_init(n_core_blocks);
-#endif
+#else /* INDIRECT_CORE */
+  core_init(n_core_blocks, core_table_blocks);
+#endif /* INDIRECT_CORE */
   core_block_mem = malloc((long)n_core_blocks << BLOCK_SHIFT);
   rassert(core_block_mem);
   memset(core_block_mem, 0xaa, (long)n_core_blocks << BLOCK_SHIFT);
 
-#ifdef INODE_SWAP
-  fd_open(fs_path);
-  xfs_init(0);
-  printf("free inodes %d blocks %d\n", fs_tab[0].s_tinode, fs_tab[0].s_tfree);
-#else
-#ifdef INDIRECT_SWAP
-  swap_init(n_swap_blocks, swap_table_blocks);
-#else
+#ifndef INDIRECT_SWAP
   swap_init(n_swap_blocks);
-#endif
+#else /* INDIRECT_SWAP */
+  swap_init(n_swap_blocks, swap_table_blocks);
+#endif /* INDIRECT_SWAP */
   swap_block_mem = malloc((long)n_swap_blocks << BLOCK_SHIFT);
   rassert(swap_block_mem);
   memset(swap_block_mem, 0xaa, (long)n_swap_blocks << BLOCK_SHIFT);
-#endif
 
   process_init(n_processes, spare);
   for (i = 0; i < n_processes; ++i)
@@ -376,10 +236,6 @@ int main(int argc, char **argv) {
 
   while (true) {
  //printf("avail %d %d(%d) %d(%d)\n", process_avail, CORE_AVAIL, core_table.avail, SWAP_AVAIL, swap_table.avail);
-#ifdef __FUZIX__
-    if (read(0, &test, sizeof(test)) != sizeof(test))
-      break;
-#else
     switch ((unsigned int)scanf("%s", buf)) { // cast because of ACK bug
     case -1:
       goto done;
@@ -389,7 +245,7 @@ int main(int argc, char **argv) {
       rassert(false);
     }
     if (strcmp(buf, "alloc") == 0) {
-      test.type = PROCESS_TEST_TYPE_ALLOC;
+      test.type = 0;
       rassert(
         scanf(
           "%d %ld %s",
@@ -408,7 +264,7 @@ int main(int argc, char **argv) {
         rassert(false);
     }
     else if (strcmp(buf, "realloc") == 0) {
-      test.type = PROCESS_TEST_TYPE_REALLOC;
+      test.type = 1;
       rassert(
         scanf(
           "%d %ld %ld %s",
@@ -429,21 +285,20 @@ int main(int argc, char **argv) {
         rassert(false);
     }
     else if (strcmp(buf, "run") == 0) {
-      test.type = PROCESS_TEST_TYPE_RUN;
+      test.type = 2;
       rassert(scanf("%d", &test.process) == 1);
       rassert(test.process >= 0 && test.process < n_processes);
-    } 
+    }
     else if (strcmp(buf, "free") == 0) {
-      test.type = PROCESS_TEST_TYPE_FREE;
+      test.type = 3;
       rassert(scanf("%d %ld", &test.process, &test.old_size) == 2);
       rassert(test.process >= 0 && test.process < n_processes);
       rassert(test.old_size >= 0);
     }
     else
       rassert(false);
-#endif
     switch (test.type) {
-    case PROCESS_TEST_TYPE_ALLOC:
+    case 0:
       printf(
         "alloc %d %ld %s\n",
         test.process,
@@ -478,13 +333,11 @@ int main(int argc, char **argv) {
             test.size,
             0L
           );
-#ifdef PREALLOCATE_SWAP
  //printf("new swap [%d,%d)\n", processes[test.process].swap_item.base, processes[test.process].swap_item.limit);
-#endif
         }
       }
       break;
-    case PROCESS_TEST_TYPE_REALLOC:
+    case 1:
       printf(
         "realloc %d %ld %ld %s\n",
         test.process,
@@ -512,11 +365,7 @@ int main(int argc, char **argv) {
           );
           rassert(actual_old_blocks <= old_blocks);
         }
-#ifdef PREALLOCATE_SWAP
  //printf("old core [%d,%d) swap [%d,%d)\n", core_base, core_base + actual_old_blocks, processes[test.process].swap_item.base, processes[test.process].swap_item.limit);
-#else
- //printf("old core [%d,%d)\n", core_base, core_base + actual_old_blocks);
-#endif
         core_hash_verify(
           test.process,
           ((long)core_base << BLOCK_SHIFT) + test.size,
@@ -542,11 +391,7 @@ int main(int argc, char **argv) {
               processes[test.process].core_item.limit ==
                 core_base + blocks
             );
-#ifdef PREALLOCATE_SWAP
  //printf("new core [%d,%d) swap [%d,%d)\n", core_base, core_base + blocks, processes[test.process].swap_item.base, processes[test.process].swap_item.limit);
-#else
- //printf("new core [%d,%d)\n", core_base, core_base + blocks);
-#endif
             core_hash_init(
               test.process,
               ((long)core_base << BLOCK_SHIFT) + actual_old_size,
@@ -557,7 +402,7 @@ int main(int argc, char **argv) {
         }
       }
       break;
-    case PROCESS_TEST_TYPE_RUN:
+    case 2:
       printf("run %d\n", test.process);
       if (processes[test.process].size == -1L)
         printf("... not allocated, ignore\n");
@@ -566,7 +411,7 @@ int main(int argc, char **argv) {
         printf("... ok\n");
       }
       break;
-    case PROCESS_TEST_TYPE_FREE:
+    case 3:
       printf("free %d %ld\n", test.process, test.old_size);
       if (processes[test.process].size == -1L)
         printf("... not allocated, ignore\n");
@@ -593,36 +438,23 @@ int main(int argc, char **argv) {
           core_size = processes[test.process].size;
         }
         else {
-#ifdef INODE_SWAP
-          swap_base = 0;
-          swap_size = (long)processes[test.process].swap_inode->c_node.i_size;
-          swap_blocks = (int)((swap_size + (BLOCK_SIZE - 1)) >> BLOCK_SHIFT);
-#endif
           if (processes + test.process == victim) { // victim
-#ifndef INODE_SWAP
             swap_base = victim->swap_item.base;
-#ifdef PREALLOCATE_SWAP
             swap_blocks = victim_swap_blocks;
-#else
-            swap_blocks = victim->swap_item.limit - victim->swap_item.base;
-#endif
             swap_size = swap_blocks << BLOCK_SHIFT;
-#endif
-#ifdef PREALLOCATE_CORE
-            core_base = victim->core_item.base + swap_blocks;
-            core_blocks = victim_core_blocks;
-#else
+#ifndef INDIRECT_CORE
             core_base = victim->core_item.base;
             core_blocks = victim->core_item.limit - core_base;
-#endif
+#else /* INDIRECT_CORE */
+            core_base = victim->core_item.base + swap_blocks;
+            core_blocks = victim_core_blocks;
+#endif /* INDIRECT_CORE */
             core_size = victim->size - swap_size;
           }
           else { // fully in swap
-#ifndef INODE_SWAP
             swap_base = processes[test.process].swap_item.base;
             swap_blocks = processes[test.process].swap_item.limit - swap_base;
             swap_size = processes[test.process].size;
-#endif
             core_base = -1;
             core_blocks = 0;
             core_size = 0L;
@@ -639,12 +471,8 @@ int main(int argc, char **argv) {
         );
         swap_hash_verify(
           test.process,
-#ifdef INODE_SWAP
-          processes[test.process].swap_inode
-#else
           (long)swap_base << BLOCK_SHIFT,
           swap_size
-#endif
         );
         process_free(processes + test.process);
         processes[test.process].size = -1L;
@@ -654,9 +482,7 @@ int main(int argc, char **argv) {
     }
   }
 
-#ifndef __FUZIX__
 done:
-#endif
   printf("final state:\n");
   for (i = 0; i < n_processes; ++i) {
     if (processes[i].size == -1L)
@@ -672,36 +498,23 @@ done:
         core_size = processes[i].size;
       }
       else {
-#ifdef INODE_SWAP
-        swap_base = 0;
-        swap_size = (long)processes[i].swap_inode->c_node.i_size;
-        swap_blocks = (int)((swap_size + (BLOCK_SIZE - 1)) >> BLOCK_SHIFT);
-#endif
         if (processes + i == victim) { // victim
-#ifndef INODE_SWAP
           swap_base = victim->swap_item.base;
-#ifdef PREALLOCATE_SWAP
           swap_blocks = victim_swap_blocks;
-#else
-          swap_blocks = victim->swap_item.limit - victim->swap_item.base;
-#endif
           swap_size = swap_blocks << BLOCK_SHIFT;
-#endif
-#ifdef PREALLOCATE_CORE
-          core_base = victim->core_item.base + swap_blocks;
-          core_blocks = victim_core_blocks;
-#else
+#ifndef INDIRECT_CORE
           core_base = victim->core_item.base;
           core_blocks = victim->core_item.limit - core_base;
-#endif
+#else /* INDIRECT_CORE */
+          core_base = victim->core_item.base + swap_blocks;
+          core_blocks = victim_core_blocks;
+#endif /* INDIRECT_CORE */
           core_size = victim->size - swap_size;
         }
         else { // fully in swap
-#ifndef INODE_SWAP
           swap_base = processes[i].swap_item.base;
           swap_blocks = processes[i].swap_item.limit - swap_base;
           swap_size = processes[i].size;
-#endif
           core_base = -1;
           core_blocks = 0;
           core_size = 0L;
@@ -731,34 +544,25 @@ done:
         core_table_mem + core_base,
         core_blocks
       );
-#endif
+#endif /* INDIRECT_CORE */
       swap_hash_verify(
         i,
-#ifdef INODE_SWAP
-        processes[i].swap_inode
-#else
         (long)swap_base << BLOCK_SHIFT,
         swap_size
-#endif
       );
-#ifdef INODE_SWAP
- //printf("deref inode %d\n", processes[i].swap_inode->c_num);
-      i_deref(processes[i].swap_inode);
-#elif defined(INDIRECT_SWAP)
+#ifdef INDIRECT_SWAP
       block_pool_free(
         &swap_block_pool,
         swap_table_mem + swap_base,
         swap_blocks
       );
-#endif
+#endif /* INDIRECT_SWAP */
     }
   }
 
 #ifdef INDIRECT_CORE
-#ifndef NDEBUG
   for (i = 0; i < core_table_blocks; ++i)
     rassert(core_table_mem[i] == 0x55555555);
-#endif
   {
     k = core_block_pool.n_blocks >> 3;
     for (j = 0; j < k; ++j)
@@ -767,18 +571,13 @@ done:
     if (k)
       rassert(core_block_pool.bitmap[j] == (uint8_t)~(-1 << k));
   }
-#endif
+#endif /* INDIRECT_CORE */
   j = n_core_blocks << BLOCK_SHIFT;
   for (i = 0; i < j; ++i)
     rassert(core_block_mem[i] == 0xaa);
-#ifdef INODE_SWAP
-  printf("free inodes %d blocks %d\n", fs_tab[0].s_tinode, fs_tab[0].s_tfree);
-#else
 #ifdef INDIRECT_SWAP
-#ifndef NDEBUG
   for (i = 0; i < swap_table_blocks; ++i)
     rassert(swap_table_mem[i] == 0x55555555);
-#endif
   {
     k = swap_block_pool.n_blocks >> 3;
     for (j = 0; j < k; ++j)
@@ -787,11 +586,10 @@ done:
     if (k)
       rassert(swap_block_pool.bitmap[j] == (uint8_t)~(-1 << k));
   }
-#endif
+#endif /* INDIRECT_SWAP */
   j = n_swap_blocks << BLOCK_SHIFT;
   for (i = 0; i < j; ++i)
     rassert(swap_block_mem[i] == 0xaa);
-#endif
 
   return 0;
 }
diff --git a/q.sh b/q.sh
index 3558241..3a3d9ee 100755 (executable)
--- a/q.sh
+++ b/q.sh
@@ -1,7 +1,5 @@
 #!/bin/sh
 (cd indirect_core_indirect_swap && make clean && make && ./o.sh)
-(cd indirect_core_inode_swap && make clean && make && ./o.sh)
-(cd indirect_core_preallocate_swap && make clean && make && ./o.sh)
+(cd indirect_core_contiguous_swap && make clean && make && ./o.sh)
 (cd moveable_core_indirect_swap && make clean && make && ./o.sh)
-(cd moveable_core_inode_swap && make clean && make && ./o.sh)
-(cd moveable_core_preallocate_swap && make clean && make && ./o.sh)
+(cd moveable_core_contiguous_swap && make clean && make && ./o.sh)
diff --git a/swap.c b/swap.c
index b3226cc..3511bab 100644 (file)
--- a/swap.c
+++ b/swap.c
@@ -2,9 +2,7 @@
 #include <stddef.h>
 //#include <stdio.h>
 #include <stdlib.h>
-#ifndef NDEBUG
 #include <string.h>
-#endif
 #include "swap.h"
 #include "process.h"
 #include "rassert.h"
@@ -13,20 +11,18 @@ struct pool_head swap_table;
 #ifdef INDIRECT_SWAP
 int *swap_table_mem;
 struct block_pool swap_block_pool;
-#endif
+#endif /* INDIRECT_SWAP */
 
-#ifdef PREALLOCATE_SWAP
 int victim_swap_blocks;
-#endif
 
 static void swap_move(struct pool_item *item, int new_base) {
   int base, blocks;
-#ifdef INDIRECT_SWAP
-  int i;
-#else
+#ifndef INDIRECT_SWAP
   struct process *process;
   long size;
-#endif
+#else /* INDIRECT_SWAP */
+  int i;
+#endif /* INDIRECT_SWAP */
 
   base = item->base;
   blocks = item->limit - base;
@@ -38,14 +34,7 @@ static void swap_move(struct pool_item *item, int new_base) {
   //  new_base + blocks
   //);
   assert(new_base <= base || new_base >= base + blocks);
-#ifdef INDIRECT_SWAP
-  for (i = 0; i < blocks; ++i) {
-    swap_table_mem[new_base + i] = swap_table_mem[base + i];
-#ifndef NDEBUG
-    swap_table_mem[base + i] = 0x55555555;
-#endif
-  }
-#else
+#ifndef INDIRECT_SWAP
   // see if incomplete last block, if so don't copy extra part
   process =
     (struct process *)((char *)item - offsetof(struct process, swap_item));
@@ -55,89 +44,37 @@ static void swap_move(struct pool_item *item, int new_base) {
 
   // copy by abstract routine
   swap_copy((long)base << BLOCK_SHIFT, (long)new_base << BLOCK_SHIFT, size);
-#endif
-}
-
-#ifdef MOVEABLE_SWAP
-static void swap_move_up(struct pool_item *item, int new_limit) {
-  int limit, blocks;
-#ifdef INDIRECT_SWAP
-  int i;
-#else
-  long limit1, new_limit1, size;
-  struct process *process;
-  long trim;
-#endif
-
-  limit = item->limit;
-  blocks = limit - item->base;
-  //printf(
-  //  "swap_move_up [%d,%d) to [%d,%d)\n",
-  //  limit - blocks,
-  //  limit,
-  //  new_limit - blocks,
-  //  new_limit
-  //);
-  assert(new_limit >= limit || new_limit <= limit - blocks);
-#ifdef INDIRECT_SWAP
-  blocks = -blocks;
-  for (i = -1; i >= blocks; --i) {
-    swap_table_mem[new_limit + i] = swap_table_mem[limit + i];
-#ifndef NDEBUG
-    swap_table_mem[limit + i] = 0x55555555;
-#endif
-  }
-#else
-  // set up transfer parameters
-  limit1 = (long)limit << BLOCK_SHIFT;
-  new_limit1 = (long)new_limit << BLOCK_SHIFT;
-  size = (long)blocks << BLOCK_SHIFT;
-
-  // see if incomplete last block, if so don't copy extra part
-  process =
-    (struct process *)((char *)item - offsetof(struct process, swap_item));
-  trim = size - process->size;
-  if (trim > 0) {
-    limit1 -= trim;
-    new_limit1 -= trim;
-    size = process->size;
+#else /* INDIRECT_SWAP */
+  for (i = 0; i < blocks; ++i) {
+    swap_table_mem[new_base + i] = swap_table_mem[base + i];
+    swap_table_mem[base + i] = 0x55555555;
   }
-
-  // copy by abstract routine
-  swap_copy_up(limit1, new_limit1, size);
-#endif
+#endif /* INDIRECT_SWAP */
 }
-#endif
 
-#ifdef INDIRECT_SWAP
-void swap_init(int n_blocks, int table_size)
-#else
+#ifndef INDIRECT_SWAP
 void swap_init(int n_blocks)
-#endif
+#else /* INDIRECT_SWAP */
+void swap_init(int n_blocks, int table_size)
+#endif /* INDIRECT_SWAP */
 {
   pool_init(
     &swap_table,
     0,
-#ifdef INDIRECT_SWAP
-    table_size,
-#else
+#ifndef INDIRECT_SWAP
     n_blocks,
-#endif
+#else /* INDIRECT_SWAP */
+    table_size,
+#endif /* INDIRECT_SWAP */
     swap_move,
-#ifdef MOVEABLE_SWAP
-    swap_move_up
-#else
     NULL
-#endif
   );
 
 #ifdef INDIRECT_SWAP
   swap_table_mem = malloc(table_size * sizeof(int));
   rassert(swap_table_mem);
-#ifndef NDEBUG
   memset(swap_table_mem, 0x55, table_size * sizeof(int));
-#endif
 
   block_pool_init(&swap_block_pool, n_blocks);
-#endif
+#endif /* INDIRECT_SWAP */
 }
diff --git a/swap.h b/swap.h
index 87aeb6d..ef608fb 100644 (file)
--- a/swap.h
+++ b/swap.h
@@ -1,40 +1,30 @@
 #ifndef _SWAP_H
 #define _SWAP_H 1
 
-#define PREALLOCATE_SWAP 1
 #define INDIRECT_SWAP 1
-//#define MOVEABLE_SWAP 1
 
 #include <stdint.h>
 #ifdef INDIRECT_SWAP
 #include "block_pool.h"
-#endif
+#endif /* INDIRECT_SWAP */
 #include "pool.h"
 
-#ifdef INDIRECT_SWAP
-#define SWAP_AVAIL swap_block_pool.avail
-#else
-#define SWAP_AVAIL swap_table.avail
-#endif
-
 extern struct pool_head swap_table;
 #ifdef INDIRECT_SWAP
 extern int *swap_table_mem;
 extern struct block_pool swap_block_pool;
-#endif
+#endif /* INDIRECT_SWAP */
 
-#ifdef PREALLOCATE_SWAP
 extern int victim_swap_blocks;
-#endif
 
-#ifdef INDIRECT_SWAP
-void swap_init(int n_table, int n_blocks);
-#else
+#ifndef INDIRECT_SWAP
 void swap_init(int n_table);
 
 // abstract
 void swap_copy(long src_base, long dest_base, long size);
 void swap_copy_up(long src_limit, long dest_limit, long size);
-#endif
+#else /* INDIRECT_SWAP */
+void swap_init(int n_table, int n_blocks);
+#endif /* INDIRECT_SWAP */
 
 #endif