History log of /openbsd-current/sys/uvm/uvm_anon.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.58 06-Apr-2024 mpi

Prevent accounting bug when an anon w/ swap slot is passed to uvm_anon_release()

uvm_anon_release() is always called for anon that have an associated page so
decrementing `uvmexp.swpgonly' is incorrect. This happened because the page
was cleared before calling uvm_anfree().

Reported by many including mvs@, miod@ and robert@

ok kettenis@, miod@


Revision tags: OPENBSD_7_5_BASE
# 1.57 27-Oct-2023 mpi

Do not decrement the swap counter if the anon is associated to a "bad" slot.

When such anon is freed its content is obviously not living in swap.

ok miod@


Revision tags: OPENBSD_7_4_BASE
# 1.56 02-Sep-2023 mpi

Zap anon pages mappings in uvm_anon_release() instead of in the fault handler.

This makes all code paths deactivating or freeing anons consistent.

No objection from the usual suspects.


# 1.55 11-Apr-2023 jsg

fix double words in comments
feedback and ok jmc@ miod, ok millert@


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE OPENBSD_7_1_BASE OPENBSD_7_2_BASE OPENBSD_7_3_BASE
# 1.54 26-Mar-2021 mpi

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

No functional change.

ok mlarkin@


# 1.53 20-Mar-2021 mpi

Sync some comments in order to reduce the difference with NetBSD.

No functionnal change.

ok kettenis@


# 1.52 04-Mar-2021 mpi

Modify `uvmexp.swpgonly' atomically, required for uvm_fault() w/o KERNEL_LOCK()

ok kettenis@


# 1.51 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.50 24-Nov-2020 mpi

Grab the `pageqlock' before calling uvm_pageclean() as intended.

Document which global data structures require this lock and add some
asserts where the lock should be held.

Some code paths are still incorrect and should be revisited.

ok jmatthew@


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.49 04-Jan-2020 beck

Add uvm_anfree_list() to free anons as a list of pages. Use this in
the amap code to free pages as a list instead of one at a time to
allow for more efficient freeing.

Most of the work done at elk lakes, with testing by me and mlarkin
and kettenis. Speeds up a test program which zeros a big pile of memory
and then exits considerably.

ok kettenis@


Revision tags: 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.48 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.47 17-Jun-2016 dlg

pool_setipl on all uvm pools.

ok kettenis@ visa@


# 1.46 08-May-2016 stefan

Wait for RAM in uvm_fault when allocating uvm structures fails

Only fail hard when running out of swap space also, as suggested by
kettenis@

While there, let amap_add() return a success status and handle
amap_add() errors in uvm_fault() similar to other out of RAM situations.
These bits are needed for further amap reorganization diffs.

lots of feedback and ok kettenis@


# 1.45 29-Mar-2016 chl

Remove dead assignments and now unused variables.

Found by LLVM/Clang Static Analyzer.

ok mpi@ stefan@


Revision tags: OPENBSD_5_9_BASE
# 1.44 21-Aug-2015 visa

Remove the unused loan_count field and the related uvm logic. Most of
the page loaning code is already in the Attic.

ok kettenis@, beck@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.43 23-Dec-2014 tedu

convert pool_init nointr to waitok


# 1.42 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.41 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.40 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.39 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.38 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_4_BASE OPENBSD_5_5_BASE
# 1.37 30-May-2013 tedu

remove lots of comments about locking per beck's request


# 1.36 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.35 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.


Revision tags: OPENBSD_4_6_BASE OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.34 16-Jun-2009 oga

date based reversion of uvm to the 4th May.

We still have no idea why this stops the crashes. but it does.

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.33 16-Jun-2009 oga

Backout all changes to uvm after pmemrange (which will be backed out
separately).

a change at or just before the hackathon has either exposed or added a
very very nasty memory corruption bug that is giving us hell right now.
So in the interest of kernel stability these diffs are being backed out
until such a time as that corruption bug has been found and squashed,
then the ones that are proven good may slowly return.

a quick hitlist of the main commits this backs out:

mine:
uvm_objwire
the lock change in uvm_swap.c
using trees for uvm objects instead of the hash
removing the pgo_releasepg callback.

art@'s:
putting pmap_page_protect(VM_PROT_NONE) in uvm_pagedeactivate() since
all callers called that just prior anyway.

ok beck@, ariane@.

prompted by deraadt@.


# 1.32 06-Jun-2009 art

Since all callers of uvm_pagedeactivate did pmap_page_protect(.., VM_PROT_NONE)
just move that into uvm_pagedeactivate.

oga@ ok


# 1.31 30-May-2009 oga

in the (currently unused) loaning case for uvm_anfree, zero out anon->an_page
so we won't hit the kassert a little bit below it.

"obviously better than what is there now" beck@


# 1.30 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_4_BASE OPENBSD_4_5_BASE
# 1.29 10-Apr-2008 miod

Correctly amount swap usage for anons, from NetBSD via PR 5772.


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE
# 1.28 18-Jun-2007 pedro

Bring back Mickey's UVM anon change. Testing by thib@, beck@ and
ckuethe@ for a while. Okay beck@, "it is good timing" deraadt@.


# 1.27 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.26 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")


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.25 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.24 26-Jul-2006 mickey

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


# 1.23 13-Jul-2006 deraadt

Back out the anon change. Apparently it was tested by a few, but most of
us did not see it or get a chance to test it before it was commited. It
broke cvs, in the ami driver, making it not succeed at seeing it's devices.


# 1.22 21-Jun-2006 mickey

from netbsd: make anons dynamically allocated from pool.
this results in lesse kva waste due to static preallocation of those
for every phys page and also every swap page.
tested by beck krw miod


Revision tags: OPENBSD_3_1_BASE OPENBSD_3_2_BASE OPENBSD_3_3_BASE OPENBSD_3_4_BASE OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE OPENBSD_3_8_BASE OPENBSD_3_9_BASE SMP_SYNC_A SMP_SYNC_B UBC_SYNC_A UBC_SYNC_B
# 1.21 14-Mar-2002 millert

First round of __P removal in sys


# 1.20 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.19 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.18 28-Nov-2001 art

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


# 1.17 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.16 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.15 11-Nov-2001 art

Sync in more stuff from NetBSD.


# 1.14 07-Nov-2001 art

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


# 1.13 06-Nov-2001 art

More sync to NetBSD.
- Use malloc/free instead of MALLOC/FREE for variable sized allocations.
- Move the memory inheritance code to sys/mman.h and rename from VM_* to MAP_*
- various cleanups and simplifications.


# 1.12 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.11 05-Nov-2001 art

Minor sync to NetBSD.


Revision tags: OPENBSD_3_0_BASE
# 1.10 19-Sep-2001 mickey

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


# 1.9 26-Jul-2001 art

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


# 1.8 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.7 23-Jun-2001 smart

Sync with NetBSD 19990911 (just before PMAP_NEW was required)
- thread_sleep_msg() -> uvm_sleep()
- initialize reference count lock in uvm_anon_{init,add}()
- add uao_flush()
- replace boolean 'islocked' with 'lockflags'
- in uvm_fault() change FALSE to TRUE to in 'wide' fault handling
- get rid of uvm_km_get()
- various bug fixes


Revision tags: OPENBSD_2_9_BASE
# 1.6 29-Jan-2001 niklas

$OpenBSD$


Revision tags: OPENBSD_2_8_BASE
# 1.5 07-Sep-2000 art

Convert bzero to memset(X, 0..) and bcopy to memcpy.
This is to match (make diffs smaller) the code in NetBSD.
new gcc inlines those functions, so this could also be a performance win.


Revision tags: OPENBSD_2_7_BASE
# 1.4 15-Mar-2000 art

Fix the NetBSD id strings.


Revision tags: OPENBSD_2_6_BASE SMP_BASE kame_19991208
# 1.3 23-Aug-1999 art

branches: 1.3.4;
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.57 27-Oct-2023 mpi

Do not decrement the swap counter if the anon is associated to a "bad" slot.

When such anon is freed its content is obviously not living in swap.

ok miod@


Revision tags: OPENBSD_7_4_BASE
# 1.56 02-Sep-2023 mpi

Zap anon pages mappings in uvm_anon_release() instead of in the fault handler.

This makes all code paths deactivating or freeing anons consistent.

No objection from the usual suspects.


# 1.55 11-Apr-2023 jsg

fix double words in comments
feedback and ok jmc@ miod, ok millert@


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE OPENBSD_7_1_BASE OPENBSD_7_2_BASE OPENBSD_7_3_BASE
# 1.54 26-Mar-2021 mpi

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

No functional change.

ok mlarkin@


# 1.53 20-Mar-2021 mpi

Sync some comments in order to reduce the difference with NetBSD.

No functionnal change.

ok kettenis@


# 1.52 04-Mar-2021 mpi

Modify `uvmexp.swpgonly' atomically, required for uvm_fault() w/o KERNEL_LOCK()

ok kettenis@


# 1.51 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.50 24-Nov-2020 mpi

