Changeset View
Changeset View
Standalone View
Standalone View
swap_pager.c
Show First 20 Lines • Show All 900 Lines • ▼ Show 20 Lines | swap_pager_reserve(vm_object_t object, vm_pindex_t start, vm_size_t size) | ||||
daddr_t addr, blk, n_free, s_free; | daddr_t addr, blk, n_free, s_free; | ||||
int i, j, n; | int i, j, n; | ||||
swp_pager_init_freerange(&s_free, &n_free); | swp_pager_init_freerange(&s_free, &n_free); | ||||
VM_OBJECT_WLOCK(object); | VM_OBJECT_WLOCK(object); | ||||
for (i = 0; i < size; i += n) { | for (i = 0; i < size; i += n) { | ||||
n = size - i; | n = size - i; | ||||
blk = swp_pager_getswapspace(&n, 1); | blk = swp_pager_getswapspace(&n, 1); | ||||
if (blk == SWAPBLK_NONE && n_free > 0) { | |||||
blk = s_free; | |||||
if (n < n_free) { | |||||
s_free += n; | |||||
n_free -= n; | |||||
} else { | |||||
n = n_free; | |||||
swp_pager_init_freerange(&s_free, &n_free); | |||||
} | |||||
} | |||||
if (blk == SWAPBLK_NONE) { | if (blk == SWAPBLK_NONE) { | ||||
swp_pager_meta_free(object, start, i); | swp_pager_meta_free(object, start, i); | ||||
VM_OBJECT_WUNLOCK(object); | break; | ||||
return (-1); | |||||
} | } | ||||
for (j = 0; j < n; ++j) { | for (j = 0; j < n; ++j) { | ||||
addr = swp_pager_meta_build(object, | addr = swp_pager_meta_build(object, | ||||
start + i + j, blk + j); | start + i + j, blk + j); | ||||
if (addr != SWAPBLK_NONE) | if (addr != SWAPBLK_NONE) | ||||
swp_pager_update_freerange(&s_free, &n_free, | swp_pager_update_freerange(&s_free, &n_free, | ||||
addr); | addr); | ||||
} | } | ||||
} | } | ||||
swp_pager_freeswapspace(s_free, n_free); | swp_pager_freeswapspace(s_free, n_free); | ||||
VM_OBJECT_WUNLOCK(object); | VM_OBJECT_WUNLOCK(object); | ||||
return (0); | return (i == size ? 0 : -1); | ||||
} | } | ||||
/* | /* | ||||
* SWAP_PAGER_COPY() - copy blocks from source pager to destination pager | * SWAP_PAGER_COPY() - copy blocks from source pager to destination pager | ||||
* and destroy the source. | * and destroy the source. | ||||
* | * | ||||
* Copy any valid swapblks from the source to the destination. In | * Copy any valid swapblks from the source to the destination. In | ||||
* cases where both the source and destination have a valid swapblk, | * cases where both the source and destination have a valid swapblk, | ||||
▲ Show 20 Lines • Show All 2,059 Lines • Show Last 20 Lines |