Commit graph

4908 commits

Author SHA1 Message Date
Bojan Novković
a02f9685ed vm_meter: Add counter for NOFREE pages
This change adds a new counter that tracks the total number
of permanently allocated pages.

Differential Revision:	https://reviews.freebsd.org/D46978
Reviewed by:	alc, markj
2024-10-07 18:46:32 +02:00
Doug Moore
6af02087d2 swap_pager: rename iter init functions
Add _init to the function names of the functions that initialize
iterators for swblks.

Reported by:	alc, markj
Reviewed by:	alc
Differential Revision:	https://reviews.freebsd.org/D46974
2024-10-07 11:11:33 -05:00
Konstantin Belousov
6a3fbdc7e9 kinfo_vmobject: report backing object of the SysV shm segments
Use reserved work for kvo_flags.
Mark such object with KVMO_FLAG_SYSVSHM.
Provide segment key in kvo_vn_fileid, vnode never can back shm mapping.
Provide sequence number in kvo_vn_fsid_freebsd11.

Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D46959
2024-10-07 11:22:12 +03:00
Konstantin Belousov
f186252e0d vm_object: add OBJ_SYSVSHM flag to indicate SysV shm backing object
Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D46959
2024-10-07 11:22:12 +03:00
Konstantin Belousov
34935a6b37 vm_object: reformat flags definitions
Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D46959
2024-10-07 11:22:12 +03:00
Mark Johnston
7f1dfd6c33 vm_object: Fix the argument type to vm_object_set_flag()
Reported by:	kib
Fixes:		9d52823bf1 ("vm_object: Widen the flags field")
2024-10-06 22:55:02 +00:00
Mark Johnston
9d52823bf1 vm_object: Widen the flags field
Take advantage of a nearby 2-byte hole to avoid growing the struct.
This way, only the offsets of "flags" and "pg_color" change.  Bump
__FreeBSD_version since some out-of-tree kernel modules may access these
fields, though I haven't found any examples so far.

Reviewed by:	kib
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D35905
2024-10-06 13:13:30 +00:00
Bojan Novković
149e1af6ae vm_kern: Use VM_ALLOC_NOFREE when allocating 'zero_region' page
Allocate the 'zero_region' page using VM_ALLOC_NOFREE since
 it never gets released.

 Differential Revision:  https://reviews.freebsd.org/D46885
 Reviewed by:    alc, markj, kib
2024-10-05 17:05:40 +02:00
Doug Moore
52b3514052 swap_pager: examine swblks with pctrie iterators
Replace calls to pctrie lookup and remove functions, which always
begin with a search from the pctrie root, with the use of pctrie
iterators to traverse and remove items from the pctrie of swapblks
without duplicating searches.  Take care to reset iterators after
reacquiring an object lock, since with the lock released they could be
invalidated.

Reviewed by:	alc, markj, kib
Tested by:	pho (previous versions)
Differential Revision:	https://reviews.freebsd.org/D46620
2024-09-29 11:38:53 -05:00
Doug Moore
76c60597fa swap_pager: use vm_page_iterators for lookup
Replace the use of page lookups and page next pointers in swap_pager.c
with vm_page iterators.

Reviewed by:	markj
Differential Revision:	https://reviews.freebsd.org/D46704
2024-09-28 16:46:40 -05:00
Konstantin Belousov
1784fb4449 vm_page_free_pages_toq(): return the count of freed pages
Reviewed by:	bnovkov
Sponsored by:	Advanced Micro Devices (AMD)
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D46820
2024-09-27 20:34:23 +03:00
Doug Moore
f1aaef47a0 swap_pager: update meta_free comment
Clarify the comment that introduces swp_page_meta_free.

Reviewed by:	markj, alc
Differential Revision:	https://reviews.freebsd.org/D46754
2024-09-23 13:27:54 -05:00
Doug Moore
940fec94b5 swap_pager: deoptimize swapoff_object
Undo a change in swap_pager_swapoff_object that assumed a swap block
would be valid after reacquiring a lock, when that validity cannot be
assumed.

