History log of /openbsd-current/sys/uvm/uvm_pager.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.91 11-Aug-2023 mpi

Kill unused variable in uvm_aio_aiodone_pages().


# 1.90 13-May-2023 mpi

Put back in the simplification of the aiodone daemon.

Previous "breakage" of the swap on arm64 has been found to be an issue
on one machine the rockpro/arm64 related to a deadlock built into the
sdmmc(4) stack interacting with swapping code both running under
KERNEL_LOCK().

This issue is easily reproducible on -current and entering swap when
building LLVM on a rockpro crashes the machine by memory corruption.

Tested by mlarkin@ on octeon & i386, by myself on amd64 & arm64 and by
sthen@ on i386 port bulk.

ok beck@ some time ago.

Previous commit message:

Simplify the aiodone daemon which is only used for async writes.

- Remove unused support for asynchronous read, including error conditions

- Grab the proper lock for each page that has been written to swap. This
allows to enable an assertion in uvm_page_unbusy().

- Move the uvm_anon_release() call outside of uvm_page_unbusy() and
assert for the different anon cases.

ok beck@, kettenis@


Revision tags: OPENBSD_7_2_BASE OPENBSD_7_3_BASE
# 1.89 19-Aug-2022 mpi

Grab the mutex before iterating on the global list.

Prevent race reported some months ago.

ok mlarkin@, jsg@, kn@


# 1.88 15-Aug-2022 jsg

remove unused uvm_aiobuf_pool


# 1.87 07-Aug-2022 miod

Use PMAP_PREFER_ALIGN() == 0 rather than !defined(PMAP_PREFER) to enable the
fast path in the pager code; this benefits most mips64 platforms.

ok kettenis@ mpi@


# 1.86 02-Aug-2022 mpi

Bring back the direct map optimization when PMAP_PREFER isn't defined.

PMAP_PREFER is checked to prevent cache aliasing issues when the physical
page is mapped at different virtual addresses.

This speeds up file-based mmap faults.

ok kettenis@


# 1.85 24-Jul-2022 mpi

Revert simplification of the aiodone daemon it breaks swap on arm64.

Found the hard way by mlarkin@ and deraadt@.


# 1.84 17-Jul-2022 kettenis

Revert the changes made in rev 1.82. It is important to use pmap_enter(9)
and pmap_remove(9) here since we're dealing with managed pages here. Found
out the hard way by deraadt@ on landisk where we're running into issues
with virtual cache aliases because multiple mappings exist for the
pages we're dealing with here. The pmap_enter(9) and pmap_remove(9)
functions handle conflicting cache aliases, whereas pmap_map_direct(9) and
pmap_kenter_pa(9) assume that the pages is exclusively mapped in the kernel
pmap.

ok deraadt@


# 1.83 11-Jul-2022 mpi

Simplify the aiodone daemon which is only used for async writes.

- Remove unused support for asynchronous read, including error conditions

- Grab the proper lock for each page that has been written to swap. This
allows to enable an assertion in uvm_page_unbusy().

- Move the uvm_anon_release() call outside of uvm_page_unbusy() and
assert for the different anon cases.

ok beck@, kettenis@


# 1.82 30-Jun-2022 mpi

Reduce allocations and possible failures in uvm_pagermapin/out().

. If a direct map exists use it to map single-page allocations
. Use pmap_kenter_pa() instead of pmap_enter() in all other cases.

This speeds up file-based mmap up to 75% when I/O are performed and it
also reduces possible allocations failtures in the page daemon making
it more stable in OOM situations.

ok kettenis@, beck@


# 1.81 28-Jun-2022 mpi

Reserve a second segment for the page daemon.

This ensures uvm_swap_io() can succeeds even in OOM situations because two
uvm_pagermapin() allocations, requiring a segment each, are needed to bounce
or encrypt a swap cluster.

ok beck@, kettenis@


# 1.80 28-Jun-2022 mpi

Move the guts of uvm_aio_aiodone() into a separate function.

This will help dealing with error cases.

No functionnal changes.


# 1.79 28-Jun-2022 mpi

Do not clean PG_BUSY before calling uvm_anon_release().

Fix an assertion reported by gkoehler@.

ok kettenis@


Revision tags: OPENBSD_7_1_BASE
# 1.78 18-Feb-2022 kettenis

Convert KVA allocation to km_alloc(9).

ok mpi@


# 1.77 15-Dec-2021 mpi

Use a per-UVM object lock to serialize the lower part of the fault handler.

Like the per-amap lock the `vmobjlock' is principally used to serialized
access to objects in the fault handler to allow faults occurring on
different CPUs and different objects to be processed in parallel.

The fault handler now acquires the `vmobjlock' of a given UVM object as
soon as it finds one. For now a write-lock is always acquired even if
some operations could use a read-lock.

Every pager, corresponding to a different kind of UVM object, now expect
the UVM object to be locked and some operations, like *_get() return it
unlocked. This is enforced by assertions checking for rw_write_held().

The KERNEL_LOCK() is now pushed to the VFS boundary in the vnode pager.

To ensure the correct amap or object lock is held when modifying a page
many uvm_page* operations are now asserting for the "owner" lock.
However, fields of the "struct vm_page" are still being protected by the
global `pageqlock'. To prevent lock ordering issues with the new
`vmobjlock' and to reduce differences with NetBSD this lock is now taken
and released for each page instead of around the whole loop.

This commit does not remove the KERNEL_LOCK/UNLOCK() dance. Unlocking
will follow if there is no fallout.

Ported from NetBSD, tested by many, thanks!

ok kettenis@, kn@


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.76 26-Mar-2021 mpi

Remove parenthesis around return value to reduce the diff with NetBSD.

No functional change.

ok mlarkin@


# 1.75 12-Mar-2021 jsg

spelling

ok mpi@


# 1.74 19-Jan-2021 mpi

(re)Introduce locking for amaps & anons.

A rwlock is attached to every amap and is shared with all its anon. The
same lock will be used by multiple amaps if they have anons in common.

This should be enough to get the upper part of the fault handler out of the
KERNEL_LOCK() which seems to bring up to 20% improvements in builds.

This is based/copied/adapted from the most recent work done in NetBSD which
is an evolution of the precendent simple_lock scheme.

Tested by many, thanks!

ok kettenis@, mvs@


# 1.73 21-Oct-2020 mpi

Constify and use C99 initializer for "struct uvm_pagerops".

While here put some KERNEL_ASSERT_LOCKED() in the functions called from
the page fault handler. The removal of locking of `uobj' will need to be
revisited and these are good indicator that something is missing and that
many comments are lying.

ok kettenis


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.72 08-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok visa@, jca@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.71 17-Dec-2014 tedu

remove lock.h from uvm_extern.h. another holdover from the simpletonlock
era. fix uvm including c files to include lock.h or atomic.h as necessary.
ok deraadt


# 1.70 16-Nov-2014 deraadt

Replace a plethora of historical protection options with just
PROT_NONE, PROT_READ, PROT_WRITE, and PROT_EXEC from mman.h.
PROT_MASK is introduced as the one true way of extracting those bits.
Remove UVM_ADV_* wrapper, using the standard names.
ok doug guenther kettenis


# 1.69 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.68 11-Jul-2014 jsg

Chuck Cranor rescinded clauses in his license
on the 2nd of February 2011 in NetBSD.

http://marc.info/?l=netbsd-source-changes&m=129658899212732&w=2
http://marc.info/?l=netbsd-source-changes&m=129659095515558&w=2
http://marc.info/?l=netbsd-source-changes&m=129659157916514&w=2
http://marc.info/?l=netbsd-source-changes&m=129665962324372&w=2
http://marc.info/?l=netbsd-source-changes&m=129666033625342&w=2
http://marc.info/?l=netbsd-source-changes&m=129666052825545&w=2
http://marc.info/?l=netbsd-source-changes&m=129666922906480&w=2
http://marc.info/?l=netbsd-source-changes&m=129667725518082&w=2


# 1.67 09-May-2014 tedu

stop using B_AGE, it was effectively retired some time ago.


# 1.66 08-May-2014 kettenis

Fix some potential integer overflows caused by converting a page number into
an offset/size/address by shifting by PAGE_SHIFT. Make uvm_objwrire/unwire
use voff_t instead of off_t. The former is the right type here even if it is
equivalent to the latter.

Inspired by a somewhat similar changes in Bitrig.

ok deraadt@, guenther@


# 1.65 13-Apr-2014 tedu

compress code by turning four line comments into one line comments.
emphatic ok usual suspects, grudging ok miod


Revision tags: OPENBSD_5_5_BASE
# 1.64 02-Nov-2013 krw

No need to cast constants or simple variables to (daddr_t). Use
(u_int64_t) instead of (daddr_t) when casting a variable in an
expression passed to DL_SETDSIZE().

Change a variable counting open files from daddr_t to int64_t.

ok deraadt@ with the tweak to fix that pesky expression.


Revision tags: OPENBSD_5_4_BASE
# 1.63 11-Jun-2013 deraadt

final removal of daddr64_t. daddr_t has been 64 bit for a long enough
test period; i think 3 years ago the last bugs fell out.
ok otto beck others


# 1.62 30-May-2013 tedu

remove lots of comments about locking per beck's request


# 1.61 30-May-2013 tedu

remove simple_locks from uvm code. ok beck deraadt


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.60 03-Jul-2011 oga

Rip out and burn support for UVM_HIST.

The vm hackers don't use it, don't maintain it and have to look at it all the
time. About time this 800 lines of code hit /dev/null.

``never liked it'' tedu@. ariane@ was very happy when i told her i wrote
this diff.


# 1.59 15-Apr-2011 oga

for uvm_pager_dropcluster in the PG_RELEASED case we specifically unbusy the
page so that um_anfree will free it for us.

uvm_anfree does a pmap_page_protect(, VM_PROT_NONE) just before it frees the
page, so we don't need to do it here ourselves.

ok ariane@


# 1.58 15-Apr-2011 oga

move uvm_pageratop from uvm_pager.c local to a general uvm function
(uvm_atopg) and use it in uvm_km_doputpage to replace some handrolled
code. Shrinks the kernel a trivial amount.

ok beck@ and miod@ (who suggested i name it uvm_atopg not uvm_atop)


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.57 24-Jul-2010 kettenis

Don't sleep while holding the uvm_psel_lck mutex. Should fix "locking against
myself" panics that some people have seen over the last year-and-a-half.

Cherry picked from a more complex (and therefore scarier) diff from oga@.

ok tedu@, oga@


# 1.56 27-Jun-2010 oga

Kill another #ifdef UBC chunk that was annoying me while doing something
else.

ok thib@


Revision tags: OPENBSD_4_7_BASE
# 1.55 12-Feb-2010 tedu

introduce a uvm_km_valloc_try function that won't get a lower level lock
for use by the uvm pseg code. this is the path of least resistance until
we sort out how many of these functions we really need. problem found by mikeb
ok kettenis oga


# 1.54 22-Jul-2009 oga

Put the PG_RELEASED changes diff back in.

This has has been tested very very thoroughly on all archs we have
excepting 88k and 68k. Please see cvs log for the individual commit
messages.

ok beck@, thib@


Revision tags: OPENBSD_4_6_BASE
# 1.53 17-Jun-2009 oga

date based reversion of uvm to the 4th May.

More backouts in line with previous ones, this appears to bring us back to a
stable condition.

A machine forced to 64mb of ram cycled 10GB through swap with this diff
and is still running as I type this. Other tests by ariane@ and thib@
also seem to show that it's alright.

ok deraadt@, thib@, ariane@


# 1.52 16-Jun-2009 oga

Backout all the PG_RELEASED changes.

This is for the same reason as the earlier backouts, to avoid the bug
either added or exposed sometime around c2k9. This *should* be the last
one.

prompted by deraadt@

ok ariane@


# 1.51 23-May-2009 oga

More PG_RELEASED cleaning.

similar to the aobj.c changes, this one does vnodes. Vnodes are more
complex because they actaully have to sync to backing store. So firstly,
convert sync to sleep instead of setting released.

Now, for backing store, in the PGO_FREE case, if we set PG_RELEASED
*before* an async io, (nothing else will see it, the page is busy), then
we can ignore the page after the io is done. We could do something
similar for PGO_DEACTIVATE too, but that is another change. On error we
just clear the released flag, nothing else sets it for uobj pages other
than aiodoned.

ok thib@, beck@, ariane@


# 1.50 04-May-2009 oga

Instead of keeping two ints in the uvm structure specifically just to
sleep on them (and otherwise ignore them) sleep on the pointer to the
{aiodoned,pagedaemon}_proc members, and nuke the two extra words.

"no objections" art@, ok beck@.


# 1.49 06-Apr-2009 oga

Instead of doing splbio(); simple_lock(&uvm.aiodoned_lock); just replace
the simple lock with a real lock - a IPL_BIO mutex. While i'm here, make
the sleeping condition one hell of a lot simpler in the aio daemon.

some ideas from and ok art@.


# 1.48 25-Mar-2009 oga

Move all of the pseudo-inline functions in uvm into C files.

By pseudo-inline, I mean that if a certain macro was defined, they would
be inlined. However, no architecture defines that, and none has for a
very very long time. Therefore mainly this just makes the code a damned
sight easier to read. Some k&r -> ansi declarations while I'm in there.

"just commit it" art@. ok weingart@.


# 1.47 20-Mar-2009 oga

While working on some stuff in uvm I've gotten REALLY sick of reading
K&R function declarations, so switch them all over to ansi-style, in
accordance with the prophesy.

"go for it" art@


Revision tags: OPENBSD_4_5_BASE
# 1.46 27-Jan-2009 ariane

Simplify page-out/page-in map management; fix rare pager deadlock.

Ok: miod, tedu


# 1.45 24-Nov-2008 thib

garbage collect uvm_errno2vmerror();

ok miod@, art@


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.44 26-Nov-2007 miod

In uvm_aio_aiodone(), kill the variable-sized array on stack, and use a
fixed size array which size should match any buf; if a bogus buf is passed
to this function, the kernel will KASSERT instead of potentially running out
of stack and having an undefined behaviour.

ok deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.43 06-Jun-2007 deraadt

now that all partition size/offsets are potentially 64-bit, change the
type of all variables to daddr64_t. this includes the APIs for XXsize()
and XXdump(), all range checks inside bio drivers, internal variables
for disklabel handling, and even uvm's swap offsets. re-read numerous
times by otto, miod, krw, thib to look for errors


# 1.42 13-Apr-2007 art

While splitting flags and pqflags might have been a good idea in theory
to separate locking, on most modern machines this is not enough
since operations on short types touch other short types that share the
same word in memory.

Merge pg_flags and pqflags again and now use atomic operations to change
the flags. Also bump wire_count to an int and pg_version might go
int as well, just for alignment.

tested by many, many. ok miod@


# 1.41 04-Apr-2007 art

Mechanically rename the "flags" and "version" fields in struct vm_page
to "pg_flags" and "pg_version", so that they are a bit easier to work with.
Whoever uses generic names like this for a popular struct obviously doesn't
read much code.

Most architectures compile and there are no functionality changes.

deraadt@ ok ("if something fails to compile, we fix that by hand")


# 1.40 25-Mar-2007 art

remove KERN_SUCCESS and use 0 instead.
eyeballed by miod@ and pedro@


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.39 31-Jul-2006 mickey

fix uvmhist #2: args are always u_long so fix missing %d and %x and no %ll; no change for normal code


# 1.38 26-Jul-2006 mickey

fix fmts for UVMHIST_LOG() entries making it more useful on 64bit archs; miod@ ok


Revision tags: OPENBSD_3_8_BASE OPENBSD_3_9_BASE
# 1.37 26-Jul-2005 art

- Make a UVM_OBJ_IS_DEVICE macro.
- Use it to skip device mappings while dumping core.
- Ignore EFAULT errors while dumping core since they can happen
even for valid mappings. Just skip that part of the core file and
let it get automagically zero-filled.

This fixes the broken X core dumps that people have been seeing and also
fixes some other potential problems that could prevent core dumps (mmaps
beyond EOF, etc.).

tedu@ ok


# 1.36 24-May-2005 tedu

add a new field to vm_space and use it to track the number of anon
pages a process uses. this is now the userland "data size" value.
ok art deraadt tdeval. thanks testers.


Revision tags: OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE SMP_SYNC_A SMP_SYNC_B
# 1.35 23-Feb-2004 drahn

sync of pmap_update() calls with NetBSD. pmap_update is defined away on
all architectures but arm, where it is needed.


Revision tags: OPENBSD_3_4_BASE UBC_SYNC_A
# 1.34 29-Mar-2003 mickey

ubchist is not a fully cooked kadaver and though use the other well formed pdhist one until ubc gaets back. art@ ok


Revision tags: OPENBSD_3_3_BASE
# 1.33 29-Oct-2002 art

Since memory deallocation can't fail, remove the error return from
uvm_unmap, uvm_deallocate and a few other functions.
Simplifies some code and reduces diff to the UBC branch.


Revision tags: OPENBSD_3_2_BASE UBC_SYNC_B
# 1.32 24-May-2002 art

Make sure that b_iodone handlers are called at splbio (and splassert(IPL_BIO) in all known callers, just to make sure).


# 1.31 22-May-2002 art

splassert(IPL_BIO) in the b_iodone handlers.


Revision tags: OPENBSD_3_1_BASE
# 1.30 02-Jan-2002 miod

Back out a few more uvm changes, especially wrt swap usage.
This unbreaks m68k m88k sparc and perhaps others, which eventually froze
when hitting swap.
Tested by various people on various platforms.
ok art@


# 1.29 19-Dec-2001 art

UBC was a disaster. It worked very good when it worked, but on some
machines or some configurations or in some phase of the moon (we actually
don't know when or why) files disappeared. Since we've not been able to
track down the problem in two weeks intense debugging and we need -current
to be stable, back out everything to a state it had before UBC.

We apologise for the inconvenience.


Revision tags: UBC_BASE
# 1.28 04-Dec-2001 art

branches: 1.28.2;
Yet another sync to NetBSD uvm.
Today we add a pmap argument to pmap_update() and allocate map entries for
kernel_map from kmem_map instead of using the static entries. This should
get rid of MAX_KMAPENT panics. Also some uvm_loan problems are fixed.


# 1.27 30-Nov-2001 csapuntz

Call buf_cleanout, which handles wakeups


# 1.26 29-Nov-2001 art

Correctly handle b_vp with bgetvp and brelvp in {get,put}pages.
Prevents panics caused by vnodes being recycled under our feet.


# 1.25 28-Nov-2001 art

Sync in more uvm from NetBSD. Mostly just cosmetic stuff.
Contains also support for page coloring.


# 1.24 28-Nov-2001 art

Sync in more uvm changes from NetBSD.
This time we're getting rid of KERN_* and VM_PAGER_* error codes and
use errnos instead.


# 1.23 27-Nov-2001 art

Merge in the unified buffer cache code as found in NetBSD 2001/03/10. The
code is written mostly by Chuck Silvers <chuq@chuq.com>/<chs@netbsd.org>.

Tested for the past few weeks by many developers, should be in a pretty stable
state, but will require optimizations and additional cleanups.


# 1.22 12-Nov-2001 art

Bring in more changes from NetBSD. Mostly pagedaemon improvements.


# 1.21 10-Nov-2001 art

Merge in some parts of the ubc work that has been done in NetBSD that are not
UBC, but prerequsites for it.

- Create a daemon that processes async I/O (swap and paging in the future)
requests that need processing in process context and that were processed
in the pagedaemon before.
- Convert some ugly ifdef DIAGNOSTIC code to less intrusive KASSERTs.
- misc other cleanups.


# 1.20 07-Nov-2001 art

Another sync of uvm to NetBSD. Just minor fiddling, no major changes.


# 1.19 07-Nov-2001 art

Add an alignment argument to uvm_map that specifies an alignment hint
for the virtual address.


# 1.18 06-Nov-2001 art

Move the last content from vm/ to uvm/
The only thing left in vm/ are just dumb wrappers.
vm/vm.h includes uvm/uvm_extern.h
vm/pmap.h includes uvm/uvm_pmap.h
vm/vm_page.h includes uvm/uvm_page.h


# 1.17 05-Nov-2001 art

Minor sync to NetBSD.


Revision tags: OPENBSD_3_0_BASE
# 1.16 20-Sep-2001 mpech

occured->occurred

idea from deraadt@ via NetBSD
millert@ ok


# 1.15 19-Sep-2001 mickey

merge vm/vm_kern.h into uvm/uvm_extern.h; art@ ok


# 1.14 11-Aug-2001 art

Various random fixes from NetBSD.
Including support for zeroing pages in the idle loop (not enabled yet).


# 1.13 06-Aug-2001 art

Add a new type voff_t (right now it's typedefed as off_t) used for offsets
into objects.

Gives the possibilty to mmap beyond the size of vaddr_t.

From NetBSD.


# 1.12 26-Jul-2001 art

Add support for disabling swap devices (swapctl -d).
Improve error handling on I/O errors to swap.
From NetBSD


# 1.11 25-Jul-2001 art

Change the pmap_enter interface to merge access_type and the wired boolean
and arbitrary flags into one argument.

One new flag is PMAP_CANFAIL that tells pmap_enter that it can fail if there
are not enough resources to satisfy the request. If this flag is not passed,
pmap_enter should panic as it should have done before this change (XXX - many
pmaps are still not doing that).

Only i386 and alpha implement CANFAIL for now.

Includes uvm updates from NetBSD.


# 1.10 18-Jul-2001 art

Get rid of the PMAP_NEW option by making it mandatory for all archs.
The archs that didn't have a proper PMAP_NEW now have a dummy implementation
with wrappers around the old functions.


# 1.9 08-Jun-2001 art

Change the paddr_t pmap_extract(struct pmap *, vaddr_t) interface to
boolean_t pmap_extract(struct pmap *, vaddr_t, paddr_t *).
Matches NetBSD. Tested by various people on various platforms.


Revision tags: OPENBSD_2_9_BASE
# 1.8 22-Mar-2001 smart

Sync style, typo, and comments a little closer to NetBSD. art@ ok


# 1.7 08-Mar-2001 smart

Replace thread_wakeup() with wakeup(). It is defined in vm_extern.h as a
wrapper, so this removes a dependence on the old VM system. From NetBSD.
art@ ok


# 1.6 29-Jan-2001 niklas

$OpenBSD$


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE
# 1.5 16-Mar-2000 art

Bring in some new UVM code from NetBSD (not current).

- Introduce a new type of map that are interrupt safe and never allow faults
in them. mb_map and kmem_map are made intrsafe.
- Add "access protection" to uvm_vslock (to be passed down to uvm_fault and
later to pmap_enter).
- madvise(2) now works.
- various cleanups.


Revision tags: OPENBSD_2_6_BASE SMP_BASE kame_19991208
# 1.4 03-Sep-1999 art

branches: 1.4.4;
Change the pmap_enter api to pass down an argument that indicates
the access type that caused this mapping. This is to simplify pmaps
with mod/ref emulation (none for the moment) and in some cases speed
up pmap_is_{referenced,modified}.
At the same time, clean up some mappings that had too high protection.

XXX - the access type is incorrect in old vm, it's only used by uvm and MD code.
The actual use of this in pmap_enter implementations is not in this commit.


# 1.3 23-Aug-1999 art

sync with NetBSD from 1999.05.24 (there is a reason for this date)
Mostly cleanups, but also a few improvements to pagedaemon for better
handling of low memory and/or low swap conditions.


Revision tags: OPENBSD_2_5_BASE
# 1.2 26-Feb-1999 art

add OpenBSD tags


# 1.1 26-Feb-1999 art

Import of uvm from NetBSD. Some local changes, some code disabled


# 1.90 13-May-2023 mpi

Put back in the simplification of the aiodone daemon.

Previous "breakage" of the swap on arm64 has been found to be an issue
on one machine the rockpro/arm64 related to a deadlock built into the
sdmmc(4) stack interacting with swapping code both running under
KERNEL_LOCK().

This issue is easily reproducible on -current and entering swap when
building LLVM on a rockpro crashes the machine by memory corruption.

Tested by mlarkin@ on octeon & i386, by myself on amd64 & arm64 and by
sthen@ on i386 port bulk.

ok beck@ some time ago.

Previous commit message:

Simplify the aiodone daemon which is only used for async writes.

- Remove unused support for asynchronous read, including error conditions

- Grab the proper lock for each page that has been written to swap. This
allows to enable an assertion in uvm_page_unbusy().

- Move the uvm_anon_release() call outside of uvm_page_unbusy() and
assert for the different anon cases.

ok beck@, kettenis@


Revision tags: OPENBSD_7_2_BASE OPENBSD_7_3_BASE
# 1.89 19-Aug-2022 mpi

Grab the mutex before iterating on the global list.

Prevent race reported some months ago.

ok mlarkin@, jsg@, kn@


# 1.88 15-Aug-2022 jsg

remove unused uvm_aiobuf_pool


# 1.87 07-Aug-2022 miod

Use PMAP_PREFER_ALIGN() == 0 rather than !defined(PMAP_PREFER) to enable the
fast path in the pager code; this benefits most mips64 platforms.

ok kettenis@ mpi@


# 1.86 02-Aug-2022 mpi

Bring back the direct map optimization when PMAP_PREFER isn't defined.

PMAP_PREFER is checked to prevent cache aliasing issues when the physical
page is mapped at different virtual addresses.

This speeds up file-based mmap faults.

ok kettenis@


# 1.85 24-Jul-2022 mpi

Revert simplification of the aiodone daemon it breaks swap on arm64.

Found the hard way by mlarkin@ and deraadt@.


# 1.84 17-Jul-2022 kettenis

Revert the changes made in rev 1.82. It is important to use pmap_enter(9)
and pmap_remove(9) here since we're dealing with managed pages here. Found
out the hard way by deraadt@ on landisk where we're running into issues
with virtual cache aliases because multiple mappings exist for the
pages we're dealing with here. The pmap_enter(9) and pmap_remove(9)
functions handle conflicting cache aliases, whereas pmap_map_direct(9) and
pmap_kenter_pa(9) assume that the pages is exclusively mapped in the kernel
pmap.

ok deraadt@


# 1.83 11-Jul-2022 mpi

Simplify the aiodone daemon which is only used for async writes.

- Remove unused support for asynchronous read, including error conditions

- Grab the proper lock for each page that has been written to swap. This
allows to enable an assertion in uvm_page_unbusy().

- Move the uvm_anon_release() call outside of uvm_page_unbusy() and
assert for the different anon cases.

ok beck@, kettenis@


# 1.82 30-Jun-2022 mpi

Reduce allocations and possible failures in uvm_pagermapin/out().

. If a direct map exists use it to map single-page allocations
. Use pmap_kenter_pa() instead of pmap_enter() in all other cases.

This speeds up file-based mmap up to 75% when I/O are performed and it
also reduces possible allocations failtures in the page daemon making
it more stable in OOM situations.

ok kettenis@, beck@


# 1.81 28-Jun-2022 mpi

Reserve a second segment for the page daemon.

This ensures uvm_swap_io() can succeeds even in OOM situations because two
uvm_pagermapin() allocations, requiring a segment each, are needed to bounce
or encrypt a swap cluster.

ok beck@, kettenis@


# 1.80 28-Jun-2022 mpi

Move the guts of uvm_aio_aiodone() into a separate function.

This will help dealing with error cases.

No functionnal changes.


# 1.79 28-Jun-2022 mpi

Do not clean PG_BUSY before calling uvm_anon_release().

Fix an assertion reported by gkoehler@.

ok kettenis@


Revision tags: OPENBSD_7_1_BASE
# 1.78 18-Feb-2022 kettenis

Convert KVA allocation to km_alloc(9).

ok mpi@


# 1.77 15-Dec-2021 mpi

Use a per-UVM object lock to serialize the lower part of the fault handler.

Like the per-amap lock the `vmobjlock' is principally used to serialized
access to objects in the fault handler to allow faults occurring on
different CPUs and different objects to be processed in parallel.

The fault handler now acquires the `vmobjlock' of a given UVM object as
soon as it finds one. For now a write-lock is always acquired even if
some operations could use a read-lock.

Every pager, corresponding to a different kind of UVM object, now expect
the UVM object to be locked and some operations, like *_get() return it
unlocked. This is enforced by assertions checking for rw_write_held().

The KERNEL_LOCK() is now pushed to the VFS boundary in the vnode pager.

To ensure the correct amap or object lock is held when modifying a page
many uvm_page* operations are now asserting for the "owner" lock.
However, fields of the "struct vm_page" are still being protected by the
global `pageqlock'. To prevent lock ordering issues with the new
`vmobjlock' and to reduce differences with NetBSD this lock is now taken
and released for each page instead of around the whole loop.

This commit does not remove the KERNEL_LOCK/UNLOCK() dance. Unlocking
will follow if there is no fallout.

Ported from NetBSD, tested by many, thanks!

ok kettenis@, kn@


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.76 26-Mar-2021 mpi

Remove parenthesis around return value to reduce the diff with NetBSD.

No functional change.

ok mlarkin@


# 1.75 12-Mar-2021 jsg

spelling

ok mpi@


# 1.74 19-Jan-2021 mpi

(re)Introduce locking for amaps & anons.

A rwlock is attached to every amap and is shared with all its anon. The
same lock will be used by multiple amaps if they have anons in common.

This should be enough to get the upper part of the fault handler out of the
KERNEL_LOCK() which seems to bring up to 20% improvements in builds.

This is based/copied/adapted from the most recent work done in NetBSD which
is an evolution of the precendent simple_lock scheme.

Tested by many, thanks!

ok kettenis@, mvs@


# 1.73 21-Oct-2020 mpi

Constify and use C99 initializer for "struct uvm_pagerops".

While here put some KERNEL_ASSERT_LOCKED() in the functions called from
the page fault handler. The removal of locking of `uobj' will need to be
revisited and these are good indicator that something is missing and that
many comments are lying.

ok kettenis


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.72 08-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok visa@, jca@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.71 17-Dec-2014 tedu

remove lock.h from uvm_extern.h. another holdover from the simpletonlock
era. fix uvm including c files to include lock.h or atomic.h as necessary.
ok deraadt


# 1.70 16-Nov-2014 deraadt

Replace a plethora of historical protection options with just
PROT_NONE, PROT_READ, PROT_WRITE, and PROT_EXEC from mman.h.
PROT_MASK is introduced as the one true way of extracting those bits.
Remove UVM_ADV_* wrapper, using the standard names.
ok doug guenther kettenis


# 1.69 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.68 11-Jul-2014 jsg

Chuck Cranor rescinded clauses in his license
on the 2nd of February 2011 in NetBSD.

http://marc.info/?l=netbsd-source-changes&m=129658899212732&w=2
http://marc.info/?l=netbsd-source-changes&m=129659095515558&w=2
http://marc.info/?l=netbsd-source-changes&m=129659157916514&w=2
http://marc.info/?l=netbsd-source-changes&m=129665962324372&w=2
http://marc.info/?l=netbsd-source-changes&m=129666033625342&w=2
http://marc.info/?l=netbsd-source-changes&m=129666052825545&w=2
http://marc.info/?l=netbsd-source-changes&m=129666922906480&w=2
http://marc.info/?l=netbsd-source-changes&m=129667725518082&w=2


# 1.67 09-May-2014 tedu

stop using B_AGE, it was effectively retired some time ago.


# 1.66 08-May-2014 kettenis

Fix some potential integer overflows caused by converting a page number into
an offset/size/address by shifting by PAGE_SHIFT. Make uvm_objwrire/unwire
use voff_t instead of off_t. The former is the right type here even if it is
equivalent to the latter.

Inspired by a somewhat similar changes in Bitrig.

ok deraadt@, guenther@


# 1.65 13-Apr-2014 tedu

compress code by turning four line comments into one line comments.
emphatic ok usual suspects, grudging ok miod


Revision tags: OPENBSD_5_5_BASE
# 1.64 02-Nov-2013 krw

No need to cast constants or simple variables to (daddr_t). Use
(u_int64_t) instead of (daddr_t) when casting a variable in an
expression passed to DL_SETDSIZE().

Change a variable counting open files from daddr_t to int64_t.

ok deraadt@ with the tweak to fix that pesky expression.


Revision tags: OPENBSD_5_4_BASE
# 1.63 11-Jun-2013 deraadt

final removal of daddr64_t. daddr_t has been 64 bit for a long enough
test period; i think 3 years ago the last bugs fell out.
ok otto beck others


# 1.62 30-May-2013 tedu

remove lots of comments about locking per beck's request


# 1.61 30-May-2013 tedu

remove simple_locks from uvm code. ok beck deraadt


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.60 03-Jul-2011 oga

Rip out and burn support for UVM_HIST.

The vm hackers don't use it, don't maintain it and have to look at it all the
time. About time this 800 lines of code hit /dev/null.

``never liked it'' tedu@. ariane@ was very happy when i told her i wrote
this diff.


# 1.59 15-Apr-2011 oga

for uvm_pager_dropcluster in the PG_RELEASED case we specifically unbusy the
page so that um_anfree will free it for us.

uvm_anfree does a pmap_page_protect(, VM_PROT_NONE) just before it frees the
page, so we don't need to do it here ourselves.

ok ariane@


# 1.58 15-Apr-2011 oga

move uvm_pageratop from uvm_pager.c local to a general uvm function
(uvm_atopg) and use it in uvm_km_doputpage to replace some handrolled
code. Shrinks the kernel a trivial amount.

ok beck@ and miod@ (who suggested i name it uvm_atopg not uvm_atop)


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.57 24-Jul-2010 kettenis

Don't sleep while holding the uvm_psel_lck mutex. Should fix "locking against
myself" panics that some people have seen over the last year-and-a-half.

Cherry picked from a more complex (and therefore scarier) diff from oga@.

ok tedu@, oga@


# 1.56 27-Jun-2010 oga

Kill another #ifdef UBC chunk that was annoying me while doing something
else.

ok thib@


Revision tags: OPENBSD_4_7_BASE
# 1.55 12-Feb-2010 tedu

introduce a uvm_km_valloc_try function that won't get a lower level lock
for use by the uvm pseg code. this is the path of least resistance until
we sort out how many of these functions we really need. problem found by mikeb
ok kettenis oga


# 1.54 22-Jul-2009 oga

Put the PG_RELEASED changes diff back in.

This has has been tested very very thoroughly on all archs we have
excepting 88k and 68k. Please see cvs log for the individual commit
messages.

ok beck@, thib@


Revision tags: OPENBSD_4_6_BASE
# 1.53 17-Jun-2009 oga

date based reversion of uvm to the 4th May.

More backouts in line with previous ones, this appears to bring us back to a
stable condition.

A machine forced to 64mb of ram cycled 10GB through swap with this diff
and is still running as I type this. Other tests by ariane@ and thib@
also seem to show that it's alright.

ok deraadt@, thib@, ariane@


# 1.52 16-Jun-2009 oga

Backout all the PG_RELEASED changes.

This is for the same reason as the earlier backouts, to avoid the bug
either added or exposed sometime around c2k9. This *should* be the last
one.

prompted by deraadt@

ok ariane@


# 1.51 23-May-2009 oga

More PG_RELEASED cleaning.

similar to the aobj.c changes, this one does vnodes. Vnodes are more
complex because they actaully have to sync to backing store. So firstly,
convert sync to sleep instead of setting released.

Now, for backing store, in the PGO_FREE case, if we set PG_RELEASED
*before* an async io, (nothing else will see it, the page is busy), then
we can ignore the page after the io is done. We could do something
similar for PGO_DEACTIVATE too, but that is another change. On error we
just clear the released flag, nothing else sets it for uobj pages other
than aiodoned.

ok thib@, beck@, ariane@


# 1.50 04-May-2009 oga

Instead of keeping two ints in the uvm structure specifically just to
sleep on them (and otherwise ignore them) sleep on the pointer to the
{aiodoned,pagedaemon}_proc members, and nuke the two extra words.

"no objections" art@, ok beck@.


# 1.49 06-Apr-2009 oga

Instead of doing splbio(); simple_lock(&uvm.aiodoned_lock); just replace
the simple lock with a real lock - a IPL_BIO mutex. While i'm here, make
the sleeping condition one hell of a lot simpler in the aio daemon.

some ideas from and ok art@.


# 1.48 25-Mar-2009 oga

Move all of the pseudo-inline functions in uvm into C files.

By pseudo-inline, I mean that if a certain macro was defined, they would
be inlined. However, no architecture defines that, and none has for a
very very long time. Therefore mainly this just makes the code a damned
sight easier to read. Some k&r -> ansi declarations while I'm in there.

"just commit it" art@. ok weingart@.


# 1.47 20-Mar-2009 oga

While working on some stuff in uvm I've gotten REALLY sick of reading
K&R function declarations, so switch them all over to ansi-style, in
accordance with the prophesy.

"go for it" art@


Revision tags: OPENBSD_4_5_BASE
# 1.46 27-Jan-2009 ariane

Simplify page-out/page-in map management; fix rare pager deadlock.

Ok: miod, tedu


# 1.45 24-Nov-2008 thib

garbage collect uvm_errno2vmerror();

ok miod@, art@


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.44 26-Nov-2007 miod

In uvm_aio_aiodone(), kill the variable-sized array on stack, and use a
fixed size array which size should match any buf; if a bogus buf is passed
to this function, the kernel will KASSERT instead of potentially running out
of stack and having an undefined behaviour.

ok deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.43 06-Jun-2007 deraadt

now that all partition size/offsets are potentially 64-bit, change the
type of all variables to daddr64_t. this includes the APIs for XXsize()
and XXdump(), all range checks inside bio drivers, internal variables
for disklabel handling, and even uvm's swap offsets. re-read numerous
times by otto, miod, krw, thib to look for errors


# 1.42 13-Apr-2007 art

While splitting flags and pqflags might have been a good idea in theory
to separate locking, on most modern machines this is not enough
since operations on short types touch other short types that share the
same word in memory.

Merge pg_flags and pqflags again and now use atomic operations to change
the flags. Also bump wire_count to an int and pg_version might go
int as well, just for alignment.

tested by many, many. ok miod@


# 1.41 04-Apr-2007 art

Mechanically rename the "flags" and "version" fields in struct vm_page
to "pg_flags" and "pg_version", so that they are a bit easier to work with.
Whoever uses generic names like this for a popular struct obviously doesn't
read much code.

Most architectures compile and there are no functionality changes.

deraadt@ ok ("if something fails to compile, we fix that by hand")


# 1.40 25-Mar-2007 art

remove KERN_SUCCESS and use 0 instead.
eyeballed by miod@ and pedro@


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.39 31-Jul-2006 mickey

fix uvmhist #2: args are always u_long so fix missing %d and %x and no %ll; no change for normal code


# 1.38 26-Jul-2006 mickey

fix fmts for UVMHIST_LOG() entries making it more useful on 64bit archs; miod@ ok


Revision tags: OPENBSD_3_8_BASE OPENBSD_3_9_BASE
# 1.37 26-Jul-2005 art

- Make a UVM_OBJ_IS_DEVICE macro.
- Use it to skip device mappings while dumping core.
- Ignore EFAULT errors while dumping core since they can happen
even for valid mappings. Just skip that part of the core file and
let it get automagically zero-filled.

This fixes the broken X core dumps that people have been seeing and also
fixes some other potential problems that could prevent core dumps (mmaps
beyond EOF, etc.).

tedu@ ok


# 1.36 24-May-2005 tedu

add a new field to vm_space and use it to track the number of anon
pages a process uses. this is now the userland "data size" value.
ok art deraadt tdeval. thanks testers.


Revision tags: OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE SMP_SYNC_A SMP_SYNC_B
# 1.35 23-Feb-2004 drahn

sync of pmap_update() calls with NetBSD. pmap_update is defined away on
all architectures but arm, where it is needed.


Revision tags: OPENBSD_3_4_BASE UBC_SYNC_A
# 1.34 29-Mar-2003 mickey

ubchist is not a fully cooked kadaver and though use the other well formed pdhist one until ubc gaets back. art@ ok


Revision tags: OPENBSD_3_3_BASE
# 1.33 29-Oct-2002 art

Since memory deallocation can't fail, remove the error return from
uvm_unmap, uvm_deallocate and a few other functions.
Simplifies some code and reduces diff to the UBC branch.


Revision tags: OPENBSD_3_2_BASE UBC_SYNC_B
# 1.32 24-May-2002 art

Make sure that b_iodone handlers are called at splbio (and splassert(IPL_BIO) in all known callers, just to make sure).


# 1.31 22-May-2002 art

splassert(IPL_BIO) in the b_iodone handlers.


Revision tags: OPENBSD_3_1_BASE
# 1.30 02-Jan-2002 miod

Back out a few more uvm changes, especially wrt swap usage.
This unbreaks m68k m88k sparc and perhaps others, which eventually froze
when hitting swap.
Tested by various people on various platforms.
ok art@


# 1.29 19-Dec-2001 art

UBC was a disaster. It worked very good when it worked, but on some
machines or some configurations or in some phase of the moon (we actually
don't know when or why) files disappeared. Since we've not been able to
track down the problem in two weeks intense debugging and we need -current
to be stable, back out everything to a state it had before UBC.

We apologise for the inconvenience.


Revision tags: UBC_BASE
# 1.28 04-Dec-2001 art

branches: 1.28.2;
Yet another sync to NetBSD uvm.
Today we add a pmap argument to pmap_update() and allocate map entries for
kernel_map from kmem_map instead of using the static entries. This should
get rid of MAX_KMAPENT panics. Also some uvm_loan problems are fixed.


# 1.27 30-Nov-2001 csapuntz

Call buf_cleanout, which handles wakeups


# 1.26 29-Nov-2001 art

Correctly handle b_vp with bgetvp and brelvp in {get,put}pages.
Prevents panics caused by vnodes being recycled under our feet.


# 1.25 28-Nov-2001 art

Sync in more uvm from NetBSD. Mostly just cosmetic stuff.
Contains also support for page coloring.


# 1.24 28-Nov-2001 art

Sync in more uvm changes from NetBSD.
This time we're getting rid of KERN_* and VM_PAGER_* error codes and
use errnos instead.


# 1.23 27-Nov-2001 art

Merge in the unified buffer cache code as found in NetBSD 2001/03/10. The
code is written mostly by Chuck Silvers <chuq@chuq.com>/<chs@netbsd.org>.

Tested for the past few weeks by many developers, should be in a pretty stable
state, but will require optimizations and additional cleanups.


# 1.22 12-Nov-2001 art

Bring in more changes from NetBSD. Mostly pagedaemon improvements.


# 1.21 10-Nov-2001 art

Merge in some parts of the ubc work that has been done in NetBSD that are not
UBC, but prerequsites for it.

- Create a daemon that processes async I/O (swap and paging in the future)
requests that need processing in process context and that were processed
in the pagedaemon before.
- Convert some ugly ifdef DIAGNOSTIC code to less intrusive KASSERTs.
- misc other cleanups.


# 1.20 07-Nov-2001 art

Another sync of uvm to NetBSD. Just minor fiddling, no major changes.


# 1.19 07-Nov-2001 art

Add an alignment argument to uvm_map that specifies an alignment hint
for the virtual address.


# 1.18 06-Nov-2001 art

Move the last content from vm/ to uvm/
The only thing left in vm/ are just dumb wrappers.
vm/vm.h includes uvm/uvm_extern.h
vm/pmap.h includes uvm/uvm_pmap.h
vm/vm_page.h includes uvm/uvm_page.h


# 1.17 05-Nov-2001 art

Minor sync to NetBSD.


Revision tags: OPENBSD_3_0_BASE
# 1.16 20-Sep-2001 mpech

occured->occurred

idea from deraadt@ via NetBSD
millert@ ok


# 1.15 19-Sep-2001 mickey

merge vm/vm_kern.h into uvm/uvm_extern.h; art@ ok


# 1.14 11-Aug-2001 art

Various random fixes from NetBSD.
Including support for zeroing pages in the idle loop (not enabled yet).


# 1.13 06-Aug-2001 art

Add a new type voff_t (right now it's typedefed as off_t) used for offsets
into objects.

Gives the possibilty to mmap beyond the size of vaddr_t.

From NetBSD.


# 1.12 26-Jul-2001 art

Add support for disabling swap devices (swapctl -d).
Improve error handling on I/O errors to swap.
From NetBSD


# 1.11 25-Jul-2001 art

Change the pmap_enter interface to merge access_type and the wired boolean
and arbitrary flags into one argument.

One new flag is PMAP_CANFAIL that tells pmap_enter that it can fail if there
are not enough resources to satisfy the request. If this flag is not passed,
pmap_enter should panic as it should have done before this change (XXX - many
pmaps are still not doing that).

Only i386 and alpha implement CANFAIL for now.

Includes uvm updates from NetBSD.


# 1.10 18-Jul-2001 art

Get rid of the PMAP_NEW option by making it mandatory for all archs.
The archs that didn't have a proper PMAP_NEW now have a dummy implementation
with wrappers around the old functions.


# 1.9 08-Jun-2001 art

Change the paddr_t pmap_extract(struct pmap *, vaddr_t) interface to
boolean_t pmap_extract(struct pmap *, vaddr_t, paddr_t *).
Matches NetBSD. Tested by various people on various platforms.


Revision tags: OPENBSD_2_9_BASE
# 1.8 22-Mar-2001 smart

Sync style, typo, and comments a little closer to NetBSD. art@ ok


# 1.7 08-Mar-2001 smart

Replace thread_wakeup() with wakeup(). It is defined in vm_extern.h as a
wrapper, so this removes a dependence on the old VM system. From NetBSD.
art@ ok


# 1.6 29-Jan-2001 niklas

$OpenBSD$


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE
# 1.5 16-Mar-2000 art

Bring in some new UVM code from NetBSD (not current).

- Introduce a new type of map that are interrupt safe and never allow faults
in them. mb_map and kmem_map are made intrsafe.
- Add "access protection" to uvm_vslock (to be passed down to uvm_fault and
later to pmap_enter).
- madvise(2) now works.
- various cleanups.


Revision tags: OPENBSD_2_6_BASE SMP_BASE kame_19991208
# 1.4 03-Sep-1999 art

branches: 1.4.4;
Change the pmap_enter api to pass down an argument that indicates
the access type that caused this mapping. This is to simplify pmaps
with mod/ref emulation (none for the moment) and in some cases speed
up pmap_is_{referenced,modified}.
At the same time, clean up some mappings that had too high protection.

XXX - the access type is incorrect in old vm, it's only used by uvm and MD code.
The actual use of this in pmap_enter implementations is not in this commit.


# 1.3 23-Aug-1999 art

sync with NetBSD from 1999.05.24 (there is a reason for this date)
Mostly cleanups, but also a few improvements to pagedaemon for better
handling of low memory and/or low swap conditions.


Revision tags: OPENBSD_2_5_BASE
# 1.2 26-Feb-1999 art

add OpenBSD tags


# 1.1 26-Feb-1999 art

Import of uvm from NetBSD. Some local changes, some code disabled


# 1.89 19-Aug-2022 mpi

Grab the mutex before iterating on the global list.

Prevent race reported some months ago.

ok mlarkin@, jsg@, kn@


# 1.88 15-Aug-2022 jsg

remove unused uvm_aiobuf_pool


# 1.87 07-Aug-2022 miod

Use PMAP_PREFER_ALIGN() == 0 rather than !defined(PMAP_PREFER) to enable the
fast path in the pager code; this benefits most mips64 platforms.

ok kettenis@ mpi@


# 1.86 02-Aug-2022 mpi

Bring back the direct map optimization when PMAP_PREFER isn't defined.

PMAP_PREFER is checked to prevent cache aliasing issues when the physical
page is mapped at different virtual addresses.

This speeds up file-based mmap faults.

ok kettenis@


# 1.85 24-Jul-2022 mpi

Revert simplification of the aiodone daemon it breaks swap on arm64.

Found the hard way by mlarkin@ and deraadt@.


# 1.84 17-Jul-2022 kettenis

Revert the changes made in rev 1.82. It is important to use pmap_enter(9)
and pmap_remove(9) here since we're dealing with managed pages here. Found
out the hard way by deraadt@ on landisk where we're running into issues
with virtual cache aliases because multiple mappings exist for the
pages we're dealing with here. The pmap_enter(9) and pmap_remove(9)
functions handle conflicting cache aliases, whereas pmap_map_direct(9) and
pmap_kenter_pa(9) assume that the pages is exclusively mapped in the kernel
pmap.

ok deraadt@


# 1.83 11-Jul-2022 mpi

Simplify the aiodone daemon which is only used for async writes.

- Remove unused support for asynchronous read, including error conditions

- Grab the proper lock for each page that has been written to swap. This
allows to enable an assertion in uvm_page_unbusy().

- Move the uvm_anon_release() call outside of uvm_page_unbusy() and
assert for the different anon cases.

ok beck@, kettenis@


# 1.82 30-Jun-2022 mpi

Reduce allocations and possible failures in uvm_pagermapin/out().

. If a direct map exists use it to map single-page allocations
. Use pmap_kenter_pa() instead of pmap_enter() in all other cases.

This speeds up file-based mmap up to 75% when I/O are performed and it
also reduces possible allocations failtures in the page daemon making
it more stable in OOM situations.

ok kettenis@, beck@


# 1.81 28-Jun-2022 mpi

Reserve a second segment for the page daemon.

This ensures uvm_swap_io() can succeeds even in OOM situations because two
uvm_pagermapin() allocations, requiring a segment each, are needed to bounce
or encrypt a swap cluster.

ok beck@, kettenis@


# 1.80 28-Jun-2022 mpi

Move the guts of uvm_aio_aiodone() into a separate function.

This will help dealing with error cases.

No functionnal changes.


# 1.79 28-Jun-2022 mpi

Do not clean PG_BUSY before calling uvm_anon_release().

Fix an assertion reported by gkoehler@.

ok kettenis@


Revision tags: OPENBSD_7_1_BASE
# 1.78 18-Feb-2022 kettenis

Convert KVA allocation to km_alloc(9).

ok mpi@


# 1.77 15-Dec-2021 mpi

Use a per-UVM object lock to serialize the lower part of the fault handler.

Like the per-amap lock the `vmobjlock' is principally used to serialized
access to objects in the fault handler to allow faults occurring on
different CPUs and different objects to be processed in parallel.

The fault handler now acquires the `vmobjlock' of a given UVM object as
soon as it finds one. For now a write-lock is always acquired even if
some operations could use a read-lock.

Every pager, corresponding to a different kind of UVM object, now expect
the UVM object to be locked and some operations, like *_get() return it
unlocked. This is enforced by assertions checking for rw_write_held().

The KERNEL_LOCK() is now pushed to the VFS boundary in the vnode pager.

To ensure the correct amap or object lock is held when modifying a page
many uvm_page* operations are now asserting for the "owner" lock.
However, fields of the "struct vm_page" are still being protected by the
global `pageqlock'. To prevent lock ordering issues with the new
`vmobjlock' and to reduce differences with NetBSD this lock is now taken
and released for each page instead of around the whole loop.

This commit does not remove the KERNEL_LOCK/UNLOCK() dance. Unlocking
will follow if there is no fallout.

Ported from NetBSD, tested by many, thanks!

ok kettenis@, kn@


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.76 26-Mar-2021 mpi

Remove parenthesis around return value to reduce the diff with NetBSD.

No functional change.

ok mlarkin@


# 1.75 12-Mar-2021 jsg

spelling

ok mpi@


# 1.74 19-Jan-2021 mpi

(re)Introduce locking for amaps & anons.

A rwlock is attached to every amap and is shared with all its anon. The
same lock will be used by multiple amaps if they have anons in common.

This should be enough to get the upper part of the fault handler out of the
KERNEL_LOCK() which seems to bring up to 20% improvements in builds.

This is based/copied/adapted from the most recent work done in NetBSD which
is an evolution of the precendent simple_lock scheme.

Tested by many, thanks!

ok kettenis@, mvs@


# 1.73 21-Oct-2020 mpi

Constify and use C99 initializer for "struct uvm_pagerops".

While here put some KERNEL_ASSERT_LOCKED() in the functions called from
the page fault handler. The removal of locking of `uobj' will need to be
revisited and these are good indicator that something is missing and that
many comments are lying.

ok kettenis


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.72 08-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok visa@, jca@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.71 17-Dec-2014 tedu

remove lock.h from uvm_extern.h. another holdover from the simpletonlock
era. fix uvm including c files to include lock.h or atomic.h as necessary.
ok deraadt


# 1.70 16-Nov-2014 deraadt

Replace a plethora of historical protection options with just
PROT_NONE, PROT_READ, PROT_WRITE, and PROT_EXEC from mman.h.
PROT_MASK is introduced as the one true way of extracting those bits.
Remove UVM_ADV_* wrapper, using the standard names.
ok doug guenther kettenis


# 1.69 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.68 11-Jul-2014 jsg

Chuck Cranor rescinded clauses in his license
on the 2nd of February 2011 in NetBSD.

http://marc.info/?l=netbsd-source-changes&m=129658899212732&w=2
http://marc.info/?l=netbsd-source-changes&m=129659095515558&w=2
http://marc.info/?l=netbsd-source-changes&m=129659157916514&w=2
http://marc.info/?l=netbsd-source-changes&m=129665962324372&w=2
http://marc.info/?l=netbsd-source-changes&m=129666033625342&w=2
http://marc.info/?l=netbsd-source-changes&m=129666052825545&w=2
http://marc.info/?l=netbsd-source-changes&m=129666922906480&w=2
http://marc.info/?l=netbsd-source-changes&m=129667725518082&w=2


# 1.67 09-May-2014 tedu

stop using B_AGE, it was effectively retired some time ago.


# 1.66 08-May-2014 kettenis

Fix some potential integer overflows caused by converting a page number into
an offset/size/address by shifting by PAGE_SHIFT. Make uvm_objwrire/unwire
use voff_t instead of off_t. The former is the right type here even if it is
equivalent to the latter.

Inspired by a somewhat similar changes in Bitrig.

ok deraadt@, guenther@


# 1.65 13-Apr-2014 tedu

compress code by turning four line comments into one line comments.
emphatic ok usual suspects, grudging ok miod


Revision tags: OPENBSD_5_5_BASE
# 1.64 02-Nov-2013 krw

No need to cast constants or simple variables to (daddr_t). Use
(u_int64_t) instead of (daddr_t) when casting a variable in an
expression passed to DL_SETDSIZE().

Change a variable counting open files from daddr_t to int64_t.

ok deraadt@ with the tweak to fix that pesky expression.


Revision tags: OPENBSD_5_4_BASE
# 1.63 11-Jun-2013 deraadt

final removal of daddr64_t. daddr_t has been 64 bit for a long enough
test period; i think 3 years ago the last bugs fell out.
ok otto beck others


# 1.62 30-May-2013 tedu

remove lots of comments about locking per beck's request


# 1.61 30-May-2013 tedu

remove simple_locks from uvm code. ok beck deraadt


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.60 03-Jul-2011 oga

Rip out and burn support for UVM_HIST.

The vm hackers don't use it, don't maintain it and have to look at it all the
time. About time this 800 lines of code hit /dev/null.

``never liked it'' tedu@. ariane@ was very happy when i told her i wrote
this diff.


# 1.59 15-Apr-2011 oga

for uvm_pager_dropcluster in the PG_RELEASED case we specifically unbusy the
page so that um_anfree will free it for us.

uvm_anfree does a pmap_page_protect(, VM_PROT_NONE) just before it frees the
page, so we don't need to do it here ourselves.

ok ariane@


# 1.58 15-Apr-2011 oga

move uvm_pageratop from uvm_pager.c local to a general uvm function
(uvm_atopg) and use it in uvm_km_doputpage to replace some handrolled
code. Shrinks the kernel a trivial amount.

ok beck@ and miod@ (who suggested i name it uvm_atopg not uvm_atop)


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.57 24-Jul-2010 kettenis

Don't sleep while holding the uvm_psel_lck mutex. Should fix "locking against
myself" panics that some people have seen over the last year-and-a-half.

Cherry picked from a more complex (and therefore scarier) diff from oga@.

ok tedu@, oga@


# 1.56 27-Jun-2010 oga

Kill another #ifdef UBC chunk that was annoying me while doing something
else.

ok thib@


Revision tags: OPENBSD_4_7_BASE
# 1.55 12-Feb-2010 tedu

introduce a uvm_km_valloc_try function that won't get a lower level lock
for use by the uvm pseg code. this is the path of least resistance until
we sort out how many of these functions we really need. problem found by mikeb
ok kettenis oga


# 1.54 22-Jul-2009 oga

Put the PG_RELEASED changes diff back in.

This has has been tested very very thoroughly on all archs we have
excepting 88k and 68k. Please see cvs log for the individual commit
messages.

ok beck@, thib@


Revision tags: OPENBSD_4_6_BASE
# 1.53 17-Jun-2009 oga

date based reversion of uvm to the 4th May.

More backouts in line with previous ones, this appears to bring us back to a
stable condition.

A machine forced to 64mb of ram cycled 10GB through swap with this diff
and is still running as I type this. Other tests by ariane@ and thib@
also seem to show that it's alright.

ok deraadt@, thib@, ariane@


# 1.52 16-Jun-2009 oga

Backout all the PG_RELEASED changes.

This is for the same reason as the earlier backouts, to avoid the bug
either added or exposed sometime around c2k9. This *should* be the last
one.

prompted by deraadt@

ok ariane@


# 1.51 23-May-2009 oga

More PG_RELEASED cleaning.

similar to the aobj.c changes, this one does vnodes. Vnodes are more
complex because they actaully have to sync to backing store. So firstly,
convert sync to sleep instead of setting released.

Now, for backing store, in the PGO_FREE case, if we set PG_RELEASED
*before* an async io, (nothing else will see it, the page is busy), then
we can ignore the page after the io is done. We could do something
similar for PGO_DEACTIVATE too, but that is another change. On error we
just clear the released flag, nothing else sets it for uobj pages other
than aiodoned.

ok thib@, beck@, ariane@


# 1.50 04-May-2009 oga

Instead of keeping two ints in the uvm structure specifically just to
sleep on them (and otherwise ignore them) sleep on the pointer to the
{aiodoned,pagedaemon}_proc members, and nuke the two extra words.

"no objections" art@, ok beck@.


# 1.49 06-Apr-2009 oga

Instead of doing splbio(); simple_lock(&uvm.aiodoned_lock); just replace
the simple lock with a real lock - a IPL_BIO mutex. While i'm here, make
the sleeping condition one hell of a lot simpler in the aio daemon.

some ideas from and ok art@.


# 1.48 25-Mar-2009 oga

Move all of the pseudo-inline functions in uvm into C files.

By pseudo-inline, I mean that if a certain macro was defined, they would
be inlined. However, no architecture defines that, and none has for a
very very long time. Therefore mainly this just makes the code a damned
sight easier to read. Some k&r -> ansi declarations while I'm in there.

"just commit it" art@. ok weingart@.


# 1.47 20-Mar-2009 oga

While working on some stuff in uvm I've gotten REALLY sick of reading
K&R function declarations, so switch them all over to ansi-style, in
accordance with the prophesy.

"go for it" art@


Revision tags: OPENBSD_4_5_BASE
# 1.46 27-Jan-2009 ariane

Simplify page-out/page-in map management; fix rare pager deadlock.

Ok: miod, tedu


# 1.45 24-Nov-2008 thib

garbage collect uvm_errno2vmerror();

ok miod@, art@


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.44 26-Nov-2007 miod

In uvm_aio_aiodone(), kill the variable-sized array on stack, and use a
fixed size array which size should match any buf; if a bogus buf is passed
to this function, the kernel will KASSERT instead of potentially running out
of stack and having an undefined behaviour.

ok deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.43 06-Jun-2007 deraadt

now that all partition size/offsets are potentially 64-bit, change the
type of all variables to daddr64_t. this includes the APIs for XXsize()
and XXdump(), all range checks inside bio drivers, internal variables
for disklabel handling, and even uvm's swap offsets. re-read numerous
times by otto, miod, krw, thib to look for errors


# 1.42 13-Apr-2007 art

While splitting flags and pqflags might have been a good idea in theory
to separate locking, on most modern machines this is not enough
since operations on short types touch other short types that share the
same word in memory.

Merge pg_flags and pqflags again and now use atomic operations to change
the flags. Also bump wire_count to an int and pg_version might go
int as well, just for alignment.

tested by many, many. ok miod@


# 1.41 04-Apr-2007 art

Mechanically rename the "flags" and "version" fields in struct vm_page
to "pg_flags" and "pg_version", so that they are a bit easier to work with.
Whoever uses generic names like this for a popular struct obviously doesn't
read much code.

Most architectures compile and there are no functionality changes.

deraadt@ ok ("if something fails to compile, we fix that by hand")


# 1.40 25-Mar-2007 art

remove KERN_SUCCESS and use 0 instead.
eyeballed by miod@ and pedro@


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.39 31-Jul-2006 mickey

fix uvmhist #2: args are always u_long so fix missing %d and %x and no %ll; no change for normal code


# 1.38 26-Jul-2006 mickey

fix fmts for UVMHIST_LOG() entries making it more useful on 64bit archs; miod@ ok


Revision tags: OPENBSD_3_8_BASE OPENBSD_3_9_BASE
# 1.37 26-Jul-2005 art

- Make a UVM_OBJ_IS_DEVICE macro.
- Use it to skip device mappings while dumping core.
- Ignore EFAULT errors while dumping core since they can happen
even for valid mappings. Just skip that part of the core file and
let it get automagically zero-filled.

This fixes the broken X core dumps that people have been seeing and also
fixes some other potential problems that could prevent core dumps (mmaps
beyond EOF, etc.).

tedu@ ok


# 1.36 24-May-2005 tedu

add a new field to vm_space and use it to track the number of anon
pages a process uses. this is now the userland "data size" value.
ok art deraadt tdeval. thanks testers.


Revision tags: OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE SMP_SYNC_A SMP_SYNC_B
# 1.35 23-Feb-2004 drahn

sync of pmap_update() calls with NetBSD. pmap_update is defined away on
all architectures but arm, where it is needed.


Revision tags: OPENBSD_3_4_BASE UBC_SYNC_A
# 1.34 29-Mar-2003 mickey

ubchist is not a fully cooked kadaver and though use the other well formed pdhist one until ubc gaets back. art@ ok


Revision tags: OPENBSD_3_3_BASE
# 1.33 29-Oct-2002 art

Since memory deallocation can't fail, remove the error return from
uvm_unmap, uvm_deallocate and a few other functions.
Simplifies some code and reduces diff to the UBC branch.


Revision tags: OPENBSD_3_2_BASE UBC_SYNC_B
# 1.32 24-May-2002 art

Make sure that b_iodone handlers are called at splbio (and splassert(IPL_BIO) in all known callers, just to make sure).


# 1.31 22-May-2002 art

splassert(IPL_BIO) in the b_iodone handlers.


Revision tags: OPENBSD_3_1_BASE
# 1.30 02-Jan-2002 miod

Back out a few more uvm changes, especially wrt swap usage.
This unbreaks m68k m88k sparc and perhaps others, which eventually froze
when hitting swap.
Tested by various people on various platforms.
ok art@


# 1.29 19-Dec-2001 art

UBC was a disaster. It worked very good when it worked, but on some
machines or some configurations or in some phase of the moon (we actually
don't know when or why) files disappeared. Since we've not been able to
track down the problem in two weeks intense debugging and we need -current
to be stable, back out everything to a state it had before UBC.

We apologise for the inconvenience.


Revision tags: UBC_BASE
# 1.28 04-Dec-2001 art

branches: 1.28.2;
Yet another sync to NetBSD uvm.
Today we add a pmap argument to pmap_update() and allocate map entries for
kernel_map from kmem_map instead of using the static entries. This should
get rid of MAX_KMAPENT panics. Also some uvm_loan problems are fixed.


# 1.27 30-Nov-2001 csapuntz

Call buf_cleanout, which handles wakeups


# 1.26 29-Nov-2001 art

Correctly handle b_vp with bgetvp and brelvp in {get,put}pages.
Prevents panics caused by vnodes being recycled under our feet.


# 1.25 28-Nov-2001 art

Sync in more uvm from NetBSD. Mostly just cosmetic stuff.
Contains also support for page coloring.


# 1.24 28-Nov-2001 art

Sync in more uvm changes from NetBSD.
This time we're getting rid of KERN_* and VM_PAGER_* error codes and
use errnos instead.


# 1.23 27-Nov-2001 art

Merge in the unified buffer cache code as found in NetBSD 2001/03/10. The
code is written mostly by Chuck Silvers <chuq@chuq.com>/<chs@netbsd.org>.

Tested for the past few weeks by many developers, should be in a pretty stable
state, but will require optimizations and additional cleanups.


# 1.22 12-Nov-2001 art

Bring in more changes from NetBSD. Mostly pagedaemon improvements.


# 1.21 10-Nov-2001 art

Merge in some parts of the ubc work that has been done in NetBSD that are not
UBC, but prerequsites for it.

- Create a daemon that processes async I/O (swap and paging in the future)
requests that need processing in process context and that were processed
in the pagedaemon before.
- Convert some ugly ifdef DIAGNOSTIC code to less intrusive KASSERTs.
- misc other cleanups.


# 1.20 07-Nov-2001 art

Another sync of uvm to NetBSD. Just minor fiddling, no major changes.


# 1.19 07-Nov-2001 art

Add an alignment argument to uvm_map that specifies an alignment hint
for the virtual address.


# 1.18 06-Nov-2001 art

Move the last content from vm/ to uvm/
The only thing left in vm/ are just dumb wrappers.
vm/vm.h includes uvm/uvm_extern.h
vm/pmap.h includes uvm/uvm_pmap.h
vm/vm_page.h includes uvm/uvm_page.h


# 1.17 05-Nov-2001 art

Minor sync to NetBSD.


Revision tags: OPENBSD_3_0_BASE
# 1.16 20-Sep-2001 mpech

occured->occurred

idea from deraadt@ via NetBSD
millert@ ok


# 1.15 19-Sep-2001 mickey

merge vm/vm_kern.h into uvm/uvm_extern.h; art@ ok


# 1.14 11-Aug-2001 art

Various random fixes from NetBSD.
Including support for zeroing pages in the idle loop (not enabled yet).


# 1.13 06-Aug-2001 art

Add a new type voff_t (right now it's typedefed as off_t) used for offsets
into objects.

Gives the possibilty to mmap beyond the size of vaddr_t.

From NetBSD.


# 1.12 26-Jul-2001 art

Add support for disabling swap devices (swapctl -d).
Improve error handling on I/O errors to swap.
From NetBSD


# 1.11 25-Jul-2001 art

Change the pmap_enter interface to merge access_type and the wired boolean
and arbitrary flags into one argument.

One new flag is PMAP_CANFAIL that tells pmap_enter that it can fail if there
are not enough resources to satisfy the request. If this flag is not passed,
pmap_enter should panic as it should have done before this change (XXX - many
pmaps are still not doing that).

Only i386 and alpha implement CANFAIL for now.

Includes uvm updates from NetBSD.


# 1.10 18-Jul-2001 art

Get rid of the PMAP_NEW option by making it mandatory for all archs.
The archs that didn't have a proper PMAP_NEW now have a dummy implementation
with wrappers around the old functions.


# 1.9 08-Jun-2001 art

Change the paddr_t pmap_extract(struct pmap *, vaddr_t) interface to
boolean_t pmap_extract(struct pmap *, vaddr_t, paddr_t *).
Matches NetBSD. Tested by various people on various platforms.


Revision tags: OPENBSD_2_9_BASE
# 1.8 22-Mar-2001 smart

Sync style, typo, and comments a little closer to NetBSD. art@ ok


# 1.7 08-Mar-2001 smart

Replace thread_wakeup() with wakeup(). It is defined in vm_extern.h as a
wrapper, so this removes a dependence on the old VM system. From NetBSD.
art@ ok


# 1.6 29-Jan-2001 niklas

$OpenBSD$


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE
# 1.5 16-Mar-2000 art

Bring in some new UVM code from NetBSD (not current).

- Introduce a new type of map that are interrupt safe and never allow faults
in them. mb_map and kmem_map are made intrsafe.
- Add "access protection" to uvm_vslock (to be passed down to uvm_fault and
later to pmap_enter).
- madvise(2) now works.
- various cleanups.


Revision tags: OPENBSD_2_6_BASE SMP_BASE kame_19991208
# 1.4 03-Sep-1999 art

branches: 1.4.4;
Change the pmap_enter api to pass down an argument that indicates
the access type that caused this mapping. This is to simplify pmaps
with mod/ref emulation (none for the moment) and in some cases speed
up pmap_is_{referenced,modified}.
At the same time, clean up some mappings that had too high protection.

XXX - the access type is incorrect in old vm, it's only used by uvm and MD code.
The actual use of this in pmap_enter implementations is not in this commit.


# 1.3 23-Aug-1999 art

sync with NetBSD from 1999.05.24 (there is a reason for this date)
Mostly cleanups, but also a few improvements to pagedaemon for better
handling of low memory and/or low swap conditions.


Revision tags: OPENBSD_2_5_BASE
# 1.2 26-Feb-1999 art

add OpenBSD tags


# 1.1 26-Feb-1999 art

Import of uvm from NetBSD. Some local changes, some code disabled


# 1.88 15-Aug-2022 jsg

remove unused uvm_aiobuf_pool


# 1.87 07-Aug-2022 miod

Use PMAP_PREFER_ALIGN() == 0 rather than !defined(PMAP_PREFER) to enable the
fast path in the pager code; this benefits most mips64 platforms.

ok kettenis@ mpi@


# 1.86 02-Aug-2022 mpi

Bring back the direct map optimization when PMAP_PREFER isn't defined.

PMAP_PREFER is checked to prevent cache aliasing issues when the physical
page is mapped at different virtual addresses.

This speeds up file-based mmap faults.

ok kettenis@


# 1.85 24-Jul-2022 mpi

Revert simplification of the aiodone daemon it breaks swap on arm64.

Found the hard way by mlarkin@ and deraadt@.


# 1.84 17-Jul-2022 kettenis

Revert the changes made in rev 1.82. It is important to use pmap_enter(9)
and pmap_remove(9) here since we're dealing with managed pages here. Found
out the hard way by deraadt@ on landisk where we're running into issues
with virtual cache aliases because multiple mappings exist for the
pages we're dealing with here. The pmap_enter(9) and pmap_remove(9)
functions handle conflicting cache aliases, whereas pmap_map_direct(9) and
pmap_kenter_pa(9) assume that the pages is exclusively mapped in the kernel
pmap.

ok deraadt@


# 1.83 11-Jul-2022 mpi

Simplify the aiodone daemon which is only used for async writes.

- Remove unused support for asynchronous read, including error conditions

- Grab the proper lock for each page that has been written to swap. This
allows to enable an assertion in uvm_page_unbusy().

- Move the uvm_anon_release() call outside of uvm_page_unbusy() and
assert for the different anon cases.

ok beck@, kettenis@


# 1.82 30-Jun-2022 mpi

Reduce allocations and possible failures in uvm_pagermapin/out().

. If a direct map exists use it to map single-page allocations
. Use pmap_kenter_pa() instead of pmap_enter() in all other cases.

This speeds up file-based mmap up to 75% when I/O are performed and it
also reduces possible allocations failtures in the page daemon making
it more stable in OOM situations.

ok kettenis@, beck@


# 1.81 28-Jun-2022 mpi

Reserve a second segment for the page daemon.

This ensures uvm_swap_io() can succeeds even in OOM situations because two
uvm_pagermapin() allocations, requiring a segment each, are needed to bounce
or encrypt a swap cluster.

ok beck@, kettenis@


# 1.80 28-Jun-2022 mpi

Move the guts of uvm_aio_aiodone() into a separate function.

This will help dealing with error cases.

No functionnal changes.


# 1.79 28-Jun-2022 mpi

Do not clean PG_BUSY before calling uvm_anon_release().

Fix an assertion reported by gkoehler@.

ok kettenis@


Revision tags: OPENBSD_7_1_BASE
# 1.78 18-Feb-2022 kettenis

Convert KVA allocation to km_alloc(9).

ok mpi@


# 1.77 15-Dec-2021 mpi

Use a per-UVM object lock to serialize the lower part of the fault handler.

Like the per-amap lock the `vmobjlock' is principally used to serialized
access to objects in the fault handler to allow faults occurring on
different CPUs and different objects to be processed in parallel.

The fault handler now acquires the `vmobjlock' of a given UVM object as
soon as it finds one. For now a write-lock is always acquired even if
some operations could use a read-lock.

Every pager, corresponding to a different kind of UVM object, now expect
the UVM object to be locked and some operations, like *_get() return it
unlocked. This is enforced by assertions checking for rw_write_held().

The KERNEL_LOCK() is now pushed to the VFS boundary in the vnode pager.

To ensure the correct amap or object lock is held when modifying a page
many uvm_page* operations are now asserting for the "owner" lock.
However, fields of the "struct vm_page" are still being protected by the
global `pageqlock'. To prevent lock ordering issues with the new
`vmobjlock' and to reduce differences with NetBSD this lock is now taken
and released for each page instead of around the whole loop.

This commit does not remove the KERNEL_LOCK/UNLOCK() dance. Unlocking
will follow if there is no fallout.

Ported from NetBSD, tested by many, thanks!

ok kettenis@, kn@


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.76 26-Mar-2021 mpi

Remove parenthesis around return value to reduce the diff with NetBSD.

No functional change.

ok mlarkin@


# 1.75 12-Mar-2021 jsg

spelling

ok mpi@


# 1.74 19-Jan-2021 mpi

(re)Introduce locking for amaps & anons.

A rwlock is attached to every amap and is shared with all its anon. The
same lock will be used by multiple amaps if they have anons in common.

This should be enough to get the upper part of the fault handler out of the
KERNEL_LOCK() which seems to bring up to 20% improvements in builds.

This is based/copied/adapted from the most recent work done in NetBSD which
is an evolution of the precendent simple_lock scheme.

Tested by many, thanks!

ok kettenis@, mvs@


# 1.73 21-Oct-2020 mpi

Constify and use C99 initializer for "struct uvm_pagerops".

While here put some KERNEL_ASSERT_LOCKED() in the functions called from
the page fault handler. The removal of locking of `uobj' will need to be
revisited and these are good indicator that something is missing and that
many comments are lying.

ok kettenis


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.72 08-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok visa@, jca@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.71 17-Dec-2014 tedu

remove lock.h from uvm_extern.h. another holdover from the simpletonlock
era. fix uvm including c files to include lock.h or atomic.h as necessary.
ok deraadt


# 1.70 16-Nov-2014 deraadt

Replace a plethora of historical protection options with just
PROT_NONE, PROT_READ, PROT_WRITE, and PROT_EXEC from mman.h.
PROT_MASK is introduced as the one true way of extracting those bits.
Remove UVM_ADV_* wrapper, using the standard names.
ok doug guenther kettenis


# 1.69 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.68 11-Jul-2014 jsg

Chuck Cranor rescinded clauses in his license
on the 2nd of February 2011 in NetBSD.

http://marc.info/?l=netbsd-source-changes&m=129658899212732&w=2
http://marc.info/?l=netbsd-source-changes&m=129659095515558&w=2
http://marc.info/?l=netbsd-source-changes&m=129659157916514&w=2
http://marc.info/?l=netbsd-source-changes&m=129665962324372&w=2
http://marc.info/?l=netbsd-source-changes&m=129666033625342&w=2
http://marc.info/?l=netbsd-source-changes&m=129666052825545&w=2
http://marc.info/?l=netbsd-source-changes&m=129666922906480&w=2
http://marc.info/?l=netbsd-source-changes&m=129667725518082&w=2


# 1.67 09-May-2014 tedu

stop using B_AGE, it was effectively retired some time ago.


# 1.66 08-May-2014 kettenis

Fix some potential integer overflows caused by converting a page number into
an offset/size/address by shifting by PAGE_SHIFT. Make uvm_objwrire/unwire
use voff_t instead of off_t. The former is the right type here even if it is
equivalent to the latter.

Inspired by a somewhat similar changes in Bitrig.

ok deraadt@, guenther@


# 1.65 13-Apr-2014 tedu

compress code by turning four line comments into one line comments.
emphatic ok usual suspects, grudging ok miod


Revision tags: OPENBSD_5_5_BASE
# 1.64 02-Nov-2013 krw

No need to cast constants or simple variables to (daddr_t). Use
(u_int64_t) instead of (daddr_t) when casting a variable in an
expression passed to DL_SETDSIZE().

Change a variable counting open files from daddr_t to int64_t.

ok deraadt@ with the tweak to fix that pesky expression.


Revision tags: OPENBSD_5_4_BASE
# 1.63 11-Jun-2013 deraadt

final removal of daddr64_t. daddr_t has been 64 bit for a long enough
test period; i think 3 years ago the last bugs fell out.
ok otto beck others


# 1.62 30-May-2013 tedu

remove lots of comments about locking per beck's request


# 1.61 30-May-2013 tedu

remove simple_locks from uvm code. ok beck deraadt


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.60 03-Jul-2011 oga

Rip out and burn support for UVM_HIST.

The vm hackers don't use it, don't maintain it and have to look at it all the
time. About time this 800 lines of code hit /dev/null.

``never liked it'' tedu@. ariane@ was very happy when i told her i wrote
this diff.


# 1.59 15-Apr-2011 oga

for uvm_pager_dropcluster in the PG_RELEASED case we specifically unbusy the
page so that um_anfree will free it for us.

uvm_anfree does a pmap_page_protect(, VM_PROT_NONE) just before it frees the
page, so we don't need to do it here ourselves.

ok ariane@


# 1.58 15-Apr-2011 oga

move uvm_pageratop from uvm_pager.c local to a general uvm function
(uvm_atopg) and use it in uvm_km_doputpage to replace some handrolled
code. Shrinks the kernel a trivial amount.

ok beck@ and miod@ (who suggested i name it uvm_atopg not uvm_atop)


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.57 24-Jul-2010 kettenis

Don't sleep while holding the uvm_psel_lck mutex. Should fix "locking against
myself" panics that some people have seen over the last year-and-a-half.

Cherry picked from a more complex (and therefore scarier) diff from oga@.

ok tedu@, oga@


# 1.56 27-Jun-2010 oga

Kill another #ifdef UBC chunk that was annoying me while doing something
else.

ok thib@


Revision tags: OPENBSD_4_7_BASE
# 1.55 12-Feb-2010 tedu

introduce a uvm_km_valloc_try function that won't get a lower level lock
for use by the uvm pseg code. this is the path of least resistance until
we sort out how many of these functions we really need. problem found by mikeb
ok kettenis oga


# 1.54 22-Jul-2009 oga

Put the PG_RELEASED changes diff back in.

This has has been tested very very thoroughly on all archs we have
excepting 88k and 68k. Please see cvs log for the individual commit
messages.

ok beck@, thib@


Revision tags: OPENBSD_4_6_BASE
# 1.53 17-Jun-2009 oga

date based reversion of uvm to the 4th May.

More backouts in line with previous ones, this appears to bring us back to a
stable condition.

A machine forced to 64mb of ram cycled 10GB through swap with this diff
and is still running as I type this. Other tests by ariane@ and thib@
also seem to show that it's alright.

ok deraadt@, thib@, ariane@


# 1.52 16-Jun-2009 oga

Backout all the PG_RELEASED changes.

This is for the same reason as the earlier backouts, to avoid the bug
either added or exposed sometime around c2k9. This *should* be the last
one.

prompted by deraadt@

ok ariane@


# 1.51 23-May-2009 oga

More PG_RELEASED cleaning.

similar to the aobj.c changes, this one does vnodes. Vnodes are more
complex because they actaully have to sync to backing store. So firstly,
convert sync to sleep instead of setting released.

Now, for backing store, in the PGO_FREE case, if we set PG_RELEASED
*before* an async io, (nothing else will see it, the page is busy), then
we can ignore the page after the io is done. We could do something
similar for PGO_DEACTIVATE too, but that is another change. On error we
just clear the released flag, nothing else sets it for uobj pages other
than aiodoned.

ok thib@, beck@, ariane@


# 1.50 04-May-2009 oga

Instead of keeping two ints in the uvm structure specifically just to
sleep on them (and otherwise ignore them) sleep on the pointer to the
{aiodoned,pagedaemon}_proc members, and nuke the two extra words.

"no objections" art@, ok beck@.


# 1.49 06-Apr-2009 oga

Instead of doing splbio(); simple_lock(&uvm.aiodoned_lock); just replace
the simple lock with a real lock - a IPL_BIO mutex. While i'm here, make
the sleeping condition one hell of a lot simpler in the aio daemon.

some ideas from and ok art@.


# 1.48 25-Mar-2009 oga

Move all of the pseudo-inline functions in uvm into C files.

By pseudo-inline, I mean that if a certain macro was defined, they would
be inlined. However, no architecture defines that, and none has for a
very very long time. Therefore mainly this just makes the code a damned
sight easier to read. Some k&r -> ansi declarations while I'm in there.

"just commit it" art@. ok weingart@.


# 1.47 20-Mar-2009 oga

While working on some stuff in uvm I've gotten REALLY sick of reading
K&R function declarations, so switch them all over to ansi-style, in
accordance with the prophesy.

"go for it" art@


Revision tags: OPENBSD_4_5_BASE
# 1.46 27-Jan-2009 ariane

Simplify page-out/page-in map management; fix rare pager deadlock.

Ok: miod, tedu


# 1.45 24-Nov-2008 thib

garbage collect uvm_errno2vmerror();

ok miod@, art@


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.44 26-Nov-2007 miod

In uvm_aio_aiodone(), kill the variable-sized array on stack, and use a
fixed size array which size should match any buf; if a bogus buf is passed
to this function, the kernel will KASSERT instead of potentially running out
of stack and having an undefined behaviour.

ok deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.43 06-Jun-2007 deraadt

now that all partition size/offsets are potentially 64-bit, change the
type of all variables to daddr64_t. this includes the APIs for XXsize()
and XXdump(), all range checks inside bio drivers, internal variables
for disklabel handling, and even uvm's swap offsets. re-read numerous
times by otto, miod, krw, thib to look for errors


# 1.42 13-Apr-2007 art

While splitting flags and pqflags might have been a good idea in theory
to separate locking, on most modern machines this is not enough
since operations on short types touch other short types that share the
same word in memory.

Merge pg_flags and pqflags again and now use atomic operations to change
the flags. Also bump wire_count to an int and pg_version might go
int as well, just for alignment.

tested by many, many. ok miod@


# 1.41 04-Apr-2007 art

Mechanically rename the "flags" and "version" fields in struct vm_page
to "pg_flags" and "pg_version", so that they are a bit easier to work with.
Whoever uses generic names like this for a popular struct obviously doesn't
read much code.

Most architectures compile and there are no functionality changes.

deraadt@ ok ("if something fails to compile, we fix that by hand")


# 1.40 25-Mar-2007 art

remove KERN_SUCCESS and use 0 instead.
eyeballed by miod@ and pedro@


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.39 31-Jul-2006 mickey

fix uvmhist #2: args are always u_long so fix missing %d and %x and no %ll; no change for normal code


# 1.38 26-Jul-2006 mickey

fix fmts for UVMHIST_LOG() entries making it more useful on 64bit archs; miod@ ok


Revision tags: OPENBSD_3_8_BASE OPENBSD_3_9_BASE
# 1.37 26-Jul-2005 art

- Make a UVM_OBJ_IS_DEVICE macro.
- Use it to skip device mappings while dumping core.
- Ignore EFAULT errors while dumping core since they can happen
even for valid mappings. Just skip that part of the core file and
let it get automagically zero-filled.

This fixes the broken X core dumps that people have been seeing and also
fixes some other potential problems that could prevent core dumps (mmaps
beyond EOF, etc.).

tedu@ ok


# 1.36 24-May-2005 tedu

add a new field to vm_space and use it to track the number of anon
pages a process uses. this is now the userland "data size" value.
ok art deraadt tdeval. thanks testers.


Revision tags: OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE SMP_SYNC_A SMP_SYNC_B
# 1.35 23-Feb-2004 drahn

sync of pmap_update() calls with NetBSD. pmap_update is defined away on
all architectures but arm, where it is needed.


Revision tags: OPENBSD_3_4_BASE UBC_SYNC_A
# 1.34 29-Mar-2003 mickey

ubchist is not a fully cooked kadaver and though use the other well formed pdhist one until ubc gaets back. art@ ok


Revision tags: OPENBSD_3_3_BASE
# 1.33 29-Oct-2002 art

Since memory deallocation can't fail, remove the error return from
uvm_unmap, uvm_deallocate and a few other functions.
Simplifies some code and reduces diff to the UBC branch.


Revision tags: OPENBSD_3_2_BASE UBC_SYNC_B
# 1.32 24-May-2002 art

Make sure that b_iodone handlers are called at splbio (and splassert(IPL_BIO) in all known callers, just to make sure).


# 1.31 22-May-2002 art

splassert(IPL_BIO) in the b_iodone handlers.


Revision tags: OPENBSD_3_1_BASE
# 1.30 02-Jan-2002 miod

Back out a few more uvm changes, especially wrt swap usage.
This unbreaks m68k m88k sparc and perhaps others, which eventually froze
when hitting swap.
Tested by various people on various platforms.
ok art@


# 1.29 19-Dec-2001 art

UBC was a disaster. It worked very good when it worked, but on some
machines or some configurations or in some phase of the moon (we actually
don't know when or why) files disappeared. Since we've not been able to
track down the problem in two weeks intense debugging and we need -current
to be stable, back out everything to a state it had before UBC.

We apologise for the inconvenience.


Revision tags: UBC_BASE
# 1.28 04-Dec-2001 art

branches: 1.28.2;
Yet another sync to NetBSD uvm.
Today we add a pmap argument to pmap_update() and allocate map entries for
kernel_map from kmem_map instead of using the static entries. This should
get rid of MAX_KMAPENT panics. Also some uvm_loan problems are fixed.


# 1.27 30-Nov-2001 csapuntz

Call buf_cleanout, which handles wakeups


# 1.26 29-Nov-2001 art

Correctly handle b_vp with bgetvp and brelvp in {get,put}pages.
Prevents panics caused by vnodes being recycled under our feet.


# 1.25 28-Nov-2001 art

Sync in more uvm from NetBSD. Mostly just cosmetic stuff.
Contains also support for page coloring.


# 1.24 28-Nov-2001 art

Sync in more uvm changes from NetBSD.
This time we're getting rid of KERN_* and VM_PAGER_* error codes and
use errnos instead.


# 1.23 27-Nov-2001 art

Merge in the unified buffer cache code as found in NetBSD 2001/03/10. The
code is written mostly by Chuck Silvers <chuq@chuq.com>/<chs@netbsd.org>.

Tested for the past few weeks by many developers, should be in a pretty stable
state, but will require optimizations and additional cleanups.


# 1.22 12-Nov-2001 art

Bring in more changes from NetBSD. Mostly pagedaemon improvements.


# 1.21 10-Nov-2001 art

Merge in some parts of the ubc work that has been done in NetBSD that are not
UBC, but prerequsites for it.

- Create a daemon that processes async I/O (swap and paging in the future)
requests that need processing in process context and that were processed
in the pagedaemon before.
- Convert some ugly ifdef DIAGNOSTIC code to less intrusive KASSERTs.
- misc other cleanups.


# 1.20 07-Nov-2001 art

Another sync of uvm to NetBSD. Just minor fiddling, no major changes.


# 1.19 07-Nov-2001 art

Add an alignment argument to uvm_map that specifies an alignment hint
for the virtual address.


# 1.18 06-Nov-2001 art

Move the last content from vm/ to uvm/
The only thing left in vm/ are just dumb wrappers.
vm/vm.h includes uvm/uvm_extern.h
vm/pmap.h includes uvm/uvm_pmap.h
vm/vm_page.h includes uvm/uvm_page.h


# 1.17 05-Nov-2001 art

Minor sync to NetBSD.


Revision tags: OPENBSD_3_0_BASE
# 1.16 20-Sep-2001 mpech

occured->occurred

idea from deraadt@ via NetBSD
millert@ ok


# 1.15 19-Sep-2001 mickey

merge vm/vm_kern.h into uvm/uvm_extern.h; art@ ok


# 1.14 11-Aug-2001 art

Various random fixes from NetBSD.
Including support for zeroing pages in the idle loop (not enabled yet).


# 1.13 06-Aug-2001 art

Add a new type voff_t (right now it's typedefed as off_t) used for offsets
into objects.

Gives the possibilty to mmap beyond the size of vaddr_t.

From NetBSD.


# 1.12 26-Jul-2001 art

Add support for disabling swap devices (swapctl -d).
Improve error handling on I/O errors to swap.
From NetBSD


# 1.11 25-Jul-2001 art

Change the pmap_enter interface to merge access_type and the wired boolean
and arbitrary flags into one argument.

One new flag is PMAP_CANFAIL that tells pmap_enter that it can fail if there
are not enough resources to satisfy the request. If this flag is not passed,
pmap_enter should panic as it should have done before this change (XXX - many
pmaps are still not doing that).

Only i386 and alpha implement CANFAIL for now.

Includes uvm updates from NetBSD.


# 1.10 18-Jul-2001 art

Get rid of the PMAP_NEW option by making it mandatory for all archs.
The archs that didn't have a proper PMAP_NEW now have a dummy implementation
with wrappers around the old functions.


# 1.9 08-Jun-2001 art

Change the paddr_t pmap_extract(struct pmap *, vaddr_t) interface to
boolean_t pmap_extract(struct pmap *, vaddr_t, paddr_t *).
Matches NetBSD. Tested by various people on various platforms.


Revision tags: OPENBSD_2_9_BASE
# 1.8 22-Mar-2001 smart

Sync style, typo, and comments a little closer to NetBSD. art@ ok


# 1.7 08-Mar-2001 smart

Replace thread_wakeup() with wakeup(). It is defined in vm_extern.h as a
wrapper, so this removes a dependence on the old VM system. From NetBSD.
art@ ok


# 1.6 29-Jan-2001 niklas

$OpenBSD$


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE
# 1.5 16-Mar-2000 art

Bring in some new UVM code from NetBSD (not current).

- Introduce a new type of map that are interrupt safe and never allow faults
in them. mb_map and kmem_map are made intrsafe.
- Add "access protection" to uvm_vslock (to be passed down to uvm_fault and
later to pmap_enter).
- madvise(2) now works.
- various cleanups.


Revision tags: OPENBSD_2_6_BASE SMP_BASE kame_19991208
# 1.4 03-Sep-1999 art

branches: 1.4.4;
Change the pmap_enter api to pass down an argument that indicates
the access type that caused this mapping. This is to simplify pmaps
with mod/ref emulation (none for the moment) and in some cases speed
up pmap_is_{referenced,modified}.
At the same time, clean up some mappings that had too high protection.

XXX - the access type is incorrect in old vm, it's only used by uvm and MD code.
The actual use of this in pmap_enter implementations is not in this commit.


# 1.3 23-Aug-1999 art

sync with NetBSD from 1999.05.24 (there is a reason for this date)
Mostly cleanups, but also a few improvements to pagedaemon for better
handling of low memory and/or low swap conditions.


Revision tags: OPENBSD_2_5_BASE
# 1.2 26-Feb-1999 art

add OpenBSD tags


# 1.1 26-Feb-1999 art

Import of uvm from NetBSD. Some local changes, some code disabled


# 1.87 07-Aug-2022 miod

Use PMAP_PREFER_ALIGN() == 0 rather than !defined(PMAP_PREFER) to enable the
fast path in the pager code; this benefits most mips64 platforms.

ok kettenis@ mpi@


# 1.86 02-Aug-2022 mpi

Bring back the direct map optimization when PMAP_PREFER isn't defined.

PMAP_PREFER is checked to prevent cache aliasing issues when the physical
page is mapped at different virtual addresses.

This speeds up file-based mmap faults.

ok kettenis@


# 1.85 24-Jul-2022 mpi

Revert simplification of the aiodone daemon it breaks swap on arm64.

Found the hard way by mlarkin@ and deraadt@.


# 1.84 17-Jul-2022 kettenis

Revert the changes made in rev 1.82. It is important to use pmap_enter(9)
and pmap_remove(9) here since we're dealing with managed pages here. Found
out the hard way by deraadt@ on landisk where we're running into issues
with virtual cache aliases because multiple mappings exist for the
pages we're dealing with here. The pmap_enter(9) and pmap_remove(9)
functions handle conflicting cache aliases, whereas pmap_map_direct(9) and
pmap_kenter_pa(9) assume that the pages is exclusively mapped in the kernel
pmap.

ok deraadt@


# 1.83 11-Jul-2022 mpi

Simplify the aiodone daemon which is only used for async writes.

- Remove unused support for asynchronous read, including error conditions

- Grab the proper lock for each page that has been written to swap. This
allows to enable an assertion in uvm_page_unbusy().

- Move the uvm_anon_release() call outside of uvm_page_unbusy() and
assert for the different anon cases.

ok beck@, kettenis@


# 1.82 30-Jun-2022 mpi

Reduce allocations and possible failures in uvm_pagermapin/out().

. If a direct map exists use it to map single-page allocations
. Use pmap_kenter_pa() instead of pmap_enter() in all other cases.

This speeds up file-based mmap up to 75% when I/O are performed and it
also reduces possible allocations failtures in the page daemon making
it more stable in OOM situations.

ok kettenis@, beck@


# 1.81 28-Jun-2022 mpi

Reserve a second segment for the page daemon.

This ensures uvm_swap_io() can succeeds even in OOM situations because two
uvm_pagermapin() allocations, requiring a segment each, are needed to bounce
or encrypt a swap cluster.

ok beck@, kettenis@


# 1.80 28-Jun-2022 mpi

Move the guts of uvm_aio_aiodone() into a separate function.

This will help dealing with error cases.

No functionnal changes.


# 1.79 28-Jun-2022 mpi

Do not clean PG_BUSY before calling uvm_anon_release().

Fix an assertion reported by gkoehler@.

ok kettenis@


Revision tags: OPENBSD_7_1_BASE
# 1.78 18-Feb-2022 kettenis

Convert KVA allocation to km_alloc(9).

ok mpi@


# 1.77 15-Dec-2021 mpi

Use a per-UVM object lock to serialize the lower part of the fault handler.

Like the per-amap lock the `vmobjlock' is principally used to serialized
access to objects in the fault handler to allow faults occurring on
different CPUs and different objects to be processed in parallel.

The fault handler now acquires the `vmobjlock' of a given UVM object as
soon as it finds one. For now a write-lock is always acquired even if
some operations could use a read-lock.

Every pager, corresponding to a different kind of UVM object, now expect
the UVM object to be locked and some operations, like *_get() return it
unlocked. This is enforced by assertions checking for rw_write_held().

The KERNEL_LOCK() is now pushed to the VFS boundary in the vnode pager.

To ensure the correct amap or object lock is held when modifying a page
many uvm_page* operations are now asserting for the "owner" lock.
However, fields of the "struct vm_page" are still being protected by the
global `pageqlock'. To prevent lock ordering issues with the new
`vmobjlock' and to reduce differences with NetBSD this lock is now taken
and released for each page instead of around the whole loop.

This commit does not remove the KERNEL_LOCK/UNLOCK() dance. Unlocking
will follow if there is no fallout.

Ported from NetBSD, tested by many, thanks!

ok kettenis@, kn@


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.76 26-Mar-2021 mpi

Remove parenthesis around return value to reduce the diff with NetBSD.

No functional change.

ok mlarkin@


# 1.75 12-Mar-2021 jsg

spelling

ok mpi@


# 1.74 19-Jan-2021 mpi

(re)Introduce locking for amaps & anons.

A rwlock is attached to every amap and is shared with all its anon. The
same lock will be used by multiple amaps if they have anons in common.

This should be enough to get the upper part of the fault handler out of the
KERNEL_LOCK() which seems to bring up to 20% improvements in builds.

This is based/copied/adapted from the most recent work done in NetBSD which
is an evolution of the precendent simple_lock scheme.

Tested by many, thanks!

ok kettenis@, mvs@


# 1.73 21-Oct-2020 mpi

Constify and use C99 initializer for "struct uvm_pagerops".

While here put some KERNEL_ASSERT_LOCKED() in the functions called from
the page fault handler. The removal of locking of `uobj' will need to be
revisited and these are good indicator that something is missing and that
many comments are lying.

ok kettenis


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.72 08-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok visa@, jca@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.71 17-Dec-2014 tedu

remove lock.h from uvm_extern.h. another holdover from the simpletonlock
era. fix uvm including c files to include lock.h or atomic.h as necessary.
ok deraadt


# 1.70 16-Nov-2014 deraadt

Replace a plethora of historical protection options with just
PROT_NONE, PROT_READ, PROT_WRITE, and PROT_EXEC from mman.h.
PROT_MASK is introduced as the one true way of extracting those bits.
Remove UVM_ADV_* wrapper, using the standard names.
ok doug guenther kettenis


# 1.69 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.68 11-Jul-2014 jsg

Chuck Cranor rescinded clauses in his license
on the 2nd of February 2011 in NetBSD.

http://marc.info/?l=netbsd-source-changes&m=129658899212732&w=2
http://marc.info/?l=netbsd-source-changes&m=129659095515558&w=2
http://marc.info/?l=netbsd-source-changes&m=129659157916514&w=2
http://marc.info/?l=netbsd-source-changes&m=129665962324372&w=2
http://marc.info/?l=netbsd-source-changes&m=129666033625342&w=2
http://marc.info/?l=netbsd-source-changes&m=129666052825545&w=2
http://marc.info/?l=netbsd-source-changes&m=129666922906480&w=2
http://marc.info/?l=netbsd-source-changes&m=129667725518082&w=2


# 1.67 09-May-2014 tedu

stop using B_AGE, it was effectively retired some time ago.


# 1.66 08-May-2014 kettenis

Fix some potential integer overflows caused by converting a page number into
an offset/size/address by shifting by PAGE_SHIFT. Make uvm_objwrire/unwire
use voff_t instead of off_t. The former is the right type here even if it is
equivalent to the latter.

Inspired by a somewhat similar changes in Bitrig.

ok deraadt@, guenther@


# 1.65 13-Apr-2014 tedu

compress code by turning four line comments into one line comments.
emphatic ok usual suspects, grudging ok miod


Revision tags: OPENBSD_5_5_BASE
# 1.64 02-Nov-2013 krw

No need to cast constants or simple variables to (daddr_t). Use
(u_int64_t) instead of (daddr_t) when casting a variable in an
expression passed to DL_SETDSIZE().

Change a variable counting open files from daddr_t to int64_t.

ok deraadt@ with the tweak to fix that pesky expression.


Revision tags: OPENBSD_5_4_BASE
# 1.63 11-Jun-2013 deraadt

final removal of daddr64_t. daddr_t has been 64 bit for a long enough
test period; i think 3 years ago the last bugs fell out.
ok otto beck others


# 1.62 30-May-2013 tedu

remove lots of comments about locking per beck's request


# 1.61 30-May-2013 tedu

remove simple_locks from uvm code. ok beck deraadt


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.60 03-Jul-2011 oga

Rip out and burn support for UVM_HIST.

The vm hackers don't use it, don't maintain it and have to look at it all the
time. About time this 800 lines of code hit /dev/null.

``never liked it'' tedu@. ariane@ was very happy when i told her i wrote
this diff.


# 1.59 15-Apr-2011 oga

for uvm_pager_dropcluster in the PG_RELEASED case we specifically unbusy the
page so that um_anfree will free it for us.

uvm_anfree does a pmap_page_protect(, VM_PROT_NONE) just before it frees the
page, so we don't need to do it here ourselves.

ok ariane@


# 1.58 15-Apr-2011 oga

move uvm_pageratop from uvm_pager.c local to a general uvm function
(uvm_atopg) and use it in uvm_km_doputpage to replace some handrolled
code. Shrinks the kernel a trivial amount.

ok beck@ and miod@ (who suggested i name it uvm_atopg not uvm_atop)


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.57 24-Jul-2010 kettenis

Don't sleep while holding the uvm_psel_lck mutex. Should fix "locking against
myself" panics that some people have seen over the last year-and-a-half.

Cherry picked from a more complex (and therefore scarier) diff from oga@.

ok tedu@, oga@


# 1.56 27-Jun-2010 oga

Kill another #ifdef UBC chunk that was annoying me while doing something
else.

ok thib@


Revision tags: OPENBSD_4_7_BASE
# 1.55 12-Feb-2010 tedu

introduce a uvm_km_valloc_try function that won't get a lower level lock
for use by the uvm pseg code. this is the path of least resistance until
we sort out how many of these functions we really need. problem found by mikeb
ok kettenis oga


# 1.54 22-Jul-2009 oga

Put the PG_RELEASED changes diff back in.

This has has been tested very very thoroughly on all archs we have
excepting 88k and 68k. Please see cvs log for the individual commit
messages.

ok beck@, thib@


Revision tags: OPENBSD_4_6_BASE
# 1.53 17-Jun-2009 oga

date based reversion of uvm to the 4th May.

More backouts in line with previous ones, this appears to bring us back to a
stable condition.

A machine forced to 64mb of ram cycled 10GB through swap with this diff
and is still running as I type this. Other tests by ariane@ and thib@
also seem to show that it's alright.

ok deraadt@, thib@, ariane@


# 1.52 16-Jun-2009 oga

Backout all the PG_RELEASED changes.

This is for the same reason as the earlier backouts, to avoid the bug
either added or exposed sometime around c2k9. This *should* be the last
one.

prompted by deraadt@

ok ariane@


# 1.51 23-May-2009 oga

More PG_RELEASED cleaning.

similar to the aobj.c changes, this one does vnodes. Vnodes are more
complex because they actaully have to sync to backing store. So firstly,
convert sync to sleep instead of setting released.

Now, for backing store, in the PGO_FREE case, if we set PG_RELEASED
*before* an async io, (nothing else will see it, the page is busy), then
we can ignore the page after the io is done. We could do something
similar for PGO_DEACTIVATE too, but that is another change. On error we
just clear the released flag, nothing else sets it for uobj pages other
than aiodoned.

ok thib@, beck@, ariane@


# 1.50 04-May-2009 oga

Instead of keeping two ints in the uvm structure specifically just to
sleep on them (and otherwise ignore them) sleep on the pointer to the
{aiodoned,pagedaemon}_proc members, and nuke the two extra words.

"no objections" art@, ok beck@.


# 1.49 06-Apr-2009 oga

Instead of doing splbio(); simple_lock(&uvm.aiodoned_lock); just replace
the simple lock with a real lock - a IPL_BIO mutex. While i'm here, make
the sleeping condition one hell of a lot simpler in the aio daemon.

some ideas from and ok art@.


# 1.48 25-Mar-2009 oga

Move all of the pseudo-inline functions in uvm into C files.

By pseudo-inline, I mean that if a certain macro was defined, they would
be inlined. However, no architecture defines that, and none has for a
very very long time. Therefore mainly this just makes the code a damned
sight easier to read. Some k&r -> ansi declarations while I'm in there.

"just commit it" art@. ok weingart@.


# 1.47 20-Mar-2009 oga

While working on some stuff in uvm I've gotten REALLY sick of reading
K&R function declarations, so switch them all over to ansi-style, in
accordance with the prophesy.

"go for it" art@


Revision tags: OPENBSD_4_5_BASE
# 1.46 27-Jan-2009 ariane

Simplify page-out/page-in map management; fix rare pager deadlock.

Ok: miod, tedu


# 1.45 24-Nov-2008 thib

garbage collect uvm_errno2vmerror();

ok miod@, art@


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.44 26-Nov-2007 miod

In uvm_aio_aiodone(), kill the variable-sized array on stack, and use a
fixed size array which size should match any buf; if a bogus buf is passed
to this function, the kernel will KASSERT instead of potentially running out
of stack and having an undefined behaviour.

ok deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.43 06-Jun-2007 deraadt

now that all partition size/offsets are potentially 64-bit, change the
type of all variables to daddr64_t. this includes the APIs for XXsize()
and XXdump(), all range checks inside bio drivers, internal variables
for disklabel handling, and even uvm's swap offsets. re-read numerous
times by otto, miod, krw, thib to look for errors


# 1.42 13-Apr-2007 art

While splitting flags and pqflags might have been a good idea in theory
to separate locking, on most modern machines this is not enough
since operations on short types touch other short types that share the
same word in memory.

Merge pg_flags and pqflags again and now use atomic operations to change
the flags. Also bump wire_count to an int and pg_version might go
int as well, just for alignment.

tested by many, many. ok miod@


# 1.41 04-Apr-2007 art

Mechanically rename the "flags" and "version" fields in struct vm_page
to "pg_flags" and "pg_version", so that they are a bit easier to work with.
Whoever uses generic names like this for a popular struct obviously doesn't
read much code.

Most architectures compile and there are no functionality changes.

deraadt@ ok ("if something fails to compile, we fix that by hand")


# 1.40 25-Mar-2007 art

remove KERN_SUCCESS and use 0 instead.
eyeballed by miod@ and pedro@


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.39 31-Jul-2006 mickey

fix uvmhist #2: args are always u_long so fix missing %d and %x and no %ll; no change for normal code


# 1.38 26-Jul-2006 mickey

fix fmts for UVMHIST_LOG() entries making it more useful on 64bit archs; miod@ ok


Revision tags: OPENBSD_3_8_BASE OPENBSD_3_9_BASE
# 1.37 26-Jul-2005 art

- Make a UVM_OBJ_IS_DEVICE macro.
- Use it to skip device mappings while dumping core.
- Ignore EFAULT errors while dumping core since they can happen
even for valid mappings. Just skip that part of the core file and
let it get automagically zero-filled.

This fixes the broken X core dumps that people have been seeing and also
fixes some other potential problems that could prevent core dumps (mmaps
beyond EOF, etc.).

tedu@ ok


# 1.36 24-May-2005 tedu

add a new field to vm_space and use it to track the number of anon
pages a process uses. this is now the userland "data size" value.
ok art deraadt tdeval. thanks testers.


Revision tags: OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE SMP_SYNC_A SMP_SYNC_B
# 1.35 23-Feb-2004 drahn

sync of pmap_update() calls with NetBSD. pmap_update is defined away on
all architectures but arm, where it is needed.


Revision tags: OPENBSD_3_4_BASE UBC_SYNC_A
# 1.34 29-Mar-2003 mickey

ubchist is not a fully cooked kadaver and though use the other well formed pdhist one until ubc gaets back. art@ ok


Revision tags: OPENBSD_3_3_BASE
# 1.33 29-Oct-2002 art

Since memory deallocation can't fail, remove the error return from
uvm_unmap, uvm_deallocate and a few other functions.
Simplifies some code and reduces diff to the UBC branch.


Revision tags: OPENBSD_3_2_BASE UBC_SYNC_B
# 1.32 24-May-2002 art

Make sure that b_iodone handlers are called at splbio (and splassert(IPL_BIO) in all known callers, just to make sure).


# 1.31 22-May-2002 art

splassert(IPL_BIO) in the b_iodone handlers.


Revision tags: OPENBSD_3_1_BASE
# 1.30 02-Jan-2002 miod

Back out a few more uvm changes, especially wrt swap usage.
This unbreaks m68k m88k sparc and perhaps others, which eventually froze
when hitting swap.
Tested by various people on various platforms.
ok art@


# 1.29 19-Dec-2001 art

UBC was a disaster. It worked very good when it worked, but on some
machines or some configurations or in some phase of the moon (we actually
don't know when or why) files disappeared. Since we've not been able to
track down the problem in two weeks intense debugging and we need -current
to be stable, back out everything to a state it had before UBC.

We apologise for the inconvenience.


Revision tags: UBC_BASE
# 1.28 04-Dec-2001 art

branches: 1.28.2;
Yet another sync to NetBSD uvm.
Today we add a pmap argument to pmap_update() and allocate map entries for
kernel_map from kmem_map instead of using the static entries. This should
get rid of MAX_KMAPENT panics. Also some uvm_loan problems are fixed.


# 1.27 30-Nov-2001 csapuntz

Call buf_cleanout, which handles wakeups


# 1.26 29-Nov-2001 art

Correctly handle b_vp with bgetvp and brelvp in {get,put}pages.
Prevents panics caused by vnodes being recycled under our feet.


# 1.25 28-Nov-2001 art

Sync in more uvm from NetBSD. Mostly just cosmetic stuff.
Contains also support for page coloring.


# 1.24 28-Nov-2001 art

Sync in more uvm changes from NetBSD.
This time we're getting rid of KERN_* and VM_PAGER_* error codes and
use errnos instead.


# 1.23 27-Nov-2001 art

Merge in the unified buffer cache code as found in NetBSD 2001/03/10. The
code is written mostly by Chuck Silvers <chuq@chuq.com>/<chs@netbsd.org>.

Tested for the past few weeks by many developers, should be in a pretty stable
state, but will require optimizations and additional cleanups.


# 1.22 12-Nov-2001 art

Bring in more changes from NetBSD. Mostly pagedaemon improvements.


# 1.21 10-Nov-2001 art

Merge in some parts of the ubc work that has been done in NetBSD that are not
UBC, but prerequsites for it.

- Create a daemon that processes async I/O (swap and paging in the future)
requests that need processing in process context and that were processed
in the pagedaemon before.
- Convert some ugly ifdef DIAGNOSTIC code to less intrusive KASSERTs.
- misc other cleanups.


# 1.20 07-Nov-2001 art

Another sync of uvm to NetBSD. Just minor fiddling, no major changes.


# 1.19 07-Nov-2001 art

Add an alignment argument to uvm_map that specifies an alignment hint
for the virtual address.


# 1.18 06-Nov-2001 art

Move the last content from vm/ to uvm/
The only thing left in vm/ are just dumb wrappers.
vm/vm.h includes uvm/uvm_extern.h
vm/pmap.h includes uvm/uvm_pmap.h
vm/vm_page.h includes uvm/uvm_page.h


# 1.17 05-Nov-2001 art

Minor sync to NetBSD.


Revision tags: OPENBSD_3_0_BASE
# 1.16 20-Sep-2001 mpech

occured->occurred

idea from deraadt@ via NetBSD
millert@ ok


# 1.15 19-Sep-2001 mickey

merge vm/vm_kern.h into uvm/uvm_extern.h; art@ ok


# 1.14 11-Aug-2001 art

Various random fixes from NetBSD.
Including support for zeroing pages in the idle loop (not enabled yet).


# 1.13 06-Aug-2001 art

Add a new type voff_t (right now it's typedefed as off_t) used for offsets
into objects.

Gives the possibilty to mmap beyond the size of vaddr_t.

From NetBSD.


# 1.12 26-Jul-2001 art

Add support for disabling swap devices (swapctl -d).
Improve error handling on I/O errors to swap.
From NetBSD


# 1.11 25-Jul-2001 art

Change the pmap_enter interface to merge access_type and the wired boolean
and arbitrary flags into one argument.

One new flag is PMAP_CANFAIL that tells pmap_enter that it can fail if there
are not enough resources to satisfy the request. If this flag is not passed,
pmap_enter should panic as it should have done before this change (XXX - many
pmaps are still not doing that).

Only i386 and alpha implement CANFAIL for now.

Includes uvm updates from NetBSD.


# 1.10 18-Jul-2001 art

Get rid of the PMAP_NEW option by making it mandatory for all archs.
The archs that didn't have a proper PMAP_NEW now have a dummy implementation
with wrappers around the old functions.


# 1.9 08-Jun-2001 art

Change the paddr_t pmap_extract(struct pmap *, vaddr_t) interface to
boolean_t pmap_extract(struct pmap *, vaddr_t, paddr_t *).
Matches NetBSD. Tested by various people on various platforms.


Revision tags: OPENBSD_2_9_BASE
# 1.8 22-Mar-2001 smart

Sync style, typo, and comments a little closer to NetBSD. art@ ok


# 1.7 08-Mar-2001 smart

Replace thread_wakeup() with wakeup(). It is defined in vm_extern.h as a
wrapper, so this removes a dependence on the old VM system. From NetBSD.
art@ ok


# 1.6 29-Jan-2001 niklas

$OpenBSD$


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE
# 1.5 16-Mar-2000 art

Bring in some new UVM code from NetBSD (not current).

- Introduce a new type of map that are interrupt safe and never allow faults
in them. mb_map and kmem_map are made intrsafe.
- Add "access protection" to uvm_vslock (to be passed down to uvm_fault and
later to pmap_enter).
- madvise(2) now works.
- various cleanups.


Revision tags: OPENBSD_2_6_BASE SMP_BASE kame_19991208
# 1.4 03-Sep-1999 art

branches: 1.4.4;
Change the pmap_enter api to pass down an argument that indicates
the access type that caused this mapping. This is to simplify pmaps
with mod/ref emulation (none for the moment) and in some cases speed
up pmap_is_{referenced,modified}.
At the same time, clean up some mappings that had too high protection.

XXX - the access type is incorrect in old vm, it's only used by uvm and MD code.
The actual use of this in pmap_enter implementations is not in this commit.


# 1.3 23-Aug-1999 art

sync with NetBSD from 1999.05.24 (there is a reason for this date)
Mostly cleanups, but also a few improvements to pagedaemon for better
handling of low memory and/or low swap conditions.


Revision tags: OPENBSD_2_5_BASE
# 1.2 26-Feb-1999 art

add OpenBSD tags


# 1.1 26-Feb-1999 art

Import of uvm from NetBSD. Some local changes, some code disabled


# 1.86 02-Aug-2022 mpi

Bring back the direct map optimization when PMAP_PREFER isn't defined.

PMAP_PREFER is checked to prevent cache aliasing issues when the physical
page is mapped at different virtual addresses.

This speeds up file-based mmap faults.

ok kettenis@


# 1.85 24-Jul-2022 mpi

Revert simplification of the aiodone daemon it breaks swap on arm64.

Found the hard way by mlarkin@ and deraadt@.


# 1.84 17-Jul-2022 kettenis

Revert the changes made in rev 1.82. It is important to use pmap_enter(9)
and pmap_remove(9) here since we're dealing with managed pages here. Found
out the hard way by deraadt@ on landisk where we're running into issues
with virtual cache aliases because multiple mappings exist for the
pages we're dealing with here. The pmap_enter(9) and pmap_remove(9)
functions handle conflicting cache aliases, whereas pmap_map_direct(9) and
pmap_kenter_pa(9) assume that the pages is exclusively mapped in the kernel
pmap.

ok deraadt@


# 1.83 11-Jul-2022 mpi

Simplify the aiodone daemon which is only used for async writes.

- Remove unused support for asynchronous read, including error conditions

- Grab the proper lock for each page that has been written to swap. This
allows to enable an assertion in uvm_page_unbusy().

- Move the uvm_anon_release() call outside of uvm_page_unbusy() and
assert for the different anon cases.

ok beck@, kettenis@


# 1.82 30-Jun-2022 mpi

Reduce allocations and possible failures in uvm_pagermapin/out().

. If a direct map exists use it to map single-page allocations
. Use pmap_kenter_pa() instead of pmap_enter() in all other cases.

This speeds up file-based mmap up to 75% when I/O are performed and it
also reduces possible allocations failtures in the page daemon making
it more stable in OOM situations.

ok kettenis@, beck@


# 1.81 28-Jun-2022 mpi

Reserve a second segment for the page daemon.

This ensures uvm_swap_io() can succeeds even in OOM situations because two
uvm_pagermapin() allocations, requiring a segment each, are needed to bounce
or encrypt a swap cluster.

ok beck@, kettenis@


# 1.80 28-Jun-2022 mpi

Move the guts of uvm_aio_aiodone() into a separate function.

This will help dealing with error cases.

No functionnal changes.


# 1.79 28-Jun-2022 mpi

Do not clean PG_BUSY before calling uvm_anon_release().

Fix an assertion reported by gkoehler@.

ok kettenis@


Revision tags: OPENBSD_7_1_BASE
# 1.78 18-Feb-2022 kettenis

Convert KVA allocation to km_alloc(9).

ok mpi@


# 1.77 15-Dec-2021 mpi

Use a per-UVM object lock to serialize the lower part of the fault handler.

Like the per-amap lock the `vmobjlock' is principally used to serialized
access to objects in the fault handler to allow faults occurring on
different CPUs and different objects to be processed in parallel.

The fault handler now acquires the `vmobjlock' of a given UVM object as
soon as it finds one. For now a write-lock is always acquired even if
some operations could use a read-lock.

Every pager, corresponding to a different kind of UVM object, now expect
the UVM object to be locked and some operations, like *_get() return it
unlocked. This is enforced by assertions checking for rw_write_held().

The KERNEL_LOCK() is now pushed to the VFS boundary in the vnode pager.

To ensure the correct amap or object lock is held when modifying a page
many uvm_page* operations are now asserting for the "owner" lock.
However, fields of the "struct vm_page" are still being protected by the
global `pageqlock'. To prevent lock ordering issues with the new
`vmobjlock' and to reduce differences with NetBSD this lock is now taken
and released for each page instead of around the whole loop.

This commit does not remove the KERNEL_LOCK/UNLOCK() dance. Unlocking
will follow if there is no fallout.

Ported from NetBSD, tested by many, thanks!

ok kettenis@, kn@


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.76 26-Mar-2021 mpi

Remove parenthesis around return value to reduce the diff with NetBSD.

No functional change.

ok mlarkin@


# 1.75 12-Mar-2021 jsg

spelling

ok mpi@


# 1.74 19-Jan-2021 mpi

(re)Introduce locking for amaps & anons.

A rwlock is attached to every amap and is shared with all its anon. The
same lock will be used by multiple amaps if they have anons in common.

This should be enough to get the upper part of the fault handler out of the
KERNEL_LOCK() which seems to bring up to 20% improvements in builds.

This is based/copied/adapted from the most recent work done in NetBSD which
is an evolution of the precendent simple_lock scheme.

Tested by many, thanks!

ok kettenis@, mvs@


# 1.73 21-Oct-2020 mpi

Constify and use C99 initializer for "struct uvm_pagerops".

While here put some KERNEL_ASSERT_LOCKED() in the functions called from
the page fault handler. The removal of locking of `uobj' will need to be
revisited and these are good indicator that something is missing and that
many comments are lying.

ok kettenis


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.72 08-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok visa@, jca@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.71 17-Dec-2014 tedu

remove lock.h from uvm_extern.h. another holdover from the simpletonlock
era. fix uvm including c files to include lock.h or atomic.h as necessary.
ok deraadt


# 1.70 16-Nov-2014 deraadt

Replace a plethora of historical protection options with just
PROT_NONE, PROT_READ, PROT_WRITE, and PROT_EXEC from mman.h.
PROT_MASK is introduced as the one true way of extracting those bits.
Remove UVM_ADV_* wrapper, using the standard names.
ok doug guenther kettenis


# 1.69 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.68 11-Jul-2014 jsg

Chuck Cranor rescinded clauses in his license
on the 2nd of February 2011 in NetBSD.

http://marc.info/?l=netbsd-source-changes&m=129658899212732&w=2
http://marc.info/?l=netbsd-source-changes&m=129659095515558&w=2
http://marc.info/?l=netbsd-source-changes&m=129659157916514&w=2
http://marc.info/?l=netbsd-source-changes&m=129665962324372&w=2
http://marc.info/?l=netbsd-source-changes&m=129666033625342&w=2
http://marc.info/?l=netbsd-source-changes&m=129666052825545&w=2
http://marc.info/?l=netbsd-source-changes&m=129666922906480&w=2
http://marc.info/?l=netbsd-source-changes&m=129667725518082&w=2


# 1.67 09-May-2014 tedu

stop using B_AGE, it was effectively retired some time ago.


# 1.66 08-May-2014 kettenis

Fix some potential integer overflows caused by converting a page number into
an offset/size/address by shifting by PAGE_SHIFT. Make uvm_objwrire/unwire
use voff_t instead of off_t. The former is the right type here even if it is
equivalent to the latter.

Inspired by a somewhat similar changes in Bitrig.

ok deraadt@, guenther@


# 1.65 13-Apr-2014 tedu

compress code by turning four line comments into one line comments.
emphatic ok usual suspects, grudging ok miod


Revision tags: OPENBSD_5_5_BASE
# 1.64 02-Nov-2013 krw

No need to cast constants or simple variables to (daddr_t). Use
(u_int64_t) instead of (daddr_t) when casting a variable in an
expression passed to DL_SETDSIZE().

Change a variable counting open files from daddr_t to int64_t.

ok deraadt@ with the tweak to fix that pesky expression.


Revision tags: OPENBSD_5_4_BASE
# 1.63 11-Jun-2013 deraadt

final removal of daddr64_t. daddr_t has been 64 bit for a long enough
test period; i think 3 years ago the last bugs fell out.
ok otto beck others


# 1.62 30-May-2013 tedu

remove lots of comments about locking per beck's request


# 1.61 30-May-2013 tedu

remove simple_locks from uvm code. ok beck deraadt


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.60 03-Jul-2011 oga

Rip out and burn support for UVM_HIST.

The vm hackers don't use it, don't maintain it and have to look at it all the
time. About time this 800 lines of code hit /dev/null.

``never liked it'' tedu@. ariane@ was very happy when i told her i wrote
this diff.


# 1.59 15-Apr-2011 oga

for uvm_pager_dropcluster in the PG_RELEASED case we specifically unbusy the
page so that um_anfree will free it for us.

uvm_anfree does a pmap_page_protect(, VM_PROT_NONE) just before it frees the
page, so we don't need to do it here ourselves.

ok ariane@


# 1.58 15-Apr-2011 oga

move uvm_pageratop from uvm_pager.c local to a general uvm function
(uvm_atopg) and use it in uvm_km_doputpage to replace some handrolled
code. Shrinks the kernel a trivial amount.

ok beck@ and miod@ (who suggested i name it uvm_atopg not uvm_atop)


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.57 24-Jul-2010 kettenis

Don't sleep while holding the uvm_psel_lck mutex. Should fix "locking against
myself" panics that some people have seen over the last year-and-a-half.

Cherry picked from a more complex (and therefore scarier) diff from oga@.

ok tedu@, oga@


# 1.56 27-Jun-2010 oga

Kill another #ifdef UBC chunk that was annoying me while doing something
else.

ok thib@


Revision tags: OPENBSD_4_7_BASE
# 1.55 12-Feb-2010 tedu

introduce a uvm_km_valloc_try function that won't get a lower level lock
for use by the uvm pseg code. this is the path of least resistance until
we sort out how many of these functions we really need. problem found by mikeb
ok kettenis oga


# 1.54 22-Jul-2009 oga

Put the PG_RELEASED changes diff back in.

This has has been tested very very thoroughly on all archs we have
excepting 88k and 68k. Please see cvs log for the individual commit
messages.

ok beck@, thib@


Revision tags: OPENBSD_4_6_BASE
# 1.53 17-Jun-2009 oga

date based reversion of uvm to the 4th May.

More backouts in line with previous ones, this appears to bring us back to a
stable condition.

A machine forced to 64mb of ram cycled 10GB through swap with this diff
and is still running as I type this. Other tests by ariane@ and thib@
also seem to show that it's alright.

ok deraadt@, thib@, ariane@


# 1.52 16-Jun-2009 oga

Backout all the PG_RELEASED changes.

This is for the same reason as the earlier backouts, to avoid the bug
either added or exposed sometime around c2k9. This *should* be the last
one.

prompted by deraadt@

ok ariane@


# 1.51 23-May-2009 oga

More PG_RELEASED cleaning.

similar to the aobj.c changes, this one does vnodes. Vnodes are more
complex because they actaully have to sync to backing store. So firstly,
convert sync to sleep instead of setting released.

Now, for backing store, in the PGO_FREE case, if we set PG_RELEASED
*before* an async io, (nothing else will see it, the page is busy), then
we can ignore the page after the io is done. We could do something
similar for PGO_DEACTIVATE too, but that is another change. On error we
just clear the released flag, nothing else sets it for uobj pages other
than aiodoned.

ok thib@, beck@, ariane@


# 1.50 04-May-2009 oga

Instead of keeping two ints in the uvm structure specifically just to
sleep on them (and otherwise ignore them) sleep on the pointer to the
{aiodoned,pagedaemon}_proc members, and nuke the two extra words.

"no objections" art@, ok beck@.


# 1.49 06-Apr-2009 oga

Instead of doing splbio(); simple_lock(&uvm.aiodoned_lock); just replace
the simple lock with a real lock - a IPL_BIO mutex. While i'm here, make
the sleeping condition one hell of a lot simpler in the aio daemon.

some ideas from and ok art@.


# 1.48 25-Mar-2009 oga

Move all of the pseudo-inline functions in uvm into C files.

By pseudo-inline, I mean that if a certain macro was defined, they would
be inlined. However, no architecture defines that, and none has for a
very very long time. Therefore mainly this just makes the code a damned
sight easier to read. Some k&r -> ansi declarations while I'm in there.

"just commit it" art@. ok weingart@.


# 1.47 20-Mar-2009 oga

While working on some stuff in uvm I've gotten REALLY sick of reading
K&R function declarations, so switch them all over to ansi-style, in
accordance with the prophesy.

"go for it" art@


Revision tags: OPENBSD_4_5_BASE
# 1.46 27-Jan-2009 ariane

Simplify page-out/page-in map management; fix rare pager deadlock.

Ok: miod, tedu


# 1.45 24-Nov-2008 thib

garbage collect uvm_errno2vmerror();

ok miod@, art@


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.44 26-Nov-2007 miod

In uvm_aio_aiodone(), kill the variable-sized array on stack, and use a
fixed size array which size should match any buf; if a bogus buf is passed
to this function, the kernel will KASSERT instead of potentially running out
of stack and having an undefined behaviour.

ok deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.43 06-Jun-2007 deraadt

now that all partition size/offsets are potentially 64-bit, change the
type of all variables to daddr64_t. this includes the APIs for XXsize()
and XXdump(), all range checks inside bio drivers, internal variables
for disklabel handling, and even uvm's swap offsets. re-read numerous
times by otto, miod, krw, thib to look for errors


# 1.42 13-Apr-2007 art

While splitting flags and pqflags might have been a good idea in theory
to separate locking, on most modern machines this is not enough
since operations on short types touch other short types that share the
same word in memory.

Merge pg_flags and pqflags again and now use atomic operations to change
the flags. Also bump wire_count to an int and pg_version might go
int as well, just for alignment.

tested by many, many. ok miod@


# 1.41 04-Apr-2007 art

Mechanically rename the "flags" and "version" fields in struct vm_page
to "pg_flags" and "pg_version", so that they are a bit easier to work with.
Whoever uses generic names like this for a popular struct obviously doesn't
read much code.

Most architectures compile and there are no functionality changes.

deraadt@ ok ("if something fails to compile, we fix that by hand")


# 1.40 25-Mar-2007 art

remove KERN_SUCCESS and use 0 instead.
eyeballed by miod@ and pedro@


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.39 31-Jul-2006 mickey

fix uvmhist #2: args are always u_long so fix missing %d and %x and no %ll; no change for normal code


# 1.38 26-Jul-2006 mickey

fix fmts for UVMHIST_LOG() entries making it more useful on 64bit archs; miod@ ok


Revision tags: OPENBSD_3_8_BASE OPENBSD_3_9_BASE
# 1.37 26-Jul-2005 art

- Make a UVM_OBJ_IS_DEVICE macro.
- Use it to skip device mappings while dumping core.
- Ignore EFAULT errors while dumping core since they can happen
even for valid mappings. Just skip that part of the core file and
let it get automagically zero-filled.

This fixes the broken X core dumps that people have been seeing and also
fixes some other potential problems that could prevent core dumps (mmaps
beyond EOF, etc.).

tedu@ ok


# 1.36 24-May-2005 tedu

add a new field to vm_space and use it to track the number of anon
pages a process uses. this is now the userland "data size" value.
ok art deraadt tdeval. thanks testers.


Revision tags: OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE SMP_SYNC_A SMP_SYNC_B
# 1.35 23-Feb-2004 drahn

sync of pmap_update() calls with NetBSD. pmap_update is defined away on
all architectures but arm, where it is needed.


Revision tags: OPENBSD_3_4_BASE UBC_SYNC_A
# 1.34 29-Mar-2003 mickey

ubchist is not a fully cooked kadaver and though use the other well formed pdhist one until ubc gaets back. art@ ok


Revision tags: OPENBSD_3_3_BASE
# 1.33 29-Oct-2002 art

Since memory deallocation can't fail, remove the error return from
uvm_unmap, uvm_deallocate and a few other functions.
Simplifies some code and reduces diff to the UBC branch.


Revision tags: OPENBSD_3_2_BASE UBC_SYNC_B
# 1.32 24-May-2002 art

Make sure that b_iodone handlers are called at splbio (and splassert(IPL_BIO) in all known callers, just to make sure).


# 1.31 22-May-2002 art

splassert(IPL_BIO) in the b_iodone handlers.


Revision tags: OPENBSD_3_1_BASE
# 1.30 02-Jan-2002 miod

Back out a few more uvm changes, especially wrt swap usage.
This unbreaks m68k m88k sparc and perhaps others, which eventually froze
when hitting swap.
Tested by various people on various platforms.
ok art@


# 1.29 19-Dec-2001 art

UBC was a disaster. It worked very good when it worked, but on some
machines or some configurations or in some phase of the moon (we actually
don't know when or why) files disappeared. Since we've not been able to
track down the problem in two weeks intense debugging and we need -current
to be stable, back out everything to a state it had before UBC.

We apologise for the inconvenience.


Revision tags: UBC_BASE
# 1.28 04-Dec-2001 art

branches: 1.28.2;
Yet another sync to NetBSD uvm.
Today we add a pmap argument to pmap_update() and allocate map entries for
kernel_map from kmem_map instead of using the static entries. This should
get rid of MAX_KMAPENT panics. Also some uvm_loan problems are fixed.


# 1.27 30-Nov-2001 csapuntz

Call buf_cleanout, which handles wakeups


# 1.26 29-Nov-2001 art

Correctly handle b_vp with bgetvp and brelvp in {get,put}pages.
Prevents panics caused by vnodes being recycled under our feet.


# 1.25 28-Nov-2001 art

Sync in more uvm from NetBSD. Mostly just cosmetic stuff.
Contains also support for page coloring.


# 1.24 28-Nov-2001 art

Sync in more uvm changes from NetBSD.
This time we're getting rid of KERN_* and VM_PAGER_* error codes and
use errnos instead.


# 1.23 27-Nov-2001 art

Merge in the unified buffer cache code as found in NetBSD 2001/03/10. The
code is written mostly by Chuck Silvers <chuq@chuq.com>/<chs@netbsd.org>.

Tested for the past few weeks by many developers, should be in a pretty stable
state, but will require optimizations and additional cleanups.


# 1.22 12-Nov-2001 art

Bring in more changes from NetBSD. Mostly pagedaemon improvements.


# 1.21 10-Nov-2001 art

Merge in some parts of the ubc work that has been done in NetBSD that are not
UBC, but prerequsites for it.

- Create a daemon that processes async I/O (swap and paging in the future)
requests that need processing in process context and that were processed
in the pagedaemon before.
- Convert some ugly ifdef DIAGNOSTIC code to less intrusive KASSERTs.
- misc other cleanups.


# 1.20 07-Nov-2001 art

Another sync of uvm to NetBSD. Just minor fiddling, no major changes.


# 1.19 07-Nov-2001 art

Add an alignment argument to uvm_map that specifies an alignment hint
for the virtual address.


# 1.18 06-Nov-2001 art

Move the last content from vm/ to uvm/
The only thing left in vm/ are just dumb wrappers.
vm/vm.h includes uvm/uvm_extern.h
vm/pmap.h includes uvm/uvm_pmap.h
vm/vm_page.h includes uvm/uvm_page.h


# 1.17 05-Nov-2001 art

Minor sync to NetBSD.


Revision tags: OPENBSD_3_0_BASE
# 1.16 20-Sep-2001 mpech

occured->occurred

idea from deraadt@ via NetBSD
millert@ ok


# 1.15 19-Sep-2001 mickey

merge vm/vm_kern.h into uvm/uvm_extern.h; art@ ok


# 1.14 11-Aug-2001 art

Various random fixes from NetBSD.
Including support for zeroing pages in the idle loop (not enabled yet).


# 1.13 06-Aug-2001 art

Add a new type voff_t (right now it's typedefed as off_t) used for offsets
into objects.

Gives the possibilty to mmap beyond the size of vaddr_t.

From NetBSD.


# 1.12 26-Jul-2001 art

Add support for disabling swap devices (swapctl -d).
Improve error handling on I/O errors to swap.
From NetBSD


# 1.11 25-Jul-2001 art

Change the pmap_enter interface to merge access_type and the wired boolean
and arbitrary flags into one argument.

One new flag is PMAP_CANFAIL that tells pmap_enter that it can fail if there
are not enough resources to satisfy the request. If this flag is not passed,
pmap_enter should panic as it should have done before this change (XXX - many
pmaps are still not doing that).

Only i386 and alpha implement CANFAIL for now.

Includes uvm updates from NetBSD.


# 1.10 18-Jul-2001 art

Get rid of the PMAP_NEW option by making it mandatory for all archs.
The archs that didn't have a proper PMAP_NEW now have a dummy implementation
with wrappers around the old functions.


# 1.9 08-Jun-2001 art

Change the paddr_t pmap_extract(struct pmap *, vaddr_t) interface to
boolean_t pmap_extract(struct pmap *, vaddr_t, paddr_t *).
Matches NetBSD. Tested by various people on various platforms.


Revision tags: OPENBSD_2_9_BASE
# 1.8 22-Mar-2001 smart

Sync style, typo, and comments a little closer to NetBSD. art@ ok


# 1.7 08-Mar-2001 smart

Replace thread_wakeup() with wakeup(). It is defined in vm_extern.h as a
wrapper, so this removes a dependence on the old VM system. From NetBSD.
art@ ok


# 1.6 29-Jan-2001 niklas

$OpenBSD$


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE
# 1.5 16-Mar-2000 art

Bring in some new UVM code from NetBSD (not current).

- Introduce a new type of map that are interrupt safe and never allow faults
in them. mb_map and kmem_map are made intrsafe.
- Add "access protection" to uvm_vslock (to be passed down to uvm_fault and
later to pmap_enter).
- madvise(2) now works.
- various cleanups.


Revision tags: OPENBSD_2_6_BASE SMP_BASE kame_19991208
# 1.4 03-Sep-1999 art

branches: 1.4.4;
Change the pmap_enter api to pass down an argument that indicates
the access type that caused this mapping. This is to simplify pmaps
with mod/ref emulation (none for the moment) and in some cases speed
up pmap_is_{referenced,modified}.
At the same time, clean up some mappings that had too high protection.

XXX - the access type is incorrect in old vm, it's only used by uvm and MD code.
The actual use of this in pmap_enter implementations is not in this commit.


# 1.3 23-Aug-1999 art

sync with NetBSD from 1999.05.24 (there is a reason for this date)
Mostly cleanups, but also a few improvements to pagedaemon for better
handling of low memory and/or low swap conditions.


Revision tags: OPENBSD_2_5_BASE
# 1.2 26-Feb-1999 art

add OpenBSD tags


# 1.1 26-Feb-1999 art

Import of uvm from NetBSD. Some local changes, some code disabled


# 1.85 24-Jul-2022 mpi

Revert simplification of the aiodone daemon it breaks swap on arm64.

Found the hard way by mlarkin@ and deraadt@.


# 1.84 17-Jul-2022 kettenis

Revert the changes made in rev 1.82. It is important to use pmap_enter(9)
and pmap_remove(9) here since we're dealing with managed pages here. Found
out the hard way by deraadt@ on landisk where we're running into issues
with virtual cache aliases because multiple mappings exist for the
pages we're dealing with here. The pmap_enter(9) and pmap_remove(9)
functions handle conflicting cache aliases, whereas pmap_map_direct(9) and
pmap_kenter_pa(9) assume that the pages is exclusively mapped in the kernel
pmap.

ok deraadt@


# 1.83 11-Jul-2022 mpi

Simplify the aiodone daemon which is only used for async writes.

- Remove unused support for asynchronous read, including error conditions

- Grab the proper lock for each page that has been written to swap. This
allows to enable an assertion in uvm_page_unbusy().

- Move the uvm_anon_release() call outside of uvm_page_unbusy() and
assert for the different anon cases.

ok beck@, kettenis@


# 1.82 30-Jun-2022 mpi

Reduce allocations and possible failures in uvm_pagermapin/out().

. If a direct map exists use it to map single-page allocations
. Use pmap_kenter_pa() instead of pmap_enter() in all other cases.

This speeds up file-based mmap up to 75% when I/O are performed and it
also reduces possible allocations failtures in the page daemon making
it more stable in OOM situations.

ok kettenis@, beck@


# 1.81 28-Jun-2022 mpi

Reserve a second segment for the page daemon.

This ensures uvm_swap_io() can succeeds even in OOM situations because two
uvm_pagermapin() allocations, requiring a segment each, are needed to bounce
or encrypt a swap cluster.

ok beck@, kettenis@


# 1.80 28-Jun-2022 mpi

Move the guts of uvm_aio_aiodone() into a separate function.

This will help dealing with error cases.

No functionnal changes.


# 1.79 28-Jun-2022 mpi

Do not clean PG_BUSY before calling uvm_anon_release().

Fix an assertion reported by gkoehler@.

ok kettenis@


Revision tags: OPENBSD_7_1_BASE
# 1.78 18-Feb-2022 kettenis

Convert KVA allocation to km_alloc(9).

ok mpi@


# 1.77 15-Dec-2021 mpi

Use a per-UVM object lock to serialize the lower part of the fault handler.

Like the per-amap lock the `vmobjlock' is principally used to serialized
access to objects in the fault handler to allow faults occurring on
different CPUs and different objects to be processed in parallel.

The fault handler now acquires the `vmobjlock' of a given UVM object as
soon as it finds one. For now a write-lock is always acquired even if
some operations could use a read-lock.

Every pager, corresponding to a different kind of UVM object, now expect
the UVM object to be locked and some operations, like *_get() return it
unlocked. This is enforced by assertions checking for rw_write_held().

The KERNEL_LOCK() is now pushed to the VFS boundary in the vnode pager.

To ensure the correct amap or object lock is held when modifying a page
many uvm_page* operations are now asserting for the "owner" lock.
However, fields of the "struct vm_page" are still being protected by the
global `pageqlock'. To prevent lock ordering issues with the new
`vmobjlock' and to reduce differences with NetBSD this lock is now taken
and released for each page instead of around the whole loop.

This commit does not remove the KERNEL_LOCK/UNLOCK() dance. Unlocking
will follow if there is no fallout.

Ported from NetBSD, tested by many, thanks!

ok kettenis@, kn@


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.76 26-Mar-2021 mpi

Remove parenthesis around return value to reduce the diff with NetBSD.

No functional change.

ok mlarkin@


# 1.75 12-Mar-2021 jsg

spelling

ok mpi@


# 1.74 19-Jan-2021 mpi

(re)Introduce locking for amaps & anons.

A rwlock is attached to every amap and is shared with all its anon. The
same lock will be used by multiple amaps if they have anons in common.

This should be enough to get the upper part of the fault handler out of the
KERNEL_LOCK() which seems to bring up to 20% improvements in builds.

This is based/copied/adapted from the most recent work done in NetBSD which
is an evolution of the precendent simple_lock scheme.

Tested by many, thanks!

ok kettenis@, mvs@


# 1.73 21-Oct-2020 mpi

Constify and use C99 initializer for "struct uvm_pagerops".

While here put some KERNEL_ASSERT_LOCKED() in the functions called from
the page fault handler. The removal of locking of `uobj' will need to be
revisited and these are good indicator that something is missing and that
many comments are lying.

ok kettenis


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.72 08-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok visa@, jca@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.71 17-Dec-2014 tedu

remove lock.h from uvm_extern.h. another holdover from the simpletonlock
era. fix uvm including c files to include lock.h or atomic.h as necessary.
ok deraadt


# 1.70 16-Nov-2014 deraadt

Replace a plethora of historical protection options with just
PROT_NONE, PROT_READ, PROT_WRITE, and PROT_EXEC from mman.h.
PROT_MASK is introduced as the one true way of extracting those bits.
Remove UVM_ADV_* wrapper, using the standard names.
ok doug guenther kettenis


# 1.69 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.68 11-Jul-2014 jsg

Chuck Cranor rescinded clauses in his license
on the 2nd of February 2011 in NetBSD.

http://marc.info/?l=netbsd-source-changes&m=129658899212732&w=2
http://marc.info/?l=netbsd-source-changes&m=129659095515558&w=2
http://marc.info/?l=netbsd-source-changes&m=129659157916514&w=2
http://marc.info/?l=netbsd-source-changes&m=129665962324372&w=2
http://marc.info/?l=netbsd-source-changes&m=129666033625342&w=2
http://marc.info/?l=netbsd-source-changes&m=129666052825545&w=2
http://marc.info/?l=netbsd-source-changes&m=129666922906480&w=2
http://marc.info/?l=netbsd-source-changes&m=129667725518082&w=2


# 1.67 09-May-2014 tedu

stop using B_AGE, it was effectively retired some time ago.


# 1.66 08-May-2014 kettenis

Fix some potential integer overflows caused by converting a page number into
an offset/size/address by shifting by PAGE_SHIFT. Make uvm_objwrire/unwire
use voff_t instead of off_t. The former is the right type here even if it is
equivalent to the latter.

Inspired by a somewhat similar changes in Bitrig.

ok deraadt@, guenther@


# 1.65 13-Apr-2014 tedu

compress code by turning four line comments into one line comments.
emphatic ok usual suspects, grudging ok miod


Revision tags: OPENBSD_5_5_BASE
# 1.64 02-Nov-2013 krw

No need to cast constants or simple variables to (daddr_t). Use
(u_int64_t) instead of (daddr_t) when casting a variable in an
expression passed to DL_SETDSIZE().

Change a variable counting open files from daddr_t to int64_t.

ok deraadt@ with the tweak to fix that pesky expression.


Revision tags: OPENBSD_5_4_BASE
# 1.63 11-Jun-2013 deraadt

final removal of daddr64_t. daddr_t has been 64 bit for a long enough
test period; i think 3 years ago the last bugs fell out.
ok otto beck others


# 1.62 30-May-2013 tedu

remove lots of comments about locking per beck's request


# 1.61 30-May-2013 tedu

remove simple_locks from uvm code. ok beck deraadt


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.60 03-Jul-2011 oga

Rip out and burn support for UVM_HIST.

The vm hackers don't use it, don't maintain it and have to look at it all the
time. About time this 800 lines of code hit /dev/null.

``never liked it'' tedu@. ariane@ was very happy when i told her i wrote
this diff.


# 1.59 15-Apr-2011 oga

for uvm_pager_dropcluster in the PG_RELEASED case we specifically unbusy the
page so that um_anfree will free it for us.

uvm_anfree does a pmap_page_protect(, VM_PROT_NONE) just before it frees the
page, so we don't need to do it here ourselves.

ok ariane@


# 1.58 15-Apr-2011 oga

move uvm_pageratop from uvm_pager.c local to a general uvm function
(uvm_atopg) and use it in uvm_km_doputpage to replace some handrolled
code. Shrinks the kernel a trivial amount.

ok beck@ and miod@ (who suggested i name it uvm_atopg not uvm_atop)


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.57 24-Jul-2010 kettenis

Don't sleep while holding the uvm_psel_lck mutex. Should fix "locking against
myself" panics that some people have seen over the last year-and-a-half.

Cherry picked from a more complex (and therefore scarier) diff from oga@.

ok tedu@, oga@


# 1.56 27-Jun-2010 oga

Kill another #ifdef UBC chunk that was annoying me while doing something
else.

ok thib@


Revision tags: OPENBSD_4_7_BASE
# 1.55 12-Feb-2010 tedu

introduce a uvm_km_valloc_try function that won't get a lower level lock
for use by the uvm pseg code. this is the path of least resistance until
we sort out how many of these functions we really need. problem found by mikeb
ok kettenis oga


# 1.54 22-Jul-2009 oga

Put the PG_RELEASED changes diff back in.

This has has been tested very very thoroughly on all archs we have
excepting 88k and 68k. Please see cvs log for the individual commit
messages.

ok beck@, thib@


Revision tags: OPENBSD_4_6_BASE
# 1.53 17-Jun-2009 oga

date based reversion of uvm to the 4th May.

More backouts in line with previous ones, this appears to bring us back to a
stable condition.

A machine forced to 64mb of ram cycled 10GB through swap with this diff
and is still running as I type this. Other tests by ariane@ and thib@
also seem to show that it's alright.

ok deraadt@, thib@, ariane@


# 1.52 16-Jun-2009 oga

Backout all the PG_RELEASED changes.

This is for the same reason as the earlier backouts, to avoid the bug
either added or exposed sometime around c2k9. This *should* be the last
one.

prompted by deraadt@

ok ariane@


# 1.51 23-May-2009 oga

More PG_RELEASED cleaning.

similar to the aobj.c changes, this one does vnodes. Vnodes are more
complex because they actaully have to sync to backing store. So firstly,
convert sync to sleep instead of setting released.

Now, for backing store, in the PGO_FREE case, if we set PG_RELEASED
*before* an async io, (nothing else will see it, the page is busy), then
we can ignore the page after the io is done. We could do something
similar for PGO_DEACTIVATE too, but that is another change. On error we
just clear the released flag, nothing else sets it for uobj pages other
than aiodoned.

ok thib@, beck@, ariane@


# 1.50 04-May-2009 oga

Instead of keeping two ints in the uvm structure specifically just to
sleep on them (and otherwise ignore them) sleep on the pointer to the
{aiodoned,pagedaemon}_proc members, and nuke the two extra words.

"no objections" art@, ok beck@.


# 1.49 06-Apr-2009 oga

Instead of doing splbio(); simple_lock(&uvm.aiodoned_lock); just replace
the simple lock with a real lock - a IPL_BIO mutex. While i'm here, make
the sleeping condition one hell of a lot simpler in the aio daemon.

some ideas from and ok art@.


# 1.48 25-Mar-2009 oga

Move all of the pseudo-inline functions in uvm into C files.

By pseudo-inline, I mean that if a certain macro was defined, they would
be inlined. However, no architecture defines that, and none has for a
very very long time. Therefore mainly this just makes the code a damned
sight easier to read. Some k&r -> ansi declarations while I'm in there.

"just commit it" art@. ok weingart@.


# 1.47 20-Mar-2009 oga

While working on some stuff in uvm I've gotten REALLY sick of reading
K&R function declarations, so switch them all over to ansi-style, in
accordance with the prophesy.

"go for it" art@


Revision tags: OPENBSD_4_5_BASE
# 1.46 27-Jan-2009 ariane

Simplify page-out/page-in map management; fix rare pager deadlock.

Ok: miod, tedu


# 1.45 24-Nov-2008 thib

garbage collect uvm_errno2vmerror();

ok miod@, art@


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.44 26-Nov-2007 miod

In uvm_aio_aiodone(), kill the variable-sized array on stack, and use a
fixed size array which size should match any buf; if a bogus buf is passed
to this function, the kernel will KASSERT instead of potentially running out
of stack and having an undefined behaviour.

ok deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.43 06-Jun-2007 deraadt

now that all partition size/offsets are potentially 64-bit, change the
type of all variables to daddr64_t. this includes the APIs for XXsize()
and XXdump(), all range checks inside bio drivers, internal variables
for disklabel handling, and even uvm's swap offsets. re-read numerous
times by otto, miod, krw, thib to look for errors


# 1.42 13-Apr-2007 art

While splitting flags and pqflags might have been a good idea in theory
to separate locking, on most modern machines this is not enough
since operations on short types touch other short types that share the
same word in memory.

Merge pg_flags and pqflags again and now use atomic operations to change
the flags. Also bump wire_count to an int and pg_version might go
int as well, just for alignment.

tested by many, many. ok miod@


# 1.41 04-Apr-2007 art

Mechanically rename the "flags" and "version" fields in struct vm_page
to "pg_flags" and "pg_version", so that they are a bit easier to work with.
Whoever uses generic names like this for a popular struct obviously doesn't
read much code.

Most architectures compile and there are no functionality changes.

deraadt@ ok ("if something fails to compile, we fix that by hand")


# 1.40 25-Mar-2007 art

remove KERN_SUCCESS and use 0 instead.
eyeballed by miod@ and pedro@


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.39 31-Jul-2006 mickey

fix uvmhist #2: args are always u_long so fix missing %d and %x and no %ll; no change for normal code


# 1.38 26-Jul-2006 mickey

fix fmts for UVMHIST_LOG() entries making it more useful on 64bit archs; miod@ ok


Revision tags: OPENBSD_3_8_BASE OPENBSD_3_9_BASE
# 1.37 26-Jul-2005 art

- Make a UVM_OBJ_IS_DEVICE macro.
- Use it to skip device mappings while dumping core.
- Ignore EFAULT errors while dumping core since they can happen
even for valid mappings. Just skip that part of the core file and
let it get automagically zero-filled.

This fixes the broken X core dumps that people have been seeing and also
fixes some other potential problems that could prevent core dumps (mmaps
beyond EOF, etc.).

tedu@ ok


# 1.36 24-May-2005 tedu

add a new field to vm_space and use it to track the number of anon
pages a process uses. this is now the userland "data size" value.
ok art deraadt tdeval. thanks testers.


Revision tags: OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE SMP_SYNC_A SMP_SYNC_B
# 1.35 23-Feb-2004 drahn

sync of pmap_update() calls with NetBSD. pmap_update is defined away on
all architectures but arm, where it is needed.


Revision tags: OPENBSD_3_4_BASE UBC_SYNC_A
# 1.34 29-Mar-2003 mickey

ubchist is not a fully cooked kadaver and though use the other well formed pdhist one until ubc gaets back. art@ ok


Revision tags: OPENBSD_3_3_BASE
# 1.33 29-Oct-2002 art

Since memory deallocation can't fail, remove the error return from
uvm_unmap, uvm_deallocate and a few other functions.
Simplifies some code and reduces diff to the UBC branch.


Revision tags: OPENBSD_3_2_BASE UBC_SYNC_B
# 1.32 24-May-2002 art

Make sure that b_iodone handlers are called at splbio (and splassert(IPL_BIO) in all known callers, just to make sure).


# 1.31 22-May-2002 art

splassert(IPL_BIO) in the b_iodone handlers.


Revision tags: OPENBSD_3_1_BASE
# 1.30 02-Jan-2002 miod

Back out a few more uvm changes, especially wrt swap usage.
This unbreaks m68k m88k sparc and perhaps others, which eventually froze
when hitting swap.
Tested by various people on various platforms.
ok art@


# 1.29 19-Dec-2001 art

UBC was a disaster. It worked very good when it worked, but on some
machines or some configurations or in some phase of the moon (we actually
don't know when or why) files disappeared. Since we've not been able to
track down the problem in two weeks intense debugging and we need -current
to be stable, back out everything to a state it had before UBC.

We apologise for the inconvenience.


Revision tags: UBC_BASE
# 1.28 04-Dec-2001 art

branches: 1.28.2;
Yet another sync to NetBSD uvm.
Today we add a pmap argument to pmap_update() and allocate map entries for
kernel_map from kmem_map instead of using the static entries. This should
get rid of MAX_KMAPENT panics. Also some uvm_loan problems are fixed.


# 1.27 30-Nov-2001 csapuntz

Call buf_cleanout, which handles wakeups


# 1.26 29-Nov-2001 art

Correctly handle b_vp with bgetvp and brelvp in {get,put}pages.
Prevents panics caused by vnodes being recycled under our feet.


# 1.25 28-Nov-2001 art

Sync in more uvm from NetBSD. Mostly just cosmetic stuff.
Contains also support for page coloring.


# 1.24 28-Nov-2001 art

Sync in more uvm changes from NetBSD.
This time we're getting rid of KERN_* and VM_PAGER_* error codes and
use errnos instead.


# 1.23 27-Nov-2001 art

Merge in the unified buffer cache code as found in NetBSD 2001/03/10. The
code is written mostly by Chuck Silvers <chuq@chuq.com>/<chs@netbsd.org>.

Tested for the past few weeks by many developers, should be in a pretty stable
state, but will require optimizations and additional cleanups.


# 1.22 12-Nov-2001 art

Bring in more changes from NetBSD. Mostly pagedaemon improvements.


# 1.21 10-Nov-2001 art

Merge in some parts of the ubc work that has been done in NetBSD that are not
UBC, but prerequsites for it.

- Create a daemon that processes async I/O (swap and paging in the future)
requests that need processing in process context and that were processed
in the pagedaemon before.
- Convert some ugly ifdef DIAGNOSTIC code to less intrusive KASSERTs.
- misc other cleanups.


# 1.20 07-Nov-2001 art

Another sync of uvm to NetBSD. Just minor fiddling, no major changes.


# 1.19 07-Nov-2001 art

Add an alignment argument to uvm_map that specifies an alignment hint
for the virtual address.


# 1.18 06-Nov-2001 art

Move the last content from vm/ to uvm/
The only thing left in vm/ are just dumb wrappers.
vm/vm.h includes uvm/uvm_extern.h
vm/pmap.h includes uvm/uvm_pmap.h
vm/vm_page.h includes uvm/uvm_page.h


# 1.17 05-Nov-2001 art

Minor sync to NetBSD.


Revision tags: OPENBSD_3_0_BASE
# 1.16 20-Sep-2001 mpech

occured->occurred

idea from deraadt@ via NetBSD
millert@ ok


# 1.15 19-Sep-2001 mickey

merge vm/vm_kern.h into uvm/uvm_extern.h; art@ ok


# 1.14 11-Aug-2001 art

Various random fixes from NetBSD.
Including support for zeroing pages in the idle loop (not enabled yet).


# 1.13 06-Aug-2001 art

Add a new type voff_t (right now it's typedefed as off_t) used for offsets
into objects.

Gives the possibilty to mmap beyond the size of vaddr_t.

From NetBSD.


# 1.12 26-Jul-2001 art

Add support for disabling swap devices (swapctl -d).
Improve error handling on I/O errors to swap.
From NetBSD


# 1.11 25-Jul-2001 art

Change the pmap_enter interface to merge access_type and the wired boolean
and arbitrary flags into one argument.

One new flag is PMAP_CANFAIL that tells pmap_enter that it can fail if there
are not enough resources to satisfy the request. If this flag is not passed,
pmap_enter should panic as it should have done before this change (XXX - many
pmaps are still not doing that).

Only i386 and alpha implement CANFAIL for now.

Includes uvm updates from NetBSD.


# 1.10 18-Jul-2001 art

Get rid of the PMAP_NEW option by making it mandatory for all archs.
The archs that didn't have a proper PMAP_NEW now have a dummy implementation
with wrappers around the old functions.


# 1.9 08-Jun-2001 art

Change the paddr_t pmap_extract(struct pmap *, vaddr_t) interface to
boolean_t pmap_extract(struct pmap *, vaddr_t, paddr_t *).
Matches NetBSD. Tested by various people on various platforms.


Revision tags: OPENBSD_2_9_BASE
# 1.8 22-Mar-2001 smart

Sync style, typo, and comments a little closer to NetBSD. art@ ok


# 1.7 08-Mar-2001 smart

Replace thread_wakeup() with wakeup(). It is defined in vm_extern.h as a
wrapper, so this removes a dependence on the old VM system. From NetBSD.
art@ ok


# 1.6 29-Jan-2001 niklas

$OpenBSD$


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE
# 1.5 16-Mar-2000 art

Bring in some new UVM code from NetBSD (not current).

- Introduce a new type of map that are interrupt safe and never allow faults
in them. mb_map and kmem_map are made intrsafe.
- Add "access protection" to uvm_vslock (to be passed down to uvm_fault and
later to pmap_enter).
- madvise(2) now works.
- various cleanups.


Revision tags: OPENBSD_2_6_BASE SMP_BASE kame_19991208
# 1.4 03-Sep-1999 art

branches: 1.4.4;
Change the pmap_enter api to pass down an argument that indicates
the access type that caused this mapping. This is to simplify pmaps
with mod/ref emulation (none for the moment) and in some cases speed
up pmap_is_{referenced,modified}.
At the same time, clean up some mappings that had too high protection.

XXX - the access type is incorrect in old vm, it's only used by uvm and MD code.
The actual use of this in pmap_enter implementations is not in this commit.


# 1.3 23-Aug-1999 art

sync with NetBSD from 1999.05.24 (there is a reason for this date)
Mostly cleanups, but also a few improvements to pagedaemon for better
handling of low memory and/or low swap conditions.


Revision tags: OPENBSD_2_5_BASE
# 1.2 26-Feb-1999 art

add OpenBSD tags


# 1.1 26-Feb-1999 art

Import of uvm from NetBSD. Some local changes, some code disabled


# 1.84 17-Jul-2022 kettenis

Revert the changes made in rev 1.82. It is important to use pmap_enter(9)
and pmap_remove(9) here since we're dealing with managed pages here. Found
out the hard way by deraadt@ on landisk where we're running into issues
with virtual cache aliases because multiple mappings exist for the
pages we're dealing with here. The pmap_enter(9) and pmap_remove(9)
functions handle conflicting cache aliases, whereas pmap_map_direct(9) and
pmap_kenter_pa(9) assume that the pages is exclusively mapped in the kernel
pmap.

ok deraadt@


# 1.83 11-Jul-2022 mpi

Simplify the aiodone daemon which is only used for async writes.

- Remove unused support for asynchronous read, including error conditions

- Grab the proper lock for each page that has been written to swap. This
allows to enable an assertion in uvm_page_unbusy().

- Move the uvm_anon_release() call outside of uvm_page_unbusy() and
assert for the different anon cases.

ok beck@, kettenis@


# 1.82 30-Jun-2022 mpi

Reduce allocations and possible failures in uvm_pagermapin/out().

. If a direct map exists use it to map single-page allocations
. Use pmap_kenter_pa() instead of pmap_enter() in all other cases.

This speeds up file-based mmap up to 75% when I/O are performed and it
also reduces possible allocations failtures in the page daemon making
it more stable in OOM situations.

ok kettenis@, beck@


# 1.81 28-Jun-2022 mpi

Reserve a second segment for the page daemon.

This ensures uvm_swap_io() can succeeds even in OOM situations because two
uvm_pagermapin() allocations, requiring a segment each, are needed to bounce
or encrypt a swap cluster.

ok beck@, kettenis@


# 1.80 28-Jun-2022 mpi

Move the guts of uvm_aio_aiodone() into a separate function.

This will help dealing with error cases.

No functionnal changes.


# 1.79 28-Jun-2022 mpi

Do not clean PG_BUSY before calling uvm_anon_release().

Fix an assertion reported by gkoehler@.

ok kettenis@


Revision tags: OPENBSD_7_1_BASE
# 1.78 18-Feb-2022 kettenis

Convert KVA allocation to km_alloc(9).

ok mpi@


# 1.77 15-Dec-2021 mpi

Use a per-UVM object lock to serialize the lower part of the fault handler.

Like the per-amap lock the `vmobjlock' is principally used to serialized
access to objects in the fault handler to allow faults occurring on
different CPUs and different objects to be processed in parallel.

The fault handler now acquires the `vmobjlock' of a given UVM object as
soon as it finds one. For now a write-lock is always acquired even if
some operations could use a read-lock.

Every pager, corresponding to a different kind of UVM object, now expect
the UVM object to be locked and some operations, like *_get() return it
unlocked. This is enforced by assertions checking for rw_write_held().

The KERNEL_LOCK() is now pushed to the VFS boundary in the vnode pager.

To ensure the correct amap or object lock is held when modifying a page
many uvm_page* operations are now asserting for the "owner" lock.
However, fields of the "struct vm_page" are still being protected by the
global `pageqlock'. To prevent lock ordering issues with the new
`vmobjlock' and to reduce differences with NetBSD this lock is now taken
and released for each page instead of around the whole loop.

This commit does not remove the KERNEL_LOCK/UNLOCK() dance. Unlocking
will follow if there is no fallout.

Ported from NetBSD, tested by many, thanks!

ok kettenis@, kn@


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.76 26-Mar-2021 mpi

Remove parenthesis around return value to reduce the diff with NetBSD.

No functional change.

ok mlarkin@


# 1.75 12-Mar-2021 jsg

spelling

ok mpi@


# 1.74 19-Jan-2021 mpi

(re)Introduce locking for amaps & anons.

A rwlock is attached to every amap and is shared with all its anon. The
same lock will be used by multiple amaps if they have anons in common.

This should be enough to get the upper part of the fault handler out of the
KERNEL_LOCK() which seems to bring up to 20% improvements in builds.

This is based/copied/adapted from the most recent work done in NetBSD which
is an evolution of the precendent simple_lock scheme.

Tested by many, thanks!

ok kettenis@, mvs@


# 1.73 21-Oct-2020 mpi

Constify and use C99 initializer for "struct uvm_pagerops".

While here put some KERNEL_ASSERT_LOCKED() in the functions called from
the page fault handler. The removal of locking of `uobj' will need to be
revisited and these are good indicator that something is missing and that
many comments are lying.

ok kettenis


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.72 08-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok visa@, jca@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.71 17-Dec-2014 tedu

remove lock.h from uvm_extern.h. another holdover from the simpletonlock
era. fix uvm including c files to include lock.h or atomic.h as necessary.
ok deraadt


# 1.70 16-Nov-2014 deraadt

Replace a plethora of historical protection options with just
PROT_NONE, PROT_READ, PROT_WRITE, and PROT_EXEC from mman.h.
PROT_MASK is introduced as the one true way of extracting those bits.
Remove UVM_ADV_* wrapper, using the standard names.
ok doug guenther kettenis


# 1.69 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.68 11-Jul-2014 jsg

Chuck Cranor rescinded clauses in his license
on the 2nd of February 2011 in NetBSD.

http://marc.info/?l=netbsd-source-changes&m=129658899212732&w=2
http://marc.info/?l=netbsd-source-changes&m=129659095515558&w=2
http://marc.info/?l=netbsd-source-changes&m=129659157916514&w=2
http://marc.info/?l=netbsd-source-changes&m=129665962324372&w=2
http://marc.info/?l=netbsd-source-changes&m=129666033625342&w=2
http://marc.info/?l=netbsd-source-changes&m=129666052825545&w=2
http://marc.info/?l=netbsd-source-changes&m=129666922906480&w=2
http://marc.info/?l=netbsd-source-changes&m=129667725518082&w=2


# 1.67 09-May-2014 tedu

stop using B_AGE, it was effectively retired some time ago.


# 1.66 08-May-2014 kettenis

Fix some potential integer overflows caused by converting a page number into
an offset/size/address by shifting by PAGE_SHIFT. Make uvm_objwrire/unwire
use voff_t instead of off_t. The former is the right type here even if it is
equivalent to the latter.

Inspired by a somewhat similar changes in Bitrig.

ok deraadt@, guenther@


# 1.65 13-Apr-2014 tedu

compress code by turning four line comments into one line comments.
emphatic ok usual suspects, grudging ok miod


Revision tags: OPENBSD_5_5_BASE
# 1.64 02-Nov-2013 krw

No need to cast constants or simple variables to (daddr_t). Use
(u_int64_t) instead of (daddr_t) when casting a variable in an
expression passed to DL_SETDSIZE().

Change a variable counting open files from daddr_t to int64_t.

ok deraadt@ with the tweak to fix that pesky expression.


Revision tags: OPENBSD_5_4_BASE
# 1.63 11-Jun-2013 deraadt

final removal of daddr64_t. daddr_t has been 64 bit for a long enough
test period; i think 3 years ago the last bugs fell out.
ok otto beck others


# 1.62 30-May-2013 tedu

remove lots of comments about locking per beck's request


# 1.61 30-May-2013 tedu

remove simple_locks from uvm code. ok beck deraadt


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.60 03-Jul-2011 oga

Rip out and burn support for UVM_HIST.

The vm hackers don't use it, don't maintain it and have to look at it all the
time. About time this 800 lines of code hit /dev/null.

``never liked it'' tedu@. ariane@ was very happy when i told her i wrote
this diff.


# 1.59 15-Apr-2011 oga

for uvm_pager_dropcluster in the PG_RELEASED case we specifically unbusy the
page so that um_anfree will free it for us.

uvm_anfree does a pmap_page_protect(, VM_PROT_NONE) just before it frees the
page, so we don't need to do it here ourselves.

ok ariane@


# 1.58 15-Apr-2011 oga

move uvm_pageratop from uvm_pager.c local to a general uvm function
(uvm_atopg) and use it in uvm_km_doputpage to replace some handrolled
code. Shrinks the kernel a trivial amount.

ok beck@ and miod@ (who suggested i name it uvm_atopg not uvm_atop)


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.57 24-Jul-2010 kettenis

Don't sleep while holding the uvm_psel_lck mutex. Should fix "locking against
myself" panics that some people have seen over the last year-and-a-half.

Cherry picked from a more complex (and therefore scarier) diff from oga@.

ok tedu@, oga@


# 1.56 27-Jun-2010 oga

Kill another #ifdef UBC chunk that was annoying me while doing something
else.

ok thib@


Revision tags: OPENBSD_4_7_BASE
# 1.55 12-Feb-2010 tedu

introduce a uvm_km_valloc_try function that won't get a lower level lock
for use by the uvm pseg code. this is the path of least resistance until
we sort out how many of these functions we really need. problem found by mikeb
ok kettenis oga


# 1.54 22-Jul-2009 oga

Put the PG_RELEASED changes diff back in.

This has has been tested very very thoroughly on all archs we have
excepting 88k and 68k. Please see cvs log for the individual commit
messages.

ok beck@, thib@


Revision tags: OPENBSD_4_6_BASE
# 1.53 17-Jun-2009 oga

date based reversion of uvm to the 4th May.

More backouts in line with previous ones, this appears to bring us back to a
stable condition.

A machine forced to 64mb of ram cycled 10GB through swap with this diff
and is still running as I type this. Other tests by ariane@ and thib@
also seem to show that it's alright.

ok deraadt@, thib@, ariane@


# 1.52 16-Jun-2009 oga

Backout all the PG_RELEASED changes.

This is for the same reason as the earlier backouts, to avoid the bug
either added or exposed sometime around c2k9. This *should* be the last
one.

prompted by deraadt@

ok ariane@


# 1.51 23-May-2009 oga

More PG_RELEASED cleaning.

similar to the aobj.c changes, this one does vnodes. Vnodes are more
complex because they actaully have to sync to backing store. So firstly,
convert sync to sleep instead of setting released.

Now, for backing store, in the PGO_FREE case, if we set PG_RELEASED
*before* an async io, (nothing else will see it, the page is busy), then
we can ignore the page after the io is done. We could do something
similar for PGO_DEACTIVATE too, but that is another change. On error we
just clear the released flag, nothing else sets it for uobj pages other
than aiodoned.

ok thib@, beck@, ariane@


# 1.50 04-May-2009 oga

Instead of keeping two ints in the uvm structure specifically just to
sleep on them (and otherwise ignore them) sleep on the pointer to the
{aiodoned,pagedaemon}_proc members, and nuke the two extra words.

"no objections" art@, ok beck@.


# 1.49 06-Apr-2009 oga

Instead of doing splbio(); simple_lock(&uvm.aiodoned_lock); just replace
the simple lock with a real lock - a IPL_BIO mutex. While i'm here, make
the sleeping condition one hell of a lot simpler in the aio daemon.

some ideas from and ok art@.


# 1.48 25-Mar-2009 oga

Move all of the pseudo-inline functions in uvm into C files.

By pseudo-inline, I mean that if a certain macro was defined, they would
be inlined. However, no architecture defines that, and none has for a
very very long time. Therefore mainly this just makes the code a damned
sight easier to read. Some k&r -> ansi declarations while I'm in there.

"just commit it" art@. ok weingart@.


# 1.47 20-Mar-2009 oga

While working on some stuff in uvm I've gotten REALLY sick of reading
K&R function declarations, so switch them all over to ansi-style, in
accordance with the prophesy.

"go for it" art@


Revision tags: OPENBSD_4_5_BASE
# 1.46 27-Jan-2009 ariane

Simplify page-out/page-in map management; fix rare pager deadlock.

Ok: miod, tedu


# 1.45 24-Nov-2008 thib

garbage collect uvm_errno2vmerror();

ok miod@, art@


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.44 26-Nov-2007 miod

In uvm_aio_aiodone(), kill the variable-sized array on stack, and use a
fixed size array which size should match any buf; if a bogus buf is passed
to this function, the kernel will KASSERT instead of potentially running out
of stack and having an undefined behaviour.

ok deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.43 06-Jun-2007 deraadt

now that all partition size/offsets are potentially 64-bit, change the
type of all variables to daddr64_t. this includes the APIs for XXsize()
and XXdump(), all range checks inside bio drivers, internal variables
for disklabel handling, and even uvm's swap offsets. re-read numerous
times by otto, miod, krw, thib to look for errors


# 1.42 13-Apr-2007 art

While splitting flags and pqflags might have been a good idea in theory
to separate locking, on most modern machines this is not enough
since operations on short types touch other short types that share the
same word in memory.

Merge pg_flags and pqflags again and now use atomic operations to change
the flags. Also bump wire_count to an int and pg_version might go
int as well, just for alignment.

tested by many, many. ok miod@


# 1.41 04-Apr-2007 art

Mechanically rename the "flags" and "version" fields in struct vm_page
to "pg_flags" and "pg_version", so that they are a bit easier to work with.
Whoever uses generic names like this for a popular struct obviously doesn't
read much code.

Most architectures compile and there are no functionality changes.

deraadt@ ok ("if something fails to compile, we fix that by hand")


# 1.40 25-Mar-2007 art

remove KERN_SUCCESS and use 0 instead.
eyeballed by miod@ and pedro@


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.39 31-Jul-2006 mickey

fix uvmhist #2: args are always u_long so fix missing %d and %x and no %ll; no change for normal code


# 1.38 26-Jul-2006 mickey

fix fmts for UVMHIST_LOG() entries making it more useful on 64bit archs; miod@ ok


Revision tags: OPENBSD_3_8_BASE OPENBSD_3_9_BASE
# 1.37 26-Jul-2005 art

- Make a UVM_OBJ_IS_DEVICE macro.
- Use it to skip device mappings while dumping core.
- Ignore EFAULT errors while dumping core since they can happen
even for valid mappings. Just skip that part of the core file and
let it get automagically zero-filled.

This fixes the broken X core dumps that people have been seeing and also
fixes some other potential problems that could prevent core dumps (mmaps
beyond EOF, etc.).

tedu@ ok


# 1.36 24-May-2005 tedu

add a new field to vm_space and use it to track the number of anon
pages a process uses. this is now the userland "data size" value.
ok art deraadt tdeval. thanks testers.


Revision tags: OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE SMP_SYNC_A SMP_SYNC_B
# 1.35 23-Feb-2004 drahn

sync of pmap_update() calls with NetBSD. pmap_update is defined away on
all architectures but arm, where it is needed.


Revision tags: OPENBSD_3_4_BASE UBC_SYNC_A
# 1.34 29-Mar-2003 mickey

ubchist is not a fully cooked kadaver and though use the other well formed pdhist one until ubc gaets back. art@ ok


Revision tags: OPENBSD_3_3_BASE
# 1.33 29-Oct-2002 art

Since memory deallocation can't fail, remove the error return from
uvm_unmap, uvm_deallocate and a few other functions.
Simplifies some code and reduces diff to the UBC branch.


Revision tags: OPENBSD_3_2_BASE UBC_SYNC_B
# 1.32 24-May-2002 art

Make sure that b_iodone handlers are called at splbio (and splassert(IPL_BIO) in all known callers, just to make sure).


# 1.31 22-May-2002 art

splassert(IPL_BIO) in the b_iodone handlers.


Revision tags: OPENBSD_3_1_BASE
# 1.30 02-Jan-2002 miod

Back out a few more uvm changes, especially wrt swap usage.
This unbreaks m68k m88k sparc and perhaps others, which eventually froze
when hitting swap.
Tested by various people on various platforms.
ok art@


# 1.29 19-Dec-2001 art

UBC was a disaster. It worked very good when it worked, but on some
machines or some configurations or in some phase of the moon (we actually
don't know when or why) files disappeared. Since we've not been able to
track down the problem in two weeks intense debugging and we need -current
to be stable, back out everything to a state it had before UBC.

We apologise for the inconvenience.


Revision tags: UBC_BASE
# 1.28 04-Dec-2001 art

branches: 1.28.2;
Yet another sync to NetBSD uvm.
Today we add a pmap argument to pmap_update() and allocate map entries for
kernel_map from kmem_map instead of using the static entries. This should
get rid of MAX_KMAPENT panics. Also some uvm_loan problems are fixed.


# 1.27 30-Nov-2001 csapuntz

Call buf_cleanout, which handles wakeups


# 1.26 29-Nov-2001 art

Correctly handle b_vp with bgetvp and brelvp in {get,put}pages.
Prevents panics caused by vnodes being recycled under our feet.


# 1.25 28-Nov-2001 art

Sync in more uvm from NetBSD. Mostly just cosmetic stuff.
Contains also support for page coloring.


# 1.24 28-Nov-2001 art

Sync in more uvm changes from NetBSD.
This time we're getting rid of KERN_* and VM_PAGER_* error codes and
use errnos instead.


# 1.23 27-Nov-2001 art

Merge in the unified buffer cache code as found in NetBSD 2001/03/10. The
code is written mostly by Chuck Silvers <chuq@chuq.com>/<chs@netbsd.org>.

Tested for the past few weeks by many developers, should be in a pretty stable
state, but will require optimizations and additional cleanups.


# 1.22 12-Nov-2001 art

Bring in more changes from NetBSD. Mostly pagedaemon improvements.


# 1.21 10-Nov-2001 art

Merge in some parts of the ubc work that has been done in NetBSD that are not
UBC, but prerequsites for it.

- Create a daemon that processes async I/O (swap and paging in the future)
requests that need processing in process context and that were processed
in the pagedaemon before.
- Convert some ugly ifdef DIAGNOSTIC code to less intrusive KASSERTs.
- misc other cleanups.


# 1.20 07-Nov-2001 art

Another sync of uvm to NetBSD. Just minor fiddling, no major changes.


# 1.19 07-Nov-2001 art

Add an alignment argument to uvm_map that specifies an alignment hint
for the virtual address.


# 1.18 06-Nov-2001 art

Move the last content from vm/ to uvm/
The only thing left in vm/ are just dumb wrappers.
vm/vm.h includes uvm/uvm_extern.h
vm/pmap.h includes uvm/uvm_pmap.h
vm/vm_page.h includes uvm/uvm_page.h


# 1.17 05-Nov-2001 art

Minor sync to NetBSD.


Revision tags: OPENBSD_3_0_BASE
# 1.16 20-Sep-2001 mpech

occured->occurred

idea from deraadt@ via NetBSD
millert@ ok


# 1.15 19-Sep-2001 mickey

merge vm/vm_kern.h into uvm/uvm_extern.h; art@ ok


# 1.14 11-Aug-2001 art

Various random fixes from NetBSD.
Including support for zeroing pages in the idle loop (not enabled yet).


# 1.13 06-Aug-2001 art

Add a new type voff_t (right now it's typedefed as off_t) used for offsets
into objects.

Gives the possibilty to mmap beyond the size of vaddr_t.

From NetBSD.


# 1.12 26-Jul-2001 art

Add support for disabling swap devices (swapctl -d).
Improve error handling on I/O errors to swap.
From NetBSD


# 1.11 25-Jul-2001 art

Change the pmap_enter interface to merge access_type and the wired boolean
and arbitrary flags into one argument.

One new flag is PMAP_CANFAIL that tells pmap_enter that it can fail if there
are not enough resources to satisfy the request. If this flag is not passed,
pmap_enter should panic as it should have done before this change (XXX - many
pmaps are still not doing that).

Only i386 and alpha implement CANFAIL for now.

Includes uvm updates from NetBSD.


# 1.10 18-Jul-2001 art

Get rid of the PMAP_NEW option by making it mandatory for all archs.
The archs that didn't have a proper PMAP_NEW now have a dummy implementation
with wrappers around the old functions.


# 1.9 08-Jun-2001 art

Change the paddr_t pmap_extract(struct pmap *, vaddr_t) interface to
boolean_t pmap_extract(struct pmap *, vaddr_t, paddr_t *).
Matches NetBSD. Tested by various people on various platforms.


Revision tags: OPENBSD_2_9_BASE
# 1.8 22-Mar-2001 smart

Sync style, typo, and comments a little closer to NetBSD. art@ ok


# 1.7 08-Mar-2001 smart

Replace thread_wakeup() with wakeup(). It is defined in vm_extern.h as a
wrapper, so this removes a dependence on the old VM system. From NetBSD.
art@ ok


# 1.6 29-Jan-2001 niklas

$OpenBSD$


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE
# 1.5 16-Mar-2000 art

Bring in some new UVM code from NetBSD (not current).

- Introduce a new type of map that are interrupt safe and never allow faults
in them. mb_map and kmem_map are made intrsafe.
- Add "access protection" to uvm_vslock (to be passed down to uvm_fault and
later to pmap_enter).
- madvise(2) now works.
- various cleanups.


Revision tags: OPENBSD_2_6_BASE SMP_BASE kame_19991208
# 1.4 03-Sep-1999 art

branches: 1.4.4;
Change the pmap_enter api to pass down an argument that indicates
the access type that caused this mapping. This is to simplify pmaps
with mod/ref emulation (none for the moment) and in some cases speed
up pmap_is_{referenced,modified}.
At the same time, clean up some mappings that had too high protection.

XXX - the access type is incorrect in old vm, it's only used by uvm and MD code.
The actual use of this in pmap_enter implementations is not in this commit.


# 1.3 23-Aug-1999 art

sync with NetBSD from 1999.05.24 (there is a reason for this date)
Mostly cleanups, but also a few improvements to pagedaemon for better
handling of low memory and/or low swap conditions.


Revision tags: OPENBSD_2_5_BASE
# 1.2 26-Feb-1999 art

add OpenBSD tags


# 1.1 26-Feb-1999 art

Import of uvm from NetBSD. Some local changes, some code disabled


# 1.83 11-Jul-2022 mpi

Simplify the aiodone daemon which is only used for async writes.

- Remove unused support for asynchronous read, including error conditions

- Grab the proper lock for each page that has been written to swap. This
allows to enable an assertion in uvm_page_unbusy().

- Move the uvm_anon_release() call outside of uvm_page_unbusy() and
assert for the different anon cases.

ok beck@, kettenis@


# 1.82 30-Jun-2022 mpi

Reduce allocations and possible failures in uvm_pagermapin/out().

. If a direct map exists use it to map single-page allocations
. Use pmap_kenter_pa() instead of pmap_enter() in all other cases.

This speeds up file-based mmap up to 75% when I/O are performed and it
also reduces possible allocations failtures in the page daemon making
it more stable in OOM situations.

ok kettenis@, beck@


# 1.81 28-Jun-2022 mpi

Reserve a second segment for the page daemon.

This ensures uvm_swap_io() can succeeds even in OOM situations because two
uvm_pagermapin() allocations, requiring a segment each, are needed to bounce
or encrypt a swap cluster.

ok beck@, kettenis@


# 1.80 28-Jun-2022 mpi

Move the guts of uvm_aio_aiodone() into a separate function.

This will help dealing with error cases.

No functionnal changes.


# 1.79 28-Jun-2022 mpi

Do not clean PG_BUSY before calling uvm_anon_release().

Fix an assertion reported by gkoehler@.

ok kettenis@


Revision tags: OPENBSD_7_1_BASE
# 1.78 18-Feb-2022 kettenis

Convert KVA allocation to km_alloc(9).

ok mpi@


# 1.77 15-Dec-2021 mpi

Use a per-UVM object lock to serialize the lower part of the fault handler.

Like the per-amap lock the `vmobjlock' is principally used to serialized
access to objects in the fault handler to allow faults occurring on
different CPUs and different objects to be processed in parallel.

The fault handler now acquires the `vmobjlock' of a given UVM object as
soon as it finds one. For now a write-lock is always acquired even if
some operations could use a read-lock.

Every pager, corresponding to a different kind of UVM object, now expect
the UVM object to be locked and some operations, like *_get() return it
unlocked. This is enforced by assertions checking for rw_write_held().

The KERNEL_LOCK() is now pushed to the VFS boundary in the vnode pager.

To ensure the correct amap or object lock is held when modifying a page
many uvm_page* operations are now asserting for the "owner" lock.
However, fields of the "struct vm_page" are still being protected by the
global `pageqlock'. To prevent lock ordering issues with the new
`vmobjlock' and to reduce differences with NetBSD this lock is now taken
and released for each page instead of around the whole loop.

This commit does not remove the KERNEL_LOCK/UNLOCK() dance. Unlocking
will follow if there is no fallout.

Ported from NetBSD, tested by many, thanks!

ok kettenis@, kn@


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.76 26-Mar-2021 mpi

Remove parenthesis around return value to reduce the diff with NetBSD.

No functional change.

ok mlarkin@


# 1.75 12-Mar-2021 jsg

spelling

ok mpi@


# 1.74 19-Jan-2021 mpi

(re)Introduce locking for amaps & anons.

A rwlock is attached to every amap and is shared with all its anon. The
same lock will be used by multiple amaps if they have anons in common.

This should be enough to get the upper part of the fault handler out of the
KERNEL_LOCK() which seems to bring up to 20% improvements in builds.

This is based/copied/adapted from the most recent work done in NetBSD which
is an evolution of the precendent simple_lock scheme.

Tested by many, thanks!

ok kettenis@, mvs@


# 1.73 21-Oct-2020 mpi

Constify and use C99 initializer for "struct uvm_pagerops".

While here put some KERNEL_ASSERT_LOCKED() in the functions called from
the page fault handler. The removal of locking of `uobj' will need to be
revisited and these are good indicator that something is missing and that
many comments are lying.

ok kettenis


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.72 08-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok visa@, jca@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.71 17-Dec-2014 tedu

remove lock.h from uvm_extern.h. another holdover from the simpletonlock
era. fix uvm including c files to include lock.h or atomic.h as necessary.
ok deraadt


# 1.70 16-Nov-2014 deraadt

Replace a plethora of historical protection options with just
PROT_NONE, PROT_READ, PROT_WRITE, and PROT_EXEC from mman.h.
PROT_MASK is introduced as the one true way of extracting those bits.
Remove UVM_ADV_* wrapper, using the standard names.
ok doug guenther kettenis


# 1.69 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.68 11-Jul-2014 jsg

Chuck Cranor rescinded clauses in his license
on the 2nd of February 2011 in NetBSD.

http://marc.info/?l=netbsd-source-changes&m=129658899212732&w=2
http://marc.info/?l=netbsd-source-changes&m=129659095515558&w=2
http://marc.info/?l=netbsd-source-changes&m=129659157916514&w=2
http://marc.info/?l=netbsd-source-changes&m=129665962324372&w=2
http://marc.info/?l=netbsd-source-changes&m=129666033625342&w=2
http://marc.info/?l=netbsd-source-changes&m=129666052825545&w=2
http://marc.info/?l=netbsd-source-changes&m=129666922906480&w=2
http://marc.info/?l=netbsd-source-changes&m=129667725518082&w=2


# 1.67 09-May-2014 tedu

stop using B_AGE, it was effectively retired some time ago.


# 1.66 08-May-2014 kettenis

Fix some potential integer overflows caused by converting a page number into
an offset/size/address by shifting by PAGE_SHIFT. Make uvm_objwrire/unwire
use voff_t instead of off_t. The former is the right type here even if it is
equivalent to the latter.

Inspired by a somewhat similar changes in Bitrig.

ok deraadt@, guenther@


# 1.65 13-Apr-2014 tedu

compress code by turning four line comments into one line comments.
emphatic ok usual suspects, grudging ok miod


Revision tags: OPENBSD_5_5_BASE
# 1.64 02-Nov-2013 krw

No need to cast constants or simple variables to (daddr_t). Use
(u_int64_t) instead of (daddr_t) when casting a variable in an
expression passed to DL_SETDSIZE().

Change a variable counting open files from daddr_t to int64_t.

ok deraadt@ with the tweak to fix that pesky expression.


Revision tags: OPENBSD_5_4_BASE
# 1.63 11-Jun-2013 deraadt

final removal of daddr64_t. daddr_t has been 64 bit for a long enough
test period; i think 3 years ago the last bugs fell out.
ok otto beck others


# 1.62 30-May-2013 tedu

remove lots of comments about locking per beck's request


# 1.61 30-May-2013 tedu

remove simple_locks from uvm code. ok beck deraadt


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.60 03-Jul-2011 oga

Rip out and burn support for UVM_HIST.

The vm hackers don't use it, don't maintain it and have to look at it all the
time. About time this 800 lines of code hit /dev/null.

``never liked it'' tedu@. ariane@ was very happy when i told her i wrote
this diff.


# 1.59 15-Apr-2011 oga

for uvm_pager_dropcluster in the PG_RELEASED case we specifically unbusy the
page so that um_anfree will free it for us.

uvm_anfree does a pmap_page_protect(, VM_PROT_NONE) just before it frees the
page, so we don't need to do it here ourselves.

ok ariane@


# 1.58 15-Apr-2011 oga

move uvm_pageratop from uvm_pager.c local to a general uvm function
(uvm_atopg) and use it in uvm_km_doputpage to replace some handrolled
code. Shrinks the kernel a trivial amount.

ok beck@ and miod@ (who suggested i name it uvm_atopg not uvm_atop)


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.57 24-Jul-2010 kettenis

Don't sleep while holding the uvm_psel_lck mutex. Should fix "locking against
myself" panics that some people have seen over the last year-and-a-half.

Cherry picked from a more complex (and therefore scarier) diff from oga@.

ok tedu@, oga@


# 1.56 27-Jun-2010 oga

Kill another #ifdef UBC chunk that was annoying me while doing something
else.

ok thib@


Revision tags: OPENBSD_4_7_BASE
# 1.55 12-Feb-2010 tedu

introduce a uvm_km_valloc_try function that won't get a lower level lock
for use by the uvm pseg code. this is the path of least resistance until
we sort out how many of these functions we really need. problem found by mikeb
ok kettenis oga


# 1.54 22-Jul-2009 oga

Put the PG_RELEASED changes diff back in.

This has has been tested very very thoroughly on all archs we have
excepting 88k and 68k. Please see cvs log for the individual commit
messages.

ok beck@, thib@


Revision tags: OPENBSD_4_6_BASE
# 1.53 17-Jun-2009 oga

date based reversion of uvm to the 4th May.

More backouts in line with previous ones, this appears to bring us back to a
stable condition.

A machine forced to 64mb of ram cycled 10GB through swap with this diff
and is still running as I type this. Other tests by ariane@ and thib@
also seem to show that it's alright.

ok deraadt@, thib@, ariane@


# 1.52 16-Jun-2009 oga

Backout all the PG_RELEASED changes.

This is for the same reason as the earlier backouts, to avoid the bug
either added or exposed sometime around c2k9. This *should* be the last
one.

prompted by deraadt@

ok ariane@


# 1.51 23-May-2009 oga

More PG_RELEASED cleaning.

similar to the aobj.c changes, this one does vnodes. Vnodes are more
complex because they actaully have to sync to backing store. So firstly,
convert sync to sleep instead of setting released.

Now, for backing store, in the PGO_FREE case, if we set PG_RELEASED
*before* an async io, (nothing else will see it, the page is busy), then
we can ignore the page after the io is done. We could do something
similar for PGO_DEACTIVATE too, but that is another change. On error we
just clear the released flag, nothing else sets it for uobj pages other
than aiodoned.

ok thib@, beck@, ariane@


# 1.50 04-May-2009 oga

Instead of keeping two ints in the uvm structure specifically just to
sleep on them (and otherwise ignore them) sleep on the pointer to the
{aiodoned,pagedaemon}_proc members, and nuke the two extra words.

"no objections" art@, ok beck@.


# 1.49 06-Apr-2009 oga

Instead of doing splbio(); simple_lock(&uvm.aiodoned_lock); just replace
the simple lock with a real lock - a IPL_BIO mutex. While i'm here, make
the sleeping condition one hell of a lot simpler in the aio daemon.

some ideas from and ok art@.


# 1.48 25-Mar-2009 oga

Move all of the pseudo-inline functions in uvm into C files.

By pseudo-inline, I mean that if a certain macro was defined, they would
be inlined. However, no architecture defines that, and none has for a
very very long time. Therefore mainly this just makes the code a damned
sight easier to read. Some k&r -> ansi declarations while I'm in there.

"just commit it" art@. ok weingart@.


# 1.47 20-Mar-2009 oga

While working on some stuff in uvm I've gotten REALLY sick of reading
K&R function declarations, so switch them all over to ansi-style, in
accordance with the prophesy.

"go for it" art@


Revision tags: OPENBSD_4_5_BASE
# 1.46 27-Jan-2009 ariane

Simplify page-out/page-in map management; fix rare pager deadlock.

Ok: miod, tedu


# 1.45 24-Nov-2008 thib

garbage collect uvm_errno2vmerror();

ok miod@, art@


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.44 26-Nov-2007 miod

In uvm_aio_aiodone(), kill the variable-sized array on stack, and use a
fixed size array which size should match any buf; if a bogus buf is passed
to this function, the kernel will KASSERT instead of potentially running out
of stack and having an undefined behaviour.

ok deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.43 06-Jun-2007 deraadt

now that all partition size/offsets are potentially 64-bit, change the
type of all variables to daddr64_t. this includes the APIs for XXsize()
and XXdump(), all range checks inside bio drivers, internal variables
for disklabel handling, and even uvm's swap offsets. re-read numerous
times by otto, miod, krw, thib to look for errors


# 1.42 13-Apr-2007 art

While splitting flags and pqflags might have been a good idea in theory
to separate locking, on most modern machines this is not enough
since operations on short types touch other short types that share the
same word in memory.

Merge pg_flags and pqflags again and now use atomic operations to change
the flags. Also bump wire_count to an int and pg_version might go
int as well, just for alignment.

tested by many, many. ok miod@


# 1.41 04-Apr-2007 art

Mechanically rename the "flags" and "version" fields in struct vm_page
to "pg_flags" and "pg_version", so that they are a bit easier to work with.
Whoever uses generic names like this for a popular struct obviously doesn't
read much code.

Most architectures compile and there are no functionality changes.

deraadt@ ok ("if something fails to compile, we fix that by hand")


# 1.40 25-Mar-2007 art

remove KERN_SUCCESS and use 0 instead.
eyeballed by miod@ and pedro@


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.39 31-Jul-2006 mickey

fix uvmhist #2: args are always u_long so fix missing %d and %x and no %ll; no change for normal code


# 1.38 26-Jul-2006 mickey

fix fmts for UVMHIST_LOG() entries making it more useful on 64bit archs; miod@ ok


Revision tags: OPENBSD_3_8_BASE OPENBSD_3_9_BASE
# 1.37 26-Jul-2005 art

- Make a UVM_OBJ_IS_DEVICE macro.
- Use it to skip device mappings while dumping core.
- Ignore EFAULT errors while dumping core since they can happen
even for valid mappings. Just skip that part of the core file and
let it get automagically zero-filled.

This fixes the broken X core dumps that people have been seeing and also
fixes some other potential problems that could prevent core dumps (mmaps
beyond EOF, etc.).

tedu@ ok


# 1.36 24-May-2005 tedu

add a new field to vm_space and use it to track the number of anon
pages a process uses. this is now the userland "data size" value.
ok art deraadt tdeval. thanks testers.


Revision tags: OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE SMP_SYNC_A SMP_SYNC_B
# 1.35 23-Feb-2004 drahn

sync of pmap_update() calls with NetBSD. pmap_update is defined away on
all architectures but arm, where it is needed.


Revision tags: OPENBSD_3_4_BASE UBC_SYNC_A
# 1.34 29-Mar-2003 mickey

ubchist is not a fully cooked kadaver and though use the other well formed pdhist one until ubc gaets back. art@ ok


Revision tags: OPENBSD_3_3_BASE
# 1.33 29-Oct-2002 art

Since memory deallocation can't fail, remove the error return from
uvm_unmap, uvm_deallocate and a few other functions.
Simplifies some code and reduces diff to the UBC branch.


Revision tags: OPENBSD_3_2_BASE UBC_SYNC_B
# 1.32 24-May-2002 art

Make sure that b_iodone handlers are called at splbio (and splassert(IPL_BIO) in all known callers, just to make sure).


# 1.31 22-May-2002 art

splassert(IPL_BIO) in the b_iodone handlers.


Revision tags: OPENBSD_3_1_BASE
# 1.30 02-Jan-2002 miod

Back out a few more uvm changes, especially wrt swap usage.
This unbreaks m68k m88k sparc and perhaps others, which eventually froze
when hitting swap.
Tested by various people on various platforms.
ok art@


# 1.29 19-Dec-2001 art

UBC was a disaster. It worked very good when it worked, but on some
machines or some configurations or in some phase of the moon (we actually
don't know when or why) files disappeared. Since we've not been able to
track down the problem in two weeks intense debugging and we need -current
to be stable, back out everything to a state it had before UBC.

We apologise for the inconvenience.


Revision tags: UBC_BASE
# 1.28 04-Dec-2001 art

branches: 1.28.2;
Yet another sync to NetBSD uvm.
Today we add a pmap argument to pmap_update() and allocate map entries for
kernel_map from kmem_map instead of using the static entries. This should
get rid of MAX_KMAPENT panics. Also some uvm_loan problems are fixed.


# 1.27 30-Nov-2001 csapuntz

Call buf_cleanout, which handles wakeups


# 1.26 29-Nov-2001 art

Correctly handle b_vp with bgetvp and brelvp in {get,put}pages.
Prevents panics caused by vnodes being recycled under our feet.


# 1.25 28-Nov-2001 art

Sync in more uvm from NetBSD. Mostly just cosmetic stuff.
Contains also support for page coloring.


# 1.24 28-Nov-2001 art

Sync in more uvm changes from NetBSD.
This time we're getting rid of KERN_* and VM_PAGER_* error codes and
use errnos instead.


# 1.23 27-Nov-2001 art

Merge in the unified buffer cache code as found in NetBSD 2001/03/10. The
code is written mostly by Chuck Silvers <chuq@chuq.com>/<chs@netbsd.org>.

Tested for the past few weeks by many developers, should be in a pretty stable
state, but will require optimizations and additional cleanups.


# 1.22 12-Nov-2001 art

Bring in more changes from NetBSD. Mostly pagedaemon improvements.


# 1.21 10-Nov-2001 art

Merge in some parts of the ubc work that has been done in NetBSD that are not
UBC, but prerequsites for it.

- Create a daemon that processes async I/O (swap and paging in the future)
requests that need processing in process context and that were processed
in the pagedaemon before.
- Convert some ugly ifdef DIAGNOSTIC code to less intrusive KASSERTs.
- misc other cleanups.


# 1.20 07-Nov-2001 art

Another sync of uvm to NetBSD. Just minor fiddling, no major changes.


# 1.19 07-Nov-2001 art

Add an alignment argument to uvm_map that specifies an alignment hint
for the virtual address.


# 1.18 06-Nov-2001 art

Move the last content from vm/ to uvm/
The only thing left in vm/ are just dumb wrappers.
vm/vm.h includes uvm/uvm_extern.h
vm/pmap.h includes uvm/uvm_pmap.h
vm/vm_page.h includes uvm/uvm_page.h


# 1.17 05-Nov-2001 art

Minor sync to NetBSD.


Revision tags: OPENBSD_3_0_BASE
# 1.16 20-Sep-2001 mpech

occured->occurred

idea from deraadt@ via NetBSD
millert@ ok


# 1.15 19-Sep-2001 mickey

merge vm/vm_kern.h into uvm/uvm_extern.h; art@ ok


# 1.14 11-Aug-2001 art

Various random fixes from NetBSD.
Including support for zeroing pages in the idle loop (not enabled yet).


# 1.13 06-Aug-2001 art

Add a new type voff_t (right now it's typedefed as off_t) used for offsets
into objects.

Gives the possibilty to mmap beyond the size of vaddr_t.

From NetBSD.


# 1.12 26-Jul-2001 art

Add support for disabling swap devices (swapctl -d).
Improve error handling on I/O errors to swap.
From NetBSD


# 1.11 25-Jul-2001 art

Change the pmap_enter interface to merge access_type and the wired boolean
and arbitrary flags into one argument.

One new flag is PMAP_CANFAIL that tells pmap_enter that it can fail if there
are not enough resources to satisfy the request. If this flag is not passed,
pmap_enter should panic as it should have done before this change (XXX - many
pmaps are still not doing that).

Only i386 and alpha implement CANFAIL for now.

Includes uvm updates from NetBSD.


# 1.10 18-Jul-2001 art

Get rid of the PMAP_NEW option by making it mandatory for all archs.
The archs that didn't have a proper PMAP_NEW now have a dummy implementation
with wrappers around the old functions.


# 1.9 08-Jun-2001 art

Change the paddr_t pmap_extract(struct pmap *, vaddr_t) interface to
boolean_t pmap_extract(struct pmap *, vaddr_t, paddr_t *).
Matches NetBSD. Tested by various people on various platforms.


Revision tags: OPENBSD_2_9_BASE
# 1.8 22-Mar-2001 smart

Sync style, typo, and comments a little closer to NetBSD. art@ ok


# 1.7 08-Mar-2001 smart

Replace thread_wakeup() with wakeup(). It is defined in vm_extern.h as a
wrapper, so this removes a dependence on the old VM system. From NetBSD.
art@ ok


# 1.6 29-Jan-2001 niklas

$OpenBSD$


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE
# 1.5 16-Mar-2000 art

Bring in some new UVM code from NetBSD (not current).

- Introduce a new type of map that are interrupt safe and never allow faults
in them. mb_map and kmem_map are made intrsafe.
- Add "access protection" to uvm_vslock (to be passed down to uvm_fault and
later to pmap_enter).
- madvise(2) now works.
- various cleanups.


Revision tags: OPENBSD_2_6_BASE SMP_BASE kame_19991208
# 1.4 03-Sep-1999 art

branches: 1.4.4;
Change the pmap_enter api to pass down an argument that indicates
the access type that caused this mapping. This is to simplify pmaps
with mod/ref emulation (none for the moment) and in some cases speed
up pmap_is_{referenced,modified}.
At the same time, clean up some mappings that had too high protection.

XXX - the access type is incorrect in old vm, it's only used by uvm and MD code.
The actual use of this in pmap_enter implementations is not in this commit.


# 1.3 23-Aug-1999 art

sync with NetBSD from 1999.05.24 (there is a reason for this date)
Mostly cleanups, but also a few improvements to pagedaemon for better
handling of low memory and/or low swap conditions.


Revision tags: OPENBSD_2_5_BASE
# 1.2 26-Feb-1999 art

add OpenBSD tags


# 1.1 26-Feb-1999 art

Import of uvm from NetBSD. Some local changes, some code disabled


# 1.82 30-Jun-2022 mpi

Reduce allocations and possible failures in uvm_pagermapin/out().

. If a direct map exists use it to map single-page allocations
. Use pmap_kenter_pa() instead of pmap_enter() in all other cases.

This speeds up file-based mmap up to 75% when I/O are performed and it
also reduces possible allocations failtures in the page daemon making
it more stable in OOM situations.

ok kettenis@, beck@


# 1.81 28-Jun-2022 mpi

Reserve a second segment for the page daemon.

This ensures uvm_swap_io() can succeeds even in OOM situations because two
uvm_pagermapin() allocations, requiring a segment each, are needed to bounce
or encrypt a swap cluster.

ok beck@, kettenis@


# 1.80 28-Jun-2022 mpi

Move the guts of uvm_aio_aiodone() into a separate function.

This will help dealing with error cases.

No functionnal changes.


# 1.79 28-Jun-2022 mpi

Do not clean PG_BUSY before calling uvm_anon_release().

Fix an assertion reported by gkoehler@.

ok kettenis@


Revision tags: OPENBSD_7_1_BASE
# 1.78 18-Feb-2022 kettenis

Convert KVA allocation to km_alloc(9).

ok mpi@


# 1.77 15-Dec-2021 mpi

Use a per-UVM object lock to serialize the lower part of the fault handler.

Like the per-amap lock the `vmobjlock' is principally used to serialized
access to objects in the fault handler to allow faults occurring on
different CPUs and different objects to be processed in parallel.

The fault handler now acquires the `vmobjlock' of a given UVM object as
soon as it finds one. For now a write-lock is always acquired even if
some operations could use a read-lock.

Every pager, corresponding to a different kind of UVM object, now expect
the UVM object to be locked and some operations, like *_get() return it
unlocked. This is enforced by assertions checking for rw_write_held().

The KERNEL_LOCK() is now pushed to the VFS boundary in the vnode pager.

To ensure the correct amap or object lock is held when modifying a page
many uvm_page* operations are now asserting for the "owner" lock.
However, fields of the "struct vm_page" are still being protected by the
global `pageqlock'. To prevent lock ordering issues with the new
`vmobjlock' and to reduce differences with NetBSD this lock is now taken
and released for each page instead of around the whole loop.

This commit does not remove the KERNEL_LOCK/UNLOCK() dance. Unlocking
will follow if there is no fallout.

Ported from NetBSD, tested by many, thanks!

ok kettenis@, kn@


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.76 26-Mar-2021 mpi

Remove parenthesis around return value to reduce the diff with NetBSD.

No functional change.

ok mlarkin@


# 1.75 12-Mar-2021 jsg

spelling

ok mpi@


# 1.74 19-Jan-2021 mpi

(re)Introduce locking for amaps & anons.

A rwlock is attached to every amap and is shared with all its anon. The
same lock will be used by multiple amaps if they have anons in common.

This should be enough to get the upper part of the fault handler out of the
KERNEL_LOCK() which seems to bring up to 20% improvements in builds.

This is based/copied/adapted from the most recent work done in NetBSD which
is an evolution of the precendent simple_lock scheme.

Tested by many, thanks!

ok kettenis@, mvs@


# 1.73 21-Oct-2020 mpi

Constify and use C99 initializer for "struct uvm_pagerops".

While here put some KERNEL_ASSERT_LOCKED() in the functions called from
the page fault handler. The removal of locking of `uobj' will need to be
revisited and these are good indicator that something is missing and that
many comments are lying.

ok kettenis


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.72 08-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok visa@, jca@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.71 17-Dec-2014 tedu

remove lock.h from uvm_extern.h. another holdover from the simpletonlock
era. fix uvm including c files to include lock.h or atomic.h as necessary.
ok deraadt


# 1.70 16-Nov-2014 deraadt

Replace a plethora of historical protection options with just
PROT_NONE, PROT_READ, PROT_WRITE, and PROT_EXEC from mman.h.
PROT_MASK is introduced as the one true way of extracting those bits.
Remove UVM_ADV_* wrapper, using the standard names.
ok doug guenther kettenis


# 1.69 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.68 11-Jul-2014 jsg

Chuck Cranor rescinded clauses in his license
on the 2nd of February 2011 in NetBSD.

http://marc.info/?l=netbsd-source-changes&m=129658899212732&w=2
http://marc.info/?l=netbsd-source-changes&m=129659095515558&w=2
http://marc.info/?l=netbsd-source-changes&m=129659157916514&w=2
http://marc.info/?l=netbsd-source-changes&m=129665962324372&w=2
http://marc.info/?l=netbsd-source-changes&m=129666033625342&w=2
http://marc.info/?l=netbsd-source-changes&m=129666052825545&w=2
http://marc.info/?l=netbsd-source-changes&m=129666922906480&w=2
http://marc.info/?l=netbsd-source-changes&m=129667725518082&w=2


# 1.67 09-May-2014 tedu

stop using B_AGE, it was effectively retired some time ago.


# 1.66 08-May-2014 kettenis

Fix some potential integer overflows caused by converting a page number into
an offset/size/address by shifting by PAGE_SHIFT. Make uvm_objwrire/unwire
use voff_t instead of off_t. The former is the right type here even if it is
equivalent to the latter.

Inspired by a somewhat similar changes in Bitrig.

ok deraadt@, guenther@


# 1.65 13-Apr-2014 tedu

compress code by turning four line comments into one line comments.
emphatic ok usual suspects, grudging ok miod


Revision tags: OPENBSD_5_5_BASE
# 1.64 02-Nov-2013 krw

No need to cast constants or simple variables to (daddr_t). Use
(u_int64_t) instead of (daddr_t) when casting a variable in an
expression passed to DL_SETDSIZE().

Change a variable counting open files from daddr_t to int64_t.

ok deraadt@ with the tweak to fix that pesky expression.


Revision tags: OPENBSD_5_4_BASE
# 1.63 11-Jun-2013 deraadt

final removal of daddr64_t. daddr_t has been 64 bit for a long enough
test period; i think 3 years ago the last bugs fell out.
ok otto beck others


# 1.62 30-May-2013 tedu

remove lots of comments about locking per beck's request


# 1.61 30-May-2013 tedu

remove simple_locks from uvm code. ok beck deraadt


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.60 03-Jul-2011 oga

Rip out and burn support for UVM_HIST.

The vm hackers don't use it, don't maintain it and have to look at it all the
time. About time this 800 lines of code hit /dev/null.

``never liked it'' tedu@. ariane@ was very happy when i told her i wrote
this diff.


# 1.59 15-Apr-2011 oga

for uvm_pager_dropcluster in the PG_RELEASED case we specifically unbusy the
page so that um_anfree will free it for us.

uvm_anfree does a pmap_page_protect(, VM_PROT_NONE) just before it frees the
page, so we don't need to do it here ourselves.

ok ariane@


# 1.58 15-Apr-2011 oga

move uvm_pageratop from uvm_pager.c local to a general uvm function
(uvm_atopg) and use it in uvm_km_doputpage to replace some handrolled
code. Shrinks the kernel a trivial amount.

ok beck@ and miod@ (who suggested i name it uvm_atopg not uvm_atop)


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.57 24-Jul-2010 kettenis

Don't sleep while holding the uvm_psel_lck mutex. Should fix "locking against
myself" panics that some people have seen over the last year-and-a-half.

Cherry picked from a more complex (and therefore scarier) diff from oga@.

ok tedu@, oga@


# 1.56 27-Jun-2010 oga

Kill another #ifdef UBC chunk that was annoying me while doing something
else.

ok thib@


Revision tags: OPENBSD_4_7_BASE
# 1.55 12-Feb-2010 tedu

introduce a uvm_km_valloc_try function that won't get a lower level lock
for use by the uvm pseg code. this is the path of least resistance until
we sort out how many of these functions we really need. problem found by mikeb
ok kettenis oga


# 1.54 22-Jul-2009 oga

Put the PG_RELEASED changes diff back in.

This has has been tested very very thoroughly on all archs we have
excepting 88k and 68k. Please see cvs log for the individual commit
messages.

ok beck@, thib@


Revision tags: OPENBSD_4_6_BASE
# 1.53 17-Jun-2009 oga

date based reversion of uvm to the 4th May.

More backouts in line with previous ones, this appears to bring us back to a
stable condition.

A machine forced to 64mb of ram cycled 10GB through swap with this diff
and is still running as I type this. Other tests by ariane@ and thib@
also seem to show that it's alright.

ok deraadt@, thib@, ariane@


# 1.52 16-Jun-2009 oga

Backout all the PG_RELEASED changes.

This is for the same reason as the earlier backouts, to avoid the bug
either added or exposed sometime around c2k9. This *should* be the last
one.

prompted by deraadt@

ok ariane@


# 1.51 23-May-2009 oga

More PG_RELEASED cleaning.

similar to the aobj.c changes, this one does vnodes. Vnodes are more
complex because they actaully have to sync to backing store. So firstly,
convert sync to sleep instead of setting released.

Now, for backing store, in the PGO_FREE case, if we set PG_RELEASED
*before* an async io, (nothing else will see it, the page is busy), then
we can ignore the page after the io is done. We could do something
similar for PGO_DEACTIVATE too, but that is another change. On error we
just clear the released flag, nothing else sets it for uobj pages other
than aiodoned.

ok thib@, beck@, ariane@


# 1.50 04-May-2009 oga

Instead of keeping two ints in the uvm structure specifically just to
sleep on them (and otherwise ignore them) sleep on the pointer to the
{aiodoned,pagedaemon}_proc members, and nuke the two extra words.

"no objections" art@, ok beck@.


# 1.49 06-Apr-2009 oga

Instead of doing splbio(); simple_lock(&uvm.aiodoned_lock); just replace
the simple lock with a real lock - a IPL_BIO mutex. While i'm here, make
the sleeping condition one hell of a lot simpler in the aio daemon.

some ideas from and ok art@.


# 1.48 25-Mar-2009 oga

Move all of the pseudo-inline functions in uvm into C files.

By pseudo-inline, I mean that if a certain macro was defined, they would
be inlined. However, no architecture defines that, and none has for a
very very long time. Therefore mainly this just makes the code a damned
sight easier to read. Some k&r -> ansi declarations while I'm in there.

"just commit it" art@. ok weingart@.


# 1.47 20-Mar-2009 oga

While working on some stuff in uvm I've gotten REALLY sick of reading
K&R function declarations, so switch them all over to ansi-style, in
accordance with the prophesy.

"go for it" art@


Revision tags: OPENBSD_4_5_BASE
# 1.46 27-Jan-2009 ariane

Simplify page-out/page-in map management; fix rare pager deadlock.

Ok: miod, tedu


# 1.45 24-Nov-2008 thib

garbage collect uvm_errno2vmerror();

ok miod@, art@


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.44 26-Nov-2007 miod

In uvm_aio_aiodone(), kill the variable-sized array on stack, and use a
fixed size array which size should match any buf; if a bogus buf is passed
to this function, the kernel will KASSERT instead of potentially running out
of stack and having an undefined behaviour.

ok deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.43 06-Jun-2007 deraadt

now that all partition size/offsets are potentially 64-bit, change the
type of all variables to daddr64_t. this includes the APIs for XXsize()
and XXdump(), all range checks inside bio drivers, internal variables
for disklabel handling, and even uvm's swap offsets. re-read numerous
times by otto, miod, krw, thib to look for errors


# 1.42 13-Apr-2007 art

While splitting flags and pqflags might have been a good idea in theory
to separate locking, on most modern machines this is not enough
since operations on short types touch other short types that share the
same word in memory.

Merge pg_flags and pqflags again and now use atomic operations to change
the flags. Also bump wire_count to an int and pg_version might go
int as well, just for alignment.

tested by many, many. ok miod@


# 1.41 04-Apr-2007 art

Mechanically rename the "flags" and "version" fields in struct vm_page
to "pg_flags" and "pg_version", so that they are a bit easier to work with.
Whoever uses generic names like this for a popular struct obviously doesn't
read much code.

Most architectures compile and there are no functionality changes.

deraadt@ ok ("if something fails to compile, we fix that by hand")


# 1.40 25-Mar-2007 art

remove KERN_SUCCESS and use 0 instead.
eyeballed by miod@ and pedro@


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.39 31-Jul-2006 mickey

fix uvmhist #2: args are always u_long so fix missing %d and %x and no %ll; no change for normal code


# 1.38 26-Jul-2006 mickey

fix fmts for UVMHIST_LOG() entries making it more useful on 64bit archs; miod@ ok


Revision tags: OPENBSD_3_8_BASE OPENBSD_3_9_BASE
# 1.37 26-Jul-2005 art

- Make a UVM_OBJ_IS_DEVICE macro.
- Use it to skip device mappings while dumping core.
- Ignore EFAULT errors while dumping core since they can happen
even for valid mappings. Just skip that part of the core file and
let it get automagically zero-filled.

This fixes the broken X core dumps that people have been seeing and also
fixes some other potential problems that could prevent core dumps (mmaps
beyond EOF, etc.).

tedu@ ok


# 1.36 24-May-2005 tedu

add a new field to vm_space and use it to track the number of anon
pages a process uses. this is now the userland "data size" value.
ok art deraadt tdeval. thanks testers.


Revision tags: OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE SMP_SYNC_A SMP_SYNC_B
# 1.35 23-Feb-2004 drahn

sync of pmap_update() calls with NetBSD. pmap_update is defined away on
all architectures but arm, where it is needed.


Revision tags: OPENBSD_3_4_BASE UBC_SYNC_A
# 1.34 29-Mar-2003 mickey

ubchist is not a fully cooked kadaver and though use the other well formed pdhist one until ubc gaets back. art@ ok


Revision tags: OPENBSD_3_3_BASE
# 1.33 29-Oct-2002 art

Since memory deallocation can't fail, remove the error return from
uvm_unmap, uvm_deallocate and a few other functions.
Simplifies some code and reduces diff to the UBC branch.


Revision tags: OPENBSD_3_2_BASE UBC_SYNC_B
# 1.32 24-May-2002 art

Make sure that b_iodone handlers are called at splbio (and splassert(IPL_BIO) in all known callers, just to make sure).


# 1.31 22-May-2002 art

splassert(IPL_BIO) in the b_iodone handlers.


Revision tags: OPENBSD_3_1_BASE
# 1.30 02-Jan-2002 miod

Back out a few more uvm changes, especially wrt swap usage.
This unbreaks m68k m88k sparc and perhaps others, which eventually froze
when hitting swap.
Tested by various people on various platforms.
ok art@


# 1.29 19-Dec-2001 art

UBC was a disaster. It worked very good when it worked, but on some
machines or some configurations or in some phase of the moon (we actually
don't know when or why) files disappeared. Since we've not been able to
track down the problem in two weeks intense debugging and we need -current
to be stable, back out everything to a state it had before UBC.

We apologise for the inconvenience.


Revision tags: UBC_BASE
# 1.28 04-Dec-2001 art

branches: 1.28.2;
Yet another sync to NetBSD uvm.
Today we add a pmap argument to pmap_update() and allocate map entries for
kernel_map from kmem_map instead of using the static entries. This should
get rid of MAX_KMAPENT panics. Also some uvm_loan problems are fixed.


# 1.27 30-Nov-2001 csapuntz

Call buf_cleanout, which handles wakeups


# 1.26 29-Nov-2001 art

Correctly handle b_vp with bgetvp and brelvp in {get,put}pages.
Prevents panics caused by vnodes being recycled under our feet.


# 1.25 28-Nov-2001 art

Sync in more uvm from NetBSD. Mostly just cosmetic stuff.
Contains also support for page coloring.


# 1.24 28-Nov-2001 art

Sync in more uvm changes from NetBSD.
This time we're getting rid of KERN_* and VM_PAGER_* error codes and
use errnos instead.


# 1.23 27-Nov-2001 art

Merge in the unified buffer cache code as found in NetBSD 2001/03/10. The
code is written mostly by Chuck Silvers <chuq@chuq.com>/<chs@netbsd.org>.

Tested for the past few weeks by many developers, should be in a pretty stable
state, but will require optimizations and additional cleanups.


# 1.22 12-Nov-2001 art

Bring in more changes from NetBSD. Mostly pagedaemon improvements.


# 1.21 10-Nov-2001 art

Merge in some parts of the ubc work that has been done in NetBSD that are not
UBC, but prerequsites for it.

- Create a daemon that processes async I/O (swap and paging in the future)
requests that need processing in process context and that were processed
in the pagedaemon before.
- Convert some ugly ifdef DIAGNOSTIC code to less intrusive KASSERTs.
- misc other cleanups.


# 1.20 07-Nov-2001 art

Another sync of uvm to NetBSD. Just minor fiddling, no major changes.


# 1.19 07-Nov-2001 art

Add an alignment argument to uvm_map that specifies an alignment hint
for the virtual address.


# 1.18 06-Nov-2001 art

Move the last content from vm/ to uvm/
The only thing left in vm/ are just dumb wrappers.
vm/vm.h includes uvm/uvm_extern.h
vm/pmap.h includes uvm/uvm_pmap.h
vm/vm_page.h includes uvm/uvm_page.h


# 1.17 05-Nov-2001 art

Minor sync to NetBSD.


Revision tags: OPENBSD_3_0_BASE
# 1.16 20-Sep-2001 mpech

occured->occurred

idea from deraadt@ via NetBSD
millert@ ok


# 1.15 19-Sep-2001 mickey

merge vm/vm_kern.h into uvm/uvm_extern.h; art@ ok


# 1.14 11-Aug-2001 art

Various random fixes from NetBSD.
Including support for zeroing pages in the idle loop (not enabled yet).


# 1.13 06-Aug-2001 art

Add a new type voff_t (right now it's typedefed as off_t) used for offsets
into objects.

Gives the possibilty to mmap beyond the size of vaddr_t.

From NetBSD.


# 1.12 26-Jul-2001 art

Add support for disabling swap devices (swapctl -d).
Improve error handling on I/O errors to swap.
From NetBSD


# 1.11 25-Jul-2001 art

Change the pmap_enter interface to merge access_type and the wired boolean
and arbitrary flags into one argument.

One new flag is PMAP_CANFAIL that tells pmap_enter that it can fail if there
are not enough resources to satisfy the request. If this flag is not passed,
pmap_enter should panic as it should have done before this change (XXX - many
pmaps are still not doing that).

Only i386 and alpha implement CANFAIL for now.

Includes uvm updates from NetBSD.


# 1.10 18-Jul-2001 art

Get rid of the PMAP_NEW option by making it mandatory for all archs.
The archs that didn't have a proper PMAP_NEW now have a dummy implementation
with wrappers around the old functions.


# 1.9 08-Jun-2001 art

Change the paddr_t pmap_extract(struct pmap *, vaddr_t) interface to
boolean_t pmap_extract(struct pmap *, vaddr_t, paddr_t *).
Matches NetBSD. Tested by various people on various platforms.


Revision tags: OPENBSD_2_9_BASE
# 1.8 22-Mar-2001 smart

Sync style, typo, and comments a little closer to NetBSD. art@ ok


# 1.7 08-Mar-2001 smart

Replace thread_wakeup() with wakeup(). It is defined in vm_extern.h as a
wrapper, so this removes a dependence on the old VM system. From NetBSD.
art@ ok


# 1.6 29-Jan-2001 niklas

$OpenBSD$


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE
# 1.5 16-Mar-2000 art

Bring in some new UVM code from NetBSD (not current).

- Introduce a new type of map that are interrupt safe and never allow faults
in them. mb_map and kmem_map are made intrsafe.
- Add "access protection" to uvm_vslock (to be passed down to uvm_fault and
later to pmap_enter).
- madvise(2) now works.
- various cleanups.


Revision tags: OPENBSD_2_6_BASE SMP_BASE kame_19991208
# 1.4 03-Sep-1999 art

branches: 1.4.4;
Change the pmap_enter api to pass down an argument that indicates
the access type that caused this mapping. This is to simplify pmaps
with mod/ref emulation (none for the moment) and in some cases speed
up pmap_is_{referenced,modified}.
At the same time, clean up some mappings that had too high protection.

XXX - the access type is incorrect in old vm, it's only used by uvm and MD code.
The actual use of this in pmap_enter implementations is not in this commit.


# 1.3 23-Aug-1999 art

sync with NetBSD from 1999.05.24 (there is a reason for this date)
Mostly cleanups, but also a few improvements to pagedaemon for better
handling of low memory and/or low swap conditions.


Revision tags: OPENBSD_2_5_BASE
# 1.2 26-Feb-1999 art

add OpenBSD tags


# 1.1 26-Feb-1999 art

Import of uvm from NetBSD. Some local changes, some code disabled


# 1.81 28-Jun-2022 mpi

Reserve a second segment for the page daemon.

This ensures uvm_swap_io() can succeeds even in OOM situations because two
uvm_pagermapin() allocations, requiring a segment each, are needed to bounce
or encrypt a swap cluster.

ok beck@, kettenis@


# 1.80 28-Jun-2022 mpi

Move the guts of uvm_aio_aiodone() into a separate function.

This will help dealing with error cases.

No functionnal changes.


# 1.79 28-Jun-2022 mpi

Do not clean PG_BUSY before calling uvm_anon_release().

Fix an assertion reported by gkoehler@.

ok kettenis@


Revision tags: OPENBSD_7_1_BASE
# 1.78 18-Feb-2022 kettenis

Convert KVA allocation to km_alloc(9).

ok mpi@


# 1.77 15-Dec-2021 mpi

Use a per-UVM object lock to serialize the lower part of the fault handler.

Like the per-amap lock the `vmobjlock' is principally used to serialized
access to objects in the fault handler to allow faults occurring on
different CPUs and different objects to be processed in parallel.

The fault handler now acquires the `vmobjlock' of a given UVM object as
soon as it finds one. For now a write-lock is always acquired even if
some operations could use a read-lock.

Every pager, corresponding to a different kind of UVM object, now expect
the UVM object to be locked and some operations, like *_get() return it
unlocked. This is enforced by assertions checking for rw_write_held().

The KERNEL_LOCK() is now pushed to the VFS boundary in the vnode pager.

To ensure the correct amap or object lock is held when modifying a page
many uvm_page* operations are now asserting for the "owner" lock.
However, fields of the "struct vm_page" are still being protected by the
global `pageqlock'. To prevent lock ordering issues with the new
`vmobjlock' and to reduce differences with NetBSD this lock is now taken
and released for each page instead of around the whole loop.

This commit does not remove the KERNEL_LOCK/UNLOCK() dance. Unlocking
will follow if there is no fallout.

Ported from NetBSD, tested by many, thanks!

ok kettenis@, kn@


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.76 26-Mar-2021 mpi

Remove parenthesis around return value to reduce the diff with NetBSD.

No functional change.

ok mlarkin@


# 1.75 12-Mar-2021 jsg

spelling

ok mpi@


# 1.74 19-Jan-2021 mpi

(re)Introduce locking for amaps & anons.

A rwlock is attached to every amap and is shared with all its anon. The
same lock will be used by multiple amaps if they have anons in common.

This should be enough to get the upper part of the fault handler out of the
KERNEL_LOCK() which seems to bring up to 20% improvements in builds.

This is based/copied/adapted from the most recent work done in NetBSD which
is an evolution of the precendent simple_lock scheme.

Tested by many, thanks!

ok kettenis@, mvs@


# 1.73 21-Oct-2020 mpi

Constify and use C99 initializer for "struct uvm_pagerops".

While here put some KERNEL_ASSERT_LOCKED() in the functions called from
the page fault handler. The removal of locking of `uobj' will need to be
revisited and these are good indicator that something is missing and that
many comments are lying.

ok kettenis


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.72 08-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok visa@, jca@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.71 17-Dec-2014 tedu

remove lock.h from uvm_extern.h. another holdover from the simpletonlock
era. fix uvm including c files to include lock.h or atomic.h as necessary.
ok deraadt


# 1.70 16-Nov-2014 deraadt

Replace a plethora of historical protection options with just
PROT_NONE, PROT_READ, PROT_WRITE, and PROT_EXEC from mman.h.
PROT_MASK is introduced as the one true way of extracting those bits.
Remove UVM_ADV_* wrapper, using the standard names.
ok doug guenther kettenis


# 1.69 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.68 11-Jul-2014 jsg

Chuck Cranor rescinded clauses in his license
on the 2nd of February 2011 in NetBSD.

http://marc.info/?l=netbsd-source-changes&m=129658899212732&w=2
http://marc.info/?l=netbsd-source-changes&m=129659095515558&w=2
http://marc.info/?l=netbsd-source-changes&m=129659157916514&w=2
http://marc.info/?l=netbsd-source-changes&m=129665962324372&w=2
http://marc.info/?l=netbsd-source-changes&m=129666033625342&w=2
http://marc.info/?l=netbsd-source-changes&m=129666052825545&w=2
http://marc.info/?l=netbsd-source-changes&m=129666922906480&w=2
http://marc.info/?l=netbsd-source-changes&m=129667725518082&w=2


# 1.67 09-May-2014 tedu

stop using B_AGE, it was effectively retired some time ago.


# 1.66 08-May-2014 kettenis

Fix some potential integer overflows caused by converting a page number into
an offset/size/address by shifting by PAGE_SHIFT. Make uvm_objwrire/unwire
use voff_t instead of off_t. The former is the right type here even if it is
equivalent to the latter.

Inspired by a somewhat similar changes in Bitrig.

ok deraadt@, guenther@


# 1.65 13-Apr-2014 tedu

compress code by turning four line comments into one line comments.
emphatic ok usual suspects, grudging ok miod


Revision tags: OPENBSD_5_5_BASE
# 1.64 02-Nov-2013 krw

No need to cast constants or simple variables to (daddr_t). Use
(u_int64_t) instead of (daddr_t) when casting a variable in an
expression passed to DL_SETDSIZE().

Change a variable counting open files from daddr_t to int64_t.

ok deraadt@ with the tweak to fix that pesky expression.


Revision tags: OPENBSD_5_4_BASE
# 1.63 11-Jun-2013 deraadt

final removal of daddr64_t. daddr_t has been 64 bit for a long enough
test period; i think 3 years ago the last bugs fell out.
ok otto beck others


# 1.62 30-May-2013 tedu

remove lots of comments about locking per beck's request


# 1.61 30-May-2013 tedu

remove simple_locks from uvm code. ok beck deraadt


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.60 03-Jul-2011 oga

Rip out and burn support for UVM_HIST.

The vm hackers don't use it, don't maintain it and have to look at it all the
time. About time this 800 lines of code hit /dev/null.

``never liked it'' tedu@. ariane@ was very happy when i told her i wrote
this diff.


# 1.59 15-Apr-2011 oga

for uvm_pager_dropcluster in the PG_RELEASED case we specifically unbusy the
page so that um_anfree will free it for us.

uvm_anfree does a pmap_page_protect(, VM_PROT_NONE) just before it frees the
page, so we don't need to do it here ourselves.

ok ariane@


# 1.58 15-Apr-2011 oga

move uvm_pageratop from uvm_pager.c local to a general uvm function
(uvm_atopg) and use it in uvm_km_doputpage to replace some handrolled
code. Shrinks the kernel a trivial amount.

ok beck@ and miod@ (who suggested i name it uvm_atopg not uvm_atop)


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.57 24-Jul-2010 kettenis

Don't sleep while holding the uvm_psel_lck mutex. Should fix "locking against
myself" panics that some people have seen over the last year-and-a-half.

Cherry picked from a more complex (and therefore scarier) diff from oga@.

ok tedu@, oga@


# 1.56 27-Jun-2010 oga

Kill another #ifdef UBC chunk that was annoying me while doing something
else.

ok thib@


Revision tags: OPENBSD_4_7_BASE
# 1.55 12-Feb-2010 tedu

introduce a uvm_km_valloc_try function that won't get a lower level lock
for use by the uvm pseg code. this is the path of least resistance until
we sort out how many of these functions we really need. problem found by mikeb
ok kettenis oga


# 1.54 22-Jul-2009 oga

Put the PG_RELEASED changes diff back in.

This has has been tested very very thoroughly on all archs we have
excepting 88k and 68k. Please see cvs log for the individual commit
messages.

ok beck@, thib@


Revision tags: OPENBSD_4_6_BASE
# 1.53 17-Jun-2009 oga

date based reversion of uvm to the 4th May.

More backouts in line with previous ones, this appears to bring us back to a
stable condition.

A machine forced to 64mb of ram cycled 10GB through swap with this diff
and is still running as I type this. Other tests by ariane@ and thib@
also seem to show that it's alright.

ok deraadt@, thib@, ariane@


# 1.52 16-Jun-2009 oga

Backout all the PG_RELEASED changes.

This is for the same reason as the earlier backouts, to avoid the bug
either added or exposed sometime around c2k9. This *should* be the last
one.

prompted by deraadt@

ok ariane@


# 1.51 23-May-2009 oga

More PG_RELEASED cleaning.

similar to the aobj.c changes, this one does vnodes. Vnodes are more
complex because they actaully have to sync to backing store. So firstly,
convert sync to sleep instead of setting released.

Now, for backing store, in the PGO_FREE case, if we set PG_RELEASED
*before* an async io, (nothing else will see it, the page is busy), then
we can ignore the page after the io is done. We could do something
similar for PGO_DEACTIVATE too, but that is another change. On error we
just clear the released flag, nothing else sets it for uobj pages other
than aiodoned.

ok thib@, beck@, ariane@


# 1.50 04-May-2009 oga

Instead of keeping two ints in the uvm structure specifically just to
sleep on them (and otherwise ignore them) sleep on the pointer to the
{aiodoned,pagedaemon}_proc members, and nuke the two extra words.

"no objections" art@, ok beck@.


# 1.49 06-Apr-2009 oga

Instead of doing splbio(); simple_lock(&uvm.aiodoned_lock); just replace
the simple lock with a real lock - a IPL_BIO mutex. While i'm here, make
the sleeping condition one hell of a lot simpler in the aio daemon.

some ideas from and ok art@.


# 1.48 25-Mar-2009 oga

Move all of the pseudo-inline functions in uvm into C files.

By pseudo-inline, I mean that if a certain macro was defined, they would
be inlined. However, no architecture defines that, and none has for a
very very long time. Therefore mainly this just makes the code a damned
sight easier to read. Some k&r -> ansi declarations while I'm in there.

"just commit it" art@. ok weingart@.


# 1.47 20-Mar-2009 oga

While working on some stuff in uvm I've gotten REALLY sick of reading
K&R function declarations, so switch them all over to ansi-style, in
accordance with the prophesy.

"go for it" art@


Revision tags: OPENBSD_4_5_BASE
# 1.46 27-Jan-2009 ariane

Simplify page-out/page-in map management; fix rare pager deadlock.

Ok: miod, tedu


# 1.45 24-Nov-2008 thib

garbage collect uvm_errno2vmerror();

ok miod@, art@


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.44 26-Nov-2007 miod

In uvm_aio_aiodone(), kill the variable-sized array on stack, and use a
fixed size array which size should match any buf; if a bogus buf is passed
to this function, the kernel will KASSERT instead of potentially running out
of stack and having an undefined behaviour.

ok deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.43 06-Jun-2007 deraadt

now that all partition size/offsets are potentially 64-bit, change the
type of all variables to daddr64_t. this includes the APIs for XXsize()
and XXdump(), all range checks inside bio drivers, internal variables
for disklabel handling, and even uvm's swap offsets. re-read numerous
times by otto, miod, krw, thib to look for errors


# 1.42 13-Apr-2007 art

While splitting flags and pqflags might have been a good idea in theory
to separate locking, on most modern machines this is not enough
since operations on short types touch other short types that share the
same word in memory.

Merge pg_flags and pqflags again and now use atomic operations to change
the flags. Also bump wire_count to an int and pg_version might go
int as well, just for alignment.

tested by many, many. ok miod@


# 1.41 04-Apr-2007 art

Mechanically rename the "flags" and "version" fields in struct vm_page
to "pg_flags" and "pg_version", so that they are a bit easier to work with.
Whoever uses generic names like this for a popular struct obviously doesn't
read much code.

Most architectures compile and there are no functionality changes.

deraadt@ ok ("if something fails to compile, we fix that by hand")


# 1.40 25-Mar-2007 art

remove KERN_SUCCESS and use 0 instead.
eyeballed by miod@ and pedro@


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.39 31-Jul-2006 mickey

fix uvmhist #2: args are always u_long so fix missing %d and %x and no %ll; no change for normal code


# 1.38 26-Jul-2006 mickey

fix fmts for UVMHIST_LOG() entries making it more useful on 64bit archs; miod@ ok


Revision tags: OPENBSD_3_8_BASE OPENBSD_3_9_BASE
# 1.37 26-Jul-2005 art

- Make a UVM_OBJ_IS_DEVICE macro.
- Use it to skip device mappings while dumping core.
- Ignore EFAULT errors while dumping core since they can happen
even for valid mappings. Just skip that part of the core file and
let it get automagically zero-filled.

This fixes the broken X core dumps that people have been seeing and also
fixes some other potential problems that could prevent core dumps (mmaps
beyond EOF, etc.).

tedu@ ok


# 1.36 24-May-2005 tedu

add a new field to vm_space and use it to track the number of anon
pages a process uses. this is now the userland "data size" value.
ok art deraadt tdeval. thanks testers.


Revision tags: OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE SMP_SYNC_A SMP_SYNC_B
# 1.35 23-Feb-2004 drahn

sync of pmap_update() calls with NetBSD. pmap_update is defined away on
all architectures but arm, where it is needed.


Revision tags: OPENBSD_3_4_BASE UBC_SYNC_A
# 1.34 29-Mar-2003 mickey

ubchist is not a fully cooked kadaver and though use the other well formed pdhist one until ubc gaets back. art@ ok


Revision tags: OPENBSD_3_3_BASE
# 1.33 29-Oct-2002 art

Since memory deallocation can't fail, remove the error return from
uvm_unmap, uvm_deallocate and a few other functions.
Simplifies some code and reduces diff to the UBC branch.


Revision tags: OPENBSD_3_2_BASE UBC_SYNC_B
# 1.32 24-May-2002 art

Make sure that b_iodone handlers are called at splbio (and splassert(IPL_BIO) in all known callers, just to make sure).


# 1.31 22-May-2002 art

splassert(IPL_BIO) in the b_iodone handlers.


Revision tags: OPENBSD_3_1_BASE
# 1.30 02-Jan-2002 miod

Back out a few more uvm changes, especially wrt swap usage.
This unbreaks m68k m88k sparc and perhaps others, which eventually froze
when hitting swap.
Tested by various people on various platforms.
ok art@


# 1.29 19-Dec-2001 art

UBC was a disaster. It worked very good when it worked, but on some
machines or some configurations or in some phase of the moon (we actually
don't know when or why) files disappeared. Since we've not been able to
track down the problem in two weeks intense debugging and we need -current
to be stable, back out everything to a state it had before UBC.

We apologise for the inconvenience.


Revision tags: UBC_BASE
# 1.28 04-Dec-2001 art

branches: 1.28.2;
Yet another sync to NetBSD uvm.
Today we add a pmap argument to pmap_update() and allocate map entries for
kernel_map from kmem_map instead of using the static entries. This should
get rid of MAX_KMAPENT panics. Also some uvm_loan problems are fixed.


# 1.27 30-Nov-2001 csapuntz

Call buf_cleanout, which handles wakeups


# 1.26 29-Nov-2001 art

Correctly handle b_vp with bgetvp and brelvp in {get,put}pages.
Prevents panics caused by vnodes being recycled under our feet.


# 1.25 28-Nov-2001 art

Sync in more uvm from NetBSD. Mostly just cosmetic stuff.
Contains also support for page coloring.


# 1.24 28-Nov-2001 art

Sync in more uvm changes from NetBSD.
This time we're getting rid of KERN_* and VM_PAGER_* error codes and
use errnos instead.


# 1.23 27-Nov-2001 art

Merge in the unified buffer cache code as found in NetBSD 2001/03/10. The
code is written mostly by Chuck Silvers <chuq@chuq.com>/<chs@netbsd.org>.

Tested for the past few weeks by many developers, should be in a pretty stable
state, but will require optimizations and additional cleanups.


# 1.22 12-Nov-2001 art

Bring in more changes from NetBSD. Mostly pagedaemon improvements.


# 1.21 10-Nov-2001 art

Merge in some parts of the ubc work that has been done in NetBSD that are not
UBC, but prerequsites for it.

- Create a daemon that processes async I/O (swap and paging in the future)
requests that need processing in process context and that were processed
in the pagedaemon before.
- Convert some ugly ifdef DIAGNOSTIC code to less intrusive KASSERTs.
- misc other cleanups.


# 1.20 07-Nov-2001 art

Another sync of uvm to NetBSD. Just minor fiddling, no major changes.


# 1.19 07-Nov-2001 art

Add an alignment argument to uvm_map that specifies an alignment hint
for the virtual address.


# 1.18 06-Nov-2001 art

Move the last content from vm/ to uvm/
The only thing left in vm/ are just dumb wrappers.
vm/vm.h includes uvm/uvm_extern.h
vm/pmap.h includes uvm/uvm_pmap.h
vm/vm_page.h includes uvm/uvm_page.h


# 1.17 05-Nov-2001 art

Minor sync to NetBSD.


Revision tags: OPENBSD_3_0_BASE
# 1.16 20-Sep-2001 mpech

occured->occurred

idea from deraadt@ via NetBSD
millert@ ok


# 1.15 19-Sep-2001 mickey

merge vm/vm_kern.h into uvm/uvm_extern.h; art@ ok


# 1.14 11-Aug-2001 art

Various random fixes from NetBSD.
Including support for zeroing pages in the idle loop (not enabled yet).


# 1.13 06-Aug-2001 art

Add a new type voff_t (right now it's typedefed as off_t) used for offsets
into objects.

Gives the possibilty to mmap beyond the size of vaddr_t.

From NetBSD.


# 1.12 26-Jul-2001 art

Add support for disabling swap devices (swapctl -d).
Improve error handling on I/O errors to swap.
From NetBSD


# 1.11 25-Jul-2001 art

Change the pmap_enter interface to merge access_type and the wired boolean
and arbitrary flags into one argument.

One new flag is PMAP_CANFAIL that tells pmap_enter that it can fail if there
are not enough resources to satisfy the request. If this flag is not passed,
pmap_enter should panic as it should have done before this change (XXX - many
pmaps are still not doing that).

Only i386 and alpha implement CANFAIL for now.

Includes uvm updates from NetBSD.


# 1.10 18-Jul-2001 art

Get rid of the PMAP_NEW option by making it mandatory for all archs.
The archs that didn't have a proper PMAP_NEW now have a dummy implementation
with wrappers around the old functions.


# 1.9 08-Jun-2001 art

Change the paddr_t pmap_extract(struct pmap *, vaddr_t) interface to
boolean_t pmap_extract(struct pmap *, vaddr_t, paddr_t *).
Matches NetBSD. Tested by various people on various platforms.


Revision tags: OPENBSD_2_9_BASE
# 1.8 22-Mar-2001 smart

Sync style, typo, and comments a little closer to NetBSD. art@ ok


# 1.7 08-Mar-2001 smart

Replace thread_wakeup() with wakeup(). It is defined in vm_extern.h as a
wrapper, so this removes a dependence on the old VM system. From NetBSD.
art@ ok


# 1.6 29-Jan-2001 niklas

$OpenBSD$


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE
# 1.5 16-Mar-2000 art

Bring in some new UVM code from NetBSD (not current).

- Introduce a new type of map that are interrupt safe and never allow faults
in them. mb_map and kmem_map are made intrsafe.
- Add "access protection" to uvm_vslock (to be passed down to uvm_fault and
later to pmap_enter).
- madvise(2) now works.
- various cleanups.


Revision tags: OPENBSD_2_6_BASE SMP_BASE kame_19991208
# 1.4 03-Sep-1999 art

branches: 1.4.4;
Change the pmap_enter api to pass down an argument that indicates
the access type that caused this mapping. This is to simplify pmaps
with mod/ref emulation (none for the moment) and in some cases speed
up pmap_is_{referenced,modified}.
At the same time, clean up some mappings that had too high protection.

XXX - the access type is incorrect in old vm, it's only used by uvm and MD code.
The actual use of this in pmap_enter implementations is not in this commit.


# 1.3 23-Aug-1999 art

sync with NetBSD from 1999.05.24 (there is a reason for this date)
Mostly cleanups, but also a few improvements to pagedaemon for better
handling of low memory and/or low swap conditions.


Revision tags: OPENBSD_2_5_BASE
# 1.2 26-Feb-1999 art

add OpenBSD tags


# 1.1 26-Feb-1999 art

Import of uvm from NetBSD. Some local changes, some code disabled


# 1.80 28-Jun-2022 mpi

Move the guts of uvm_aio_aiodone() into a separate function.

This will help dealing with error cases.

No functionnal changes.


# 1.79 28-Jun-2022 mpi

Do not clean PG_BUSY before calling uvm_anon_release().

Fix an assertion reported by gkoehler@.

ok kettenis@


Revision tags: OPENBSD_7_1_BASE
# 1.78 18-Feb-2022 kettenis

Convert KVA allocation to km_alloc(9).

ok mpi@


# 1.77 15-Dec-2021 mpi

Use a per-UVM object lock to serialize the lower part of the fault handler.

Like the per-amap lock the `vmobjlock' is principally used to serialized
access to objects in the fault handler to allow faults occurring on
different CPUs and different objects to be processed in parallel.

The fault handler now acquires the `vmobjlock' of a given UVM object as
soon as it finds one. For now a write-lock is always acquired even if
some operations could use a read-lock.

Every pager, corresponding to a different kind of UVM object, now expect
the UVM object to be locked and some operations, like *_get() return it
unlocked. This is enforced by assertions checking for rw_write_held().

The KERNEL_LOCK() is now pushed to the VFS boundary in the vnode pager.

To ensure the correct amap or object lock is held when modifying a page
many uvm_page* operations are now asserting for the "owner" lock.
However, fields of the "struct vm_page" are still being protected by the
global `pageqlock'. To prevent lock ordering issues with the new
`vmobjlock' and to reduce differences with NetBSD this lock is now taken
and released for each page instead of around the whole loop.

This commit does not remove the KERNEL_LOCK/UNLOCK() dance. Unlocking
will follow if there is no fallout.

Ported from NetBSD, tested by many, thanks!

ok kettenis@, kn@


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.76 26-Mar-2021 mpi

Remove parenthesis around return value to reduce the diff with NetBSD.

No functional change.

ok mlarkin@


# 1.75 12-Mar-2021 jsg

spelling

ok mpi@


# 1.74 19-Jan-2021 mpi

(re)Introduce locking for amaps & anons.

A rwlock is attached to every amap and is shared with all its anon. The
same lock will be used by multiple amaps if they have anons in common.

This should be enough to get the upper part of the fault handler out of the
KERNEL_LOCK() which seems to bring up to 20% improvements in builds.

This is based/copied/adapted from the most recent work done in NetBSD which
is an evolution of the precendent simple_lock scheme.

Tested by many, thanks!

ok kettenis@, mvs@


# 1.73 21-Oct-2020 mpi

Constify and use C99 initializer for "struct uvm_pagerops".

While here put some KERNEL_ASSERT_LOCKED() in the functions called from
the page fault handler. The removal of locking of `uobj' will need to be
revisited and these are good indicator that something is missing and that
many comments are lying.

ok kettenis


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.72 08-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok visa@, jca@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.71 17-Dec-2014 tedu

remove lock.h from uvm_extern.h. another holdover from the simpletonlock
era. fix uvm including c files to include lock.h or atomic.h as necessary.
ok deraadt


# 1.70 16-Nov-2014 deraadt

Replace a plethora of historical protection options with just
PROT_NONE, PROT_READ, PROT_WRITE, and PROT_EXEC from mman.h.
PROT_MASK is introduced as the one true way of extracting those bits.
Remove UVM_ADV_* wrapper, using the standard names.
ok doug guenther kettenis


# 1.69 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.68 11-Jul-2014 jsg

Chuck Cranor rescinded clauses in his license
on the 2nd of February 2011 in NetBSD.

http://marc.info/?l=netbsd-source-changes&m=129658899212732&w=2
http://marc.info/?l=netbsd-source-changes&m=129659095515558&w=2
http://marc.info/?l=netbsd-source-changes&m=129659157916514&w=2
http://marc.info/?l=netbsd-source-changes&m=129665962324372&w=2
http://marc.info/?l=netbsd-source-changes&m=129666033625342&w=2
http://marc.info/?l=netbsd-source-changes&m=129666052825545&w=2
http://marc.info/?l=netbsd-source-changes&m=129666922906480&w=2
http://marc.info/?l=netbsd-source-changes&m=129667725518082&w=2


# 1.67 09-May-2014 tedu

stop using B_AGE, it was effectively retired some time ago.


# 1.66 08-May-2014 kettenis

Fix some potential integer overflows caused by converting a page number into
an offset/size/address by shifting by PAGE_SHIFT. Make uvm_objwrire/unwire
use voff_t instead of off_t. The former is the right type here even if it is
equivalent to the latter.

Inspired by a somewhat similar changes in Bitrig.

ok deraadt@, guenther@


# 1.65 13-Apr-2014 tedu

compress code by turning four line comments into one line comments.
emphatic ok usual suspects, grudging ok miod


Revision tags: OPENBSD_5_5_BASE
# 1.64 02-Nov-2013 krw

No need to cast constants or simple variables to (daddr_t). Use
(u_int64_t) instead of (daddr_t) when casting a variable in an
expression passed to DL_SETDSIZE().

Change a variable counting open files from daddr_t to int64_t.

ok deraadt@ with the tweak to fix that pesky expression.


Revision tags: OPENBSD_5_4_BASE
# 1.63 11-Jun-2013 deraadt

final removal of daddr64_t. daddr_t has been 64 bit for a long enough
test period; i think 3 years ago the last bugs fell out.
ok otto beck others


# 1.62 30-May-2013 tedu

remove lots of comments about locking per beck's request


# 1.61 30-May-2013 tedu

remove simple_locks from uvm code. ok beck deraadt


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.60 03-Jul-2011 oga

Rip out and burn support for UVM_HIST.

The vm hackers don't use it, don't maintain it and have to look at it all the
time. About time this 800 lines of code hit /dev/null.

``never liked it'' tedu@. ariane@ was very happy when i told her i wrote
this diff.


# 1.59 15-Apr-2011 oga

for uvm_pager_dropcluster in the PG_RELEASED case we specifically unbusy the
page so that um_anfree will free it for us.

uvm_anfree does a pmap_page_protect(, VM_PROT_NONE) just before it frees the
page, so we don't need to do it here ourselves.

ok ariane@


# 1.58 15-Apr-2011 oga

move uvm_pageratop from uvm_pager.c local to a general uvm function
(uvm_atopg) and use it in uvm_km_doputpage to replace some handrolled
code. Shrinks the kernel a trivial amount.

ok beck@ and miod@ (who suggested i name it uvm_atopg not uvm_atop)


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.57 24-Jul-2010 kettenis

Don't sleep while holding the uvm_psel_lck mutex. Should fix "locking against
myself" panics that some people have seen over the last year-and-a-half.

Cherry picked from a more complex (and therefore scarier) diff from oga@.

ok tedu@, oga@


# 1.56 27-Jun-2010 oga

Kill another #ifdef UBC chunk that was annoying me while doing something
else.

ok thib@


Revision tags: OPENBSD_4_7_BASE
# 1.55 12-Feb-2010 tedu

introduce a uvm_km_valloc_try function that won't get a lower level lock
for use by the uvm pseg code. this is the path of least resistance until
we sort out how many of these functions we really need. problem found by mikeb
ok kettenis oga


# 1.54 22-Jul-2009 oga

Put the PG_RELEASED changes diff back in.

This has has been tested very very thoroughly on all archs we have
excepting 88k and 68k. Please see cvs log for the individual commit
messages.

ok beck@, thib@


Revision tags: OPENBSD_4_6_BASE
# 1.53 17-Jun-2009 oga

date based reversion of uvm to the 4th May.

More backouts in line with previous ones, this appears to bring us back to a
stable condition.

A machine forced to 64mb of ram cycled 10GB through swap with this diff
and is still running as I type this. Other tests by ariane@ and thib@
also seem to show that it's alright.

ok deraadt@, thib@, ariane@


# 1.52 16-Jun-2009 oga

Backout all the PG_RELEASED changes.

This is for the same reason as the earlier backouts, to avoid the bug
either added or exposed sometime around c2k9. This *should* be the last
one.

prompted by deraadt@

ok ariane@


# 1.51 23-May-2009 oga

More PG_RELEASED cleaning.

similar to the aobj.c changes, this one does vnodes. Vnodes are more
complex because they actaully have to sync to backing store. So firstly,
convert sync to sleep instead of setting released.

Now, for backing store, in the PGO_FREE case, if we set PG_RELEASED
*before* an async io, (nothing else will see it, the page is busy), then
we can ignore the page after the io is done. We could do something
similar for PGO_DEACTIVATE too, but that is another change. On error we
just clear the released flag, nothing else sets it for uobj pages other
than aiodoned.

ok thib@, beck@, ariane@


# 1.50 04-May-2009 oga

Instead of keeping two ints in the uvm structure specifically just to
sleep on them (and otherwise ignore them) sleep on the pointer to the
{aiodoned,pagedaemon}_proc members, and nuke the two extra words.

"no objections" art@, ok beck@.


# 1.49 06-Apr-2009 oga

Instead of doing splbio(); simple_lock(&uvm.aiodoned_lock); just replace
the simple lock with a real lock - a IPL_BIO mutex. While i'm here, make
the sleeping condition one hell of a lot simpler in the aio daemon.

some ideas from and ok art@.


# 1.48 25-Mar-2009 oga

Move all of the pseudo-inline functions in uvm into C files.

By pseudo-inline, I mean that if a certain macro was defined, they would
be inlined. However, no architecture defines that, and none has for a
very very long time. Therefore mainly this just makes the code a damned
sight easier to read. Some k&r -> ansi declarations while I'm in there.

"just commit it" art@. ok weingart@.


# 1.47 20-Mar-2009 oga

While working on some stuff in uvm I've gotten REALLY sick of reading
K&R function declarations, so switch them all over to ansi-style, in
accordance with the prophesy.

"go for it" art@


Revision tags: OPENBSD_4_5_BASE
# 1.46 27-Jan-2009 ariane

Simplify page-out/page-in map management; fix rare pager deadlock.

Ok: miod, tedu


# 1.45 24-Nov-2008 thib

garbage collect uvm_errno2vmerror();

ok miod@, art@


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.44 26-Nov-2007 miod

In uvm_aio_aiodone(), kill the variable-sized array on stack, and use a
fixed size array which size should match any buf; if a bogus buf is passed
to this function, the kernel will KASSERT instead of potentially running out
of stack and having an undefined behaviour.

ok deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.43 06-Jun-2007 deraadt

now that all partition size/offsets are potentially 64-bit, change the
type of all variables to daddr64_t. this includes the APIs for XXsize()
and XXdump(), all range checks inside bio drivers, internal variables
for disklabel handling, and even uvm's swap offsets. re-read numerous
times by otto, miod, krw, thib to look for errors


# 1.42 13-Apr-2007 art

While splitting flags and pqflags might have been a good idea in theory
to separate locking, on most modern machines this is not enough
since operations on short types touch other short types that share the
same word in memory.

Merge pg_flags and pqflags again and now use atomic operations to change
the flags. Also bump wire_count to an int and pg_version might go
int as well, just for alignment.

tested by many, many. ok miod@


# 1.41 04-Apr-2007 art

Mechanically rename the "flags" and "version" fields in struct vm_page
to "pg_flags" and "pg_version", so that they are a bit easier to work with.
Whoever uses generic names like this for a popular struct obviously doesn't
read much code.

Most architectures compile and there are no functionality changes.

deraadt@ ok ("if something fails to compile, we fix that by hand")


# 1.40 25-Mar-2007 art

remove KERN_SUCCESS and use 0 instead.
eyeballed by miod@ and pedro@


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.39 31-Jul-2006 mickey

fix uvmhist #2: args are always u_long so fix missing %d and %x and no %ll; no change for normal code


# 1.38 26-Jul-2006 mickey

fix fmts for UVMHIST_LOG() entries making it more useful on 64bit archs; miod@ ok


Revision tags: OPENBSD_3_8_BASE OPENBSD_3_9_BASE
# 1.37 26-Jul-2005 art

- Make a UVM_OBJ_IS_DEVICE macro.
- Use it to skip device mappings while dumping core.
- Ignore EFAULT errors while dumping core since they can happen
even for valid mappings. Just skip that part of the core file and
let it get automagically zero-filled.

This fixes the broken X core dumps that people have been seeing and also
fixes some other potential problems that could prevent core dumps (mmaps
beyond EOF, etc.).

tedu@ ok


# 1.36 24-May-2005 tedu

add a new field to vm_space and use it to track the number of anon
pages a process uses. this is now the userland "data size" value.
ok art deraadt tdeval. thanks testers.


Revision tags: OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE SMP_SYNC_A SMP_SYNC_B
# 1.35 23-Feb-2004 drahn

sync of pmap_update() calls with NetBSD. pmap_update is defined away on
all architectures but arm, where it is needed.


Revision tags: OPENBSD_3_4_BASE UBC_SYNC_A
# 1.34 29-Mar-2003 mickey

ubchist is not a fully cooked kadaver and though use the other well formed pdhist one until ubc gaets back. art@ ok


Revision tags: OPENBSD_3_3_BASE
# 1.33 29-Oct-2002 art

Since memory deallocation can't fail, remove the error return from
uvm_unmap, uvm_deallocate and a few other functions.
Simplifies some code and reduces diff to the UBC branch.


Revision tags: OPENBSD_3_2_BASE UBC_SYNC_B
# 1.32 24-May-2002 art

Make sure that b_iodone handlers are called at splbio (and splassert(IPL_BIO) in all known callers, just to make sure).


# 1.31 22-May-2002 art

splassert(IPL_BIO) in the b_iodone handlers.


Revision tags: OPENBSD_3_1_BASE
# 1.30 02-Jan-2002 miod

Back out a few more uvm changes, especially wrt swap usage.
This unbreaks m68k m88k sparc and perhaps others, which eventually froze
when hitting swap.
Tested by various people on various platforms.
ok art@


# 1.29 19-Dec-2001 art

UBC was a disaster. It worked very good when it worked, but on some
machines or some configurations or in some phase of the moon (we actually
don't know when or why) files disappeared. Since we've not been able to
track down the problem in two weeks intense debugging and we need -current
to be stable, back out everything to a state it had before UBC.

We apologise for the inconvenience.


Revision tags: UBC_BASE
# 1.28 04-Dec-2001 art

branches: 1.28.2;
Yet another sync to NetBSD uvm.
Today we add a pmap argument to pmap_update() and allocate map entries for
kernel_map from kmem_map instead of using the static entries. This should
get rid of MAX_KMAPENT panics. Also some uvm_loan problems are fixed.


# 1.27 30-Nov-2001 csapuntz

Call buf_cleanout, which handles wakeups


# 1.26 29-Nov-2001 art

Correctly handle b_vp with bgetvp and brelvp in {get,put}pages.
Prevents panics caused by vnodes being recycled under our feet.


# 1.25 28-Nov-2001 art

Sync in more uvm from NetBSD. Mostly just cosmetic stuff.
Contains also support for page coloring.


# 1.24 28-Nov-2001 art

Sync in more uvm changes from NetBSD.
This time we're getting rid of KERN_* and VM_PAGER_* error codes and
use errnos instead.


# 1.23 27-Nov-2001 art

Merge in the unified buffer cache code as found in NetBSD 2001/03/10. The
code is written mostly by Chuck Silvers <chuq@chuq.com>/<chs@netbsd.org>.

Tested for the past few weeks by many developers, should be in a pretty stable
state, but will require optimizations and additional cleanups.


# 1.22 12-Nov-2001 art

Bring in more changes from NetBSD. Mostly pagedaemon improvements.


# 1.21 10-Nov-2001 art

Merge in some parts of the ubc work that has been done in NetBSD that are not
UBC, but prerequsites for it.

- Create a daemon that processes async I/O (swap and paging in the future)
requests that need processing in process context and that were processed
in the pagedaemon before.
- Convert some ugly ifdef DIAGNOSTIC code to less intrusive KASSERTs.
- misc other cleanups.


# 1.20 07-Nov-2001 art

Another sync of uvm to NetBSD. Just minor fiddling, no major changes.


# 1.19 07-Nov-2001 art

Add an alignment argument to uvm_map that specifies an alignment hint
for the virtual address.


# 1.18 06-Nov-2001 art

Move the last content from vm/ to uvm/
The only thing left in vm/ are just dumb wrappers.
vm/vm.h includes uvm/uvm_extern.h
vm/pmap.h includes uvm/uvm_pmap.h
vm/vm_page.h includes uvm/uvm_page.h


# 1.17 05-Nov-2001 art

Minor sync to NetBSD.


Revision tags: OPENBSD_3_0_BASE
# 1.16 20-Sep-2001 mpech

occured->occurred

idea from deraadt@ via NetBSD
millert@ ok


# 1.15 19-Sep-2001 mickey

merge vm/vm_kern.h into uvm/uvm_extern.h; art@ ok


# 1.14 11-Aug-2001 art

Various random fixes from NetBSD.
Including support for zeroing pages in the idle loop (not enabled yet).


# 1.13 06-Aug-2001 art

Add a new type voff_t (right now it's typedefed as off_t) used for offsets
into objects.

Gives the possibilty to mmap beyond the size of vaddr_t.

From NetBSD.


# 1.12 26-Jul-2001 art

Add support for disabling swap devices (swapctl -d).
Improve error handling on I/O errors to swap.
From NetBSD


# 1.11 25-Jul-2001 art

Change the pmap_enter interface to merge access_type and the wired boolean
and arbitrary flags into one argument.

One new flag is PMAP_CANFAIL that tells pmap_enter that it can fail if there
are not enough resources to satisfy the request. If this flag is not passed,
pmap_enter should panic as it should have done before this change (XXX - many
pmaps are still not doing that).

Only i386 and alpha implement CANFAIL for now.

Includes uvm updates from NetBSD.


# 1.10 18-Jul-2001 art

Get rid of the PMAP_NEW option by making it mandatory for all archs.
The archs that didn't have a proper PMAP_NEW now have a dummy implementation
with wrappers around the old functions.


# 1.9 08-Jun-2001 art

Change the paddr_t pmap_extract(struct pmap *, vaddr_t) interface to
boolean_t pmap_extract(struct pmap *, vaddr_t, paddr_t *).
Matches NetBSD. Tested by various people on various platforms.


Revision tags: OPENBSD_2_9_BASE
# 1.8 22-Mar-2001 smart

Sync style, typo, and comments a little closer to NetBSD. art@ ok


# 1.7 08-Mar-2001 smart

Replace thread_wakeup() with wakeup(). It is defined in vm_extern.h as a
wrapper, so this removes a dependence on the old VM system. From NetBSD.
art@ ok


# 1.6 29-Jan-2001 niklas

$OpenBSD$


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE
# 1.5 16-Mar-2000 art

Bring in some new UVM code from NetBSD (not current).

- Introduce a new type of map that are interrupt safe and never allow faults
in them. mb_map and kmem_map are made intrsafe.
- Add "access protection" to uvm_vslock (to be passed down to uvm_fault and
later to pmap_enter).
- madvise(2) now works.
- various cleanups.


Revision tags: OPENBSD_2_6_BASE SMP_BASE kame_19991208
# 1.4 03-Sep-1999 art

branches: 1.4.4;
Change the pmap_enter api to pass down an argument that indicates
the access type that caused this mapping. This is to simplify pmaps
with mod/ref emulation (none for the moment) and in some cases speed
up pmap_is_{referenced,modified}.
At the same time, clean up some mappings that had too high protection.

XXX - the access type is incorrect in old vm, it's only used by uvm and MD code.
The actual use of this in pmap_enter implementations is not in this commit.


# 1.3 23-Aug-1999 art

sync with NetBSD from 1999.05.24 (there is a reason for this date)
Mostly cleanups, but also a few improvements to pagedaemon for better
handling of low memory and/or low swap conditions.


Revision tags: OPENBSD_2_5_BASE
# 1.2 26-Feb-1999 art

add OpenBSD tags


# 1.1 26-Feb-1999 art

Import of uvm from NetBSD. Some local changes, some code disabled


# 1.78 18-Feb-2022 kettenis

Convert KVA allocation to km_alloc(9).

ok mpi@


# 1.77 15-Dec-2021 mpi

Use a per-UVM object lock to serialize the lower part of the fault handler.

Like the per-amap lock the `vmobjlock' is principally used to serialized
access to objects in the fault handler to allow faults occurring on
different CPUs and different objects to be processed in parallel.

The fault handler now acquires the `vmobjlock' of a given UVM object as
soon as it finds one. For now a write-lock is always acquired even if
some operations could use a read-lock.

Every pager, corresponding to a different kind of UVM object, now expect
the UVM object to be locked and some operations, like *_get() return it
unlocked. This is enforced by assertions checking for rw_write_held().

The KERNEL_LOCK() is now pushed to the VFS boundary in the vnode pager.

To ensure the correct amap or object lock is held when modifying a page
many uvm_page* operations are now asserting for the "owner" lock.
However, fields of the "struct vm_page" are still being protected by the
global `pageqlock'. To prevent lock ordering issues with the new
`vmobjlock' and to reduce differences with NetBSD this lock is now taken
and released for each page instead of around the whole loop.

This commit does not remove the KERNEL_LOCK/UNLOCK() dance. Unlocking
will follow if there is no fallout.

Ported from NetBSD, tested by many, thanks!

ok kettenis@, kn@


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.76 26-Mar-2021 mpi

Remove parenthesis around return value to reduce the diff with NetBSD.

No functional change.

ok mlarkin@


# 1.75 12-Mar-2021 jsg

spelling

ok mpi@


# 1.74 19-Jan-2021 mpi

(re)Introduce locking for amaps & anons.

A rwlock is attached to every amap and is shared with all its anon. The
same lock will be used by multiple amaps if they have anons in common.

This should be enough to get the upper part of the fault handler out of the
KERNEL_LOCK() which seems to bring up to 20% improvements in builds.

This is based/copied/adapted from the most recent work done in NetBSD which
is an evolution of the precendent simple_lock scheme.

Tested by many, thanks!

ok kettenis@, mvs@


# 1.73 21-Oct-2020 mpi

Constify and use C99 initializer for "struct uvm_pagerops".

While here put some KERNEL_ASSERT_LOCKED() in the functions called from
the page fault handler. The removal of locking of `uobj' will need to be
revisited and these are good indicator that something is missing and that
many comments are lying.

ok kettenis


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.72 08-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok visa@, jca@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.71 17-Dec-2014 tedu

remove lock.h from uvm_extern.h. another holdover from the simpletonlock
era. fix uvm including c files to include lock.h or atomic.h as necessary.
ok deraadt


# 1.70 16-Nov-2014 deraadt

Replace a plethora of historical protection options with just
PROT_NONE, PROT_READ, PROT_WRITE, and PROT_EXEC from mman.h.
PROT_MASK is introduced as the one true way of extracting those bits.
Remove UVM_ADV_* wrapper, using the standard names.
ok doug guenther kettenis


# 1.69 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.68 11-Jul-2014 jsg

Chuck Cranor rescinded clauses in his license
on the 2nd of February 2011 in NetBSD.

http://marc.info/?l=netbsd-source-changes&m=129658899212732&w=2
http://marc.info/?l=netbsd-source-changes&m=129659095515558&w=2
http://marc.info/?l=netbsd-source-changes&m=129659157916514&w=2
http://marc.info/?l=netbsd-source-changes&m=129665962324372&w=2
http://marc.info/?l=netbsd-source-changes&m=129666033625342&w=2
http://marc.info/?l=netbsd-source-changes&m=129666052825545&w=2
http://marc.info/?l=netbsd-source-changes&m=129666922906480&w=2
http://marc.info/?l=netbsd-source-changes&m=129667725518082&w=2


# 1.67 09-May-2014 tedu

stop using B_AGE, it was effectively retired some time ago.


# 1.66 08-May-2014 kettenis

Fix some potential integer overflows caused by converting a page number into
an offset/size/address by shifting by PAGE_SHIFT. Make uvm_objwrire/unwire
use voff_t instead of off_t. The former is the right type here even if it is
equivalent to the latter.

Inspired by a somewhat similar changes in Bitrig.

ok deraadt@, guenther@


# 1.65 13-Apr-2014 tedu

compress code by turning four line comments into one line comments.
emphatic ok usual suspects, grudging ok miod


Revision tags: OPENBSD_5_5_BASE
# 1.64 02-Nov-2013 krw

No need to cast constants or simple variables to (daddr_t). Use
(u_int64_t) instead of (daddr_t) when casting a variable in an
expression passed to DL_SETDSIZE().

Change a variable counting open files from daddr_t to int64_t.

ok deraadt@ with the tweak to fix that pesky expression.


Revision tags: OPENBSD_5_4_BASE
# 1.63 11-Jun-2013 deraadt

final removal of daddr64_t. daddr_t has been 64 bit for a long enough
test period; i think 3 years ago the last bugs fell out.
ok otto beck others


# 1.62 30-May-2013 tedu

remove lots of comments about locking per beck's request


# 1.61 30-May-2013 tedu

remove simple_locks from uvm code. ok beck deraadt


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.60 03-Jul-2011 oga

Rip out and burn support for UVM_HIST.

The vm hackers don't use it, don't maintain it and have to look at it all the
time. About time this 800 lines of code hit /dev/null.

``never liked it'' tedu@. ariane@ was very happy when i told her i wrote
this diff.


# 1.59 15-Apr-2011 oga

for uvm_pager_dropcluster in the PG_RELEASED case we specifically unbusy the
page so that um_anfree will free it for us.

uvm_anfree does a pmap_page_protect(, VM_PROT_NONE) just before it frees the
page, so we don't need to do it here ourselves.

ok ariane@


# 1.58 15-Apr-2011 oga

move uvm_pageratop from uvm_pager.c local to a general uvm function
(uvm_atopg) and use it in uvm_km_doputpage to replace some handrolled
code. Shrinks the kernel a trivial amount.

ok beck@ and miod@ (who suggested i name it uvm_atopg not uvm_atop)


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.57 24-Jul-2010 kettenis

Don't sleep while holding the uvm_psel_lck mutex. Should fix "locking against
myself" panics that some people have seen over the last year-and-a-half.

Cherry picked from a more complex (and therefore scarier) diff from oga@.

ok tedu@, oga@


# 1.56 27-Jun-2010 oga

Kill another #ifdef UBC chunk that was annoying me while doing something
else.

ok thib@


Revision tags: OPENBSD_4_7_BASE
# 1.55 12-Feb-2010 tedu

introduce a uvm_km_valloc_try function that won't get a lower level lock
for use by the uvm pseg code. this is the path of least resistance until
we sort out how many of these functions we really need. problem found by mikeb
ok kettenis oga


# 1.54 22-Jul-2009 oga

Put the PG_RELEASED changes diff back in.

This has has been tested very very thoroughly on all archs we have
excepting 88k and 68k. Please see cvs log for the individual commit
messages.

ok beck@, thib@


Revision tags: OPENBSD_4_6_BASE
# 1.53 17-Jun-2009 oga

date based reversion of uvm to the 4th May.

More backouts in line with previous ones, this appears to bring us back to a
stable condition.

A machine forced to 64mb of ram cycled 10GB through swap with this diff
and is still running as I type this. Other tests by ariane@ and thib@
also seem to show that it's alright.

ok deraadt@, thib@, ariane@


# 1.52 16-Jun-2009 oga

Backout all the PG_RELEASED changes.

This is for the same reason as the earlier backouts, to avoid the bug
either added or exposed sometime around c2k9. This *should* be the last
one.

prompted by deraadt@

ok ariane@


# 1.51 23-May-2009 oga

More PG_RELEASED cleaning.

similar to the aobj.c changes, this one does vnodes. Vnodes are more
complex because they actaully have to sync to backing store. So firstly,
convert sync to sleep instead of setting released.

Now, for backing store, in the PGO_FREE case, if we set PG_RELEASED
*before* an async io, (nothing else will see it, the page is busy), then
we can ignore the page after the io is done. We could do something
similar for PGO_DEACTIVATE too, but that is another change. On error we
just clear the released flag, nothing else sets it for uobj pages other
than aiodoned.

ok thib@, beck@, ariane@


# 1.50 04-May-2009 oga

Instead of keeping two ints in the uvm structure specifically just to
sleep on them (and otherwise ignore them) sleep on the pointer to the
{aiodoned,pagedaemon}_proc members, and nuke the two extra words.

"no objections" art@, ok beck@.


# 1.49 06-Apr-2009 oga

Instead of doing splbio(); simple_lock(&uvm.aiodoned_lock); just replace
the simple lock with a real lock - a IPL_BIO mutex. While i'm here, make
the sleeping condition one hell of a lot simpler in the aio daemon.

some ideas from and ok art@.


# 1.48 25-Mar-2009 oga

Move all of the pseudo-inline functions in uvm into C files.

By pseudo-inline, I mean that if a certain macro was defined, they would
be inlined. However, no architecture defines that, and none has for a
very very long time. Therefore mainly this just makes the code a damned
sight easier to read. Some k&r -> ansi declarations while I'm in there.

"just commit it" art@. ok weingart@.


# 1.47 20-Mar-2009 oga

While working on some stuff in uvm I've gotten REALLY sick of reading
K&R function declarations, so switch them all over to ansi-style, in
accordance with the prophesy.

"go for it" art@


Revision tags: OPENBSD_4_5_BASE
# 1.46 27-Jan-2009 ariane

Simplify page-out/page-in map management; fix rare pager deadlock.

Ok: miod, tedu


# 1.45 24-Nov-2008 thib

garbage collect uvm_errno2vmerror();

ok miod@, art@


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.44 26-Nov-2007 miod

In uvm_aio_aiodone(), kill the variable-sized array on stack, and use a
fixed size array which size should match any buf; if a bogus buf is passed
to this function, the kernel will KASSERT instead of potentially running out
of stack and having an undefined behaviour.

ok deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.43 06-Jun-2007 deraadt

now that all partition size/offsets are potentially 64-bit, change the
type of all variables to daddr64_t. this includes the APIs for XXsize()
and XXdump(), all range checks inside bio drivers, internal variables
for disklabel handling, and even uvm's swap offsets. re-read numerous
times by otto, miod, krw, thib to look for errors


# 1.42 13-Apr-2007 art

While splitting flags and pqflags might have been a good idea in theory
to separate locking, on most modern machines this is not enough
since operations on short types touch other short types that share the
same word in memory.

Merge pg_flags and pqflags again and now use atomic operations to change
the flags. Also bump wire_count to an int and pg_version might go
int as well, just for alignment.

tested by many, many. ok miod@


# 1.41 04-Apr-2007 art

Mechanically rename the "flags" and "version" fields in struct vm_page
to "pg_flags" and "pg_version", so that they are a bit easier to work with.
Whoever uses generic names like this for a popular struct obviously doesn't
read much code.

Most architectures compile and there are no functionality changes.

deraadt@ ok ("if something fails to compile, we fix that by hand")


# 1.40 25-Mar-2007 art

remove KERN_SUCCESS and use 0 instead.
eyeballed by miod@ and pedro@


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.39 31-Jul-2006 mickey

fix uvmhist #2: args are always u_long so fix missing %d and %x and no %ll; no change for normal code


# 1.38 26-Jul-2006 mickey

fix fmts for UVMHIST_LOG() entries making it more useful on 64bit archs; miod@ ok


Revision tags: OPENBSD_3_8_BASE OPENBSD_3_9_BASE
# 1.37 26-Jul-2005 art

- Make a UVM_OBJ_IS_DEVICE macro.
- Use it to skip device mappings while dumping core.
- Ignore EFAULT errors while dumping core since they can happen
even for valid mappings. Just skip that part of the core file and
let it get automagically zero-filled.

This fixes the broken X core dumps that people have been seeing and also
fixes some other potential problems that could prevent core dumps (mmaps
beyond EOF, etc.).

tedu@ ok


# 1.36 24-May-2005 tedu

add a new field to vm_space and use it to track the number of anon
pages a process uses. this is now the userland "data size" value.
ok art deraadt tdeval. thanks testers.


Revision tags: OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE SMP_SYNC_A SMP_SYNC_B
# 1.35 23-Feb-2004 drahn

sync of pmap_update() calls with NetBSD. pmap_update is defined away on
all architectures but arm, where it is needed.


Revision tags: OPENBSD_3_4_BASE UBC_SYNC_A
# 1.34 29-Mar-2003 mickey

ubchist is not a fully cooked kadaver and though use the other well formed pdhist one until ubc gaets back. art@ ok


Revision tags: OPENBSD_3_3_BASE
# 1.33 29-Oct-2002 art

Since memory deallocation can't fail, remove the error return from
uvm_unmap, uvm_deallocate and a few other functions.
Simplifies some code and reduces diff to the UBC branch.


Revision tags: OPENBSD_3_2_BASE UBC_SYNC_B
# 1.32 24-May-2002 art

Make sure that b_iodone handlers are called at splbio (and splassert(IPL_BIO) in all known callers, just to make sure).


# 1.31 22-May-2002 art

splassert(IPL_BIO) in the b_iodone handlers.


Revision tags: OPENBSD_3_1_BASE
# 1.30 02-Jan-2002 miod

Back out a few more uvm changes, especially wrt swap usage.
This unbreaks m68k m88k sparc and perhaps others, which eventually froze
when hitting swap.
Tested by various people on various platforms.
ok art@


# 1.29 19-Dec-2001 art

UBC was a disaster. It worked very good when it worked, but on some
machines or some configurations or in some phase of the moon (we actually
don't know when or why) files disappeared. Since we've not been able to
track down the problem in two weeks intense debugging and we need -current
to be stable, back out everything to a state it had before UBC.

We apologise for the inconvenience.


Revision tags: UBC_BASE
# 1.28 04-Dec-2001 art

branches: 1.28.2;
Yet another sync to NetBSD uvm.
Today we add a pmap argument to pmap_update() and allocate map entries for
kernel_map from kmem_map instead of using the static entries. This should
get rid of MAX_KMAPENT panics. Also some uvm_loan problems are fixed.


# 1.27 30-Nov-2001 csapuntz

Call buf_cleanout, which handles wakeups


# 1.26 29-Nov-2001 art

Correctly handle b_vp with bgetvp and brelvp in {get,put}pages.
Prevents panics caused by vnodes being recycled under our feet.


# 1.25 28-Nov-2001 art

Sync in more uvm from NetBSD. Mostly just cosmetic stuff.
Contains also support for page coloring.


# 1.24 28-Nov-2001 art

Sync in more uvm changes from NetBSD.
This time we're getting rid of KERN_* and VM_PAGER_* error codes and
use errnos instead.


# 1.23 27-Nov-2001 art

Merge in the unified buffer cache code as found in NetBSD 2001/03/10. The
code is written mostly by Chuck Silvers <chuq@chuq.com>/<chs@netbsd.org>.

Tested for the past few weeks by many developers, should be in a pretty stable
state, but will require optimizations and additional cleanups.


# 1.22 12-Nov-2001 art

Bring in more changes from NetBSD. Mostly pagedaemon improvements.


# 1.21 10-Nov-2001 art

Merge in some parts of the ubc work that has been done in NetBSD that are not
UBC, but prerequsites for it.

- Create a daemon that processes async I/O (swap and paging in the future)
requests that need processing in process context and that were processed
in the pagedaemon before.
- Convert some ugly ifdef DIAGNOSTIC code to less intrusive KASSERTs.
- misc other cleanups.


# 1.20 07-Nov-2001 art

Another sync of uvm to NetBSD. Just minor fiddling, no major changes.


# 1.19 07-Nov-2001 art

Add an alignment argument to uvm_map that specifies an alignment hint
for the virtual address.


# 1.18 06-Nov-2001 art

Move the last content from vm/ to uvm/
The only thing left in vm/ are just dumb wrappers.
vm/vm.h includes uvm/uvm_extern.h
vm/pmap.h includes uvm/uvm_pmap.h
vm/vm_page.h includes uvm/uvm_page.h


# 1.17 05-Nov-2001 art

Minor sync to NetBSD.


Revision tags: OPENBSD_3_0_BASE
# 1.16 20-Sep-2001 mpech

occured->occurred

idea from deraadt@ via NetBSD
millert@ ok


# 1.15 19-Sep-2001 mickey

merge vm/vm_kern.h into uvm/uvm_extern.h; art@ ok


# 1.14 11-Aug-2001 art

Various random fixes from NetBSD.
Including support for zeroing pages in the idle loop (not enabled yet).


# 1.13 06-Aug-2001 art

Add a new type voff_t (right now it's typedefed as off_t) used for offsets
into objects.

Gives the possibilty to mmap beyond the size of vaddr_t.

From NetBSD.


# 1.12 26-Jul-2001 art

Add support for disabling swap devices (swapctl -d).
Improve error handling on I/O errors to swap.
From NetBSD


# 1.11 25-Jul-2001 art

Change the pmap_enter interface to merge access_type and the wired boolean
and arbitrary flags into one argument.

One new flag is PMAP_CANFAIL that tells pmap_enter that it can fail if there
are not enough resources to satisfy the request. If this flag is not passed,
pmap_enter should panic as it should have done before this change (XXX - many
pmaps are still not doing that).

Only i386 and alpha implement CANFAIL for now.

Includes uvm updates from NetBSD.


# 1.10 18-Jul-2001 art

Get rid of the PMAP_NEW option by making it mandatory for all archs.
The archs that didn't have a proper PMAP_NEW now have a dummy implementation
with wrappers around the old functions.


# 1.9 08-Jun-2001 art

Change the paddr_t pmap_extract(struct pmap *, vaddr_t) interface to
boolean_t pmap_extract(struct pmap *, vaddr_t, paddr_t *).
Matches NetBSD. Tested by various people on various platforms.


Revision tags: OPENBSD_2_9_BASE
# 1.8 22-Mar-2001 smart

Sync style, typo, and comments a little closer to NetBSD. art@ ok


# 1.7 08-Mar-2001 smart

Replace thread_wakeup() with wakeup(). It is defined in vm_extern.h as a
wrapper, so this removes a dependence on the old VM system. From NetBSD.
art@ ok


# 1.6 29-Jan-2001 niklas

$OpenBSD$


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE
# 1.5 16-Mar-2000 art

Bring in some new UVM code from NetBSD (not current).

- Introduce a new type of map that are interrupt safe and never allow faults
in them. mb_map and kmem_map are made intrsafe.
- Add "access protection" to uvm_vslock (to be passed down to uvm_fault and
later to pmap_enter).
- madvise(2) now works.
- various cleanups.


Revision tags: OPENBSD_2_6_BASE SMP_BASE kame_19991208
# 1.4 03-Sep-1999 art

branches: 1.4.4;
Change the pmap_enter api to pass down an argument that indicates
the access type that caused this mapping. This is to simplify pmaps
with mod/ref emulation (none for the moment) and in some cases speed
up pmap_is_{referenced,modified}.
At the same time, clean up some mappings that had too high protection.

XXX - the access type is incorrect in old vm, it's only used by uvm and MD code.
The actual use of this in pmap_enter implementations is not in this commit.


# 1.3 23-Aug-1999 art

sync with NetBSD from 1999.05.24 (there is a reason for this date)
Mostly cleanups, but also a few improvements to pagedaemon for better
handling of low memory and/or low swap conditions.


Revision tags: OPENBSD_2_5_BASE
# 1.2 26-Feb-1999 art

add OpenBSD tags


# 1.1 26-Feb-1999 art

Import of uvm from NetBSD. Some local changes, some code disabled


# 1.77 15-Dec-2021 mpi

Use a per-UVM object lock to serialize the lower part of the fault handler.

Like the per-amap lock the `vmobjlock' is principally used to serialized
access to objects in the fault handler to allow faults occurring on
different CPUs and different objects to be processed in parallel.

The fault handler now acquires the `vmobjlock' of a given UVM object as
soon as it finds one. For now a write-lock is always acquired even if
some operations could use a read-lock.

Every pager, corresponding to a different kind of UVM object, now expect
the UVM object to be locked and some operations, like *_get() return it
unlocked. This is enforced by assertions checking for rw_write_held().

The KERNEL_LOCK() is now pushed to the VFS boundary in the vnode pager.

To ensure the correct amap or object lock is held when modifying a page
many uvm_page* operations are now asserting for the "owner" lock.
However, fields of the "struct vm_page" are still being protected by the
global `pageqlock'. To prevent lock ordering issues with the new
`vmobjlock' and to reduce differences with NetBSD this lock is now taken
and released for each page instead of around the whole loop.

This commit does not remove the KERNEL_LOCK/UNLOCK() dance. Unlocking
will follow if there is no fallout.

Ported from NetBSD, tested by many, thanks!

ok kettenis@, kn@


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.76 26-Mar-2021 mpi

Remove parenthesis around return value to reduce the diff with NetBSD.

No functional change.

ok mlarkin@


# 1.75 12-Mar-2021 jsg

spelling

ok mpi@


# 1.74 19-Jan-2021 mpi

(re)Introduce locking for amaps & anons.

A rwlock is attached to every amap and is shared with all its anon. The
same lock will be used by multiple amaps if they have anons in common.

This should be enough to get the upper part of the fault handler out of the
KERNEL_LOCK() which seems to bring up to 20% improvements in builds.

This is based/copied/adapted from the most recent work done in NetBSD which
is an evolution of the precendent simple_lock scheme.

Tested by many, thanks!

ok kettenis@, mvs@


# 1.73 21-Oct-2020 mpi

Constify and use C99 initializer for "struct uvm_pagerops".

While here put some KERNEL_ASSERT_LOCKED() in the functions called from
the page fault handler. The removal of locking of `uobj' will need to be
revisited and these are good indicator that something is missing and that
many comments are lying.

ok kettenis


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.72 08-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok visa@, jca@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.71 17-Dec-2014 tedu

remove lock.h from uvm_extern.h. another holdover from the simpletonlock
era. fix uvm including c files to include lock.h or atomic.h as necessary.
ok deraadt


# 1.70 16-Nov-2014 deraadt

Replace a plethora of historical protection options with just
PROT_NONE, PROT_READ, PROT_WRITE, and PROT_EXEC from mman.h.
PROT_MASK is introduced as the one true way of extracting those bits.
Remove UVM_ADV_* wrapper, using the standard names.
ok doug guenther kettenis


# 1.69 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.68 11-Jul-2014 jsg

Chuck Cranor rescinded clauses in his license
on the 2nd of February 2011 in NetBSD.

http://marc.info/?l=netbsd-source-changes&m=129658899212732&w=2
http://marc.info/?l=netbsd-source-changes&m=129659095515558&w=2
http://marc.info/?l=netbsd-source-changes&m=129659157916514&w=2
http://marc.info/?l=netbsd-source-changes&m=129665962324372&w=2
http://marc.info/?l=netbsd-source-changes&m=129666033625342&w=2
http://marc.info/?l=netbsd-source-changes&m=129666052825545&w=2
http://marc.info/?l=netbsd-source-changes&m=129666922906480&w=2
http://marc.info/?l=netbsd-source-changes&m=129667725518082&w=2


# 1.67 09-May-2014 tedu

stop using B_AGE, it was effectively retired some time ago.


# 1.66 08-May-2014 kettenis

Fix some potential integer overflows caused by converting a page number into
an offset/size/address by shifting by PAGE_SHIFT. Make uvm_objwrire/unwire
use voff_t instead of off_t. The former is the right type here even if it is
equivalent to the latter.

Inspired by a somewhat similar changes in Bitrig.

ok deraadt@, guenther@


# 1.65 13-Apr-2014 tedu

compress code by turning four line comments into one line comments.
emphatic ok usual suspects, grudging ok miod


Revision tags: OPENBSD_5_5_BASE
# 1.64 02-Nov-2013 krw

No need to cast constants or simple variables to (daddr_t). Use
(u_int64_t) instead of (daddr_t) when casting a variable in an
expression passed to DL_SETDSIZE().

Change a variable counting open files from daddr_t to int64_t.

ok deraadt@ with the tweak to fix that pesky expression.


Revision tags: OPENBSD_5_4_BASE
# 1.63 11-Jun-2013 deraadt

final removal of daddr64_t. daddr_t has been 64 bit for a long enough
test period; i think 3 years ago the last bugs fell out.
ok otto beck others


# 1.62 30-May-2013 tedu

remove lots of comments about locking per beck's request


# 1.61 30-May-2013 tedu

remove simple_locks from uvm code. ok beck deraadt


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.60 03-Jul-2011 oga

Rip out and burn support for UVM_HIST.

The vm hackers don't use it, don't maintain it and have to look at it all the
time. About time this 800 lines of code hit /dev/null.

``never liked it'' tedu@. ariane@ was very happy when i told her i wrote
this diff.


# 1.59 15-Apr-2011 oga

for uvm_pager_dropcluster in the PG_RELEASED case we specifically unbusy the
page so that um_anfree will free it for us.

uvm_anfree does a pmap_page_protect(, VM_PROT_NONE) just before it frees the
page, so we don't need to do it here ourselves.

ok ariane@


# 1.58 15-Apr-2011 oga

move uvm_pageratop from uvm_pager.c local to a general uvm function
(uvm_atopg) and use it in uvm_km_doputpage to replace some handrolled
code. Shrinks the kernel a trivial amount.

ok beck@ and miod@ (who suggested i name it uvm_atopg not uvm_atop)


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.57 24-Jul-2010 kettenis

Don't sleep while holding the uvm_psel_lck mutex. Should fix "locking against
myself" panics that some people have seen over the last year-and-a-half.

Cherry picked from a more complex (and therefore scarier) diff from oga@.

ok tedu@, oga@


# 1.56 27-Jun-2010 oga

Kill another #ifdef UBC chunk that was annoying me while doing something
else.

ok thib@


Revision tags: OPENBSD_4_7_BASE
# 1.55 12-Feb-2010 tedu

introduce a uvm_km_valloc_try function that won't get a lower level lock
for use by the uvm pseg code. this is the path of least resistance until
we sort out how many of these functions we really need. problem found by mikeb
ok kettenis oga


# 1.54 22-Jul-2009 oga

Put the PG_RELEASED changes diff back in.

This has has been tested very very thoroughly on all archs we have
excepting 88k and 68k. Please see cvs log for the individual commit
messages.

ok beck@, thib@


Revision tags: OPENBSD_4_6_BASE
# 1.53 17-Jun-2009 oga

date based reversion of uvm to the 4th May.

More backouts in line with previous ones, this appears to bring us back to a
stable condition.

A machine forced to 64mb of ram cycled 10GB through swap with this diff
and is still running as I type this. Other tests by ariane@ and thib@
also seem to show that it's alright.

ok deraadt@, thib@, ariane@


# 1.52 16-Jun-2009 oga

Backout all the PG_RELEASED changes.

This is for the same reason as the earlier backouts, to avoid the bug
either added or exposed sometime around c2k9. This *should* be the last
one.

prompted by deraadt@

ok ariane@


# 1.51 23-May-2009 oga

More PG_RELEASED cleaning.

similar to the aobj.c changes, this one does vnodes. Vnodes are more
complex because they actaully have to sync to backing store. So firstly,
convert sync to sleep instead of setting released.

Now, for backing store, in the PGO_FREE case, if we set PG_RELEASED
*before* an async io, (nothing else will see it, the page is busy), then
we can ignore the page after the io is done. We could do something
similar for PGO_DEACTIVATE too, but that is another change. On error we
just clear the released flag, nothing else sets it for uobj pages other
than aiodoned.

ok thib@, beck@, ariane@


# 1.50 04-May-2009 oga

Instead of keeping two ints in the uvm structure specifically just to
sleep on them (and otherwise ignore them) sleep on the pointer to the
{aiodoned,pagedaemon}_proc members, and nuke the two extra words.

"no objections" art@, ok beck@.


# 1.49 06-Apr-2009 oga

Instead of doing splbio(); simple_lock(&uvm.aiodoned_lock); just replace
the simple lock with a real lock - a IPL_BIO mutex. While i'm here, make
the sleeping condition one hell of a lot simpler in the aio daemon.

some ideas from and ok art@.


# 1.48 25-Mar-2009 oga

Move all of the pseudo-inline functions in uvm into C files.

By pseudo-inline, I mean that if a certain macro was defined, they would
be inlined. However, no architecture defines that, and none has for a
very very long time. Therefore mainly this just makes the code a damned
sight easier to read. Some k&r -> ansi declarations while I'm in there.

"just commit it" art@. ok weingart@.


# 1.47 20-Mar-2009 oga

While working on some stuff in uvm I've gotten REALLY sick of reading
K&R function declarations, so switch them all over to ansi-style, in
accordance with the prophesy.

"go for it" art@


Revision tags: OPENBSD_4_5_BASE
# 1.46 27-Jan-2009 ariane

Simplify page-out/page-in map management; fix rare pager deadlock.

Ok: miod, tedu


# 1.45 24-Nov-2008 thib

garbage collect uvm_errno2vmerror();

ok miod@, art@


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.44 26-Nov-2007 miod

In uvm_aio_aiodone(), kill the variable-sized array on stack, and use a
fixed size array which size should match any buf; if a bogus buf is passed
to this function, the kernel will KASSERT instead of potentially running out
of stack and having an undefined behaviour.

ok deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.43 06-Jun-2007 deraadt

now that all partition size/offsets are potentially 64-bit, change the
type of all variables to daddr64_t. this includes the APIs for XXsize()
and XXdump(), all range checks inside bio drivers, internal variables
for disklabel handling, and even uvm's swap offsets. re-read numerous
times by otto, miod, krw, thib to look for errors


# 1.42 13-Apr-2007 art

While splitting flags and pqflags might have been a good idea in theory
to separate locking, on most modern machines this is not enough
since operations on short types touch other short types that share the
same word in memory.

Merge pg_flags and pqflags again and now use atomic operations to change
the flags. Also bump wire_count to an int and pg_version might go
int as well, just for alignment.

tested by many, many. ok miod@


# 1.41 04-Apr-2007 art

Mechanically rename the "flags" and "version" fields in struct vm_page
to "pg_flags" and "pg_version", so that they are a bit easier to work with.
Whoever uses generic names like this for a popular struct obviously doesn't
read much code.

Most architectures compile and there are no functionality changes.

deraadt@ ok ("if something fails to compile, we fix that by hand")


# 1.40 25-Mar-2007 art

remove KERN_SUCCESS and use 0 instead.
eyeballed by miod@ and pedro@


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.39 31-Jul-2006 mickey

fix uvmhist #2: args are always u_long so fix missing %d and %x and no %ll; no change for normal code


# 1.38 26-Jul-2006 mickey

fix fmts for UVMHIST_LOG() entries making it more useful on 64bit archs; miod@ ok


Revision tags: OPENBSD_3_8_BASE OPENBSD_3_9_BASE
# 1.37 26-Jul-2005 art

- Make a UVM_OBJ_IS_DEVICE macro.
- Use it to skip device mappings while dumping core.
- Ignore EFAULT errors while dumping core since they can happen
even for valid mappings. Just skip that part of the core file and
let it get automagically zero-filled.

This fixes the broken X core dumps that people have been seeing and also
fixes some other potential problems that could prevent core dumps (mmaps
beyond EOF, etc.).

tedu@ ok


# 1.36 24-May-2005 tedu

add a new field to vm_space and use it to track the number of anon
pages a process uses. this is now the userland "data size" value.
ok art deraadt tdeval. thanks testers.


Revision tags: OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE SMP_SYNC_A SMP_SYNC_B
# 1.35 23-Feb-2004 drahn

sync of pmap_update() calls with NetBSD. pmap_update is defined away on
all architectures but arm, where it is needed.


Revision tags: OPENBSD_3_4_BASE UBC_SYNC_A
# 1.34 29-Mar-2003 mickey

ubchist is not a fully cooked kadaver and though use the other well formed pdhist one until ubc gaets back. art@ ok


Revision tags: OPENBSD_3_3_BASE
# 1.33 29-Oct-2002 art

Since memory deallocation can't fail, remove the error return from
uvm_unmap, uvm_deallocate and a few other functions.
Simplifies some code and reduces diff to the UBC branch.


Revision tags: OPENBSD_3_2_BASE UBC_SYNC_B
# 1.32 24-May-2002 art

Make sure that b_iodone handlers are called at splbio (and splassert(IPL_BIO) in all known callers, just to make sure).


# 1.31 22-May-2002 art

splassert(IPL_BIO) in the b_iodone handlers.


Revision tags: OPENBSD_3_1_BASE
# 1.30 02-Jan-2002 miod

Back out a few more uvm changes, especially wrt swap usage.
This unbreaks m68k m88k sparc and perhaps others, which eventually froze
when hitting swap.
Tested by various people on various platforms.
ok art@


# 1.29 19-Dec-2001 art

UBC was a disaster. It worked very good when it worked, but on some
machines or some configurations or in some phase of the moon (we actually
don't know when or why) files disappeared. Since we've not been able to
track down the problem in two weeks intense debugging and we need -current
to be stable, back out everything to a state it had before UBC.

We apologise for the inconvenience.


Revision tags: UBC_BASE
# 1.28 04-Dec-2001 art

branches: 1.28.2;
Yet another sync to NetBSD uvm.
Today we add a pmap argument to pmap_update() and allocate map entries for
kernel_map from kmem_map instead of using the static entries. This should
get rid of MAX_KMAPENT panics. Also some uvm_loan problems are fixed.


# 1.27 30-Nov-2001 csapuntz

Call buf_cleanout, which handles wakeups


# 1.26 29-Nov-2001 art

Correctly handle b_vp with bgetvp and brelvp in {get,put}pages.
Prevents panics caused by vnodes being recycled under our feet.


# 1.25 28-Nov-2001 art

Sync in more uvm from NetBSD. Mostly just cosmetic stuff.
Contains also support for page coloring.


# 1.24 28-Nov-2001 art

Sync in more uvm changes from NetBSD.
This time we're getting rid of KERN_* and VM_PAGER_* error codes and
use errnos instead.


# 1.23 27-Nov-2001 art

Merge in the unified buffer cache code as found in NetBSD 2001/03/10. The
code is written mostly by Chuck Silvers <chuq@chuq.com>/<chs@netbsd.org>.

Tested for the past few weeks by many developers, should be in a pretty stable
state, but will require optimizations and additional cleanups.


# 1.22 12-Nov-2001 art

Bring in more changes from NetBSD. Mostly pagedaemon improvements.


# 1.21 10-Nov-2001 art

Merge in some parts of the ubc work that has been done in NetBSD that are not
UBC, but prerequsites for it.

- Create a daemon that processes async I/O (swap and paging in the future)
requests that need processing in process context and that were processed
in the pagedaemon before.
- Convert some ugly ifdef DIAGNOSTIC code to less intrusive KASSERTs.
- misc other cleanups.


# 1.20 07-Nov-2001 art

Another sync of uvm to NetBSD. Just minor fiddling, no major changes.


# 1.19 07-Nov-2001 art

Add an alignment argument to uvm_map that specifies an alignment hint
for the virtual address.


# 1.18 06-Nov-2001 art

Move the last content from vm/ to uvm/
The only thing left in vm/ are just dumb wrappers.
vm/vm.h includes uvm/uvm_extern.h
vm/pmap.h includes uvm/uvm_pmap.h
vm/vm_page.h includes uvm/uvm_page.h


# 1.17 05-Nov-2001 art

Minor sync to NetBSD.


Revision tags: OPENBSD_3_0_BASE
# 1.16 20-Sep-2001 mpech

occured->occurred

idea from deraadt@ via NetBSD
millert@ ok


# 1.15 19-Sep-2001 mickey

merge vm/vm_kern.h into uvm/uvm_extern.h; art@ ok


# 1.14 11-Aug-2001 art

Various random fixes from NetBSD.
Including support for zeroing pages in the idle loop (not enabled yet).


# 1.13 06-Aug-2001 art

Add a new type voff_t (right now it's typedefed as off_t) used for offsets
into objects.

Gives the possibilty to mmap beyond the size of vaddr_t.

From NetBSD.


# 1.12 26-Jul-2001 art

Add support for disabling swap devices (swapctl -d).
Improve error handling on I/O errors to swap.
From NetBSD


# 1.11 25-Jul-2001 art

Change the pmap_enter interface to merge access_type and the wired boolean
and arbitrary flags into one argument.

One new flag is PMAP_CANFAIL that tells pmap_enter that it can fail if there
are not enough resources to satisfy the request. If this flag is not passed,
pmap_enter should panic as it should have done before this change (XXX - many
pmaps are still not doing that).

Only i386 and alpha implement CANFAIL for now.

Includes uvm updates from NetBSD.


# 1.10 18-Jul-2001 art

Get rid of the PMAP_NEW option by making it mandatory for all archs.
The archs that didn't have a proper PMAP_NEW now have a dummy implementation
with wrappers around the old functions.


# 1.9 08-Jun-2001 art

Change the paddr_t pmap_extract(struct pmap *, vaddr_t) interface to
boolean_t pmap_extract(struct pmap *, vaddr_t, paddr_t *).
Matches NetBSD. Tested by various people on various platforms.


Revision tags: OPENBSD_2_9_BASE
# 1.8 22-Mar-2001 smart

Sync style, typo, and comments a little closer to NetBSD. art@ ok


# 1.7 08-Mar-2001 smart

Replace thread_wakeup() with wakeup(). It is defined in vm_extern.h as a
wrapper, so this removes a dependence on the old VM system. From NetBSD.
art@ ok


# 1.6 29-Jan-2001 niklas

$OpenBSD$


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE
# 1.5 16-Mar-2000 art

Bring in some new UVM code from NetBSD (not current).

- Introduce a new type of map that are interrupt safe and never allow faults
in them. mb_map and kmem_map are made intrsafe.
- Add "access protection" to uvm_vslock (to be passed down to uvm_fault and
later to pmap_enter).
- madvise(2) now works.
- various cleanups.


Revision tags: OPENBSD_2_6_BASE SMP_BASE kame_19991208
# 1.4 03-Sep-1999 art

branches: 1.4.4;
Change the pmap_enter api to pass down an argument that indicates
the access type that caused this mapping. This is to simplify pmaps
with mod/ref emulation (none for the moment) and in some cases speed
up pmap_is_{referenced,modified}.
At the same time, clean up some mappings that had too high protection.

XXX - the access type is incorrect in old vm, it's only used by uvm and MD code.
The actual use of this in pmap_enter implementations is not in this commit.


# 1.3 23-Aug-1999 art

sync with NetBSD from 1999.05.24 (there is a reason for this date)
Mostly cleanups, but also a few improvements to pagedaemon for better
handling of low memory and/or low swap conditions.


Revision tags: OPENBSD_2_5_BASE
# 1.2 26-Feb-1999 art

add OpenBSD tags


# 1.1 26-Feb-1999 art

Import of uvm from NetBSD. Some local changes, some code disabled


# 1.76 26-Mar-2021 mpi

Remove parenthesis around return value to reduce the diff with NetBSD.

No functional change.

ok mlarkin@


# 1.75 12-Mar-2021 jsg

spelling

ok mpi@


# 1.74 19-Jan-2021 mpi

(re)Introduce locking for amaps & anons.

A rwlock is attached to every amap and is shared with all its anon. The
same lock will be used by multiple amaps if they have anons in common.

This should be enough to get the upper part of the fault handler out of the
KERNEL_LOCK() which seems to bring up to 20% improvements in builds.

This is based/copied/adapted from the most recent work done in NetBSD which
is an evolution of the precendent simple_lock scheme.

Tested by many, thanks!

ok kettenis@, mvs@


# 1.73 21-Oct-2020 mpi

Constify and use C99 initializer for "struct uvm_pagerops".

While here put some KERNEL_ASSERT_LOCKED() in the functions called from
the page fault handler. The removal of locking of `uobj' will need to be
revisited and these are good indicator that something is missing and that
many comments are lying.

ok kettenis


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.72 08-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok visa@, jca@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.71 17-Dec-2014 tedu

remove lock.h from uvm_extern.h. another holdover from the simpletonlock
era. fix uvm including c files to include lock.h or atomic.h as necessary.
ok deraadt


# 1.70 16-Nov-2014 deraadt

Replace a plethora of historical protection options with just
PROT_NONE, PROT_READ, PROT_WRITE, and PROT_EXEC from mman.h.
PROT_MASK is introduced as the one true way of extracting those bits.
Remove UVM_ADV_* wrapper, using the standard names.
ok doug guenther kettenis


# 1.69 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.68 11-Jul-2014 jsg

Chuck Cranor rescinded clauses in his license
on the 2nd of February 2011 in NetBSD.

http://marc.info/?l=netbsd-source-changes&m=129658899212732&w=2
http://marc.info/?l=netbsd-source-changes&m=129659095515558&w=2
http://marc.info/?l=netbsd-source-changes&m=129659157916514&w=2
http://marc.info/?l=netbsd-source-changes&m=129665962324372&w=2
http://marc.info/?l=netbsd-source-changes&m=129666033625342&w=2
http://marc.info/?l=netbsd-source-changes&m=129666052825545&w=2
http://marc.info/?l=netbsd-source-changes&m=129666922906480&w=2
http://marc.info/?l=netbsd-source-changes&m=129667725518082&w=2


# 1.67 09-May-2014 tedu

stop using B_AGE, it was effectively retired some time ago.


# 1.66 08-May-2014 kettenis

Fix some potential integer overflows caused by converting a page number into
an offset/size/address by shifting by PAGE_SHIFT. Make uvm_objwrire/unwire
use voff_t instead of off_t. The former is the right type here even if it is
equivalent to the latter.

Inspired by a somewhat similar changes in Bitrig.

ok deraadt@, guenther@


# 1.65 13-Apr-2014 tedu

compress code by turning four line comments into one line comments.
emphatic ok usual suspects, grudging ok miod


Revision tags: OPENBSD_5_5_BASE
# 1.64 02-Nov-2013 krw

No need to cast constants or simple variables to (daddr_t). Use
(u_int64_t) instead of (daddr_t) when casting a variable in an
expression passed to DL_SETDSIZE().

Change a variable counting open files from daddr_t to int64_t.

ok deraadt@ with the tweak to fix that pesky expression.


Revision tags: OPENBSD_5_4_BASE
# 1.63 11-Jun-2013 deraadt

final removal of daddr64_t. daddr_t has been 64 bit for a long enough
test period; i think 3 years ago the last bugs fell out.
ok otto beck others


# 1.62 30-May-2013 tedu

remove lots of comments about locking per beck's request


# 1.61 30-May-2013 tedu

remove simple_locks from uvm code. ok beck deraadt


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.60 03-Jul-2011 oga

Rip out and burn support for UVM_HIST.

The vm hackers don't use it, don't maintain it and have to look at it all the
time. About time this 800 lines of code hit /dev/null.

``never liked it'' tedu@. ariane@ was very happy when i told her i wrote
this diff.


# 1.59 15-Apr-2011 oga

for uvm_pager_dropcluster in the PG_RELEASED case we specifically unbusy the
page so that um_anfree will free it for us.

uvm_anfree does a pmap_page_protect(, VM_PROT_NONE) just before it frees the
page, so we don't need to do it here ourselves.

ok ariane@


# 1.58 15-Apr-2011 oga

move uvm_pageratop from uvm_pager.c local to a general uvm function
(uvm_atopg) and use it in uvm_km_doputpage to replace some handrolled
code. Shrinks the kernel a trivial amount.

ok beck@ and miod@ (who suggested i name it uvm_atopg not uvm_atop)


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.57 24-Jul-2010 kettenis

Don't sleep while holding the uvm_psel_lck mutex. Should fix "locking against
myself" panics that some people have seen over the last year-and-a-half.

Cherry picked from a more complex (and therefore scarier) diff from oga@.

ok tedu@, oga@


# 1.56 27-Jun-2010 oga

Kill another #ifdef UBC chunk that was annoying me while doing something
else.

ok thib@


Revision tags: OPENBSD_4_7_BASE
# 1.55 12-Feb-2010 tedu

introduce a uvm_km_valloc_try function that won't get a lower level lock
for use by the uvm pseg code. this is the path of least resistance until
we sort out how many of these functions we really need. problem found by mikeb
ok kettenis oga


# 1.54 22-Jul-2009 oga

Put the PG_RELEASED changes diff back in.

This has has been tested very very thoroughly on all archs we have
excepting 88k and 68k. Please see cvs log for the individual commit
messages.

ok beck@, thib@


Revision tags: OPENBSD_4_6_BASE
# 1.53 17-Jun-2009 oga

date based reversion of uvm to the 4th May.

More backouts in line with previous ones, this appears to bring us back to a
stable condition.

A machine forced to 64mb of ram cycled 10GB through swap with this diff
and is still running as I type this. Other tests by ariane@ and thib@
also seem to show that it's alright.

ok deraadt@, thib@, ariane@


# 1.52 16-Jun-2009 oga

Backout all the PG_RELEASED changes.

This is for the same reason as the earlier backouts, to avoid the bug
either added or exposed sometime around c2k9. This *should* be the last
one.

prompted by deraadt@

ok ariane@


# 1.51 23-May-2009 oga

More PG_RELEASED cleaning.

similar to the aobj.c changes, this one does vnodes. Vnodes are more
complex because they actaully have to sync to backing store. So firstly,
convert sync to sleep instead of setting released.

Now, for backing store, in the PGO_FREE case, if we set PG_RELEASED
*before* an async io, (nothing else will see it, the page is busy), then
we can ignore the page after the io is done. We could do something
similar for PGO_DEACTIVATE too, but that is another change. On error we
just clear the released flag, nothing else sets it for uobj pages other
than aiodoned.

ok thib@, beck@, ariane@


# 1.50 04-May-2009 oga

Instead of keeping two ints in the uvm structure specifically just to
sleep on them (and otherwise ignore them) sleep on the pointer to the
{aiodoned,pagedaemon}_proc members, and nuke the two extra words.

"no objections" art@, ok beck@.


# 1.49 06-Apr-2009 oga

Instead of doing splbio(); simple_lock(&uvm.aiodoned_lock); just replace
the simple lock with a real lock - a IPL_BIO mutex. While i'm here, make
the sleeping condition one hell of a lot simpler in the aio daemon.

some ideas from and ok art@.


# 1.48 25-Mar-2009 oga

Move all of the pseudo-inline functions in uvm into C files.

By pseudo-inline, I mean that if a certain macro was defined, they would
be inlined. However, no architecture defines that, and none has for a
very very long time. Therefore mainly this just makes the code a damned
sight easier to read. Some k&r -> ansi declarations while I'm in there.

"just commit it" art@. ok weingart@.


# 1.47 20-Mar-2009 oga

While working on some stuff in uvm I've gotten REALLY sick of reading
K&R function declarations, so switch them all over to ansi-style, in
accordance with the prophesy.

"go for it" art@


Revision tags: OPENBSD_4_5_BASE
# 1.46 27-Jan-2009 ariane

Simplify page-out/page-in map management; fix rare pager deadlock.

Ok: miod, tedu


# 1.45 24-Nov-2008 thib

garbage collect uvm_errno2vmerror();

ok miod@, art@


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.44 26-Nov-2007 miod

In uvm_aio_aiodone(), kill the variable-sized array on stack, and use a
fixed size array which size should match any buf; if a bogus buf is passed
to this function, the kernel will KASSERT instead of potentially running out
of stack and having an undefined behaviour.

ok deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.43 06-Jun-2007 deraadt

now that all partition size/offsets are potentially 64-bit, change the
type of all variables to daddr64_t. this includes the APIs for XXsize()
and XXdump(), all range checks inside bio drivers, internal variables
for disklabel handling, and even uvm's swap offsets. re-read numerous
times by otto, miod, krw, thib to look for errors


# 1.42 13-Apr-2007 art

While splitting flags and pqflags might have been a good idea in theory
to separate locking, on most modern machines this is not enough
since operations on short types touch other short types that share the
same word in memory.

Merge pg_flags and pqflags again and now use atomic operations to change
the flags. Also bump wire_count to an int and pg_version might go
int as well, just for alignment.

tested by many, many. ok miod@


# 1.41 04-Apr-2007 art

Mechanically rename the "flags" and "version" fields in struct vm_page
to "pg_flags" and "pg_version", so that they are a bit easier to work with.
Whoever uses generic names like this for a popular struct obviously doesn't
read much code.

Most architectures compile and there are no functionality changes.

deraadt@ ok ("if something fails to compile, we fix that by hand")


# 1.40 25-Mar-2007 art

remove KERN_SUCCESS and use 0 instead.
eyeballed by miod@ and pedro@


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.39 31-Jul-2006 mickey

fix uvmhist #2: args are always u_long so fix missing %d and %x and no %ll; no change for normal code


# 1.38 26-Jul-2006 mickey

fix fmts for UVMHIST_LOG() entries making it more useful on 64bit archs; miod@ ok


Revision tags: OPENBSD_3_8_BASE OPENBSD_3_9_BASE
# 1.37 26-Jul-2005 art

- Make a UVM_OBJ_IS_DEVICE macro.
- Use it to skip device mappings while dumping core.
- Ignore EFAULT errors while dumping core since they can happen
even for valid mappings. Just skip that part of the core file and
let it get automagically zero-filled.

This fixes the broken X core dumps that people have been seeing and also
fixes some other potential problems that could prevent core dumps (mmaps
beyond EOF, etc.).

tedu@ ok


# 1.36 24-May-2005 tedu

add a new field to vm_space and use it to track the number of anon
pages a process uses. this is now the userland "data size" value.
ok art deraadt tdeval. thanks testers.


Revision tags: OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE SMP_SYNC_A SMP_SYNC_B
# 1.35 23-Feb-2004 drahn

sync of pmap_update() calls with NetBSD. pmap_update is defined away on
all architectures but arm, where it is needed.


Revision tags: OPENBSD_3_4_BASE UBC_SYNC_A
# 1.34 29-Mar-2003 mickey

ubchist is not a fully cooked kadaver and though use the other well formed pdhist one until ubc gaets back. art@ ok


Revision tags: OPENBSD_3_3_BASE
# 1.33 29-Oct-2002 art

Since memory deallocation can't fail, remove the error return from
uvm_unmap, uvm_deallocate and a few other functions.
Simplifies some code and reduces diff to the UBC branch.


Revision tags: OPENBSD_3_2_BASE UBC_SYNC_B
# 1.32 24-May-2002 art

Make sure that b_iodone handlers are called at splbio (and splassert(IPL_BIO) in all known callers, just to make sure).


# 1.31 22-May-2002 art

splassert(IPL_BIO) in the b_iodone handlers.


Revision tags: OPENBSD_3_1_BASE
# 1.30 02-Jan-2002 miod

Back out a few more uvm changes, especially wrt swap usage.
This unbreaks m68k m88k sparc and perhaps others, which eventually froze
when hitting swap.
Tested by various people on various platforms.
ok art@


# 1.29 19-Dec-2001 art

UBC was a disaster. It worked very good when it worked, but on some
machines or some configurations or in some phase of the moon (we actually
don't know when or why) files disappeared. Since we've not been able to
track down the problem in two weeks intense debugging and we need -current
to be stable, back out everything to a state it had before UBC.

We apologise for the inconvenience.


Revision tags: UBC_BASE
# 1.28 04-Dec-2001 art

branches: 1.28.2;
Yet another sync to NetBSD uvm.
Today we add a pmap argument to pmap_update() and allocate map entries for
kernel_map from kmem_map instead of using the static entries. This should
get rid of MAX_KMAPENT panics. Also some uvm_loan problems are fixed.


# 1.27 30-Nov-2001 csapuntz

Call buf_cleanout, which handles wakeups


# 1.26 29-Nov-2001 art

Correctly handle b_vp with bgetvp and brelvp in {get,put}pages.
Prevents panics caused by vnodes being recycled under our feet.


# 1.25 28-Nov-2001 art

Sync in more uvm from NetBSD. Mostly just cosmetic stuff.
Contains also support for page coloring.


# 1.24 28-Nov-2001 art

Sync in more uvm changes from NetBSD.
This time we're getting rid of KERN_* and VM_PAGER_* error codes and
use errnos instead.


# 1.23 27-Nov-2001 art

Merge in the unified buffer cache code as found in NetBSD 2001/03/10. The
code is written mostly by Chuck Silvers <chuq@chuq.com>/<chs@netbsd.org>.

Tested for the past few weeks by many developers, should be in a pretty stable
state, but will require optimizations and additional cleanups.


# 1.22 12-Nov-2001 art

Bring in more changes from NetBSD. Mostly pagedaemon improvements.


# 1.21 10-Nov-2001 art

Merge in some parts of the ubc work that has been done in NetBSD that are not
UBC, but prerequsites for it.

- Create a daemon that processes async I/O (swap and paging in the future)
requests that need processing in process context and that were processed
in the pagedaemon before.
- Convert some ugly ifdef DIAGNOSTIC code to less intrusive KASSERTs.
- misc other cleanups.


# 1.20 07-Nov-2001 art

Another sync of uvm to NetBSD. Just minor fiddling, no major changes.


# 1.19 07-Nov-2001 art

Add an alignment argument to uvm_map that specifies an alignment hint
for the virtual address.


# 1.18 06-Nov-2001 art

Move the last content from vm/ to uvm/
The only thing left in vm/ are just dumb wrappers.
vm/vm.h includes uvm/uvm_extern.h
vm/pmap.h includes uvm/uvm_pmap.h
vm/vm_page.h includes uvm/uvm_page.h


# 1.17 05-Nov-2001 art

Minor sync to NetBSD.


Revision tags: OPENBSD_3_0_BASE
# 1.16 20-Sep-2001 mpech

occured->occurred

idea from deraadt@ via NetBSD
millert@ ok


# 1.15 19-Sep-2001 mickey

merge vm/vm_kern.h into uvm/uvm_extern.h; art@ ok


# 1.14 11-Aug-2001 art

Various random fixes from NetBSD.
Including support for zeroing pages in the idle loop (not enabled yet).


# 1.13 06-Aug-2001 art

Add a new type voff_t (right now it's typedefed as off_t) used for offsets
into objects.

Gives the possibilty to mmap beyond the size of vaddr_t.

From NetBSD.


# 1.12 26-Jul-2001 art

Add support for disabling swap devices (swapctl -d).
Improve error handling on I/O errors to swap.
From NetBSD


# 1.11 25-Jul-2001 art

Change the pmap_enter interface to merge access_type and the wired boolean
and arbitrary flags into one argument.

One new flag is PMAP_CANFAIL that tells pmap_enter that it can fail if there
are not enough resources to satisfy the request. If this flag is not passed,
pmap_enter should panic as it should have done before this change (XXX - many
pmaps are still not doing that).

Only i386 and alpha implement CANFAIL for now.

Includes uvm updates from NetBSD.


# 1.10 18-Jul-2001 art

Get rid of the PMAP_NEW option by making it mandatory for all archs.
The archs that didn't have a proper PMAP_NEW now have a dummy implementation
with wrappers around the old functions.


# 1.9 08-Jun-2001 art

Change the paddr_t pmap_extract(struct pmap *, vaddr_t) interface to
boolean_t pmap_extract(struct pmap *, vaddr_t, paddr_t *).
Matches NetBSD. Tested by various people on various platforms.


Revision tags: OPENBSD_2_9_BASE
# 1.8 22-Mar-2001 smart

Sync style, typo, and comments a little closer to NetBSD. art@ ok


# 1.7 08-Mar-2001 smart

Replace thread_wakeup() with wakeup(). It is defined in vm_extern.h as a
wrapper, so this removes a dependence on the old VM system. From NetBSD.
art@ ok


# 1.6 29-Jan-2001 niklas

$OpenBSD$


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE
# 1.5 16-Mar-2000 art

Bring in some new UVM code from NetBSD (not current).

- Introduce a new type of map that are interrupt safe and never allow faults
in them. mb_map and kmem_map are made intrsafe.
- Add "access protection" to uvm_vslock (to be passed down to uvm_fault and
later to pmap_enter).
- madvise(2) now works.
- various cleanups.


Revision tags: OPENBSD_2_6_BASE SMP_BASE kame_19991208
# 1.4 03-Sep-1999 art

branches: 1.4.4;
Change the pmap_enter api to pass down an argument that indicates
the access type that caused this mapping. This is to simplify pmaps
with mod/ref emulation (none for the moment) and in some cases speed
up pmap_is_{referenced,modified}.
At the same time, clean up some mappings that had too high protection.

XXX - the access type is incorrect in old vm, it's only used by uvm and MD code.
The actual use of this in pmap_enter implementations is not in this commit.


# 1.3 23-Aug-1999 art

sync with NetBSD from 1999.05.24 (there is a reason for this date)
Mostly cleanups, but also a few improvements to pagedaemon for better
handling of low memory and/or low swap conditions.


Revision tags: OPENBSD_2_5_BASE
# 1.2 26-Feb-1999 art

add OpenBSD tags


# 1.1 26-Feb-1999 art

Import of uvm from NetBSD. Some local changes, some code disabled


# 1.75 12-Mar-2021 jsg

spelling

ok mpi@


# 1.74 19-Jan-2021 mpi

(re)Introduce locking for amaps & anons.

A rwlock is attached to every amap and is shared with all its anon. The
same lock will be used by multiple amaps if they have anons in common.

This should be enough to get the upper part of the fault handler out of the
KERNEL_LOCK() which seems to bring up to 20% improvements in builds.

This is based/copied/adapted from the most recent work done in NetBSD which
is an evolution of the precendent simple_lock scheme.

Tested by many, thanks!

ok kettenis@, mvs@


# 1.73 21-Oct-2020 mpi

Constify and use C99 initializer for "struct uvm_pagerops".

While here put some KERNEL_ASSERT_LOCKED() in the functions called from
the page fault handler. The removal of locking of `uobj' will need to be
revisited and these are good indicator that something is missing and that
many comments are lying.

ok kettenis


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.72 08-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok visa@, jca@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.71 17-Dec-2014 tedu

remove lock.h from uvm_extern.h. another holdover from the simpletonlock
era. fix uvm including c files to include lock.h or atomic.h as necessary.
ok deraadt


# 1.70 16-Nov-2014 deraadt

Replace a plethora of historical protection options with just
PROT_NONE, PROT_READ, PROT_WRITE, and PROT_EXEC from mman.h.
PROT_MASK is introduced as the one true way of extracting those bits.
Remove UVM_ADV_* wrapper, using the standard names.
ok doug guenther kettenis


# 1.69 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.68 11-Jul-2014 jsg

Chuck Cranor rescinded clauses in his license
on the 2nd of February 2011 in NetBSD.

http://marc.info/?l=netbsd-source-changes&m=129658899212732&w=2
http://marc.info/?l=netbsd-source-changes&m=129659095515558&w=2
http://marc.info/?l=netbsd-source-changes&m=129659157916514&w=2
http://marc.info/?l=netbsd-source-changes&m=129665962324372&w=2
http://marc.info/?l=netbsd-source-changes&m=129666033625342&w=2
http://marc.info/?l=netbsd-source-changes&m=129666052825545&w=2
http://marc.info/?l=netbsd-source-changes&m=129666922906480&w=2
http://marc.info/?l=netbsd-source-changes&m=129667725518082&w=2


# 1.67 09-May-2014 tedu

stop using B_AGE, it was effectively retired some time ago.


# 1.66 08-May-2014 kettenis

Fix some potential integer overflows caused by converting a page number into
an offset/size/address by shifting by PAGE_SHIFT. Make uvm_objwrire/unwire
use voff_t instead of off_t. The former is the right type here even if it is
equivalent to the latter.

Inspired by a somewhat similar changes in Bitrig.

ok deraadt@, guenther@


# 1.65 13-Apr-2014 tedu

compress code by turning four line comments into one line comments.
emphatic ok usual suspects, grudging ok miod


Revision tags: OPENBSD_5_5_BASE
# 1.64 02-Nov-2013 krw

No need to cast constants or simple variables to (daddr_t). Use
(u_int64_t) instead of (daddr_t) when casting a variable in an
expression passed to DL_SETDSIZE().

Change a variable counting open files from daddr_t to int64_t.

ok deraadt@ with the tweak to fix that pesky expression.


Revision tags: OPENBSD_5_4_BASE
# 1.63 11-Jun-2013 deraadt

final removal of daddr64_t. daddr_t has been 64 bit for a long enough
test period; i think 3 years ago the last bugs fell out.
ok otto beck others


# 1.62 30-May-2013 tedu

remove lots of comments about locking per beck's request


# 1.61 30-May-2013 tedu

remove simple_locks from uvm code. ok beck deraadt


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.60 03-Jul-2011 oga

Rip out and burn support for UVM_HIST.

The vm hackers don't use it, don't maintain it and have to look at it all the
time. About time this 800 lines of code hit /dev/null.

``never liked it'' tedu@. ariane@ was very happy when i told her i wrote
this diff.


# 1.59 15-Apr-2011 oga

for uvm_pager_dropcluster in the PG_RELEASED case we specifically unbusy the
page so that um_anfree will free it for us.

uvm_anfree does a pmap_page_protect(, VM_PROT_NONE) just before it frees the
page, so we don't need to do it here ourselves.

ok ariane@


# 1.58 15-Apr-2011 oga

move uvm_pageratop from uvm_pager.c local to a general uvm function
(uvm_atopg) and use it in uvm_km_doputpage to replace some handrolled
code. Shrinks the kernel a trivial amount.

ok beck@ and miod@ (who suggested i name it uvm_atopg not uvm_atop)


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.57 24-Jul-2010 kettenis

Don't sleep while holding the uvm_psel_lck mutex. Should fix "locking against
myself" panics that some people have seen over the last year-and-a-half.

Cherry picked from a more complex (and therefore scarier) diff from oga@.

ok tedu@, oga@


# 1.56 27-Jun-2010 oga

Kill another #ifdef UBC chunk that was annoying me while doing something
else.

ok thib@


Revision tags: OPENBSD_4_7_BASE
# 1.55 12-Feb-2010 tedu

introduce a uvm_km_valloc_try function that won't get a lower level lock
for use by the uvm pseg code. this is the path of least resistance until
we sort out how many of these functions we really need. problem found by mikeb
ok kettenis oga


# 1.54 22-Jul-2009 oga

Put the PG_RELEASED changes diff back in.

This has has been tested very very thoroughly on all archs we have
excepting 88k and 68k. Please see cvs log for the individual commit
messages.

ok beck@, thib@


Revision tags: OPENBSD_4_6_BASE
# 1.53 17-Jun-2009 oga

date based reversion of uvm to the 4th May.

More backouts in line with previous ones, this appears to bring us back to a
stable condition.

A machine forced to 64mb of ram cycled 10GB through swap with this diff
and is still running as I type this. Other tests by ariane@ and thib@
also seem to show that it's alright.

ok deraadt@, thib@, ariane@


# 1.52 16-Jun-2009 oga

Backout all the PG_RELEASED changes.

This is for the same reason as the earlier backouts, to avoid the bug
either added or exposed sometime around c2k9. This *should* be the last
one.

prompted by deraadt@

ok ariane@


# 1.51 23-May-2009 oga

More PG_RELEASED cleaning.

similar to the aobj.c changes, this one does vnodes. Vnodes are more
complex because they actaully have to sync to backing store. So firstly,
convert sync to sleep instead of setting released.

Now, for backing store, in the PGO_FREE case, if we set PG_RELEASED
*before* an async io, (nothing else will see it, the page is busy), then
we can ignore the page after the io is done. We could do something
similar for PGO_DEACTIVATE too, but that is another change. On error we
just clear the released flag, nothing else sets it for uobj pages other
than aiodoned.

ok thib@, beck@, ariane@


# 1.50 04-May-2009 oga

Instead of keeping two ints in the uvm structure specifically just to
sleep on them (and otherwise ignore them) sleep on the pointer to the
{aiodoned,pagedaemon}_proc members, and nuke the two extra words.

"no objections" art@, ok beck@.


# 1.49 06-Apr-2009 oga

Instead of doing splbio(); simple_lock(&uvm.aiodoned_lock); just replace
the simple lock with a real lock - a IPL_BIO mutex. While i'm here, make
the sleeping condition one hell of a lot simpler in the aio daemon.

some ideas from and ok art@.


# 1.48 25-Mar-2009 oga

Move all of the pseudo-inline functions in uvm into C files.

By pseudo-inline, I mean that if a certain macro was defined, they would
be inlined. However, no architecture defines that, and none has for a
very very long time. Therefore mainly this just makes the code a damned
sight easier to read. Some k&r -> ansi declarations while I'm in there.

"just commit it" art@. ok weingart@.


# 1.47 20-Mar-2009 oga

While working on some stuff in uvm I've gotten REALLY sick of reading
K&R function declarations, so switch them all over to ansi-style, in
accordance with the prophesy.

"go for it" art@


Revision tags: OPENBSD_4_5_BASE
# 1.46 27-Jan-2009 ariane

Simplify page-out/page-in map management; fix rare pager deadlock.

Ok: miod, tedu


# 1.45 24-Nov-2008 thib

garbage collect uvm_errno2vmerror();

ok miod@, art@


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.44 26-Nov-2007 miod

In uvm_aio_aiodone(), kill the variable-sized array on stack, and use a
fixed size array which size should match any buf; if a bogus buf is passed
to this function, the kernel will KASSERT instead of potentially running out
of stack and having an undefined behaviour.

ok deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.43 06-Jun-2007 deraadt

now that all partition size/offsets are potentially 64-bit, change the
type of all variables to daddr64_t. this includes the APIs for XXsize()
and XXdump(), all range checks inside bio drivers, internal variables
for disklabel handling, and even uvm's swap offsets. re-read numerous
times by otto, miod, krw, thib to look for errors


# 1.42 13-Apr-2007 art

While splitting flags and pqflags might have been a good idea in theory
to separate locking, on most modern machines this is not enough
since operations on short types touch other short types that share the
same word in memory.

Merge pg_flags and pqflags again and now use atomic operations to change
the flags. Also bump wire_count to an int and pg_version might go
int as well, just for alignment.

tested by many, many. ok miod@


# 1.41 04-Apr-2007 art

Mechanically rename the "flags" and "version" fields in struct vm_page
to "pg_flags" and "pg_version", so that they are a bit easier to work with.
Whoever uses generic names like this for a popular struct obviously doesn't
read much code.

Most architectures compile and there are no functionality changes.

deraadt@ ok ("if something fails to compile, we fix that by hand")


# 1.40 25-Mar-2007 art

remove KERN_SUCCESS and use 0 instead.
eyeballed by miod@ and pedro@


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.39 31-Jul-2006 mickey

fix uvmhist #2: args are always u_long so fix missing %d and %x and no %ll; no change for normal code


# 1.38 26-Jul-2006 mickey

fix fmts for UVMHIST_LOG() entries making it more useful on 64bit archs; miod@ ok


Revision tags: OPENBSD_3_8_BASE OPENBSD_3_9_BASE
# 1.37 26-Jul-2005 art

- Make a UVM_OBJ_IS_DEVICE macro.
- Use it to skip device mappings while dumping core.
- Ignore EFAULT errors while dumping core since they can happen
even for valid mappings. Just skip that part of the core file and
let it get automagically zero-filled.

This fixes the broken X core dumps that people have been seeing and also
fixes some other potential problems that could prevent core dumps (mmaps
beyond EOF, etc.).

tedu@ ok


# 1.36 24-May-2005 tedu

add a new field to vm_space and use it to track the number of anon
pages a process uses. this is now the userland "data size" value.
ok art deraadt tdeval. thanks testers.


Revision tags: OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE SMP_SYNC_A SMP_SYNC_B
# 1.35 23-Feb-2004 drahn

sync of pmap_update() calls with NetBSD. pmap_update is defined away on
all architectures but arm, where it is needed.


Revision tags: OPENBSD_3_4_BASE UBC_SYNC_A
# 1.34 29-Mar-2003 mickey

ubchist is not a fully cooked kadaver and though use the other well formed pdhist one until ubc gaets back. art@ ok


Revision tags: OPENBSD_3_3_BASE
# 1.33 29-Oct-2002 art

Since memory deallocation can't fail, remove the error return from
uvm_unmap, uvm_deallocate and a few other functions.
Simplifies some code and reduces diff to the UBC branch.


Revision tags: OPENBSD_3_2_BASE UBC_SYNC_B
# 1.32 24-May-2002 art

Make sure that b_iodone handlers are called at splbio (and splassert(IPL_BIO) in all known callers, just to make sure).


# 1.31 22-May-2002 art

splassert(IPL_BIO) in the b_iodone handlers.


Revision tags: OPENBSD_3_1_BASE
# 1.30 02-Jan-2002 miod

Back out a few more uvm changes, especially wrt swap usage.
This unbreaks m68k m88k sparc and perhaps others, which eventually froze
when hitting swap.
Tested by various people on various platforms.
ok art@


# 1.29 19-Dec-2001 art

UBC was a disaster. It worked very good when it worked, but on some
machines or some configurations or in some phase of the moon (we actually
don't know when or why) files disappeared. Since we've not been able to
track down the problem in two weeks intense debugging and we need -current
to be stable, back out everything to a state it had before UBC.

We apologise for the inconvenience.


Revision tags: UBC_BASE
# 1.28 04-Dec-2001 art

branches: 1.28.2;
Yet another sync to NetBSD uvm.
Today we add a pmap argument to pmap_update() and allocate map entries for
kernel_map from kmem_map instead of using the static entries. This should
get rid of MAX_KMAPENT panics. Also some uvm_loan problems are fixed.


# 1.27 30-Nov-2001 csapuntz

Call buf_cleanout, which handles wakeups


# 1.26 29-Nov-2001 art

Correctly handle b_vp with bgetvp and brelvp in {get,put}pages.
Prevents panics caused by vnodes being recycled under our feet.


# 1.25 28-Nov-2001 art

Sync in more uvm from NetBSD. Mostly just cosmetic stuff.
Contains also support for page coloring.


# 1.24 28-Nov-2001 art

Sync in more uvm changes from NetBSD.
This time we're getting rid of KERN_* and VM_PAGER_* error codes and
use errnos instead.


# 1.23 27-Nov-2001 art

Merge in the unified buffer cache code as found in NetBSD 2001/03/10. The
code is written mostly by Chuck Silvers <chuq@chuq.com>/<chs@netbsd.org>.

Tested for the past few weeks by many developers, should be in a pretty stable
state, but will require optimizations and additional cleanups.


# 1.22 12-Nov-2001 art

Bring in more changes from NetBSD. Mostly pagedaemon improvements.


# 1.21 10-Nov-2001 art

Merge in some parts of the ubc work that has been done in NetBSD that are not
UBC, but prerequsites for it.

- Create a daemon that processes async I/O (swap and paging in the future)
requests that need processing in process context and that were processed
in the pagedaemon before.
- Convert some ugly ifdef DIAGNOSTIC code to less intrusive KASSERTs.
- misc other cleanups.


# 1.20 07-Nov-2001 art

Another sync of uvm to NetBSD. Just minor fiddling, no major changes.


# 1.19 07-Nov-2001 art

Add an alignment argument to uvm_map that specifies an alignment hint
for the virtual address.


# 1.18 06-Nov-2001 art

Move the last content from vm/ to uvm/
The only thing left in vm/ are just dumb wrappers.
vm/vm.h includes uvm/uvm_extern.h
vm/pmap.h includes uvm/uvm_pmap.h
vm/vm_page.h includes uvm/uvm_page.h


# 1.17 05-Nov-2001 art

Minor sync to NetBSD.


Revision tags: OPENBSD_3_0_BASE
# 1.16 20-Sep-2001 mpech

occured->occurred

idea from deraadt@ via NetBSD
millert@ ok


# 1.15 19-Sep-2001 mickey

merge vm/vm_kern.h into uvm/uvm_extern.h; art@ ok


# 1.14 11-Aug-2001 art

Various random fixes from NetBSD.
Including support for zeroing pages in the idle loop (not enabled yet).


# 1.13 06-Aug-2001 art

Add a new type voff_t (right now it's typedefed as off_t) used for offsets
into objects.

Gives the possibilty to mmap beyond the size of vaddr_t.

From NetBSD.


# 1.12 26-Jul-2001 art

Add support for disabling swap devices (swapctl -d).
Improve error handling on I/O errors to swap.
From NetBSD


# 1.11 25-Jul-2001 art

Change the pmap_enter interface to merge access_type and the wired boolean
and arbitrary flags into one argument.

One new flag is PMAP_CANFAIL that tells pmap_enter that it can fail if there
are not enough resources to satisfy the request. If this flag is not passed,
pmap_enter should panic as it should have done before this change (XXX - many
pmaps are still not doing that).

Only i386 and alpha implement CANFAIL for now.

Includes uvm updates from NetBSD.


# 1.10 18-Jul-2001 art

Get rid of the PMAP_NEW option by making it mandatory for all archs.
The archs that didn't have a proper PMAP_NEW now have a dummy implementation
with wrappers around the old functions.


# 1.9 08-Jun-2001 art

Change the paddr_t pmap_extract(struct pmap *, vaddr_t) interface to
boolean_t pmap_extract(struct pmap *, vaddr_t, paddr_t *).
Matches NetBSD. Tested by various people on various platforms.


Revision tags: OPENBSD_2_9_BASE
# 1.8 22-Mar-2001 smart

Sync style, typo, and comments a little closer to NetBSD. art@ ok


# 1.7 08-Mar-2001 smart

Replace thread_wakeup() with wakeup(). It is defined in vm_extern.h as a
wrapper, so this removes a dependence on the old VM system. From NetBSD.
art@ ok


# 1.6 29-Jan-2001 niklas

$OpenBSD$


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE
# 1.5 16-Mar-2000 art

Bring in some new UVM code from NetBSD (not current).

- Introduce a new type of map that are interrupt safe and never allow faults
in them. mb_map and kmem_map are made intrsafe.
- Add "access protection" to uvm_vslock (to be passed down to uvm_fault and
later to pmap_enter).
- madvise(2) now works.
- various cleanups.


Revision tags: OPENBSD_2_6_BASE SMP_BASE kame_19991208
# 1.4 03-Sep-1999 art

branches: 1.4.4;
Change the pmap_enter api to pass down an argument that indicates
the access type that caused this mapping. This is to simplify pmaps
with mod/ref emulation (none for the moment) and in some cases speed
up pmap_is_{referenced,modified}.
At the same time, clean up some mappings that had too high protection.

XXX - the access type is incorrect in old vm, it's only used by uvm and MD code.
The actual use of this in pmap_enter implementations is not in this commit.


# 1.3 23-Aug-1999 art

sync with NetBSD from 1999.05.24 (there is a reason for this date)
Mostly cleanups, but also a few improvements to pagedaemon for better
handling of low memory and/or low swap conditions.


Revision tags: OPENBSD_2_5_BASE
# 1.2 26-Feb-1999 art

add OpenBSD tags


# 1.1 26-Feb-1999 art

Import of uvm from NetBSD. Some local changes, some code disabled


# 1.74 19-Jan-2021 mpi

(re)Introduce locking for amaps & anons.

A rwlock is attached to every amap and is shared with all its anon. The
same lock will be used by multiple amaps if they have anons in common.

This should be enough to get the upper part of the fault handler out of the
KERNEL_LOCK() which seems to bring up to 20% improvements in builds.

This is based/copied/adapted from the most recent work done in NetBSD which
is an evolution of the precendent simple_lock scheme.

Tested by many, thanks!

ok kettenis@, mvs@


# 1.73 21-Oct-2020 mpi

Constify and use C99 initializer for "struct uvm_pagerops".

While here put some KERNEL_ASSERT_LOCKED() in the functions called from
the page fault handler. The removal of locking of `uobj' will need to be
revisited and these are good indicator that something is missing and that
many comments are lying.

ok kettenis


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.72 08-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok visa@, jca@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.71 17-Dec-2014 tedu

remove lock.h from uvm_extern.h. another holdover from the simpletonlock
era. fix uvm including c files to include lock.h or atomic.h as necessary.
ok deraadt


# 1.70 16-Nov-2014 deraadt

Replace a plethora of historical protection options with just
PROT_NONE, PROT_READ, PROT_WRITE, and PROT_EXEC from mman.h.
PROT_MASK is introduced as the one true way of extracting those bits.
Remove UVM_ADV_* wrapper, using the standard names.
ok doug guenther kettenis


# 1.69 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.68 11-Jul-2014 jsg

Chuck Cranor rescinded clauses in his license
on the 2nd of February 2011 in NetBSD.

http://marc.info/?l=netbsd-source-changes&m=129658899212732&w=2
http://marc.info/?l=netbsd-source-changes&m=129659095515558&w=2
http://marc.info/?l=netbsd-source-changes&m=129659157916514&w=2
http://marc.info/?l=netbsd-source-changes&m=129665962324372&w=2
http://marc.info/?l=netbsd-source-changes&m=129666033625342&w=2
http://marc.info/?l=netbsd-source-changes&m=129666052825545&w=2
http://marc.info/?l=netbsd-source-changes&m=129666922906480&w=2
http://marc.info/?l=netbsd-source-changes&m=129667725518082&w=2


# 1.67 09-May-2014 tedu

stop using B_AGE, it was effectively retired some time ago.


# 1.66 08-May-2014 kettenis

Fix some potential integer overflows caused by converting a page number into
an offset/size/address by shifting by PAGE_SHIFT. Make uvm_objwrire/unwire
use voff_t instead of off_t. The former is the right type here even if it is
equivalent to the latter.

Inspired by a somewhat similar changes in Bitrig.

ok deraadt@, guenther@


# 1.65 13-Apr-2014 tedu

compress code by turning four line comments into one line comments.
emphatic ok usual suspects, grudging ok miod


Revision tags: OPENBSD_5_5_BASE
# 1.64 02-Nov-2013 krw

No need to cast constants or simple variables to (daddr_t). Use
(u_int64_t) instead of (daddr_t) when casting a variable in an
expression passed to DL_SETDSIZE().

Change a variable counting open files from daddr_t to int64_t.

ok deraadt@ with the tweak to fix that pesky expression.


Revision tags: OPENBSD_5_4_BASE
# 1.63 11-Jun-2013 deraadt

final removal of daddr64_t. daddr_t has been 64 bit for a long enough
test period; i think 3 years ago the last bugs fell out.
ok otto beck others


# 1.62 30-May-2013 tedu

remove lots of comments about locking per beck's request


# 1.61 30-May-2013 tedu

remove simple_locks from uvm code. ok beck deraadt


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.60 03-Jul-2011 oga

Rip out and burn support for UVM_HIST.

The vm hackers don't use it, don't maintain it and have to look at it all the
time. About time this 800 lines of code hit /dev/null.

``never liked it'' tedu@. ariane@ was very happy when i told her i wrote
this diff.


# 1.59 15-Apr-2011 oga

for uvm_pager_dropcluster in the PG_RELEASED case we specifically unbusy the
page so that um_anfree will free it for us.

uvm_anfree does a pmap_page_protect(, VM_PROT_NONE) just before it frees the
page, so we don't need to do it here ourselves.

ok ariane@


# 1.58 15-Apr-2011 oga

move uvm_pageratop from uvm_pager.c local to a general uvm function
(uvm_atopg) and use it in uvm_km_doputpage to replace some handrolled
code. Shrinks the kernel a trivial amount.

ok beck@ and miod@ (who suggested i name it uvm_atopg not uvm_atop)


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.57 24-Jul-2010 kettenis

Don't sleep while holding the uvm_psel_lck mutex. Should fix "locking against
myself" panics that some people have seen over the last year-and-a-half.

Cherry picked from a more complex (and therefore scarier) diff from oga@.

ok tedu@, oga@


# 1.56 27-Jun-2010 oga

Kill another #ifdef UBC chunk that was annoying me while doing something
else.

ok thib@


Revision tags: OPENBSD_4_7_BASE
# 1.55 12-Feb-2010 tedu

introduce a uvm_km_valloc_try function that won't get a lower level lock
for use by the uvm pseg code. this is the path of least resistance until
we sort out how many of these functions we really need. problem found by mikeb
ok kettenis oga


# 1.54 22-Jul-2009 oga

Put the PG_RELEASED changes diff back in.

This has has been tested very very thoroughly on all archs we have
excepting 88k and 68k. Please see cvs log for the individual commit
messages.

ok beck@, thib@


Revision tags: OPENBSD_4_6_BASE
# 1.53 17-Jun-2009 oga

date based reversion of uvm to the 4th May.

More backouts in line with previous ones, this appears to bring us back to a
stable condition.

A machine forced to 64mb of ram cycled 10GB through swap with this diff
and is still running as I type this. Other tests by ariane@ and thib@
also seem to show that it's alright.

ok deraadt@, thib@, ariane@


# 1.52 16-Jun-2009 oga

Backout all the PG_RELEASED changes.

This is for the same reason as the earlier backouts, to avoid the bug
either added or exposed sometime around c2k9. This *should* be the last
one.

prompted by deraadt@

ok ariane@


# 1.51 23-May-2009 oga

More PG_RELEASED cleaning.

similar to the aobj.c changes, this one does vnodes. Vnodes are more
complex because they actaully have to sync to backing store. So firstly,
convert sync to sleep instead of setting released.

Now, for backing store, in the PGO_FREE case, if we set PG_RELEASED
*before* an async io, (nothing else will see it, the page is busy), then
we can ignore the page after the io is done. We could do something
similar for PGO_DEACTIVATE too, but that is another change. On error we
just clear the released flag, nothing else sets it for uobj pages other
than aiodoned.

ok thib@, beck@, ariane@


# 1.50 04-May-2009 oga

Instead of keeping two ints in the uvm structure specifically just to
sleep on them (and otherwise ignore them) sleep on the pointer to the
{aiodoned,pagedaemon}_proc members, and nuke the two extra words.

"no objections" art@, ok beck@.


# 1.49 06-Apr-2009 oga

Instead of doing splbio(); simple_lock(&uvm.aiodoned_lock); just replace
the simple lock with a real lock - a IPL_BIO mutex. While i'm here, make
the sleeping condition one hell of a lot simpler in the aio daemon.

some ideas from and ok art@.


# 1.48 25-Mar-2009 oga

Move all of the pseudo-inline functions in uvm into C files.

By pseudo-inline, I mean that if a certain macro was defined, they would
be inlined. However, no architecture defines that, and none has for a
very very long time. Therefore mainly this just makes the code a damned
sight easier to read. Some k&r -> ansi declarations while I'm in there.

"just commit it" art@. ok weingart@.


# 1.47 20-Mar-2009 oga

While working on some stuff in uvm I've gotten REALLY sick of reading
K&R function declarations, so switch them all over to ansi-style, in
accordance with the prophesy.

"go for it" art@


Revision tags: OPENBSD_4_5_BASE
# 1.46 27-Jan-2009 ariane

Simplify page-out/page-in map management; fix rare pager deadlock.

Ok: miod, tedu


# 1.45 24-Nov-2008 thib

garbage collect uvm_errno2vmerror();

ok miod@, art@


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.44 26-Nov-2007 miod

In uvm_aio_aiodone(), kill the variable-sized array on stack, and use a
fixed size array which size should match any buf; if a bogus buf is passed
to this function, the kernel will KASSERT instead of potentially running out
of stack and having an undefined behaviour.

ok deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.43 06-Jun-2007 deraadt

now that all partition size/offsets are potentially 64-bit, change the
type of all variables to daddr64_t. this includes the APIs for XXsize()
and XXdump(), all range checks inside bio drivers, internal variables
for disklabel handling, and even uvm's swap offsets. re-read numerous
times by otto, miod, krw, thib to look for errors


# 1.42 13-Apr-2007 art

While splitting flags and pqflags might have been a good idea in theory
to separate locking, on most modern machines this is not enough
since operations on short types touch other short types that share the
same word in memory.

Merge pg_flags and pqflags again and now use atomic operations to change
the flags. Also bump wire_count to an int and pg_version might go
int as well, just for alignment.

tested by many, many. ok miod@


# 1.41 04-Apr-2007 art

Mechanically rename the "flags" and "version" fields in struct vm_page
to "pg_flags" and "pg_version", so that they are a bit easier to work with.
Whoever uses generic names like this for a popular struct obviously doesn't
read much code.

Most architectures compile and there are no functionality changes.

deraadt@ ok ("if something fails to compile, we fix that by hand")


# 1.40 25-Mar-2007 art

remove KERN_SUCCESS and use 0 instead.
eyeballed by miod@ and pedro@


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.39 31-Jul-2006 mickey

fix uvmhist #2: args are always u_long so fix missing %d and %x and no %ll; no change for normal code


# 1.38 26-Jul-2006 mickey

fix fmts for UVMHIST_LOG() entries making it more useful on 64bit archs; miod@ ok


Revision tags: OPENBSD_3_8_BASE OPENBSD_3_9_BASE
# 1.37 26-Jul-2005 art

- Make a UVM_OBJ_IS_DEVICE macro.
- Use it to skip device mappings while dumping core.
- Ignore EFAULT errors while dumping core since they can happen
even for valid mappings. Just skip that part of the core file and
let it get automagically zero-filled.

This fixes the broken X core dumps that people have been seeing and also
fixes some other potential problems that could prevent core dumps (mmaps
beyond EOF, etc.).

tedu@ ok


# 1.36 24-May-2005 tedu

add a new field to vm_space and use it to track the number of anon
pages a process uses. this is now the userland "data size" value.
ok art deraadt tdeval. thanks testers.


Revision tags: OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE SMP_SYNC_A SMP_SYNC_B
# 1.35 23-Feb-2004 drahn

sync of pmap_update() calls with NetBSD. pmap_update is defined away on
all architectures but arm, where it is needed.


Revision tags: OPENBSD_3_4_BASE UBC_SYNC_A
# 1.34 29-Mar-2003 mickey

ubchist is not a fully cooked kadaver and though use the other well formed pdhist one until ubc gaets back. art@ ok


Revision tags: OPENBSD_3_3_BASE
# 1.33 29-Oct-2002 art

Since memory deallocation can't fail, remove the error return from
uvm_unmap, uvm_deallocate and a few other functions.
Simplifies some code and reduces diff to the UBC branch.


Revision tags: OPENBSD_3_2_BASE UBC_SYNC_B
# 1.32 24-May-2002 art

Make sure that b_iodone handlers are called at splbio (and splassert(IPL_BIO) in all known callers, just to make sure).


# 1.31 22-May-2002 art

splassert(IPL_BIO) in the b_iodone handlers.


Revision tags: OPENBSD_3_1_BASE
# 1.30 02-Jan-2002 miod

Back out a few more uvm changes, especially wrt swap usage.
This unbreaks m68k m88k sparc and perhaps others, which eventually froze
when hitting swap.
Tested by various people on various platforms.
ok art@


# 1.29 19-Dec-2001 art

UBC was a disaster. It worked very good when it worked, but on some
machines or some configurations or in some phase of the moon (we actually
don't know when or why) files disappeared. Since we've not been able to
track down the problem in two weeks intense debugging and we need -current
to be stable, back out everything to a state it had before UBC.

We apologise for the inconvenience.


Revision tags: UBC_BASE
# 1.28 04-Dec-2001 art

branches: 1.28.2;
Yet another sync to NetBSD uvm.
Today we add a pmap argument to pmap_update() and allocate map entries for
kernel_map from kmem_map instead of using the static entries. This should
get rid of MAX_KMAPENT panics. Also some uvm_loan problems are fixed.


# 1.27 30-Nov-2001 csapuntz

Call buf_cleanout, which handles wakeups


# 1.26 29-Nov-2001 art

Correctly handle b_vp with bgetvp and brelvp in {get,put}pages.
Prevents panics caused by vnodes being recycled under our feet.


# 1.25 28-Nov-2001 art

Sync in more uvm from NetBSD. Mostly just cosmetic stuff.
Contains also support for page coloring.


# 1.24 28-Nov-2001 art

Sync in more uvm changes from NetBSD.
This time we're getting rid of KERN_* and VM_PAGER_* error codes and
use errnos instead.


# 1.23 27-Nov-2001 art

Merge in the unified buffer cache code as found in NetBSD 2001/03/10. The
code is written mostly by Chuck Silvers <chuq@chuq.com>/<chs@netbsd.org>.

Tested for the past few weeks by many developers, should be in a pretty stable
state, but will require optimizations and additional cleanups.


# 1.22 12-Nov-2001 art

Bring in more changes from NetBSD. Mostly pagedaemon improvements.


# 1.21 10-Nov-2001 art

Merge in some parts of the ubc work that has been done in NetBSD that are not
UBC, but prerequsites for it.

- Create a daemon that processes async I/O (swap and paging in the future)
requests that need processing in process context and that were processed
in the pagedaemon before.
- Convert some ugly ifdef DIAGNOSTIC code to less intrusive KASSERTs.
- misc other cleanups.


# 1.20 07-Nov-2001 art

Another sync of uvm to NetBSD. Just minor fiddling, no major changes.


# 1.19 07-Nov-2001 art

Add an alignment argument to uvm_map that specifies an alignment hint
for the virtual address.


# 1.18 06-Nov-2001 art

Move the last content from vm/ to uvm/
The only thing left in vm/ are just dumb wrappers.
vm/vm.h includes uvm/uvm_extern.h
vm/pmap.h includes uvm/uvm_pmap.h
vm/vm_page.h includes uvm/uvm_page.h


# 1.17 05-Nov-2001 art

Minor sync to NetBSD.


Revision tags: OPENBSD_3_0_BASE
# 1.16 20-Sep-2001 mpech

occured->occurred

idea from deraadt@ via NetBSD
millert@ ok


# 1.15 19-Sep-2001 mickey

merge vm/vm_kern.h into uvm/uvm_extern.h; art@ ok


# 1.14 11-Aug-2001 art

Various random fixes from NetBSD.
Including support for zeroing pages in the idle loop (not enabled yet).


# 1.13 06-Aug-2001 art

Add a new type voff_t (right now it's typedefed as off_t) used for offsets
into objects.

Gives the possibilty to mmap beyond the size of vaddr_t.

From NetBSD.


# 1.12 26-Jul-2001 art

Add support for disabling swap devices (swapctl -d).
Improve error handling on I/O errors to swap.
From NetBSD


# 1.11 25-Jul-2001 art

Change the pmap_enter interface to merge access_type and the wired boolean
and arbitrary flags into one argument.

One new flag is PMAP_CANFAIL that tells pmap_enter that it can fail if there
are not enough resources to satisfy the request. If this flag is not passed,
pmap_enter should panic as it should have done before this change (XXX - many
pmaps are still not doing that).

Only i386 and alpha implement CANFAIL for now.

Includes uvm updates from NetBSD.


# 1.10 18-Jul-2001 art

Get rid of the PMAP_NEW option by making it mandatory for all archs.
The archs that didn't have a proper PMAP_NEW now have a dummy implementation
with wrappers around the old functions.


# 1.9 08-Jun-2001 art

Change the paddr_t pmap_extract(struct pmap *, vaddr_t) interface to
boolean_t pmap_extract(struct pmap *, vaddr_t, paddr_t *).
Matches NetBSD. Tested by various people on various platforms.


Revision tags: OPENBSD_2_9_BASE
# 1.8 22-Mar-2001 smart

Sync style, typo, and comments a little closer to NetBSD. art@ ok


# 1.7 08-Mar-2001 smart

Replace thread_wakeup() with wakeup(). It is defined in vm_extern.h as a
wrapper, so this removes a dependence on the old VM system. From NetBSD.
art@ ok


# 1.6 29-Jan-2001 niklas

$OpenBSD$


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE
# 1.5 16-Mar-2000 art

Bring in some new UVM code from NetBSD (not current).

- Introduce a new type of map that are interrupt safe and never allow faults
in them. mb_map and kmem_map are made intrsafe.
- Add "access protection" to uvm_vslock (to be passed down to uvm_fault and
later to pmap_enter).
- madvise(2) now works.
- various cleanups.


Revision tags: OPENBSD_2_6_BASE SMP_BASE kame_19991208
# 1.4 03-Sep-1999 art

branches: 1.4.4;
Change the pmap_enter api to pass down an argument that indicates
the access type that caused this mapping. This is to simplify pmaps
with mod/ref emulation (none for the moment) and in some cases speed
up pmap_is_{referenced,modified}.
At the same time, clean up some mappings that had too high protection.

XXX - the access type is incorrect in old vm, it's only used by uvm and MD code.
The actual use of this in pmap_enter implementations is not in this commit.


# 1.3 23-Aug-1999 art

sync with NetBSD from 1999.05.24 (there is a reason for this date)
Mostly cleanups, but also a few improvements to pagedaemon for better
handling of low memory and/or low swap conditions.


Revision tags: OPENBSD_2_5_BASE
# 1.2 26-Feb-1999 art

add OpenBSD tags


# 1.1 26-Feb-1999 art

Import of uvm from NetBSD. Some local changes, some code disabled


# 1.73 21-Oct-2020 mpi

Constify and use C99 initializer for "struct uvm_pagerops".

While here put some KERNEL_ASSERT_LOCKED() in the functions called from
the page fault handler. The removal of locking of `uobj' will need to be
revisited and these are good indicator that something is missing and that
many comments are lying.

ok kettenis


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.72 08-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok visa@, jca@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.71 17-Dec-2014 tedu

remove lock.h from uvm_extern.h. another holdover from the simpletonlock
era. fix uvm including c files to include lock.h or atomic.h as necessary.
ok deraadt


# 1.70 16-Nov-2014 deraadt

Replace a plethora of historical protection options with just
PROT_NONE, PROT_READ, PROT_WRITE, and PROT_EXEC from mman.h.
PROT_MASK is introduced as the one true way of extracting those bits.
Remove UVM_ADV_* wrapper, using the standard names.
ok doug guenther kettenis


# 1.69 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.68 11-Jul-2014 jsg

Chuck Cranor rescinded clauses in his license
on the 2nd of February 2011 in NetBSD.

http://marc.info/?l=netbsd-source-changes&m=129658899212732&w=2
http://marc.info/?l=netbsd-source-changes&m=129659095515558&w=2
http://marc.info/?l=netbsd-source-changes&m=129659157916514&w=2
http://marc.info/?l=netbsd-source-changes&m=129665962324372&w=2
http://marc.info/?l=netbsd-source-changes&m=129666033625342&w=2
http://marc.info/?l=netbsd-source-changes&m=129666052825545&w=2
http://marc.info/?l=netbsd-source-changes&m=129666922906480&w=2
http://marc.info/?l=netbsd-source-changes&m=129667725518082&w=2


# 1.67 09-May-2014 tedu

stop using B_AGE, it was effectively retired some time ago.


# 1.66 08-May-2014 kettenis

Fix some potential integer overflows caused by converting a page number into
an offset/size/address by shifting by PAGE_SHIFT. Make uvm_objwrire/unwire
use voff_t instead of off_t. The former is the right type here even if it is
equivalent to the latter.

Inspired by a somewhat similar changes in Bitrig.

ok deraadt@, guenther@


# 1.65 13-Apr-2014 tedu

compress code by turning four line comments into one line comments.
emphatic ok usual suspects, grudging ok miod


Revision tags: OPENBSD_5_5_BASE
# 1.64 02-Nov-2013 krw

No need to cast constants or simple variables to (daddr_t). Use
(u_int64_t) instead of (daddr_t) when casting a variable in an
expression passed to DL_SETDSIZE().

Change a variable counting open files from daddr_t to int64_t.

ok deraadt@ with the tweak to fix that pesky expression.


Revision tags: OPENBSD_5_4_BASE
# 1.63 11-Jun-2013 deraadt

final removal of daddr64_t. daddr_t has been 64 bit for a long enough
test period; i think 3 years ago the last bugs fell out.
ok otto beck others


# 1.62 30-May-2013 tedu

remove lots of comments about locking per beck's request


# 1.61 30-May-2013 tedu

remove simple_locks from uvm code. ok beck deraadt


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.60 03-Jul-2011 oga

Rip out and burn support for UVM_HIST.

The vm hackers don't use it, don't maintain it and have to look at it all the
time. About time this 800 lines of code hit /dev/null.

``never liked it'' tedu@. ariane@ was very happy when i told her i wrote
this diff.


# 1.59 15-Apr-2011 oga

for uvm_pager_dropcluster in the PG_RELEASED case we specifically unbusy the
page so that um_anfree will free it for us.

uvm_anfree does a pmap_page_protect(, VM_PROT_NONE) just before it frees the
page, so we don't need to do it here ourselves.

ok ariane@


# 1.58 15-Apr-2011 oga

move uvm_pageratop from uvm_pager.c local to a general uvm function
(uvm_atopg) and use it in uvm_km_doputpage to replace some handrolled
code. Shrinks the kernel a trivial amount.

ok beck@ and miod@ (who suggested i name it uvm_atopg not uvm_atop)


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.57 24-Jul-2010 kettenis

Don't sleep while holding the uvm_psel_lck mutex. Should fix "locking against
myself" panics that some people have seen over the last year-and-a-half.

Cherry picked from a more complex (and therefore scarier) diff from oga@.

ok tedu@, oga@


# 1.56 27-Jun-2010 oga

Kill another #ifdef UBC chunk that was annoying me while doing something
else.

ok thib@


Revision tags: OPENBSD_4_7_BASE
# 1.55 12-Feb-2010 tedu

introduce a uvm_km_valloc_try function that won't get a lower level lock
for use by the uvm pseg code. this is the path of least resistance until
we sort out how many of these functions we really need. problem found by mikeb
ok kettenis oga


# 1.54 22-Jul-2009 oga

Put the PG_RELEASED changes diff back in.

This has has been tested very very thoroughly on all archs we have
excepting 88k and 68k. Please see cvs log for the individual commit
messages.

ok beck@, thib@


Revision tags: OPENBSD_4_6_BASE
# 1.53 17-Jun-2009 oga

date based reversion of uvm to the 4th May.

More backouts in line with previous ones, this appears to bring us back to a
stable condition.

A machine forced to 64mb of ram cycled 10GB through swap with this diff
and is still running as I type this. Other tests by ariane@ and thib@
also seem to show that it's alright.

ok deraadt@, thib@, ariane@


# 1.52 16-Jun-2009 oga

Backout all the PG_RELEASED changes.

This is for the same reason as the earlier backouts, to avoid the bug
either added or exposed sometime around c2k9. This *should* be the last
one.

prompted by deraadt@

ok ariane@


# 1.51 23-May-2009 oga

More PG_RELEASED cleaning.

similar to the aobj.c changes, this one does vnodes. Vnodes are more
complex because they actaully have to sync to backing store. So firstly,
convert sync to sleep instead of setting released.

Now, for backing store, in the PGO_FREE case, if we set PG_RELEASED
*before* an async io, (nothing else will see it, the page is busy), then
we can ignore the page after the io is done. We could do something
similar for PGO_DEACTIVATE too, but that is another change. On error we
just clear the released flag, nothing else sets it for uobj pages other
than aiodoned.

ok thib@, beck@, ariane@


# 1.50 04-May-2009 oga

Instead of keeping two ints in the uvm structure specifically just to
sleep on them (and otherwise ignore them) sleep on the pointer to the
{aiodoned,pagedaemon}_proc members, and nuke the two extra words.

"no objections" art@, ok beck@.


# 1.49 06-Apr-2009 oga

Instead of doing splbio(); simple_lock(&uvm.aiodoned_lock); just replace
the simple lock with a real lock - a IPL_BIO mutex. While i'm here, make
the sleeping condition one hell of a lot simpler in the aio daemon.

some ideas from and ok art@.


# 1.48 25-Mar-2009 oga

Move all of the pseudo-inline functions in uvm into C files.

By pseudo-inline, I mean that if a certain macro was defined, they would
be inlined. However, no architecture defines that, and none has for a
very very long time. Therefore mainly this just makes the code a damned
sight easier to read. Some k&r -> ansi declarations while I'm in there.

"just commit it" art@. ok weingart@.


# 1.47 20-Mar-2009 oga

While working on some stuff in uvm I've gotten REALLY sick of reading
K&R function declarations, so switch them all over to ansi-style, in
accordance with the prophesy.

"go for it" art@


Revision tags: OPENBSD_4_5_BASE
# 1.46 27-Jan-2009 ariane

Simplify page-out/page-in map management; fix rare pager deadlock.

Ok: miod, tedu


# 1.45 24-Nov-2008 thib

garbage collect uvm_errno2vmerror();

ok miod@, art@


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.44 26-Nov-2007 miod

In uvm_aio_aiodone(), kill the variable-sized array on stack, and use a
fixed size array which size should match any buf; if a bogus buf is passed
to this function, the kernel will KASSERT instead of potentially running out
of stack and having an undefined behaviour.

ok deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.43 06-Jun-2007 deraadt

now that all partition size/offsets are potentially 64-bit, change the
type of all variables to daddr64_t. this includes the APIs for XXsize()
and XXdump(), all range checks inside bio drivers, internal variables
for disklabel handling, and even uvm's swap offsets. re-read numerous
times by otto, miod, krw, thib to look for errors


# 1.42 13-Apr-2007 art

While splitting flags and pqflags might have been a good idea in theory
to separate locking, on most modern machines this is not enough
since operations on short types touch other short types that share the
same word in memory.

Merge pg_flags and pqflags again and now use atomic operations to change
the flags. Also bump wire_count to an int and pg_version might go
int as well, just for alignment.

tested by many, many. ok miod@


# 1.41 04-Apr-2007 art

Mechanically rename the "flags" and "version" fields in struct vm_page
to "pg_flags" and "pg_version", so that they are a bit easier to work with.
Whoever uses generic names like this for a popular struct obviously doesn't
read much code.

Most architectures compile and there are no functionality changes.

deraadt@ ok ("if something fails to compile, we fix that by hand")


# 1.40 25-Mar-2007 art

remove KERN_SUCCESS and use 0 instead.
eyeballed by miod@ and pedro@


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.39 31-Jul-2006 mickey

fix uvmhist #2: args are always u_long so fix missing %d and %x and no %ll; no change for normal code


# 1.38 26-Jul-2006 mickey

fix fmts for UVMHIST_LOG() entries making it more useful on 64bit archs; miod@ ok


Revision tags: OPENBSD_3_8_BASE OPENBSD_3_9_BASE
# 1.37 26-Jul-2005 art

- Make a UVM_OBJ_IS_DEVICE macro.
- Use it to skip device mappings while dumping core.
- Ignore EFAULT errors while dumping core since they can happen
even for valid mappings. Just skip that part of the core file and
let it get automagically zero-filled.

This fixes the broken X core dumps that people have been seeing and also
fixes some other potential problems that could prevent core dumps (mmaps
beyond EOF, etc.).

tedu@ ok


# 1.36 24-May-2005 tedu

add a new field to vm_space and use it to track the number of anon
pages a process uses. this is now the userland "data size" value.
ok art deraadt tdeval. thanks testers.


Revision tags: OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE SMP_SYNC_A SMP_SYNC_B
# 1.35 23-Feb-2004 drahn

sync of pmap_update() calls with NetBSD. pmap_update is defined away on
all architectures but arm, where it is needed.


Revision tags: OPENBSD_3_4_BASE UBC_SYNC_A
# 1.34 29-Mar-2003 mickey

ubchist is not a fully cooked kadaver and though use the other well formed pdhist one until ubc gaets back. art@ ok


Revision tags: OPENBSD_3_3_BASE
# 1.33 29-Oct-2002 art

Since memory deallocation can't fail, remove the error return from
uvm_unmap, uvm_deallocate and a few other functions.
Simplifies some code and reduces diff to the UBC branch.


Revision tags: OPENBSD_3_2_BASE UBC_SYNC_B
# 1.32 24-May-2002 art

Make sure that b_iodone handlers are called at splbio (and splassert(IPL_BIO) in all known callers, just to make sure).


# 1.31 22-May-2002 art

splassert(IPL_BIO) in the b_iodone handlers.


Revision tags: OPENBSD_3_1_BASE
# 1.30 02-Jan-2002 miod

Back out a few more uvm changes, especially wrt swap usage.
This unbreaks m68k m88k sparc and perhaps others, which eventually froze
when hitting swap.
Tested by various people on various platforms.
ok art@


# 1.29 19-Dec-2001 art

UBC was a disaster. It worked very good when it worked, but on some
machines or some configurations or in some phase of the moon (we actually
don't know when or why) files disappeared. Since we've not been able to
track down the problem in two weeks intense debugging and we need -current
to be stable, back out everything to a state it had before UBC.

We apologise for the inconvenience.


Revision tags: UBC_BASE
# 1.28 04-Dec-2001 art

branches: 1.28.2;
Yet another sync to NetBSD uvm.
Today we add a pmap argument to pmap_update() and allocate map entries for
kernel_map from kmem_map instead of using the static entries. This should
get rid of MAX_KMAPENT panics. Also some uvm_loan problems are fixed.


# 1.27 30-Nov-2001 csapuntz

Call buf_cleanout, which handles wakeups


# 1.26 29-Nov-2001 art

Correctly handle b_vp with bgetvp and brelvp in {get,put}pages.
Prevents panics caused by vnodes being recycled under our feet.


# 1.25 28-Nov-2001 art

Sync in more uvm from NetBSD. Mostly just cosmetic stuff.
Contains also support for page coloring.


# 1.24 28-Nov-2001 art

Sync in more uvm changes from NetBSD.
This time we're getting rid of KERN_* and VM_PAGER_* error codes and
use errnos instead.


# 1.23 27-Nov-2001 art

Merge in the unified buffer cache code as found in NetBSD 2001/03/10. The
code is written mostly by Chuck Silvers <chuq@chuq.com>/<chs@netbsd.org>.

Tested for the past few weeks by many developers, should be in a pretty stable
state, but will require optimizations and additional cleanups.


# 1.22 12-Nov-2001 art

Bring in more changes from NetBSD. Mostly pagedaemon improvements.


# 1.21 10-Nov-2001 art

Merge in some parts of the ubc work that has been done in NetBSD that are not
UBC, but prerequsites for it.

- Create a daemon that processes async I/O (swap and paging in the future)
requests that need processing in process context and that were processed
in the pagedaemon before.
- Convert some ugly ifdef DIAGNOSTIC code to less intrusive KASSERTs.
- misc other cleanups.


# 1.20 07-Nov-2001 art

Another sync of uvm to NetBSD. Just minor fiddling, no major changes.


# 1.19 07-Nov-2001 art

Add an alignment argument to uvm_map that specifies an alignment hint
for the virtual address.


# 1.18 06-Nov-2001 art

Move the last content from vm/ to uvm/
The only thing left in vm/ are just dumb wrappers.
vm/vm.h includes uvm/uvm_extern.h
vm/pmap.h includes uvm/uvm_pmap.h
vm/vm_page.h includes uvm/uvm_page.h


# 1.17 05-Nov-2001 art

Minor sync to NetBSD.


Revision tags: OPENBSD_3_0_BASE
# 1.16 20-Sep-2001 mpech

occured->occurred

idea from deraadt@ via NetBSD
millert@ ok


# 1.15 19-Sep-2001 mickey

merge vm/vm_kern.h into uvm/uvm_extern.h; art@ ok


# 1.14 11-Aug-2001 art

Various random fixes from NetBSD.
Including support for zeroing pages in the idle loop (not enabled yet).


# 1.13 06-Aug-2001 art

Add a new type voff_t (right now it's typedefed as off_t) used for offsets
into objects.

Gives the possibilty to mmap beyond the size of vaddr_t.

From NetBSD.


# 1.12 26-Jul-2001 art

Add support for disabling swap devices (swapctl -d).
Improve error handling on I/O errors to swap.
From NetBSD


# 1.11 25-Jul-2001 art

Change the pmap_enter interface to merge access_type and the wired boolean
and arbitrary flags into one argument.

One new flag is PMAP_CANFAIL that tells pmap_enter that it can fail if there
are not enough resources to satisfy the request. If this flag is not passed,
pmap_enter should panic as it should have done before this change (XXX - many
pmaps are still not doing that).

Only i386 and alpha implement CANFAIL for now.

Includes uvm updates from NetBSD.


# 1.10 18-Jul-2001 art

Get rid of the PMAP_NEW option by making it mandatory for all archs.
The archs that didn't have a proper PMAP_NEW now have a dummy implementation
with wrappers around the old functions.


# 1.9 08-Jun-2001 art

Change the paddr_t pmap_extract(struct pmap *, vaddr_t) interface to
boolean_t pmap_extract(struct pmap *, vaddr_t, paddr_t *).
Matches NetBSD. Tested by various people on various platforms.


Revision tags: OPENBSD_2_9_BASE
# 1.8 22-Mar-2001 smart

Sync style, typo, and comments a little closer to NetBSD. art@ ok


# 1.7 08-Mar-2001 smart

Replace thread_wakeup() with wakeup(). It is defined in vm_extern.h as a
wrapper, so this removes a dependence on the old VM system. From NetBSD.
art@ ok


# 1.6 29-Jan-2001 niklas

$OpenBSD$


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE
# 1.5 16-Mar-2000 art

Bring in some new UVM code from NetBSD (not current).

- Introduce a new type of map that are interrupt safe and never allow faults
in them. mb_map and kmem_map are made intrsafe.
- Add "access protection" to uvm_vslock (to be passed down to uvm_fault and
later to pmap_enter).
- madvise(2) now works.
- various cleanups.


Revision tags: OPENBSD_2_6_BASE SMP_BASE kame_19991208
# 1.4 03-Sep-1999 art

branches: 1.4.4;
Change the pmap_enter api to pass down an argument that indicates
the access type that caused this mapping. This is to simplify pmaps
with mod/ref emulation (none for the moment) and in some cases speed
up pmap_is_{referenced,modified}.
At the same time, clean up some mappings that had too high protection.

XXX - the access type is incorrect in old vm, it's only used by uvm and MD code.
The actual use of this in pmap_enter implementations is not in this commit.


# 1.3 23-Aug-1999 art

sync with NetBSD from 1999.05.24 (there is a reason for this date)
Mostly cleanups, but also a few improvements to pagedaemon for better
handling of low memory and/or low swap conditions.


Revision tags: OPENBSD_2_5_BASE
# 1.2 26-Feb-1999 art

add OpenBSD tags


# 1.1 26-Feb-1999 art

Import of uvm from NetBSD. Some local changes, some code disabled


# 1.72 08-Dec-2019 mpi

Convert infinite sleeps to {m,t}sleep_nsec(9).

ok visa@, jca@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.71 17-Dec-2014 tedu

remove lock.h from uvm_extern.h. another holdover from the simpletonlock
era. fix uvm including c files to include lock.h or atomic.h as necessary.
ok deraadt


# 1.70 16-Nov-2014 deraadt

Replace a plethora of historical protection options with just
PROT_NONE, PROT_READ, PROT_WRITE, and PROT_EXEC from mman.h.
PROT_MASK is introduced as the one true way of extracting those bits.
Remove UVM_ADV_* wrapper, using the standard names.
ok doug guenther kettenis


# 1.69 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.68 11-Jul-2014 jsg

Chuck Cranor rescinded clauses in his license
on the 2nd of February 2011 in NetBSD.

http://marc.info/?l=netbsd-source-changes&m=129658899212732&w=2
http://marc.info/?l=netbsd-source-changes&m=129659095515558&w=2
http://marc.info/?l=netbsd-source-changes&m=129659157916514&w=2
http://marc.info/?l=netbsd-source-changes&m=129665962324372&w=2
http://marc.info/?l=netbsd-source-changes&m=129666033625342&w=2
http://marc.info/?l=netbsd-source-changes&m=129666052825545&w=2
http://marc.info/?l=netbsd-source-changes&m=129666922906480&w=2
http://marc.info/?l=netbsd-source-changes&m=129667725518082&w=2


# 1.67 09-May-2014 tedu

stop using B_AGE, it was effectively retired some time ago.


# 1.66 08-May-2014 kettenis

Fix some potential integer overflows caused by converting a page number into
an offset/size/address by shifting by PAGE_SHIFT. Make uvm_objwrire/unwire
use voff_t instead of off_t. The former is the right type here even if it is
equivalent to the latter.

Inspired by a somewhat similar changes in Bitrig.

ok deraadt@, guenther@


# 1.65 13-Apr-2014 tedu

compress code by turning four line comments into one line comments.
emphatic ok usual suspects, grudging ok miod


Revision tags: OPENBSD_5_5_BASE
# 1.64 02-Nov-2013 krw

No need to cast constants or simple variables to (daddr_t). Use
(u_int64_t) instead of (daddr_t) when casting a variable in an
expression passed to DL_SETDSIZE().

Change a variable counting open files from daddr_t to int64_t.

ok deraadt@ with the tweak to fix that pesky expression.


Revision tags: OPENBSD_5_4_BASE
# 1.63 11-Jun-2013 deraadt

final removal of daddr64_t. daddr_t has been 64 bit for a long enough
test period; i think 3 years ago the last bugs fell out.
ok otto beck others


# 1.62 30-May-2013 tedu

remove lots of comments about locking per beck's request


# 1.61 30-May-2013 tedu

remove simple_locks from uvm code. ok beck deraadt


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.60 03-Jul-2011 oga

Rip out and burn support for UVM_HIST.

The vm hackers don't use it, don't maintain it and have to look at it all the
time. About time this 800 lines of code hit /dev/null.

``never liked it'' tedu@. ariane@ was very happy when i told her i wrote
this diff.


# 1.59 15-Apr-2011 oga

for uvm_pager_dropcluster in the PG_RELEASED case we specifically unbusy the
page so that um_anfree will free it for us.

uvm_anfree does a pmap_page_protect(, VM_PROT_NONE) just before it frees the
page, so we don't need to do it here ourselves.

ok ariane@


# 1.58 15-Apr-2011 oga

move uvm_pageratop from uvm_pager.c local to a general uvm function
(uvm_atopg) and use it in uvm_km_doputpage to replace some handrolled
code. Shrinks the kernel a trivial amount.

ok beck@ and miod@ (who suggested i name it uvm_atopg not uvm_atop)


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.57 24-Jul-2010 kettenis

Don't sleep while holding the uvm_psel_lck mutex. Should fix "locking against
myself" panics that some people have seen over the last year-and-a-half.

Cherry picked from a more complex (and therefore scarier) diff from oga@.

ok tedu@, oga@


# 1.56 27-Jun-2010 oga

Kill another #ifdef UBC chunk that was annoying me while doing something
else.

ok thib@


Revision tags: OPENBSD_4_7_BASE
# 1.55 12-Feb-2010 tedu

introduce a uvm_km_valloc_try function that won't get a lower level lock
for use by the uvm pseg code. this is the path of least resistance until
we sort out how many of these functions we really need. problem found by mikeb
ok kettenis oga


# 1.54 22-Jul-2009 oga

Put the PG_RELEASED changes diff back in.

This has has been tested very very thoroughly on all archs we have
excepting 88k and 68k. Please see cvs log for the individual commit
messages.

ok beck@, thib@


Revision tags: OPENBSD_4_6_BASE
# 1.53 17-Jun-2009 oga

date based reversion of uvm to the 4th May.

More backouts in line with previous ones, this appears to bring us back to a
stable condition.

A machine forced to 64mb of ram cycled 10GB through swap with this diff
and is still running as I type this. Other tests by ariane@ and thib@
also seem to show that it's alright.

ok deraadt@, thib@, ariane@


# 1.52 16-Jun-2009 oga

Backout all the PG_RELEASED changes.

This is for the same reason as the earlier backouts, to avoid the bug
either added or exposed sometime around c2k9. This *should* be the last
one.

prompted by deraadt@

ok ariane@


# 1.51 23-May-2009 oga

More PG_RELEASED cleaning.

similar to the aobj.c changes, this one does vnodes. Vnodes are more
complex because they actaully have to sync to backing store. So firstly,
convert sync to sleep instead of setting released.

Now, for backing store, in the PGO_FREE case, if we set PG_RELEASED
*before* an async io, (nothing else will see it, the page is busy), then
we can ignore the page after the io is done. We could do something
similar for PGO_DEACTIVATE too, but that is another change. On error we
just clear the released flag, nothing else sets it for uobj pages other
than aiodoned.

ok thib@, beck@, ariane@


# 1.50 04-May-2009 oga

Instead of keeping two ints in the uvm structure specifically just to
sleep on them (and otherwise ignore them) sleep on the pointer to the
{aiodoned,pagedaemon}_proc members, and nuke the two extra words.

"no objections" art@, ok beck@.


# 1.49 06-Apr-2009 oga

Instead of doing splbio(); simple_lock(&uvm.aiodoned_lock); just replace
the simple lock with a real lock - a IPL_BIO mutex. While i'm here, make
the sleeping condition one hell of a lot simpler in the aio daemon.

some ideas from and ok art@.


# 1.48 25-Mar-2009 oga

Move all of the pseudo-inline functions in uvm into C files.

By pseudo-inline, I mean that if a certain macro was defined, they would
be inlined. However, no architecture defines that, and none has for a
very very long time. Therefore mainly this just makes the code a damned
sight easier to read. Some k&r -> ansi declarations while I'm in there.

"just commit it" art@. ok weingart@.


# 1.47 20-Mar-2009 oga

While working on some stuff in uvm I've gotten REALLY sick of reading
K&R function declarations, so switch them all over to ansi-style, in
accordance with the prophesy.

"go for it" art@


Revision tags: OPENBSD_4_5_BASE
# 1.46 27-Jan-2009 ariane

Simplify page-out/page-in map management; fix rare pager deadlock.

Ok: miod, tedu


# 1.45 24-Nov-2008 thib

garbage collect uvm_errno2vmerror();

ok miod@, art@


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.44 26-Nov-2007 miod

In uvm_aio_aiodone(), kill the variable-sized array on stack, and use a
fixed size array which size should match any buf; if a bogus buf is passed
to this function, the kernel will KASSERT instead of potentially running out
of stack and having an undefined behaviour.

ok deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.43 06-Jun-2007 deraadt

now that all partition size/offsets are potentially 64-bit, change the
type of all variables to daddr64_t. this includes the APIs for XXsize()
and XXdump(), all range checks inside bio drivers, internal variables
for disklabel handling, and even uvm's swap offsets. re-read numerous
times by otto, miod, krw, thib to look for errors


# 1.42 13-Apr-2007 art

While splitting flags and pqflags might have been a good idea in theory
to separate locking, on most modern machines this is not enough
since operations on short types touch other short types that share the
same word in memory.

Merge pg_flags and pqflags again and now use atomic operations to change
the flags. Also bump wire_count to an int and pg_version might go
int as well, just for alignment.

tested by many, many. ok miod@


# 1.41 04-Apr-2007 art

Mechanically rename the "flags" and "version" fields in struct vm_page
to "pg_flags" and "pg_version", so that they are a bit easier to work with.
Whoever uses generic names like this for a popular struct obviously doesn't
read much code.

Most architectures compile and there are no functionality changes.

deraadt@ ok ("if something fails to compile, we fix that by hand")


# 1.40 25-Mar-2007 art

remove KERN_SUCCESS and use 0 instead.
eyeballed by miod@ and pedro@


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.39 31-Jul-2006 mickey

fix uvmhist #2: args are always u_long so fix missing %d and %x and no %ll; no change for normal code


# 1.38 26-Jul-2006 mickey

fix fmts for UVMHIST_LOG() entries making it more useful on 64bit archs; miod@ ok


Revision tags: OPENBSD_3_8_BASE OPENBSD_3_9_BASE
# 1.37 26-Jul-2005 art

- Make a UVM_OBJ_IS_DEVICE macro.
- Use it to skip device mappings while dumping core.
- Ignore EFAULT errors while dumping core since they can happen
even for valid mappings. Just skip that part of the core file and
let it get automagically zero-filled.

This fixes the broken X core dumps that people have been seeing and also
fixes some other potential problems that could prevent core dumps (mmaps
beyond EOF, etc.).

tedu@ ok


# 1.36 24-May-2005 tedu

add a new field to vm_space and use it to track the number of anon
pages a process uses. this is now the userland "data size" value.
ok art deraadt tdeval. thanks testers.


Revision tags: OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE SMP_SYNC_A SMP_SYNC_B
# 1.35 23-Feb-2004 drahn

sync of pmap_update() calls with NetBSD. pmap_update is defined away on
all architectures but arm, where it is needed.


Revision tags: OPENBSD_3_4_BASE UBC_SYNC_A
# 1.34 29-Mar-2003 mickey

ubchist is not a fully cooked kadaver and though use the other well formed pdhist one until ubc gaets back. art@ ok


Revision tags: OPENBSD_3_3_BASE
# 1.33 29-Oct-2002 art

Since memory deallocation can't fail, remove the error return from
uvm_unmap, uvm_deallocate and a few other functions.
Simplifies some code and reduces diff to the UBC branch.


Revision tags: OPENBSD_3_2_BASE UBC_SYNC_B
# 1.32 24-May-2002 art

Make sure that b_iodone handlers are called at splbio (and splassert(IPL_BIO) in all known callers, just to make sure).


# 1.31 22-May-2002 art

splassert(IPL_BIO) in the b_iodone handlers.


Revision tags: OPENBSD_3_1_BASE
# 1.30 02-Jan-2002 miod

Back out a few more uvm changes, especially wrt swap usage.
This unbreaks m68k m88k sparc and perhaps others, which eventually froze
when hitting swap.
Tested by various people on various platforms.
ok art@


# 1.29 19-Dec-2001 art

UBC was a disaster. It worked very good when it worked, but on some
machines or some configurations or in some phase of the moon (we actually
don't know when or why) files disappeared. Since we've not been able to
track down the problem in two weeks intense debugging and we need -current
to be stable, back out everything to a state it had before UBC.

We apologise for the inconvenience.


Revision tags: UBC_BASE
# 1.28 04-Dec-2001 art

branches: 1.28.2;
Yet another sync to NetBSD uvm.
Today we add a pmap argument to pmap_update() and allocate map entries for
kernel_map from kmem_map instead of using the static entries. This should
get rid of MAX_KMAPENT panics. Also some uvm_loan problems are fixed.


# 1.27 30-Nov-2001 csapuntz

Call buf_cleanout, which handles wakeups


# 1.26 29-Nov-2001 art

Correctly handle b_vp with bgetvp and brelvp in {get,put}pages.
Prevents panics caused by vnodes being recycled under our feet.


# 1.25 28-Nov-2001 art

Sync in more uvm from NetBSD. Mostly just cosmetic stuff.
Contains also support for page coloring.


# 1.24 28-Nov-2001 art

Sync in more uvm changes from NetBSD.
This time we're getting rid of KERN_* and VM_PAGER_* error codes and
use errnos instead.


# 1.23 27-Nov-2001 art

Merge in the unified buffer cache code as found in NetBSD 2001/03/10. The
code is written mostly by Chuck Silvers <chuq@chuq.com>/<chs@netbsd.org>.

Tested for the past few weeks by many developers, should be in a pretty stable
state, but will require optimizations and additional cleanups.


# 1.22 12-Nov-2001 art

Bring in more changes from NetBSD. Mostly pagedaemon improvements.


# 1.21 10-Nov-2001 art

Merge in some parts of the ubc work that has been done in NetBSD that are not
UBC, but prerequsites for it.

- Create a daemon that processes async I/O (swap and paging in the future)
requests that need processing in process context and that were processed
in the pagedaemon before.
- Convert some ugly ifdef DIAGNOSTIC code to less intrusive KASSERTs.
- misc other cleanups.


# 1.20 07-Nov-2001 art

Another sync of uvm to NetBSD. Just minor fiddling, no major changes.


# 1.19 07-Nov-2001 art

Add an alignment argument to uvm_map that specifies an alignment hint
for the virtual address.


# 1.18 06-Nov-2001 art

Move the last content from vm/ to uvm/
The only thing left in vm/ are just dumb wrappers.
vm/vm.h includes uvm/uvm_extern.h
vm/pmap.h includes uvm/uvm_pmap.h
vm/vm_page.h includes uvm/uvm_page.h


# 1.17 05-Nov-2001 art

Minor sync to NetBSD.


Revision tags: OPENBSD_3_0_BASE
# 1.16 20-Sep-2001 mpech

occured->occurred

idea from deraadt@ via NetBSD
millert@ ok


# 1.15 19-Sep-2001 mickey

merge vm/vm_kern.h into uvm/uvm_extern.h; art@ ok


# 1.14 11-Aug-2001 art

Various random fixes from NetBSD.
Including support for zeroing pages in the idle loop (not enabled yet).


# 1.13 06-Aug-2001 art

Add a new type voff_t (right now it's typedefed as off_t) used for offsets
into objects.

Gives the possibilty to mmap beyond the size of vaddr_t.

From NetBSD.


# 1.12 26-Jul-2001 art

Add support for disabling swap devices (swapctl -d).
Improve error handling on I/O errors to swap.
From NetBSD


# 1.11 25-Jul-2001 art

Change the pmap_enter interface to merge access_type and the wired boolean
and arbitrary flags into one argument.

One new flag is PMAP_CANFAIL that tells pmap_enter that it can fail if there
are not enough resources to satisfy the request. If this flag is not passed,
pmap_enter should panic as it should have done before this change (XXX - many
pmaps are still not doing that).

Only i386 and alpha implement CANFAIL for now.

Includes uvm updates from NetBSD.


# 1.10 18-Jul-2001 art

Get rid of the PMAP_NEW option by making it mandatory for all archs.
The archs that didn't have a proper PMAP_NEW now have a dummy implementation
with wrappers around the old functions.


# 1.9 08-Jun-2001 art

Change the paddr_t pmap_extract(struct pmap *, vaddr_t) interface to
boolean_t pmap_extract(struct pmap *, vaddr_t, paddr_t *).
Matches NetBSD. Tested by various people on various platforms.


Revision tags: OPENBSD_2_9_BASE
# 1.8 22-Mar-2001 smart

Sync style, typo, and comments a little closer to NetBSD. art@ ok


# 1.7 08-Mar-2001 smart

Replace thread_wakeup() with wakeup(). It is defined in vm_extern.h as a
wrapper, so this removes a dependence on the old VM system. From NetBSD.
art@ ok


# 1.6 29-Jan-2001 niklas

$OpenBSD$


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE
# 1.5 16-Mar-2000 art

Bring in some new UVM code from NetBSD (not current).

- Introduce a new type of map that are interrupt safe and never allow faults
in them. mb_map and kmem_map are made intrsafe.
- Add "access protection" to uvm_vslock (to be passed down to uvm_fault and
later to pmap_enter).
- madvise(2) now works.
- various cleanups.


Revision tags: OPENBSD_2_6_BASE SMP_BASE kame_19991208
# 1.4 03-Sep-1999 art

branches: 1.4.4;
Change the pmap_enter api to pass down an argument that indicates
the access type that caused this mapping. This is to simplify pmaps
with mod/ref emulation (none for the moment) and in some cases speed
up pmap_is_{referenced,modified}.
At the same time, clean up some mappings that had too high protection.

XXX - the access type is incorrect in old vm, it's only used by uvm and MD code.
The actual use of this in pmap_enter implementations is not in this commit.


# 1.3 23-Aug-1999 art

sync with NetBSD from 1999.05.24 (there is a reason for this date)
Mostly cleanups, but also a few improvements to pagedaemon for better
handling of low memory and/or low swap conditions.


Revision tags: OPENBSD_2_5_BASE
# 1.2 26-Feb-1999 art

add OpenBSD tags


# 1.1 26-Feb-1999 art

Import of uvm from NetBSD. Some local changes, some code disabled


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.71 17-Dec-2014 tedu

remove lock.h from uvm_extern.h. another holdover from the simpletonlock
era. fix uvm including c files to include lock.h or atomic.h as necessary.
ok deraadt


# 1.70 16-Nov-2014 deraadt

Replace a plethora of historical protection options with just
PROT_NONE, PROT_READ, PROT_WRITE, and PROT_EXEC from mman.h.
PROT_MASK is introduced as the one true way of extracting those bits.
Remove UVM_ADV_* wrapper, using the standard names.
ok doug guenther kettenis


# 1.69 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.68 11-Jul-2014 jsg

Chuck Cranor rescinded clauses in his license
on the 2nd of February 2011 in NetBSD.

http://marc.info/?l=netbsd-source-changes&m=129658899212732&w=2
http://marc.info/?l=netbsd-source-changes&m=129659095515558&w=2
http://marc.info/?l=netbsd-source-changes&m=129659157916514&w=2
http://marc.info/?l=netbsd-source-changes&m=129665962324372&w=2
http://marc.info/?l=netbsd-source-changes&m=129666033625342&w=2
http://marc.info/?l=netbsd-source-changes&m=129666052825545&w=2
http://marc.info/?l=netbsd-source-changes&m=129666922906480&w=2
http://marc.info/?l=netbsd-source-changes&m=129667725518082&w=2


# 1.67 09-May-2014 tedu

stop using B_AGE, it was effectively retired some time ago.


# 1.66 08-May-2014 kettenis

Fix some potential integer overflows caused by converting a page number into
an offset/size/address by shifting by PAGE_SHIFT. Make uvm_objwrire/unwire
use voff_t instead of off_t. The former is the right type here even if it is
equivalent to the latter.

Inspired by a somewhat similar changes in Bitrig.

ok deraadt@, guenther@


# 1.65 13-Apr-2014 tedu

compress code by turning four line comments into one line comments.
emphatic ok usual suspects, grudging ok miod


Revision tags: OPENBSD_5_5_BASE
# 1.64 02-Nov-2013 krw

No need to cast constants or simple variables to (daddr_t). Use
(u_int64_t) instead of (daddr_t) when casting a variable in an
expression passed to DL_SETDSIZE().

Change a variable counting open files from daddr_t to int64_t.

ok deraadt@ with the tweak to fix that pesky expression.


Revision tags: OPENBSD_5_4_BASE
# 1.63 11-Jun-2013 deraadt

final removal of daddr64_t. daddr_t has been 64 bit for a long enough
test period; i think 3 years ago the last bugs fell out.
ok otto beck others


# 1.62 30-May-2013 tedu

remove lots of comments about locking per beck's request


# 1.61 30-May-2013 tedu

remove simple_locks from uvm code. ok beck deraadt


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.60 03-Jul-2011 oga

Rip out and burn support for UVM_HIST.

The vm hackers don't use it, don't maintain it and have to look at it all the
time. About time this 800 lines of code hit /dev/null.

``never liked it'' tedu@. ariane@ was very happy when i told her i wrote
this diff.


# 1.59 15-Apr-2011 oga

for uvm_pager_dropcluster in the PG_RELEASED case we specifically unbusy the
page so that um_anfree will free it for us.

uvm_anfree does a pmap_page_protect(, VM_PROT_NONE) just before it frees the
page, so we don't need to do it here ourselves.

ok ariane@


# 1.58 15-Apr-2011 oga

move uvm_pageratop from uvm_pager.c local to a general uvm function
(uvm_atopg) and use it in uvm_km_doputpage to replace some handrolled
code. Shrinks the kernel a trivial amount.

ok beck@ and miod@ (who suggested i name it uvm_atopg not uvm_atop)


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.57 24-Jul-2010 kettenis

Don't sleep while holding the uvm_psel_lck mutex. Should fix "locking against
myself" panics that some people have seen over the last year-and-a-half.

Cherry picked from a more complex (and therefore scarier) diff from oga@.

ok tedu@, oga@


# 1.56 27-Jun-2010 oga

Kill another #ifdef UBC chunk that was annoying me while doing something
else.

ok thib@


Revision tags: OPENBSD_4_7_BASE
# 1.55 12-Feb-2010 tedu

introduce a uvm_km_valloc_try function that won't get a lower level lock
for use by the uvm pseg code. this is the path of least resistance until
we sort out how many of these functions we really need. problem found by mikeb
ok kettenis oga


# 1.54 22-Jul-2009 oga

Put the PG_RELEASED changes diff back in.

This has has been tested very very thoroughly on all archs we have
excepting 88k and 68k. Please see cvs log for the individual commit
messages.

ok beck@, thib@


Revision tags: OPENBSD_4_6_BASE
# 1.53 17-Jun-2009 oga

date based reversion of uvm to the 4th May.

More backouts in line with previous ones, this appears to bring us back to a
stable condition.

A machine forced to 64mb of ram cycled 10GB through swap with this diff
and is still running as I type this. Other tests by ariane@ and thib@
also seem to show that it's alright.

ok deraadt@, thib@, ariane@


# 1.52 16-Jun-2009 oga

Backout all the PG_RELEASED changes.

This is for the same reason as the earlier backouts, to avoid the bug
either added or exposed sometime around c2k9. This *should* be the last
one.

prompted by deraadt@

ok ariane@


# 1.51 23-May-2009 oga

More PG_RELEASED cleaning.

similar to the aobj.c changes, this one does vnodes. Vnodes are more
complex because they actaully have to sync to backing store. So firstly,
convert sync to sleep instead of setting released.

Now, for backing store, in the PGO_FREE case, if we set PG_RELEASED
*before* an async io, (nothing else will see it, the page is busy), then
we can ignore the page after the io is done. We could do something
similar for PGO_DEACTIVATE too, but that is another change. On error we
just clear the released flag, nothing else sets it for uobj pages other
than aiodoned.

ok thib@, beck@, ariane@


# 1.50 04-May-2009 oga

Instead of keeping two ints in the uvm structure specifically just to
sleep on them (and otherwise ignore them) sleep on the pointer to the
{aiodoned,pagedaemon}_proc members, and nuke the two extra words.

"no objections" art@, ok beck@.


# 1.49 06-Apr-2009 oga

Instead of doing splbio(); simple_lock(&uvm.aiodoned_lock); just replace
the simple lock with a real lock - a IPL_BIO mutex. While i'm here, make
the sleeping condition one hell of a lot simpler in the aio daemon.

some ideas from and ok art@.


# 1.48 25-Mar-2009 oga

Move all of the pseudo-inline functions in uvm into C files.

By pseudo-inline, I mean that if a certain macro was defined, they would
be inlined. However, no architecture defines that, and none has for a
very very long time. Therefore mainly this just makes the code a damned
sight easier to read. Some k&r -> ansi declarations while I'm in there.

"just commit it" art@. ok weingart@.


# 1.47 20-Mar-2009 oga

While working on some stuff in uvm I've gotten REALLY sick of reading
K&R function declarations, so switch them all over to ansi-style, in
accordance with the prophesy.

"go for it" art@


Revision tags: OPENBSD_4_5_BASE
# 1.46 27-Jan-2009 ariane

Simplify page-out/page-in map management; fix rare pager deadlock.

Ok: miod, tedu


# 1.45 24-Nov-2008 thib

garbage collect uvm_errno2vmerror();

ok miod@, art@


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.44 26-Nov-2007 miod

In uvm_aio_aiodone(), kill the variable-sized array on stack, and use a
fixed size array which size should match any buf; if a bogus buf is passed
to this function, the kernel will KASSERT instead of potentially running out
of stack and having an undefined behaviour.

ok deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.43 06-Jun-2007 deraadt

now that all partition size/offsets are potentially 64-bit, change the
type of all variables to daddr64_t. this includes the APIs for XXsize()
and XXdump(), all range checks inside bio drivers, internal variables
for disklabel handling, and even uvm's swap offsets. re-read numerous
times by otto, miod, krw, thib to look for errors


# 1.42 13-Apr-2007 art

While splitting flags and pqflags might have been a good idea in theory
to separate locking, on most modern machines this is not enough
since operations on short types touch other short types that share the
same word in memory.

Merge pg_flags and pqflags again and now use atomic operations to change
the flags. Also bump wire_count to an int and pg_version might go
int as well, just for alignment.

tested by many, many. ok miod@


# 1.41 04-Apr-2007 art

Mechanically rename the "flags" and "version" fields in struct vm_page
to "pg_flags" and "pg_version", so that they are a bit easier to work with.
Whoever uses generic names like this for a popular struct obviously doesn't
read much code.

Most architectures compile and there are no functionality changes.

deraadt@ ok ("if something fails to compile, we fix that by hand")


# 1.40 25-Mar-2007 art

remove KERN_SUCCESS and use 0 instead.
eyeballed by miod@ and pedro@


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.39 31-Jul-2006 mickey

fix uvmhist #2: args are always u_long so fix missing %d and %x and no %ll; no change for normal code


# 1.38 26-Jul-2006 mickey

fix fmts for UVMHIST_LOG() entries making it more useful on 64bit archs; miod@ ok


Revision tags: OPENBSD_3_8_BASE OPENBSD_3_9_BASE
# 1.37 26-Jul-2005 art

- Make a UVM_OBJ_IS_DEVICE macro.
- Use it to skip device mappings while dumping core.
- Ignore EFAULT errors while dumping core since they can happen
even for valid mappings. Just skip that part of the core file and
let it get automagically zero-filled.

This fixes the broken X core dumps that people have been seeing and also
fixes some other potential problems that could prevent core dumps (mmaps
beyond EOF, etc.).

tedu@ ok


# 1.36 24-May-2005 tedu

add a new field to vm_space and use it to track the number of anon
pages a process uses. this is now the userland "data size" value.
ok art deraadt tdeval. thanks testers.


Revision tags: OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE SMP_SYNC_A SMP_SYNC_B
# 1.35 23-Feb-2004 drahn

sync of pmap_update() calls with NetBSD. pmap_update is defined away on
all architectures but arm, where it is needed.


Revision tags: OPENBSD_3_4_BASE UBC_SYNC_A
# 1.34 29-Mar-2003 mickey

ubchist is not a fully cooked kadaver and though use the other well formed pdhist one until ubc gaets back. art@ ok


Revision tags: OPENBSD_3_3_BASE
# 1.33 29-Oct-2002 art

Since memory deallocation can't fail, remove the error return from
uvm_unmap, uvm_deallocate and a few other functions.
Simplifies some code and reduces diff to the UBC branch.


Revision tags: OPENBSD_3_2_BASE UBC_SYNC_B
# 1.32 24-May-2002 art

Make sure that b_iodone handlers are called at splbio (and splassert(IPL_BIO) in all known callers, just to make sure).


# 1.31 22-May-2002 art

splassert(IPL_BIO) in the b_iodone handlers.


Revision tags: OPENBSD_3_1_BASE
# 1.30 02-Jan-2002 miod

Back out a few more uvm changes, especially wrt swap usage.
This unbreaks m68k m88k sparc and perhaps others, which eventually froze
when hitting swap.
Tested by various people on various platforms.
ok art@


# 1.29 19-Dec-2001 art

UBC was a disaster. It worked very good when it worked, but on some
machines or some configurations or in some phase of the moon (we actually
don't know when or why) files disappeared. Since we've not been able to
track down the problem in two weeks intense debugging and we need -current
to be stable, back out everything to a state it had before UBC.

We apologise for the inconvenience.


Revision tags: UBC_BASE
# 1.28 04-Dec-2001 art

branches: 1.28.2;
Yet another sync to NetBSD uvm.
Today we add a pmap argument to pmap_update() and allocate map entries for
kernel_map from kmem_map instead of using the static entries. This should
get rid of MAX_KMAPENT panics. Also some uvm_loan problems are fixed.


# 1.27 30-Nov-2001 csapuntz

Call buf_cleanout, which handles wakeups


# 1.26 29-Nov-2001 art

Correctly handle b_vp with bgetvp and brelvp in {get,put}pages.
Prevents panics caused by vnodes being recycled under our feet.


# 1.25 28-Nov-2001 art

Sync in more uvm from NetBSD. Mostly just cosmetic stuff.
Contains also support for page coloring.


# 1.24 28-Nov-2001 art

Sync in more uvm changes from NetBSD.
This time we're getting rid of KERN_* and VM_PAGER_* error codes and
use errnos instead.


# 1.23 27-Nov-2001 art

Merge in the unified buffer cache code as found in NetBSD 2001/03/10. The
code is written mostly by Chuck Silvers <chuq@chuq.com>/<chs@netbsd.org>.

Tested for the past few weeks by many developers, should be in a pretty stable
state, but will require optimizations and additional cleanups.


# 1.22 12-Nov-2001 art

Bring in more changes from NetBSD. Mostly pagedaemon improvements.


# 1.21 10-Nov-2001 art

Merge in some parts of the ubc work that has been done in NetBSD that are not
UBC, but prerequsites for it.

- Create a daemon that processes async I/O (swap and paging in the future)
requests that need processing in process context and that were processed
in the pagedaemon before.
- Convert some ugly ifdef DIAGNOSTIC code to less intrusive KASSERTs.
- misc other cleanups.


# 1.20 07-Nov-2001 art

Another sync of uvm to NetBSD. Just minor fiddling, no major changes.


# 1.19 07-Nov-2001 art

Add an alignment argument to uvm_map that specifies an alignment hint
for the virtual address.


# 1.18 06-Nov-2001 art

Move the last content from vm/ to uvm/
The only thing left in vm/ are just dumb wrappers.
vm/vm.h includes uvm/uvm_extern.h
vm/pmap.h includes uvm/uvm_pmap.h
vm/vm_page.h includes uvm/uvm_page.h


# 1.17 05-Nov-2001 art

Minor sync to NetBSD.


Revision tags: OPENBSD_3_0_BASE
# 1.16 20-Sep-2001 mpech

occured->occurred

idea from deraadt@ via NetBSD
millert@ ok


# 1.15 19-Sep-2001 mickey

merge vm/vm_kern.h into uvm/uvm_extern.h; art@ ok


# 1.14 11-Aug-2001 art

Various random fixes from NetBSD.
Including support for zeroing pages in the idle loop (not enabled yet).


# 1.13 06-Aug-2001 art

Add a new type voff_t (right now it's typedefed as off_t) used for offsets
into objects.

Gives the possibilty to mmap beyond the size of vaddr_t.

From NetBSD.


# 1.12 26-Jul-2001 art

Add support for disabling swap devices (swapctl -d).
Improve error handling on I/O errors to swap.
From NetBSD


# 1.11 25-Jul-2001 art

Change the pmap_enter interface to merge access_type and the wired boolean
and arbitrary flags into one argument.

One new flag is PMAP_CANFAIL that tells pmap_enter that it can fail if there
are not enough resources to satisfy the request. If this flag is not passed,
pmap_enter should panic as it should have done before this change (XXX - many
pmaps are still not doing that).

Only i386 and alpha implement CANFAIL for now.

Includes uvm updates from NetBSD.


# 1.10 18-Jul-2001 art

Get rid of the PMAP_NEW option by making it mandatory for all archs.
The archs that didn't have a proper PMAP_NEW now have a dummy implementation
with wrappers around the old functions.


# 1.9 08-Jun-2001 art

Change the paddr_t pmap_extract(struct pmap *, vaddr_t) interface to
boolean_t pmap_extract(struct pmap *, vaddr_t, paddr_t *).
Matches NetBSD. Tested by various people on various platforms.


Revision tags: OPENBSD_2_9_BASE
# 1.8 22-Mar-2001 smart

Sync style, typo, and comments a little closer to NetBSD. art@ ok


# 1.7 08-Mar-2001 smart

Replace thread_wakeup() with wakeup(). It is defined in vm_extern.h as a
wrapper, so this removes a dependence on the old VM system. From NetBSD.
art@ ok


# 1.6 29-Jan-2001 niklas

$OpenBSD$


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE
# 1.5 16-Mar-2000 art

Bring in some new UVM code from NetBSD (not current).

- Introduce a new type of map that are interrupt safe and never allow faults
in them. mb_map and kmem_map are made intrsafe.
- Add "access protection" to uvm_vslock (to be passed down to uvm_fault and
later to pmap_enter).
- madvise(2) now works.
- various cleanups.


Revision tags: OPENBSD_2_6_BASE SMP_BASE kame_19991208
# 1.4 03-Sep-1999 art

branches: 1.4.4;
Change the pmap_enter api to pass down an argument that indicates
the access type that caused this mapping. This is to simplify pmaps
with mod/ref emulation (none for the moment) and in some cases speed
up pmap_is_{referenced,modified}.
At the same time, clean up some mappings that had too high protection.

XXX - the access type is incorrect in old vm, it's only used by uvm and MD code.
The actual use of this in pmap_enter implementations is not in this commit.


# 1.3 23-Aug-1999 art

sync with NetBSD from 1999.05.24 (there is a reason for this date)
Mostly cleanups, but also a few improvements to pagedaemon for better
handling of low memory and/or low swap conditions.


Revision tags: OPENBSD_2_5_BASE
# 1.2 26-Feb-1999 art

add OpenBSD tags


# 1.1 26-Feb-1999 art

Import of uvm from NetBSD. Some local changes, some code disabled