Grab the `pageqlock' before calling uvm_pageclean() as intended.

Document which global data structures require this lock and add some
asserts where the lock should be held.

Some code paths are still incorrect and should be revisited.

ok jmatthew@


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.49 04-Jan-2020 beck

Add uvm_anfree_list() to free anons as a list of pages. Use this in
the amap code to free pages as a list instead of one at a time to
allow for more efficient freeing.

Most of the work done at elk lakes, with testing by me and mlarkin
and kettenis. Speeds up a test program which zeros a big pile of memory
and then exits considerably.

ok kettenis@


Revision tags: 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.48 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.47 17-Jun-2016 dlg

pool_setipl on all uvm pools.

ok kettenis@ visa@


# 1.46 08-May-2016 stefan

Wait for RAM in uvm_fault when allocating uvm structures fails

Only fail hard when running out of swap space also, as suggested by
kettenis@

While there, let amap_add() return a success status and handle
amap_add() errors in uvm_fault() similar to other out of RAM situations.
These bits are needed for further amap reorganization diffs.

lots of feedback and ok kettenis@


# 1.45 29-Mar-2016 chl

Remove dead assignments and now unused variables.

Found by LLVM/Clang Static Analyzer.

ok mpi@ stefan@


Revision tags: OPENBSD_5_9_BASE
# 1.44 21-Aug-2015 visa

Remove the unused loan_count field and the related uvm logic. Most of
the page loaning code is already in the Attic.

ok kettenis@, beck@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.43 23-Dec-2014 tedu

convert pool_init nointr to waitok


# 1.42 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.41 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.40 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.39 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.38 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_4_BASE OPENBSD_5_5_BASE
# 1.37 30-May-2013 tedu

remove lots of comments about locking per beck's request


# 1.36 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.35 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.


Revision tags: OPENBSD_4_6_BASE OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.34 16-Jun-2009 oga

date based reversion of uvm to the 4th May.

We still have no idea why this stops the crashes. but it does.

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.33 16-Jun-2009 oga

Backout all changes to uvm after pmemrange (which will be backed out
separately).

a change at or just before the hackathon has either exposed or added a
very very nasty memory corruption bug that is giving us hell right now.
So in the interest of kernel stability these diffs are being backed out
until such a time as that corruption bug has been found and squashed,
then the ones that are proven good may slowly return.

a quick hitlist of the main commits this backs out:

mine:
uvm_objwire
the lock change in uvm_swap.c
using trees for uvm objects instead of the hash
removing the pgo_releasepg callback.

art@'s:
putting pmap_page_protect(VM_PROT_NONE) in uvm_pagedeactivate() since
all callers called that just prior anyway.

ok beck@, ariane@.

prompted by deraadt@.


# 1.32 06-Jun-2009 art

Since all callers of uvm_pagedeactivate did pmap_page_protect(.., VM_PROT_NONE)
just move that into uvm_pagedeactivate.

oga@ ok


# 1.31 30-May-2009 oga

in the (currently unused) loaning case for uvm_anfree, zero out anon->an_page
so we won't hit the kassert a little bit below it.

"obviously better than what is there now" beck@


# 1.30 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_4_BASE OPENBSD_4_5_BASE
# 1.29 10-Apr-2008 miod

Correctly amount swap usage for anons, from NetBSD via PR 5772.


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE
# 1.28 18-Jun-2007 pedro

Bring back Mickey's UVM anon change. Testing by thib@, beck@ and
ckuethe@ for a while. Okay beck@, "it is good timing" deraadt@.


# 1.27 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.26 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")


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.25 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.24 26-Jul-2006 mickey

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


# 1.23 13-Jul-2006 deraadt

Back out the anon change. Apparently it was tested by a few, but most of
us did not see it or get a chance to test it before it was commited. It
broke cvs, in the ami driver, making it not succeed at seeing it's devices.


# 1.22 21-Jun-2006 mickey

from netbsd: make anons dynamically allocated from pool.
this results in lesse kva waste due to static preallocation of those
for every phys page and also every swap page.
tested by beck krw miod


Revision tags: OPENBSD_3_1_BASE OPENBSD_3_2_BASE OPENBSD_3_3_BASE OPENBSD_3_4_BASE OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE OPENBSD_3_8_BASE OPENBSD_3_9_BASE SMP_SYNC_A SMP_SYNC_B UBC_SYNC_A UBC_SYNC_B
# 1.21 14-Mar-2002 millert

First round of __P removal in sys


# 1.20 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.19 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.18 28-Nov-2001 art

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


# 1.17 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.16 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.15 11-Nov-2001 art

Sync in more stuff from NetBSD.


# 1.14 07-Nov-2001 art

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


# 1.13 06-Nov-2001 art

More sync to NetBSD.
- Use malloc/free instead of MALLOC/FREE for variable sized allocations.
- Move the memory inheritance code to sys/mman.h and rename from VM_* to MAP_*
- various cleanups and simplifications.


# 1.12 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.11 05-Nov-2001 art

Minor sync to NetBSD.


Revision tags: OPENBSD_3_0_BASE
# 1.10 19-Sep-2001 mickey

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


# 1.9 26-Jul-2001 art

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


# 1.8 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.7 23-Jun-2001 smart

Sync with NetBSD 19990911 (just before PMAP_NEW was required)
- thread_sleep_msg() -> uvm_sleep()
- initialize reference count lock in uvm_anon_{init,add}()
- add uao_flush()
- replace boolean 'islocked' with 'lockflags'
- in uvm_fault() change FALSE to TRUE to in 'wide' fault handling
- get rid of uvm_km_get()
- various bug fixes


Revision tags: OPENBSD_2_9_BASE
# 1.6 29-Jan-2001 niklas

$OpenBSD$


Revision tags: OPENBSD_2_8_BASE
# 1.5 07-Sep-2000 art

Convert bzero to memset(X, 0..) and bcopy to memcpy.
This is to match (make diffs smaller) the code in NetBSD.
new gcc inlines those functions, so this could also be a performance win.


Revision tags: OPENBSD_2_7_BASE
# 1.4 15-Mar-2000 art

Fix the NetBSD id strings.


Revision tags: OPENBSD_2_6_BASE SMP_BASE kame_19991208
# 1.3 23-Aug-1999 art

branches: 1.3.4;
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.56 02-Sep-2023 mpi

Zap anon pages mappings in uvm_anon_release() instead of in the fault handler.

This makes all code paths deactivating or freeing anons consistent.

No objection from the usual suspects.


# 1.55 11-Apr-2023 jsg

fix double words in comments
feedback and ok jmc@ miod, ok millert@


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE OPENBSD_7_1_BASE OPENBSD_7_2_BASE OPENBSD_7_3_BASE
# 1.54 26-Mar-2021 mpi

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

No functional change.

ok mlarkin@


# 1.53 20-Mar-2021 mpi

Sync some comments in order to reduce the difference with NetBSD.

No functionnal change.

ok kettenis@


# 1.52 04-Mar-2021 mpi

Modify `uvmexp.swpgonly' atomically, required for uvm_fault() w/o KERNEL_LOCK()

ok kettenis@


# 1.51 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.50 24-Nov-2020 mpi