Reviewed by:	markj
Differential Revision:	https://reviews.freebsd.org/D46753
2024-09-23 12:11:55 -05:00
Bojan Novković
29a6f8fd93 vm: Use VM_ALLOC_NOFREE when allocating bogus_page
Allocate the 'bogus_page' page using VM_ALLOC_NOFREE since
it never gets released.

Differential Revision:	https://reviews.freebsd.org/D46699
Reviewed by:	alc, markj, kib
2024-09-22 16:02:53 +02:00
Konstantin Belousov
0ecbb28ce3 vm_map: add vm_map_find_locked(9)
Reviewed by:	alc, markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D46678
2024-09-20 09:46:06 +03:00
Doug Moore
c3d743a67a vm_object: use reclaim callback to free pages
Instead of iterating over object->memq to free pages, use a callback
in VM_RADIX_PCTRIE_RECLAIM_CALLBACK to do it.

Reviewed by:	rlibby
Differential Revision:	https://reviews.freebsd.org/D45588
2024-09-19 15:23:19 -05:00
Doug Moore
450a6690f5 vm_radix: offer pctrie_iterator access
Add to the vm_radix and vm_page interfaces methods to use pctrie
iterators with vm_radix tries.

Reviewed by:	markj
Differential Revision:	https://reviews.freebsd.org/D46663
2024-09-19 11:49:40 -05:00
Doug Moore
bae517022c swap_pager: enhance meta_transfer comments
Clarify comments about what happens to source blocks in
swp_pager_meta_transfer.  No functional changes.

Reviewed by:	alc
Differential Revision:	https://reviews.freebsd.org/D46682
2024-09-16 00:31:11 -05:00
Doug Moore
4ccad54520 swap_pager: avoid meta_transfer race
Function swp_pager_meta_transfer expects that after dropping and
reacquiring an object lock, the swap block it's processing still
exists, and has not been removed from the trie and freed.  Rewrite to
avoid depending on that, by scrubbing, removing and freeing it before
releasing the lock.

Reviewed by:	alc, markj
Differential Revision:	https://reviews.freebsd.org/D46629
2024-09-15 01:00:00 -05:00
Doug Moore
4876924c0c vm_page: fuse two allocation loops
Combine two loops, each iterating over the same array of pages to
initialize them, into a single loop.

Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D46609
2024-09-12 23:41:01 -05:00
Doug Moore
9426470572 swap_pager: clean up pctrie usage
Define wrapper functions for the pctrie operations specific to
swap_pager, to hide some verbose details.  Separate the meta_transfer
and meta_free functions into separate functions.

Reviewed by:	kib (previous version)
Tested by:	pho (previous version)
Differential Revision:	https://reviews.freebsd.org/D46315
2024-09-09 16:44:13 -05:00
Doug Moore
6aede562b4 vm_phys: hide alloc_freelist_pages
Make vm_phys_alloc_freelist_pages static.  There are no longer any
callers outside of vm_phys.c.

Reviewed by:	alc, markj
Differential Revision:	https://reviews.freebsd.org/D46539
2024-09-05 11:17:53 -05:00
Doug Moore
d48524e21f dev_pager: define free_page for mgt devices
Callers of cdev_pager_free_page in the kernel always have object->type
== OBJT_MGTDEVICE. Define a function for them to call that skips the
runtime type check in cdev_pager_free.

Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D46389
2024-08-21 15:48:59 -05:00
Doug Moore
e413e15c1a swap_pager_freespace: fix freed count
Function swp_pager_meta_transfer uses 'pindex' as the start address of
the swblk in calculating which page to lookup in order to count freed
pages.  However, the lookup for a swblk at 'pindex' or greater may
produce one greater than 'pindex', given by sb->p, and that's the
value that should be used to compute a page adddress.

Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D46234
2024-08-07 03:37:18 -05:00
Konstantin Belousov
8bb6b413f6 vm/vm_pageout.c: eliminate write-only variable
PR:	280631
Fixes:	acb4cb33d3 (non-debug builds)
Sponsored by:	The FreeBSD Foundation
2024-08-05 18:07:18 +03:00
Doug Moore
acb4cb33d3 vm_pageout: simplify pageout_cluster
Rewrite vm_pageout_cluster to eliminate redundant variables and
duplicated code.

