2020-06-12 01:21:05 +03:00
|
|
|
/* $NetBSD: uvm_loan.c,v 1.104 2020/06/11 22:21:05 ad Exp $ */
|
1998-02-05 09:25:08 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1997 Charles D. Cranor and Washington University.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
1998-02-07 14:07:38 +03:00
|
|
|
*
|
|
|
|
* from: Id: uvm_loan.c,v 1.1.6.4 1998/02/06 05:08:43 chs Exp
|
1998-02-05 09:25:08 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* uvm_loan.c: page loanout handler
|
|
|
|
*/
|
|
|
|
|
2001-11-10 10:36:59 +03:00
|
|
|
#include <sys/cdefs.h>
|
2020-06-12 01:21:05 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: uvm_loan.c,v 1.104 2020/06/11 22:21:05 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>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/mman.h>
|
|
|
|
|
|
|
|
#include <uvm/uvm.h>
|
|
|
|
|
2012-07-31 03:56:48 +04:00
|
|
|
#ifdef UVMHIST
|
|
|
|
UVMHIST_DEFINE(loanhist);
|
|
|
|
#endif
|
|
|
|
|
1998-02-05 09:25:08 +03:00
|
|
|
/*
|
2001-05-25 08:06:11 +04:00
|
|
|
* "loaned" pages are pages which are (read-only, copy-on-write) loaned
|
1998-02-05 09:25:08 +03:00
|
|
|
* from the VM system to other parts of the kernel. this allows page
|
|
|
|
* copying to be avoided (e.g. you can loan pages from objs/anons to
|
|
|
|
* the mbuf system).
|
|
|
|
*
|
|
|
|
* there are 3 types of loans possible:
|
|
|
|
* O->K uvm_object page to wired kernel page (e.g. mbuf data area)
|
1999-05-28 01:50:03 +04:00
|
|
|
* A->K anon page to wired kernel page (e.g. mbuf data area)
|
1998-02-05 09:25:08 +03:00
|
|
|
* O->A uvm_object to anon loan (e.g. vnode page to an anon)
|
|
|
|
* note that it possible to have an O page loaned to both an A and K
|
|
|
|
* at the same time.
|
|
|
|
*
|
|
|
|
* loans are tracked by pg->loan_count. an O->A page will have both
|
2019-12-13 23:10:21 +03:00
|
|
|
* a uvm_object and a vm_anon, but PG_ANON will not be set. this sort
|
1998-02-05 09:25:08 +03:00
|
|
|
* of page is considered "owned" by the uvm_object (not the anon).
|
|
|
|
*
|
1999-05-28 01:50:03 +04:00
|
|
|
* each loan of a page to the kernel bumps the pg->wire_count. the
|
|
|
|
* kernel mappings for these pages will be read-only and wired. since
|
|
|
|
* the page will also be wired, it will not be a candidate for pageout,
|
|
|
|
* and thus will never be pmap_page_protect()'d with VM_PROT_NONE. a
|
|
|
|
* write fault in the kernel to one of these pages will not cause
|
|
|
|
* copy-on-write. instead, the page fault is considered fatal. this
|
|
|
|
* is because the kernel mapping will have no way to look up the
|
|
|
|
* object/anon which the page is owned by. this is a good side-effect,
|
|
|
|
* since a kernel write to a loaned page is an error.
|
1998-02-05 09:25:08 +03:00
|
|
|
*
|
2001-05-25 08:06:11 +04:00
|
|
|
* owners that want to free their pages and discover that they are
|
1998-02-05 09:25:08 +03:00
|
|
|
* loaned out simply "disown" them (the page becomes an orphan). these
|
|
|
|
* pages should be freed when the last loan is dropped. in some cases
|
|
|
|
* an anon may "adopt" an orphaned page.
|
|
|
|
*
|
2019-12-13 23:10:21 +03:00
|
|
|
* locking: to read pg->loan_count either the owner or pg->interlock
|
1998-02-05 09:25:08 +03:00
|
|
|
* must be locked. to modify pg->loan_count, both the owner of the page
|
2019-12-13 23:10:21 +03:00
|
|
|
* and pg->interlock must be locked. pg->flags is (as always) locked by
|
1998-02-05 09:25:08 +03:00
|
|
|
* the owner of the page.
|
|
|
|
*
|
|
|
|
* note that locking from the "loaned" side is tricky since the object
|
|
|
|
* getting the loaned page has no reference to the page's owner and thus
|
|
|
|
* the owner could "die" at any time. in order to prevent the owner
|
2019-12-13 23:10:21 +03:00
|
|
|
* from dying pg->interlock should be locked. this forces us to sometimes
|
1998-02-05 09:25:08 +03:00
|
|
|
* use "try" locking.
|
|
|
|
*
|
|
|
|
* loans are typically broken by the following events:
|
2001-05-25 08:06:11 +04:00
|
|
|
* 1. user-level xwrite fault to a loaned page
|
1998-02-05 09:25:08 +03:00
|
|
|
* 2. pageout of clean+inactive O->A loaned page
|
|
|
|
* 3. owner frees page (e.g. pager flush)
|
|
|
|
*
|
|
|
|
* note that loaning a page causes all mappings of the page to become
|
|
|
|
* read-only (via pmap_page_protect). this could have an unexpected
|
1999-05-28 01:50:03 +04:00
|
|
|
* effect on normal "wired" pages if one is not careful (XXX).
|
1998-02-05 09:25:08 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* local prototypes
|
|
|
|
*/
|
|
|
|
|
2004-03-24 10:50:48 +03:00
|
|
|
static int uvm_loananon(struct uvm_faultinfo *, void ***,
|
|
|
|
int, struct vm_anon *);
|
|
|
|
static int uvm_loanuobj(struct uvm_faultinfo *, void ***,
|
|
|
|
int, vaddr_t);
|
|
|
|
static int uvm_loanzero(struct uvm_faultinfo *, void ***, int);
|
|
|
|
static void uvm_unloananon(struct vm_anon **, int);
|
|
|
|
static void uvm_unloanpage(struct vm_page **, int);
|
2020-05-17 22:38:16 +03:00
|
|
|
static int uvm_loanpage(struct vm_page **, int, bool);
|
2001-09-22 09:58:04 +04:00
|
|
|
|
1998-02-05 09:25:08 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* inlines
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* uvm_loanentry: loan out pages in a map entry (helper fn for uvm_loan())
|
|
|
|
*
|
|
|
|
* => "ufi" is the result of a successful map lookup (meaning that
|
2001-08-27 06:34:29 +04:00
|
|
|
* on entry the map is locked by the caller)
|
2001-04-10 04:53:21 +04:00
|
|
|
* => we may unlock and then relock the map if needed (for I/O)
|
1998-02-05 09:25:08 +03:00
|
|
|
* => we put our output result in "output"
|
2001-08-27 06:34:29 +04:00
|
|
|
* => we always return with the map unlocked
|
2001-04-10 04:53:21 +04:00
|
|
|
* => possible return values:
|
|
|
|
* -1 == error, map is unlocked
|
|
|
|
* 0 == map relock error (try again!), map is unlocked
|
2001-08-27 06:34:29 +04:00
|
|
|
* >0 == number of pages we loaned, map is unlocked
|
2005-06-28 08:06:52 +04:00
|
|
|
*
|
|
|
|
* NOTE: We can live with this being an inline, because it is only called
|
|
|
|
* from one place.
|
1998-02-05 09:25:08 +03:00
|
|
|
*/
|
|
|
|
|
2005-12-24 23:45:08 +03:00
|
|
|
static inline int
|
2005-06-27 06:19:48 +04:00
|
|
|
uvm_loanentry(struct uvm_faultinfo *ufi, void ***output, int flags)
|
1998-02-05 09:25:08 +03:00
|
|
|
{
|
1998-10-12 03:16:20 +04:00
|
|
|
vaddr_t curaddr = ufi->orig_rvaddr;
|
1998-08-13 06:10:37 +04:00
|
|
|
vsize_t togo = ufi->size;
|
1998-03-09 03:58:55 +03:00
|
|
|
struct vm_aref *aref = &ufi->entry->aref;
|
|
|
|
struct uvm_object *uobj = ufi->entry->object.uvm_obj;
|
|
|
|
struct vm_anon *anon;
|
|
|
|
int rv, result = 0;
|
|
|
|
|
2004-11-23 07:51:56 +03:00
|
|
|
UVMHIST_FUNC(__func__); UVMHIST_CALLED(loanhist);
|
|
|
|
|
1998-03-09 03:58:55 +03:00
|
|
|
/*
|
2001-04-10 04:53:21 +04:00
|
|
|
* lock us the rest of the way down (we unlock before return)
|
1998-03-09 03:58:55 +03:00
|
|
|
*/
|
2011-06-12 07:35:36 +04:00
|
|
|
if (aref->ar_amap) {
|
2020-02-23 18:46:38 +03:00
|
|
|
amap_lock(aref->ar_amap, RW_WRITER);
|
2011-06-12 07:35:36 +04:00
|
|
|
}
|
1998-03-09 03:58:55 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* loop until done
|
|
|
|
*/
|
|
|
|
while (togo) {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* find the page we want. check the anon layer first.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (aref->ar_amap) {
|
|
|
|
anon = amap_lookup(aref, curaddr - ufi->entry->start);
|
|
|
|
} else {
|
|
|
|
anon = NULL;
|
|
|
|
}
|
|
|
|
|
2001-04-10 04:53:21 +04:00
|
|
|
/* locked: map, amap, uobj */
|
1998-03-09 03:58:55 +03:00
|
|
|
if (anon) {
|
|
|
|
rv = uvm_loananon(ufi, output, flags, anon);
|
|
|
|
} else if (uobj) {
|
|
|
|
rv = uvm_loanuobj(ufi, output, flags, curaddr);
|
|
|
|
} else if (UVM_ET_ISCOPYONWRITE(ufi->entry)) {
|
|
|
|
rv = uvm_loanzero(ufi, output, flags);
|
|
|
|
} else {
|
2011-06-12 07:35:36 +04:00
|
|
|
uvmfault_unlockall(ufi, aref->ar_amap, uobj);
|
2001-11-06 11:07:49 +03:00
|
|
|
rv = -1;
|
1998-03-09 03:58:55 +03:00
|
|
|
}
|
2001-08-27 06:34:29 +04:00
|
|
|
/* locked: if (rv > 0) => map, amap, uobj [o.w. unlocked] */
|
2007-07-21 23:21:53 +04:00
|
|
|
KASSERT(rv > 0 || aref->ar_amap == NULL ||
|
2020-02-23 18:46:38 +03:00
|
|
|
!rw_write_held(aref->ar_amap->am_lock));
|
2008-01-02 14:48:20 +03:00
|
|
|
KASSERT(rv > 0 || uobj == NULL ||
|
2020-02-23 18:46:38 +03:00
|
|
|
!rw_write_held(uobj->vmobjlock));
|
1998-03-09 03:58:55 +03:00
|
|
|
|
|
|
|
/* total failure */
|
2004-11-23 07:51:56 +03:00
|
|
|
if (rv < 0) {
|
Update the kernhist(9) kernel history code to address issues identified
in PR kern/52639, as well as some general cleaning-up...
(As proposed on tech-kern@ with additional changes and enhancements.)
Details of changes:
* All history arguments are now stored as uintmax_t values[1], both in
the kernel and in the structures used for exporting the history data
to userland via sysctl(9). This avoids problems on some architectures
where passing a 64-bit (or larger) value to printf(3) can cause it to
process the value as multiple arguments. (This can be particularly
problematic when printf()'s format string is not a literal, since in
that case the compiler cannot know how large each argument should be.)
* Update the data structures used for exporting kernel history data to
include a version number as well as the length of history arguments.
* All [2] existing users of kernhist(9) have had their format strings
updated. Each format specifier now includes an explicit length
modifier 'j' to refer to numeric values of the size of uintmax_t.
* All [2] existing users of kernhist(9) have had their format strings
updated to replace uses of "%p" with "%#jx", and the pointer
arguments are now cast to (uintptr_t) before being subsequently cast
to (uintmax_t). This is needed to avoid compiler warnings about
casting "pointer to integer of a different size."
* All [2] existing users of kernhist(9) have had instances of "%s" or
"%c" format strings replaced with numeric formats; several instances
of mis-match between format string and argument list have been fixed.
* vmstat(1) has been modified to handle the new size of arguments in the
history data as exported by sysctl(9).
* vmstat(1) now provides a warning message if the history requested with
the -u option does not exist (previously, this condition was silently
ignored, with only a single blank line being printed).
* vmstat(1) now checks the version and argument length included in the
data exported via sysctl(9) and exits if they do not match the values
with which vmstat was built.
* The kernhist(9) man-page has been updated to note the additional
requirements imposed on the format strings, along with several other
minor changes and enhancements.
[1] It would have been possible to use an explicit length (for example,
uint64_t) for the history arguments. But that would require another
"rototill" of all the users in the future when we add support for an
architecture that supports a larger size. Also, the printf(3) format
specifiers for explicitly-sized values, such as "%"PRIu64, are much
more verbose (and less aesthetically appealing, IMHO) than simply
using "%ju".
[2] I've tried very hard to find "all [the] existing users of kernhist(9)"
but it is possible that I've missed some of them. I would be glad to
update any stragglers that anyone identifies.
2017-10-28 03:37:11 +03:00
|
|
|
UVMHIST_LOG(loanhist, "failure %jd", rv, 0,0,0);
|
2001-11-06 11:07:49 +03:00
|
|
|
return (-1);
|
2004-11-23 07:51:56 +03:00
|
|
|
}
|
1998-03-09 03:58:55 +03:00
|
|
|
|
|
|
|
/* relock failed, need to do another lookup */
|
2004-11-23 07:51:56 +03:00
|
|
|
if (rv == 0) {
|
Update the kernhist(9) kernel history code to address issues identified
in PR kern/52639, as well as some general cleaning-up...
(As proposed on tech-kern@ with additional changes and enhancements.)
Details of changes:
* All history arguments are now stored as uintmax_t values[1], both in
the kernel and in the structures used for exporting the history data
to userland via sysctl(9). This avoids problems on some architectures
where passing a 64-bit (or larger) value to printf(3) can cause it to
process the value as multiple arguments. (This can be particularly
problematic when printf()'s format string is not a literal, since in
that case the compiler cannot know how large each argument should be.)
* Update the data structures used for exporting kernel history data to
include a version number as well as the length of history arguments.
* All [2] existing users of kernhist(9) have had their format strings
updated. Each format specifier now includes an explicit length
modifier 'j' to refer to numeric values of the size of uintmax_t.
* All [2] existing users of kernhist(9) have had their format strings
updated to replace uses of "%p" with "%#jx", and the pointer
arguments are now cast to (uintptr_t) before being subsequently cast
to (uintmax_t). This is needed to avoid compiler warnings about
casting "pointer to integer of a different size."
* All [2] existing users of kernhist(9) have had instances of "%s" or
"%c" format strings replaced with numeric formats; several instances
of mis-match between format string and argument list have been fixed.
* vmstat(1) has been modified to handle the new size of arguments in the
history data as exported by sysctl(9).
* vmstat(1) now provides a warning message if the history requested with
the -u option does not exist (previously, this condition was silently
ignored, with only a single blank line being printed).
* vmstat(1) now checks the version and argument length included in the
data exported via sysctl(9) and exits if they do not match the values
with which vmstat was built.
* The kernhist(9) man-page has been updated to note the additional
requirements imposed on the format strings, along with several other
minor changes and enhancements.
[1] It would have been possible to use an explicit length (for example,
uint64_t) for the history arguments. But that would require another
"rototill" of all the users in the future when we add support for an
architecture that supports a larger size. Also, the printf(3) format
specifiers for explicitly-sized values, such as "%"PRIu64, are much
more verbose (and less aesthetically appealing, IMHO) than simply
using "%ju".
[2] I've tried very hard to find "all [the] existing users of kernhist(9)"
but it is possible that I've missed some of them. I would be glad to
update any stragglers that anyone identifies.
2017-10-28 03:37:11 +03:00
|
|
|
UVMHIST_LOG(loanhist, "relock failure %jd", result
|
2004-11-23 07:51:56 +03:00
|
|
|
,0,0,0);
|
2001-11-06 11:07:49 +03:00
|
|
|
return (result);
|
2004-11-23 07:51:56 +03:00
|
|
|
}
|
1998-03-09 03:58:55 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* got it... advance to next page
|
|
|
|
*/
|
2001-11-06 11:07:49 +03:00
|
|
|
|
1998-03-09 03:58:55 +03:00
|
|
|
result++;
|
|
|
|
togo -= PAGE_SIZE;
|
|
|
|
curaddr += PAGE_SIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-08-27 06:34:29 +04:00
|
|
|
* unlock what we locked, unlock the maps and return
|
1998-03-09 03:58:55 +03:00
|
|
|
*/
|
2001-11-06 11:07:49 +03:00
|
|
|
|
2011-06-12 07:35:36 +04:00
|
|
|
if (aref->ar_amap) {
|
2001-04-10 04:53:21 +04:00
|
|
|
amap_unlock(aref->ar_amap);
|
2011-06-12 07:35:36 +04:00
|
|
|
}
|
2007-02-22 09:05:00 +03:00
|
|
|
uvmfault_unlockmaps(ufi, false);
|
Update the kernhist(9) kernel history code to address issues identified
in PR kern/52639, as well as some general cleaning-up...
(As proposed on tech-kern@ with additional changes and enhancements.)
Details of changes:
* All history arguments are now stored as uintmax_t values[1], both in
the kernel and in the structures used for exporting the history data
to userland via sysctl(9). This avoids problems on some architectures
where passing a 64-bit (or larger) value to printf(3) can cause it to
process the value as multiple arguments. (This can be particularly
problematic when printf()'s format string is not a literal, since in
that case the compiler cannot know how large each argument should be.)
* Update the data structures used for exporting kernel history data to
include a version number as well as the length of history arguments.
* All [2] existing users of kernhist(9) have had their format strings
updated. Each format specifier now includes an explicit length
modifier 'j' to refer to numeric values of the size of uintmax_t.
* All [2] existing users of kernhist(9) have had their format strings
updated to replace uses of "%p" with "%#jx", and the pointer
arguments are now cast to (uintptr_t) before being subsequently cast
to (uintmax_t). This is needed to avoid compiler warnings about
casting "pointer to integer of a different size."
* All [2] existing users of kernhist(9) have had instances of "%s" or
"%c" format strings replaced with numeric formats; several instances
of mis-match between format string and argument list have been fixed.
* vmstat(1) has been modified to handle the new size of arguments in the
history data as exported by sysctl(9).
* vmstat(1) now provides a warning message if the history requested with
the -u option does not exist (previously, this condition was silently
ignored, with only a single blank line being printed).
* vmstat(1) now checks the version and argument length included in the
data exported via sysctl(9) and exits if they do not match the values
with which vmstat was built.
* The kernhist(9) man-page has been updated to note the additional
requirements imposed on the format strings, along with several other
minor changes and enhancements.
[1] It would have been possible to use an explicit length (for example,
uint64_t) for the history arguments. But that would require another
"rototill" of all the users in the future when we add support for an
architecture that supports a larger size. Also, the printf(3) format
specifiers for explicitly-sized values, such as "%"PRIu64, are much
more verbose (and less aesthetically appealing, IMHO) than simply
using "%ju".
[2] I've tried very hard to find "all [the] existing users of kernhist(9)"
but it is possible that I've missed some of them. I would be glad to
update any stragglers that anyone identifies.
2017-10-28 03:37:11 +03:00
|
|
|
UVMHIST_LOG(loanhist, "done %jd", result, 0,0,0);
|
2001-11-06 11:07:49 +03:00
|
|
|
return (result);
|
1998-02-05 09:25:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* normal functions
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2001-04-10 04:53:21 +04:00
|
|
|
* uvm_loan: loan pages in a map out to anons or to the kernel
|
2001-05-25 08:06:11 +04:00
|
|
|
*
|
1998-02-05 09:25:08 +03:00
|
|
|
* => map should be unlocked
|
|
|
|
* => start and len should be multiples of PAGE_SIZE
|
|
|
|
* => result is either an array of anon's or vm_pages (depending on flags)
|
|
|
|
* => flag values: UVM_LOAN_TOANON - loan to anons
|
|
|
|
* UVM_LOAN_TOPAGE - loan to wired kernel page
|
|
|
|
* one and only one of these flags must be set!
|
2001-04-10 04:53:21 +04:00
|
|
|
* => returns 0 (success), or an appropriate error number
|
1998-02-05 09:25:08 +03:00
|
|
|
*/
|
|
|
|
|
1998-03-09 03:58:55 +03:00
|
|
|
int
|
2005-06-27 06:19:48 +04:00
|
|
|
uvm_loan(struct vm_map *map, vaddr_t start, vsize_t len, void *v, int flags)
|
1998-02-05 09:25:08 +03:00
|
|
|
{
|
1998-03-09 03:58:55 +03:00
|
|
|
struct uvm_faultinfo ufi;
|
2001-11-06 11:07:49 +03:00
|
|
|
void **result, **output;
|
2001-03-15 09:10:32 +03:00
|
|
|
int rv, error;
|
1999-06-03 04:05:45 +04:00
|
|
|
|
2004-11-23 07:51:56 +03:00
|
|
|
UVMHIST_FUNC(__func__); UVMHIST_CALLED(loanhist);
|
|
|
|
|
1998-03-09 03:58:55 +03:00
|
|
|
/*
|
|
|
|
* ensure that one and only one of the flags is set
|
|
|
|
*/
|
|
|
|
|
2001-03-15 09:10:32 +03:00
|
|
|
KASSERT(((flags & UVM_LOAN_TOANON) == 0) ^
|
|
|
|
((flags & UVM_LOAN_TOPAGE) == 0));
|
1998-03-09 03:58:55 +03:00
|
|
|
|
|
|
|
/*
|
2001-11-06 11:07:49 +03:00
|
|
|
* "output" is a pointer to the current place to put the loaned page.
|
1998-03-09 03:58:55 +03:00
|
|
|
*/
|
|
|
|
|
2001-11-06 11:07:49 +03:00
|
|
|
result = v;
|
1998-03-09 03:58:55 +03:00
|
|
|
output = &result[0]; /* start at the beginning ... */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* while we've got pages to do
|
|
|
|
*/
|
|
|
|
|
|
|
|
while (len > 0) {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* fill in params for a call to uvmfault_lookup
|
|
|
|
*/
|
|
|
|
|
|
|
|
ufi.orig_map = map;
|
|
|
|
ufi.orig_rvaddr = start;
|
|
|
|
ufi.orig_size = len;
|
2001-05-25 08:06:11 +04:00
|
|
|
|
1998-03-09 03:58:55 +03:00
|
|
|
/*
|
|
|
|
* do the lookup, the only time this will fail is if we hit on
|
|
|
|
* an unmapped region (an error)
|
|
|
|
*/
|
|
|
|
|
2007-02-22 09:05:00 +03:00
|
|
|
if (!uvmfault_lookup(&ufi, false)) {
|
2001-03-15 09:10:32 +03:00
|
|
|
error = ENOENT;
|
1998-03-09 03:58:55 +03:00
|
|
|
goto fail;
|
2001-03-15 09:10:32 +03:00
|
|
|
}
|
1998-03-09 03:58:55 +03:00
|
|
|
|
|
|
|
/*
|
2001-04-10 04:53:21 +04:00
|
|
|
* map now locked. now do the loanout...
|
1998-03-09 03:58:55 +03:00
|
|
|
*/
|
2001-11-06 11:07:49 +03:00
|
|
|
|
1998-03-09 03:58:55 +03:00
|
|
|
rv = uvm_loanentry(&ufi, &output, flags);
|
2001-03-15 09:10:32 +03:00
|
|
|
if (rv < 0) {
|
2001-04-10 04:53:21 +04:00
|
|
|
/* all unlocked due to error */
|
2001-03-15 09:10:32 +03:00
|
|
|
error = EINVAL;
|
1998-03-09 03:58:55 +03:00
|
|
|
goto fail;
|
2001-03-15 09:10:32 +03:00
|
|
|
}
|
1998-03-09 03:58:55 +03:00
|
|
|
|
|
|
|
/*
|
2001-08-27 06:34:29 +04:00
|
|
|
* done! the map is unlocked. advance, if possible.
|
2001-04-10 04:53:21 +04:00
|
|
|
*
|
2004-03-24 10:50:48 +03:00
|
|
|
* XXXCDC: could be recoded to hold the map lock with
|
|
|
|
* smarter code (but it only happens on map entry
|
2001-08-27 06:34:29 +04:00
|
|
|
* boundaries, so it isn't that bad).
|
1998-03-09 03:58:55 +03:00
|
|
|
*/
|
2001-11-06 11:07:49 +03:00
|
|
|
|
2001-04-10 04:53:21 +04:00
|
|
|
if (rv) {
|
|
|
|
rv <<= PAGE_SHIFT;
|
|
|
|
len -= rv;
|
|
|
|
start += rv;
|
|
|
|
}
|
1998-03-09 03:58:55 +03:00
|
|
|
}
|
2004-11-23 07:51:56 +03:00
|
|
|
UVMHIST_LOG(loanhist, "success", 0,0,0,0);
|
2001-03-15 09:10:32 +03:00
|
|
|
return 0;
|
1998-02-05 09:25:08 +03:00
|
|
|
|
|
|
|
fail:
|
1998-03-09 03:58:55 +03:00
|
|
|
/*
|
2001-11-06 11:07:49 +03:00
|
|
|
* failed to complete loans. drop any loans and return failure code.
|
2001-04-10 04:53:21 +04:00
|
|
|
* map is already unlocked.
|
1998-03-09 03:58:55 +03:00
|
|
|
*/
|
2001-11-06 11:07:49 +03:00
|
|
|
|
1998-03-09 03:58:55 +03:00
|
|
|
if (output - result) {
|
2001-11-06 11:07:49 +03:00
|
|
|
if (flags & UVM_LOAN_TOANON) {
|
1998-03-09 03:58:55 +03:00
|
|
|
uvm_unloananon((struct vm_anon **)result,
|
2001-11-06 11:07:49 +03:00
|
|
|
output - result);
|
|
|
|
} else {
|
1998-03-09 03:58:55 +03:00
|
|
|
uvm_unloanpage((struct vm_page **)result,
|
2001-11-06 11:07:49 +03:00
|
|
|
output - result);
|
|
|
|
}
|
1998-03-09 03:58:55 +03:00
|
|
|
}
|
Update the kernhist(9) kernel history code to address issues identified
in PR kern/52639, as well as some general cleaning-up...
(As proposed on tech-kern@ with additional changes and enhancements.)
Details of changes:
* All history arguments are now stored as uintmax_t values[1], both in
the kernel and in the structures used for exporting the history data
to userland via sysctl(9). This avoids problems on some architectures
where passing a 64-bit (or larger) value to printf(3) can cause it to
process the value as multiple arguments. (This can be particularly
problematic when printf()'s format string is not a literal, since in
that case the compiler cannot know how large each argument should be.)
* Update the data structures used for exporting kernel history data to
include a version number as well as the length of history arguments.
* All [2] existing users of kernhist(9) have had their format strings
updated. Each format specifier now includes an explicit length
modifier 'j' to refer to numeric values of the size of uintmax_t.
* All [2] existing users of kernhist(9) have had their format strings
updated to replace uses of "%p" with "%#jx", and the pointer
arguments are now cast to (uintptr_t) before being subsequently cast
to (uintmax_t). This is needed to avoid compiler warnings about
casting "pointer to integer of a different size."
* All [2] existing users of kernhist(9) have had instances of "%s" or
"%c" format strings replaced with numeric formats; several instances
of mis-match between format string and argument list have been fixed.
* vmstat(1) has been modified to handle the new size of arguments in the
history data as exported by sysctl(9).
* vmstat(1) now provides a warning message if the history requested with
the -u option does not exist (previously, this condition was silently
ignored, with only a single blank line being printed).
* vmstat(1) now checks the version and argument length included in the
data exported via sysctl(9) and exits if they do not match the values
with which vmstat was built.
* The kernhist(9) man-page has been updated to note the additional
requirements imposed on the format strings, along with several other
minor changes and enhancements.
[1] It would have been possible to use an explicit length (for example,
uint64_t) for the history arguments. But that would require another
"rototill" of all the users in the future when we add support for an
architecture that supports a larger size. Also, the printf(3) format
specifiers for explicitly-sized values, such as "%"PRIu64, are much
more verbose (and less aesthetically appealing, IMHO) than simply
using "%ju".
[2] I've tried very hard to find "all [the] existing users of kernhist(9)"
but it is possible that I've missed some of them. I would be glad to
update any stragglers that anyone identifies.
2017-10-28 03:37:11 +03:00
|
|
|
UVMHIST_LOG(loanhist, "error %jd", error,0,0,0);
|
2001-04-08 20:51:51 +04:00
|
|
|
return (error);
|
1998-02-05 09:25:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* uvm_loananon: loan a page from an anon out
|
2001-05-25 08:06:11 +04:00
|
|
|
*
|
2001-04-10 04:53:21 +04:00
|
|
|
* => called with map, amap, uobj locked
|
1998-02-05 09:25:08 +03:00
|
|
|
* => return value:
|
|
|
|
* -1 = fatal error, everything is unlocked, abort.
|
|
|
|
* 0 = lookup in ufi went stale, everything unlocked, relookup and
|
|
|
|
* try again
|
|
|
|
* 1 = got it, everything still locked
|
|
|
|
*/
|
|
|
|
|
1998-03-09 03:58:55 +03:00
|
|
|
int
|
2005-06-27 06:19:48 +04:00
|
|
|
uvm_loananon(struct uvm_faultinfo *ufi, void ***output, int flags,
|
|
|
|
struct vm_anon *anon)
|
1998-02-05 09:25:08 +03:00
|
|
|
{
|
1998-03-09 03:58:55 +03:00
|
|
|
struct vm_page *pg;
|
2001-11-06 11:07:49 +03:00
|
|
|
int error;
|
1998-03-09 03:58:55 +03:00
|
|
|
|
2004-11-23 07:51:56 +03:00
|
|
|
UVMHIST_FUNC(__func__); UVMHIST_CALLED(loanhist);
|
|
|
|
|
1998-03-09 03:58:55 +03:00
|
|
|
/*
|
2001-04-10 04:53:21 +04:00
|
|
|
* if we are loaning to "another" anon then it is easy, we just
|
1998-03-09 03:58:55 +03:00
|
|
|
* bump the reference count on the current anon and return a
|
2001-04-10 04:53:21 +04:00
|
|
|
* pointer to it (it becomes copy-on-write shared).
|
1998-03-09 03:58:55 +03:00
|
|
|
*/
|
2001-11-06 11:07:49 +03:00
|
|
|
|
1998-03-09 03:58:55 +03:00
|
|
|
if (flags & UVM_LOAN_TOANON) {
|
2020-02-23 18:46:38 +03:00
|
|
|
KASSERT(rw_write_held(anon->an_lock));
|
2005-05-11 17:02:25 +04:00
|
|
|
pg = anon->an_page;
|
2019-12-13 23:10:21 +03:00
|
|
|
if (pg && (pg->flags & PG_ANON) != 0 && anon->an_ref == 1) {
|
2004-11-21 09:45:49 +03:00
|
|
|
if (pg->wire_count > 0) {
|
Update the kernhist(9) kernel history code to address issues identified
in PR kern/52639, as well as some general cleaning-up...
(As proposed on tech-kern@ with additional changes and enhancements.)
Details of changes:
* All history arguments are now stored as uintmax_t values[1], both in
the kernel and in the structures used for exporting the history data
to userland via sysctl(9). This avoids problems on some architectures
where passing a 64-bit (or larger) value to printf(3) can cause it to
process the value as multiple arguments. (This can be particularly
problematic when printf()'s format string is not a literal, since in
that case the compiler cannot know how large each argument should be.)
* Update the data structures used for exporting kernel history data to
include a version number as well as the length of history arguments.
* All [2] existing users of kernhist(9) have had their format strings
updated. Each format specifier now includes an explicit length
modifier 'j' to refer to numeric values of the size of uintmax_t.
* All [2] existing users of kernhist(9) have had their format strings
updated to replace uses of "%p" with "%#jx", and the pointer
arguments are now cast to (uintptr_t) before being subsequently cast
to (uintmax_t). This is needed to avoid compiler warnings about
casting "pointer to integer of a different size."
* All [2] existing users of kernhist(9) have had instances of "%s" or
"%c" format strings replaced with numeric formats; several instances
of mis-match between format string and argument list have been fixed.
* vmstat(1) has been modified to handle the new size of arguments in the
history data as exported by sysctl(9).
* vmstat(1) now provides a warning message if the history requested with
the -u option does not exist (previously, this condition was silently
ignored, with only a single blank line being printed).
* vmstat(1) now checks the version and argument length included in the
data exported via sysctl(9) and exits if they do not match the values
with which vmstat was built.
* The kernhist(9) man-page has been updated to note the additional
requirements imposed on the format strings, along with several other
minor changes and enhancements.
[1] It would have been possible to use an explicit length (for example,
uint64_t) for the history arguments. But that would require another
"rototill" of all the users in the future when we add support for an
architecture that supports a larger size. Also, the printf(3) format
specifiers for explicitly-sized values, such as "%"PRIu64, are much
more verbose (and less aesthetically appealing, IMHO) than simply
using "%ju".
[2] I've tried very hard to find "all [the] existing users of kernhist(9)"
but it is possible that I've missed some of them. I would be glad to
update any stragglers that anyone identifies.
2017-10-28 03:37:11 +03:00
|
|
|
UVMHIST_LOG(loanhist, "->A wired %#jx",
|
|
|
|
(uintptr_t)pg, 0, 0, 0);
|
2004-11-21 09:45:49 +03:00
|
|
|
uvmfault_unlockall(ufi,
|
|
|
|
ufi->entry->aref.ar_amap,
|
2011-06-12 07:35:36 +04:00
|
|
|
ufi->entry->object.uvm_obj);
|
2004-11-21 09:45:49 +03:00
|
|
|
return (-1);
|
|
|
|
}
|
1999-09-12 05:16:55 +04:00
|
|
|
pmap_page_protect(pg, VM_PROT_READ);
|
2001-11-06 11:07:49 +03:00
|
|
|
}
|
1998-03-09 03:58:55 +03:00
|
|
|
anon->an_ref++;
|
|
|
|
**output = anon;
|
2001-11-06 11:07:49 +03:00
|
|
|
(*output)++;
|
2004-11-23 07:51:56 +03:00
|
|
|
UVMHIST_LOG(loanhist, "->A done", 0,0,0,0);
|
2001-11-06 11:07:49 +03:00
|
|
|
return (1);
|
1998-03-09 03:58:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* we are loaning to a kernel-page. we need to get the page
|
|
|
|
* resident so we can wire it. uvmfault_anonget will handle
|
|
|
|
* this for us.
|
|
|
|
*/
|
|
|
|
|
2020-02-23 18:46:38 +03:00
|
|
|
KASSERT(rw_write_held(anon->an_lock));
|
2001-11-06 11:07:49 +03:00
|
|
|
error = uvmfault_anonget(ufi, ufi->entry->aref.ar_amap, anon);
|
1998-03-09 03:58:55 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* if we were unable to get the anon, then uvmfault_anonget has
|
|
|
|
* unlocked everything and returned an error code.
|
|
|
|
*/
|
2001-11-06 11:07:49 +03:00
|
|
|
|
|
|
|
if (error) {
|
Update the kernhist(9) kernel history code to address issues identified
in PR kern/52639, as well as some general cleaning-up...
(As proposed on tech-kern@ with additional changes and enhancements.)
Details of changes:
* All history arguments are now stored as uintmax_t values[1], both in
the kernel and in the structures used for exporting the history data
to userland via sysctl(9). This avoids problems on some architectures
where passing a 64-bit (or larger) value to printf(3) can cause it to
process the value as multiple arguments. (This can be particularly
problematic when printf()'s format string is not a literal, since in
that case the compiler cannot know how large each argument should be.)
* Update the data structures used for exporting kernel history data to
include a version number as well as the length of history arguments.
* All [2] existing users of kernhist(9) have had their format strings
updated. Each format specifier now includes an explicit length
modifier 'j' to refer to numeric values of the size of uintmax_t.
* All [2] existing users of kernhist(9) have had their format strings
updated to replace uses of "%p" with "%#jx", and the pointer
arguments are now cast to (uintptr_t) before being subsequently cast
to (uintmax_t). This is needed to avoid compiler warnings about
casting "pointer to integer of a different size."
* All [2] existing users of kernhist(9) have had instances of "%s" or
"%c" format strings replaced with numeric formats; several instances
of mis-match between format string and argument list have been fixed.
* vmstat(1) has been modified to handle the new size of arguments in the
history data as exported by sysctl(9).
* vmstat(1) now provides a warning message if the history requested with
the -u option does not exist (previously, this condition was silently
ignored, with only a single blank line being printed).
* vmstat(1) now checks the version and argument length included in the
data exported via sysctl(9) and exits if they do not match the values
with which vmstat was built.
* The kernhist(9) man-page has been updated to note the additional
requirements imposed on the format strings, along with several other
minor changes and enhancements.
[1] It would have been possible to use an explicit length (for example,
uint64_t) for the history arguments. But that would require another
"rototill" of all the users in the future when we add support for an
architecture that supports a larger size. Also, the printf(3) format
specifiers for explicitly-sized values, such as "%"PRIu64, are much
more verbose (and less aesthetically appealing, IMHO) than simply
using "%ju".
[2] I've tried very hard to find "all [the] existing users of kernhist(9)"
but it is possible that I've missed some of them. I would be glad to
update any stragglers that anyone identifies.
2017-10-28 03:37:11 +03:00
|
|
|
UVMHIST_LOG(loanhist, "error %jd", error,0,0,0);
|
2020-03-22 21:32:41 +03:00
|
|
|
KASSERT(error != ENOLCK);
|
1998-03-09 03:58:55 +03:00
|
|
|
|
|
|
|
/* need to refault (i.e. refresh our lookup) ? */
|
2001-11-06 11:07:49 +03:00
|
|
|
if (error == ERESTART) {
|
|
|
|
return (0);
|
|
|
|
}
|
1998-03-09 03:58:55 +03:00
|
|
|
|
|
|
|
/* "try again"? sleep a bit and retry ... */
|
2001-11-06 11:07:49 +03:00
|
|
|
if (error == EAGAIN) {
|
2009-12-06 01:34:43 +03:00
|
|
|
kpause("loanagain", false, hz/2, NULL);
|
2001-11-06 11:07:49 +03:00
|
|
|
return (0);
|
1998-03-09 03:58:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* otherwise flag it as an error */
|
2001-11-06 11:07:49 +03:00
|
|
|
return (-1);
|
1998-03-09 03:58:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* we have the page and its owner locked: do the loan now.
|
|
|
|
*/
|
|
|
|
|
2005-05-11 17:02:25 +04:00
|
|
|
pg = anon->an_page;
|
2004-11-21 09:45:49 +03:00
|
|
|
if (pg->wire_count > 0) {
|
Update the kernhist(9) kernel history code to address issues identified
in PR kern/52639, as well as some general cleaning-up...
(As proposed on tech-kern@ with additional changes and enhancements.)
Details of changes:
* All history arguments are now stored as uintmax_t values[1], both in
the kernel and in the structures used for exporting the history data
to userland via sysctl(9). This avoids problems on some architectures
where passing a 64-bit (or larger) value to printf(3) can cause it to
process the value as multiple arguments. (This can be particularly
problematic when printf()'s format string is not a literal, since in
that case the compiler cannot know how large each argument should be.)
* Update the data structures used for exporting kernel history data to
include a version number as well as the length of history arguments.
* All [2] existing users of kernhist(9) have had their format strings
updated. Each format specifier now includes an explicit length
modifier 'j' to refer to numeric values of the size of uintmax_t.
* All [2] existing users of kernhist(9) have had their format strings
updated to replace uses of "%p" with "%#jx", and the pointer
arguments are now cast to (uintptr_t) before being subsequently cast
to (uintmax_t). This is needed to avoid compiler warnings about
casting "pointer to integer of a different size."
* All [2] existing users of kernhist(9) have had instances of "%s" or
"%c" format strings replaced with numeric formats; several instances
of mis-match between format string and argument list have been fixed.
* vmstat(1) has been modified to handle the new size of arguments in the
history data as exported by sysctl(9).
* vmstat(1) now provides a warning message if the history requested with
the -u option does not exist (previously, this condition was silently
ignored, with only a single blank line being printed).
* vmstat(1) now checks the version and argument length included in the
data exported via sysctl(9) and exits if they do not match the values
with which vmstat was built.
* The kernhist(9) man-page has been updated to note the additional
requirements imposed on the format strings, along with several other
minor changes and enhancements.
[1] It would have been possible to use an explicit length (for example,
uint64_t) for the history arguments. But that would require another
"rototill" of all the users in the future when we add support for an
architecture that supports a larger size. Also, the printf(3) format
specifiers for explicitly-sized values, such as "%"PRIu64, are much
more verbose (and less aesthetically appealing, IMHO) than simply
using "%ju".
[2] I've tried very hard to find "all [the] existing users of kernhist(9)"
but it is possible that I've missed some of them. I would be glad to
update any stragglers that anyone identifies.
2017-10-28 03:37:11 +03:00
|
|
|
UVMHIST_LOG(loanhist, "->K wired %#jx", (uintptr_t)pg, 0, 0, 0);
|
2004-11-21 09:45:49 +03:00
|
|
|
KASSERT(pg->uobject == NULL);
|
2011-06-12 07:35:36 +04:00
|
|
|
uvmfault_unlockall(ufi, ufi->entry->aref.ar_amap, NULL);
|
2004-11-21 09:45:49 +03:00
|
|
|
return (-1);
|
|
|
|
}
|
2001-11-06 11:07:49 +03:00
|
|
|
if (pg->loan_count == 0) {
|
1999-09-12 05:16:55 +04:00
|
|
|
pmap_page_protect(pg, VM_PROT_READ);
|
2001-11-06 11:07:49 +03:00
|
|
|
}
|
2020-01-01 01:42:50 +03:00
|
|
|
uvm_pagelock(pg);
|
1998-03-09 03:58:55 +03:00
|
|
|
pg->loan_count++;
|
2018-05-19 14:02:33 +03:00
|
|
|
KASSERT(pg->loan_count > 0); /* detect wrap-around */
|
2006-12-15 16:51:30 +03:00
|
|
|
uvm_pageactivate(pg);
|
2020-01-01 01:42:50 +03:00
|
|
|
uvm_pageunlock(pg);
|
1998-03-09 03:58:55 +03:00
|
|
|
**output = pg;
|
2001-11-06 11:07:49 +03:00
|
|
|
(*output)++;
|
1998-03-09 03:58:55 +03:00
|
|
|
|
2011-06-12 07:35:36 +04:00
|
|
|
/* unlock and return success */
|
2006-01-31 17:11:25 +03:00
|
|
|
if (pg->uobject)
|
2020-02-23 18:46:38 +03:00
|
|
|
rw_exit(pg->uobject->vmobjlock);
|
2004-11-23 07:51:56 +03:00
|
|
|
UVMHIST_LOG(loanhist, "->K done", 0,0,0,0);
|
2001-11-06 11:07:49 +03:00
|
|
|
return (1);
|
1998-02-05 09:25:08 +03:00
|
|
|
}
|
|
|
|
|
2003-05-03 21:54:32 +04:00
|
|
|
/*
|
2004-01-07 15:17:10 +03:00
|
|
|
* uvm_loanpage: loan out pages to kernel (->K)
|
2003-05-03 21:54:32 +04:00
|
|
|
*
|
2004-11-21 09:45:49 +03:00
|
|
|
* => pages should be object-owned and the object should be locked.
|
|
|
|
* => in the case of error, the object might be unlocked and relocked.
|
2020-05-17 22:38:16 +03:00
|
|
|
* => pages will be unbusied (if busied is true).
|
2004-11-21 09:45:49 +03:00
|
|
|
* => fail with EBUSY if meet a wired page.
|
2003-05-03 21:54:32 +04:00
|
|
|
*/
|
2004-11-21 09:45:49 +03:00
|
|
|
static int
|
2020-05-17 22:38:16 +03:00
|
|
|
uvm_loanpage(struct vm_page **pgpp, int npages, bool busied)
|
2003-05-03 21:54:32 +04:00
|
|
|
{
|
|
|
|
int i;
|
2004-11-21 09:45:49 +03:00
|
|
|
int error = 0;
|
2003-05-03 21:54:32 +04:00
|
|
|
|
2004-11-23 07:51:56 +03:00
|
|
|
UVMHIST_FUNC(__func__); UVMHIST_CALLED(loanhist);
|
|
|
|
|
2003-05-03 21:54:32 +04:00
|
|
|
for (i = 0; i < npages; i++) {
|
|
|
|
struct vm_page *pg = pgpp[i];
|
|
|
|
|
|
|
|
KASSERT(pg->uobject != NULL);
|
2004-11-21 09:45:49 +03:00
|
|
|
KASSERT(pg->uobject == pgpp[0]->uobject);
|
2003-05-03 21:54:32 +04:00
|
|
|
KASSERT(!(pg->flags & (PG_RELEASED|PG_PAGEOUT)));
|
2020-02-23 18:46:38 +03:00
|
|
|
KASSERT(rw_write_held(pg->uobject->vmobjlock));
|
2020-05-17 22:38:16 +03:00
|
|
|
KASSERT(busied == ((pg->flags & PG_BUSY) != 0));
|
2003-05-03 21:54:32 +04:00
|
|
|
|
2004-11-21 09:45:49 +03:00
|
|
|
if (pg->wire_count > 0) {
|
Update the kernhist(9) kernel history code to address issues identified
in PR kern/52639, as well as some general cleaning-up...
(As proposed on tech-kern@ with additional changes and enhancements.)
Details of changes:
* All history arguments are now stored as uintmax_t values[1], both in
the kernel and in the structures used for exporting the history data
to userland via sysctl(9). This avoids problems on some architectures
where passing a 64-bit (or larger) value to printf(3) can cause it to
process the value as multiple arguments. (This can be particularly
problematic when printf()'s format string is not a literal, since in
that case the compiler cannot know how large each argument should be.)
* Update the data structures used for exporting kernel history data to
include a version number as well as the length of history arguments.
* All [2] existing users of kernhist(9) have had their format strings
updated. Each format specifier now includes an explicit length
modifier 'j' to refer to numeric values of the size of uintmax_t.
* All [2] existing users of kernhist(9) have had their format strings
updated to replace uses of "%p" with "%#jx", and the pointer
arguments are now cast to (uintptr_t) before being subsequently cast
to (uintmax_t). This is needed to avoid compiler warnings about
casting "pointer to integer of a different size."
* All [2] existing users of kernhist(9) have had instances of "%s" or
"%c" format strings replaced with numeric formats; several instances
of mis-match between format string and argument list have been fixed.
* vmstat(1) has been modified to handle the new size of arguments in the
history data as exported by sysctl(9).
* vmstat(1) now provides a warning message if the history requested with
the -u option does not exist (previously, this condition was silently
ignored, with only a single blank line being printed).
* vmstat(1) now checks the version and argument length included in the
data exported via sysctl(9) and exits if they do not match the values
with which vmstat was built.
* The kernhist(9) man-page has been updated to note the additional
requirements imposed on the format strings, along with several other
minor changes and enhancements.
[1] It would have been possible to use an explicit length (for example,
uint64_t) for the history arguments. But that would require another
"rototill" of all the users in the future when we add support for an
architecture that supports a larger size. Also, the printf(3) format
specifiers for explicitly-sized values, such as "%"PRIu64, are much
more verbose (and less aesthetically appealing, IMHO) than simply
using "%ju".
[2] I've tried very hard to find "all [the] existing users of kernhist(9)"
but it is possible that I've missed some of them. I would be glad to
update any stragglers that anyone identifies.
2017-10-28 03:37:11 +03:00
|
|
|
UVMHIST_LOG(loanhist, "wired %#jx", (uintptr_t)pg,
|
|
|
|
0, 0, 0);
|
2004-11-21 09:45:49 +03:00
|
|
|
error = EBUSY;
|
|
|
|
break;
|
|
|
|
}
|
2003-05-03 21:54:32 +04:00
|
|
|
if (pg->loan_count == 0) {
|
|
|
|
pmap_page_protect(pg, VM_PROT_READ);
|
|
|
|
}
|
2020-01-01 01:42:50 +03:00
|
|
|
uvm_pagelock(pg);
|
2003-05-03 21:54:32 +04:00
|
|
|
pg->loan_count++;
|
2018-05-25 23:11:03 +03:00
|
|
|
KASSERT(pg->loan_count > 0); /* detect wrap-around */
|
2006-12-15 16:51:30 +03:00
|
|
|
uvm_pageactivate(pg);
|
2020-01-01 01:42:50 +03:00
|
|
|
uvm_pageunlock(pg);
|
2003-05-03 21:54:32 +04:00
|
|
|
}
|
2004-11-21 09:45:49 +03:00
|
|
|
|
2020-05-17 22:38:16 +03:00
|
|
|
if (busied) {
|
|
|
|
uvm_page_unbusy(pgpp, npages);
|
|
|
|
}
|
2004-11-21 09:45:49 +03:00
|
|
|
|
|
|
|
if (error) {
|
|
|
|
/*
|
|
|
|
* backout what we've done
|
|
|
|
*/
|
2020-02-23 18:46:38 +03:00
|
|
|
krwlock_t *slock = pgpp[0]->uobject->vmobjlock;
|
2004-11-21 09:45:49 +03:00
|
|
|
|
2020-02-23 18:46:38 +03:00
|
|
|
rw_exit(slock);
|
2004-11-21 09:45:49 +03:00
|
|
|
uvm_unloan(pgpp, i, UVM_LOAN_TOPAGE);
|
2020-02-23 18:46:38 +03:00
|
|
|
rw_enter(slock, RW_WRITER);
|
2004-11-21 09:45:49 +03:00
|
|
|
}
|
|
|
|
|
Update the kernhist(9) kernel history code to address issues identified
in PR kern/52639, as well as some general cleaning-up...
(As proposed on tech-kern@ with additional changes and enhancements.)
Details of changes:
* All history arguments are now stored as uintmax_t values[1], both in
the kernel and in the structures used for exporting the history data
to userland via sysctl(9). This avoids problems on some architectures
where passing a 64-bit (or larger) value to printf(3) can cause it to
process the value as multiple arguments. (This can be particularly
problematic when printf()'s format string is not a literal, since in
that case the compiler cannot know how large each argument should be.)
* Update the data structures used for exporting kernel history data to
include a version number as well as the length of history arguments.
* All [2] existing users of kernhist(9) have had their format strings
updated. Each format specifier now includes an explicit length
modifier 'j' to refer to numeric values of the size of uintmax_t.
* All [2] existing users of kernhist(9) have had their format strings
updated to replace uses of "%p" with "%#jx", and the pointer
arguments are now cast to (uintptr_t) before being subsequently cast
to (uintmax_t). This is needed to avoid compiler warnings about
casting "pointer to integer of a different size."
* All [2] existing users of kernhist(9) have had instances of "%s" or
"%c" format strings replaced with numeric formats; several instances
of mis-match between format string and argument list have been fixed.
* vmstat(1) has been modified to handle the new size of arguments in the
history data as exported by sysctl(9).
* vmstat(1) now provides a warning message if the history requested with
the -u option does not exist (previously, this condition was silently
ignored, with only a single blank line being printed).
* vmstat(1) now checks the version and argument length included in the
data exported via sysctl(9) and exits if they do not match the values
with which vmstat was built.
* The kernhist(9) man-page has been updated to note the additional
requirements imposed on the format strings, along with several other
minor changes and enhancements.
[1] It would have been possible to use an explicit length (for example,
uint64_t) for the history arguments. But that would require another
"rototill" of all the users in the future when we add support for an
architecture that supports a larger size. Also, the printf(3) format
specifiers for explicitly-sized values, such as "%"PRIu64, are much
more verbose (and less aesthetically appealing, IMHO) than simply
using "%ju".
[2] I've tried very hard to find "all [the] existing users of kernhist(9)"
but it is possible that I've missed some of them. I would be glad to
update any stragglers that anyone identifies.
2017-10-28 03:37:11 +03:00
|
|
|
UVMHIST_LOG(loanhist, "done %jd", error, 0, 0, 0);
|
2004-11-21 09:45:49 +03:00
|
|
|
return error;
|
2003-05-03 21:54:32 +04:00
|
|
|
}
|
|
|
|
|
2004-01-07 15:17:10 +03:00
|
|
|
/*
|
|
|
|
* XXX UBC temp limit
|
|
|
|
* number of pages to get at once.
|
|
|
|
* should be <= MAX_READ_AHEAD in genfs_vnops.c
|
|
|
|
*/
|
|
|
|
#define UVM_LOAN_GET_CHUNK 16
|
|
|
|
|
|
|
|
/*
|
2020-05-20 00:52:04 +03:00
|
|
|
* uvm_loanuobjchunk: helper for uvm_loanuobjpages()
|
2004-01-07 15:17:10 +03:00
|
|
|
*/
|
2020-05-20 00:52:04 +03:00
|
|
|
static int
|
|
|
|
uvm_loanuobjchunk(struct uvm_object *uobj, voff_t pgoff, int orignpages,
|
|
|
|
struct vm_page **pgpp)
|
2004-01-07 15:17:10 +03:00
|
|
|
{
|
2020-05-20 00:52:04 +03:00
|
|
|
int error, npages;
|
2004-01-07 15:17:10 +03:00
|
|
|
|
2020-05-20 00:52:04 +03:00
|
|
|
rw_enter(uobj->vmobjlock, RW_WRITER);
|
|
|
|
reget:
|
|
|
|
npages = orignpages;
|
|
|
|
error = (*uobj->pgops->pgo_get)(uobj, pgoff, pgpp, &npages, 0,
|
|
|
|
VM_PROT_READ, 0, PGO_SYNCIO);
|
|
|
|
switch (error) {
|
|
|
|
case 0:
|
|
|
|
KASSERT(npages == orignpages);
|
|
|
|
|
|
|
|
/* check for released pages */
|
|
|
|
rw_enter(uobj->vmobjlock, RW_WRITER);
|
|
|
|
for (int i = 0; i < npages; i++) {
|
|
|
|
KASSERT(pgpp[i]->uobject->vmobjlock == uobj->vmobjlock);
|
|
|
|
if ((pgpp[i]->flags & PG_RELEASED) != 0) {
|
2004-01-07 15:17:10 +03:00
|
|
|
/*
|
|
|
|
* release pages and try again.
|
|
|
|
*/
|
2020-05-20 00:52:04 +03:00
|
|
|
uvm_page_unbusy(pgpp, npages);
|
2004-01-07 15:17:10 +03:00
|
|
|
goto reget;
|
|
|
|
}
|
2020-05-20 00:52:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* loan out pages. they will be unbusied whatever happens. */
|
|
|
|
error = uvm_loanpage(pgpp, npages, true);
|
|
|
|
rw_exit(uobj->vmobjlock);
|
2020-05-20 21:37:50 +03:00
|
|
|
if (error != 0) {
|
|
|
|
memset(pgpp, 0, sizeof(pgpp[0]) * npages);
|
|
|
|
}
|
2020-05-20 00:52:04 +03:00
|
|
|
return error;
|
2004-01-07 15:17:10 +03:00
|
|
|
|
2020-05-20 00:52:04 +03:00
|
|
|
case EAGAIN:
|
|
|
|
kpause("loanuopg", false, hz/2, NULL);
|
|
|
|
rw_enter(uobj->vmobjlock, RW_WRITER);
|
|
|
|
goto reget;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return error;
|
2004-01-07 15:17:10 +03:00
|
|
|
}
|
2020-05-20 00:52:04 +03:00
|
|
|
}
|
2004-01-07 15:17:10 +03:00
|
|
|
|
2020-05-20 00:52:04 +03:00
|
|
|
/*
|
|
|
|
* uvm_loanuobjpages: loan pages from a uobj out (O->K)
|
|
|
|
*
|
|
|
|
* => uobj shouldn't be locked. (we'll lock it)
|
|
|
|
* => fail with EBUSY if we meet a wired page.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
uvm_loanuobjpages(struct uvm_object *uobj, voff_t pgoff, int npages,
|
|
|
|
struct vm_page **pgpp)
|
|
|
|
{
|
|
|
|
int ndone, error, chunk;
|
2004-11-21 09:45:49 +03:00
|
|
|
|
2020-05-20 00:52:04 +03:00
|
|
|
KASSERT(npages > 0);
|
|
|
|
|
2020-05-20 21:37:50 +03:00
|
|
|
memset(pgpp, 0, sizeof(pgpp[0]) * npages);
|
2020-05-20 00:52:04 +03:00
|
|
|
for (ndone = 0; ndone < npages; ndone += chunk) {
|
|
|
|
chunk = MIN(UVM_LOAN_GET_CHUNK, npages - ndone);
|
|
|
|
error = uvm_loanuobjchunk(uobj, pgoff + (ndone << PAGE_SHIFT),
|
|
|
|
chunk, pgpp + ndone);
|
|
|
|
if (error != 0) {
|
|
|
|
if (ndone != 0) {
|
|
|
|
uvm_unloan(pgpp, ndone, UVM_LOAN_TOPAGE);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2004-11-21 09:45:49 +03:00
|
|
|
|
|
|
|
return error;
|
2004-01-07 15:17:10 +03:00
|
|
|
}
|
|
|
|
|
1998-02-05 09:25:08 +03:00
|
|
|
/*
|
|
|
|
* uvm_loanuobj: loan a page from a uobj out
|
|
|
|
*
|
2001-04-10 04:53:21 +04:00
|
|
|
* => called with map, amap, uobj locked
|
1998-02-05 09:25:08 +03:00
|
|
|
* => return value:
|
|
|
|
* -1 = fatal error, everything is unlocked, abort.
|
|
|
|
* 0 = lookup in ufi went stale, everything unlocked, relookup and
|
|
|
|
* try again
|
|
|
|
* 1 = got it, everything still locked
|
|
|
|
*/
|
|
|
|
|
2001-09-22 09:58:04 +04:00
|
|
|
static int
|
2005-06-27 06:19:48 +04:00
|
|
|
uvm_loanuobj(struct uvm_faultinfo *ufi, void ***output, int flags, vaddr_t va)
|
1998-02-05 09:25:08 +03:00
|
|
|
{
|
1998-03-09 03:58:55 +03:00
|
|
|
struct vm_amap *amap = ufi->entry->aref.ar_amap;
|
|
|
|
struct uvm_object *uobj = ufi->entry->object.uvm_obj;
|
|
|
|
struct vm_page *pg;
|
2001-11-06 11:07:49 +03:00
|
|
|
int error, npages;
|
2007-02-22 01:59:35 +03:00
|
|
|
bool locked;
|
1998-03-09 03:58:55 +03:00
|
|
|
|
2004-11-23 07:51:56 +03:00
|
|
|
UVMHIST_FUNC(__func__); UVMHIST_CALLED(loanhist);
|
|
|
|
|
1998-03-09 03:58:55 +03:00
|
|
|
/*
|
|
|
|
* first we must make sure the page is resident.
|
|
|
|
*
|
|
|
|
* XXXCDC: duplicate code with uvm_fault().
|
|
|
|
*/
|
|
|
|
|
2010-02-03 17:02:49 +03:00
|
|
|
/* locked: maps(read), amap(if there) */
|
2020-02-23 18:46:38 +03:00
|
|
|
rw_enter(uobj->vmobjlock, RW_WRITER);
|
2010-02-03 17:02:49 +03:00
|
|
|
/* locked: maps(read), amap(if there), uobj */
|
|
|
|
|
2001-04-10 04:53:21 +04:00
|
|
|
if (uobj->pgops->pgo_get) { /* try locked pgo_get */
|
1998-03-09 03:58:55 +03:00
|
|
|
npages = 1;
|
|
|
|
pg = NULL;
|
2002-05-07 06:29:52 +04:00
|
|
|
error = (*uobj->pgops->pgo_get)(uobj,
|
|
|
|
va - ufi->entry->start + ufi->entry->offset,
|
1998-03-09 03:58:55 +03:00
|
|
|
&pg, &npages, 0, VM_PROT_READ, MADV_NORMAL, PGO_LOCKED);
|
|
|
|
} else {
|
2001-11-06 11:07:49 +03:00
|
|
|
error = EIO; /* must have pgo_get op */
|
1998-03-09 03:58:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* check the result of the locked pgo_get. if there is a problem,
|
|
|
|
* then we fail the loan.
|
|
|
|
*/
|
|
|
|
|
2001-11-06 11:07:49 +03:00
|
|
|
if (error && error != EBUSY) {
|
2011-06-12 07:35:36 +04:00
|
|
|
uvmfault_unlockall(ufi, amap, uobj);
|
2001-11-06 11:07:49 +03:00
|
|
|
return (-1);
|
1998-03-09 03:58:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* if we need to unlock for I/O, do so now.
|
|
|
|
*/
|
|
|
|
|
2001-11-06 11:07:49 +03:00
|
|
|
if (error == EBUSY) {
|
2011-06-12 07:35:36 +04:00
|
|
|
uvmfault_unlockall(ufi, amap, NULL);
|
2001-11-06 11:07:49 +03:00
|
|
|
|
1998-03-09 03:58:55 +03:00
|
|
|
/* locked: uobj */
|
2001-11-06 11:07:49 +03:00
|
|
|
npages = 1;
|
2002-05-07 06:29:52 +04:00
|
|
|
error = (*uobj->pgops->pgo_get)(uobj,
|
|
|
|
va - ufi->entry->start + ufi->entry->offset,
|
2001-08-18 09:51:44 +04:00
|
|
|
&pg, &npages, 0, VM_PROT_READ, MADV_NORMAL, PGO_SYNCIO);
|
1998-03-09 03:58:55 +03:00
|
|
|
/* locked: <nothing> */
|
2001-05-25 08:06:11 +04:00
|
|
|
|
2001-11-06 11:07:49 +03:00
|
|
|
if (error) {
|
2003-10-26 19:04:00 +03:00
|
|
|
if (error == EAGAIN) {
|
2009-12-06 01:34:43 +03:00
|
|
|
kpause("fltagain2", false, hz/2, NULL);
|
2001-11-06 11:07:49 +03:00
|
|
|
return (0);
|
2001-05-25 08:06:11 +04:00
|
|
|
}
|
2001-11-06 11:07:49 +03:00
|
|
|
return (-1);
|
1998-03-09 03:58:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* pgo_get was a success. attempt to relock everything.
|
|
|
|
*/
|
|
|
|
|
|
|
|
locked = uvmfault_relock(ufi);
|
|
|
|
if (locked && amap)
|
2020-02-23 18:46:38 +03:00
|
|
|
amap_lock(amap, RW_WRITER);
|
2006-01-31 17:11:25 +03:00
|
|
|
uobj = pg->uobject;
|
2020-02-23 18:46:38 +03:00
|
|
|
rw_enter(uobj->vmobjlock, RW_WRITER);
|
1998-03-09 03:58:55 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* verify that the page has not be released and re-verify
|
|
|
|
* that amap slot is still free. if there is a problem we
|
|
|
|
* drop our lock (thus force a lookup refresh/retry).
|
|
|
|
*/
|
2001-05-25 08:06:11 +04:00
|
|
|
|
1998-03-09 03:58:55 +03:00
|
|
|
if ((pg->flags & PG_RELEASED) != 0 ||
|
|
|
|
(locked && amap && amap_lookup(&ufi->entry->aref,
|
1998-10-12 03:16:20 +04:00
|
|
|
ufi->orig_rvaddr - ufi->entry->start))) {
|
1998-03-09 03:58:55 +03:00
|
|
|
if (locked)
|
2011-06-12 07:35:36 +04:00
|
|
|
uvmfault_unlockall(ufi, amap, NULL);
|
2007-02-22 09:05:00 +03:00
|
|
|
locked = false;
|
2001-05-25 08:06:11 +04:00
|
|
|
}
|
1998-03-09 03:58:55 +03:00
|
|
|
|
|
|
|
/*
|
2020-05-17 22:38:16 +03:00
|
|
|
* unbusy the page.
|
1998-03-09 03:58:55 +03:00
|
|
|
*/
|
|
|
|
|
2020-05-17 22:38:16 +03:00
|
|
|
if ((pg->flags & PG_RELEASED) == 0) {
|
2020-01-01 01:42:50 +03:00
|
|
|
uvm_pagelock(pg);
|
2020-03-17 21:31:38 +03:00
|
|
|
uvm_pagewakeup(pg);
|
2020-01-01 01:42:50 +03:00
|
|
|
uvm_pageunlock(pg);
|
2020-03-17 21:31:38 +03:00
|
|
|
pg->flags &= ~PG_BUSY;
|
|
|
|
UVM_PAGE_OWN(pg, NULL);
|
2020-05-17 22:38:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* didn't get the lock? release the page and retry.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (locked == false) {
|
|
|
|
if (pg->flags & PG_RELEASED) {
|
|
|
|
uvm_pagefree(pg);
|
|
|
|
}
|
2020-02-23 18:46:38 +03:00
|
|
|
rw_exit(uobj->vmobjlock);
|
1998-03-09 03:58:55 +03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-17 22:38:16 +03:00
|
|
|
/*
|
|
|
|
* for tmpfs vnodes, the page will be from a UAO rather than
|
|
|
|
* the vnode. just check the locks match.
|
|
|
|
*/
|
|
|
|
|
|
|
|
KASSERT(uobj->vmobjlock == pg->uobject->vmobjlock);
|
2006-01-31 17:11:25 +03:00
|
|
|
|
1998-03-09 03:58:55 +03:00
|
|
|
/*
|
2020-05-17 22:38:16 +03:00
|
|
|
* at this point we have the page we want ("pg") and we have
|
|
|
|
* all data structures locked. do the loanout. page can not
|
|
|
|
* be PG_RELEASED (we caught this above).
|
1998-03-09 03:58:55 +03:00
|
|
|
*/
|
|
|
|
|
2001-11-06 11:07:49 +03:00
|
|
|
if ((flags & UVM_LOAN_TOANON) == 0) {
|
2020-05-17 22:38:16 +03:00
|
|
|
if (uvm_loanpage(&pg, 1, false)) {
|
2011-06-12 07:35:36 +04:00
|
|
|
uvmfault_unlockall(ufi, amap, uobj);
|
2004-11-21 09:45:49 +03:00
|
|
|
return (-1);
|
|
|
|
}
|
2020-02-23 18:46:38 +03:00
|
|
|
rw_exit(uobj->vmobjlock);
|
2001-11-06 11:07:49 +03:00
|
|
|
**output = pg;
|
|
|
|
(*output)++;
|
|
|
|
return (1);
|
1998-03-09 03:58:55 +03:00
|
|
|
}
|
|
|
|
|
2011-06-12 07:35:36 +04:00
|
|
|
#ifdef notdef
|
1998-03-09 03:58:55 +03:00
|
|
|
/*
|
|
|
|
* must be a loan to an anon. check to see if there is already
|
|
|
|
* an anon associated with this page. if so, then just return
|
2001-05-25 08:06:11 +04:00
|
|
|
* a reference to this object. the page should already be
|
1998-03-09 03:58:55 +03:00
|
|
|
* mapped read-only because it is already on loan.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (pg->uanon) {
|
2011-08-06 21:25:03 +04:00
|
|
|
/* XXX: locking */
|
1998-03-09 03:58:55 +03:00
|
|
|
anon = pg->uanon;
|
|
|
|
anon->an_ref++;
|
2020-03-14 23:23:51 +03:00
|
|
|
uvm_pagelock(pg);
|
2020-03-17 21:31:38 +03:00
|
|
|
uvm_pagewakeup(pg);
|
2020-03-14 23:23:51 +03:00
|
|
|
uvm_pageunlock(pg);
|
2020-03-17 21:31:38 +03:00
|
|
|
pg->flags &= ~PG_BUSY;
|
|
|
|
UVM_PAGE_OWN(pg, NULL);
|
2020-02-23 18:46:38 +03:00
|
|
|
rw_exit(uobj->vmobjlock);
|
2001-11-06 11:07:49 +03:00
|
|
|
**output = anon;
|
|
|
|
(*output)++;
|
|
|
|
return (1);
|
1998-03-09 03:58:55 +03:00
|
|
|
}
|
2001-05-25 08:06:11 +04:00
|
|
|
|
1998-03-09 03:58:55 +03:00
|
|
|
/*
|
|
|
|
* need to allocate a new anon
|
|
|
|
*/
|
|
|
|
|
|
|
|
anon = uvm_analloc();
|
2001-11-06 11:07:49 +03:00
|
|
|
if (anon == NULL) {
|
2004-11-21 09:45:49 +03:00
|
|
|
goto fail;
|
1998-03-09 03:58:55 +03:00
|
|
|
}
|
2004-11-21 09:45:49 +03:00
|
|
|
if (pg->wire_count > 0) {
|
Update the kernhist(9) kernel history code to address issues identified
in PR kern/52639, as well as some general cleaning-up...
(As proposed on tech-kern@ with additional changes and enhancements.)
Details of changes:
* All history arguments are now stored as uintmax_t values[1], both in
the kernel and in the structures used for exporting the history data
to userland via sysctl(9). This avoids problems on some architectures
where passing a 64-bit (or larger) value to printf(3) can cause it to
process the value as multiple arguments. (This can be particularly
problematic when printf()'s format string is not a literal, since in
that case the compiler cannot know how large each argument should be.)
* Update the data structures used for exporting kernel history data to
include a version number as well as the length of history arguments.
* All [2] existing users of kernhist(9) have had their format strings
updated. Each format specifier now includes an explicit length
modifier 'j' to refer to numeric values of the size of uintmax_t.
* All [2] existing users of kernhist(9) have had their format strings
updated to replace uses of "%p" with "%#jx", and the pointer
arguments are now cast to (uintptr_t) before being subsequently cast
to (uintmax_t). This is needed to avoid compiler warnings about
casting "pointer to integer of a different size."
* All [2] existing users of kernhist(9) have had instances of "%s" or
"%c" format strings replaced with numeric formats; several instances
of mis-match between format string and argument list have been fixed.
* vmstat(1) has been modified to handle the new size of arguments in the
history data as exported by sysctl(9).
* vmstat(1) now provides a warning message if the history requested with
the -u option does not exist (previously, this condition was silently
ignored, with only a single blank line being printed).
* vmstat(1) now checks the version and argument length included in the
data exported via sysctl(9) and exits if they do not match the values
with which vmstat was built.
* The kernhist(9) man-page has been updated to note the additional
requirements imposed on the format strings, along with several other
minor changes and enhancements.
[1] It would have been possible to use an explicit length (for example,
uint64_t) for the history arguments. But that would require another
"rototill" of all the users in the future when we add support for an
architecture that supports a larger size. Also, the printf(3) format
specifiers for explicitly-sized values, such as "%"PRIu64, are much
more verbose (and less aesthetically appealing, IMHO) than simply
using "%ju".
[2] I've tried very hard to find "all [the] existing users of kernhist(9)"
but it is possible that I've missed some of them. I would be glad to
update any stragglers that anyone identifies.
2017-10-28 03:37:11 +03:00
|
|
|
UVMHIST_LOG(loanhist, "wired %#jx", (uintptr_t)pg, 0, 0, 0);
|
2004-11-21 09:45:49 +03:00
|
|
|
goto fail;
|
|
|
|
}
|
2001-11-06 11:07:49 +03:00
|
|
|
if (pg->loan_count == 0) {
|
1999-09-12 05:16:55 +04:00
|
|
|
pmap_page_protect(pg, VM_PROT_READ);
|
2001-11-06 11:07:49 +03:00
|
|
|
}
|
2020-01-01 01:42:50 +03:00
|
|
|
uvm_pagelock(pg);
|
1998-03-09 03:58:55 +03:00
|
|
|
pg->loan_count++;
|
2018-05-25 23:11:03 +03:00
|
|
|
KASSERT(pg->loan_count > 0); /* detect wrap-around */
|
2011-08-06 21:25:03 +04:00
|
|
|
pg->uanon = anon;
|
|
|
|
anon->an_page = pg;
|
|
|
|
anon->an_lock = /* TODO: share amap lock */
|
1998-03-09 03:58:55 +03:00
|
|
|
uvm_pageactivate(pg);
|
2020-03-17 21:31:38 +03:00
|
|
|
uvm_pagewakeup(pg);
|
2020-01-01 01:42:50 +03:00
|
|
|
uvm_pageunlock(pg);
|
2020-03-17 21:31:38 +03:00
|
|
|
pg->flags &= ~PG_BUSY;
|
|
|
|
UVM_PAGE_OWN(pg, NULL);
|
2020-02-23 18:46:38 +03:00
|
|
|
rw_exit(uobj->vmobjlock);
|
|
|
|
rw_exit(&anon->an_lock);
|
2001-11-06 11:07:49 +03:00
|
|
|
**output = anon;
|
|
|
|
(*output)++;
|
|
|
|
return (1);
|
2004-11-21 09:45:49 +03:00
|
|
|
|
|
|
|
fail:
|
2004-11-23 07:51:56 +03:00
|
|
|
UVMHIST_LOG(loanhist, "fail", 0,0,0,0);
|
2004-11-21 09:45:49 +03:00
|
|
|
/*
|
|
|
|
* unlock everything and bail out.
|
|
|
|
*/
|
2020-03-14 23:23:51 +03:00
|
|
|
uvm_pagelock(pg);
|
2020-03-17 21:31:38 +03:00
|
|
|
uvm_pagewakeup(pg);
|
2020-03-14 23:23:51 +03:00
|
|
|
uvm_pageunlock(pg);
|
2020-03-17 21:31:38 +03:00
|
|
|
pg->flags &= ~PG_BUSY;
|
|
|
|
UVM_PAGE_OWN(pg, NULL);
|
2004-11-21 09:45:49 +03:00
|
|
|
uvmfault_unlockall(ufi, amap, uobj, NULL);
|
2011-08-06 21:25:03 +04:00
|
|
|
if (anon) {
|
|
|
|
anon->an_ref--;
|
2020-03-20 22:08:54 +03:00
|
|
|
uvm_anfree(anon);
|
2011-08-06 21:25:03 +04:00
|
|
|
}
|
2011-06-12 07:35:36 +04:00
|
|
|
#endif /* notdef */
|
2004-11-21 09:45:49 +03:00
|
|
|
return (-1);
|
1998-02-05 09:25:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2003-03-04 09:18:54 +03:00
|
|
|
* uvm_loanzero: loan a zero-fill page out
|
1998-02-05 09:25:08 +03:00
|
|
|
*
|
2001-04-10 04:53:21 +04:00
|
|
|
* => called with map, amap, uobj locked
|
1998-02-05 09:25:08 +03:00
|
|
|
* => return value:
|
|
|
|
* -1 = fatal error, everything is unlocked, abort.
|
|
|
|
* 0 = lookup in ufi went stale, everything unlocked, relookup and
|
|
|
|
* try again
|
|
|
|
* 1 = got it, everything still locked
|
|
|
|
*/
|
|
|
|
|
2003-03-04 09:18:54 +03:00
|
|
|
static struct uvm_object uvm_loanzero_object;
|
2020-02-23 18:46:38 +03:00
|
|
|
static krwlock_t uvm_loanzero_lock __cacheline_aligned;
|
2003-03-04 09:18:54 +03:00
|
|
|
|
2001-09-22 09:58:04 +04:00
|
|
|
static int
|
2005-06-27 06:19:48 +04:00
|
|
|
uvm_loanzero(struct uvm_faultinfo *ufi, void ***output, int flags)
|
1998-02-05 09:25:08 +03:00
|
|
|
{
|
1998-03-09 03:58:55 +03:00
|
|
|
struct vm_page *pg;
|
2001-11-06 11:07:49 +03:00
|
|
|
struct vm_amap *amap = ufi->entry->aref.ar_amap;
|
1998-03-09 03:58:55 +03:00
|
|
|
|
2004-11-23 07:51:56 +03:00
|
|
|
UVMHIST_FUNC(__func__); UVMHIST_CALLED(loanhist);
|
2003-10-27 15:47:33 +03:00
|
|
|
again:
|
2020-02-23 18:46:38 +03:00
|
|
|
rw_enter(uvm_loanzero_object.vmobjlock, RW_WRITER);
|
2003-03-04 09:18:54 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* first, get ahold of our single zero page.
|
|
|
|
*/
|
|
|
|
|
2019-12-16 00:11:34 +03:00
|
|
|
pg = uvm_pagelookup(&uvm_loanzero_object, 0);
|
|
|
|
if (__predict_false(pg == NULL)) {
|
2003-03-04 09:18:54 +03:00
|
|
|
while ((pg = uvm_pagealloc(&uvm_loanzero_object, 0, NULL,
|
|
|
|
UVM_PGA_ZERO)) == NULL) {
|
2020-02-23 18:46:38 +03:00
|
|
|
rw_exit(uvm_loanzero_object.vmobjlock);
|
2011-06-12 07:35:36 +04:00
|
|
|
uvmfault_unlockall(ufi, amap, NULL);
|
2003-03-04 09:18:54 +03:00
|
|
|
uvm_wait("loanzero");
|
2001-11-06 11:07:49 +03:00
|
|
|
if (!uvmfault_relock(ufi)) {
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
if (amap) {
|
2020-02-23 18:46:38 +03:00
|
|
|
amap_lock(amap, RW_WRITER);
|
2001-11-06 11:07:49 +03:00
|
|
|
}
|
2003-10-27 15:47:33 +03:00
|
|
|
goto again;
|
1998-03-09 03:58:55 +03:00
|
|
|
}
|
2001-05-25 08:06:11 +04:00
|
|
|
|
2003-03-04 09:18:54 +03:00
|
|
|
/* got a zero'd page. */
|
2020-03-17 21:31:38 +03:00
|
|
|
pg->flags &= ~(PG_BUSY|PG_FAKE);
|
2003-03-04 09:18:54 +03:00
|
|
|
pg->flags |= PG_RDONLY;
|
2020-01-01 01:42:50 +03:00
|
|
|
uvm_pagelock(pg);
|
2003-10-27 15:47:33 +03:00
|
|
|
uvm_pageactivate(pg);
|
2020-03-17 21:31:38 +03:00
|
|
|
uvm_pagewakeup(pg);
|
2020-01-01 01:42:50 +03:00
|
|
|
uvm_pageunlock(pg);
|
2020-03-17 21:31:38 +03:00
|
|
|
UVM_PAGE_OWN(pg, NULL);
|
2003-03-04 09:18:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((flags & UVM_LOAN_TOANON) == 0) { /* loaning to kernel-page */
|
2019-12-13 23:10:21 +03:00
|
|
|
mutex_enter(&pg->interlock);
|
2003-03-04 09:18:54 +03:00
|
|
|
pg->loan_count++;
|
2018-05-25 23:11:03 +03:00
|
|
|
KASSERT(pg->loan_count > 0); /* detect wrap-around */
|
2019-12-13 23:10:21 +03:00
|
|
|
mutex_exit(&pg->interlock);
|
2020-02-23 18:46:38 +03:00
|
|
|
rw_exit(uvm_loanzero_object.vmobjlock);
|
1998-03-09 03:58:55 +03:00
|
|
|
**output = pg;
|
2001-11-06 11:07:49 +03:00
|
|
|
(*output)++;
|
|
|
|
return (1);
|
1998-03-09 03:58:55 +03:00
|
|
|
}
|
|
|
|
|
2011-06-12 07:35:36 +04:00
|
|
|
#ifdef notdef
|
2003-03-04 09:18:54 +03:00
|
|
|
/*
|
|
|
|
* loaning to an anon. check to see if there is already an anon
|
|
|
|
* associated with this page. if so, then just return a reference
|
|
|
|
* to this object.
|
|
|
|
*/
|
2001-01-23 05:27:39 +03:00
|
|
|
|
2003-03-04 09:18:54 +03:00
|
|
|
if (pg->uanon) {
|
|
|
|
anon = pg->uanon;
|
2020-02-23 18:46:38 +03:00
|
|
|
rw_enter(&anon->an_lock, RW_WRITER);
|
2003-03-04 09:18:54 +03:00
|
|
|
anon->an_ref++;
|
2020-02-23 18:46:38 +03:00
|
|
|
rw_exit(&anon->an_lock);
|
|
|
|
rw_exit(uvm_loanzero_object.vmobjlock);
|
2003-03-04 09:18:54 +03:00
|
|
|
**output = anon;
|
|
|
|
(*output)++;
|
|
|
|
return (1);
|
|
|
|
}
|
1998-03-09 03:58:55 +03:00
|
|
|
|
2003-03-04 09:18:54 +03:00
|
|
|
/*
|
|
|
|
* need to allocate a new anon
|
|
|
|
*/
|
1998-03-09 03:58:55 +03:00
|
|
|
|
2003-03-04 09:18:54 +03:00
|
|
|
anon = uvm_analloc();
|
|
|
|
if (anon == NULL) {
|
|
|
|
/* out of swap causes us to fail */
|
2020-02-23 18:46:38 +03:00
|
|
|
rw_exit(uvm_loanzero_object.vmobjlock);
|
2006-01-31 17:11:25 +03:00
|
|
|
uvmfault_unlockall(ufi, amap, NULL, NULL);
|
2003-03-04 09:18:54 +03:00
|
|
|
return (-1);
|
1998-03-09 03:58:55 +03:00
|
|
|
}
|
2005-05-11 17:02:25 +04:00
|
|
|
anon->an_page = pg;
|
2003-03-04 09:18:54 +03:00
|
|
|
pg->uanon = anon;
|
2020-01-01 01:42:50 +03:00
|
|
|
uvm_pagelock(pg);
|
2003-03-04 09:18:54 +03:00
|
|
|
pg->loan_count++;
|
2018-05-25 23:11:03 +03:00
|
|
|
KASSERT(pg->loan_count > 0); /* detect wrap-around */
|
1998-03-09 03:58:55 +03:00
|
|
|
uvm_pageactivate(pg);
|
2020-01-01 01:42:50 +03:00
|
|
|
uvm_pageunlock(pg);
|
2020-02-23 18:46:38 +03:00
|
|
|
rw_exit(&anon->an_lock);
|
|
|
|
rw_exit(uvm_loanzero_object.vmobjlock);
|
1998-03-09 03:58:55 +03:00
|
|
|
**output = anon;
|
2001-11-06 11:07:49 +03:00
|
|
|
(*output)++;
|
|
|
|
return (1);
|
2011-06-12 07:35:36 +04:00
|
|
|
#else
|
|
|
|
return (-1);
|
|
|
|
#endif
|
1998-02-05 09:25:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* uvm_unloananon: kill loans on anons (basically a normal ref drop)
|
|
|
|
*
|
|
|
|
* => we expect all our resources to be unlocked
|
|
|
|
*/
|
|
|
|
|
2001-09-22 09:58:04 +04:00
|
|
|
static void
|
2005-06-27 06:19:48 +04:00
|
|
|
uvm_unloananon(struct vm_anon **aloans, int nanons)
|
1998-02-05 09:25:08 +03:00
|
|
|
{
|
2011-06-12 07:35:36 +04:00
|
|
|
#ifdef notdef
|
2011-08-06 21:25:03 +04:00
|
|
|
struct vm_anon *anon, *to_free = NULL;
|
1998-02-05 09:25:08 +03:00
|
|
|
|
2011-08-06 21:25:03 +04:00
|
|
|
/* TODO: locking */
|
2020-02-23 18:46:38 +03:00
|
|
|
amap_lock(amap, RW_WRITER);
|
1998-03-09 03:58:55 +03:00
|
|
|
while (nanons-- > 0) {
|
|
|
|
anon = *aloans++;
|
2011-08-06 21:25:03 +04:00
|
|
|
if (--anon->an_ref == 0) {
|
2020-03-20 22:08:54 +03:00
|
|
|
uvm_anfree(anon);
|
1998-03-09 03:58:55 +03:00
|
|
|
}
|
|
|
|
}
|
2020-03-20 22:08:54 +03:00
|
|
|
amap_unlock(amap);
|
2011-06-12 07:35:36 +04:00
|
|
|
#endif /* notdef */
|
1998-02-05 09:25:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* uvm_unloanpage: kill loans on pages loaned out to the kernel
|
|
|
|
*
|
|
|
|
* => we expect all our resources to be unlocked
|
|
|
|
*/
|
|
|
|
|
2001-09-22 09:58:04 +04:00
|
|
|
static void
|
2005-06-27 06:19:48 +04:00
|
|
|
uvm_unloanpage(struct vm_page **ploans, int npages)
|
1998-02-05 09:25:08 +03:00
|
|
|
{
|
1998-03-09 03:58:55 +03:00
|
|
|
struct vm_page *pg;
|
2020-02-23 18:46:38 +03:00
|
|
|
krwlock_t *slock;
|
1998-02-05 09:25:08 +03:00
|
|
|
|
1998-03-09 03:58:55 +03:00
|
|
|
while (npages-- > 0) {
|
|
|
|
pg = *ploans++;
|
1998-02-05 09:25:08 +03:00
|
|
|
|
1998-03-09 03:58:55 +03:00
|
|
|
/*
|
2001-12-31 22:21:36 +03:00
|
|
|
* do a little dance to acquire the object or anon lock
|
|
|
|
* as appropriate. we are locking in the wrong order,
|
|
|
|
* so we have to do a try-lock here.
|
|
|
|
*/
|
|
|
|
|
2019-12-13 23:10:21 +03:00
|
|
|
mutex_enter(&pg->interlock);
|
2001-12-31 22:21:36 +03:00
|
|
|
slock = NULL;
|
|
|
|
while (pg->uobject != NULL || pg->uanon != NULL) {
|
|
|
|
if (pg->uobject != NULL) {
|
2011-06-12 07:35:36 +04:00
|
|
|
slock = pg->uobject->vmobjlock;
|
2001-12-31 22:21:36 +03:00
|
|
|
} else {
|
2011-06-12 07:35:36 +04:00
|
|
|
slock = pg->uanon->an_lock;
|
2001-12-31 22:21:36 +03:00
|
|
|
}
|
2020-02-23 18:46:38 +03:00
|
|
|
if (rw_tryenter(slock, RW_WRITER)) {
|
2001-12-31 22:21:36 +03:00
|
|
|
break;
|
|
|
|
}
|
2008-01-02 14:48:20 +03:00
|
|
|
/* XXX Better than yielding but inadequate. */
|
2019-12-13 23:10:21 +03:00
|
|
|
kpause("livelock", false, 1, &pg->interlock);
|
2020-02-25 00:06:11 +03:00
|
|
|
slock = NULL;
|
2001-12-31 22:21:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* drop our loan. if page is owned by an anon but
|
2019-12-13 23:10:21 +03:00
|
|
|
* PG_ANON is not set, the page was loaned to the anon
|
2001-12-31 22:21:36 +03:00
|
|
|
* from an object which dropped ownership, so resolve
|
|
|
|
* this by turning the anon's loan into real ownership
|
2019-12-13 23:10:21 +03:00
|
|
|
* (ie. decrement loan_count again and set PG_ANON).
|
2001-12-31 22:21:36 +03:00
|
|
|
* after all this, if there are no loans left, put the
|
|
|
|
* page back a paging queue (if the page is owned by
|
|
|
|
* an anon) or free it (if the page is now unowned).
|
1998-03-09 03:58:55 +03:00
|
|
|
*/
|
1998-02-05 09:25:08 +03:00
|
|
|
|
2001-11-06 11:07:49 +03:00
|
|
|
KASSERT(pg->loan_count > 0);
|
|
|
|
pg->loan_count--;
|
2001-12-31 22:21:36 +03:00
|
|
|
if (pg->uobject == NULL && pg->uanon != NULL &&
|
2019-12-13 23:10:21 +03:00
|
|
|
(pg->flags & PG_ANON) == 0) {
|
2001-12-31 22:21:36 +03:00
|
|
|
KASSERT(pg->loan_count > 0);
|
|
|
|
pg->loan_count--;
|
2019-12-13 23:10:21 +03:00
|
|
|
pg->flags |= PG_ANON;
|
2001-12-31 22:21:36 +03:00
|
|
|
}
|
2019-12-13 23:10:21 +03:00
|
|
|
mutex_exit(&pg->interlock);
|
2006-12-15 16:51:30 +03:00
|
|
|
if (pg->loan_count == 0 && pg->uobject == NULL &&
|
|
|
|
pg->uanon == NULL) {
|
|
|
|
KASSERT((pg->flags & PG_BUSY) == 0);
|
|
|
|
uvm_pagefree(pg);
|
2001-12-31 22:21:36 +03:00
|
|
|
}
|
2020-02-25 00:06:11 +03:00
|
|
|
if (slock != NULL) {
|
|
|
|
rw_exit(slock);
|
|
|
|
}
|
1998-03-09 03:58:55 +03:00
|
|
|
}
|
1998-02-05 09:25:08 +03:00
|
|
|
}
|
|
|
|
|
2001-09-22 09:58:04 +04:00
|
|
|
/*
|
2001-11-06 11:07:49 +03:00
|
|
|
* uvm_unloan: kill loans on pages or anons.
|
2001-09-22 09:58:04 +04:00
|
|
|
*/
|
2001-11-06 11:07:49 +03:00
|
|
|
|
2001-09-22 09:58:04 +04:00
|
|
|
void
|
2001-11-06 11:07:49 +03:00
|
|
|
uvm_unloan(void *v, int npages, int flags)
|
2001-09-22 09:58:04 +04:00
|
|
|
{
|
2001-11-06 11:07:49 +03:00
|
|
|
if (flags & UVM_LOAN_TOANON) {
|
|
|
|
uvm_unloananon(v, npages);
|
|
|
|
} else {
|
|
|
|
uvm_unloanpage(v, npages);
|
|
|
|
}
|
2001-09-22 09:58:04 +04:00
|
|
|
}
|
2003-03-04 09:18:54 +03:00
|
|
|
|
2003-03-05 04:52:41 +03:00
|
|
|
/*
|
|
|
|
* Minimal pager for uvm_loanzero_object. We need to provide a "put"
|
|
|
|
* method, because the page can end up on a paging queue, and the
|
|
|
|
* page daemon will want to call pgo_put when it encounters the page
|
|
|
|
* on the inactive list.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int
|
2006-11-01 13:17:58 +03:00
|
|
|
ulz_put(struct uvm_object *uobj, voff_t start, voff_t stop, int flags)
|
2003-03-05 04:52:41 +03:00
|
|
|
{
|
|
|
|
struct vm_page *pg;
|
|
|
|
|
|
|
|
KDASSERT(uobj == &uvm_loanzero_object);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Don't need to do any work here if we're not freeing pages.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if ((flags & PGO_FREE) == 0) {
|
2020-02-23 18:46:38 +03:00
|
|
|
rw_exit(uobj->vmobjlock);
|
2003-03-05 04:52:41 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* we don't actually want to ever free the uvm_loanzero_page, so
|
|
|
|
* just reactivate or dequeue it.
|
|
|
|
*/
|
|
|
|
|
2019-12-16 00:11:34 +03:00
|
|
|
pg = uvm_pagelookup(uobj, 0);
|
2003-03-05 04:52:41 +03:00
|
|
|
KASSERT(pg != NULL);
|
|
|
|
|
2020-01-01 01:42:50 +03:00
|
|
|
uvm_pagelock(pg);
|
2019-12-16 00:11:34 +03:00
|
|
|
if (pg->uanon) {
|
2003-03-05 04:52:41 +03:00
|
|
|
uvm_pageactivate(pg);
|
2019-12-16 00:11:34 +03:00
|
|
|
} else {
|
2003-03-05 04:52:41 +03:00
|
|
|
uvm_pagedequeue(pg);
|
2019-12-13 23:10:21 +03:00
|
|
|
}
|
2020-01-01 01:42:50 +03:00
|
|
|
uvm_pageunlock(pg);
|
2003-03-05 04:52:41 +03:00
|
|
|
|
2020-02-23 18:46:38 +03:00
|
|
|
rw_exit(uobj->vmobjlock);
|
2003-03-05 04:52:41 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-12-01 13:40:27 +03:00
|
|
|
static const struct uvm_pagerops ulz_pager = {
|
2007-12-01 13:18:21 +03:00
|
|
|
.pgo_put = ulz_put,
|
2003-03-05 04:52:41 +03:00
|
|
|
};
|
|
|
|
|
2003-03-04 09:18:54 +03:00
|
|
|
/*
|
|
|
|
* uvm_loan_init(): initialize the uvm_loan() facility.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
|
|
|
uvm_loan_init(void)
|
|
|
|
{
|
|
|
|
|
2020-02-23 18:46:38 +03:00
|
|
|
rw_init(&uvm_loanzero_lock);
|
2011-06-12 07:35:36 +04:00
|
|
|
uvm_obj_init(&uvm_loanzero_object, &ulz_pager, false, 0);
|
|
|
|
uvm_obj_setlock(&uvm_loanzero_object, &uvm_loanzero_lock);
|
2004-11-23 07:51:56 +03:00
|
|
|
|
|
|
|
UVMHIST_INIT(loanhist, 300);
|
2003-03-04 09:18:54 +03:00
|
|
|
}
|
2003-05-03 21:54:32 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* uvm_loanbreak: break loan on a uobj page
|
|
|
|
*
|
|
|
|
* => called with uobj locked
|
2020-05-17 22:38:16 +03:00
|
|
|
* => the page may be busy; if it's busy, it will be unbusied
|
2003-05-03 21:54:32 +04:00
|
|
|
* => return value:
|
|
|
|
* newly allocated page if succeeded
|
|
|
|
*/
|
|
|
|
struct vm_page *
|
|
|
|
uvm_loanbreak(struct vm_page *uobjpage)
|
|
|
|
{
|
|
|
|
struct vm_page *pg;
|
2017-03-20 02:44:34 +03:00
|
|
|
struct uvm_object *uobj __diagused = uobjpage->uobject;
|
2003-05-03 21:54:32 +04:00
|
|
|
|
|
|
|
KASSERT(uobj != NULL);
|
2020-02-23 18:46:38 +03:00
|
|
|
KASSERT(rw_write_held(uobj->vmobjlock));
|
2003-05-03 21:54:32 +04:00
|
|
|
|
|
|
|
/* alloc new un-owned page */
|
|
|
|
pg = uvm_pagealloc(NULL, 0, NULL, 0);
|
|
|
|
if (pg == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* copy the data from the old page to the new
|
2006-10-14 13:23:56 +04:00
|
|
|
* one and clear the fake flags on the new page (keep it busy).
|
|
|
|
* force a reload of the old page by clearing it from all
|
|
|
|
* pmaps.
|
2019-12-18 23:38:14 +03:00
|
|
|
* then rename the pages.
|
2003-05-03 21:54:32 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
uvm_pagecopy(uobjpage, pg); /* old -> new */
|
2006-10-14 13:23:56 +04:00
|
|
|
pg->flags &= ~PG_FAKE;
|
2020-01-15 20:55:43 +03:00
|
|
|
KASSERT(uvm_pagegetdirty(pg) == UVM_PAGE_STATUS_DIRTY);
|
2003-05-03 21:54:32 +04:00
|
|
|
pmap_page_protect(uobjpage, VM_PROT_NONE);
|
|
|
|
/* uobj still locked */
|
2020-05-17 22:38:16 +03:00
|
|
|
if ((uobjpage->flags & PG_BUSY) != 0) {
|
|
|
|
uobjpage->flags &= ~PG_BUSY;
|
|
|
|
UVM_PAGE_OWN(uobjpage, NULL);
|
|
|
|
}
|
2003-05-03 21:54:32 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* if the page is no longer referenced by
|
|
|
|
* an anon (i.e. we are breaking an O->K
|
|
|
|
* loan), then remove it from any pageq's.
|
|
|
|
*/
|
2020-01-01 01:42:50 +03:00
|
|
|
|
|
|
|
uvm_pagelock2(uobjpage, pg);
|
2020-03-17 21:31:38 +03:00
|
|
|
uvm_pagewakeup(uobjpage);
|
2003-05-03 21:54:32 +04:00
|
|
|
if (uobjpage->uanon == NULL)
|
|
|
|
uvm_pagedequeue(uobjpage);
|
|
|
|
|
2019-12-18 23:38:14 +03:00
|
|
|
/*
|
|
|
|
* replace uobjpage with new page.
|
|
|
|
*/
|
|
|
|
|
|
|
|
uvm_pagereplace(uobjpage, pg);
|
|
|
|
|
2003-05-03 21:54:32 +04:00
|
|
|
/*
|
|
|
|
* at this point we have absolutely no
|
|
|
|
* control over uobjpage
|
|
|
|
*/
|
|
|
|
|
|
|
|
uvm_pageactivate(pg);
|
2020-01-01 01:42:50 +03:00
|
|
|
uvm_pageunlock2(uobjpage, pg);
|
2003-05-03 21:54:32 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* done! loan is broken and "pg" is
|
|
|
|
* PG_BUSY. it can now replace uobjpage.
|
|
|
|
*/
|
|
|
|
|
|
|
|
return pg;
|
|
|
|
}
|
2010-02-02 09:06:02 +03:00
|
|
|
|
|
|
|
int
|
2010-02-02 20:40:43 +03:00
|
|
|
uvm_loanbreak_anon(struct vm_anon *anon, struct uvm_object *uobj)
|
2010-02-02 09:06:02 +03:00
|
|
|
{
|
2019-12-18 23:38:14 +03:00
|
|
|
struct vm_page *newpg, *oldpg;
|
2020-01-15 20:55:43 +03:00
|
|
|
unsigned oldstatus;
|
2010-02-02 09:06:02 +03:00
|
|
|
|
2020-02-23 18:46:38 +03:00
|
|
|
KASSERT(rw_write_held(anon->an_lock));
|
|
|
|
KASSERT(uobj == NULL || rw_write_held(uobj->vmobjlock));
|
2020-01-15 20:55:43 +03:00
|
|
|
KASSERT(anon->an_page->loan_count > 0);
|
2010-02-03 17:02:49 +03:00
|
|
|
|
2010-02-02 09:06:02 +03:00
|
|
|
/* get new un-owned replacement page */
|
2019-12-18 23:38:14 +03:00
|
|
|
newpg = uvm_pagealloc(NULL, 0, NULL, 0);
|
|
|
|
if (newpg == NULL) {
|
2010-02-02 09:06:02 +03:00
|
|
|
return ENOMEM;
|
|
|
|
}
|
|
|
|
|
2019-12-18 23:38:14 +03:00
|
|
|
oldpg = anon->an_page;
|
2020-01-01 01:42:50 +03:00
|
|
|
/* copy old -> new */
|
|
|
|
uvm_pagecopy(oldpg, newpg);
|
2020-01-15 20:55:43 +03:00
|
|
|
KASSERT(uvm_pagegetdirty(newpg) == UVM_PAGE_STATUS_DIRTY);
|
2020-01-01 01:42:50 +03:00
|
|
|
|
|
|
|
/* force reload */
|
|
|
|
pmap_page_protect(oldpg, VM_PROT_NONE);
|
2020-01-15 20:55:43 +03:00
|
|
|
oldstatus = uvm_pagegetdirty(anon->an_page);
|
2020-01-01 01:42:50 +03:00
|
|
|
|
|
|
|
uvm_pagelock2(oldpg, newpg);
|
2019-12-18 23:38:14 +03:00
|
|
|
if (uobj == NULL) {
|
|
|
|
/*
|
|
|
|
* we were the lender (A->K); need to remove the page from
|
|
|
|
* pageq's.
|
2020-01-15 20:55:43 +03:00
|
|
|
*
|
|
|
|
* PG_ANON is updated by the caller.
|
2019-12-18 23:38:14 +03:00
|
|
|
*/
|
2020-01-15 20:55:43 +03:00
|
|
|
KASSERT((oldpg->flags & PG_ANON) != 0);
|
|
|
|
oldpg->flags &= ~PG_ANON;
|
2019-12-18 23:38:14 +03:00
|
|
|
uvm_pagedequeue(oldpg);
|
|
|
|
}
|
|
|
|
oldpg->uanon = NULL;
|
2010-02-02 09:06:02 +03:00
|
|
|
|
2010-02-02 20:40:43 +03:00
|
|
|
if (uobj) {
|
2010-02-02 09:06:02 +03:00
|
|
|
/* if we were receiver of loan */
|
2020-01-15 20:55:43 +03:00
|
|
|
KASSERT((oldpg->pqflags & PG_ANON) == 0);
|
2019-12-18 23:38:14 +03:00
|
|
|
oldpg->loan_count--;
|
2010-02-02 09:06:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* install new page in anon */
|
2019-12-18 23:38:14 +03:00
|
|
|
anon->an_page = newpg;
|
|
|
|
newpg->uanon = anon;
|
|
|
|
newpg->flags |= PG_ANON;
|
2010-02-02 09:06:02 +03:00
|
|
|
|
2019-12-18 23:38:14 +03:00
|
|
|
uvm_pageactivate(newpg);
|
2020-01-01 01:42:50 +03:00
|
|
|
uvm_pageunlock2(oldpg, newpg);
|
2010-02-02 09:06:02 +03:00
|
|
|
|
2019-12-18 23:38:14 +03:00
|
|
|
newpg->flags &= ~(PG_BUSY|PG_FAKE);
|
|
|
|
UVM_PAGE_OWN(newpg, NULL);
|
2010-02-02 09:06:02 +03:00
|
|
|
|
2019-12-13 23:10:21 +03:00
|
|
|
if (uobj) {
|
2020-02-23 18:46:38 +03:00
|
|
|
rw_exit(uobj->vmobjlock);
|
2019-12-13 23:10:21 +03:00
|
|
|
}
|
|
|
|
|
2010-02-02 09:06:02 +03:00
|
|
|
/* done! */
|
2020-01-15 20:55:43 +03:00
|
|
|
kpreempt_disable();
|
2020-06-12 01:21:05 +03:00
|
|
|
if (uobj == NULL) {
|
2020-01-15 20:55:43 +03:00
|
|
|
CPU_COUNT(CPU_COUNT_ANONUNKNOWN + oldstatus, -1);
|
|
|
|
}
|
|
|
|
CPU_COUNT(CPU_COUNT_ANONDIRTY, 1);
|
|
|
|
kpreempt_enable();
|
2010-02-02 09:06:02 +03:00
|
|
|
return 0;
|
|
|
|
}
|