Fix a bug in undo successful process realloc, fix a bug in number of blocks to transf...
authorNick Downing <nick@ndcode.org>
Sat, 6 Apr 2019 03:17:07 +0000 (14:17 +1100)
committerNick Downing <nick@ndcode.org>
Sat, 6 Apr 2019 03:23:13 +0000 (14:23 +1100)
inode_test_gen.c
inode_test_run.c
pool_test_gen.c
process.c
process_test_gen.c
process_test_run.c
swap.c
swap.h

index 00ba901..cf98d60 100644 (file)
@@ -5,25 +5,25 @@
 #include "rassert.h"
 
 #define BLOCK_SIZE 0x200
-#define BLOCK_SIZE_SHIFT 9
+#define BLOCK_SHIFT 9
 
-#define BLOCK_PTRS 0x100
-#define BLOCK_PTRS_SHIFT 8
+#define INDIRECT_SIZE 0x100
+#define INDIRECT_SHIFT 8
 
 int rand_int(int n) {
   return (int)((long long)rand() * n / (RAND_MAX + 1LL));
 }
 
 int bytes_to_blocks(int size) {
-  size = (size + (BLOCK_SIZE - 1)) >> BLOCK_SIZE_SHIFT;
+  size = (size + (BLOCK_SIZE - 1)) >> BLOCK_SHIFT;
   int blocks = size;
   if (size > 18) {
     // has indirect blocks
-    size = (size + (BLOCK_PTRS - 1 - 18)) >> BLOCK_PTRS_SHIFT;
+    size = (size + (INDIRECT_SIZE - 1 - 18)) >> INDIRECT_SHIFT;
     blocks += size;
     if (size > 1) {
       // has double indirect blocks
-      size = (size + (BLOCK_PTRS - 1 - 1)) >> BLOCK_PTRS_SHIFT;
+      size = (size + (INDIRECT_SIZE - 1 - 1)) >> INDIRECT_SHIFT;
       rassert(size == 1);
       blocks += size;
     }
@@ -52,7 +52,7 @@ int main(int argc, char **argv) {
     int file = rand_int(n_files);
     int old_size = files[file];
     if (old_size == -1) {
-      int size = rand_int(file_size * BLOCK_SIZE);
+      int size = rand_int((file_size << BLOCK_SHIFT) + 1);
       int size_blocks = bytes_to_blocks(size);
       bool success = blocks_used + size_blocks <= n_blocks;
       printf(
@@ -67,7 +67,7 @@ int main(int argc, char **argv) {
       }
     }
     else if (rand_int(4)) {
-      int size = rand_int(file_size * BLOCK_SIZE);
+      int size = rand_int((file_size << BLOCK_SHIFT) + 1);
       int size_blocks = bytes_to_blocks(size);
       int old_size_blocks = bytes_to_blocks(old_size);
       bool success = blocks_used + size_blocks - old_size_blocks <= n_blocks;
index b7a7f5a..77e899b 100644 (file)
@@ -8,10 +8,10 @@
 #include "util.h"
 
 #define BLOCK_SIZE 0x200
-#define BLOCK_SIZE_SHIFT 9
+#define BLOCK_SHIFT 9
 
-#define BLOCK_PTRS 0x100
-#define BLOCK_PTRS_SHIFT 8
+#define INDIRECT_SIZE 0x100
+#define INDIRECT_SHIFT 8
 
 #define TRANSFER_SIZE 821 // a prime number somewhat near the block size
 
index d0e0abe..1f57e12 100644 (file)
@@ -30,7 +30,7 @@ int main(int argc, char **argv) {
     int item = rand_int(n_items);
     int old_size = items[item];
     if (old_size == -1) {
-      int size = rand_int(item_size);
+      int size = rand_int(item_size + 1);
       bool success = pool_used + size <= pool_size;
       printf(
         "alloc %d %d %s\n",
@@ -44,7 +44,7 @@ int main(int argc, char **argv) {
       }
     }
     else if (rand_int(4)) {
-      int size = rand_int(item_size);
+      int size = rand_int(item_size + 1);
       bool success = pool_used + size - old_size <= pool_size;
       printf(
         "realloc%s %d %d %d %s\n",
index 517d2a3..fbc00ac 100644 (file)
--- a/process.c
+++ b/process.c
@@ -245,7 +245,7 @@ static void do_swap_out(int swap_out) {
 #ifdef INDIRECT_SWAP
       rassert(swap_block_alloc(swap_table_mem + swap_base, blocks));
 #endif
-      swap_write(swap_base, core_base, size);
+      swap_write(core_base, swap_base, size);
 #ifdef INDIRECT_CORE
       core_block_free(core_table_mem + core_base, blocks);
 #endif
index c055849..6dbf00f 100644 (file)
@@ -26,7 +26,7 @@ int main(int argc, char **argv) {
   int process_blocks = atoi(argv[4]);
   int seed = argc >= 6 ? atoi(argv[5]) : 1;
 
-  long process_size = (long)process_blocks * BLOCK_SIZE;
+  long process_size = (long)process_blocks << BLOCK_SHIFT;
 
   int *processes = malloc(n_processes * sizeof(long));
   rassert(processes);
index 091842f..510ce58 100644 (file)
@@ -303,7 +303,7 @@ int main(int argc, char **argv) {
         if (result) {
           if (!success) {
             printf("... undo\n");
-            rassert(process_realloc(processes + process, actual_old_blocks));
+            rassert(process_realloc(processes + process, actual_old_size));
           }
           else {
             core_base = processes[process].core_item.base;
@@ -512,9 +512,11 @@ done:
       rassert(core_block_bitmap[j] == (uint8_t)~(-1 << k));
   }
 #endif
-  for (int i = 0; i < n_core_blocks; ++i)
-    for (int j = 0; j < BLOCK_SIZE; ++j)
-      rassert(core_block_mem[i * BLOCK_SIZE + j] == 0xaa);
+  {
+    int j = n_core_blocks << BLOCK_SHIFT;
+    for (int i = 0; i < j; ++i)
+      rassert(core_block_mem[i] == 0xaa);
+  }
 #ifdef INDIRECT_SWAP
   for (int i = 0; i < swap_table_blocks; ++i)
     rassert(swap_table_mem[i] == 0x55555555);
@@ -527,9 +529,11 @@ done:
       rassert(swap_block_bitmap[j] == (uint8_t)~(-1 << k));
   }
 #endif
-  for (int i = 0; i < n_swap_blocks; ++i)
-    for (int j = 0; j < BLOCK_SIZE; ++j)
-      rassert(swap_block_mem[i * BLOCK_SIZE + j] == 0xaa);
+  {
+    int j = n_swap_blocks << BLOCK_SHIFT;
+    for (int i = 0; i < j; ++i)
+      rassert(swap_block_mem[i] == 0xaa);
+  }
 
   return 0;
 }
diff --git a/swap.c b/swap.c
index 50f8e88..49abae0 100644 (file)
--- a/swap.c
+++ b/swap.c
@@ -208,7 +208,7 @@ void swap_read(int swap_base, int core_base, long size) {
 #if defined(INDIRECT_CORE) || defined(INDIRECT_SWAP)
  printf("blocks");
 #endif
-  for (int i = 0; i < size; ++i) {
+  for (int i = 0; i < blocks; ++i) {
     int swap_block = swap_base + i;
 #ifdef INDIRECT_SWAP
     swap_block = swap_table_mem[swap_block];
@@ -240,13 +240,13 @@ void swap_read(int swap_base, int core_base, long size) {
 #endif
 }
 
-void swap_write(int swap_base, int core_base, long size) {
+void swap_write(int core_base, int swap_base, long size) {
   int blocks = (int)((size + (BLOCK_SIZE - 1)) >> BLOCK_SHIFT);
  printf("swap_write core [%d,%d) to swap [%d,%d)\n", core_base, core_base + blocks, swap_base, swap_base + blocks);
 #if defined(INDIRECT_CORE) || defined(INDIRECT_SWAP)
  printf("blocks");
 #endif
-  for (int i = 0; i < size; ++i) {
+  for (int i = 0; i < blocks; ++i) {
     int core_block = core_base + i;
 #ifdef INDIRECT_CORE
     core_block = core_table_mem[core_block];
diff --git a/swap.h b/swap.h
index 2d1d0b3..62e458e 100644 (file)
--- a/swap.h
+++ b/swap.h
@@ -4,7 +4,7 @@
 #include <stdint.h>
 #include "pool.h"
 
-//#define INDIRECT_SWAP 1
+#define INDIRECT_SWAP 1
 //#define MOVEABLE_SWAP 1
 
 #ifdef MOVEABLE_SWAP
@@ -54,7 +54,7 @@ void swap_copy_up(long src_limit, long dest_limit, long size);
 #endif
 
 void swap_read(int swap_base, int core_base, long size);
-void swap_write(int swap_base, int core_base, long size);
+void swap_write(int core_base, int swap_base, long size);
 
 // abstract
 void core_to_swap_copy(long src_base, long dest_base, long size);