Home | History | Annotate | Line # | Download | only in uvm
uvm_pglist.c revision 1.13.2.5
      1  1.13.2.5  nathanw /*	$NetBSD: uvm_pglist.c,v 1.13.2.5 2002/06/20 03:50:45 nathanw Exp $	*/
      2       1.2  thorpej 
      3       1.1      mrg /*-
      4       1.1      mrg  * Copyright (c) 1997 The NetBSD Foundation, Inc.
      5       1.1      mrg  * All rights reserved.
      6  1.13.2.1  nathanw  *
      7       1.1      mrg  * This code is derived from software contributed to The NetBSD Foundation
      8       1.1      mrg  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
      9  1.13.2.1  nathanw  * NASA Ames Research Center.
     10       1.1      mrg  *
     11       1.1      mrg  * Redistribution and use in source and binary forms, with or without
     12       1.1      mrg  * modification, are permitted provided that the following conditions
     13       1.1      mrg  * are met:
     14       1.1      mrg  * 1. Redistributions of source code must retain the above copyright
     15       1.1      mrg  *    notice, this list of conditions and the following disclaimer.
     16  1.13.2.1  nathanw  * 2. Redistributions in binary form must reproduce the above copyright
     17       1.1      mrg  *    notice, this list of conditions and the following disclaimer in the
     18       1.1      mrg  *    documentation and/or other materials provided with the distribution.
     19       1.1      mrg  * 3. All advertising materials mentioning features or use of this software
     20       1.1      mrg  *    must display the following acknowledgement:
     21       1.1      mrg  *      This product includes software developed by the NetBSD
     22       1.1      mrg  *      Foundation, Inc. and its contributors.
     23       1.1      mrg  * 4. Neither the name of The NetBSD Foundation nor the names of its
     24       1.1      mrg  *    contributors may be used to endorse or promote products derived
     25       1.1      mrg  *    from this software without specific prior written permission.
     26  1.13.2.1  nathanw  *
     27       1.1      mrg  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     28       1.1      mrg  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     29       1.1      mrg  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     30       1.1      mrg  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     31       1.1      mrg  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32       1.1      mrg  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33       1.1      mrg  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34       1.1      mrg  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35       1.1      mrg  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36       1.1      mrg  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37       1.1      mrg  * POSSIBILITY OF SUCH DAMAGE.
     38       1.1      mrg  */
     39       1.1      mrg 
     40       1.1      mrg /*
     41       1.1      mrg  * uvm_pglist.c: pglist functions
     42       1.1      mrg  */
     43  1.13.2.4  nathanw 
     44  1.13.2.4  nathanw #include <sys/cdefs.h>
     45  1.13.2.5  nathanw __KERNEL_RCSID(0, "$NetBSD: uvm_pglist.c,v 1.13.2.5 2002/06/20 03:50:45 nathanw Exp $");
     46       1.1      mrg 
     47       1.1      mrg #include <sys/param.h>
     48       1.1      mrg #include <sys/systm.h>
     49       1.1      mrg #include <sys/malloc.h>
     50       1.1      mrg #include <sys/proc.h>
     51       1.1      mrg 
     52       1.1      mrg #include <uvm/uvm.h>
     53       1.1      mrg 
     54       1.1      mrg #ifdef VM_PAGE_ALLOC_MEMORY_STATS
     55       1.1      mrg #define	STAT_INCR(v)	(v)++
     56       1.1      mrg #define	STAT_DECR(v)	do { \
     57       1.1      mrg 		if ((v) == 0) \
     58       1.1      mrg 			printf("%s:%d -- Already 0!\n", __FILE__, __LINE__); \
     59       1.1      mrg 		else \
     60       1.1      mrg 			(v)--; \
     61       1.1      mrg 	} while (0)
     62       1.1      mrg u_long	uvm_pglistalloc_npages;
     63       1.1      mrg #else
     64       1.1      mrg #define	STAT_INCR(v)
     65       1.1      mrg #define	STAT_DECR(v)
     66       1.1      mrg #endif
     67       1.1      mrg 
     68       1.1      mrg /*
     69       1.1      mrg  * uvm_pglistalloc: allocate a list of pages
     70       1.1      mrg  *
     71       1.1      mrg  * => allocated pages are placed at the tail of rlist.  rlist is
     72       1.1      mrg  *    assumed to be properly initialized by caller.
     73       1.1      mrg  * => returns 0 on success or errno on failure
     74       1.1      mrg  * => XXX: implementation allocates only a single segment, also
     75       1.1      mrg  *	might be able to better advantage of vm_physeg[].
     76       1.1      mrg  * => doesn't take into account clean non-busy pages on inactive list
     77       1.1      mrg  *	that could be used(?)
     78       1.1      mrg  * => params:
     79       1.1      mrg  *	size		the size of the allocation, rounded to page size.
     80       1.1      mrg  *	low		the low address of the allowed allocation range.
     81       1.1      mrg  *	high		the high address of the allowed allocation range.
     82       1.1      mrg  *	alignment	memory must be aligned to this power-of-two boundary.
     83  1.13.2.1  nathanw  *	boundary	no segment in the allocation may cross this
     84       1.1      mrg  *			power-of-two boundary (relative to zero).
     85       1.1      mrg  */
     86       1.1      mrg 
     87  1.13.2.5  nathanw static void uvm_pglist_add(struct vm_page *, struct pglist *);
     88  1.13.2.5  nathanw static int uvm_pglistalloc_c_ps(int, psize_t, paddr_t, paddr_t,
     89  1.13.2.5  nathanw 				paddr_t, paddr_t, struct pglist *);
     90  1.13.2.5  nathanw static int uvm_pglistalloc_contig(psize_t, paddr_t, paddr_t, paddr_t, paddr_t,
     91  1.13.2.5  nathanw 				  struct pglist *);
     92  1.13.2.5  nathanw static void uvm_pglistalloc_s_ps(int, paddr_t, paddr_t,
     93  1.13.2.5  nathanw 				 struct pglist *, int *);
     94  1.13.2.5  nathanw static int uvm_pglistalloc_simple(psize_t, paddr_t, paddr_t,
     95  1.13.2.5  nathanw 				  struct pglist *, int);
     96  1.13.2.5  nathanw 
     97  1.13.2.5  nathanw static void
     98  1.13.2.5  nathanw uvm_pglist_add(pg, rlist)
     99  1.13.2.5  nathanw 	struct vm_page *pg;
    100       1.3      mrg 	struct pglist *rlist;
    101       1.1      mrg {
    102  1.13.2.5  nathanw 	int free_list, color, pgflidx;
    103       1.1      mrg #ifdef DEBUG
    104  1.13.2.1  nathanw 	struct vm_page *tp;
    105       1.1      mrg #endif
    106       1.1      mrg 
    107  1.13.2.5  nathanw #if PGFL_NQUEUES != 2
    108  1.13.2.5  nathanw #error uvm_pglistalloc needs to be updated
    109  1.13.2.5  nathanw #endif
    110       1.3      mrg 
    111  1.13.2.5  nathanw 	free_list = uvm_page_lookup_freelist(pg);
    112  1.13.2.5  nathanw 	color = VM_PGCOLOR_BUCKET(pg);
    113  1.13.2.5  nathanw 	pgflidx = (pg->flags & PG_ZERO) ? PGFL_ZEROS : PGFL_UNKNOWN;
    114  1.13.2.5  nathanw #ifdef DEBUG
    115  1.13.2.5  nathanw 	for (tp = TAILQ_FIRST(&uvm.page_free[
    116  1.13.2.5  nathanw 		free_list].pgfl_buckets[color].pgfl_queues[pgflidx]);
    117  1.13.2.5  nathanw 	     tp != NULL;
    118  1.13.2.5  nathanw 	     tp = TAILQ_NEXT(tp, pageq)) {
    119  1.13.2.5  nathanw 		if (tp == pg)
    120  1.13.2.5  nathanw 			break;
    121  1.13.2.5  nathanw 	}
    122  1.13.2.5  nathanw 	if (tp == NULL)
    123  1.13.2.5  nathanw 		panic("uvm_pglistalloc: page not on freelist");
    124  1.13.2.5  nathanw #endif
    125  1.13.2.5  nathanw 	TAILQ_REMOVE(&uvm.page_free[free_list].pgfl_buckets[
    126  1.13.2.5  nathanw 			color].pgfl_queues[pgflidx], pg, pageq);
    127  1.13.2.5  nathanw 	uvmexp.free--;
    128  1.13.2.5  nathanw 	if (pg->flags & PG_ZERO)
    129  1.13.2.5  nathanw 		uvmexp.zeropages--;
    130  1.13.2.5  nathanw 	pg->flags = PG_CLEAN;
    131  1.13.2.5  nathanw 	pg->pqflags = 0;
    132  1.13.2.5  nathanw 	pg->uobject = NULL;
    133  1.13.2.5  nathanw 	pg->uanon = NULL;
    134  1.13.2.5  nathanw 	TAILQ_INSERT_TAIL(rlist, pg, pageq);
    135  1.13.2.5  nathanw 	STAT_INCR(uvm_pglistalloc_npages);
    136  1.13.2.5  nathanw }
    137  1.13.2.3  nathanw 
    138  1.13.2.5  nathanw static int
    139  1.13.2.5  nathanw uvm_pglistalloc_c_ps(psi, size, low, high, alignment, boundary, rlist)
    140  1.13.2.5  nathanw 	int psi;
    141  1.13.2.5  nathanw 	psize_t size;
    142  1.13.2.5  nathanw 	paddr_t low, high, alignment, boundary;
    143  1.13.2.5  nathanw 	struct pglist *rlist;
    144  1.13.2.5  nathanw {
    145  1.13.2.5  nathanw 	int try, limit, tryidx, end, idx;
    146  1.13.2.5  nathanw 	struct vm_page *pgs;
    147  1.13.2.5  nathanw 	paddr_t idxpa, lastidxpa;
    148  1.13.2.5  nathanw 	u_long pagemask;
    149  1.13.2.5  nathanw #ifdef DEBUG
    150  1.13.2.5  nathanw 	int cidx;
    151  1.13.2.5  nathanw #endif
    152       1.3      mrg 
    153  1.13.2.5  nathanw 	limit = min(atop(high), vm_physmem[psi].avail_end);
    154  1.13.2.5  nathanw 	pagemask = ~(boundary - 1);
    155       1.3      mrg 
    156  1.13.2.5  nathanw 	for (try = roundup(max(atop(low), vm_physmem[psi].avail_start),
    157  1.13.2.5  nathanw 			   atop(alignment));; try += atop(alignment)) {
    158  1.13.2.5  nathanw 		if (try + atop(size) >= limit) {
    159      1.12      chs 
    160       1.3      mrg 			/*
    161       1.3      mrg 			 * We've run past the allowable range.
    162       1.3      mrg 			 */
    163      1.12      chs 
    164  1.13.2.5  nathanw 			return (0); /* FAIL */
    165       1.3      mrg 		}
    166  1.13.2.5  nathanw #ifdef DEBUG
    167       1.3      mrg 		/*
    168       1.3      mrg 		 * Make sure this is a managed physical page.
    169       1.3      mrg 		 */
    170       1.3      mrg 
    171  1.13.2.5  nathanw 		if (vm_physseg_find(try, &cidx) != psi)
    172  1.13.2.5  nathanw 			panic("pgalloc contig: botch1");
    173  1.13.2.5  nathanw 		if (cidx != try - vm_physmem[psi].start)
    174  1.13.2.5  nathanw 			panic("pgalloc contig: botch2");
    175  1.13.2.5  nathanw 		if (vm_physseg_find(try + atop(size), &cidx) != psi)
    176  1.13.2.5  nathanw 			panic("pgalloc contig: botch3");
    177  1.13.2.5  nathanw 		if (cidx != try - vm_physmem[psi].start + atop(size))
    178  1.13.2.5  nathanw 			panic("pgalloc contig: botch4");
    179  1.13.2.5  nathanw #endif
    180  1.13.2.5  nathanw 		tryidx = try - vm_physmem[psi].start;
    181  1.13.2.5  nathanw 		end = tryidx + (size / PAGE_SIZE);
    182       1.3      mrg 		pgs = vm_physmem[psi].pgs;
    183       1.3      mrg 
    184       1.3      mrg 		/*
    185       1.3      mrg 		 * Found a suitable starting page.  See of the range is free.
    186       1.3      mrg 		 */
    187      1.12      chs 
    188  1.13.2.5  nathanw 		for (idx = tryidx; idx < end; idx++) {
    189       1.3      mrg 			if (VM_PAGE_IS_FREE(&pgs[idx]) == 0) {
    190       1.3      mrg 				break;
    191       1.3      mrg 			}
    192       1.3      mrg 			idxpa = VM_PAGE_TO_PHYS(&pgs[idx]);
    193       1.3      mrg 			if (idx > tryidx) {
    194       1.3      mrg 				lastidxpa = VM_PAGE_TO_PHYS(&pgs[idx - 1]);
    195      1.12      chs 				if ((lastidxpa + PAGE_SIZE) != idxpa) {
    196       1.3      mrg 
    197       1.3      mrg 					/*
    198       1.3      mrg 					 * Region not contiguous.
    199       1.3      mrg 					 */
    200      1.12      chs 
    201  1.13.2.5  nathanw 					panic("pgalloc contig: botch5");
    202       1.3      mrg 				}
    203       1.3      mrg 				if (boundary != 0 &&
    204       1.3      mrg 				    ((lastidxpa ^ idxpa) & pagemask) != 0) {
    205      1.12      chs 
    206       1.3      mrg 					/*
    207       1.3      mrg 					 * Region crosses boundary.
    208       1.3      mrg 					 */
    209      1.12      chs 
    210       1.3      mrg 					break;
    211       1.3      mrg 				}
    212       1.3      mrg 			}
    213       1.3      mrg 		}
    214       1.3      mrg 		if (idx == end) {
    215       1.3      mrg 			break;
    216       1.3      mrg 		}
    217       1.1      mrg 	}
    218       1.1      mrg 
    219       1.3      mrg 	/*
    220       1.3      mrg 	 * we have a chunk of memory that conforms to the requested constraints.
    221       1.3      mrg 	 */
    222       1.3      mrg 	idx = tryidx;
    223       1.3      mrg 	while (idx < end) {
    224  1.13.2.5  nathanw 		uvm_pglist_add(&pgs[idx++], rlist);
    225  1.13.2.5  nathanw 	}
    226  1.13.2.5  nathanw 	return (1);
    227  1.13.2.5  nathanw }
    228  1.13.2.5  nathanw 
    229  1.13.2.5  nathanw static int
    230  1.13.2.5  nathanw uvm_pglistalloc_contig(size, low, high, alignment, boundary, rlist)
    231  1.13.2.5  nathanw 	psize_t size;
    232  1.13.2.5  nathanw 	paddr_t low, high, alignment, boundary;
    233  1.13.2.5  nathanw 	struct pglist *rlist;
    234  1.13.2.5  nathanw {
    235  1.13.2.5  nathanw 	int fl, psi;
    236  1.13.2.5  nathanw 	int s, error;
    237  1.13.2.5  nathanw 
    238  1.13.2.5  nathanw 	if (boundary != 0 && boundary < size)
    239  1.13.2.5  nathanw 		return (EINVAL);
    240  1.13.2.5  nathanw 
    241  1.13.2.5  nathanw 	/* Default to "lose". */
    242  1.13.2.5  nathanw 	error = ENOMEM;
    243  1.13.2.5  nathanw 
    244  1.13.2.5  nathanw 	/*
    245  1.13.2.5  nathanw 	 * Block all memory allocation and lock the free list.
    246  1.13.2.5  nathanw 	 */
    247  1.13.2.5  nathanw 
    248  1.13.2.5  nathanw 	s = uvm_lock_fpageq();
    249  1.13.2.5  nathanw 
    250  1.13.2.5  nathanw 	/* Are there even any free pages? */
    251  1.13.2.5  nathanw 	if (uvmexp.free <= (uvmexp.reserve_pagedaemon + uvmexp.reserve_kernel))
    252  1.13.2.5  nathanw 		goto out;
    253  1.13.2.5  nathanw 
    254  1.13.2.5  nathanw 	for (fl = 0; fl < VM_NFREELIST; fl++) {
    255  1.13.2.5  nathanw #if (VM_PHYSSEG_STRAT == VM_PSTRAT_BIGFIRST)
    256  1.13.2.5  nathanw 		for (psi = vm_nphysseg - 1 ; psi >= 0 ; psi--)
    257  1.13.2.5  nathanw #else
    258  1.13.2.5  nathanw 		for (psi = 0 ; psi < vm_nphysseg ; psi++)
    259  1.13.2.5  nathanw #endif
    260  1.13.2.5  nathanw 		{
    261  1.13.2.5  nathanw 			if (vm_physmem[psi].free_list != fl)
    262  1.13.2.5  nathanw 				continue;
    263  1.13.2.5  nathanw 
    264  1.13.2.5  nathanw 			if (uvm_pglistalloc_c_ps(psi, size, low, high,
    265  1.13.2.5  nathanw 						 alignment, boundary, rlist)) {
    266  1.13.2.5  nathanw #if 0
    267  1.13.2.5  nathanw 				printf("pgalloc: %lx-%lx\n",
    268  1.13.2.5  nathanw 				       TAILQ_FIRST(rlist)->phys_addr,
    269  1.13.2.5  nathanw 				       TAILQ_LAST(rlist, pglist)->phys_addr);
    270  1.13.2.5  nathanw #endif
    271  1.13.2.5  nathanw 				error = 0;
    272  1.13.2.5  nathanw 				goto out;
    273  1.13.2.5  nathanw 			}
    274       1.3      mrg 		}
    275  1.13.2.5  nathanw 	}
    276  1.13.2.5  nathanw 
    277  1.13.2.5  nathanw out:
    278  1.13.2.5  nathanw 	/*
    279  1.13.2.5  nathanw 	 * check to see if we need to generate some free pages waking
    280  1.13.2.5  nathanw 	 * the pagedaemon.
    281  1.13.2.5  nathanw 	 */
    282  1.13.2.5  nathanw 
    283  1.13.2.5  nathanw 	UVM_KICK_PDAEMON();
    284  1.13.2.5  nathanw 	uvm_unlock_fpageq(s);
    285  1.13.2.5  nathanw 	return (error);
    286  1.13.2.5  nathanw }
    287  1.13.2.5  nathanw 
    288  1.13.2.5  nathanw static void
    289  1.13.2.5  nathanw uvm_pglistalloc_s_ps(psi, low, high, rlist, todo)
    290  1.13.2.5  nathanw 	int psi;
    291  1.13.2.5  nathanw 	paddr_t low, high;
    292  1.13.2.5  nathanw 	struct pglist *rlist;
    293  1.13.2.5  nathanw 	int *todo;
    294  1.13.2.5  nathanw {
    295  1.13.2.5  nathanw 	int limit, try;
    296  1.13.2.5  nathanw 	struct vm_page *pg;
    297  1.13.2.5  nathanw #ifdef DEBUG
    298  1.13.2.5  nathanw 	int cidx;
    299  1.13.2.5  nathanw #endif
    300  1.13.2.5  nathanw 
    301  1.13.2.5  nathanw 	limit = min(atop(high), vm_physmem[psi].avail_end);
    302  1.13.2.5  nathanw 
    303  1.13.2.5  nathanw 	for (try = max(atop(low), vm_physmem[psi].avail_start);
    304  1.13.2.5  nathanw 	     try < limit; try ++) {
    305  1.13.2.5  nathanw #ifdef DEBUG
    306  1.13.2.5  nathanw 		if (vm_physseg_find(try, &cidx) != psi)
    307  1.13.2.5  nathanw 			panic("pgalloc simple: botch1");
    308  1.13.2.5  nathanw 		if (cidx != (try - vm_physmem[psi].start))
    309  1.13.2.5  nathanw 			panic("pgalloc simple: botch2");
    310  1.13.2.5  nathanw #endif
    311  1.13.2.5  nathanw 		pg = &vm_physmem[psi].pgs[try - vm_physmem[psi].start];
    312  1.13.2.5  nathanw 		if (VM_PAGE_IS_FREE(pg) == 0)
    313  1.13.2.5  nathanw 			continue;
    314  1.13.2.5  nathanw 
    315  1.13.2.5  nathanw 		uvm_pglist_add(pg, rlist);
    316  1.13.2.5  nathanw 		if (--(*todo) == 0)
    317  1.13.2.5  nathanw 			break;
    318  1.13.2.5  nathanw 	}
    319  1.13.2.5  nathanw }
    320  1.13.2.5  nathanw 
    321  1.13.2.5  nathanw static int
    322  1.13.2.5  nathanw uvm_pglistalloc_simple(size, low, high, rlist, waitok)
    323  1.13.2.5  nathanw 	psize_t size;
    324  1.13.2.5  nathanw 	paddr_t low, high;
    325  1.13.2.5  nathanw 	struct pglist *rlist;
    326  1.13.2.5  nathanw 	int waitok;
    327  1.13.2.5  nathanw {
    328  1.13.2.5  nathanw 	int fl, psi, s, todo, error;
    329  1.13.2.5  nathanw 
    330  1.13.2.5  nathanw 	/* Default to "lose". */
    331  1.13.2.5  nathanw 	error = ENOMEM;
    332  1.13.2.5  nathanw 
    333  1.13.2.5  nathanw 	todo = size / PAGE_SIZE;
    334  1.13.2.5  nathanw 
    335  1.13.2.5  nathanw again:
    336  1.13.2.5  nathanw 	/*
    337  1.13.2.5  nathanw 	 * Block all memory allocation and lock the free list.
    338  1.13.2.5  nathanw 	 */
    339  1.13.2.5  nathanw 
    340  1.13.2.5  nathanw 	s = uvm_lock_fpageq();
    341  1.13.2.5  nathanw 
    342  1.13.2.5  nathanw 	/* Are there even any free pages? */
    343  1.13.2.5  nathanw 	if (uvmexp.free <= (uvmexp.reserve_pagedaemon + uvmexp.reserve_kernel))
    344  1.13.2.5  nathanw 		goto out;
    345  1.13.2.5  nathanw 
    346  1.13.2.5  nathanw 	for (fl = 0; fl < VM_NFREELIST; fl++) {
    347  1.13.2.5  nathanw #if (VM_PHYSSEG_STRAT == VM_PSTRAT_BIGFIRST)
    348  1.13.2.5  nathanw 		for (psi = vm_nphysseg - 1 ; psi >= 0 ; psi--)
    349  1.13.2.5  nathanw #else
    350  1.13.2.5  nathanw 		for (psi = 0 ; psi < vm_nphysseg ; psi++)
    351       1.1      mrg #endif
    352  1.13.2.5  nathanw 		{
    353  1.13.2.5  nathanw 			if (vm_physmem[psi].free_list != fl)
    354  1.13.2.5  nathanw 				continue;
    355  1.13.2.5  nathanw 
    356  1.13.2.5  nathanw 			uvm_pglistalloc_s_ps(psi, low, high, rlist, &todo);
    357  1.13.2.5  nathanw 			if (todo == 0) {
    358  1.13.2.5  nathanw 				error = 0;
    359  1.13.2.5  nathanw 				goto out;
    360  1.13.2.5  nathanw 			}
    361  1.13.2.5  nathanw 		}
    362  1.13.2.5  nathanw 
    363       1.3      mrg 	}
    364       1.1      mrg 
    365       1.1      mrg out:
    366       1.3      mrg 	/*
    367       1.3      mrg 	 * check to see if we need to generate some free pages waking
    368       1.3      mrg 	 * the pagedaemon.
    369       1.3      mrg 	 */
    370  1.13.2.1  nathanw 
    371  1.13.2.2  nathanw 	UVM_KICK_PDAEMON();
    372      1.12      chs 	uvm_unlock_fpageq(s);
    373  1.13.2.5  nathanw 	if (error) {
    374  1.13.2.5  nathanw 		if (waitok) {
    375  1.13.2.5  nathanw 			/* XXX perhaps some time limitation? */
    376  1.13.2.5  nathanw #ifdef DEBUG
    377  1.13.2.5  nathanw 			printf("pglistalloc waiting\n");
    378  1.13.2.5  nathanw #endif
    379  1.13.2.5  nathanw 			uvm_wait("pglalloc");
    380  1.13.2.5  nathanw 			goto again;
    381  1.13.2.5  nathanw 		} else
    382  1.13.2.5  nathanw 			uvm_pglistfree(rlist);
    383  1.13.2.5  nathanw 	}
    384  1.13.2.5  nathanw #if 0
    385  1.13.2.5  nathanw 	if (!error)
    386  1.13.2.5  nathanw 		printf("pgalloc: %lx..%lx\n",
    387  1.13.2.5  nathanw 		       TAILQ_FIRST(rlist)->phys_addr,
    388  1.13.2.5  nathanw 		       TAILQ_LAST(rlist, pglist)->phys_addr);
    389  1.13.2.5  nathanw #endif
    390       1.3      mrg 	return (error);
    391  1.13.2.5  nathanw }
    392  1.13.2.5  nathanw 
    393  1.13.2.5  nathanw int
    394  1.13.2.5  nathanw uvm_pglistalloc(size, low, high, alignment, boundary, rlist, nsegs, waitok)
    395  1.13.2.5  nathanw 	psize_t size;
    396  1.13.2.5  nathanw 	paddr_t low, high, alignment, boundary;
    397  1.13.2.5  nathanw 	struct pglist *rlist;
    398  1.13.2.5  nathanw 	int nsegs, waitok;
    399  1.13.2.5  nathanw {
    400  1.13.2.5  nathanw 	int res;
    401  1.13.2.5  nathanw 
    402  1.13.2.5  nathanw 	KASSERT((alignment & (alignment - 1)) == 0);
    403  1.13.2.5  nathanw 	KASSERT((boundary & (boundary - 1)) == 0);
    404  1.13.2.5  nathanw 
    405  1.13.2.5  nathanw 	/*
    406  1.13.2.5  nathanw 	 * Our allocations are always page granularity, so our alignment
    407  1.13.2.5  nathanw 	 * must be, too.
    408  1.13.2.5  nathanw 	 */
    409  1.13.2.5  nathanw 	if (alignment < PAGE_SIZE)
    410  1.13.2.5  nathanw 		alignment = PAGE_SIZE;
    411  1.13.2.5  nathanw 	size = round_page(size);
    412  1.13.2.5  nathanw 	low = roundup(low, alignment);
    413  1.13.2.5  nathanw 
    414  1.13.2.5  nathanw 	TAILQ_INIT(rlist);
    415  1.13.2.5  nathanw 
    416  1.13.2.5  nathanw 	if ((nsegs < size / PAGE_SIZE) || (alignment != PAGE_SIZE)
    417  1.13.2.5  nathanw 	    || (boundary != 0))
    418  1.13.2.5  nathanw 		res = uvm_pglistalloc_contig(size, low, high, alignment,
    419  1.13.2.5  nathanw 					     boundary, rlist);
    420  1.13.2.5  nathanw 	else
    421  1.13.2.5  nathanw 		res = uvm_pglistalloc_simple(size, low, high, rlist, waitok);
    422  1.13.2.5  nathanw 
    423  1.13.2.5  nathanw 	return (res);
    424       1.1      mrg }
    425       1.1      mrg 
    426       1.1      mrg /*
    427       1.1      mrg  * uvm_pglistfree: free a list of pages
    428       1.1      mrg  *
    429       1.1      mrg  * => pages should already be unmapped
    430       1.1      mrg  */
    431       1.1      mrg 
    432       1.3      mrg void
    433       1.3      mrg uvm_pglistfree(list)
    434       1.3      mrg 	struct pglist *list;
    435       1.1      mrg {
    436  1.13.2.3  nathanw 	struct vm_page *pg;
    437       1.3      mrg 	int s;
    438       1.1      mrg 
    439       1.3      mrg 	/*
    440  1.13.2.3  nathanw 	 * Lock the free list and free each page.
    441       1.3      mrg 	 */
    442       1.1      mrg 
    443  1.13.2.3  nathanw 	s = uvm_lock_fpageq();
    444  1.13.2.3  nathanw 	while ((pg = TAILQ_FIRST(list)) != NULL) {
    445  1.13.2.3  nathanw 		KASSERT((pg->pqflags & (PQ_ACTIVE|PQ_INACTIVE)) == 0);
    446  1.13.2.3  nathanw 		TAILQ_REMOVE(list, pg, pageq);
    447  1.13.2.3  nathanw 		pg->pqflags = PQ_FREE;
    448  1.13.2.3  nathanw 		TAILQ_INSERT_TAIL(&uvm.page_free[uvm_page_lookup_freelist(pg)].
    449  1.13.2.3  nathanw 		    pgfl_buckets[VM_PGCOLOR_BUCKET(pg)].
    450  1.13.2.3  nathanw 		    pgfl_queues[PGFL_UNKNOWN], pg, pageq);
    451       1.3      mrg 		uvmexp.free++;
    452       1.9  thorpej 		if (uvmexp.zeropages < UVM_PAGEZERO_TARGET)
    453       1.9  thorpej 			uvm.page_idle_zero = vm_page_zero_enable;
    454       1.3      mrg 		STAT_DECR(uvm_pglistalloc_npages);
    455       1.3      mrg 	}
    456       1.7  thorpej 	uvm_unlock_fpageq(s);
    457       1.1      mrg }
    458