Grab the `pageqlock' before calling uvm_pageclean() as intended.

Document which global data structures require this lock and add some
asserts where the lock should be held.

Some code paths are still incorrect and should be revisited.

ok jmatthew@


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.49 04-Jan-2020 beck

Add uvm_anfree_list() to free anons as a list of pages. Use this in
the amap code to free pages as a list instead of one at a time to
allow for more efficient freeing.

Most of the work done at elk lakes, with testing by me and mlarkin
and kettenis. Speeds up a test program which zeros a big pile of memory
and then exits considerably.

ok kettenis@


Revision tags: 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.48 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.47 17-Jun-2016 dlg

pool_setipl on all uvm pools.

ok kettenis@ visa@


# 1.46 08-May-2016 stefan

Wait for RAM in uvm_fault when allocating uvm structures fails

Only fail hard when running out of swap space also, as suggested by
kettenis@

While there, let amap_add() return a success status and handle
amap_add() errors in uvm_fault() similar to other out of RAM situations.
These bits are needed for further amap reorganization diffs.

lots of feedback and ok kettenis@


# 1.45 29-Mar-2016 chl

Remove dead assignments and now unused variables.

Found by LLVM/Clang Static Analyzer.

ok mpi@ stefan@


Revision tags: OPENBSD_5_9_BASE
# 1.44 21-Aug-2015 visa

Remove the unused loan_count field and the related uvm logic. Most of
the page loaning code is already in the Attic.

ok kettenis@, beck@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.43 23-Dec-2014 tedu

convert pool_init nointr to waitok


# 1.42 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.41 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.40 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.39 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.38 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_4_BASE OPENBSD_5_5_BASE
# 1.37 30-May-2013 tedu

remove lots of comments about locking per beck's request


# 1.36 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.35 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.


Revision tags: OPENBSD_4_6_BASE OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.34 16-Jun-2009 oga

date based reversion of uvm to the 4th May.

We still have no idea why this stops the crashes. but it does.

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.33 16-Jun-2009 oga

Backout all changes to uvm after pmemrange (which will be backed out
separately).

a change at or just before the hackathon has either exposed or added a
very very nasty memory corruption bug that is giving us hell right now.
So in the interest of kernel stability these diffs are being backed out
until such a time as that corruption bug has been found and squashed,
then the ones that are proven good may slowly return.

a quick hitlist of the main commits this backs out:

mine:
uvm_objwire
the lock change in uvm_swap.c
using trees for uvm objects instead of the hash
removing the pgo_releasepg callback.

art@'s:
putting pmap_page_protect(VM_PROT_NONE) in uvm_pagedeactivate() since
all callers called that just prior anyway.

ok beck@, ariane@.

prompted by deraadt@.


# 1.32 06-Jun-2009 art

Since all callers of uvm_pagedeactivate did pmap_page_protect(.., VM_PROT_NONE)
just move that into uvm_pagedeactivate.

oga@ ok


# 1.31 30-May-2009 oga

in the (currently unused) loaning case for uvm_anfree, zero out anon->an_page
so we won't hit the kassert a little bit below it.

"obviously better than what is there now" beck@


# 1.30 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_4_BASE OPENBSD_4_5_BASE
# 1.29 10-Apr-2008 miod

Correctly amount swap usage for anons, from NetBSD via PR 5772.


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE
# 1.28 18-Jun-2007 pedro

Bring back Mickey's UVM anon change. Testing by thib@, beck@ and
ckuethe@ for a while. Okay beck@, "it is good timing" deraadt@.


# 1.27 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.26 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")


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.25 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.24 26-Jul-2006 mickey

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


# 1.23 13-Jul-2006 deraadt

Back out the anon change. Apparently it was tested by a few, but most of
us did not see it or get a chance to test it before it was commited. It
broke cvs, in the ami driver, making it not succeed at seeing it's devices.


# 1.22 21-Jun-2006 mickey

from netbsd: make anons dynamically allocated from pool.
this results in lesse kva waste due to static preallocation of those
for every phys page and also every swap page.
tested by beck krw miod


Revision tags: OPENBSD_3_1_BASE OPENBSD_3_2_BASE OPENBSD_3_3_BASE OPENBSD_3_4_BASE OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE OPENBSD_3_8_BASE OPENBSD_3_9_BASE SMP_SYNC_A SMP_SYNC_B UBC_SYNC_A UBC_SYNC_B
# 1.21 14-Mar-2002 millert

First round of __P removal in sys


# 1.20 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.19 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.18 28-Nov-2001 art

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


# 1.17 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.16 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.15 11-Nov-2001 art

Sync in more stuff from NetBSD.


# 1.14 07-Nov-2001 art

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


# 1.13 06-Nov-2001 art

More sync to NetBSD.
- Use malloc/free instead of MALLOC/FREE for variable sized allocations.
- Move the memory inheritance code to sys/mman.h and rename from VM_* to MAP_*
- various cleanups and simplifications.


# 1.12 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.11 05-Nov-2001 art

Minor sync to NetBSD.


Revision tags: OPENBSD_3_0_BASE
# 1.10 19-Sep-2001 mickey

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


# 1.9 26-Jul-2001 art

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


# 1.8 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.7 23-Jun-2001 smart

Sync with NetBSD 19990911 (just before PMAP_NEW was required)
- thread_sleep_msg() -> uvm_sleep()
- initialize reference count lock in uvm_anon_{init,add}()
- add uao_flush()
- replace boolean 'islocked' with 'lockflags'
- in uvm_fault() change FALSE to TRUE to in 'wide' fault handling
- get rid of uvm_km_get()
- various bug fixes


Revision tags: OPENBSD_2_9_BASE
# 1.6 29-Jan-2001 niklas

$OpenBSD$


Revision tags: OPENBSD_2_8_BASE
# 1.5 07-Sep-2000 art

Convert bzero to memset(X, 0..) and bcopy to memcpy.
This is to match (make diffs smaller) the code in NetBSD.
new gcc inlines those functions, so this could also be a performance win.


Revision tags: OPENBSD_2_7_BASE
# 1.4 15-Mar-2000 art

Fix the NetBSD id strings.


Revision tags: OPENBSD_2_6_BASE SMP_BASE kame_19991208
# 1.3 23-Aug-1999 art

branches: 1.3.4;
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.55 11-Apr-2023 jsg

fix double words in comments
feedback and ok jmc@ miod, ok millert@


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE OPENBSD_7_1_BASE OPENBSD_7_2_BASE OPENBSD_7_3_BASE
# 1.54 26-Mar-2021 mpi

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

No functional change.

ok mlarkin@


# 1.53 20-Mar-2021 mpi

Sync some comments in order to reduce the difference with NetBSD.

No functionnal change.

ok kettenis@


# 1.52 04-Mar-2021 mpi

Modify `uvmexp.swpgonly' atomically, required for uvm_fault() w/o KERNEL_LOCK()

ok kettenis@


# 1.51 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.50 24-Nov-2020 mpi

Grab the `pageqlock' before calling uvm_pageclean() as intended.

Document which global data structures require this lock and add some
asserts where the lock should be held.

Some code paths are still incorrect and should be revisited.

ok jmatthew@


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.49 04-Jan-2020 beck

Add uvm_anfree_list() to free anons as a list of pages. Use this in
the amap code to free pages as a list instead of one at a time to
allow for more efficient freeing.

Most of the work done at elk lakes, with testing by me and mlarkin
and kettenis. Speeds up a test program which zeros a big pile of memory
and then exits considerably.

ok kettenis@


Revision tags: 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.48 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.47 17-Jun-2016 dlg

pool_setipl on all uvm pools.

ok kettenis@ visa@


# 1.46 08-May-2016 stefan

Wait for RAM in uvm_fault when allocating uvm structures fails

Only fail hard when running out of swap space also, as suggested by
kettenis@

While there, let amap_add() return a success status and handle
amap_add() errors in uvm_fault() similar to other out of RAM situations.
These bits are needed for further amap reorganization diffs.

lots of feedback and ok kettenis@


# 1.45 29-Mar-2016 chl

Remove dead assignments and now unused variables.

Found by LLVM/Clang Static Analyzer.

ok mpi@ stefan@


Revision tags: OPENBSD_5_9_BASE
# 1.44 21-Aug-2015 visa

Remove the unused loan_count field and the related uvm logic. Most of
the page loaning code is already in the Attic.

ok kettenis@, beck@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.43 23-Dec-2014 tedu

convert pool_init nointr to waitok


# 1.42 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.41 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.40 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.39 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.38 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_4_BASE OPENBSD_5_5_BASE
# 1.37 30-May-2013 tedu

remove lots of comments about locking per beck's request


# 1.36 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.35 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.


Revision tags: OPENBSD_4_6_BASE OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.34 16-Jun-2009 oga

date based reversion of uvm to the 4th May.

We still have no idea why this stops the crashes. but it does.

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.33 16-Jun-2009 oga

Backout all changes to uvm after pmemrange (which will be backed out
separately).

a change at or just before the hackathon has either exposed or added a
very very nasty memory corruption bug that is giving us hell right now.
So in the interest of kernel stability these diffs are being backed out
until such a time as that corruption bug has been found and squashed,
then the ones that are proven good may slowly return.

a quick hitlist of the main commits this backs out:

mine:
uvm_objwire
the lock change in uvm_swap.c
using trees for uvm objects instead of the hash
removing the pgo_releasepg callback.

art@'s:
putting pmap_page_protect(VM_PROT_NONE) in uvm_pagedeactivate() since
all callers called that just prior anyway.

ok beck@, ariane@.

prompted by deraadt@.


# 1.32 06-Jun-2009 art

Since all callers of uvm_pagedeactivate did pmap_page_protect(.., VM_PROT_NONE)
just move that into uvm_pagedeactivate.

oga@ ok


# 1.31 30-May-2009 oga

in the (currently unused) loaning case for uvm_anfree, zero out anon->an_page
so we won't hit the kassert a little bit below it.

"obviously better than what is there now" beck@


# 1.30 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_4_BASE OPENBSD_4_5_BASE
# 1.29 10-Apr-2008 miod

Correctly amount swap usage for anons, from NetBSD via PR 5772.


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE
# 1.28 18-Jun-2007 pedro

Bring back Mickey's UVM anon change. Testing by thib@, beck@ and
ckuethe@ for a while. Okay beck@, "it is good timing" deraadt@.


# 1.27 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.26 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")


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.25 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.24 26-Jul-2006 mickey

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


# 1.23 13-Jul-2006 deraadt

Back out the anon change. Apparently it was tested by a few, but most of
us did not see it or get a chance to test it before it was commited. It
broke cvs, in the ami driver, making it not succeed at seeing it's devices.


# 1.22 21-Jun-2006 mickey

from netbsd: make anons dynamically allocated from pool.
this results in lesse kva waste due to static preallocation of those
for every phys page and also every swap page.
tested by beck krw miod


Revision tags: OPENBSD_3_1_BASE OPENBSD_3_2_BASE OPENBSD_3_3_BASE OPENBSD_3_4_BASE OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE OPENBSD_3_8_BASE OPENBSD_3_9_BASE SMP_SYNC_A SMP_SYNC_B UBC_SYNC_A UBC_SYNC_B
# 1.21 14-Mar-2002 millert

First round of __P removal in sys


# 1.20 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.19 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.18 28-Nov-2001 art

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


# 1.17 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.16 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.15 11-Nov-2001 art

Sync in more stuff from NetBSD.


# 1.14 07-Nov-2001 art

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


# 1.13 06-Nov-2001 art

More sync to NetBSD.
- Use malloc/free instead of MALLOC/FREE for variable sized allocations.
- Move the memory inheritance code to sys/mman.h and rename from VM_* to MAP_*
- various cleanups and simplifications.


# 1.12 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.11 05-Nov-2001 art

Minor sync to NetBSD.


Revision tags: OPENBSD_3_0_BASE
# 1.10 19-Sep-2001 mickey

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


# 1.9 26-Jul-2001 art

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


# 1.8 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.7 23-Jun-2001 smart

Sync with NetBSD 19990911 (just before PMAP_NEW was required)
- thread_sleep_msg() -> uvm_sleep()
- initialize reference count lock in uvm_anon_{init,add}()
- add uao_flush()
- replace boolean 'islocked' with 'lockflags'
- in uvm_fault() change FALSE to TRUE to in 'wide' fault handling
- get rid of uvm_km_get()
- various bug fixes


Revision tags: OPENBSD_2_9_BASE
# 1.6 29-Jan-2001 niklas

$OpenBSD$


Revision tags: OPENBSD_2_8_BASE
# 1.5 07-Sep-2000 art

Convert bzero to memset(X, 0..) and bcopy to memcpy.
This is to match (make diffs smaller) the code in NetBSD.
new gcc inlines those functions, so this could also be a performance win.


Revision tags: OPENBSD_2_7_BASE
# 1.4 15-Mar-2000 art

Fix the NetBSD id strings.


Revision tags: OPENBSD_2_6_BASE SMP_BASE kame_19991208
# 1.3 23-Aug-1999 art

branches: 1.3.4;
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.54 26-Mar-2021 mpi

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

No functional change.

ok mlarkin@


# 1.53 20-Mar-2021 mpi

Sync some comments in order to reduce the difference with NetBSD.

No functionnal change.

ok kettenis@


# 1.52 04-Mar-2021 mpi

Modify `uvmexp.swpgonly' atomically, required for uvm_fault() w/o KERNEL_LOCK()

