| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: uvm_pglist.c,v 1.54 2011/01/21 19:27:09 matt Exp $ */ | | 1 | /* $NetBSD: uvm_pglist.c,v 1.55 2011/01/22 01:36:27 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.54 2011/01/21 19:27:09 matt Exp $"); | | 38 | __KERNEL_RCSID(0, "$NetBSD: uvm_pglist.c,v 1.55 2011/01/22 01:36:27 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) \ |
| @@ -274,27 +274,32 @@ uvm_pglistalloc_c_ps(struct vm_physseg * | | | @@ -274,27 +274,32 @@ uvm_pglistalloc_c_ps(struct vm_physseg * |
274 | try += cnt; | | 274 | try += cnt; |
275 | } | | 275 | } |
276 | | | 276 | |
277 | /* | | 277 | /* |
278 | * we have a chunk of memory that conforms to the requested constraints. | | 278 | * we have a chunk of memory that conforms to the requested constraints. |
279 | */ | | 279 | */ |
280 | for (idx = tryidx, pgs += idx; idx < end; idx++, pgs++) | | 280 | for (idx = tryidx, pgs += idx; idx < end; idx++, pgs++) |
281 | uvm_pglist_add(pgs, rlist); | | 281 | uvm_pglist_add(pgs, rlist); |
282 | | | 282 | |
283 | /* | | 283 | /* |
284 | * the next time we need to search this segment, start after this | | 284 | * the next time we need to search this segment, start after this |
285 | * chunk of pages we just allocated. | | 285 | * chunk of pages we just allocated. |
286 | */ | | 286 | */ |
287 | ps->start_hint = tryidx + num; | | 287 | ps->start_hint = try + num - ps->avail_start; |
| | | 288 | KASSERTMSG(ps->start_hint <= ps->avail_end - ps->avail_start, |
| | | 289 | ("%x %u (%#x) <= %#"PRIxPADDR" - %#"PRIxPADDR" (%#"PRIxPADDR")", |
| | | 290 | try + num, |
| | | 291 | ps->start_hint, ps->start_hint, ps->avail_end, ps->avail_start, |
| | | 292 | ps->avail_end - ps->avail_start)); |
288 | | | 293 | |
289 | #ifdef PGALLOC_VERBOSE | | 294 | #ifdef PGALLOC_VERBOSE |
290 | printf("got %d pgs\n", num); | | 295 | printf("got %d pgs\n", num); |
291 | #endif | | 296 | #endif |
292 | return num; /* number of pages allocated */ | | 297 | return num; /* number of pages allocated */ |
293 | } | | 298 | } |
294 | | | 299 | |
295 | static int | | 300 | static int |
296 | uvm_pglistalloc_contig(int num, paddr_t low, paddr_t high, paddr_t alignment, | | 301 | uvm_pglistalloc_contig(int num, paddr_t low, paddr_t high, paddr_t alignment, |
297 | paddr_t boundary, struct pglist *rlist) | | 302 | paddr_t boundary, struct pglist *rlist) |
298 | { | | 303 | { |
299 | int fl, psi; | | 304 | int fl, psi; |
300 | struct vm_physseg *ps; | | 305 | struct vm_physseg *ps; |
| @@ -400,27 +405,32 @@ uvm_pglistalloc_s_ps(struct vm_physseg * | | | @@ -400,27 +405,32 @@ uvm_pglistalloc_s_ps(struct vm_physseg * |
400 | if (VM_PAGE_IS_FREE(pg) == 0) | | 405 | if (VM_PAGE_IS_FREE(pg) == 0) |
401 | continue; | | 406 | continue; |
402 | | | 407 | |
403 | uvm_pglist_add(pg, rlist); | | 408 | uvm_pglist_add(pg, rlist); |
404 | if (--todo == 0) { | | 409 | if (--todo == 0) { |
405 | break; | | 410 | break; |
406 | } | | 411 | } |
407 | } | | 412 | } |
408 | | | 413 | |
409 | /* | | 414 | /* |
410 | * The next time we need to search this segment, | | 415 | * The next time we need to search this segment, |
411 | * start just after the pages we just allocated. | | 416 | * start just after the pages we just allocated. |
412 | */ | | 417 | */ |
413 | ps->start_hint = try + 1 - ps->start; | | 418 | ps->start_hint = try + 1 - ps->avail_start; |
| | | 419 | KASSERTMSG(ps->start_hint <= ps->avail_end - ps->avail_start, |
| | | 420 | ("%#x %u (%#x) <= %#"PRIxPADDR" - %#"PRIxPADDR" (%#"PRIxPADDR")", |
| | | 421 | try + 1, |
| | | 422 | ps->start_hint, ps->start_hint, ps->avail_end, ps->avail_start, |
| | | 423 | ps->avail_end - ps->avail_start)); |
414 | | | 424 | |
415 | #ifdef PGALLOC_VERBOSE | | 425 | #ifdef PGALLOC_VERBOSE |
416 | printf("got %d pgs\n", num - todo); | | 426 | printf("got %d pgs\n", num - todo); |
417 | #endif | | 427 | #endif |
418 | return (num - todo); /* number of pages allocated */ | | 428 | return (num - todo); /* number of pages allocated */ |
419 | } | | 429 | } |
420 | | | 430 | |
421 | static int | | 431 | static int |
422 | uvm_pglistalloc_simple(int num, paddr_t low, paddr_t high, | | 432 | uvm_pglistalloc_simple(int num, paddr_t low, paddr_t high, |
423 | struct pglist *rlist, int waitok) | | 433 | struct pglist *rlist, int waitok) |
424 | { | | 434 | { |
425 | int fl, psi, error; | | 435 | int fl, psi, error; |
426 | struct vm_physseg *ps; | | 436 | struct vm_physseg *ps; |