Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/yamt-pagecache]: src/sys/uvm add a convenient routine for common usage



details:   https://anonhg.NetBSD.org/src/rev/f8f7ff8a1dab
branches:  yamt-pagecache
changeset: 770818:f8f7ff8a1dab
user:      yamt <yamt%NetBSD.org@localhost>
date:      Sun Nov 06 22:04:07 2011 +0000

description:
add a convenient routine for common usage

diffstat:

 sys/uvm/uvm_page_array.c |  30 ++++++++++++++++++++++++++++--
 sys/uvm/uvm_page_array.h |  11 +++++++----
 2 files changed, 35 insertions(+), 6 deletions(-)

diffs (80 lines):

diff -r 8d0e309e3cfc -r f8f7ff8a1dab sys/uvm/uvm_page_array.c
--- a/sys/uvm/uvm_page_array.c  Sun Nov 06 10:15:11 2011 +0000
+++ b/sys/uvm/uvm_page_array.c  Sun Nov 06 22:04:07 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uvm_page_array.c,v 1.1.2.1 2011/11/02 21:55:39 yamt Exp $      */
+/*     $NetBSD: uvm_page_array.c,v 1.1.2.2 2011/11/06 22:04:07 yamt Exp $      */
 
 /*-
  * Copyright (c)2011 YAMAMOTO Takashi,
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uvm_page_array.c,v 1.1.2.1 2011/11/02 21:55:39 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_page_array.c,v 1.1.2.2 2011/11/06 22:04:07 yamt Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -161,3 +161,29 @@
 #endif /* defined(DEBUG) */
        return 0;
 }
+
+/*
+ * uvm_page_array_fill_and_peek:
+ * same as uvm_page_array_peek except that, if the array is empty, try to fill
+ * it first.
+ */
+
+struct vm_page *
+uvm_page_array_fill_and_peek(struct uvm_page_array *a, struct uvm_object *uobj,
+    voff_t off, bool dirtyonly)
+{
+       struct vm_page *pg;
+       int error;
+
+       pg = uvm_page_array_peek(a);
+       if (pg != NULL) {
+               return pg;
+       }
+       error = uvm_page_array_fill(a, uobj, off, dirtyonly);
+       if (error != 0) {
+               return NULL;
+       }
+       pg = uvm_page_array_peek(a);
+       KASSERT(pg != NULL);
+       return pg;
+}
diff -r 8d0e309e3cfc -r f8f7ff8a1dab sys/uvm/uvm_page_array.h
--- a/sys/uvm/uvm_page_array.h  Sun Nov 06 10:15:11 2011 +0000
+++ b/sys/uvm/uvm_page_array.h  Sun Nov 06 22:04:07 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uvm_page_array.h,v 1.1.2.1 2011/11/02 21:55:39 yamt Exp $      */
+/*     $NetBSD: uvm_page_array.h,v 1.1.2.2 2011/11/06 22:04:07 yamt Exp $      */
 
 /*-
  * Copyright (c)2011 YAMAMOTO Takashi,
@@ -41,10 +41,11 @@
  *     struct uvm_page_array ar;
  *
  *     uvm_page_array_init(&ar);
- *     for (uvm_page_array_fill(&ar, ...), pg = uvm_page_array_peek(&ar);
- *         pg != NULL;
- *         uvm_page_array_advance(&ar), pg = uvm_page_array_peek(&ar)) {
+ *     while ((pg = uvm_page_array_fill_and_peek(&ar, uobj, off, ....))
+ *         != NULL) {
+ *             nextoff = pg->offset + PAGE_SIZE;
  *             do_something(pg);
+ *             uvm_page_array_advance(&ar);
  *     }
  *     uvm_page_array_fini(&it);
  */
@@ -64,5 +65,7 @@
 void uvm_page_array_advance(struct uvm_page_array *);
 int uvm_page_array_fill(struct uvm_page_array *, struct uvm_object *,
     voff_t, bool);
+struct vm_page *uvm_page_array_fill_and_peek(struct uvm_page_array *,
+    struct uvm_object *, voff_t, bool);
 
 #endif /* defined(_UVM_UVM_ARRAY_H_) */



Home | Main Index | Thread Index | Old Index