For INDIRECT_CORE defer swap out until after successful table memory allocation
authorNick Downing <nick@ndcode.org>
Sun, 2 Jun 2019 02:21:22 +0000 (12:21 +1000)
committerNick Downing <nick@ndcode.org>
Sun, 2 Jun 2019 02:21:22 +0000 (12:21 +1000)
core.h
process.c
swap.h

diff --git a/core.h b/core.h
index 165474b..19600b5 100644 (file)
--- a/core.h
+++ b/core.h
@@ -1,7 +1,7 @@
 #ifndef _CORE_H
 #define _CORE_H 1
 
-#define INDIRECT_CORE 1
+//#define INDIRECT_CORE 1
 
 #include <stdint.h>
 #ifdef INDIRECT_CORE
index 8599e94..0d1a350 100644 (file)
--- a/process.c
+++ b/process.c
@@ -288,9 +288,6 @@ bool process_alloc(struct process *process, int para, int paras) {
     )
   );
 #else /* INDIRECT_CORE */
-  // free up as much core as we need to
-  rassert(do_swap_out(blocks - core_block_pool.avail));
-
   // allocate core and possible swap
   if (
     !pool_alloc(
@@ -304,6 +301,9 @@ bool process_alloc(struct process *process, int para, int paras) {
     return false;
   }
 
+  // free up as much core as we need to
+  rassert(do_swap_out(blocks - core_block_pool.avail));
+
   // populate physical blocks as needed
   rassert(
     block_pool_alloc(
@@ -385,9 +385,6 @@ bool process_realloc(struct process *process, int paras, bool dir) {
     )
   );
 #else /* INDIRECT_CORE */
-  // free up as much core as we need to
-  rassert(do_swap_out(blocks_change - core_block_pool.avail));
-
   // reallocate core and possible swap
   if (
     !pool_alloc(
@@ -420,7 +417,10 @@ bool process_realloc(struct process *process, int paras, bool dir) {
       ),
       -blocks_change
     );
-  else
+  else {
+    // free up as much core as we need to
+    rassert(do_swap_out(blocks_change - core_block_pool.avail));
+
     // populate physical blocks as needed
     rassert(
       block_pool_alloc(
@@ -433,6 +433,7 @@ bool process_realloc(struct process *process, int paras, bool dir) {
         blocks_change
       )
     );
+  }
 #endif /* INDIRECT_CORE */
 
   // track total allocation
diff --git a/swap.h b/swap.h
index b751427..9b9a640 100644 (file)
--- a/swap.h
+++ b/swap.h
@@ -1,7 +1,7 @@
 #ifndef _SWAP_H
 #define _SWAP_H 1
 
-//#define INDIRECT_SWAP 1
+#define INDIRECT_SWAP 1
 
 #include <stdint.h>
 #ifdef INDIRECT_SWAP