2020-06-15 00:41:42 +03:00
|
|
|
/* $NetBSD: uvm_pglist.c,v 1.85 2020/06/14 21:41:42 ad Exp $ */
|
2009-03-10 06:27:24 +03:00
|
|
|
|
1998-02-05 09:25:08 +03:00
|
|
|
/*-
|
2019-12-27 15:51:56 +03:00
|
|
|
* Copyright (c) 1997, 2019 The NetBSD Foundation, Inc.
|
1998-02-05 09:25:08 +03:00
|
|
|
* All rights reserved.
|
2001-05-25 08:06:11 +04:00
|
|
|
*
|
1998-02-05 09:25:08 +03:00
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
|
2019-12-27 15:51:56 +03:00
|
|
|
* NASA Ames Research Center, and by Andrew Doran.
|
1998-02-05 09:25:08 +03:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
2001-05-25 08:06:11 +04:00
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
1998-02-05 09:25:08 +03:00
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2001-05-25 08:06:11 +04:00
|
|
|
*
|
1998-02-05 09:25:08 +03:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* uvm_pglist.c: pglist functions
|
|
|
|
*/
|
|
|
|
|
2001-11-10 10:36:59 +03:00
|
|
|
#include <sys/cdefs.h>
|
2020-06-15 00:41:42 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: uvm_pglist.c,v 1.85 2020/06/14 21:41:42 ad Exp $");
|
2001-11-10 10:36:59 +03:00
|
|
|
|
1998-02-05 09:25:08 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
2020-03-02 00:43:56 +03:00
|
|
|
#include <sys/cpu.h>
|
1998-02-05 09:25:08 +03:00
|
|
|
|
|
|
|
#include <uvm/uvm.h>
|
2006-09-15 19:51:12 +04:00
|
|
|
#include <uvm/uvm_pdpolicy.h>
|
2019-12-27 15:51:56 +03:00
|
|
|
#include <uvm/uvm_pgflcache.h>
|
1998-02-05 09:25:08 +03:00
|
|
|
|
|
|
|
#ifdef VM_PAGE_ALLOC_MEMORY_STATS
|
|
|
|
#define STAT_INCR(v) (v)++
|
|
|
|
#define STAT_DECR(v) do { \
|
|
|
|
if ((v) == 0) \
|
|
|
|
printf("%s:%d -- Already 0!\n", __FILE__, __LINE__); \
|
|
|
|
else \
|
|
|
|
(v)--; \
|
2002-11-02 10:40:47 +03:00
|
|
|
} while (/*CONSTCOND*/ 0)
|
1998-02-05 09:25:08 +03:00
|
|
|
u_long uvm_pglistalloc_npages;
|
|
|
|
#else
|
|
|
|
#define STAT_INCR(v)
|
|
|
|
#define STAT_DECR(v)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* uvm_pglistalloc: allocate a list of pages
|
|
|
|
*
|
2003-08-02 18:12:51 +04:00
|
|
|
* => allocated pages are placed onto an rlist. rlist is
|
|
|
|
* initialized by uvm_pglistalloc.
|
1998-02-05 09:25:08 +03:00
|
|
|
* => returns 0 on success or errno on failure
|
2003-08-02 18:12:51 +04:00
|
|
|
* => implementation allocates a single segment if any constraints are
|
|
|
|
* imposed by call arguments.
|
1998-02-05 09:25:08 +03:00
|
|
|
* => doesn't take into account clean non-busy pages on inactive list
|
|
|
|
* that could be used(?)
|
|
|
|
* => params:
|
|
|
|
* size the size of the allocation, rounded to page size.
|
|
|
|
* low the low address of the allowed allocation range.
|
|
|
|
* high the high address of the allowed allocation range.
|
|
|
|
* alignment memory must be aligned to this power-of-two boundary.
|
2001-05-25 08:06:11 +04:00
|
|
|
* boundary no segment in the allocation may cross this
|
1998-02-05 09:25:08 +03:00
|
|
|
* power-of-two boundary (relative to zero).
|
|
|
|
*/
|
|
|
|
|
2002-05-29 23:20:11 +04:00
|
|
|
static void
|
2005-06-27 06:19:48 +04:00
|
|
|
uvm_pglist_add(struct vm_page *pg, struct pglist *rlist)
|
1998-02-05 09:25:08 +03:00
|
|
|
{
|
2019-12-27 15:51:56 +03:00
|
|
|
struct pgfreelist *pgfl;
|
|
|
|
struct pgflbucket *pgb;
|
1998-02-05 09:25:08 +03:00
|
|
|
|
2019-12-27 15:51:56 +03:00
|
|
|
pgfl = &uvm.page_free[uvm_page_get_freelist(pg)];
|
|
|
|
pgb = pgfl->pgfl_buckets[uvm_page_get_bucket(pg)];
|
2008-02-27 17:24:24 +03:00
|
|
|
|
2014-10-26 04:42:07 +03:00
|
|
|
#ifdef UVMDEBUG
|
2011-01-19 00:43:29 +03:00
|
|
|
struct vm_page *tp;
|
2019-12-27 15:51:56 +03:00
|
|
|
LIST_FOREACH(tp, &pgb->pgb_colors[VM_PGCOLOR(pg)], pageq.list) {
|
2002-05-29 23:20:11 +04:00
|
|
|
if (tp == pg)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (tp == NULL)
|
|
|
|
panic("uvm_pglistalloc: page not on freelist");
|
|
|
|
#endif
|
2019-12-27 15:51:56 +03:00
|
|
|
LIST_REMOVE(pg, pageq.list);
|
|
|
|
pgb->pgb_nfree--;
|
2020-06-12 01:25:51 +03:00
|
|
|
CPU_COUNT(CPU_COUNT_FREEPAGES, -1);
|
2002-05-29 23:20:11 +04:00
|
|
|
pg->flags = PG_CLEAN;
|
|
|
|
pg->uobject = NULL;
|
|
|
|
pg->uanon = NULL;
|
2008-06-04 16:45:28 +04:00
|
|
|
TAILQ_INSERT_TAIL(rlist, pg, pageq.queue);
|
2002-05-29 23:20:11 +04:00
|
|
|
STAT_INCR(uvm_pglistalloc_npages);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2016-12-23 10:15:27 +03:00
|
|
|
uvm_pglistalloc_c_ps(uvm_physseg_t psi, int num, paddr_t low, paddr_t high,
|
2005-06-27 06:19:48 +04:00
|
|
|
paddr_t alignment, paddr_t boundary, struct pglist *rlist)
|
2002-05-29 23:20:11 +04:00
|
|
|
{
|
2014-09-05 09:36:21 +04:00
|
|
|
signed int candidate, limit, candidateidx, end, idx, skip;
|
2002-06-27 22:05:29 +04:00
|
|
|
int pagemask;
|
2011-01-19 00:43:29 +03:00
|
|
|
bool second_pass;
|
2002-06-18 19:49:48 +04:00
|
|
|
#ifdef DEBUG
|
2002-06-27 22:05:29 +04:00
|
|
|
paddr_t idxpa, lastidxpa;
|
2016-12-23 10:15:27 +03:00
|
|
|
paddr_t cidx = 0; /* XXX: GCC */
|
2002-06-18 19:49:48 +04:00
|
|
|
#endif
|
2002-06-27 22:05:29 +04:00
|
|
|
#ifdef PGALLOC_VERBOSE
|
2020-02-20 07:54:47 +03:00
|
|
|
printf("pgalloc: contig %d pgs from psi %d\n", num, psi);
|
2002-06-27 22:05:29 +04:00
|
|
|
#endif
|
a whole bunch of changes to improve performance and robustness under load:
- remove special treatment of pager_map mappings in pmaps. this is
required now, since I've removed the globals that expose the address range.
pager_map now uses pmap_kenter_pa() instead of pmap_enter(), so there's
no longer any need to special-case it.
- eliminate struct uvm_vnode by moving its fields into struct vnode.
- rewrite the pageout path. the pager is now responsible for handling the
high-level requests instead of only getting control after a bunch of work
has already been done on its behalf. this will allow us to UBCify LFS,
which needs tighter control over its pages than other filesystems do.
writing a page to disk no longer requires making it read-only, which
allows us to write wired pages without causing all kinds of havoc.
- use a new PG_PAGEOUT flag to indicate that a page should be freed
on behalf of the pagedaemon when it's unlocked. this flag is very similar
to PG_RELEASED, but unlike PG_RELEASED, PG_PAGEOUT can be cleared if the
pageout fails due to eg. an indirect-block buffer being locked.
this allows us to remove the "version" field from struct vm_page,
and together with shrinking "loan_count" from 32 bits to 16,
struct vm_page is now 4 bytes smaller.
- no longer use PG_RELEASED for swap-backed pages. if the page is busy
because it's being paged out, we can't release the swap slot to be
reallocated until that write is complete, but unlike with vnodes we
don't keep a count of in-progress writes so there's no good way to
know when the write is done. instead, when we need to free a busy
swap-backed page, just sleep until we can get it busy ourselves.
- implement a fast-path for extending writes which allows us to avoid
zeroing new pages. this substantially reduces cpu usage.
- encapsulate the data used by the genfs code in a struct genfs_node,
which must be the first element of the filesystem-specific vnode data
for filesystems which use genfs_{get,put}pages().
- eliminate many of the UVM pagerops, since they aren't needed anymore
now that the pager "put" operation is a higher-level operation.
- enhance the genfs code to allow NFS to use the genfs_{get,put}pages
instead of a modified copy.
- clean up struct vnode by removing all the fields that used to be used by
the vfs_cluster.c code (which we don't use anymore with UBC).
- remove kmem_object and mb_object since they were useless.
instead of allocating pages to these objects, we now just allocate
pages with no object. such pages are mapped in the kernel until they
are freed, so we can use the mapping to find the page to free it.
this allows us to remove splvm() protection in several places.
The sum of all these changes improves write throughput on my
decstation 5000/200 to within 1% of the rate of NetBSD 1.5
and reduces the elapsed time for "make release" of a NetBSD 1.5
source tree on my 128MB pc to 10% less than a 1.5 kernel took.
2001-09-16 00:36:31 +04:00
|
|
|
|
2011-01-19 00:43:29 +03:00
|
|
|
low = atop(low);
|
|
|
|
high = atop(high);
|
|
|
|
alignment = atop(alignment);
|
|
|
|
|
2011-01-24 22:13:55 +03:00
|
|
|
/*
|
|
|
|
* Make sure that physseg falls within with range to be allocated from.
|
|
|
|
*/
|
2016-12-23 10:15:27 +03:00
|
|
|
if (high <= uvm_physseg_get_avail_start(psi) || low >= uvm_physseg_get_avail_end(psi))
|
2011-01-24 22:13:55 +03:00
|
|
|
return 0;
|
|
|
|
|
2011-01-19 00:43:29 +03:00
|
|
|
/*
|
|
|
|
* We start our search at the just after where the last allocation
|
|
|
|
* succeeded.
|
|
|
|
*/
|
Rename min/max -> uimin/uimax for better honesty.
These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.
HOWEVER! Some subsystems have
#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))
even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.
To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.
I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:
cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))
It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.
Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)
2018-09-03 19:29:22 +03:00
|
|
|
candidate = roundup2(uimax(low, uvm_physseg_get_avail_start(psi) +
|
2016-12-23 10:15:27 +03:00
|
|
|
uvm_physseg_get_start_hint(psi)), alignment);
|
Rename min/max -> uimin/uimax for better honesty.
These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.
HOWEVER! Some subsystems have
#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))
even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.
To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.
I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:
cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))
It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.
Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)
2018-09-03 19:29:22 +03:00
|
|
|
limit = uimin(high, uvm_physseg_get_avail_end(psi));
|
2002-06-27 22:05:29 +04:00
|
|
|
pagemask = ~((boundary >> PAGE_SHIFT) - 1);
|
2011-01-19 00:43:29 +03:00
|
|
|
skip = 0;
|
|
|
|
second_pass = false;
|
2000-11-25 09:27:59 +03:00
|
|
|
|
2002-06-27 22:05:29 +04:00
|
|
|
for (;;) {
|
2011-01-19 00:43:29 +03:00
|
|
|
bool ok = true;
|
|
|
|
signed int cnt;
|
|
|
|
|
2014-09-05 09:36:21 +04:00
|
|
|
if (candidate + num > limit) {
|
2016-12-23 10:15:27 +03:00
|
|
|
if (uvm_physseg_get_start_hint(psi) == 0 || second_pass) {
|
2011-01-19 00:43:29 +03:00
|
|
|
/*
|
|
|
|
* We've run past the allowable range.
|
|
|
|
*/
|
|
|
|
return 0; /* FAIL = 0 pages*/
|
|
|
|
}
|
1998-03-09 03:58:55 +03:00
|
|
|
/*
|
2011-01-19 00:43:29 +03:00
|
|
|
* We've wrapped around the end of this segment
|
|
|
|
* so restart at the beginning but now our limit
|
|
|
|
* is were we started.
|
1998-03-09 03:58:55 +03:00
|
|
|
*/
|
2011-01-19 00:43:29 +03:00
|
|
|
second_pass = true;
|
Rename min/max -> uimin/uimax for better honesty.
These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.
HOWEVER! Some subsystems have
#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))
even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.
To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.
I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:
cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))
It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.
Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)
2018-09-03 19:29:22 +03:00
|
|
|
candidate = roundup2(uimax(low, uvm_physseg_get_avail_start(psi)), alignment);
|
|
|
|
limit = uimin(limit, uvm_physseg_get_avail_start(psi) +
|
2016-12-23 10:15:27 +03:00
|
|
|
uvm_physseg_get_start_hint(psi));
|
2011-01-19 00:43:29 +03:00
|
|
|
skip = 0;
|
|
|
|
continue;
|
1998-03-09 03:58:55 +03:00
|
|
|
}
|
2002-06-27 22:05:29 +04:00
|
|
|
if (boundary != 0 &&
|
2014-09-05 09:36:21 +04:00
|
|
|
((candidate ^ (candidate + num - 1)) & pagemask) != 0) {
|
2002-06-27 22:05:29 +04:00
|
|
|
/*
|
|
|
|
* Region crosses boundary. Jump to the boundary
|
|
|
|
* just crossed and ensure alignment.
|
|
|
|
*/
|
2014-09-05 09:36:21 +04:00
|
|
|
candidate = (candidate + num - 1) & pagemask;
|
|
|
|
candidate = roundup2(candidate, alignment);
|
2011-01-19 00:43:29 +03:00
|
|
|
skip = 0;
|
2002-06-27 22:05:29 +04:00
|
|
|
continue;
|
|
|
|
}
|
2002-06-18 19:49:48 +04:00
|
|
|
#ifdef DEBUG
|
1998-03-09 03:58:55 +03:00
|
|
|
/*
|
|
|
|
* Make sure this is a managed physical page.
|
|
|
|
*/
|
|
|
|
|
2016-12-23 10:15:27 +03:00
|
|
|
if (uvm_physseg_find(candidate, &cidx) != psi)
|
2002-06-18 19:49:48 +04:00
|
|
|
panic("pgalloc contig: botch1");
|
2016-12-23 10:15:27 +03:00
|
|
|
if (cidx != candidate - uvm_physseg_get_start(psi))
|
2002-06-18 19:49:48 +04:00
|
|
|
panic("pgalloc contig: botch2");
|
2016-12-23 10:15:27 +03:00
|
|
|
if (uvm_physseg_find(candidate + num - 1, &cidx) != psi)
|
2002-06-18 19:49:48 +04:00
|
|
|
panic("pgalloc contig: botch3");
|
2016-12-23 10:15:27 +03:00
|
|
|
if (cidx != candidate - uvm_physseg_get_start(psi) + num - 1)
|
2004-03-24 10:47:32 +03:00
|
|
|
panic("pgalloc contig: botch4");
|
2002-06-18 19:49:48 +04:00
|
|
|
#endif
|
2016-12-23 10:15:27 +03:00
|
|
|
candidateidx = candidate - uvm_physseg_get_start(psi);
|
2014-09-05 09:36:21 +04:00
|
|
|
end = candidateidx + num;
|
1998-03-09 03:58:55 +03:00
|
|
|
|
|
|
|
/*
|
2002-06-27 22:05:29 +04:00
|
|
|
* Found a suitable starting page. See if the range is free.
|
1998-03-09 03:58:55 +03:00
|
|
|
*/
|
2011-01-19 00:43:29 +03:00
|
|
|
#ifdef PGALLOC_VERBOSE
|
2020-02-20 07:54:47 +03:00
|
|
|
printf("%s: psi=%d candidate=%#x end=%#x skip=%#x, align=%#"PRIxPADDR,
|
|
|
|
__func__, psi, candidateidx, end, skip, alignment);
|
2011-01-19 00:43:29 +03:00
|
|
|
#endif
|
|
|
|
/*
|
|
|
|
* We start at the end and work backwards since if we find a
|
|
|
|
* non-free page, it makes no sense to continue.
|
|
|
|
*
|
|
|
|
* But on the plus size we have "vetted" some number of free
|
|
|
|
* pages. If this iteration fails, we may be able to skip
|
|
|
|
* testing most of those pages again in the next pass.
|
|
|
|
*/
|
2014-09-05 09:36:21 +04:00
|
|
|
for (idx = end - 1; idx >= candidateidx + skip; idx--) {
|
2016-12-23 10:15:27 +03:00
|
|
|
if (VM_PAGE_IS_FREE(uvm_physseg_get_pg(psi, idx)) == 0) {
|
2011-01-19 00:43:29 +03:00
|
|
|
ok = false;
|
1998-03-09 03:58:55 +03:00
|
|
|
break;
|
2011-01-19 00:43:29 +03:00
|
|
|
}
|
2002-06-27 22:05:29 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2014-09-05 09:36:21 +04:00
|
|
|
if (idx > candidateidx) {
|
2016-12-23 10:15:27 +03:00
|
|
|
idxpa = VM_PAGE_TO_PHYS(uvm_physseg_get_pg(psi, idx));
|
|
|
|
lastidxpa = VM_PAGE_TO_PHYS(uvm_physseg_get_pg(psi, idx - 1));
|
1998-03-09 03:58:55 +03:00
|
|
|
if ((lastidxpa + PAGE_SIZE) != idxpa) {
|
|
|
|
/*
|
|
|
|
* Region not contiguous.
|
|
|
|
*/
|
2002-06-18 19:49:48 +04:00
|
|
|
panic("pgalloc contig: botch5");
|
1998-03-09 03:58:55 +03:00
|
|
|
}
|
|
|
|
if (boundary != 0 &&
|
2002-06-27 22:05:29 +04:00
|
|
|
((lastidxpa ^ idxpa) & ~(boundary - 1))
|
|
|
|
!= 0) {
|
1998-03-09 03:58:55 +03:00
|
|
|
/*
|
|
|
|
* Region crosses boundary.
|
|
|
|
*/
|
2002-06-27 22:05:29 +04:00
|
|
|
panic("pgalloc contig: botch6");
|
1998-03-09 03:58:55 +03:00
|
|
|
}
|
|
|
|
}
|
2002-06-27 22:05:29 +04:00
|
|
|
#endif
|
1998-03-09 03:58:55 +03:00
|
|
|
}
|
2011-01-19 00:43:29 +03:00
|
|
|
|
|
|
|
if (ok) {
|
|
|
|
while (skip-- > 0) {
|
2016-12-23 10:15:27 +03:00
|
|
|
KDASSERT(VM_PAGE_IS_FREE(uvm_physseg_get_pg(psi, candidateidx + skip)));
|
2011-01-19 00:43:29 +03:00
|
|
|
}
|
|
|
|
#ifdef PGALLOC_VERBOSE
|
|
|
|
printf(": ok\n");
|
|
|
|
#endif
|
1998-03-09 03:58:55 +03:00
|
|
|
break;
|
2011-01-19 00:43:29 +03:00
|
|
|
}
|
2002-06-27 22:05:29 +04:00
|
|
|
|
2011-01-19 00:43:29 +03:00
|
|
|
#ifdef PGALLOC_VERBOSE
|
2014-09-05 09:36:21 +04:00
|
|
|
printf(": non-free at %#x\n", idx - candidateidx);
|
2011-01-19 00:43:29 +03:00
|
|
|
#endif
|
|
|
|
/*
|
|
|
|
* count the number of pages we can advance
|
|
|
|
* since we know they aren't all free.
|
|
|
|
*/
|
2014-09-05 09:36:21 +04:00
|
|
|
cnt = idx + 1 - candidateidx;
|
2011-01-19 00:43:29 +03:00
|
|
|
/*
|
|
|
|
* now round up that to the needed alignment.
|
|
|
|
*/
|
|
|
|
cnt = roundup2(cnt, alignment);
|
|
|
|
/*
|
|
|
|
* The number of pages we can skip checking
|
|
|
|
* (might be 0 if cnt > num).
|
|
|
|
*/
|
Rename min/max -> uimin/uimax for better honesty.
These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.
HOWEVER! Some subsystems have
#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))
even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.
To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.
I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:
cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))
It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.
Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)
2018-09-03 19:29:22 +03:00
|
|
|
skip = uimax(num - cnt, 0);
|
2014-09-05 09:36:21 +04:00
|
|
|
candidate += cnt;
|
1998-02-05 09:25:08 +03:00
|
|
|
}
|
1998-03-09 03:58:55 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* we have a chunk of memory that conforms to the requested constraints.
|
|
|
|
*/
|
2016-12-23 10:15:27 +03:00
|
|
|
for (idx = candidateidx; idx < end; idx++)
|
|
|
|
uvm_pglist_add(uvm_physseg_get_pg(psi, idx), rlist);
|
2011-01-19 00:43:29 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* the next time we need to search this segment, start after this
|
|
|
|
* chunk of pages we just allocated.
|
|
|
|
*/
|
2016-12-23 10:15:27 +03:00
|
|
|
uvm_physseg_set_start_hint(psi, candidate + num -
|
|
|
|
uvm_physseg_get_avail_start(psi));
|
|
|
|
KASSERTMSG(uvm_physseg_get_start_hint(psi) <=
|
|
|
|
uvm_physseg_get_avail_end(psi) - uvm_physseg_get_avail_start(psi),
|
2011-09-27 05:02:33 +04:00
|
|
|
"%x %u (%#x) <= %#"PRIxPADDR" - %#"PRIxPADDR" (%#"PRIxPADDR")",
|
2014-09-05 09:36:21 +04:00
|
|
|
candidate + num,
|
2016-12-23 10:15:27 +03:00
|
|
|
uvm_physseg_get_start_hint(psi), uvm_physseg_get_start_hint(psi),
|
|
|
|
uvm_physseg_get_avail_end(psi), uvm_physseg_get_avail_start(psi),
|
|
|
|
uvm_physseg_get_avail_end(psi) - uvm_physseg_get_avail_start(psi));
|
2002-06-27 22:05:29 +04:00
|
|
|
|
|
|
|
#ifdef PGALLOC_VERBOSE
|
|
|
|
printf("got %d pgs\n", num);
|
|
|
|
#endif
|
2011-01-19 00:43:29 +03:00
|
|
|
return num; /* number of pages allocated */
|
2002-06-18 19:49:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2005-06-27 06:19:48 +04:00
|
|
|
uvm_pglistalloc_contig(int num, paddr_t low, paddr_t high, paddr_t alignment,
|
|
|
|
paddr_t boundary, struct pglist *rlist)
|
2002-06-18 19:49:48 +04:00
|
|
|
{
|
2016-12-23 10:15:27 +03:00
|
|
|
int fl;
|
2007-07-21 23:21:53 +04:00
|
|
|
int error;
|
2002-06-18 19:49:48 +04:00
|
|
|
|
2016-12-23 10:15:27 +03:00
|
|
|
uvm_physseg_t psi;
|
2002-06-18 19:49:48 +04:00
|
|
|
/* Default to "lose". */
|
|
|
|
error = ENOMEM;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Block all memory allocation and lock the free list.
|
|
|
|
*/
|
2019-12-27 15:51:56 +03:00
|
|
|
uvm_pgfl_lock();
|
2002-06-18 19:49:48 +04:00
|
|
|
|
|
|
|
/* Are there even any free pages? */
|
2020-06-11 22:20:42 +03:00
|
|
|
if (uvm_availmem(false) <=
|
2019-12-31 16:07:09 +03:00
|
|
|
(uvmexp.reserve_pagedaemon + uvmexp.reserve_kernel))
|
2002-06-18 19:49:48 +04:00
|
|
|
goto out;
|
|
|
|
|
|
|
|
for (fl = 0; fl < VM_NFREELIST; fl++) {
|
|
|
|
#if (VM_PHYSSEG_STRAT == VM_PSTRAT_BIGFIRST)
|
2016-12-23 10:15:27 +03:00
|
|
|
for (psi = uvm_physseg_get_last(); uvm_physseg_valid_p(psi); psi = uvm_physseg_get_prev(psi))
|
2002-06-18 19:49:48 +04:00
|
|
|
#else
|
2016-12-23 10:15:27 +03:00
|
|
|
for (psi = uvm_physseg_get_first(); uvm_physseg_valid_p(psi); psi = uvm_physseg_get_next(psi))
|
2002-06-18 19:49:48 +04:00
|
|
|
#endif
|
|
|
|
{
|
2016-12-23 10:15:27 +03:00
|
|
|
if (uvm_physseg_get_free_list(psi) != fl)
|
2002-06-18 19:49:48 +04:00
|
|
|
continue;
|
|
|
|
|
2016-12-23 10:15:27 +03:00
|
|
|
num -= uvm_pglistalloc_c_ps(psi, num, low, high,
|
2002-06-27 22:05:29 +04:00
|
|
|
alignment, boundary, rlist);
|
|
|
|
if (num == 0) {
|
|
|
|
#ifdef PGALLOC_VERBOSE
|
2009-03-09 12:53:55 +03:00
|
|
|
printf("pgalloc: %"PRIxMAX"-%"PRIxMAX"\n",
|
|
|
|
(uintmax_t) VM_PAGE_TO_PHYS(TAILQ_FIRST(rlist)),
|
|
|
|
(uintmax_t) VM_PAGE_TO_PHYS(TAILQ_LAST(rlist, pglist)));
|
2002-06-18 19:49:48 +04:00
|
|
|
#endif
|
|
|
|
error = 0;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1998-02-05 09:25:08 +03:00
|
|
|
|
|
|
|
out:
|
1998-03-09 03:58:55 +03:00
|
|
|
/*
|
|
|
|
* check to see if we need to generate some free pages waking
|
|
|
|
* the pagedaemon.
|
|
|
|
*/
|
2001-05-25 08:06:11 +04:00
|
|
|
|
2019-12-27 15:51:56 +03:00
|
|
|
uvm_pgfl_unlock();
|
2019-12-21 17:50:34 +03:00
|
|
|
uvm_kick_pdaemon();
|
1998-03-09 03:58:55 +03:00
|
|
|
return (error);
|
1998-02-05 09:25:08 +03:00
|
|
|
}
|
|
|
|
|
2002-06-27 22:05:29 +04:00
|
|
|
static int
|
2016-12-23 10:15:27 +03:00
|
|
|
uvm_pglistalloc_s_ps(uvm_physseg_t psi, int num, paddr_t low, paddr_t high,
|
2005-06-27 06:19:48 +04:00
|
|
|
struct pglist *rlist)
|
2002-06-18 19:49:48 +04:00
|
|
|
{
|
2014-09-05 09:36:21 +04:00
|
|
|
int todo, limit, candidate;
|
2002-06-18 19:49:48 +04:00
|
|
|
struct vm_page *pg;
|
2011-01-19 00:43:29 +03:00
|
|
|
bool second_pass;
|
2002-06-27 22:05:29 +04:00
|
|
|
#ifdef PGALLOC_VERBOSE
|
2016-12-23 10:15:27 +03:00
|
|
|
printf("pgalloc: simple %d pgs from psi %zd\n", num, psi);
|
2002-06-27 22:05:29 +04:00
|
|
|
#endif
|
2002-06-18 19:49:48 +04:00
|
|
|
|
2016-12-23 10:15:27 +03:00
|
|
|
KASSERT(uvm_physseg_get_start(psi) <= uvm_physseg_get_avail_start(psi));
|
|
|
|
KASSERT(uvm_physseg_get_start(psi) <= uvm_physseg_get_avail_end(psi));
|
|
|
|
KASSERT(uvm_physseg_get_avail_start(psi) <= uvm_physseg_get_end(psi));
|
|
|
|
KASSERT(uvm_physseg_get_avail_end(psi) <= uvm_physseg_get_end(psi));
|
2008-02-27 17:24:24 +03:00
|
|
|
|
2011-01-19 00:43:29 +03:00
|
|
|
low = atop(low);
|
|
|
|
high = atop(high);
|
2002-06-27 22:05:29 +04:00
|
|
|
todo = num;
|
Rename min/max -> uimin/uimax for better honesty.
These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.
HOWEVER! Some subsystems have
#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))
even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.
To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.
I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:
cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))
It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.
Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)
2018-09-03 19:29:22 +03:00
|
|
|
candidate = uimax(low, uvm_physseg_get_avail_start(psi) +
|
2016-12-23 10:15:27 +03:00
|
|
|
uvm_physseg_get_start_hint(psi));
|
Rename min/max -> uimin/uimax for better honesty.
These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.
HOWEVER! Some subsystems have
#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))
even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.
To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.
I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:
cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))
It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.
Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)
2018-09-03 19:29:22 +03:00
|
|
|
limit = uimin(high, uvm_physseg_get_avail_end(psi));
|
2016-12-23 10:15:27 +03:00
|
|
|
pg = uvm_physseg_get_pg(psi, candidate - uvm_physseg_get_start(psi));
|
2011-01-19 00:43:29 +03:00
|
|
|
second_pass = false;
|
|
|
|
|
2011-01-24 22:13:55 +03:00
|
|
|
/*
|
|
|
|
* Make sure that physseg falls within with range to be allocated from.
|
|
|
|
*/
|
2016-12-23 10:15:27 +03:00
|
|
|
if (high <= uvm_physseg_get_avail_start(psi) ||
|
|
|
|
low >= uvm_physseg_get_avail_end(psi))
|
2011-01-24 22:13:55 +03:00
|
|
|
return 0;
|
|
|
|
|
2011-01-26 11:49:48 +03:00
|
|
|
again:
|
2014-09-05 09:36:21 +04:00
|
|
|
for (;; candidate++, pg++) {
|
|
|
|
if (candidate >= limit) {
|
2016-12-23 10:15:27 +03:00
|
|
|
if (uvm_physseg_get_start_hint(psi) == 0 || second_pass) {
|
2014-09-05 09:36:21 +04:00
|
|
|
candidate = limit - 1;
|
2011-01-19 00:43:29 +03:00
|
|
|
break;
|
2011-01-24 22:13:55 +03:00
|
|
|
}
|
2011-01-19 00:43:29 +03:00
|
|
|
second_pass = true;
|
Rename min/max -> uimin/uimax for better honesty.
These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.
HOWEVER! Some subsystems have
#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))
even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.
To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.
I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:
cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))
It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.
Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)
2018-09-03 19:29:22 +03:00
|
|
|
candidate = uimax(low, uvm_physseg_get_avail_start(psi));
|
|
|
|
limit = uimin(limit, uvm_physseg_get_avail_start(psi) +
|
2016-12-23 10:15:27 +03:00
|
|
|
uvm_physseg_get_start_hint(psi));
|
|
|
|
pg = uvm_physseg_get_pg(psi, candidate - uvm_physseg_get_start(psi));
|
2011-01-26 11:49:48 +03:00
|
|
|
goto again;
|
2011-01-19 00:43:29 +03:00
|
|
|
}
|
2011-01-25 01:54:01 +03:00
|
|
|
#if defined(DEBUG)
|
2011-01-21 22:27:09 +03:00
|
|
|
{
|
2016-12-23 10:15:27 +03:00
|
|
|
paddr_t cidx = 0;
|
|
|
|
const uvm_physseg_t bank = uvm_physseg_find(candidate, &cidx);
|
|
|
|
KDASSERTMSG(bank == psi,
|
2016-12-23 12:18:02 +03:00
|
|
|
"uvm_physseg_find(%#x) (%"PRIxPHYSSEG ") != psi %"PRIxPHYSSEG,
|
2016-12-23 10:15:27 +03:00
|
|
|
candidate, bank, psi);
|
|
|
|
KDASSERTMSG(cidx == candidate - uvm_physseg_get_start(psi),
|
|
|
|
"uvm_physseg_find(%#x): %#"PRIxPADDR" != off %"PRIxPADDR,
|
|
|
|
candidate, cidx, candidate - uvm_physseg_get_start(psi));
|
2011-01-21 22:27:09 +03:00
|
|
|
}
|
2002-06-18 19:49:48 +04:00
|
|
|
#endif
|
|
|
|
if (VM_PAGE_IS_FREE(pg) == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
uvm_pglist_add(pg, rlist);
|
2011-01-19 00:43:29 +03:00
|
|
|
if (--todo == 0) {
|
2002-06-18 19:49:48 +04:00
|
|
|
break;
|
2011-01-19 00:43:29 +03:00
|
|
|
}
|
2002-06-18 19:49:48 +04:00
|
|
|
}
|
2002-06-27 22:05:29 +04:00
|
|
|
|
2011-01-19 00:43:29 +03:00
|
|
|
/*
|
|
|
|
* The next time we need to search this segment,
|
|
|
|
* start just after the pages we just allocated.
|
|
|
|
*/
|
2016-12-23 10:15:27 +03:00
|
|
|
uvm_physseg_set_start_hint(psi, candidate + 1 - uvm_physseg_get_avail_start(psi));
|
|
|
|
KASSERTMSG(uvm_physseg_get_start_hint(psi) <= uvm_physseg_get_avail_end(psi) -
|
|
|
|
uvm_physseg_get_avail_start(psi),
|
2011-09-27 05:02:33 +04:00
|
|
|
"%#x %u (%#x) <= %#"PRIxPADDR" - %#"PRIxPADDR" (%#"PRIxPADDR")",
|
2014-09-05 09:36:21 +04:00
|
|
|
candidate + 1,
|
2016-12-23 10:15:27 +03:00
|
|
|
uvm_physseg_get_start_hint(psi),
|
|
|
|
uvm_physseg_get_start_hint(psi),
|
|
|
|
uvm_physseg_get_avail_end(psi),
|
|
|
|
uvm_physseg_get_avail_start(psi),
|
|
|
|
uvm_physseg_get_avail_end(psi) - uvm_physseg_get_avail_start(psi));
|
2011-01-19 00:43:29 +03:00
|
|
|
|
2002-06-27 22:05:29 +04:00
|
|
|
#ifdef PGALLOC_VERBOSE
|
|
|
|
printf("got %d pgs\n", num - todo);
|
|
|
|
#endif
|
|
|
|
return (num - todo); /* number of pages allocated */
|
2002-06-18 19:49:48 +04:00
|
|
|
}
|
|
|
|
|
2002-05-29 23:20:11 +04:00
|
|
|
static int
|
2005-06-27 06:19:48 +04:00
|
|
|
uvm_pglistalloc_simple(int num, paddr_t low, paddr_t high,
|
|
|
|
struct pglist *rlist, int waitok)
|
2002-05-29 23:20:11 +04:00
|
|
|
{
|
2016-12-23 10:15:27 +03:00
|
|
|
int fl, error;
|
|
|
|
uvm_physseg_t psi;
|
2018-11-13 13:31:01 +03:00
|
|
|
int count = 0;
|
2002-05-29 23:20:11 +04:00
|
|
|
|
|
|
|
/* Default to "lose". */
|
|
|
|
error = ENOMEM;
|
|
|
|
|
|
|
|
again:
|
|
|
|
/*
|
|
|
|
* Block all memory allocation and lock the free list.
|
|
|
|
*/
|
2019-12-27 15:51:56 +03:00
|
|
|
uvm_pgfl_lock();
|
2018-11-13 13:31:01 +03:00
|
|
|
count++;
|
2002-05-29 23:20:11 +04:00
|
|
|
|
|
|
|
/* Are there even any free pages? */
|
2020-06-11 22:20:42 +03:00
|
|
|
if (uvm_availmem(false) <=
|
2019-12-31 16:07:09 +03:00
|
|
|
(uvmexp.reserve_pagedaemon + uvmexp.reserve_kernel))
|
2002-05-29 23:20:11 +04:00
|
|
|
goto out;
|
|
|
|
|
2002-06-18 19:49:48 +04:00
|
|
|
for (fl = 0; fl < VM_NFREELIST; fl++) {
|
|
|
|
#if (VM_PHYSSEG_STRAT == VM_PSTRAT_BIGFIRST)
|
2016-12-23 10:15:27 +03:00
|
|
|
for (psi = uvm_physseg_get_last(); uvm_physseg_valid_p(psi); psi = uvm_physseg_get_prev(psi))
|
2002-06-18 19:49:48 +04:00
|
|
|
#else
|
2016-12-23 10:15:27 +03:00
|
|
|
for (psi = uvm_physseg_get_first(); uvm_physseg_valid_p(psi); psi = uvm_physseg_get_next(psi))
|
2002-06-18 19:49:48 +04:00
|
|
|
#endif
|
|
|
|
{
|
2016-12-23 10:15:27 +03:00
|
|
|
if (uvm_physseg_get_free_list(psi) != fl)
|
2002-06-18 19:49:48 +04:00
|
|
|
continue;
|
|
|
|
|
2016-12-23 10:15:27 +03:00
|
|
|
num -= uvm_pglistalloc_s_ps(psi, num, low, high, rlist);
|
2002-06-27 22:05:29 +04:00
|
|
|
if (num == 0) {
|
2002-06-18 19:49:48 +04:00
|
|
|
error = 0;
|
|
|
|
goto out;
|
|
|
|
}
|
2002-05-29 23:20:11 +04:00
|
|
|
}
|
2002-06-18 19:49:48 +04:00
|
|
|
|
2002-05-29 23:20:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
/*
|
|
|
|
* check to see if we need to generate some free pages waking
|
|
|
|
* the pagedaemon.
|
|
|
|
*/
|
|
|
|
|
2019-12-27 15:51:56 +03:00
|
|
|
uvm_pgfl_unlock();
|
2019-12-21 17:50:34 +03:00
|
|
|
uvm_kick_pdaemon();
|
2007-07-21 23:21:53 +04:00
|
|
|
|
2002-05-29 23:20:11 +04:00
|
|
|
if (error) {
|
|
|
|
if (waitok) {
|
|
|
|
/* XXX perhaps some time limitation? */
|
|
|
|
#ifdef DEBUG
|
2018-11-13 13:31:01 +03:00
|
|
|
if (count == 1)
|
|
|
|
printf("pglistalloc waiting\n");
|
2002-05-29 23:20:11 +04:00
|
|
|
#endif
|
|
|
|
uvm_wait("pglalloc");
|
|
|
|
goto again;
|
|
|
|
} else
|
|
|
|
uvm_pglistfree(rlist);
|
|
|
|
}
|
2002-06-27 22:05:29 +04:00
|
|
|
#ifdef PGALLOC_VERBOSE
|
2002-06-18 19:49:48 +04:00
|
|
|
if (!error)
|
2009-03-09 12:53:55 +03:00
|
|
|
printf("pgalloc: %"PRIxMAX"..%"PRIxMAX"\n",
|
|
|
|
(uintmax_t) VM_PAGE_TO_PHYS(TAILQ_FIRST(rlist)),
|
|
|
|
(uintmax_t) VM_PAGE_TO_PHYS(TAILQ_LAST(rlist, pglist)));
|
2002-06-18 19:49:48 +04:00
|
|
|
#endif
|
2002-05-29 23:20:11 +04:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2005-06-27 06:19:48 +04:00
|
|
|
uvm_pglistalloc(psize_t size, paddr_t low, paddr_t high, paddr_t alignment,
|
|
|
|
paddr_t boundary, struct pglist *rlist, int nsegs, int waitok)
|
2002-05-29 23:20:11 +04:00
|
|
|
{
|
2002-06-27 22:05:29 +04:00
|
|
|
int num, res;
|
2002-05-29 23:20:11 +04:00
|
|
|
|
2020-03-02 00:43:56 +03:00
|
|
|
KASSERT(!cpu_intr_p());
|
|
|
|
KASSERT(!cpu_softintr_p());
|
2002-05-29 23:20:11 +04:00
|
|
|
KASSERT((alignment & (alignment - 1)) == 0);
|
|
|
|
KASSERT((boundary & (boundary - 1)) == 0);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Our allocations are always page granularity, so our alignment
|
|
|
|
* must be, too.
|
|
|
|
*/
|
|
|
|
if (alignment < PAGE_SIZE)
|
|
|
|
alignment = PAGE_SIZE;
|
2002-06-27 22:05:29 +04:00
|
|
|
if (boundary != 0 && boundary < size)
|
|
|
|
return (EINVAL);
|
|
|
|
num = atop(round_page(size));
|
2011-01-19 00:43:29 +03:00
|
|
|
low = roundup2(low, alignment);
|
2002-05-29 23:20:11 +04:00
|
|
|
|
2002-06-02 18:44:35 +04:00
|
|
|
TAILQ_INIT(rlist);
|
|
|
|
|
2019-12-27 15:51:56 +03:00
|
|
|
/*
|
|
|
|
* Turn off the caching of free pages - we need everything to be on
|
|
|
|
* the global freelists.
|
|
|
|
*/
|
|
|
|
uvm_pgflcache_pause();
|
|
|
|
|
2002-06-20 12:24:22 +04:00
|
|
|
if ((nsegs < size >> PAGE_SHIFT) || (alignment != PAGE_SIZE) ||
|
|
|
|
(boundary != 0))
|
2002-06-27 22:05:29 +04:00
|
|
|
res = uvm_pglistalloc_contig(num, low, high, alignment,
|
|
|
|
boundary, rlist);
|
2002-05-29 23:20:11 +04:00
|
|
|
else
|
2002-06-27 22:05:29 +04:00
|
|
|
res = uvm_pglistalloc_simple(num, low, high, rlist, waitok);
|
2002-05-29 23:20:11 +04:00
|
|
|
|
2019-12-27 15:51:56 +03:00
|
|
|
uvm_pgflcache_resume();
|
|
|
|
|
2002-05-29 23:20:11 +04:00
|
|
|
return (res);
|
|
|
|
}
|
|
|
|
|
1998-02-05 09:25:08 +03:00
|
|
|
/*
|
|
|
|
* uvm_pglistfree: free a list of pages
|
|
|
|
*
|
|
|
|
* => pages should already be unmapped
|
|
|
|
*/
|
|
|
|
|
1998-03-09 03:58:55 +03:00
|
|
|
void
|
2005-06-27 06:19:48 +04:00
|
|
|
uvm_pglistfree(struct pglist *list)
|
1998-02-05 09:25:08 +03:00
|
|
|
{
|
a whole bunch of changes to improve performance and robustness under load:
- remove special treatment of pager_map mappings in pmaps. this is
required now, since I've removed the globals that expose the address range.
pager_map now uses pmap_kenter_pa() instead of pmap_enter(), so there's
no longer any need to special-case it.
- eliminate struct uvm_vnode by moving its fields into struct vnode.
- rewrite the pageout path. the pager is now responsible for handling the
high-level requests instead of only getting control after a bunch of work
has already been done on its behalf. this will allow us to UBCify LFS,
which needs tighter control over its pages than other filesystems do.
writing a page to disk no longer requires making it read-only, which
allows us to write wired pages without causing all kinds of havoc.
- use a new PG_PAGEOUT flag to indicate that a page should be freed
on behalf of the pagedaemon when it's unlocked. this flag is very similar
to PG_RELEASED, but unlike PG_RELEASED, PG_PAGEOUT can be cleared if the
pageout fails due to eg. an indirect-block buffer being locked.
this allows us to remove the "version" field from struct vm_page,
and together with shrinking "loan_count" from 32 bits to 16,
struct vm_page is now 4 bytes smaller.
- no longer use PG_RELEASED for swap-backed pages. if the page is busy
because it's being paged out, we can't release the swap slot to be
reallocated until that write is complete, but unlike with vnodes we
don't keep a count of in-progress writes so there's no good way to
know when the write is done. instead, when we need to free a busy
swap-backed page, just sleep until we can get it busy ourselves.
- implement a fast-path for extending writes which allows us to avoid
zeroing new pages. this substantially reduces cpu usage.
- encapsulate the data used by the genfs code in a struct genfs_node,
which must be the first element of the filesystem-specific vnode data
for filesystems which use genfs_{get,put}pages().
- eliminate many of the UVM pagerops, since they aren't needed anymore
now that the pager "put" operation is a higher-level operation.
- enhance the genfs code to allow NFS to use the genfs_{get,put}pages
instead of a modified copy.
- clean up struct vnode by removing all the fields that used to be used by
the vfs_cluster.c code (which we don't use anymore with UBC).
- remove kmem_object and mb_object since they were useless.
instead of allocating pages to these objects, we now just allocate
pages with no object. such pages are mapped in the kernel until they
are freed, so we can use the mapping to find the page to free it.
this allows us to remove splvm() protection in several places.
The sum of all these changes improves write throughput on my
decstation 5000/200 to within 1% of the rate of NetBSD 1.5
and reduces the elapsed time for "make release" of a NetBSD 1.5
source tree on my 128MB pc to 10% less than a 1.5 kernel took.
2001-09-16 00:36:31 +04:00
|
|
|
struct vm_page *pg;
|
1998-02-05 09:25:08 +03:00
|
|
|
|
2020-03-02 00:43:56 +03:00
|
|
|
KASSERT(!cpu_intr_p());
|
|
|
|
KASSERT(!cpu_softintr_p());
|
|
|
|
|
a whole bunch of changes to improve performance and robustness under load:
- remove special treatment of pager_map mappings in pmaps. this is
required now, since I've removed the globals that expose the address range.
pager_map now uses pmap_kenter_pa() instead of pmap_enter(), so there's
no longer any need to special-case it.
- eliminate struct uvm_vnode by moving its fields into struct vnode.
- rewrite the pageout path. the pager is now responsible for handling the
high-level requests instead of only getting control after a bunch of work
has already been done on its behalf. this will allow us to UBCify LFS,
which needs tighter control over its pages than other filesystems do.
writing a page to disk no longer requires making it read-only, which
allows us to write wired pages without causing all kinds of havoc.
- use a new PG_PAGEOUT flag to indicate that a page should be freed
on behalf of the pagedaemon when it's unlocked. this flag is very similar
to PG_RELEASED, but unlike PG_RELEASED, PG_PAGEOUT can be cleared if the
pageout fails due to eg. an indirect-block buffer being locked.
this allows us to remove the "version" field from struct vm_page,
and together with shrinking "loan_count" from 32 bits to 16,
struct vm_page is now 4 bytes smaller.
- no longer use PG_RELEASED for swap-backed pages. if the page is busy
because it's being paged out, we can't release the swap slot to be
reallocated until that write is complete, but unlike with vnodes we
don't keep a count of in-progress writes so there's no good way to
know when the write is done. instead, when we need to free a busy
swap-backed page, just sleep until we can get it busy ourselves.
- implement a fast-path for extending writes which allows us to avoid
zeroing new pages. this substantially reduces cpu usage.
- encapsulate the data used by the genfs code in a struct genfs_node,
which must be the first element of the filesystem-specific vnode data
for filesystems which use genfs_{get,put}pages().
- eliminate many of the UVM pagerops, since they aren't needed anymore
now that the pager "put" operation is a higher-level operation.
- enhance the genfs code to allow NFS to use the genfs_{get,put}pages
instead of a modified copy.
- clean up struct vnode by removing all the fields that used to be used by
the vfs_cluster.c code (which we don't use anymore with UBC).
- remove kmem_object and mb_object since they were useless.
instead of allocating pages to these objects, we now just allocate
pages with no object. such pages are mapped in the kernel until they
are freed, so we can use the mapping to find the page to free it.
this allows us to remove splvm() protection in several places.
The sum of all these changes improves write throughput on my
decstation 5000/200 to within 1% of the rate of NetBSD 1.5
and reduces the elapsed time for "make release" of a NetBSD 1.5
source tree on my 128MB pc to 10% less than a 1.5 kernel took.
2001-09-16 00:36:31 +04:00
|
|
|
while ((pg = TAILQ_FIRST(list)) != NULL) {
|
2008-06-04 16:45:28 +04:00
|
|
|
TAILQ_REMOVE(list, pg, pageq.queue);
|
2020-05-23 23:22:42 +03:00
|
|
|
uvm_pagefree(pg);
|
1998-03-09 03:58:55 +03:00
|
|
|
STAT_DECR(uvm_pglistalloc_npages);
|
|
|
|
}
|
1998-02-05 09:25:08 +03:00
|
|
|
}
|