ok kettenis@


# 1.51 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.50 24-Nov-2020 mpi

Grab the `pageqlock' before calling uvm_pageclean() as intended.

Document which global data structures require this lock and add some
asserts where the lock should be held.

Some code paths are still incorrect and should be revisited.

ok jmatthew@


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.49 04-Jan-2020 beck

Add uvm_anfree_list() to free anons as a list of pages. Use this in
the amap code to free pages as a list instead of one at a time to
allow for more efficient freeing.

Most of the work done at elk lakes, with testing by me and mlarkin
and kettenis. Speeds up a test program which zeros a big pile of memory
and then exits considerably.

ok kettenis@


Revision tags: 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.48 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.47 17-Jun-2016 dlg

pool_setipl on all uvm pools.

ok kettenis@ visa@


# 1.46 08-May-2016 stefan

Wait for RAM in uvm_fault when allocating uvm structures fails

Only fail hard when running out of swap space also, as suggested by
kettenis@

While there, let amap_add() return a success status and handle
amap_add() errors in uvm_fault() similar to other out of RAM situations.
These bits are needed for further amap reorganization diffs.

lots of feedback and ok kettenis@


# 1.45 29-Mar-2016 chl

Remove dead assignments and now unused variables.

Found by LLVM/Clang Static Analyzer.

ok mpi@ stefan@


Revision tags: OPENBSD_5_9_BASE
# 1.44 21-Aug-2015 visa

Remove the unused loan_count field and the related uvm logic. Most of
the page loaning code is already in the Attic.

ok kettenis@, beck@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.43 23-Dec-2014 tedu

convert pool_init nointr to waitok


# 1.42 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.41 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.40 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.39 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.38 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_4_BASE OPENBSD_5_5_BASE
# 1.37 30-May-2013 tedu

remove lots of comments about locking per beck's request


# 1.36 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.35 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.


Revision tags: OPENBSD_4_6_BASE OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.34 16-Jun-2009 oga

date based reversion of uvm to the 4th May.

We still have no idea why this stops the crashes. but it does.

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.33 16-Jun-2009 oga

Backout all changes to uvm after pmemrange (which will be backed out
separately).

a change at or just before the hackathon has either exposed or added a
very very nasty memory corruption bug that is giving us hell right now.
So in the interest of kernel stability these diffs are being backed out
until such a time as that corruption bug has been found and squashed,
then the ones that are proven good may slowly return.

a quick hitlist of the main commits this backs out:

mine:
uvm_objwire
the lock change in uvm_swap.c
using trees for uvm objects instead of the hash
removing the pgo_releasepg callback.

art@'s:
putting pmap_page_protect(VM_PROT_NONE) in uvm_pagedeactivate() since
all callers called that just prior anyway.

ok beck@, ariane@.

prompted by deraadt@.


# 1.32 06-Jun-2009 art

Since all callers of uvm_pagedeactivate did pmap_page_protect(.., VM_PROT_NONE)
just move that into uvm_pagedeactivate.

oga@ ok


# 1.31 30-May-2009 oga

in the (currently unused) loaning case for uvm_anfree, zero out anon->an_page
so we won't hit the kassert a little bit below it.

"obviously better than what is there now" beck@


# 1.30 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_4_BASE OPENBSD_4_5_BASE
# 1.29 10-Apr-2008 miod

Correctly amount swap usage for anons, from NetBSD via PR 5772.


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE
# 1.28 18-Jun-2007 pedro

Bring back Mickey's UVM anon change. Testing by thib@, beck@ and
ckuethe@ for a while. Okay beck@, "it is good timing" deraadt@.


# 1.27 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.26 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")


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.25 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.24 26-Jul-2006 mickey

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


# 1.23 13-Jul-2006 deraadt

Back out the anon change. Apparently it was tested by a few, but most of
us did not see it or get a chance to test it before it was commited. It
broke cvs, in the ami driver, making it not succeed at seeing it's devices.


# 1.22 21-Jun-2006 mickey

from netbsd: make anons dynamically allocated from pool.
this results in lesse kva waste due to static preallocation of those
for every phys page and also every swap page.
tested by beck krw miod


Revision tags: OPENBSD_3_1_BASE OPENBSD_3_2_BASE OPENBSD_3_3_BASE OPENBSD_3_4_BASE OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE OPENBSD_3_8_BASE OPENBSD_3_9_BASE SMP_SYNC_A SMP_SYNC_B UBC_SYNC_A UBC_SYNC_B
# 1.21 14-Mar-2002 millert

First round of __P removal in sys


# 1.20 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.19 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.18 28-Nov-2001 art

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


# 1.17 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.16 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.15 11-Nov-2001 art

Sync in more stuff from NetBSD.


# 1.14 07-Nov-2001 art

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


# 1.13 06-Nov-2001 art

More sync to NetBSD.
- Use malloc/free instead of MALLOC/FREE for variable sized allocations.
- Move the memory inheritance code to sys/mman.h and rename from VM_* to MAP_*
- various cleanups and simplifications.


# 1.12 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.11 05-Nov-2001 art

Minor sync to NetBSD.


Revision tags: OPENBSD_3_0_BASE
# 1.10 19-Sep-2001 mickey

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


# 1.9 26-Jul-2001 art

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


# 1.8 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.7 23-Jun-2001 smart

Sync with NetBSD 19990911 (just before PMAP_NEW was required)
- thread_sleep_msg() -> uvm_sleep()
- initialize reference count lock in uvm_anon_{init,add}()
- add uao_flush()
- replace boolean 'islocked' with 'lockflags'
- in uvm_fault() change FALSE to TRUE to in 'wide' fault handling
- get rid of uvm_km_get()
- various bug fixes


Revision tags: OPENBSD_2_9_BASE
# 1.6 29-Jan-2001 niklas

$OpenBSD$


Revision tags: OPENBSD_2_8_BASE
# 1.5 07-Sep-2000 art

Convert bzero to memset(X, 0..) and bcopy to memcpy.
This is to match (make diffs smaller) the code in NetBSD.
new gcc inlines those functions, so this could also be a performance win.


Revision tags: OPENBSD_2_7_BASE
# 1.4 15-Mar-2000 art

Fix the NetBSD id strings.


Revision tags: OPENBSD_2_6_BASE SMP_BASE kame_19991208
# 1.3 23-Aug-1999 art

branches: 1.3.4;
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.53 20-Mar-2021 mpi

Sync some comments in order to reduce the difference with NetBSD.

No functionnal change.

ok kettenis@


# 1.52 04-Mar-2021 mpi

Modify `uvmexp.swpgonly' atomically, required for uvm_fault() w/o KERNEL_LOCK()

ok kettenis@


# 1.51 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.50 24-Nov-2020 mpi

