summaryrefslogtreecommitdiffstats
path: root/sys/vm
diff options
context:
space:
mode:
authorjhb <jhb@FreeBSD.org>2011-11-04 04:02:50 +0000
committerjhb <jhb@FreeBSD.org>2011-11-04 04:02:50 +0000
commit78c075174e74e727279365476d0d076d6c3e3075 (patch)
tree159ae25b13b965df34d0e93885cca08178c0b2a2 /sys/vm
parent1e2d8c9d67bc3fa3bf3a560b9b8eac1745104048 (diff)
downloadFreeBSD-src-78c075174e74e727279365476d0d076d6c3e3075.zip
FreeBSD-src-78c075174e74e727279365476d0d076d6c3e3075.tar.gz
Add the posix_fadvise(2) system call. It is somewhat similar to
madvise(2) except that it operates on a file descriptor instead of a memory region. It is currently only supported on regular files. Just as with madvise(2), the advice given to posix_fadvise(2) can be divided into two types. The first type provide hints about data access patterns and are used in the file read and write routines to modify the I/O flags passed down to VOP_READ() and VOP_WRITE(). These modes are thus filesystem independent. Note that to ease implementation (and since this API is only advisory anyway), only a single non-normal range is allowed per file descriptor. The second type of hints are used to hint to the OS that data will or will not be used. These hints are implemented via a new VOP_ADVISE(). A default implementation is provided which does nothing for the WILLNEED request and attempts to move any clean pages to the cache page queue for the DONTNEED request. This latter case required two other changes. First, a new V_CLEANONLY flag was added to vinvalbuf(). This requests vinvalbuf() to only flush clean buffers for the vnode from the buffer cache and to not remove any backing pages from the vnode. This is used to ensure clean pages are not wired into the buffer cache before attempting to move them to the cache page queue. The second change adds a new vm_object_page_cache() method. This method is somewhat similar to vm_object_page_remove() except that instead of freeing each page in the specified range, it attempts to move clean pages to the cache queue if possible. To preserve the ABI of struct file, the f_cdevpriv pointer is now reused in a union to point to the currently active advice region if one is present for regular files. Reviewed by: jilles, kib, arch@ Approved by: re (kib) MFC after: 1 month
Diffstat (limited to 'sys/vm')
-rw-r--r--sys/vm/vm_object.c54
-rw-r--r--sys/vm/vm_object.h2
2 files changed, 56 insertions, 0 deletions
diff --git a/sys/vm/vm_object.c b/sys/vm/vm_object.c
index 3de793b..600dea8 100644
--- a/sys/vm/vm_object.c
+++ b/sys/vm/vm_object.c
@@ -1863,6 +1863,60 @@ skipmemq:
}
/*
+ * vm_object_page_cache:
+ *
+ * For the given object, attempt to move the specified clean
+ * pages to the cache queue. If a page is wired for any reason,
+ * then it will not be changed. Pages are specified by the given
+ * range ["start", "end"). As a special case, if "end" is zero,
+ * then the range extends from "start" to the end of the object.
+ * Any mappings to the specified pages are removed before the
+ * pages are moved to the cache queue.
+ *
+ * This operation should only be performed on objects that
+ * contain managed pages.
+ *
+ * The object must be locked.
+ */
+void
+vm_object_page_cache(vm_object_t object, vm_pindex_t start, vm_pindex_t end)
+{
+ struct mtx *mtx, *new_mtx;
+ vm_page_t p, next;
+
+ VM_OBJECT_LOCK_ASSERT(object, MA_OWNED);
+ KASSERT((object->type != OBJT_DEVICE && object->type != OBJT_SG &&
+ object->type != OBJT_PHYS),
+ ("vm_object_page_cache: illegal object %p", object));
+ if (object->resident_page_count == 0)
+ return;
+ p = vm_page_find_least(object, start);
+
+ /*
+ * Here, the variable "p" is either (1) the page with the least pindex
+ * greater than or equal to the parameter "start" or (2) NULL.
+ */
+ mtx = NULL;
+ for (; p != NULL && (p->pindex < end || end == 0); p = next) {
+ next = TAILQ_NEXT(p, listq);
+
+ /*
+ * Avoid releasing and reacquiring the same page lock.
+ */
+ new_mtx = vm_page_lockptr(p);
+ if (mtx != new_mtx) {
+ if (mtx != NULL)
+ mtx_unlock(mtx);
+ mtx = new_mtx;
+ mtx_lock(mtx);
+ }
+ vm_page_try_to_cache(p);
+ }
+ if (mtx != NULL)
+ mtx_unlock(mtx);
+}
+
+/*
* Populate the specified range of the object with valid pages. Returns
* TRUE if the range is successfully populated and FALSE otherwise.
*
diff --git a/sys/vm/vm_object.h b/sys/vm/vm_object.h
index a11f144..0c13786 100644
--- a/sys/vm/vm_object.h
+++ b/sys/vm/vm_object.h
@@ -223,6 +223,8 @@ void vm_object_destroy (vm_object_t);
void vm_object_terminate (vm_object_t);
void vm_object_set_writeable_dirty (vm_object_t);
void vm_object_init (void);
+void vm_object_page_cache(vm_object_t object, vm_pindex_t start,
+ vm_pindex_t end);
void vm_object_page_clean(vm_object_t object, vm_ooffset_t start,
vm_ooffset_t end, int flags);
void vm_object_page_remove(vm_object_t object, vm_pindex_t start,
OpenPOWER on IntegriCloud