aboutsummaryrefslogtreecommitdiff
path: root/sys/vm/vm_kern.c
diff options
context:
space:
mode:
authorAttilio Rao <attilio@FreeBSD.org>2013-03-09 02:32:23 +0000
committerAttilio Rao <attilio@FreeBSD.org>2013-03-09 02:32:23 +0000
commit89f6b8632cc94bca2738b4fcc26e1189ef4f5dde (patch)
tree382de98b1c7b142a92ed9c04ab1ea90d5a1c3a06 /sys/vm/vm_kern.c
parentc934116100c5a3574cb1bde0dc0b80b6b41d7e54 (diff)
downloadsrc-89f6b8632cc94bca2738b4fcc26e1189ef4f5dde.tar.gz
src-89f6b8632cc94bca2738b4fcc26e1189ef4f5dde.zip
Switch the vm_object mutex to be a rwlock. This will enable in the
future further optimizations where the vm_object lock will be held in read mode most of the time the page cache resident pool of pages are accessed for reading purposes. The change is mostly mechanical but few notes are reported: * The KPI changes as follow: - VM_OBJECT_LOCK() -> VM_OBJECT_WLOCK() - VM_OBJECT_TRYLOCK() -> VM_OBJECT_TRYWLOCK() - VM_OBJECT_UNLOCK() -> VM_OBJECT_WUNLOCK() - VM_OBJECT_LOCK_ASSERT(MA_OWNED) -> VM_OBJECT_ASSERT_WLOCKED() (in order to avoid visibility of implementation details) - The read-mode operations are added: VM_OBJECT_RLOCK(), VM_OBJECT_TRYRLOCK(), VM_OBJECT_RUNLOCK(), VM_OBJECT_ASSERT_RLOCKED(), VM_OBJECT_ASSERT_LOCKED() * The vm/vm_pager.h namespace pollution avoidance (forcing requiring sys/mutex.h in consumers directly to cater its inlining functions using VM_OBJECT_LOCK()) imposes that all the vm/vm_pager.h consumers now must include also sys/rwlock.h. * zfs requires a quite convoluted fix to include FreeBSD rwlocks into the compat layer because the name clash between FreeBSD and solaris versions must be avoided. At this purpose zfs redefines the vm_object locking functions directly, isolating the FreeBSD components in specific compat stubs. The KPI results heavilly broken by this commit. Thirdy part ports must be updated accordingly (I can think off-hand of VirtualBox, for example). Sponsored by: EMC / Isilon storage division Reviewed by: jeff Reviewed by: pjd (ZFS specific review) Discussed with: alc Tested by: pho
Notes
Notes: svn path=/head/; revision=248084
Diffstat (limited to 'sys/vm/vm_kern.c')
-rw-r--r--sys/vm/vm_kern.c32
1 files changed, 16 insertions, 16 deletions
diff --git a/sys/vm/vm_kern.c b/sys/vm/vm_kern.c
index ad9aa0dfa7e0..9f602b7d45ed 100644
--- a/sys/vm/vm_kern.c
+++ b/sys/vm/vm_kern.c
@@ -70,9 +70,9 @@ __FBSDID("$FreeBSD$");
#include <sys/kernel.h> /* for ticks and hz */
#include <sys/eventhandler.h>
#include <sys/lock.h>
-#include <sys/mutex.h>
#include <sys/proc.h>
#include <sys/malloc.h>
+#include <sys/rwlock.h>
#include <sys/sysctl.h>
#include <vm/vm.h>
@@ -234,7 +234,7 @@ kmem_alloc_attr(vm_map_t map, vm_size_t size, int flags, vm_paddr_t low,
vm_map_insert(map, object, offset, addr, addr + size, VM_PROT_ALL,
VM_PROT_ALL, 0);
pflags = malloc2vm_flags(flags) | VM_ALLOC_NOBUSY;
- VM_OBJECT_LOCK(object);
+ VM_OBJECT_WLOCK(object);
end_offset = offset + size;
for (; offset < end_offset; offset += PAGE_SIZE) {
tries = 0;
@@ -242,12 +242,12 @@ retry:
m = vm_page_alloc_contig(object, OFF_TO_IDX(offset), pflags, 1,
low, high, PAGE_SIZE, 0, memattr);
if (m == NULL) {
- VM_OBJECT_UNLOCK(object);
+ VM_OBJECT_WUNLOCK(object);
if (tries < ((flags & M_NOWAIT) != 0 ? 1 : 3)) {
vm_map_unlock(map);
vm_pageout_grow_cache(tries, low, high);
vm_map_lock(map);
- VM_OBJECT_LOCK(object);
+ VM_OBJECT_WLOCK(object);
tries++;
goto retry;
}
@@ -266,7 +266,7 @@ retry:
pmap_zero_page(m);
m->valid = VM_PAGE_BITS_ALL;
}
- VM_OBJECT_UNLOCK(object);
+ VM_OBJECT_WUNLOCK(object);
vm_map_unlock(map);
vm_map_wire(map, addr, addr + size, VM_MAP_WIRE_SYSTEM |
VM_MAP_WIRE_NOHOLES);
@@ -303,18 +303,18 @@ kmem_alloc_contig(vm_map_t map, vm_size_t size, int flags, vm_paddr_t low,
vm_map_insert(map, object, offset, addr, addr + size, VM_PROT_ALL,
VM_PROT_ALL, 0);
pflags = malloc2vm_flags(flags) | VM_ALLOC_NOBUSY;
- VM_OBJECT_LOCK(object);
+ VM_OBJECT_WLOCK(object);
tries = 0;
retry:
m = vm_page_alloc_contig(object, OFF_TO_IDX(offset), pflags,
atop(size), low, high, alignment, boundary, memattr);
if (m == NULL) {
- VM_OBJECT_UNLOCK(object);
+ VM_OBJECT_WUNLOCK(object);
if (tries < ((flags & M_NOWAIT) != 0 ? 1 : 3)) {
vm_map_unlock(map);
vm_pageout_grow_cache(tries, low, high);
vm_map_lock(map);
- VM_OBJECT_LOCK(object);
+ VM_OBJECT_WLOCK(object);
tries++;
goto retry;
}
@@ -328,7 +328,7 @@ retry:
pmap_zero_page(m);
m->valid = VM_PAGE_BITS_ALL;
}
- VM_OBJECT_UNLOCK(object);
+ VM_OBJECT_WUNLOCK(object);
vm_map_unlock(map);
vm_map_wire(map, addr, addr + size, VM_MAP_WIRE_SYSTEM |
VM_MAP_WIRE_NOHOLES);
@@ -488,7 +488,7 @@ kmem_back(vm_map_t map, vm_offset_t addr, vm_size_t size, int flags)
pflags = malloc2vm_flags(flags) | VM_ALLOC_WIRED;
- VM_OBJECT_LOCK(kmem_object);
+ VM_OBJECT_WLOCK(kmem_object);
for (i = 0; i < size; i += PAGE_SIZE) {
retry:
m = vm_page_alloc(kmem_object, OFF_TO_IDX(offset + i), pflags);
@@ -500,7 +500,7 @@ retry:
*/
if (m == NULL) {
if ((flags & M_NOWAIT) == 0) {
- VM_OBJECT_UNLOCK(kmem_object);
+ VM_OBJECT_WUNLOCK(kmem_object);
entry->eflags |= MAP_ENTRY_IN_TRANSITION;
vm_map_unlock(map);
VM_WAIT;
@@ -510,7 +510,7 @@ retry:
MAP_ENTRY_IN_TRANSITION,
("kmem_back: volatile entry"));
entry->eflags &= ~MAP_ENTRY_IN_TRANSITION;
- VM_OBJECT_LOCK(kmem_object);
+ VM_OBJECT_WLOCK(kmem_object);
goto retry;
}
/*
@@ -526,7 +526,7 @@ retry:
vm_page_unwire(m, 0);
vm_page_free(m);
}
- VM_OBJECT_UNLOCK(kmem_object);
+ VM_OBJECT_WUNLOCK(kmem_object);
vm_map_delete(map, addr, addr + size);
return (KERN_NO_SPACE);
}
@@ -536,7 +536,7 @@ retry:
KASSERT((m->oflags & VPO_UNMANAGED) != 0,
("kmem_malloc: page %p is managed", m));
}
- VM_OBJECT_UNLOCK(kmem_object);
+ VM_OBJECT_WUNLOCK(kmem_object);
/*
* Mark map entry as non-pageable. Repeat the assert.
@@ -556,7 +556,7 @@ retry:
/*
* Loop thru pages, entering them in the pmap.
*/
- VM_OBJECT_LOCK(kmem_object);
+ VM_OBJECT_WLOCK(kmem_object);
for (i = 0; i < size; i += PAGE_SIZE) {
m = vm_page_lookup(kmem_object, OFF_TO_IDX(offset + i));
/*
@@ -566,7 +566,7 @@ retry:
TRUE);
vm_page_wakeup(m);
}
- VM_OBJECT_UNLOCK(kmem_object);
+ VM_OBJECT_WUNLOCK(kmem_object);
return (KERN_SUCCESS);
}