summaryrefslogtreecommitdiffstats
path: root/sys/vm/vm_object.h
diff options
context:
space:
mode:
authorattilio <attilio@FreeBSD.org>2013-03-09 02:32:23 +0000
committerattilio <attilio@FreeBSD.org>2013-03-09 02:32:23 +0000
commit72f7f3e528d2e900546a7ccbe16525b12d64dd44 (patch)
tree382de98b1c7b142a92ed9c04ab1ea90d5a1c3a06 /sys/vm/vm_object.h
parent754f3790b85afd6cd15e69b91ee97848364f75f5 (diff)
parent49c5854731cc608c08a92b35c6e2be2825c64a6c (diff)
downloadFreeBSD-src-72f7f3e528d2e900546a7ccbe16525b12d64dd44.zip
FreeBSD-src-72f7f3e528d2e900546a7ccbe16525b12d64dd44.tar.gz
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
Diffstat (limited to 'sys/vm/vm_object.h')
-rw-r--r--sys/vm/vm_object.h37
1 files changed, 25 insertions, 12 deletions
diff --git a/sys/vm/vm_object.h b/sys/vm/vm_object.h
index 319324f..dac90fc 100644
--- a/sys/vm/vm_object.h
+++ b/sys/vm/vm_object.h
@@ -70,15 +70,16 @@
#include <sys/queue.h>
#include <sys/_lock.h>
#include <sys/_mutex.h>
+#include <sys/_rwlock.h>
/*
* Types defined:
*
* vm_object_t Virtual memory object.
*
- * The root of cached pages pool is protected by both the per-object mutex
+ * The root of cached pages pool is protected by both the per-object lock
* and the free pages queue mutex.
- * On insert in the cache splay tree, the per-object mutex is expected
+ * On insert in the cache splay tree, the per-object lock is expected
* to be already held and the free pages queue mutex will be
* acquired during the operation too.
* On remove and lookup from the cache splay tree, only the free
@@ -89,13 +90,13 @@
*
* List of locks
* (c) const until freed
- * (o) per-object mutex
+ * (o) per-object lock
* (f) free pages queue mutex
*
*/
struct vm_object {
- struct mtx mtx;
+ struct rwlock lock;
TAILQ_ENTRY(vm_object) object_list; /* list of all objects */
LIST_HEAD(, vm_object) shadow_head; /* objects that this is a shadow for */
LIST_ENTRY(vm_object) shadow_list; /* chain of shadow objects */
@@ -203,14 +204,26 @@ extern struct vm_object kmem_object_store;
#define kernel_object (&kernel_object_store)
#define kmem_object (&kmem_object_store)
-#define VM_OBJECT_LOCK(object) mtx_lock(&(object)->mtx)
-#define VM_OBJECT_LOCK_ASSERT(object, type) \
- mtx_assert(&(object)->mtx, (type))
-#define VM_OBJECT_SLEEP(object, wchan, pri, wmesg, timo) \
- msleep((wchan), &(object)->mtx, (pri), \
- (wmesg), (timo))
-#define VM_OBJECT_TRYLOCK(object) mtx_trylock(&(object)->mtx)
-#define VM_OBJECT_UNLOCK(object) mtx_unlock(&(object)->mtx)
+#define VM_OBJECT_ASSERT_LOCKED(object) \
+ rw_assert(&(object)->lock, RA_LOCKED)
+#define VM_OBJECT_ASSERT_RLOCKED(object) \
+ rw_assert(&(object)->lock, RA_RLOCKED)
+#define VM_OBJECT_ASSERT_WLOCKED(object) \
+ rw_assert(&(object)->lock, RA_WLOCKED)
+#define VM_OBJECT_RLOCK(object) \
+ rw_rlock(&(object)->lock)
+#define VM_OBJECT_RUNLOCK(object) \
+ rw_runlock(&(object)->lock)
+#define VM_OBJECT_SLEEP(object, wchan, pri, wmesg, timo) \
+ rw_sleep((wchan), &(object)->lock, (pri), (wmesg), (timo))
+#define VM_OBJECT_TRYRLOCK(object) \
+ rw_try_rlock(&(object)->lock)
+#define VM_OBJECT_TRYWLOCK(object) \
+ rw_try_wlock(&(object)->lock)
+#define VM_OBJECT_WLOCK(object) \
+ rw_wlock(&(object)->lock)
+#define VM_OBJECT_WUNLOCK(object) \
+ rw_wunlock(&(object)->lock)
/*
* The object must be locked or thread private.
OpenPOWER on IntegriCloud