Module Name: src
Committed By: matt
Date: Fri Jun 3 02:43:43 UTC 2011
Modified Files:
src/sys/uvm [matt-nb5-mips64]: uvm.h uvm_extern.h uvm_map.c uvm_meter.c
uvm_page.c uvm_page.h uvm_pager.c uvm_pdaemon.c uvm_pglist.c
uvm_pglist.h uvm_vnode.c
Log Message:
Rework page free lists to be sorted by color first rather than free_list.
Kept per color PGFL_* counter in each page free list.
Minor cleanups.
To generate a diff of this commit:
cvs rdiff -u -r1.55 -r1.55.16.1 src/sys/uvm/uvm.h
cvs rdiff -u -r1.148.4.2.4.2 -r1.148.4.2.4.3 src/sys/uvm/uvm_extern.h
cvs rdiff -u -r1.263.4.3.4.4 -r1.263.4.3.4.5 src/sys/uvm/uvm_map.c
cvs rdiff -u -r1.49 -r1.49.16.1 src/sys/uvm/uvm_meter.c
cvs rdiff -u -r1.140.6.3.4.3 -r1.140.6.3.4.4 src/sys/uvm/uvm_page.c
cvs rdiff -u -r1.55.14.3 -r1.55.14.4 src/sys/uvm/uvm_page.h
cvs rdiff -u -r1.92.18.1 -r1.92.18.2 src/sys/uvm/uvm_pager.c
cvs rdiff -u -r1.93.4.2 -r1.93.4.2.4.1 src/sys/uvm/uvm_pdaemon.c
cvs rdiff -u -r1.42.16.8 -r1.42.16.9 src/sys/uvm/uvm_pglist.c
cvs rdiff -u -r1.7 -r1.7.16.1 src/sys/uvm/uvm_pglist.h
cvs rdiff -u -r1.90.28.1 -r1.90.28.2 src/sys/uvm/uvm_vnode.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/uvm/uvm.h
diff -u src/sys/uvm/uvm.h:1.55 src/sys/uvm/uvm.h:1.55.16.1
--- src/sys/uvm/uvm.h:1.55 Wed Jun 4 15:06:04 2008
+++ src/sys/uvm/uvm.h Fri Jun 3 02:43:41 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: uvm.h,v 1.55 2008/06/04 15:06:04 ad Exp $ */
+/* uvm.h,v 1.55 2008/06/04 15:06:04 ad Exp */
/*
*
@@ -78,7 +78,7 @@
*/
struct uvm_cpu {
- struct pgfreelist page_free[VM_NFREELIST]; /* unallocated pages */
+ struct pgfreelist *page_free; /* unallocated pages */
int page_free_nextcolor; /* next color to allocate from */
int page_idlezero_next; /* which color to zero next */
bool page_idle_zero; /* TRUE if we should try to zero
@@ -95,7 +95,7 @@
/* vm_page related parameters */
/* vm_page queues */
- struct pgfreelist page_free[VM_NFREELIST]; /* unallocated pages */
+ struct pgfreelist *page_free; /* unallocated pages */
bool page_init_done; /* TRUE if uvm_page_init() finished */
/* page daemon trigger */
Index: src/sys/uvm/uvm_extern.h
diff -u src/sys/uvm/uvm_extern.h:1.148.4.2.4.2 src/sys/uvm/uvm_extern.h:1.148.4.2.4.3
--- src/sys/uvm/uvm_extern.h:1.148.4.2.4.2 Wed May 25 23:58:49 2011
+++ src/sys/uvm/uvm_extern.h Fri Jun 3 02:43:41 2011
@@ -331,8 +331,10 @@
not available */
int zeroaborts; /* number of times page zeroing was
aborted */
+ int colorfail; /* pagealloc where we got no page */
int colorhit; /* pagealloc where we got optimal color */
int colormiss; /* pagealloc where we didn't */
+ int colorany; /* pagealloc where we wanted any color */
int cpuhit; /* pagealloc where we allocated locally */
int cpumiss; /* pagealloc where we didn't */
@@ -457,6 +459,8 @@
int64_t colorhit;
int64_t colormiss;
int64_t ncolors;
+ int64_t colorany;
+ int64_t colorfail;
};
#ifdef _KERNEL
Index: src/sys/uvm/uvm_map.c
diff -u src/sys/uvm/uvm_map.c:1.263.4.3.4.4 src/sys/uvm/uvm_map.c:1.263.4.3.4.5
--- src/sys/uvm/uvm_map.c:1.263.4.3.4.4 Wed May 25 23:58:50 2011
+++ src/sys/uvm/uvm_map.c Fri Jun 3 02:43:41 2011
@@ -4660,7 +4660,7 @@
}
error = uvm_map_prepare(map, 0, PAGE_SIZE, NULL, UVM_UNKNOWN_OFFSET,
- VM_PAGE_TO_COLOR(pg), mapflags | UVM_FLAG_COLORMATCH, &args);
+ VM_PGCOLOR_BUCKET(pg), mapflags | UVM_FLAG_COLORMATCH, &args);
if (error) {
uvm_pagefree(pg);
return NULL;
@@ -5105,9 +5105,9 @@
/* cross-verify page queue */
if (pg->pqflags & PQ_FREE) {
- int fl = uvm_page_lookup_freelist(pg);
+ int free_list = uvm_page_lookup_freelist(pg);
int color = VM_PGCOLOR_BUCKET(pg);
- pgl = &uvm.page_free[fl].pgfl_buckets[color].pgfl_queues[
+ pgl = &uvm.page_free[color].pgfl_queues[free_list][
((pg)->flags & PG_ZERO) ? PGFL_ZEROS : PGFL_UNKNOWN];
} else {
pgl = NULL;
Index: src/sys/uvm/uvm_meter.c
diff -u src/sys/uvm/uvm_meter.c:1.49 src/sys/uvm/uvm_meter.c:1.49.16.1
--- src/sys/uvm/uvm_meter.c:1.49 Wed Jun 4 12:45:28 2008
+++ src/sys/uvm/uvm_meter.c Fri Jun 3 02:43:41 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: uvm_meter.c,v 1.49 2008/06/04 12:45:28 ad Exp $ */
+/* uvm_meter.c,v 1.49 2008/06/04 12:45:28 ad Exp */
/*
* Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -41,7 +41,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uvm_meter.c,v 1.49 2008/06/04 12:45:28 ad Exp $");
+__KERNEL_RCSID(0, "uvm_meter.c,v 1.49 2008/06/04 12:45:28 ad Exp");
#include <sys/param.h>
#include <sys/proc.h>
@@ -245,6 +245,8 @@
u.colormiss = uvmexp.colormiss;
u.cpuhit = uvmexp.cpuhit;
u.cpumiss = uvmexp.cpumiss;
+ u.colorany = uvmexp.colorany;
+ u.colorfail = uvmexp.colorfail;
node = *rnode;
node.sysctl_data = &u;
Index: src/sys/uvm/uvm_page.c
diff -u src/sys/uvm/uvm_page.c:1.140.6.3.4.3 src/sys/uvm/uvm_page.c:1.140.6.3.4.4
--- src/sys/uvm/uvm_page.c:1.140.6.3.4.3 Wed Jan 27 07:45:19 2010
+++ src/sys/uvm/uvm_page.c Fri Jun 3 02:43:41 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: uvm_page.c,v 1.140.6.3.4.3 2010/01/27 07:45:19 nisimura Exp $ */
+/* uvm_page.c,v 1.140.6.3.4.3 2010/01/27 07:45:19 nisimura Exp */
/*
* Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -71,7 +71,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uvm_page.c,v 1.140.6.3.4.3 2010/01/27 07:45:19 nisimura Exp $");
+__KERNEL_RCSID(0, "uvm_page.c,v 1.140.6.3.4.3 2010/01/27 07:45:19 nisimura Exp");
#include "opt_uvmhist.h"
#include "opt_readahead.h"
@@ -133,7 +133,7 @@
* we allocate an initial number of page colors in uvm_page_init(),
* and remember them. We may re-color pages as cache sizes are
* discovered during the autoconfiguration phase. But we can never
- * free the initial set of buckets, since they are allocated using
+ * free the initial set of pgfreelists, since they are allocated using
* uvm_pageboot_alloc().
*/
@@ -312,15 +312,16 @@
}
static void
-uvm_page_init_buckets(struct pgfreelist *pgfl)
+uvm_page_init_freelist(struct pgfreelist *pgfl)
{
- int color, i;
-
- for (color = 0; color < uvmexp.ncolors; color++) {
- for (i = 0; i < PGFL_NQUEUES; i++) {
- LIST_INIT(&pgfl->pgfl_buckets[color].pgfl_queues[i]);
+ for (size_t free_list = 0; free_list < VM_NFREELIST; free_list++) {
+ for (size_t queue = 0; queue < PGFL_NQUEUES; queue++) {
+ LIST_INIT(&pgfl->pgfl_queues[free_list][queue]);
}
}
+ for (size_t queue = 0; queue < PGFL_NQUEUES; queue++) {
+ pgfl->pgfl_pages[queue] = 0;
+ }
}
/*
@@ -332,12 +333,8 @@
void
uvm_page_init(vaddr_t *kvm_startp, vaddr_t *kvm_endp)
{
- vsize_t freepages, pagecount, bucketcount, n;
- struct pgflbucket *bucketarray, *cpuarray;
+ vsize_t freepages, pagecount;
struct vm_page *pagearray;
- int lcv;
- u_int i;
- paddr_t paddr;
KASSERT(ncpu <= 1);
CTASSERT(sizeof(pagearray->offset) >= sizeof(struct uvm_cpu *));
@@ -376,8 +373,10 @@
*/
freepages = 0;
- for (lcv = 0 ; lcv < vm_nphysseg ; lcv++)
- freepages += (vm_physmem[lcv].end - vm_physmem[lcv].start);
+ for (size_t free_list = 0 ; free_list < vm_nphysseg ; free_list++) {
+ struct vm_physseg * const seg = VM_PHYSMEM_PTR(free_list);
+ freepages += seg->end - seg->start;
+ }
/*
* Let MD code initialize the number of colors, or default
@@ -397,23 +396,19 @@
* pages).
*/
- bucketcount = uvmexp.ncolors * VM_NFREELIST;
pagecount = ((freepages + 1) << PAGE_SHIFT) /
(PAGE_SIZE + sizeof(struct vm_page));
- bucketarray = (void *)uvm_pageboot_alloc((bucketcount *
- sizeof(struct pgflbucket) * 2) + (pagecount *
- sizeof(struct vm_page)));
- cpuarray = bucketarray + bucketcount;
- pagearray = (struct vm_page *)(bucketarray + bucketcount * 2);
-
- for (lcv = 0; lcv < VM_NFREELIST; lcv++) {
- uvm.page_free[lcv].pgfl_buckets =
- (bucketarray + (lcv * uvmexp.ncolors));
- uvm_page_init_buckets(&uvm.page_free[lcv]);
- uvm.cpus[0].page_free[lcv].pgfl_buckets =
- (cpuarray + (lcv * uvmexp.ncolors));
- uvm_page_init_buckets(&uvm.cpus[0].page_free[lcv]);
+ uvm.page_free = (void *)uvm_pageboot_alloc(
+ 2 * uvmexp.ncolors * sizeof(struct pgfreelist)
+ + (pagecount * sizeof(struct vm_page)));
+
+ uvm.cpus[0].page_free = uvm.page_free + uvmexp.ncolors;
+ pagearray = (struct vm_page *)(uvm.cpus[0].page_free + uvmexp.ncolors);
+
+ for (size_t color = 0; color < uvmexp.ncolors; color++) {
+ uvm_page_init_freelist(&uvm.page_free[color]);
+ uvm_page_init_freelist(&uvm.cpus[0].page_free[color]);
}
memset(pagearray, 0, pagecount * sizeof(struct vm_page));
@@ -421,27 +416,27 @@
* init the vm_page structures and put them in the correct place.
*/
- for (lcv = 0 ; lcv < vm_nphysseg ; lcv++) {
- n = vm_physmem[lcv].end - vm_physmem[lcv].start;
+ for (size_t free_list = 0; free_list < vm_nphysseg; free_list++) {
+ struct vm_physseg * const seg = VM_PHYSMEM_PTR(free_list);
+ u_int n = seg->end - seg->start;
/* set up page array pointers */
- vm_physmem[lcv].pgs = pagearray;
+ seg->pgs = pagearray;
pagearray += n;
pagecount -= n;
- vm_physmem[lcv].lastpg = vm_physmem[lcv].pgs + (n - 1);
+ seg->lastpg = seg->pgs + (n - 1);
/* init and free vm_pages (we've already zeroed them) */
- paddr = ptoa(vm_physmem[lcv].start);
- for (i = 0 ; i < n ; i++, paddr += PAGE_SIZE) {
- vm_physmem[lcv].pgs[i].phys_addr = paddr;
+ struct vm_page *pg = seg->pgs;
+ for (u_int i = seg->start ; i < seg->end; i++, pg++) {
+ pg->phys_addr = ptoa(i);
#ifdef __HAVE_VM_PAGE_MD
- VM_MDPAGE_INIT(&vm_physmem[lcv].pgs[i]);
+ VM_MDPAGE_INIT(pg);
#endif
- if (atop(paddr) >= vm_physmem[lcv].avail_start &&
- atop(paddr) <= vm_physmem[lcv].avail_end) {
+ if (i >= seg->avail_start && i < seg->avail_end) {
uvmexp.npages++;
/* add page to free pool */
- uvm_pagefree(&vm_physmem[lcv].pgs[i]);
+ uvm_pagefree(pg);
}
}
}
@@ -858,18 +853,18 @@
}
/*
- * uvm_page_recolor: Recolor the pages if the new bucket count is
+ * uvm_page_recolor: Recolor the pages if the new color count is
* larger than the old one.
*/
void
uvm_page_recolor(int newncolors)
{
- struct pgflbucket *bucketarray, *cpuarray, *oldbucketarray;
- struct pgfreelist gpgfl, pgfl;
+ struct pgfreelist *uvmarray, *cpuarray, *olduvmarray;
+ struct pgfreelist *old_gpgfl, *old_pgfl;
struct vm_page *pg;
- vsize_t bucketcount;
- int lcv, color, i, ocolors;
+ size_t freelistcount;
+ int color, ocolors;
struct uvm_cpu *ucpu;
if (newncolors <= uvmexp.ncolors)
@@ -880,13 +875,15 @@
return;
}
- bucketcount = newncolors * VM_NFREELIST;
- bucketarray = malloc(bucketcount * sizeof(struct pgflbucket) * 2,
- M_VMPAGE, M_NOWAIT);
- cpuarray = bucketarray + bucketcount;
- if (bucketarray == NULL) {
- printf("WARNING: unable to allocate %ld page color buckets\n",
- (long) bucketcount);
+ KASSERT(!mp_online);
+
+ freelistcount = newncolors * sizeof(struct pgfreelist) * 2;
+
+ uvmarray = malloc(freelistcount, M_VMPAGE, M_NOWAIT);
+ cpuarray = uvmarray + newncolors;
+ if (uvmarray == NULL) {
+ printf("WARNING: unable to allocate %d color page freelists\n",
+ newncolors);
return;
}
@@ -895,45 +892,62 @@
/* Make sure we should still do this. */
if (newncolors <= uvmexp.ncolors) {
mutex_spin_exit(&uvm_fpageqlock);
- free(bucketarray, M_VMPAGE);
+ free(uvmarray, M_VMPAGE);
return;
}
- oldbucketarray = uvm.page_free[0].pgfl_buckets;
+ olduvmarray = uvm.page_free;
ocolors = uvmexp.ncolors;
uvmexp.ncolors = newncolors;
uvmexp.colormask = uvmexp.ncolors - 1;
ucpu = curcpu()->ci_data.cpu_uvm;
- for (lcv = 0; lcv < VM_NFREELIST; lcv++) {
- gpgfl.pgfl_buckets = (bucketarray + (lcv * newncolors));
- pgfl.pgfl_buckets = (cpuarray + (lcv * uvmexp.ncolors));
- uvm_page_init_buckets(&gpgfl);
- uvm_page_init_buckets(&pgfl);
- for (color = 0; color < ocolors; color++) {
- for (i = 0; i < PGFL_NQUEUES; i++) {
- while ((pg = LIST_FIRST(&uvm.page_free[
- lcv].pgfl_buckets[color].pgfl_queues[i]))
- != NULL) {
+ for (color = 0; color < newncolors; color++) {
+ uvm_page_init_freelist(&uvmarray[color]);
+ uvm_page_init_freelist(&cpuarray[color]);
+ }
+ old_gpgfl = olduvmarray;
+ old_pgfl = ucpu->page_free;
+ KASSERT(old_pgfl == olduvmarray + ocolors);
+ for (color = 0; color < ocolors; color++, old_gpgfl++, old_pgfl++) {
+ struct pgflist *freeq = &old_gpgfl->pgfl_queues[0][0];
+ for (size_t free_list = 0; free_list < VM_NFREELIST; free_list++) {
+ for (size_t queue = 0; queue < PGFL_NQUEUES; queue++, freeq++) {
+ KASSERT(freeq == &old_gpgfl->pgfl_queues[free_list][queue]);
+ while ((pg = LIST_FIRST(freeq)) != NULL) {
+ const u_int pgcolor = VM_PGCOLOR_BUCKET(pg);
+
LIST_REMOVE(pg, pageq.list); /* global */
LIST_REMOVE(pg, listq.list); /* cpu */
- LIST_INSERT_HEAD(&gpgfl.pgfl_buckets[
- VM_PGCOLOR_BUCKET(pg)].pgfl_queues[
- i], pg, pageq.list);
- LIST_INSERT_HEAD(&pgfl.pgfl_buckets[
- VM_PGCOLOR_BUCKET(pg)].pgfl_queues[
- i], pg, listq.list);
+
+ old_gpgfl->pgfl_pages[queue]--;
+ VM_FREE_PAGE_TO_CPU(pg)->page_free[
+ color].pgfl_pages[queue]--;
+ LIST_INSERT_HEAD(&uvmarray[pgcolor
+ ].pgfl_queues[free_list][queue],
+ pg, pageq.list);
+ LIST_INSERT_HEAD(&cpuarray[pgcolor
+ ].pgfl_queues[free_list][queue],
+ pg, listq.list);
+
+ uvmarray[pgcolor].pgfl_pages[queue]++;
+ cpuarray[pgcolor].pgfl_pages[queue]++;
}
}
}
- uvm.page_free[lcv].pgfl_buckets = gpgfl.pgfl_buckets;
- ucpu->page_free[lcv].pgfl_buckets = pgfl.pgfl_buckets;
}
+ uvm.page_free = uvmarray;
+ ucpu->page_free = cpuarray;
if (have_recolored_pages) {
+ /*
+ * We can only free the olduvmarray if is was allocated by
+ * malloc. The one allocated in uvm_page_init was allocated
+ * uvm_pageboot_alloc so it can't be freed.
+ */
mutex_spin_exit(&uvm_fpageqlock);
- free(oldbucketarray, M_VMPAGE);
+ free(olduvmarray, M_VMPAGE);
return;
}
@@ -948,11 +962,7 @@
void
uvm_cpu_attach(struct cpu_info *ci)
{
- struct pgflbucket *bucketarray;
- struct pgfreelist pgfl;
struct uvm_cpu *ucpu;
- vsize_t bucketcount;
- int lcv;
if (CPU_IS_PRIMARY(ci)) {
/* Already done in uvm_page_init(). */
@@ -963,16 +973,13 @@
uvmexp.reserve_kernel += vm_page_reserve_kernel;
/* Configure this CPU's free lists. */
- bucketcount = uvmexp.ncolors * VM_NFREELIST;
- bucketarray = malloc(bucketcount * sizeof(struct pgflbucket),
- M_VMPAGE, M_WAITOK);
ucpu = &uvm.cpus[cpu_index(ci)];
- ci->ci_data.cpu_uvm = ucpu;
- for (lcv = 0; lcv < VM_NFREELIST; lcv++) {
- pgfl.pgfl_buckets = (bucketarray + (lcv * uvmexp.ncolors));
- uvm_page_init_buckets(&pgfl);
- ucpu->page_free[lcv].pgfl_buckets = pgfl.pgfl_buckets;
+ ucpu->page_free = malloc(uvmexp.ncolors * sizeof(ucpu->page_free[0]),
+ M_VMPAGE, M_WAITOK);
+ for (size_t color = 0; color < uvmexp.ncolors; color++) {
+ uvm_page_init_freelist(&ucpu->page_free[color]);
}
+ ci->ci_data.cpu_uvm = ucpu;
}
/*
@@ -980,62 +987,76 @@
*/
static struct vm_page *
-uvm_pagealloc_pgfl(struct uvm_cpu *ucpu, int flist, int try1, int try2,
- int *trycolorp)
+uvm_pagealloc_pgfl(struct uvm_cpu *ucpu, int free_list, int try1, int try2,
+ int *trycolorp, bool anycolor)
{
- struct pgflist *freeq;
+ struct pgfreelist *gpgfl, *pgfl;
struct vm_page *pg;
int color, trycolor = *trycolorp;
- struct pgfreelist *gpgfl, *pgfl;
KASSERT(mutex_owned(&uvm_fpageqlock));
color = trycolor;
- pgfl = &ucpu->page_free[flist];
- gpgfl = &uvm.page_free[flist];
do {
+ pgfl = &ucpu->page_free[color];
+ gpgfl = &uvm.page_free[color];
+
/* cpu, try1 */
- if ((pg = LIST_FIRST((freeq =
- &pgfl->pgfl_buckets[color].pgfl_queues[try1]))) != NULL) {
- VM_FREE_PAGE_TO_CPU(pg)->pages[try1]--;
+ struct pgflist * const freeq = pgfl->pgfl_queues[free_list];
+ if ((pg = LIST_FIRST(&freeq[try1])) != NULL) {
+ KASSERT(ucpu == VM_FREE_PAGE_TO_CPU(pg));
+ KASSERT(pgfl == &ucpu->page_free[color]);
uvmexp.cpuhit++;
goto gotit;
}
+
/* global, try1 */
- if ((pg = LIST_FIRST((freeq =
- &gpgfl->pgfl_buckets[color].pgfl_queues[try1]))) != NULL) {
- VM_FREE_PAGE_TO_CPU(pg)->pages[try1]--;
+ struct pgflist * const gfreeq = gpgfl->pgfl_queues[free_list];
+ if ((pg = LIST_FIRST(&gfreeq[try1])) != NULL) {
+ ucpu = VM_FREE_PAGE_TO_CPU(pg);
+ pgfl = &ucpu->page_free[color];
uvmexp.cpumiss++;
goto gotit;
}
+
/* cpu, try2 */
- if ((pg = LIST_FIRST((freeq =
- &pgfl->pgfl_buckets[color].pgfl_queues[try2]))) != NULL) {
- VM_FREE_PAGE_TO_CPU(pg)->pages[try2]--;
+ if ((pg = LIST_FIRST(&freeq[try2])) != NULL) {
+ KASSERT(ucpu == VM_FREE_PAGE_TO_CPU(pg));
+ KASSERT(pgfl == &ucpu->page_free[color]);
uvmexp.cpuhit++;
+ try1 = try2;
goto gotit;
}
+
/* global, try2 */
- if ((pg = LIST_FIRST((freeq =
- &gpgfl->pgfl_buckets[color].pgfl_queues[try2]))) != NULL) {
- VM_FREE_PAGE_TO_CPU(pg)->pages[try2]--;
+ if ((pg = LIST_FIRST(&gfreeq[try2])) != NULL) {
+ ucpu = VM_FREE_PAGE_TO_CPU(pg);
+ pgfl = &ucpu->page_free[color];
uvmexp.cpumiss++;
+ try1 = try2;
goto gotit;
}
color = (color + 1) & uvmexp.colormask;
- } while (color != trycolor);
+ } while (anycolor && color != trycolor);
+ uvmexp.colorfail++;
return (NULL);
gotit:
LIST_REMOVE(pg, pageq.list); /* global list */
LIST_REMOVE(pg, listq.list); /* per-cpu list */
uvmexp.free--;
+ pgfl->pgfl_pages[try1]--;
+ gpgfl->pgfl_pages[try1]--;
+ ucpu->pages[try1]--;
/* update zero'd page count */
if (pg->flags & PG_ZERO)
uvmexp.zeropages--;
+ if (anycolor)
+ uvmexp.colorany++;
+
if (color == trycolor)
uvmexp.colorhit++;
else {
@@ -1068,10 +1089,12 @@
uvm_pagealloc_strat(struct uvm_object *obj, voff_t off, struct vm_anon *anon,
int flags, int strat, int free_list)
{
- int lcv, try1, try2, zeroit = 0, color;
+ int lcv, try1, try2, color;
struct uvm_cpu *ucpu;
struct vm_page *pg;
lwp_t *l;
+ bool anycolor;
+ bool zeroit = false;
KASSERT(obj == NULL || anon == NULL);
KASSERT(anon == NULL || (flags & UVM_FLAG_COLORMATCH) || off == 0);
@@ -1089,8 +1112,10 @@
ucpu = curcpu()->ci_data.cpu_uvm;
if (flags & UVM_FLAG_COLORMATCH) {
color = atop(off) & uvmexp.colormask;
+ anycolor = false;
} else {
color = ucpu->page_free_nextcolor;
+ anycolor = true;
}
/*
@@ -1142,7 +1167,7 @@
/* Check all freelists in descending priority order. */
for (lcv = 0; lcv < VM_NFREELIST; lcv++) {
pg = uvm_pagealloc_pgfl(ucpu, lcv,
- try1, try2, &color);
+ try1, try2, &color, anycolor);
if (pg != NULL)
goto gotit;
}
@@ -1155,7 +1180,7 @@
/* Attempt to allocate from the specified free list. */
KASSERT(free_list >= 0 && free_list < VM_NFREELIST);
pg = uvm_pagealloc_pgfl(ucpu, free_list,
- try1, try2, &color);
+ try1, try2, &color, anycolor);
if (pg != NULL)
goto gotit;
@@ -1189,10 +1214,10 @@
if (flags & UVM_PGA_ZERO) {
if (pg->flags & PG_ZERO) {
uvmexp.pga_zerohit++;
- zeroit = 0;
+ zeroit = false;
} else {
uvmexp.pga_zeromiss++;
- zeroit = 1;
+ zeroit = true;
}
if (ucpu->pages[PGFL_ZEROS] < ucpu->pages[PGFL_UNKNOWN]) {
ucpu->page_idle_zero = vm_page_zero_enable;
@@ -1344,7 +1369,7 @@
{
struct pgflist *pgfl;
struct uvm_cpu *ucpu;
- int index, color, queue;
+ int free_list, color, queue;
bool iszero;
KASSERT(pg);
@@ -1441,7 +1466,7 @@
*/
iszero = (pg->flags & PG_ZERO);
- index = uvm_page_lookup_freelist(pg);
+ free_list = uvm_page_lookup_freelist(pg);
color = VM_PGCOLOR_BUCKET(pg);
queue = (iszero ? PGFL_ZEROS : PGFL_UNKNOWN);
@@ -1460,8 +1485,9 @@
/* global list */
- pgfl = &uvm.page_free[index].pgfl_buckets[color].pgfl_queues[queue];
+ pgfl = &uvm.page_free[color].pgfl_queues[free_list][queue];
LIST_INSERT_HEAD(pgfl, pg, pageq.list);
+ uvm.page_free[color].pgfl_pages[queue]++;
uvmexp.free++;
if (iszero) {
uvmexp.zeropages++;
@@ -1470,8 +1496,9 @@
/* per-cpu list */
ucpu = curcpu()->ci_data.cpu_uvm;
pg->offset = (uintptr_t)ucpu;
- pgfl = &ucpu->page_free[index].pgfl_buckets[color].pgfl_queues[queue];
+ pgfl = &ucpu->page_free[color].pgfl_queues[free_list][queue];
LIST_INSERT_HEAD(pgfl, pg, listq.list);
+ ucpu->page_free[color].pgfl_pages[queue]++;
ucpu->pages[queue]++;
if (ucpu->pages[PGFL_ZEROS] < ucpu->pages[PGFL_UNKNOWN]) {
ucpu->page_idle_zero = vm_page_zero_enable;
@@ -1590,7 +1617,7 @@
/*
* uvm_pageidlezero: zero free pages while the system is idle.
*
- * => try to complete one color bucket at a time, to reduce our impact
+ * => try to complete one color at a time, to reduce our impact
* on the CPU cache.
* => we loop until we either reach the target or there is a lwp ready
* to run, or MD code detects a reason to break early.
@@ -1601,7 +1628,7 @@
struct vm_page *pg;
struct pgfreelist *pgfl, *gpgfl;
struct uvm_cpu *ucpu;
- int free_list, firstbucket, nextbucket;
+ int free_list, firstcolor, nextcolor;
ucpu = curcpu()->ci_data.cpu_uvm;
if (!ucpu->page_idle_zero ||
@@ -1610,23 +1637,31 @@
return;
}
mutex_enter(&uvm_fpageqlock);
- firstbucket = ucpu->page_free_nextcolor;
- nextbucket = firstbucket;
+ firstcolor = ucpu->page_free_nextcolor;
+ nextcolor = firstcolor;
do {
- for (free_list = 0; free_list < VM_NFREELIST; free_list++) {
+ gpgfl = &uvm.page_free[nextcolor];
+ pgfl = &ucpu->page_free[nextcolor];
+ struct pgflist *gfreeq = &gpgfl->pgfl_queues[0][0];
+ struct pgflist *freeq = &pgfl->pgfl_queues[0][0];
+ for (free_list = 0;
+ free_list < VM_NFREELIST;
+ free_list++,
+ freeq += PGFL_NQUEUES,
+ gfreeq += PGFL_NQUEUES) {
if (sched_curcpu_runnable_p()) {
goto quit;
}
- pgfl = &ucpu->page_free[free_list];
- gpgfl = &uvm.page_free[free_list];
- while ((pg = LIST_FIRST(&pgfl->pgfl_buckets[
- nextbucket].pgfl_queues[PGFL_UNKNOWN])) != NULL) {
+ KASSERT(freeq == &pgfl->pgfl_queues[free_list][0]);
+ while ((pg = LIST_FIRST(&freeq[PGFL_UNKNOWN])) != NULL) {
if (sched_curcpu_runnable_p()) {
goto quit;
}
LIST_REMOVE(pg, pageq.list); /* global list */
LIST_REMOVE(pg, listq.list); /* per-cpu list */
ucpu->pages[PGFL_UNKNOWN]--;
+ gpgfl->pgfl_pages[PGFL_UNKNOWN]--;
+ pgfl->pgfl_pages[PGFL_UNKNOWN]--;
uvmexp.free--;
KASSERT(pg->pqflags == PQ_FREE);
pg->pqflags = 0;
@@ -1643,13 +1678,13 @@
mutex_spin_enter(&uvm_fpageqlock);
pg->pqflags = PQ_FREE;
- LIST_INSERT_HEAD(&gpgfl->pgfl_buckets[
- nextbucket].pgfl_queues[
- PGFL_UNKNOWN], pg, pageq.list);
- LIST_INSERT_HEAD(&pgfl->pgfl_buckets[
- nextbucket].pgfl_queues[
- PGFL_UNKNOWN], pg, listq.list);
+ LIST_INSERT_HEAD(&gfreeq[PGFL_UNKNOWN],
+ pg, listq.list);
+ LIST_INSERT_HEAD(&freeq[PGFL_UNKNOWN],
+ pg, pageq.list);
ucpu->pages[PGFL_UNKNOWN]++;
+ gpgfl->pgfl_pages[PGFL_UNKNOWN]++;
+ pgfl->pgfl_pages[PGFL_UNKNOWN]++;
uvmexp.free++;
uvmexp.zeroaborts++;
goto quit;
@@ -1661,22 +1696,24 @@
mutex_spin_enter(&uvm_fpageqlock);
pg->pqflags = PQ_FREE;
- LIST_INSERT_HEAD(&gpgfl->pgfl_buckets[
- nextbucket].pgfl_queues[PGFL_ZEROS],
+ LIST_INSERT_HEAD(&gfreeq[PGFL_ZEROS],
pg, pageq.list);
- LIST_INSERT_HEAD(&pgfl->pgfl_buckets[
- nextbucket].pgfl_queues[PGFL_ZEROS],
+ LIST_INSERT_HEAD(&freeq[PGFL_ZEROS],
pg, listq.list);
ucpu->pages[PGFL_ZEROS]++;
+ gpgfl->pgfl_pages[PGFL_ZEROS]++;
+ pgfl->pgfl_pages[PGFL_ZEROS]++;
uvmexp.free++;
uvmexp.zeropages++;
}
}
- if (ucpu->pages[PGFL_UNKNOWN] < uvmexp.ncolors) {
+ if (pgfl->pgfl_pages[PGFL_ZEROS] >=
+ pgfl->pgfl_pages[PGFL_UNKNOWN]
+ || pgfl->pgfl_pages[PGFL_UNKNOWN] == 0) {
break;
}
- nextbucket = (nextbucket + 1) & uvmexp.colormask;
- } while (nextbucket != firstbucket);
+ nextcolor = (nextcolor + 1) & uvmexp.colormask;
+ } while (nextcolor != firstcolor);
ucpu->page_idle_zero = false;
quit:
mutex_spin_exit(&uvm_fpageqlock);
Index: src/sys/uvm/uvm_page.h
diff -u src/sys/uvm/uvm_page.h:1.55.14.3 src/sys/uvm/uvm_page.h:1.55.14.4
--- src/sys/uvm/uvm_page.h:1.55.14.3 Wed May 25 23:58:50 2011
+++ src/sys/uvm/uvm_page.h Fri Jun 3 02:43:42 2011
@@ -307,7 +307,6 @@
(((unsigned long)obj+(unsigned long)atop(off)) & uvm.page_hashmask)
#define VM_PAGE_TO_PHYS(entry) ((entry)->phys_addr)
-#define VM_PAGE_TO_COLOR(entry) (atop((entry)->phys_addr) & uvmexp.colormask)
#ifdef __HAVE_VM_PAGE_MD
#define VM_PAGE_TO_MD(pg) (&(pg)->mdpage)
Index: src/sys/uvm/uvm_pager.c
diff -u src/sys/uvm/uvm_pager.c:1.92.18.1 src/sys/uvm/uvm_pager.c:1.92.18.2
--- src/sys/uvm/uvm_pager.c:1.92.18.1 Wed May 25 23:58:50 2011
+++ src/sys/uvm/uvm_pager.c Fri Jun 3 02:43:42 2011
@@ -152,7 +152,7 @@
struct vm_page *pp;
vm_prot_t prot;
const bool pdaemon = (curlwp == uvm.pagedaemon_lwp);
- const u_int first_color = VM_PAGE_TO_COLOR(*pps);
+ const u_int first_color = VM_PGCOLOR_BUCKET(*pps);
UVMHIST_FUNC("uvm_pagermapin"); UVMHIST_CALLED(maphist);
UVMHIST_LOG(maphist,"(pps=0x%x, npages=%d, first_color=%u)",
Index: src/sys/uvm/uvm_pdaemon.c
diff -u src/sys/uvm/uvm_pdaemon.c:1.93.4.2 src/sys/uvm/uvm_pdaemon.c:1.93.4.2.4.1
--- src/sys/uvm/uvm_pdaemon.c:1.93.4.2 Mon Feb 2 19:24:04 2009
+++ src/sys/uvm/uvm_pdaemon.c Fri Jun 3 02:43:42 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: uvm_pdaemon.c,v 1.93.4.2 2009/02/02 19:24:04 snj Exp $ */
+/* uvm_pdaemon.c,v 1.93.4.2 2009/02/02 19:24:04 snj Exp */
/*
* Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -71,7 +71,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uvm_pdaemon.c,v 1.93.4.2 2009/02/02 19:24:04 snj Exp $");
+__KERNEL_RCSID(0, "uvm_pdaemon.c,v 1.93.4.2 2009/02/02 19:24:04 snj Exp");
#include "opt_uvmhist.h"
#include "opt_readahead.h"
@@ -113,6 +113,20 @@
*/
u_int uvm_extrapages;
+static bool
+uvm_color_needsscan_p(void)
+{
+ struct pgfreelist *pgfl = uvm.page_free;
+ for (int color = 0; color < uvmexp.ncolors; color++, pgfl++) {
+ u_long freepages =
+ pgfl->pgfl_pages[PGFL_UNKNOWN]
+ + pgfl->pgfl_pages[PGFL_ZEROS];
+ if (freepages * uvmexp.ncolors < uvmexp.freetarg)
+ return true;
+ }
+ return false;
+}
+
/*
* uvm_wait: wait (sleep) for the page daemon to free some pages
*
@@ -175,9 +189,10 @@
KASSERT(mutex_owned(&uvm_fpageqlock));
- if (uvmexp.free + uvmexp.paging < uvmexp.freemin ||
- (uvmexp.free + uvmexp.paging < uvmexp.freetarg &&
- uvmpdpol_needsscan_p())) {
+ if (uvmexp.free + uvmexp.paging < uvmexp.freemin
+ || (uvmexp.free + uvmexp.paging < uvmexp.freetarg
+ && uvmpdpol_needsscan_p())
+ || uvm_color_needsscan_p()) {
wakeup(&uvm.pagedaemon);
}
}
@@ -293,6 +308,7 @@
needsfree = uvmexp.free + uvmexp.paging < uvmexp.freetarg;
needsscan = needsfree || uvmpdpol_needsscan_p();
+ needsscan = needsscan || uvm_color_needsscan_p();
/*
* scan if needed
Index: src/sys/uvm/uvm_pglist.c
diff -u src/sys/uvm/uvm_pglist.c:1.42.16.8 src/sys/uvm/uvm_pglist.c:1.42.16.9
--- src/sys/uvm/uvm_pglist.c:1.42.16.8 Fri May 27 17:17:17 2011
+++ src/sys/uvm/uvm_pglist.c Fri Jun 3 02:43:42 2011
@@ -81,7 +81,8 @@
static void
uvm_pglist_add(struct vm_page *pg, struct pglist *rlist)
{
- int free_list, color, pgflidx;
+ struct uvm_cpu *ucpu;
+ int free_list, color, queue;
KASSERT(mutex_owned(&uvm_fpageqlock));
@@ -89,13 +90,14 @@
#error uvm_pglistalloc needs to be updated
#endif
+ ucpu = VM_FREE_PAGE_TO_CPU(pg);
free_list = uvm_page_lookup_freelist(pg);
color = VM_PGCOLOR_BUCKET(pg);
- pgflidx = (pg->flags & PG_ZERO) ? PGFL_ZEROS : PGFL_UNKNOWN;
+ queue = (pg->flags & PG_ZERO) ? PGFL_ZEROS : PGFL_UNKNOWN;
#if defined(DEBUG) && DEBUG > 1
struct vm_page *tp;
LIST_FOREACH(tp,
- &uvm.page_free[free_list].pgfl_buckets[color].pgfl_queues[pgflidx],
+ &uvm.page_free[color].pgfl_queues[free_list][queue],
pageq.list) {
if (tp == pg)
break;
@@ -105,10 +107,12 @@
#endif
LIST_REMOVE(pg, pageq.list); /* global */
LIST_REMOVE(pg, listq.list); /* cpu */
+ uvm.page_free[color].pgfl_pages[queue]--;
+ ucpu->page_free[color].pgfl_pages[queue]--;
+ ucpu->pages[queue]--;
uvmexp.free--;
if (pg->flags & PG_ZERO)
uvmexp.zeropages--;
- VM_FREE_PAGE_TO_CPU(pg)->pages[pgflidx]--;
pg->flags = PG_CLEAN;
pg->pqflags = 0;
pg->uobject = NULL;
@@ -387,7 +391,7 @@
#ifdef DIAGNOSTIC
if (!colorless) {
pg = TAILQ_LAST(rlist, pglist);
- KASSERT(color == ((VM_PAGE_TO_COLOR(pg) + 1) & colormask));
+ KASSERT(color == ((VM_PGCOLOR_BUCKET(pg) + 1) & colormask));
}
#endif
@@ -586,21 +590,18 @@
void
uvm_pglistfree(struct pglist *list)
{
- struct uvm_cpu *ucpu;
struct vm_page *pg;
- int index, color, queue;
- bool iszero;
/*
* Lock the free list and free each page.
*/
mutex_spin_enter(&uvm_fpageqlock);
- ucpu = curcpu()->ci_data.cpu_uvm;
+ struct uvm_cpu * const ucpu = curcpu()->ci_data.cpu_uvm;
while ((pg = TAILQ_FIRST(list)) != NULL) {
KASSERT(!uvmpdpol_pageisqueued_p(pg));
TAILQ_REMOVE(list, pg, pageq.queue);
- iszero = (pg->flags & PG_ZERO);
+ const bool iszero = (pg->flags & PG_ZERO);
pg->pqflags = PQ_FREE;
#ifdef DEBUG
pg->uobject = (void *)0xdeadbeef;
@@ -610,21 +611,29 @@
if (iszero)
uvm_pagezerocheck(pg);
#endif /* DEBUG */
- index = uvm_page_lookup_freelist(pg);
- color = VM_PGCOLOR_BUCKET(pg);
- queue = iszero ? PGFL_ZEROS : PGFL_UNKNOWN;
+ const size_t free_list = uvm_page_lookup_freelist(pg);
+ const size_t color = VM_PGCOLOR_BUCKET(pg);
+ const size_t queue = iszero ? PGFL_ZEROS : PGFL_UNKNOWN;
pg->offset = (uintptr_t)ucpu;
- LIST_INSERT_HEAD(&uvm.page_free[index].pgfl_buckets[color].
- pgfl_queues[queue], pg, pageq.list);
- LIST_INSERT_HEAD(&ucpu->page_free[index].pgfl_buckets[color].
- pgfl_queues[queue], pg, listq.list);
+ LIST_INSERT_HEAD(&uvm.page_free[color].
+ pgfl_queues[free_list][queue], pg, pageq.list);
+ LIST_INSERT_HEAD(&ucpu->page_free[color].
+ pgfl_queues[free_list][queue], pg, listq.list);
+ uvm.page_free[color].pgfl_pages[queue]++;
+ ucpu->page_free[color].pgfl_pages[queue]++;
+ ucpu->pages[queue]++;
uvmexp.free++;
if (iszero)
uvmexp.zeropages++;
- ucpu->pages[queue]++;
STAT_DECR(uvm_pglistalloc_npages);
}
- if (ucpu->pages[PGFL_ZEROS] < ucpu->pages[PGFL_UNKNOWN])
- ucpu->page_idle_zero = vm_page_zero_enable;
+ for (size_t color = 0; color < uvmexp.ncolors; color++) {
+ const u_long * const pages =
+ ucpu->page_free[color].pgfl_pages;
+ if (pages[PGFL_ZEROS] < pages[PGFL_UNKNOWN]) {
+ ucpu->page_idle_zero = vm_page_zero_enable;
+ break;
+ }
+ }
mutex_spin_exit(&uvm_fpageqlock);
}
Index: src/sys/uvm/uvm_pglist.h
diff -u src/sys/uvm/uvm_pglist.h:1.7 src/sys/uvm/uvm_pglist.h:1.7.16.1
--- src/sys/uvm/uvm_pglist.h:1.7 Wed Jun 4 12:45:28 2008
+++ src/sys/uvm/uvm_pglist.h Fri Jun 3 02:43:42 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: uvm_pglist.h,v 1.7 2008/06/04 12:45:28 ad Exp $ */
+/* uvm_pglist.h,v 1.7 2008/06/04 12:45:28 ad Exp */
/*-
* Copyright (c) 2000, 2001, 2008 The NetBSD Foundation, Inc.
@@ -41,18 +41,16 @@
/*
* A page free list consists of free pages of unknown contents and free
- * pages of all zeros.
+ * pages of all zeros. For each color, there is a global page free list
+ * as well as one for each cpu.
*/
#define PGFL_UNKNOWN 0
#define PGFL_ZEROS 1
#define PGFL_NQUEUES 2
-struct pgflbucket {
- struct pgflist pgfl_queues[PGFL_NQUEUES];
-};
-
struct pgfreelist {
- struct pgflbucket *pgfl_buckets;
+ u_long pgfl_pages[PGFL_NQUEUES];
+ struct pgflist pgfl_queues[VM_NFREELIST][PGFL_NQUEUES];
};
#endif /* _UVM_UVM_PGLIST_H_ */
Index: src/sys/uvm/uvm_vnode.c
diff -u src/sys/uvm/uvm_vnode.c:1.90.28.1 src/sys/uvm/uvm_vnode.c:1.90.28.2
--- src/sys/uvm/uvm_vnode.c:1.90.28.1 Wed May 25 23:58:50 2011
+++ src/sys/uvm/uvm_vnode.c Fri Jun 3 02:43:42 2011
@@ -269,7 +269,8 @@
mutex_enter(&uobj->vmobjlock);
continue;
}
- UVMHIST_LOG(ubchist, "alloced %p", pg,0,0,0);
+ UVMHIST_LOG(ubchist, "alloced %p (%u)", pg,
+ VM_PGCOLOR_BUCKET(pg), 0,0);
break;
} else if (flags & UFP_NOCACHE) {
UVMHIST_LOG(ubchist, "nocache",0,0,0,0);
@@ -283,7 +284,8 @@
return 0;
}
pg->flags |= PG_WANTED;
- UVMHIST_LOG(ubchist, "wait %p", pg,0,0,0);
+ UVMHIST_LOG(ubchist, "wait %p (color %u)", pg,
+ VM_PGCOLOR_BUCKET(pg), 0,0);
UVM_UNLOCK_AND_WAIT(pg, &uobj->vmobjlock, 0,
"uvn_fp2", 0);
mutex_enter(&uobj->vmobjlock);
@@ -310,7 +312,8 @@
/* mark the page BUSY and we're done. */
pg->flags |= PG_BUSY;
UVM_PAGE_OWN(pg, "uvn_findpage");
- UVMHIST_LOG(ubchist, "found %p", pg,0,0,0);
+ UVMHIST_LOG(ubchist, "found %p (color %u)",
+ pg, VM_PGCOLOR_BUCKET(pg), 0,0);
break;
}
*pgp = pg;