summaryrefslogtreecommitdiff
path: root/sys/kern
diff options
context:
space:
mode:
authorAriane van der Steldt <ariane@cvs.openbsd.org>2011-07-08 18:25:57 +0000
committerAriane van der Steldt <ariane@cvs.openbsd.org>2011-07-08 18:25:57 +0000
commit48142241ec73b235e102c03fa64123d49a404e71 (patch)
treedd15a3a9398d676617f481f94b26cb905b6b7538 /sys/kern
parent2938779744ddbf102425f64fa0f4d6f7993d1c89 (diff)
Move uvm_pmr_alloc_pig to kern/subr_hibernate.c
No callers, no functional change.
Diffstat (limited to 'sys/kern')
-rw-r--r--sys/kern/subr_hibernate.c46
1 files changed, 45 insertions, 1 deletions
diff --git a/sys/kern/subr_hibernate.c b/sys/kern/subr_hibernate.c
index f9159b5853e..b071538a289 100644
--- a/sys/kern/subr_hibernate.c
+++ b/sys/kern/subr_hibernate.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: subr_hibernate.c,v 1.2 2011/07/08 18:20:10 ariane Exp $ */
+/* $OpenBSD: subr_hibernate.c,v 1.3 2011/07/08 18:25:56 ariane Exp $ */
/*
* Copyright (c) 2011 Ariane van der Steldt <ariane@stack.nl>
@@ -262,3 +262,47 @@ uvm_pmr_zero_everything(void)
}
uvm_unlock_fpageq();
}
+
+/*
+ * Allocate the biggest contig chunk of memory.
+ */
+int
+uvm_pmr_alloc_pig(paddr_t *addr, psize_t *sz)
+{
+ struct uvm_pmemrange *pig_pmr, *pmr;
+ struct vm_page *pig_pg, *pg;
+ int memtype;
+
+ uvm_lock_fpageq();
+ pig_pg = NULL;
+ TAILQ_FOREACH(pmr, &uvm.pmr_control.use, pmr_use) {
+ for (memtype = 0; memtype < UVM_PMR_MEMTYPE_MAX; memtype++) {
+ /* Find biggest page in this memtype pmr. */
+ pg = RB_MAX(uvm_pmr_size, &pmr->size[memtype]);
+ if (pg == NULL)
+ pg = TAILQ_FIRST(&pmr->single[memtype]);
+ else
+ pg--;
+
+ if (pig_pg == NULL || (pg != NULL && pig_pg != NULL &&
+ pig_pg->fpgsz < pg->fpgsz)) {
+ pig_pmr = pmr;
+ pig_pg = pg;
+ }
+ }
+ }
+
+ /* Remove page from freelist. */
+ if (pig_pg != NULL) {
+ uvm_pmr_remove(pig_pmr, pig_pg);
+ uvmexp.free -= pig_pg->fpgsz;
+ if (pig_pg->pg_flags & PG_ZERO)
+ uvmexp.zeropages -= pig_pg->fpgsz;
+ *addr = VM_PAGE_TO_PHYS(pig_pg);
+ *sz = pig_pg->fpgsz;
+ }
+ uvm_unlock_fpageq();
+
+ /* Return. */
+ return (pig_pg != NULL ? 0 : ENOMEM);
+}