diff options
author | alc <alc@FreeBSD.org> | 2004-01-04 20:55:15 +0000 |
---|---|---|
committer | alc <alc@FreeBSD.org> | 2004-01-04 20:55:15 +0000 |
commit | 8c0190db49bd4397a735eef56aa617b16862cb56 (patch) | |
tree | ca5c1935c2a900d3b0964519f7419f8fb918f9a2 | |
parent | 6fde69b7d17726e5071e0aeb2f166836ab07b949 (diff) | |
download | FreeBSD-src-8c0190db49bd4397a735eef56aa617b16862cb56.zip FreeBSD-src-8c0190db49bd4397a735eef56aa617b16862cb56.tar.gz |
Simplify the various pager allocation routines by computing the desired
object size once and assigning that value to a local variable.
-rw-r--r-- | sys/vm/device_pager.c | 9 | ||||
-rw-r--r-- | sys/vm/phys_pager.c | 13 | ||||
-rw-r--r-- | sys/vm/swap_pager.c | 9 |
3 files changed, 16 insertions, 15 deletions
diff --git a/sys/vm/device_pager.c b/sys/vm/device_pager.c index 24186bf..5dc8898 100644 --- a/sys/vm/device_pager.c +++ b/sys/vm/device_pager.c @@ -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); diff --git a/sys/vm/phys_pager.c b/sys/vm/phys_pager.c index 6a2e191..3840004 100644 --- a/sys/vm/phys_pager.c +++ b/sys/vm/phys_pager.c @@ -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); diff --git a/sys/vm/swap_pager.c b/sys/vm/swap_pager.c index c3ba2ee..2323aef 100644 --- a/sys/vm/swap_pager.c +++ b/sys/vm/swap_pager.c @@ -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); |