Fri Jan 21 19:27:09 2011 UTC ()
Cleanup/add some asserts.  no functional change.


(matt)
diff -r1.53 -r1.54 src/sys/uvm/uvm_pglist.c

cvs diff -r1.53 -r1.54 src/sys/uvm/uvm_pglist.c (expand / switch to unified diff)

--- src/sys/uvm/uvm_pglist.c 2011/01/21 16:56:38 1.53
+++ src/sys/uvm/uvm_pglist.c 2011/01/21 19:27:09 1.54
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: uvm_pglist.c,v 1.53 2011/01/21 16:56:38 cegger Exp $ */ 1/* $NetBSD: uvm_pglist.c,v 1.54 2011/01/21 19:27:09 matt Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1997 The NetBSD Foundation, Inc. 4 * Copyright (c) 1997 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, 8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 * NASA Ames Research Center. 9 * NASA Ames Research Center.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions 12 * modification, are permitted provided that the following conditions
13 * are met: 13 * are met:
14 * 1. Redistributions of source code must retain the above copyright 14 * 1. Redistributions of source code must retain the above copyright
@@ -25,27 +25,27 @@ @@ -25,27 +25,27 @@
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE. 30 * POSSIBILITY OF SUCH DAMAGE.
31 */ 31 */
32 32
33/* 33/*
34 * uvm_pglist.c: pglist functions 34 * uvm_pglist.c: pglist functions
35 */ 35 */
36 36
37#include <sys/cdefs.h> 37#include <sys/cdefs.h>
38__KERNEL_RCSID(0, "$NetBSD: uvm_pglist.c,v 1.53 2011/01/21 16:56:38 cegger Exp $"); 38__KERNEL_RCSID(0, "$NetBSD: uvm_pglist.c,v 1.54 2011/01/21 19:27:09 matt Exp $");
39 39
40#include <sys/param.h> 40#include <sys/param.h>
41#include <sys/systm.h> 41#include <sys/systm.h>
42#include <sys/malloc.h> 42#include <sys/malloc.h>
43#include <sys/proc.h> 43#include <sys/proc.h>
44 44
45#include <uvm/uvm.h> 45#include <uvm/uvm.h>
46#include <uvm/uvm_pdpolicy.h> 46#include <uvm/uvm_pdpolicy.h>
47 47
48#ifdef VM_PAGE_ALLOC_MEMORY_STATS 48#ifdef VM_PAGE_ALLOC_MEMORY_STATS
49#define STAT_INCR(v) (v)++ 49#define STAT_INCR(v) (v)++
50#define STAT_DECR(v) do { \ 50#define STAT_DECR(v) do { \
51 if ((v) == 0) \ 51 if ((v) == 0) \
@@ -195,27 +195,27 @@ uvm_pglistalloc_c_ps(struct vm_physseg * @@ -195,27 +195,27 @@ uvm_pglistalloc_c_ps(struct vm_physseg *
195 panic("pgalloc contig: botch2"); 195 panic("pgalloc contig: botch2");
196 if (vm_physseg_find(try + num - 1, &cidx) != ps - vm_physmem) 196 if (vm_physseg_find(try + num - 1, &cidx) != ps - vm_physmem)
197 panic("pgalloc contig: botch3"); 197 panic("pgalloc contig: botch3");
198 if (cidx != try - ps->start + num - 1) 198 if (cidx != try - ps->start + num - 1)
199 panic("pgalloc contig: botch4"); 199 panic("pgalloc contig: botch4");
200#endif 200#endif
201 tryidx = try - ps->start; 201 tryidx = try - ps->start;
202 end = tryidx + num; 202 end = tryidx + num;
203 203
204 /* 204 /*
205 * Found a suitable starting page. See if the range is free. 205 * Found a suitable starting page. See if the range is free.
206 */ 206 */
207#ifdef PGALLOC_VERBOSE 207#ifdef PGALLOC_VERBOSE
208 printf("%s: ps=%p try=%#x end=%#x skip=%#x, align=0x%"PRIxPADDR, 208 printf("%s: ps=%p try=%#x end=%#x skip=%#x, align=%#"PRIxPADDR,
209 __func__, ps, tryidx, end, skip, alignment); 209 __func__, ps, tryidx, end, skip, alignment);
210#endif 210#endif
211 /* 211 /*
212 * We start at the end and work backwards since if we find a 212 * We start at the end and work backwards since if we find a
213 * non-free page, it makes no sense to continue. 213 * non-free page, it makes no sense to continue.
214 * 214 *
215 * But on the plus size we have "vetted" some number of free 215 * But on the plus size we have "vetted" some number of free
216 * pages. If this iteration fails, we may be able to skip 216 * pages. If this iteration fails, we may be able to skip
217 * testing most of those pages again in the next pass. 217 * testing most of those pages again in the next pass.
218 */ 218 */
219 for (idx = end - 1; idx >= tryidx + skip; idx--) { 219 for (idx = end - 1; idx >= tryidx + skip; idx--) {
220 if (VM_PAGE_IS_FREE(&pgs[idx]) == 0) { 220 if (VM_PAGE_IS_FREE(&pgs[idx]) == 0) {
221 ok = false; 221 ok = false;
@@ -346,59 +346,66 @@ out: @@ -346,59 +346,66 @@ out:
346 346
347 uvm_kick_pdaemon(); 347 uvm_kick_pdaemon();
348 mutex_spin_exit(&uvm_fpageqlock); 348 mutex_spin_exit(&uvm_fpageqlock);
349 return (error); 349 return (error);
350} 350}
351 351
352static int 352static int
353uvm_pglistalloc_s_ps(struct vm_physseg *ps, int num, paddr_t low, paddr_t high, 353uvm_pglistalloc_s_ps(struct vm_physseg *ps, int num, paddr_t low, paddr_t high,
354 struct pglist *rlist) 354 struct pglist *rlist)
355{ 355{
356 int todo, limit, try; 356 int todo, limit, try;
357 struct vm_page *pg; 357 struct vm_page *pg;
358 bool second_pass; 358 bool second_pass;
359#ifdef DEBUG 
360 int cidx = 0; /* XXX: GCC */ 
361#endif 
362#ifdef PGALLOC_VERBOSE 359#ifdef PGALLOC_VERBOSE
363 printf("pgalloc: simple %d pgs from psi %ld\n", num, 360 printf("pgalloc: simple %d pgs from psi %ld\n", num,
364 (long)(ps - vm_physmem)); 361 (long)(ps - vm_physmem));
365#endif 362#endif
366 363
367 KASSERT(mutex_owned(&uvm_fpageqlock)); 364 KASSERT(mutex_owned(&uvm_fpageqlock));
 365 KASSERT(ps->start <= ps->avail_start);
 366 KASSERT(ps->start <= ps->avail_end);
 367 KASSERT(ps->avail_start <= ps->end);
 368 KASSERT(ps->avail_end <= ps->end);
368 369
369 low = atop(low); 370 low = atop(low);
370 high = atop(high); 371 high = atop(high);
371 todo = num; 372 todo = num;
372 try = max(low, ps->avail_start + ps->start_hint); 373 try = max(low, ps->avail_start + ps->start_hint);
373 limit = min(high, ps->avail_end); 374 limit = min(high, ps->avail_end);
374 pg = &ps->pgs[try - ps->start]; 375 pg = &ps->pgs[try - ps->start];
375 second_pass = false; 376 second_pass = false;
376 377
377 for (;; try++, pg++) { 378 for (;; try++, pg++) {
378 if (try >= limit) { 379 if (try >= limit) {
379 if (ps->start_hint == 0 || second_pass) 380 if (ps->start_hint == 0 || second_pass)
380 break; 381 break;
381 second_pass = true; 382 second_pass = true;
382 try = max(low, ps->avail_start); 383 try = max(low, ps->avail_start);
383 limit = min(high, ps->avail_start + ps->start_hint); 384 limit = min(high, ps->avail_start + ps->start_hint);
384 pg = &ps->pgs[try - ps->start]; 385 pg = &ps->pgs[try - ps->start];
385 continue; 386 continue;
386 } 387 }
387#ifdef DEBUG 388#ifdef DEBUG
388 if (vm_physseg_find(try, &cidx) != ps - vm_physmem) 389 {
389 panic("pgalloc simple: botch1"); 390 int cidx = 0;
390 if (cidx != (try - ps->start)) 391 const int bank = vm_physseg_find(try, &cidx);
391 panic("pgalloc simple: botch2"); 392 KASSERTMSG(bank == ps - vm_physmem,
 393 ("vm_physseg_find(%#x) (%d) != ps %zd",
 394 try, bank, ps - vm_physmem));
 395 KASSERTMSG(cidx == try - ps->start,
 396 ("vm_physseg_find(%#x): %#x != off %"PRIxPADDR,
 397 try, cidx, try - ps->start));
 398 }
392#endif 399#endif
393 if (VM_PAGE_IS_FREE(pg) == 0) 400 if (VM_PAGE_IS_FREE(pg) == 0)
394 continue; 401 continue;
395 402
396 uvm_pglist_add(pg, rlist); 403 uvm_pglist_add(pg, rlist);
397 if (--todo == 0) { 404 if (--todo == 0) {
398 break; 405 break;
399 } 406 }
400 } 407 }
401 408
402 /* 409 /*
403 * The next time we need to search this segment, 410 * The next time we need to search this segment,
404 * start just after the pages we just allocated. 411 * start just after the pages we just allocated.