From: Nick Downing Date: Tue, 19 Mar 2019 10:36:45 +0000 (+1100) Subject: For direct swap, store data in swap_block_mem not swap_table_mem, also for core X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=b8232ab5eef1a290c7d25c27c07165af15a9c93c;p=moveable_pool.git For direct swap, store data in swap_block_mem not swap_table_mem, also for core --- diff --git a/core.c b/core.c index e0af29b..c415cfd 100644 --- a/core.c +++ b/core.c @@ -5,7 +5,7 @@ #include "rassert.h" struct pool_head core_table; -int *core_table_mem; +int *core_block_mem; void core_move(struct pool_item *item, int new_base) { int base = item->base; @@ -19,8 +19,8 @@ void core_move(struct pool_item *item, int new_base) { ); assert(new_base < base || new_base >= base + size); for (int i = 0; i < size; ++i) { - core_table_mem[new_base + i] = core_table_mem[base + i]; - core_table_mem[base + i] = 0xaaaaaaaa; + core_block_mem[new_base + i] = core_block_mem[base + i]; + core_block_mem[base + i] = 0xaaaaaaaa; } } @@ -37,8 +37,8 @@ void core_move_up(struct pool_item *item, int new_limit) { ); assert(new_limit > limit || new_limit <= limit + neg_size); for (int i = -1; i >= neg_size; --i) { - core_table_mem[new_limit + i] = core_table_mem[limit + i]; - core_table_mem[limit + i] = 0xaaaaaaaa; + core_block_mem[new_limit + i] = core_block_mem[limit + i]; + core_block_mem[limit + i] = 0xaaaaaaaa; } } @@ -52,6 +52,6 @@ void core_init(int table_size, int table_spare) { core_move_up ); - core_table_mem = malloc(table_size * sizeof(int)); - memset(core_table_mem, 0xaa, table_size * sizeof(int)); + core_block_mem = malloc(table_size * sizeof(int)); + memset(core_block_mem, 0xaa, table_size * sizeof(int)); } diff --git a/core.h b/core.h index 3c8ee2c..a9cb734 100644 --- a/core.h +++ b/core.h @@ -19,7 +19,7 @@ #define core_table_free(item) pool_free(&core_table, item) extern struct pool_head core_table; -extern int *core_table_mem; +extern int *core_block_mem; void core_init(int n_table, int table_spare); diff --git a/process_test_run.c b/process_test_run.c index a62a7b4..2498535 100644 --- a/process_test_run.c +++ b/process_test_run.c @@ -81,8 +81,8 @@ int main(int argc, char **argv) { long long hash = process * 17 + i * 29; hash = (hash & 0xffffffffffffffffLL) + (hash >> 32); hash = (hash & 0xffffffffffffffffLL) + (hash >> 32); - rassert(core_table_mem[core_base + i] == 0xaaaaaaaa); - core_table_mem[core_base + i] = (int)hash; + rassert(core_block_mem[core_base + i] == 0xaaaaaaaa); + core_block_mem[core_base + i] = (int)hash; } #ifdef PREALLOCATE_SWAP printf("new swap [%d,%d)\n", ~processes[process].swap_item.limit, ~processes[process].swap_item.base); @@ -144,15 +144,15 @@ int main(int argc, char **argv) { long long hash = process * 17 + i * 29; hash = (hash & 0xffffffffffffffffLL) + (hash >> 32); hash = (hash & 0xffffffffffffffffLL) + (hash >> 32); - rassert(core_table_mem[core_base + i] == 0xaaaaaaaa); - core_table_mem[core_base + i] = (int)hash; + rassert(core_block_mem[core_base + i] == 0xaaaaaaaa); + core_block_mem[core_base + i] = (int)hash; } for (int i = size; i < actual_old_size; ++i) { long long hash = process * 17 + i * 29; hash = (hash & 0xffffffffffffffffLL) + (hash >> 32); hash = (hash & 0xffffffffffffffffLL) + (hash >> 32); - rassert(core_table_mem[core_base + i] == (int)hash); - core_table_mem[core_base + i] = 0xaaaaaaaa; + rassert(core_block_mem[core_base + i] == (int)hash); + core_block_mem[core_base + i] = 0xaaaaaaaa; } #ifdef PREALLOCATE_SWAP printf("new swap [%d,%d)\n", ~processes[process].swap_item.limit, ~processes[process].swap_item.base); @@ -210,18 +210,17 @@ int main(int argc, char **argv) { hash = (hash & 0xffffffffffffffffLL) + (hash >> 32); hash = (hash & 0xffffffffffffffffLL) + (hash >> 32); if (i < core_size) { - rassert(core_table_mem[core_base + i] == (int)hash); - core_table_mem[core_base + i] = 0xaaaaaaaa; + rassert(core_block_mem[core_base + i] == (int)hash); + core_block_mem[core_base + i] = 0xaaaaaaaa; } else { #ifdef INDIRECT_SWAP - int block = swap_table_mem[swap_base + i - core_size]; - rassert(swap_block_mem[block] == (int)hash); - swap_block_mem[block] = 0x55555555; + int swap_block = swap_table_mem[swap_base + i - core_size]; #else - rassert(swap_table_mem[swap_base + i - core_size] == (int)hash); - swap_table_mem[swap_base + i - core_size] = 0xaaaaaaaa; + int swap_block = swap_base + i - core_size; #endif + rassert(swap_block_mem[swap_block] == (int)hash); + swap_block_mem[swap_block] = 0xaaaaaaaa; } } process_free(processes + process); @@ -267,31 +266,31 @@ done: hash = (hash & 0xffffffffffffffffLL) + (hash >> 32); hash = (hash & 0xffffffffffffffffLL) + (hash >> 32); if (j < core_size) { - rassert(core_table_mem[core_base + j] == (int)hash); - core_table_mem[core_base + j] = 0xaaaaaaaa; + rassert(core_block_mem[core_base + j] == (int)hash); + core_block_mem[core_base + j] = 0xaaaaaaaa; } else { #ifdef INDIRECT_SWAP - int block = swap_table_mem[swap_base + j - core_size]; - rassert(swap_block_mem[block] == (int)hash); - swap_block_mem[block] = 0x55555555; + int swap_block = swap_table_mem[swap_base + j - core_size]; #else - rassert(swap_table_mem[swap_base + j - core_size] == (int)hash); - swap_table_mem[swap_base + j - core_size] = 0xaaaaaaaa; + int swap_block = swap_base + j - core_size; #endif + rassert(swap_block_mem[swap_block] == (int)hash); + swap_block_mem[swap_block] = 0xaaaaaaaa; } } } } for (int i = 0; i < core_table.item.base; ++i) - rassert(core_table_mem[i] == 0xaaaaaaaa); - for (int i = 0; i < swap_table.item.base; ++i) - rassert(swap_table_mem[i] == 0xaaaaaaaa); + rassert(core_block_mem[i] == 0xaaaaaaaa); + int swap_limit = ~swap_table.item.base; + for (int i = 0; i < swap_limit; ++i) #ifdef INDIRECT_SWAP + rassert(swap_table_mem[i] == 0x55555555); for (int i = 0; i < n_swap_blocks; ++i) - rassert(swap_block_mem[i] == 0x55555555); #endif + rassert(swap_block_mem[i] == 0xaaaaaaaa); return 0; } diff --git a/swap.c b/swap.c index 68bca1b..e94b397 100644 --- a/swap.c +++ b/swap.c @@ -5,21 +5,22 @@ #include "swap.h" #include "rassert.h" +struct pool_head swap_table; + #ifdef INDIRECT_SWAP static uint8_t masks[8] = {0xff, 0xfe, 0xfc, 0xf8, 0xf0, 0xe0, 0xc0, 0x80}; static uint8_t bits[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80}; -uint8_t *swap_block_bitmap; +int n_swap_blocks; int n_swap_block_bitmap; +uint8_t *swap_block_bitmap; int swap_block_next; -int *swap_block_mem; -int n_swap_blocks; -#endif - -struct pool_head swap_table; int *swap_table_mem; +#endif +int *swap_block_mem; +#ifdef MOVEABLE_SWAP // swap address native wrt. pool and complemented wrt. backing store, // means that swap_move() moves upward in backing store, do backward static void swap_move(struct pool_item *item, int new_base) { @@ -40,7 +41,6 @@ static void swap_move(struct pool_item *item, int new_base) { swap_table_mem[new_limit + i] = swap_table_mem[limit + i]; swap_table_mem[limit + i] = 0xaaaaaaaa; } - } // swap address native wrt. pool and complemented wrt. backing store, @@ -64,6 +64,7 @@ static void swap_move_up(struct pool_item *item, int new_limit) { swap_table_mem[base + i] = 0xaaaaaaaa; } } +#endif #ifdef INDIRECT_SWAP void swap_init(int table_size, int table_spare, int n_blocks) @@ -76,32 +77,39 @@ void swap_init(int table_size, int table_spare) ~table_size, -1, table_spare, +#ifdef MOVEABLE_SWAP swap_move, swap_move_up +#else + NULL, + NULL +#endif ); - swap_table_mem = malloc(table_size * sizeof(int)); - rassert(swap_table_mem); - memset(swap_table_mem, 0xaa, table_size * sizeof(int)); - #ifdef INDIRECT_SWAP - n_swap_block_bitmap = (n_blocks + 7) >> 3; + n_swap_blocks = n_blocks; + n_swap_block_bitmap = (n_swap_blocks + 7) >> 3; swap_block_bitmap = malloc(n_swap_block_bitmap); rassert(swap_block_bitmap); memset(swap_block_bitmap, 0xff, n_swap_block_bitmap); if (n_blocks & 7) - swap_block_bitmap[n_blocks >> 3] = ~masks[n_blocks & 7]; + swap_block_bitmap[n_swap_blocks >> 3] = ~masks[n_swap_blocks & 7]; swap_block_next = 0; + swap_table_mem = malloc(table_size * sizeof(int)); + rassert(swap_table_mem); + memset(swap_table_mem, 0x55, table_size * sizeof(int)); + swap_block_mem = malloc(n_blocks * sizeof(int)); - rassert(swap_block_mem); - memset(swap_block_mem, 0x55, n_blocks * sizeof(int)); - n_swap_blocks = n_blocks; +#else + swap_block_mem = malloc(table_size * sizeof(int)); #endif + rassert(swap_block_mem); + memset(swap_block_mem, 0xaa, n_blocks * sizeof(int)); } #ifdef INDIRECT_SWAP -bool swap_block_alloc(int *blocks, int size) { +bool swap_block_alloc(int *table, int size) { int i, j, k; uint8_t c; @@ -120,16 +128,16 @@ bool swap_block_alloc(int *blocks, int size) { if (c) goto found; } - swap_block_free(blocks, i); + swap_block_free(table, i); return false; found: for (k = 0; (c & 1) == 0; ++k) c >>= 1; swap_block_bitmap[j] &= ~bits[k]; - assert(blocks[i] == 0xaaaaaaaa); + assert(table[i] == 0x55555555); j = (j << 3) | k; - blocks[i] = j++; + table[i] = j++; if (j >= n_swap_blocks) j = 0; swap_block_next = j; @@ -138,18 +146,18 @@ bool swap_block_alloc(int *blocks, int size) { return true; } -void swap_block_free(int *blocks, int size) { +void swap_block_free(int *table, int size) { int i, j, k; for (i = 0; i < size; ++i) { - j = blocks[i]; + j = table[i]; assert(j >= 0 && j < n_swap_blocks); k = j & 7; j >>= 3; assert((swap_block_bitmap[j] & bits[k]) == 0); swap_block_bitmap[j] |= bits[k]; #ifndef NDEBUG - blocks[i] = 0xaaaaaaaa; + table[i] = 0x55555555; #endif } } @@ -163,16 +171,14 @@ void swap_read(int swap_base, int core_base, int size) { #endif for (int i = 0; i < size; ++i) { #ifdef INDIRECT_SWAP - int block = swap_table_mem[swap_base + i]; - printf(" %d", block); - int data = swap_block_mem[block]; - swap_block_mem[block] = 0x55555555; + int swap_block = swap_table_mem[swap_base + i]; + printf(" %d", swap_block); #else - int data = swap_table_mem[swap_base + i]; - swap_table_mem[swap_base + i] = 0xaaaaaaaa; + int swap_block = swap_base + i; #endif - assert(core_table_mem[core_base + i] == 0xaaaaaaaa); - core_table_mem[core_base + i] = data; + assert(core_block_mem[core_base + i] == 0xaaaaaaaa); + core_block_mem[core_base + i] = swap_block_mem[swap_block]; + swap_block_mem[swap_block] = 0xaaaaaaaa; } #ifdef INDIRECT_SWAP printf("\n"); @@ -186,18 +192,15 @@ void swap_write(int swap_base, int core_base, int size) { printf("blocks"); #endif for (int i = 0; i < size; ++i) { - int data = core_table_mem[core_base + i]; - core_table_mem[core_base + i] = 0xaaaaaaaa; #ifdef INDIRECT_SWAP - int block = swap_table_mem[swap_base + i]; - printf(" %d", block); - assert(block >= 0 && block < n_swap_blocks); - assert(swap_block_mem[block] == 0x55555555); - swap_block_mem[block] = data; + int swap_block = swap_table_mem[swap_base + i]; + printf(" %d", swap_block); #else - assert(swap_table_mem[swap_base + i] == 0xaaaaaaaa); - swap_table_mem[swap_base + i] = data; + int swap_block = swap_base + i; #endif + assert(swap_block_mem[swap_block] == 0xaaaaaaaa); + swap_block_mem[swap_block] = core_block_mem[core_base + i]; + core_block_mem[core_base + i] = 0xaaaaaaaa; } #ifdef INDIRECT_SWAP printf("\n"); diff --git a/swap.h b/swap.h index 9e6d3a4..6d17e37 100644 --- a/swap.h +++ b/swap.h @@ -20,16 +20,17 @@ #endif #define swap_table_free(item) pool_free(&swap_table, item) +extern struct pool_head swap_table; + #ifdef INDIRECT_SWAP +extern int n_swap_blocks; +int n_swap_block_bitmap; extern uint8_t *swap_block_bitmap; extern int swap_block_next; -extern int *swap_block_mem; -extern int n_swap_blocks; -#endif - -extern struct pool_head swap_table; extern int *swap_table_mem; +#endif +extern int *swap_block_mem; #ifdef INDIRECT_SWAP void swap_init(int n_table, int table_spare, int n_blocks);