#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;
}
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(
}
}
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;
#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
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",
}
}
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",
#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
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);
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;
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);
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;
}
#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];
#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];
#include <stdint.h>
#include "pool.h"
-//#define INDIRECT_SWAP 1
+#define INDIRECT_SWAP 1
//#define MOVEABLE_SWAP 1
#ifdef MOVEABLE_SWAP
#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);