Grab the `pageqlock' before calling uvm_pageclean() as intended.

Document which global data structures require this lock and add some
asserts where the lock should be held.

Some code paths are still incorrect and should be revisited.

ok jmatthew@


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.49 04-Jan-2020 beck

Add uvm_anfree_list() to free anons as a list of pages. Use this in
the amap code to free pages as a list instead of one at a time to
allow for more efficient freeing.

Most of the work done at elk lakes, with testing by me and mlarkin
and kettenis. Speeds up a test program which zeros a big pile of memory
and then exits considerably.

ok kettenis@


Revision tags: 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.48 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.47 17-Jun-2016 dlg

pool_setipl on all uvm pools.

ok kettenis@ visa@


# 1.46 08-May-2016 stefan

Wait for RAM in uvm_fault when allocating uvm structures fails

Only fail hard when running out of swap space also, as suggested by
kettenis@

While there, let amap_add() return a success status and handle
amap_add() errors in uvm_fault() similar to other out of RAM situations.
These bits are needed for further amap reorganization diffs.

lots of feedback and ok kettenis@


# 1.45 29-Mar-2016 chl

Remove dead assignments and now unused variables.

Found by LLVM/Clang Static Analyzer.

ok mpi@ stefan@


Revision tags: OPENBSD_5_9_BASE
# 1.44 21-Aug-2015 visa

Remove the unused loan_count field and the related uvm logic. Most of
the page loaning code is already in the Attic.

ok kettenis@, beck@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.43 23-Dec-2014 tedu

convert pool_init nointr to waitok


# 1.42 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.41 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.40 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.39 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.38 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_4_BASE OPENBSD_5_5_BASE
# 1.37 30-May-2013 tedu

remove lots of comments about locking per beck's request


# 1.36 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.35 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.


Revision tags: OPENBSD_4_6_BASE OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.34 16-Jun-2009 oga

date based reversion of uvm to the 4th May.

We still have no idea why this stops the crashes. but it does.

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.33 16-Jun-2009 oga

Backout all changes to uvm after pmemrange (which will be backed out
separately).

a change at or just before the hackathon has either exposed or added a
very very nasty memory corruption bug that is giving us hell right now.
So in the interest of kernel stability these diffs are being backed out
until such a time as that corruption bug has been found and squashed,
then the ones that are proven good may slowly return.

a quick hitlist of the main commits this backs out:

mine:
uvm_objwire
the lock change in uvm_swap.c
using trees for uvm objects instead of the hash
removing the pgo_releasepg callback.

art@'s:
putting pmap_page_protect(VM_PROT_NONE) in uvm_pagedeactivate() since
all callers called that just prior anyway.

ok beck@, ariane@.

prompted by deraadt@.


# 1.32 06-Jun-2009 art

Since all callers of uvm_pagedeactivate did pmap_page_protect(.., VM_PROT_NONE)
just move that into uvm_pagedeactivate.

oga@ ok


# 1.31 30-May-2009 oga

in the (currently unused) loaning case for uvm_anfree, zero out anon->an_page
so we won't hit the kassert a little bit below it.

"obviously better than what is there now" beck@


# 1.30 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_4_BASE OPENBSD_4_5_BASE
# 1.29 10-Apr-2008 miod

Correctly amount swap usage for anons, from NetBSD via PR 5772.


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE
# 1.28 18-Jun-2007 pedro

Bring back Mickey's UVM anon change. Testing by thib@, beck@ and
ckuethe@ for a while. Okay beck@, "it is good timing" deraadt@.


# 1.27 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.26 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")


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.25 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.24 26-Jul-2006 mickey

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


# 1.23 13-Jul-2006 deraadt

Back out the anon change. Apparently it was tested by a few, but most of
us did not see it or get a chance to test it before it was commited. It
broke cvs, in the ami driver, making it not succeed at seeing it's devices.


# 1.22 21-Jun-2006 mickey

from netbsd: make anons dynamically allocated from pool.
this results in lesse kva waste due to static preallocation of those
for every phys page and also every swap page.
tested by beck krw miod


Revision tags: OPENBSD_3_1_BASE OPENBSD_3_2_BASE OPENBSD_3_3_BASE OPENBSD_3_4_BASE OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE OPENBSD_3_8_BASE OPENBSD_3_9_BASE SMP_SYNC_A SMP_SYNC_B UBC_SYNC_A UBC_SYNC_B
# 1.21 14-Mar-2002 millert

First round of __P removal in sys


# 1.20 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.19 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.18 28-Nov-2001 art

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


# 1.17 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.16 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.15 11-Nov-2001 art

Sync in more stuff from NetBSD.


# 1.14 07-Nov-2001 art

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


# 1.13 06-Nov-2001 art

More sync to NetBSD.
- Use malloc/free instead of MALLOC/FREE for variable sized allocations.
- Move the memory inheritance code to sys/mman.h and rename from VM_* to MAP_*
- various cleanups and simplifications.


# 1.12 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.11 05-Nov-2001 art

Minor sync to NetBSD.


Revision tags: OPENBSD_3_0_BASE
# 1.10 19-Sep-2001 mickey

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


# 1.9 26-Jul-2001 art

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


# 1.8 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.7 23-Jun-2001 smart

Sync with NetBSD 19990911 (just before PMAP_NEW was required)
- thread_sleep_msg() -> uvm_sleep()
- initialize reference count lock in uvm_anon_{init,add}()
- add uao_flush()
- replace boolean 'islocked' with 'lockflags'
- in uvm_fault() change FALSE to TRUE to in 'wide' fault handling
- get rid of uvm_km_get()
- various bug fixes


Revision tags: OPENBSD_2_9_BASE
# 1.6 29-Jan-2001 niklas

$OpenBSD$


Revision tags: OPENBSD_2_8_BASE
# 1.5 07-Sep-2000 art

Convert bzero to memset(X, 0..) and bcopy to memcpy.
This is to match (make diffs smaller) the code in NetBSD.
new gcc inlines those functions, so this could also be a performance win.


Revision tags: OPENBSD_2_7_BASE
# 1.4 15-Mar-2000 art

Fix the NetBSD id strings.


Revision tags: OPENBSD_2_6_BASE SMP_BASE kame_19991208
# 1.3 23-Aug-1999 art

branches: 1.3.4;
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.52 04-Mar-2021 mpi

Modify `uvmexp.swpgonly' atomically, required for uvm_fault() w/o KERNEL_LOCK()

ok kettenis@


# 1.51 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.50 24-Nov-2020 mpi

