#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;
);
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;
}
}
);
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;
}
}
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));
}
#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);
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);
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);
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);
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;
}
#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) {
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,
swap_table_mem[base + i] = 0xaaaaaaaa;
}
}
+#endif
#ifdef INDIRECT_SWAP
void swap_init(int table_size, int table_spare, int n_blocks)
~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;
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;
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
}
}
#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");
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");
#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);