Remove tests on pindex to check for object boundary conditions, since
the page_next and page_prev functions return NULL at the object
boundaries. Fix an alignment error that could happen if pindex is
aligned, and the first of vm_pageout_page_count flushable pages, and
the page at pindex-1 is also flushable.

Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D46217
2024-08-04 15:32:15 -05:00
Alan Cox
fa290859fa vm: Assert that pagesizes[] is sorted
Ensure that pmap_init() properly initialized pagesizes[].  In part, we
are making this change to document the requirement that the non-zero
elements of pagesizes[] must be in ascending order.

Reviewed by:	kib, markj
2024-08-04 14:53:15 -05:00
Alan Cox
f6ed52c1f0 vm: Stop reducing vm_pageout_page_count at startup
Attempting to reduce vm_pageout_page_count at startup when the machine
has less than 8MB of physical memory is pointless, since we haven't run
on machines with so little memory in ages.

Reviewed by:	kib, markj
Differential Revision:	https://reviews.freebsd.org/D46206
2024-08-02 14:41:36 -05:00
Doug Moore
6d86bdf1c4 vm_pageout: shrink pageout array
The array passed to vm_pageout_flush, and constructed in a middle-out
fashion, can never use array element zero. Shrink the array by one,
and reduce indices by one, to save that bit of stack space. In the
vm_object version, make the accounting look more like the pageout
version.

Reported by:	alc
Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D46208
2024-08-01 21:36:44 -05:00
Bojan Novković
d9ce4c0b66 vm_page: Fix inconsistent use of VM_NOFREE_IMPORT_ORDER in vm_page_alloc_nofree_domain
Pass VM_NOFREE_IMPORT_ORDER to vm_phys_alloc_pages instead of
VM_LEVEL_0_ORDER when allocating a higher-order page for
the NOFREE page allocator.

Reported by:	alc
Fixes:	a8693e8
2024-07-30 19:25:37 +02:00
Bojan Novković
3f32a7e4ee vm: Add a KVA arena for M_NEVERFREED allocations
This patch adds a new KVA arena for separating M_NEVERFREED allocations.
Separating KVAs for pages that are never freed should facilitate
superpage promotion in the kernel.

Differential Revision:	https://reviews.freebsd.org/D45997
Reviewed by:	alc, kib, markj
Tested by:	alc
2024-07-30 17:38:24 +02:00
Bojan Novković
a8693e89e3 vm: Introduce vm_page_alloc_nofree_domain
This patch adds a reservation-aware bump allocator intended for
allocating NOFREE pages. The main goal of this change is to reduce the
long-term fragmentation issues caused by pages that are never freed during runtime.

The `vm_page_alloc_nofree_domain` routine hands out 0-order pages from
a preallocated superpage. Once an active NOFREE superpage fills up, the
routine will try to allocate a new one and discard the old one.
This routine will get invoked whenever VM_ALLOC_NOFREE is passed to
vm_page_alloc_noobj or vm_page_alloc.

Differential Revision:	https://reviews.freebsd.org/D45863
Reviewed by:	alc, kib, markj
Tested by:	alc
2024-07-30 17:38:24 +02:00
Bojan Novković
92b9138991 vm: Introduce VM_ALLOC_NOFREE and PG_NOFREE
This patch adds two additional vm_page flags to distinguish pages that
never get released while the system is running (e.g. UMA_ZONE_NOFREE slabs).