Grab the `pageqlock' before calling uvm_pageclean() as intended.

Document which global data structures require this lock and add some
asserts where the lock should be held.

Some code paths are still incorrect and should be revisited.

ok jmatthew@


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.49 04-Jan-2020 beck

Add uvm_anfree_list() to free anons as a list of pages. Use this in
the amap code to free pages as a list instead of one at a time to
allow for more efficient freeing.

Most of the work done at elk lakes, with testing by me and mlarkin
and kettenis. Speeds up a test program which zeros a big pile of memory
and then exits considerably.

ok kettenis@


Revision tags: 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.48 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.47 17-Jun-2016 dlg

pool_setipl on all uvm pools.

ok kettenis@ visa@


# 1.46 08-May-2016 stefan

Wait for RAM in uvm_fault when allocating uvm structures fails

Only fail hard when running out of swap space also, as suggested by
kettenis@

While there, let amap_add() return a success status and handle
amap_add() errors in uvm_fault() similar to other out of RAM situations.
These bits are needed for further amap reorganization diffs.

lots of feedback and ok kettenis@


# 1.45 29-Mar-2016 chl

Remove dead assignments and now unused variables.

Found by LLVM/Clang Static Analyzer.

ok mpi@ stefan@


Revision tags: OPENBSD_5_9_BASE
# 1.44 21-Aug-2015 visa

Remove the unused loan_count field and the related uvm logic. Most of
the page loaning code is already in the Attic.

ok kettenis@, beck@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.43 23-Dec-2014 tedu

convert pool_init nointr to waitok


# 1.42 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.41 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.40 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.39 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.38 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_4_BASE OPENBSD_5_5_BASE
# 1.37 30-May-2013 tedu

remove lots of comments about locking per beck's request


# 1.36 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.35 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.


Revision tags: OPENBSD_4_6_BASE OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.34 16-Jun-2009 oga

date based reversion of uvm to the 4th May.

We still have no idea why this stops the crashes. but it does.

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.33 16-Jun-2009 oga

Backout all changes to uvm after pmemrange (which will be backed out
separately).

a change at or just before the hackathon has either exposed or added a
very very nasty memory corruption bug that is giving us hell right now.
So in the interest of kernel stability these diffs are being backed out
until such a time as that corruption bug has been found and squashed,
then the ones that are proven good may slowly return.

a quick hitlist of the main commits this backs out:

mine:
uvm_objwire
the lock change in uvm_swap.c
using trees for uvm objects instead of the hash
removing the pgo_releasepg callback.

art@'s:
putting pmap_page_protect(VM_PROT_NONE) in uvm_pagedeactivate() since
all callers called that just prior anyway.

ok beck@, ariane@.

prompted by deraadt@.


# 1.32 06-Jun-2009 art

Since all callers of uvm_pagedeactivate did pmap_page_protect(.., VM_PROT_NONE)
just move that into uvm_pagedeactivate.

oga@ ok


# 1.31 30-May-2009 oga

in the (currently unused) loaning case for uvm_anfree, zero out anon->an_page
so we won't hit the kassert a little bit below it.

"obviously better than what is there now" beck@


# 1.30 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_4_BASE OPENBSD_4_5_BASE
# 1.29 10-Apr-2008 miod

Correctly amount swap usage for anons, from NetBSD via PR 5772.


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE
# 1.28 18-Jun-2007 pedro

Bring back Mickey's UVM anon change. Testing by thib@, beck@ and
ckuethe@ for a while. Okay beck@, "it is good timing" deraadt@.


# 1.27 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.26 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")


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.25 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.24 26-Jul-2006 mickey

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


# 1.23 13-Jul-2006 deraadt

Back out the anon change. Apparently it was tested by a few, but most of
us did not see it or get a chance to test it before it was commited. It
broke cvs, in the ami driver, making it not succeed at seeing it's devices.


# 1.22 21-Jun-2006 mickey

from netbsd: make anons dynamically allocated from pool.
this results in lesse kva waste due to static preallocation of those
for every phys page and also every swap page.
tested by beck krw miod


Revision tags: OPENBSD_3_1_BASE OPENBSD_3_2_BASE OPENBSD_3_3_BASE OPENBSD_3_4_BASE OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE OPENBSD_3_8_BASE OPENBSD_3_9_BASE SMP_SYNC_A SMP_SYNC_B UBC_SYNC_A UBC_SYNC_B
# 1.21 14-Mar-2002 millert

First round of __P removal in sys


# 1.20 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.19 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.18 28-Nov-2001 art

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


# 1.17 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.16 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.15 11-Nov-2001 art

Sync in more stuff from NetBSD.


# 1.14 07-Nov-2001 art

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


# 1.13 06-Nov-2001 art

More sync to NetBSD.
- Use malloc/free instead of MALLOC/FREE for variable sized allocations.
- Move the memory inheritance code to sys/mman.h and rename from VM_* to MAP_*
- various cleanups and simplifications.


# 1.12 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.11 05-Nov-2001 art

Minor sync to NetBSD.


Revision tags: OPENBSD_3_0_BASE
# 1.10 19-Sep-2001 mickey

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


# 1.9 26-Jul-2001 art

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


# 1.8 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.7 23-Jun-2001 smart

Sync with NetBSD 19990911 (just before PMAP_NEW was required)
- thread_sleep_msg() -> uvm_sleep()
- initialize reference count lock in uvm_anon_{init,add}()
- add uao_flush()
- replace boolean 'islocked' with 'lockflags'
- in uvm_fault() change FALSE to TRUE to in 'wide' fault handling
- get rid of uvm_km_get()
- various bug fixes


Revision tags: OPENBSD_2_9_BASE
# 1.6 29-Jan-2001 niklas

$OpenBSD$


Revision tags: OPENBSD_2_8_BASE
# 1.5 07-Sep-2000 art

Convert bzero to memset(X, 0..) and bcopy to memcpy.
This is to match (make diffs smaller) the code in NetBSD.
new gcc inlines those functions, so this could also be a performance win.


Revision tags: OPENBSD_2_7_BASE
# 1.4 15-Mar-2000 art

Fix the NetBSD id strings.


Revision tags: OPENBSD_2_6_BASE SMP_BASE kame_19991208
# 1.3 23-Aug-1999 art

branches: 1.3.4;
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.51 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.50 24-Nov-2020 mpi

Grab the `pageqlock' before calling uvm_pageclean() as intended.

Document which global data structures require this lock and add some
asserts where the lock should be held.

Some code paths are still incorrect and should be revisited.

ok jmatthew@


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.49 04-Jan-2020 beck

Add uvm_anfree_list() to free anons as a list of pages. Use this in
the amap code to free pages as a list instead of one at a time to
allow for more efficient freeing.

Most of the work done at elk lakes, with testing by me and mlarkin
and kettenis. Speeds up a test program which zeros a big pile of memory
and then exits considerably.

ok kettenis@


Revision tags: 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.48 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.47 17-Jun-2016 dlg

pool_setipl on all uvm pools.

ok kettenis@ visa@


# 1.46 08-May-2016 stefan

Wait for RAM in uvm_fault when allocating uvm structures fails

Only fail hard when running out of swap space also, as suggested by
kettenis@

While there, let amap_add() return a success status and handle
amap_add() errors in uvm_fault() similar to other out of RAM situations.
These bits are needed for further amap reorganization diffs.

lots of feedback and ok kettenis@


# 1.45 29-Mar-2016 chl

Remove dead assignments and now unused variables.

Found by LLVM/Clang Static Analyzer.

ok mpi@ stefan@


Revision tags: OPENBSD_5_9_BASE
# 1.44 21-Aug-2015 visa

Remove the unused loan_count field and the related uvm logic. Most of
the page loaning code is already in the Attic.

ok kettenis@, beck@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.43 23-Dec-2014 tedu

convert pool_init nointr to waitok


# 1.42 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.41 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.40 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.39 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.38 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_4_BASE OPENBSD_5_5_BASE
# 1.37 30-May-2013 tedu

remove lots of comments about locking per beck's request


# 1.36 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.35 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.


Revision tags: OPENBSD_4_6_BASE OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.34 16-Jun-2009 oga

date based reversion of uvm to the 4th May.

We still have no idea why this stops the crashes. but it does.

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.33 16-Jun-2009 oga

Backout all changes to uvm after pmemrange (which will be backed out
separately).

a change at or just before the hackathon has either exposed or added a
very very nasty memory corruption bug that is giving us hell right now.
So in the interest of kernel stability these diffs are being backed out
until such a time as that corruption bug has been found and squashed,
then the ones that are proven good may slowly return.

a quick hitlist of the main commits this backs out:

mine:
uvm_objwire
the lock change in uvm_swap.c
using trees for uvm objects instead of the hash
removing the pgo_releasepg callback.

art@'s:
putting pmap_page_protect(VM_PROT_NONE) in uvm_pagedeactivate() since
all callers called that just prior anyway.

ok beck@, ariane@.

prompted by deraadt@.


# 1.32 06-Jun-2009 art

Since all callers of uvm_pagedeactivate did pmap_page_protect(.., VM_PROT_NONE)
just move that into uvm_pagedeactivate.

oga@ ok


# 1.31 30-May-2009 oga

in the (currently unused) loaning case for uvm_anfree, zero out anon->an_page
so we won't hit the kassert a little bit below it.

"obviously better than what is there now" beck@


# 1.30 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_4_BASE OPENBSD_4_5_BASE
# 1.29 10-Apr-2008 miod

Correctly amount swap usage for anons, from NetBSD via PR 5772.


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE
# 1.28 18-Jun-2007 pedro

Bring back Mickey's UVM anon change. Testing by thib@, beck@ and
ckuethe@ for a while. Okay beck@, "it is good timing" deraadt@.


# 1.27 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.26 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")


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.25 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.24 26-Jul-2006 mickey

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


# 1.23 13-Jul-2006 deraadt

Back out the anon change. Apparently it was tested by a few, but most of
us did not see it or get a chance to test it before it was commited. It
broke cvs, in the ami driver, making it not succeed at seeing it's devices.


# 1.22 21-Jun-2006 mickey

from netbsd: make anons dynamically allocated from pool.
this results in lesse kva waste due to static preallocation of those
for every phys page and also every swap page.
tested by beck krw miod


Revision tags: OPENBSD_3_1_BASE OPENBSD_3_2_BASE OPENBSD_3_3_BASE OPENBSD_3_4_BASE OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE OPENBSD_3_8_BASE OPENBSD_3_9_BASE SMP_SYNC_A SMP_SYNC_B UBC_SYNC_A UBC_SYNC_B
# 1.21 14-Mar-2002 millert

First round of __P removal in sys


# 1.20 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.19 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.18 28-Nov-2001 art

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


# 1.17 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.16 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.15 11-Nov-2001 art

Sync in more stuff from NetBSD.


# 1.14 07-Nov-2001 art

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


# 1.13 06-Nov-2001 art

More sync to NetBSD.
- Use malloc/free instead of MALLOC/FREE for variable sized allocations.
- Move the memory inheritance code to sys/mman.h and rename from VM_* to MAP_*
- various cleanups and simplifications.


# 1.12 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.11 05-Nov-2001 art

Minor sync to NetBSD.


Revision tags: OPENBSD_3_0_BASE
# 1.10 19-Sep-2001 mickey

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


# 1.9 26-Jul-2001 art

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


# 1.8 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.7 23-Jun-2001 smart

Sync with NetBSD 19990911 (just before PMAP_NEW was required)
- thread_sleep_msg() -> uvm_sleep()
- initialize reference count lock in uvm_anon_{init,add}()
- add uao_flush()
- replace boolean 'islocked' with 'lockflags'
- in uvm_fault() change FALSE to TRUE to in 'wide' fault handling
- get rid of uvm_km_get()
- various bug fixes


Revision tags: OPENBSD_2_9_BASE
# 1.6 29-Jan-2001 niklas

$OpenBSD$


Revision tags: OPENBSD_2_8_BASE
# 1.5 07-Sep-2000 art

Convert bzero to memset(X, 0..) and bcopy to memcpy.
This is to match (make diffs smaller) the code in NetBSD.
new gcc inlines those functions, so this could also be a performance win.


Revision tags: OPENBSD_2_7_BASE
# 1.4 15-Mar-2000 art

