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;
|
dev_t dev;
|
||||||
d_mmap_t *mapfunc;
|
d_mmap_t *mapfunc;
|
||||||
vm_object_t object;
|
vm_object_t object;
|
||||||
|
vm_pindex_t pindex;
|
||||||
unsigned int npages;
|
unsigned int npages;
|
||||||
vm_paddr_t paddr;
|
vm_paddr_t paddr;
|
||||||
vm_offset_t off;
|
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);
|
return (NULL);
|
||||||
|
|
||||||
size = round_page(size);
|
size = round_page(size);
|
||||||
|
pindex = OFF_TO_IDX(foff + size);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Make sure this device can be mapped.
|
* 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.
|
* Allocate object and associate it with the pager.
|
||||||
*/
|
*/
|
||||||
object = vm_object_allocate(OBJT_DEVICE,
|
object = vm_object_allocate(OBJT_DEVICE, pindex);
|
||||||
OFF_TO_IDX(foff + size));
|
|
||||||
object->handle = handle;
|
object->handle = handle;
|
||||||
TAILQ_INIT(&object->un_pager.devp.devp_pglist);
|
TAILQ_INIT(&object->un_pager.devp.devp_pglist);
|
||||||
mtx_lock(&dev_pager_mtx);
|
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.
|
* Gain a reference to the object.
|
||||||
*/
|
*/
|
||||||
vm_object_reference(object);
|
vm_object_reference(object);
|
||||||
if (OFF_TO_IDX(foff + size) > object->size)
|
if (pindex > object->size)
|
||||||
object->size = OFF_TO_IDX(foff + size);
|
object->size = pindex;
|
||||||
}
|
}
|
||||||
|
|
||||||
sx_xunlock(&dev_pager_sx);
|
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_ooffset_t foff)
|
||||||
{
|
{
|
||||||
vm_object_t object;
|
vm_object_t object;
|
||||||
|
vm_pindex_t pindex;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Offset should be page aligned.
|
* 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)
|
if (foff & PAGE_MASK)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
|
|
||||||
size = round_page(size);
|
pindex = OFF_TO_IDX(foff + PAGE_MASK + size);
|
||||||
|
|
||||||
if (handle != NULL) {
|
if (handle != NULL) {
|
||||||
mtx_lock(&Giant);
|
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.
|
* Allocate object and associate it with the pager.
|
||||||
*/
|
*/
|
||||||
object = vm_object_allocate(OBJT_PHYS,
|
object = vm_object_allocate(OBJT_PHYS, pindex);
|
||||||
OFF_TO_IDX(foff + size));
|
|
||||||
object->handle = handle;
|
object->handle = handle;
|
||||||
mtx_lock(&phys_pager_mtx);
|
mtx_lock(&phys_pager_mtx);
|
||||||
TAILQ_INSERT_TAIL(&phys_pager_object_list, object,
|
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.
|
* Gain a reference to the object.
|
||||||
*/
|
*/
|
||||||
vm_object_reference(object);
|
vm_object_reference(object);
|
||||||
if (OFF_TO_IDX(foff + size) > object->size)
|
if (pindex > object->size)
|
||||||
object->size = OFF_TO_IDX(foff + size);
|
object->size = pindex;
|
||||||
}
|
}
|
||||||
if (phys_pager_alloc_lock == -1)
|
if (phys_pager_alloc_lock == -1)
|
||||||
wakeup(&phys_pager_alloc_lock);
|
wakeup(&phys_pager_alloc_lock);
|
||||||
phys_pager_alloc_lock = 0;
|
phys_pager_alloc_lock = 0;
|
||||||
mtx_unlock(&Giant);
|
mtx_unlock(&Giant);
|
||||||
} else {
|
} else {
|
||||||
object = vm_object_allocate(OBJT_PHYS,
|
object = vm_object_allocate(OBJT_PHYS, pindex);
|
||||||
OFF_TO_IDX(foff + size));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (object);
|
return (object);
|
||||||
|
@ -472,6 +472,9 @@ swap_pager_alloc(void *handle, vm_ooffset_t size, vm_prot_t prot,
|
|||||||
vm_ooffset_t offset)
|
vm_ooffset_t offset)
|
||||||
{
|
{
|
||||||
vm_object_t object;
|
vm_object_t object;
|
||||||
|
vm_pindex_t pindex;
|
||||||
|
|
||||||
|
pindex = OFF_TO_IDX(offset + PAGE_MASK + size);
|
||||||
|
|
||||||
if (handle) {
|
if (handle) {
|
||||||
mtx_lock(&Giant);
|
mtx_lock(&Giant);
|
||||||
@ -487,8 +490,7 @@ swap_pager_alloc(void *handle, vm_ooffset_t size, vm_prot_t prot,
|
|||||||
if (object != NULL) {
|
if (object != NULL) {
|
||||||
vm_object_reference(object);
|
vm_object_reference(object);
|
||||||
} else {
|
} else {
|
||||||
object = vm_object_allocate(OBJT_DEFAULT,
|
object = vm_object_allocate(OBJT_DEFAULT, pindex);
|
||||||
OFF_TO_IDX(offset + PAGE_MASK + size));
|
|
||||||
object->handle = handle;
|
object->handle = handle;
|
||||||
|
|
||||||
VM_OBJECT_LOCK(object);
|
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);
|
sx_xunlock(&sw_alloc_sx);
|
||||||
mtx_unlock(&Giant);
|
mtx_unlock(&Giant);
|
||||||
} else {
|
} else {
|
||||||
object = vm_object_allocate(OBJT_DEFAULT,
|
object = vm_object_allocate(OBJT_DEFAULT, pindex);
|
||||||
OFF_TO_IDX(offset + PAGE_MASK + size));
|
|
||||||
|
|
||||||
VM_OBJECT_LOCK(object);
|
VM_OBJECT_LOCK(object);
|
||||||
swp_pager_meta_build(object, 0, SWAPBLK_NONE);
|
swp_pager_meta_build(object, 0, SWAPBLK_NONE);
|
||||||
|
Loading…
Reference in New Issue
Block a user