Simplify the various pager allocation routines by computing the desired
object size once and assigning that value to a local variable.
This commit is contained in:
parent
6e3aaeb2d7
commit
2f7af3db57
@ -108,6 +108,7 @@ dev_pager_alloc(void *handle, vm_ooffset_t size, vm_prot_t prot, vm_ooffset_t fo
|
||||
dev_t dev;
|
||||
d_mmap_t *mapfunc;
|
||||
vm_object_t object;
|
||||
vm_pindex_t pindex;
|
||||
unsigned int npages;
|
||||
vm_paddr_t paddr;
|
||||
vm_offset_t off;
|
||||
@ -119,6 +120,7 @@ dev_pager_alloc(void *handle, vm_ooffset_t size, vm_prot_t prot, vm_ooffset_t fo
|
||||
return (NULL);
|
||||
|
||||
size = round_page(size);
|
||||
pindex = OFF_TO_IDX(foff + size);
|
||||
|
||||
/*
|
||||
* Make sure this device can be mapped.
|
||||
@ -158,8 +160,7 @@ dev_pager_alloc(void *handle, vm_ooffset_t size, vm_prot_t prot, vm_ooffset_t fo
|
||||
/*
|
||||
* Allocate object and associate it with the pager.
|
||||
*/
|
||||
object = vm_object_allocate(OBJT_DEVICE,
|
||||
OFF_TO_IDX(foff + size));
|
||||
object = vm_object_allocate(OBJT_DEVICE, pindex);
|
||||
object->handle = handle;
|
||||
TAILQ_INIT(&object->un_pager.devp.devp_pglist);
|
||||
mtx_lock(&dev_pager_mtx);
|
||||
@ -170,8 +171,8 @@ dev_pager_alloc(void *handle, vm_ooffset_t size, vm_prot_t prot, vm_ooffset_t fo
|
||||
* Gain a reference to the object.
|
||||
*/
|
||||
vm_object_reference(object);
|
||||
if (OFF_TO_IDX(foff + size) > object->size)
|
||||
object->size = OFF_TO_IDX(foff + size);
|
||||
if (pindex > object->size)
|
||||
object->size = pindex;
|
||||
}
|
||||
|
||||
sx_xunlock(&dev_pager_sx);
|
||||
|
@ -65,6 +65,7 @@ phys_pager_alloc(void *handle, vm_ooffset_t size, vm_prot_t prot,
|
||||
vm_ooffset_t foff)
|
||||
{
|
||||
vm_object_t object;
|
||||
vm_pindex_t pindex;
|
||||
|
||||
/*
|
||||
* Offset should be page aligned.
|
||||
@ -72,7 +73,7 @@ phys_pager_alloc(void *handle, vm_ooffset_t size, vm_prot_t prot,
|
||||
if (foff & PAGE_MASK)
|
||||
return (NULL);
|
||||
|
||||
size = round_page(size);
|
||||
pindex = OFF_TO_IDX(foff + PAGE_MASK + size);
|
||||
|
||||
if (handle != NULL) {
|
||||
mtx_lock(&Giant);
|
||||
@ -93,8 +94,7 @@ phys_pager_alloc(void *handle, vm_ooffset_t size, vm_prot_t prot,
|
||||
/*
|
||||
* Allocate object and associate it with the pager.
|
||||
*/
|
||||
object = vm_object_allocate(OBJT_PHYS,
|
||||
OFF_TO_IDX(foff + size));
|
||||
object = vm_object_allocate(OBJT_PHYS, pindex);
|
||||
object->handle = handle;
|
||||
mtx_lock(&phys_pager_mtx);
|
||||
TAILQ_INSERT_TAIL(&phys_pager_object_list, object,
|
||||
@ -105,16 +105,15 @@ phys_pager_alloc(void *handle, vm_ooffset_t size, vm_prot_t prot,
|
||||
* Gain a reference to the object.
|
||||
*/
|
||||
vm_object_reference(object);
|
||||
if (OFF_TO_IDX(foff + size) > object->size)
|
||||
object->size = OFF_TO_IDX(foff + size);
|
||||
if (pindex > object->size)
|
||||
object->size = pindex;
|
||||
}
|
||||
if (phys_pager_alloc_lock == -1)
|
||||
wakeup(&phys_pager_alloc_lock);
|
||||
phys_pager_alloc_lock = 0;
|
||||
mtx_unlock(&Giant);
|
||||
} else {
|
||||
object = vm_object_allocate(OBJT_PHYS,
|
||||
OFF_TO_IDX(foff + size));
|
||||
object = vm_object_allocate(OBJT_PHYS, pindex);
|
||||
}
|
||||
|
||||
return (object);
|
||||
|
@ -472,6 +472,9 @@ swap_pager_alloc(void *handle, vm_ooffset_t size, vm_prot_t prot,
|
||||
vm_ooffset_t offset)
|
||||
{
|
||||
vm_object_t object;
|
||||
vm_pindex_t pindex;
|
||||
|
||||
pindex = OFF_TO_IDX(offset + PAGE_MASK + size);
|
||||
|
||||
if (handle) {
|
||||
mtx_lock(&Giant);
|
||||
@ -487,8 +490,7 @@ swap_pager_alloc(void *handle, vm_ooffset_t size, vm_prot_t prot,
|
||||
if (object != NULL) {
|
||||
vm_object_reference(object);
|
||||
} else {
|
||||
object = vm_object_allocate(OBJT_DEFAULT,
|
||||
OFF_TO_IDX(offset + PAGE_MASK + size));
|
||||
object = vm_object_allocate(OBJT_DEFAULT, pindex);
|
||||
object->handle = handle;
|
||||
|
||||
VM_OBJECT_LOCK(object);
|
||||
@ -498,8 +500,7 @@ swap_pager_alloc(void *handle, vm_ooffset_t size, vm_prot_t prot,
|
||||
sx_xunlock(&sw_alloc_sx);
|
||||
mtx_unlock(&Giant);
|
||||
} else {
|
||||
object = vm_object_allocate(OBJT_DEFAULT,
|
||||
OFF_TO_IDX(offset + PAGE_MASK + size));
|
||||
object = vm_object_allocate(OBJT_DEFAULT, pindex);
|
||||
|
||||
VM_OBJECT_LOCK(object);
|
||||
swp_pager_meta_build(object, 0, SWAPBLK_NONE);
|
||||
|
Loading…
Reference in New Issue
Block a user