Fix the NetBSD id strings.


Revision tags: OPENBSD_2_6_BASE SMP_BASE kame_19991208
# 1.3 23-Aug-1999 art

branches: 1.3.4;
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.50 24-Nov-2020 mpi

Grab the `pageqlock' before calling uvm_pageclean() as intended.

Document which global data structures require this lock and add some
asserts where the lock should be held.

Some code paths are still incorrect and should be revisited.

ok jmatthew@


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.49 04-Jan-2020 beck

Add uvm_anfree_list() to free anons as a list of pages. Use this in
the amap code to free pages as a list instead of one at a time to
allow for more efficient freeing.

Most of the work done at elk lakes, with testing by me and mlarkin
and kettenis. Speeds up a test program which zeros a big pile of memory
and then exits considerably.

ok kettenis@


Revision tags: 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.48 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.47 17-Jun-2016 dlg

pool_setipl on all uvm pools.

ok kettenis@ visa@


# 1.46 08-May-2016 stefan

Wait for RAM in uvm_fault when allocating uvm structures fails

Only fail hard when running out of swap space also, as suggested by
kettenis@

While there, let amap_add() return a success status and handle
amap_add() errors in uvm_fault() similar to other out of RAM situations.
These bits are needed for further amap reorganization diffs.

lots of feedback and ok kettenis@


# 1.45 29-Mar-2016 chl

Remove dead assignments and now unused variables.

Found by LLVM/Clang Static Analyzer.

ok mpi@ stefan@


Revision tags: OPENBSD_5_9_BASE
# 1.44 21-Aug-2015 visa

Remove the unused loan_count field and the related uvm logic. Most of
the page loaning code is already in the Attic.

ok kettenis@, beck@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.43 23-Dec-2014 tedu

convert pool_init nointr to waitok


# 1.42 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.41 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.40 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.39 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.38 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_4_BASE OPENBSD_5_5_BASE
# 1.37 30-May-2013 tedu

remove lots of comments about locking per beck's request


# 1.36 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.35 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.


Revision tags: OPENBSD_4_6_BASE OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.34 16-Jun-2009 oga

date based reversion of uvm to the 4th May.

We still have no idea why this stops the crashes. but it does.

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.33 16-Jun-2009 oga

Backout all changes to uvm after pmemrange (which will be backed out
separately).

a change at or just before the hackathon has either exposed or added a
very very nasty memory corruption bug that is giving us hell right now.
So in the interest of kernel stability these diffs are being backed out
until such a time as that corruption bug has been found and squashed,
then the ones that are proven good may slowly return.

a quick hitlist of the main commits this backs out:

mine:
uvm_objwire
the lock change in uvm_swap.c
using trees for uvm objects instead of the hash
removing the pgo_releasepg callback.

art@'s:
putting pmap_page_protect(VM_PROT_NONE) in uvm_pagedeactivate() since
all callers called that just prior anyway.

ok beck@, ariane@.

prompted by deraadt@.


# 1.32 06-Jun-2009 art

Since all callers of uvm_pagedeactivate did pmap_page_protect(.., VM_PROT_NONE)
just move that into uvm_pagedeactivate.

oga@ ok


# 1.31 30-May-2009 oga

in the (currently unused) loaning case for uvm_anfree, zero out anon->an_page
so we won't hit the kassert a little bit below it.

"obviously better than what is there now" beck@


# 1.30 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_4_BASE OPENBSD_4_5_BASE
# 1.29 10-Apr-2008 miod

Correctly amount swap usage for anons, from NetBSD via PR 5772.


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE
# 1.28 18-Jun-2007 pedro

Bring back Mickey's UVM anon change. Testing by thib@, beck@ and
ckuethe@ for a while. Okay beck@, "it is good timing" deraadt@.


# 1.27 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.26 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")


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.25 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.24 26-Jul-2006 mickey

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


# 1.23 13-Jul-2006 deraadt

Back out the anon change. Apparently it was tested by a few, but most of
us did not see it or get a chance to test it before it was commited. It
broke cvs, in the ami driver, making it not succeed at seeing it's devices.


# 1.22 21-Jun-2006 mickey

from netbsd: make anons dynamically allocated from pool.
this results in lesse kva waste due to static preallocation of those
for every phys page and also every swap page.
tested by beck krw miod


Revision tags: OPENBSD_3_1_BASE OPENBSD_3_2_BASE OPENBSD_3_3_BASE OPENBSD_3_4_BASE OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE OPENBSD_3_8_BASE OPENBSD_3_9_BASE SMP_SYNC_A SMP_SYNC_B UBC_SYNC_A UBC_SYNC_B
# 1.21 14-Mar-2002 millert

First round of __P removal in sys


# 1.20 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.19 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.18 28-Nov-2001 art

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


# 1.17 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.16 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.15 11-Nov-2001 art

Sync in more stuff from NetBSD.


# 1.14 07-Nov-2001 art

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


# 1.13 06-Nov-2001 art

More sync to NetBSD.
- Use malloc/free instead of MALLOC/FREE for variable sized allocations.
- Move the memory inheritance code to sys/mman.h and rename from VM_* to MAP_*
- various cleanups and simplifications.


# 1.12 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.11 05-Nov-2001 art

Minor sync to NetBSD.


Revision tags: OPENBSD_3_0_BASE
# 1.10 19-Sep-2001 mickey

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


# 1.9 26-Jul-2001 art

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


# 1.8 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.7 23-Jun-2001 smart

Sync with NetBSD 19990911 (just before PMAP_NEW was required)
- thread_sleep_msg() -> uvm_sleep()
- initialize reference count lock in uvm_anon_{init,add}()
- add uao_flush()
- replace boolean 'islocked' with 'lockflags'
- in uvm_fault() change FALSE to TRUE to in 'wide' fault handling
- get rid of uvm_km_get()
- various bug fixes


Revision tags: OPENBSD_2_9_BASE
# 1.6 29-Jan-2001 niklas

$OpenBSD$


Revision tags: OPENBSD_2_8_BASE
# 1.5 07-Sep-2000 art

Convert bzero to memset(X, 0..) and bcopy to memcpy.
This is to match (make diffs smaller) the code in NetBSD.
new gcc inlines those functions, so this could also be a performance win.


Revision tags: OPENBSD_2_7_BASE
# 1.4 15-Mar-2000 art

Fix the NetBSD id strings.


Revision tags: OPENBSD_2_6_BASE SMP_BASE kame_19991208
# 1.3 23-Aug-1999 art

branches: 1.3.4;
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.49 04-Jan-2020 beck

Add uvm_anfree_list() to free anons as a list of pages. Use this in
the amap code to free pages as a list instead of one at a time to
allow for more efficient freeing.

Most of the work done at elk lakes, with testing by me and mlarkin
and kettenis. Speeds up a test program which zeros a big pile of memory
and then exits considerably.

ok kettenis@


Revision tags: 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.48 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.47 17-Jun-2016 dlg

pool_setipl on all uvm pools.

ok kettenis@ visa@


# 1.46 08-May-2016 stefan

Wait for RAM in uvm_fault when allocating uvm structures fails

Only fail hard when running out of swap space also, as suggested by
kettenis@

While there, let amap_add() return a success status and handle
amap_add() errors in uvm_fault() similar to other out of RAM situations.
These bits are needed for further amap reorganization diffs.

lots of feedback and ok kettenis@


# 1.45 29-Mar-2016 chl

Remove dead assignments and now unused variables.

Found by LLVM/Clang Static Analyzer.

ok mpi@ stefan@


Revision tags: OPENBSD_5_9_BASE
# 1.44 21-Aug-2015 visa

Remove the unused loan_count field and the related uvm logic. Most of
the page loaning code is already in the Attic.

ok kettenis@, beck@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.43 23-Dec-2014 tedu

convert pool_init nointr to waitok


# 1.42 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.41 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.40 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.39 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.38 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_4_BASE OPENBSD_5_5_BASE
# 1.37 30-May-2013 tedu

remove lots of comments about locking per beck's request


# 1.36 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.35 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.


Revision tags: OPENBSD_4_6_BASE OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.34 16-Jun-2009 oga

date based reversion of uvm to the 4th May.

We still have no idea why this stops the crashes. but it does.

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.33 16-Jun-2009 oga

Backout all changes to uvm after pmemrange (which will be backed out
separately).

a change at or just before the hackathon has either exposed or added a
very very nasty memory corruption bug that is giving us hell right now.
So in the interest of kernel stability these diffs are being backed out
until such a time as that corruption bug has been found and squashed,
then the ones that are proven good may slowly return.

a quick hitlist of the main commits this backs out:

mine:
uvm_objwire
the lock change in uvm_swap.c
using trees for uvm objects instead of the hash
removing the pgo_releasepg callback.

art@'s:
putting pmap_page_protect(VM_PROT_NONE) in uvm_pagedeactivate() since
all callers called that just prior anyway.

ok beck@, ariane@.

prompted by deraadt@.


# 1.32 06-Jun-2009 art

Since all callers of uvm_pagedeactivate did pmap_page_protect(.., VM_PROT_NONE)
just move that into uvm_pagedeactivate.

oga@ ok


# 1.31 30-May-2009 oga

in the (currently unused) loaning case for uvm_anfree, zero out anon->an_page
so we won't hit the kassert a little bit below it.

"obviously better than what is there now" beck@


# 1.30 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_4_BASE OPENBSD_4_5_BASE
# 1.29 10-Apr-2008 miod

Correctly amount swap usage for anons, from NetBSD via PR 5772.


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE
# 1.28 18-Jun-2007 pedro

Bring back Mickey's UVM anon change. Testing by thib@, beck@ and
ckuethe@ for a while. Okay beck@, "it is good timing" deraadt@.


# 1.27 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.26 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")


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.25 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.24 26-Jul-2006 mickey

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


# 1.23 13-Jul-2006 deraadt

Back out the anon change. Apparently it was tested by a few, but most of
us did not see it or get a chance to test it before it was commited. It
broke cvs, in the ami driver, making it not succeed at seeing it's devices.


# 1.22 21-Jun-2006 mickey

from netbsd: make anons dynamically allocated from pool.
this results in lesse kva waste due to static preallocation of those
for every phys page and also every swap page.
tested by beck krw miod


Revision tags: OPENBSD_3_1_BASE OPENBSD_3_2_BASE OPENBSD_3_3_BASE OPENBSD_3_4_BASE OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE OPENBSD_3_8_BASE OPENBSD_3_9_BASE SMP_SYNC_A SMP_SYNC_B UBC_SYNC_A UBC_SYNC_B
# 1.21 14-Mar-2002 millert

First round of __P removal in sys


# 1.20 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.19 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.18 28-Nov-2001 art

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


# 1.17 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.16 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.15 11-Nov-2001 art

Sync in more stuff from NetBSD.


# 1.14 07-Nov-2001 art

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


# 1.13 06-Nov-2001 art

More sync to NetBSD.
- Use malloc/free instead of MALLOC/FREE for variable sized allocations.
- Move the memory inheritance code to sys/mman.h and rename from VM_* to MAP_*
- various cleanups and simplifications.


# 1.12 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.11 05-Nov-2001 art

Minor sync to NetBSD.


Revision tags: OPENBSD_3_0_BASE
# 1.10 19-Sep-2001 mickey

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


# 1.9 26-Jul-2001 art

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


# 1.8 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.7 23-Jun-2001 smart

Sync with NetBSD 19990911 (just before PMAP_NEW was required)
- thread_sleep_msg() -> uvm_sleep()
- initialize reference count lock in uvm_anon_{init,add}()
- add uao_flush()
- replace boolean 'islocked' with 'lockflags'
- in uvm_fault() change FALSE to TRUE to in 'wide' fault handling
- get rid of uvm_km_get()
- various bug fixes


Revision tags: OPENBSD_2_9_BASE
# 1.6 29-Jan-2001 niklas

$OpenBSD$


Revision tags: OPENBSD_2_8_BASE
# 1.5 07-Sep-2000 art

Convert bzero to memset(X, 0..) and bcopy to memcpy.
This is to match (make diffs smaller) the code in NetBSD.
new gcc inlines those functions, so this could also be a performance win.


Revision tags: OPENBSD_2_7_BASE
# 1.4 15-Mar-2000 art

Fix the NetBSD id strings.


Revision tags: OPENBSD_2_6_BASE SMP_BASE kame_19991208
# 1.3 23-Aug-1999 art

branches: 1.3.4;
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_6_1_BASE OPENBSD_6_2_BASE
# 1.48 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


Revision tags: OPENBSD_6_0_BASE
# 1.47 17-Jun-2016 dlg

pool_setipl on all uvm pools.

ok kettenis@ visa@


# 1.46 08-May-2016 stefan

Wait for RAM in uvm_fault when allocating uvm structures fails

Only fail hard when running out of swap space also, as suggested by
kettenis@

While there, let amap_add() return a success status and handle
amap_add() errors in uvm_fault() similar to other out of RAM situations.
These bits are needed for further amap reorganization diffs.

lots of feedback and ok kettenis@


# 1.45 29-Mar-2016 chl

Remove dead assignments and now unused variables.

Found by LLVM/Clang Static Analyzer.

ok mpi@ stefan@


Revision tags: OPENBSD_5_9_BASE
# 1.44 21-Aug-2015 visa

Remove the unused loan_count field and the related uvm logic. Most of
the page loaning code is already in the Attic.

ok kettenis@, beck@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.43 23-Dec-2014 tedu

convert pool_init nointr to waitok


# 1.42 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.41 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.40 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.39 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.38 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_4_BASE OPENBSD_5_5_BASE
# 1.37 30-May-2013 tedu

remove lots of comments about locking per beck's request


# 1.36 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.35 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.


Revision tags: OPENBSD_4_6_BASE OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.34 16-Jun-2009 oga

date based reversion of uvm to the 4th May.

We still have no idea why this stops the crashes. but it does.

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.33 16-Jun-2009 oga

Backout all changes to uvm after pmemrange (which will be backed out
separately).

a change at or just before the hackathon has either exposed or added a
very very nasty memory corruption bug that is giving us hell right now.
So in the interest of kernel stability these diffs are being backed out
until such a time as that corruption bug has been found and squashed,
then the ones that are proven good may slowly return.

a quick hitlist of the main commits this backs out:

mine:
uvm_objwire
the lock change in uvm_swap.c
using trees for uvm objects instead of the hash
removing the pgo_releasepg callback.

art@'s:
putting pmap_page_protect(VM_PROT_NONE) in uvm_pagedeactivate() since
all callers called that just prior anyway.

ok beck@, ariane@.

prompted by deraadt@.


# 1.32 06-Jun-2009 art

Since all callers of uvm_pagedeactivate did pmap_page_protect(.., VM_PROT_NONE)
just move that into uvm_pagedeactivate.

oga@ ok


# 1.31 30-May-2009 oga

in the (currently unused) loaning case for uvm_anfree, zero out anon->an_page
so we won't hit the kassert a little bit below it.

"obviously better than what is there now" beck@


# 1.30 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_4_BASE OPENBSD_4_5_BASE
# 1.29 10-Apr-2008 miod

Correctly amount swap usage for anons, from NetBSD via PR 5772.


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE
# 1.28 18-Jun-2007 pedro

Bring back Mickey's UVM anon change. Testing by thib@, beck@ and
ckuethe@ for a while. Okay beck@, "it is good timing" deraadt@.


# 1.27 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.26 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")


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.25 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.24 26-Jul-2006 mickey

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


# 1.23 13-Jul-2006 deraadt

Back out the anon change. Apparently it was tested by a few, but most of
us did not see it or get a chance to test it before it was commited. It
broke cvs, in the ami driver, making it not succeed at seeing it's devices.


# 1.22 21-Jun-2006 mickey

from netbsd: make anons dynamically allocated from pool.
this results in lesse kva waste due to static preallocation of those
for every phys page and also every swap page.
tested by beck krw miod


Revision tags: OPENBSD_3_1_BASE OPENBSD_3_2_BASE OPENBSD_3_3_BASE OPENBSD_3_4_BASE OPENBSD_3_5_BASE OPENBSD_3_6_BASE OPENBSD_3_7_BASE OPENBSD_3_8_BASE OPENBSD_3_9_BASE SMP_SYNC_A SMP_SYNC_B UBC_SYNC_A UBC_SYNC_B
# 1.21 14-Mar-2002 millert

First round of __P removal in sys


# 1.20 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.19 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.18 28-Nov-2001 art

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


# 1.17 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.16 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.15 11-Nov-2001 art

Sync in more stuff from NetBSD.


# 1.14 07-Nov-2001 art

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


# 1.13 06-Nov-2001 art

More sync to NetBSD.
- Use malloc/free instead of MALLOC/FREE for variable sized allocations.
- Move the memory inheritance code to sys/mman.h and rename from VM_* to MAP_*
- various cleanups and simplifications.


# 1.12 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.11 05-Nov-2001 art

Minor sync to NetBSD.


Revision tags: OPENBSD_3_0_BASE
# 1.10 19-Sep-2001 mickey

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


# 1.9 26-Jul-2001 art

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


# 1.8 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.7 23-Jun-2001 smart

Sync with NetBSD 19990911 (just before PMAP_NEW was required)
- thread_sleep_msg() -> uvm_sleep()
- initialize reference count lock in uvm_anon_{init,add}()
- add uao_flush()
- replace boolean 'islocked' with 'lockflags'
- in uvm_fault() change FALSE to TRUE to in 'wide' fault handling
- get rid of uvm_km_get()
- various bug fixes


Revision tags: OPENBSD_2_9_BASE
# 1.6 29-Jan-2001 niklas

$OpenBSD$


Revision tags: OPENBSD_2_8_BASE
# 1.5 07-Sep-2000 art

Convert bzero to memset(X, 0..) and bcopy to memcpy.
This is to match (make diffs smaller) the code in NetBSD.
new gcc inlines those functions, so this could also be a performance win.


Revision tags: OPENBSD_2_7_BASE
# 1.4 15-Mar-2000 art

Fix the NetBSD id strings.


Revision tags: OPENBSD_2_6_BASE SMP_BASE kame_19991208
# 1.3 23-Aug-1999 art

branches: 1.3.4;
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