process_calc(process, &calc);
assert(calc.in_core_block == calc.block_limit);
+ // for now, not allowed to resize both ends at once
+ // (in case we free physical blocks then fail to resize)
+ assert(
+ para_base == process->para_base ||
+ para_limit == process->para_limit
+ );
+
// check blocks
old_blocks = calc.block_limit - calc.block_base;
block_base = para_base >> BLOCK_PARAS_SHIFT;
if (process_avail < blocks_change)
return false;
- // this is a bit clunky, we want realloc without copying old contents,
- // so we free, try to allocate larger, if that fails, allocate original
- pool_free(&swap_table, &process->swap_item);
- if (!pool_alloc(&swap_table, &process->swap_item, blocks, 0)) {
- rassert(pool_alloc(&swap_table, &process->swap_item, old_blocks, 0));
+ // reallocate swap
+ if (
+ !pool_alloc(
+ &swap_table,
+ &process->swap_item,
+ blocks,
+ dir | POOL_ALLOC_MODE_REALLOC,
+ 0 //calc.block_base - block_base
+ )
+ )
return false;
- }
#ifndef INDIRECT_CORE
// free up as much core as we need to
calc.block_base - block_base
)
) {
- assert(blocks_change >= 0);
- pool_free(&swap_table, &process->swap_item);
+ // note: if we get to here we are resizing larger,
+ // so we can't have freed any physical blocks above
rassert(
pool_alloc(
&swap_table,
&process->swap_item,
old_blocks,
- 0
+ dir | POOL_ALLOC_MODE_REALLOC,
+ 0 //calc.block_base - block_base
)
);
return false;
#ifdef INDIRECT_SWAP
int *swap_table_mem;
struct block_pool swap_block_pool;
+#endif /* INDIRECT_SWAP */
static void swap_move(struct pool_item *item, int new_base) {
+#if 0 // only called for block under realloc, whose contents are ignored
int base, blocks;
int i;
swap_table_mem[new_base + i] = swap_table_mem[base + i];
swap_table_mem[base + i] = 0x55555555;
}
+#endif
+}
+
+static void swap_move_up(struct pool_item *item, int new_base) {
+#if 0 // only called for block under realloc, whose contents are ignored
+ int base, blocks;
+ int i;
+
+ limit = item->limit;
+ blocks = limit - item->base;
+ printf("swap_move_up [%d,%d) to [%d,%d)\n", limit - blocks, limit, new_limit - blocks, new_limit);
+ assert(new_limit >= limit || new_limit <= limit - blocks);
+
+ blocks = -blocks;
+ for (i = -1; i >= blocks; --i) {
+ swap_table_mem[new_limit + i] = swap_table_mem[limit + i];
+ swap_table_mem[limit + i] = 0x55555555;
+ }
+#endif
}
-#endif /* INDIRECT_SWAP */
#ifndef INDIRECT_SWAP
void swap_init(int n_blocks)
0,
#ifndef INDIRECT_SWAP
n_blocks,
- NULL,
#else /* INDIRECT_SWAP */
table_size,
- swap_move,
#endif /* INDIRECT_SWAP */
- NULL
+ swap_move,
+ swap_move_up
);
#ifdef INDIRECT_SWAP