Differential Revision:	https://reviews.freebsd.org/D45970
Reviewed by:	alc, kib, markj
Tested by:	alc
2024-07-30 17:38:24 +02:00
Bojan Novković
78f3e0f6b3 malloc(9): Introduce M_NEVERFREED
This patch adds an additional malloc(9) flag to distinguish allocations
that are never freed during runtime.

Differential Revision:	https://reviews.freebsd.org/D45045
Reviewed by:	alc, kib, markj
Tested by:	alc
2024-07-30 17:38:18 +02:00
Doug Moore
4113ea3403 vm_object: speed up page collect flush
vm_pageout_cluster prepares an array for passing to vm_pageout_flush
by starting in the middle of a double-sized array and working out from
the middle. Using the same technique in vm_object_page_collect_flush
saves one loop that traverses a piece of linked list, and 80 bytes of
amd64 binary code.

Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D46173
2024-07-29 13:02:13 -05:00
Mark Johnston
6aa98f78cc conf: Remove kernel stack swapping support, part 12
Remove the NO_SWAPPING option.  There is still some code in
vm_swapout.c, but it relates to RACCT handling.  Remove the option and
make compilation of vm_swapout.c conditional on RACCT.

Tested by:	pho
Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D46130
2024-07-29 01:43:59 +00:00
Mark Johnston
ec84a986ba vm: Remove kernel stack swapping support, part 11
- Remove sysctls that control stack swapping, update documentation.
- Remove vm_swapout_dummy.c, which serves no purpose now.

Tested by:	pho
Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D46129
2024-07-29 01:43:59 +00:00
Mark Johnston
01518f5eed sleepqueue: Remove kernel stack swapping support, part 10
- Remove kick_proc0().
- Make the return type of sleepq_broadcast(), sleepq_signal(), etc.,
  void.
- Fix up callers.

Tested by:	pho
Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D46128
2024-07-29 01:43:59 +00:00
Mark Johnston
235750ee51 vm: Remove kernel stack swapping support, part 8
- The kernel stack objects do not need to be pageable, so use OBJT_PHYS
  objects instead.  The main difference is that mappings do not require
  PV entries.
- Make some externally visible functions, relating to kernel thread
  stack internals, private to vm_glue.c, as their external consumers are
  now gone.

Tested by:	pho
Reviewed by:	alc, kib
Differential Revision:	https://reviews.freebsd.org/D46119
2024-07-29 01:43:59 +00:00
Mark Johnston
472888018c proc: Remove kernel stack swapping support, part 6
- Remove most checks of the P_INMEM flag.
- Some uses remain since a few userspace tools, e.g., ps(1) and top(1)
  expect the flag to be set.  These can be cleaned up but the code has
  most likely been copy-pasted elsewhere and while linger for a long
  time.

Tested by:	pho
Reviewed by:	alc, imp, kib
Differential Revision:	https://reviews.freebsd.org/D46117
2024-07-29 01:43:18 +00:00
Mark Johnston
e24a655283 thread: Remove kernel stack swapping support, part 4
- Remove the IS_SWAPPED thread inhibitor state.
- Remove all uses of TD_IS_SWAPPED() in the kernel.
- Remove the TDF_CANSWAP flag.
- Remove the P_SWAPPINGOUT and P_SWAPPINGIN flags.

Tested by:	pho
Reviewed by:	alc, imp, kib
Differential Revision:	https://reviews.freebsd.org/D46115
2024-07-29 01:40:22 +00:00
Mark Johnston
8370e9dfa1 vm: Remove kernel stack swapping support, part 3
- Modify PHOLD() to no longer fault in the process.
- Remove _PHOLD_LITE(), which is now the same as _PHOLD(), fix up
  consumers.
- Remove faultin() and its callees.

