kernel - Enhance vm_page_lookup_sbusy_try() API
authorMatthew Dillon <dillon@apollo.backplane.com>
Fri, 20 Oct 2017 19:01:03 +0000 (12:01 -0700)
committerMatthew Dillon <dillon@apollo.backplane.com>
Tue, 31 Oct 2017 17:49:47 +0000 (10:49 -0700)
* Add a pgoff/pgbytes to allow a more fine-grained test of the
  page's validity.  Will be used by kern_sendfile().

sys/kern/vfs_helper.c
sys/vm/vm_fault.c
sys/vm/vm_page.c
sys/vm/vm_page.h

index cb8190e..d582e04 100644 (file)
@@ -348,7 +348,8 @@ vop_helper_read_shortcut(struct vop_read_args *ap)
                if (n == 0)
                        break;  /* hit EOF */
 
-               m = vm_page_lookup_sbusy_try(obj, OFF_TO_IDX(uio->uio_offset));
+               m = vm_page_lookup_sbusy_try(obj, OFF_TO_IDX(uio->uio_offset),
+                                            0, PAGE_SIZE);
                if (error || m == NULL) {
                        error = 0;
                        break;
index fe3b9d7..81b6fe4 100644 (file)
@@ -3066,7 +3066,8 @@ vm_prefault_quick(pmap_t pmap, vm_offset_t addra,
                 * and hard-busy it so we can move it out of PQ_CACHE.
                 */
                if ((prot & (VM_PROT_WRITE|VM_PROT_OVERRIDE_WRITE)) == 0) {
-                       m = vm_page_lookup_sbusy_try(object, pindex);
+                       m = vm_page_lookup_sbusy_try(object, pindex,
+                                                    0, PAGE_SIZE);
                        if (m == NULL)
                                break;
                        if ((m->queue - m->pc) != PQ_CACHE) {
index 995c16b..bd54912 100644 (file)
@@ -1374,19 +1374,22 @@ VM_PAGE_DEBUG_EXT(vm_page_lookup_busy_try)(struct vm_object *object,
  * the soft busy could not be obtained, or the page data is invalid.
  */
 vm_page_t
-vm_page_lookup_sbusy_try(struct vm_object *object, vm_pindex_t pindex)
+vm_page_lookup_sbusy_try(struct vm_object *object, vm_pindex_t pindex,
+                        int pgoff, int pgbytes)
 {
        vm_page_t m;
 
        ASSERT_LWKT_TOKEN_HELD(vm_object_token(object));
        m = vm_page_rb_tree_RB_LOOKUP(&object->rb_memq, pindex);
        if (m) {
-               if (m->valid != VM_PAGE_BITS_ALL ||
+               if ((m->valid != VM_PAGE_BITS_ALL &&
+                    !vm_page_is_valid(m, pgoff, pgbytes)) ||
                    (m->flags & PG_FICTITIOUS)) {
                        m = NULL;
                } else if (vm_page_sbusy_try(m)) {
                        m = NULL;
-               } else if (m->valid != VM_PAGE_BITS_ALL ||
+               } else if ((m->valid != VM_PAGE_BITS_ALL &&
+                           !vm_page_is_valid(m, pgoff, pgbytes)) ||
                           (m->flags & PG_FICTITIOUS)) {
                        vm_page_sbusy_drop(m);
                        m = NULL;
index f6ed1ff..d1c44fc 100644 (file)
@@ -375,7 +375,7 @@ void vm_page_initfake(vm_page_t m, vm_paddr_t paddr, vm_memattr_t memattr);
 int vm_page_insert (vm_page_t, struct vm_object *, vm_pindex_t);
 vm_page_t vm_page_lookup (struct vm_object *, vm_pindex_t);
 vm_page_t vm_page_lookup_sbusy_try(struct vm_object *object,
-               vm_pindex_t pindex);
+               vm_pindex_t pindex, int pgoff, int pgbytes);
 vm_page_t VM_PAGE_DEBUG_EXT(vm_page_lookup_busy_wait)(
                struct vm_object *, vm_pindex_t, int, const char *
                VM_PAGE_DEBUG_ARGS);