summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorAriane van der Steldt <ariane@cvs.openbsd.org>2011-04-02 12:38:38 +0000
committerAriane van der Steldt <ariane@cvs.openbsd.org>2011-04-02 12:38:38 +0000
commit73d0ca48f3b21edc654d76563a7e9bcf845c06e3 (patch)
tree8b6a72f87e3dc23bfd19cf8bd552f0453d81b6a5 /sys
parent1f78efac1821c14469c471adc993a8948fdd373c (diff)
Count the number of physical pages within a memory range.
Bob needs this. ok art@ bob@ thib@
Diffstat (limited to 'sys')
-rw-r--r--sys/uvm/uvm_page.c27
-rw-r--r--sys/uvm/uvm_page.h5
2 files changed, 30 insertions, 2 deletions
diff --git a/sys/uvm/uvm_page.c b/sys/uvm/uvm_page.c
index d6f6e5418af..82951d1c99f 100644
--- a/sys/uvm/uvm_page.c
+++ b/sys/uvm/uvm_page.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uvm_page.c,v 1.102 2010/08/07 03:50:02 krw Exp $ */
+/* $OpenBSD: uvm_page.c,v 1.103 2011/04/02 12:38:37 ariane Exp $ */
/* $NetBSD: uvm_page.c,v 1.44 2000/11/27 08:40:04 chs Exp $ */
/*
@@ -1464,3 +1464,28 @@ uvm_page_lookup_freelist(struct vm_page *pg)
return (vm_physmem[lcv].free_list);
#endif
}
+
+/*
+ * uvm_pagecount: count the number of physical pages in the address range.
+ */
+psize_t
+uvm_pagecount(struct uvm_constraint_range* constraint)
+{
+ int lcv;
+ psize_t sz;
+ paddr_t low, high;
+ paddr_t ps_low, ps_high;
+
+ /* Algorithm uses page numbers. */
+ low = atop(constraint->ucr_low);
+ high = atop(constraint->ucr_high);
+
+ sz = 0;
+ for (lcv = 0; lcv < vm_nphysseg; lcv++) {
+ ps_low = MAX(low, vm_physmem[lcv].avail_start);
+ ps_high = MIN(high, vm_physmem[lcv].avail_end);
+ if (ps_low < ps_high)
+ sz += ps_high - ps_low;
+ }
+ return sz;
+}
diff --git a/sys/uvm/uvm_page.h b/sys/uvm/uvm_page.h
index 8dc67d3f933..816278f8171 100644
--- a/sys/uvm/uvm_page.h
+++ b/sys/uvm/uvm_page.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: uvm_page.h,v 1.44 2010/06/29 21:25:16 thib Exp $ */
+/* $OpenBSD: uvm_page.h,v 1.45 2011/04/02 12:38:37 ariane Exp $ */
/* $NetBSD: uvm_page.h,v 1.19 2000/12/28 08:24:55 chs Exp $ */
/*
@@ -252,6 +252,9 @@ void uvm_pagezero(struct vm_page *);
void uvm_pagealloc_pg(struct vm_page *, struct uvm_object *,
voff_t, struct vm_anon *);
+struct uvm_constraint_range; /* XXX move to uvm_extern.h? */
+psize_t uvm_pagecount(struct uvm_constraint_range*);
+
int uvm_page_lookup_freelist(struct vm_page *);
#if VM_PHYSSEG_MAX == 1