Tested by:	pho
Reviewed by:	imp, kib
Differential Revision:	https://reviews.freebsd.org/D46114
2024-07-29 01:39:49 +00:00
Mark Johnston
0dd7789512 vm: Remove kernel stack swapping support, part 2
After mi_startup() finishes, thread0 becomes the "swapper", whose
responsibility is to swap threads back in on demand.  Now that threads
can't be swapped out, there is no use for this thread.  Just sleep
forever once sysinits are finished; thread_exit() doesn't work because
thread0 is allocated statically.  The thread could be repurposed if that
would be useful.

Tested by:	pho
Reviewed by:	alc, imp, kib
Differential Revision:	https://reviews.freebsd.org/D46113
2024-07-29 01:38:39 +00:00
Mark Johnston
13a1129d70 vm: Remove kernel stack swapping support, part 1
- Disconnect the swapout daemon from the page daemon.
- Remove swapout() and swapout_procs().

Tested by:	pho
Reviewed by:	alc, imp, kib
Differential Revision:	https://reviews.freebsd.org/D46112
2024-07-29 01:38:21 +00:00
Doug Moore
b3cec803ea vm_fault: avoid vm_page_next()
Where vm_fault calls vm_page_next, replace it with a use of TAILQ_NEXT
and a KASSERT.  This avoids needless computation in a NODEBUG kernel
and makes the error checking clearer in a GENERIC kernel.

Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D46168
2024-07-27 16:11:53 -05:00
Alan Cox
096dfa338d vm: Retire vm_page_alloc_freelist{,_domain}()
Once upon a time, I created vm_page_alloc_freelist{,_domain}() to
support faster allocation of pages that were mapped by the partial
direct map on 32-bit MIPS.  At the time, I expected that these
functions might find other uses too, but those other uses never
materialized.  So, these functions have not been used for some time
now.  Instead, people use the more general vm_page_alloc_contig().

Reviewed by:	kib, markj
Differential Revision:	https://reviews.freebsd.org/D46063
2024-07-24 14:31:40 -05:00
Alan Cox
cd836f6004 vm: Retire kmem_arena
It has simply been an alias for the kernel_arena for many years now.
Enough time has passed to retire it.  Any out-of-tree kernel modules
that directly use kmem_arena should switch to kernel_arena.

Reviewed by:	kib, markj
Differential Revision:	https://reviews.freebsd.org/D46057
2024-07-24 14:31:40 -05:00
Konstantin Belousov
45cde0e439 vm_page: add vm_page_clearref() helper
It is supposed to be used for ref_count manipulations when the pages
are owned by an object, but ref_count is used for something else than
the wiring, e.g. PTE population count on the page table page.

Reviewed by:	markj
Sponsored by:	Advanced Micro Devices (AMD)
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D45910
2024-07-15 09:15:50 +03:00
Alan Cox
772ae9eddf vm ASLR: Handle VM_NRESERV_LEVEL == 0
Some flavors of powerpc don't enable superpage reservations.

Fixes: 3e00c11a4f ("arm64: Support the L3 ATTR_CONTIGUOUS page ...")
2024-07-13 14:40:43 -05:00
Alan Cox
3e00c11a4f arm64: Support the L3 ATTR_CONTIGUOUS page size in pagesizes[]
Update pagesizes[] to include the L3 ATTR_CONTIGUOUS (L3C) page size,
which is 64KB when the base page size is 4KB and 2MB when the base page
size is 16KB.

Add support for L3C pages to shm_create_largepage().

Add support for creating L3C page mappings to pmap_enter(psind=1).

Add support for reporting L3C page mappings to mincore(2) and
procstat(8).

Update vm_fault_soft_fast() and vm_fault_populate() to handle multiple
superpage sizes.

Declare arm64 as supporting two superpage reservation sizes, and
simulate two superpage reservation sizes, updating the vm_page's psind
field to reflect the correct page size from pagesizes[].  (The next
patch in this series will replace this simulation.  This patch is
already big enough.)

Co-authored-by:	Eliot Solomon <ehs3@rice.edu>
Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D45766
2024-07-13 12:43:42 -05:00