Commit graph

4650 commits

Author SHA1 Message Date
Mark Johnston
09d0e6b74a vm_object: Fix a kernel memory disclosure via the vm_object list sysctl
Reported by:	Chris J-D <chris@accessvector.net>
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit b050ee6c97)
2023-01-23 08:50:31 -05:00
Konstantin Belousov
7c09d62011 Handle ERELOOKUP from VOP_FSYNC() in several other places
(cherry picked from commit 6189672e60)
2023-01-22 11:18:09 +02:00
Konstantin Belousov
40c2681893 vm_object.c: minor style
(cherry picked from commit 70e1b11216)
2023-01-22 11:18:09 +02:00
Konstantin Belousov
c9e7aae6e6 vm_pager_allocate(): override resulting object type
Tested by:	pho

(cherry picked from commit cd086696c2)
2023-01-20 05:19:41 +02:00
Konstantin Belousov
aaac643676 vm_page_grab_valid(): clear *mp in case of pager denying page allocation
Tested by:	pho

(cherry picked from commit 3249449190)
2023-01-20 05:19:35 +02:00
Konstantin Belousov
7d05e01b3e vm_pager: add method to veto page allocation
Tested by:	pho

(cherry picked from commit ec201dddfb)
2023-01-20 05:19:29 +02:00
Konstantin Belousov
6219bd0436 vm_pager: add methods for page insertion and removal notifications
Tested by:	pho

(cherry picked from commit d537d1f12e)
2023-01-20 05:19:22 +02:00
Konstantin Belousov
e2d3dbe4ce tmpfs: make vm_object point to the tmpfs node instead of vnode
Tested by:	pho

(cherry picked from commit d9dc64f158)
2023-01-20 05:19:17 +02:00
Konstantin Belousov
d81d67edb1 Provide consistent prototype for swp_pager_meta_free()
Tested by:	pho

(cherry picked from commit 645510e62e)
2023-01-20 05:19:12 +02:00
Konstantin Belousov
86ea175ec2 Make swap_pager_freespace() global
Tested by:	pho

(cherry picked from commit baa1ccceef)
2023-01-20 05:19:07 +02:00
Mitchell Horne
25ba314991 ddb: don't limit pindex output in 'show vmopag'
This command already prints a tremendous amount of output, and properly
obeys the pager. It no longer makes sense to arbitrarily limit the pages
that are printed, as the reader will not be aware that this has
happened.

Reviewed by:	markj
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D37361

(cherry picked from commit 03d6764b38)
2022-11-14 13:04:12 -04:00
John Baldwin
32560694f7 Fix various places which cast a pointer to a vm_paddr_t or vice versa.
GCC warns about the mismatched sizes on i386 where vm_paddr_t is 64
bits.

Reviewed by:	imp, markj
Differential Revision:	https://reviews.freebsd.org/D36750

(cherry picked from commit a9fca3b987)
2022-11-11 10:18:53 -08:00
Konstantin Belousov
3e21b50930 Add vm_page_any_valid()
(cherry picked from commit 934bfc128e)
2022-10-26 03:43:43 +03:00
Mark Johnston
5019af2e87 uma: Never pass cache zones to memguard
Items allocated from cache zones cannot usefully be protected by
memguard.

PR:		267151
Reported and tested by:	pho

(cherry picked from commit 2dba2288aa)
2022-10-25 20:35:31 -04:00
Mark Johnston
6094749a1a vm_page: Fix a logic error in the handling of PQ_ACTIVE operations
As an optimization, vm_page_activate() avoids requeuing a page that's
already in the active queue.  A page's location in the active queue is
mostly unimportant.

When a page is unwired and placed back in the page queues,
vm_page_unwire() avoids moving pages out of PQ_ACTIVE to honour the
request, the idea being that they're likely mapped and so will simply
get bounced back in to PQ_ACTIVE during a queue scan.

In both cases, if the page was logically in PQ_ACTIVE but had not yet
been physically enqueued (i.e., the page is in a per-CPU batch), we
would end up clearing PGA_REQUEUE from the page.  Then, batch processing
would ignore the page, so it would end up unwired and not in any queues.
This can arise, for example, when a page is allocated and then
vm_page_activate() is called multiple times in quick succession.  The
result is that the page is hidden from the page daemon, so while it will
be freed when its VM object is destroyed, it cannot be reclaimed under
memory pressure.

Fix the bug: when checking if a page is in PQ_ACTIVE, only perform the
optimization if the page is physically enqueued.

PR:		256507
Fixes:		f3f38e2580 ("Start implementing queue state updates using fcmpset loops.")
Reviewed by:	alc, kib
Sponsored by:	E-CARD Ltd.
Sponsored by:	Klara, Inc.

(cherry picked from commit 2c9dc2384f)
2022-10-12 09:49:25 -04:00
Konstantin Belousov
74ffdb90e9 vm/vm.h: cleanup
(cherry picked from commit 55c5216582)
2022-09-30 03:29:10 +03:00
Konstantin Belousov
fc15cf8786 swap_pager: style, wrap long lines
(cherry picked from commit 26eed2aa06)
2022-09-30 03:29:09 +03:00
Konstantin Belousov
d19687c97d vm_overcommit: put into __read_mostly section
(cherry picked from commit ccdaa1ab1c)
2022-09-30 03:29:09 +03:00
Konstantin Belousov
28c771673f vm: make vm.overcommit available externally
(cherry picked from commit a6cc4c6e98)
2022-09-30 03:29:09 +03:00
Mark Johnston
3ea8c7ad90 vm_fault: Shoot down shared mappings in vm_fault_copy_entry()
As in vm_fault_cow(), it's possible, albeit rare, for multiple vm_maps
to share a shadow object.  When copying a page from a backing object
into the shadow, all mappings of the source page must therefore be
removed.  Otherwise, future operations on the object tree may detect
that the source page is fully shadowed and thus can be freed.

Approved by:	so
Security:	FreeBSD-SA-22:11.vm
Reviewed by:	alc, kib
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D35635

(cherry picked from commit 5c50e900ad)
2022-08-09 15:47:40 -04:00
Alan Cox
02e43a0d05 swap_pager: Reduce the scope of the object lock in putpages
We don't need to hold the object lock while allocating swap space, so
don't.

Reviewed by:	dougm, kib, markj
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D35839

(cherry picked from commit 54291f7d65)
2022-08-07 22:16:10 -05:00
Mark Johnston
01d3ddbfcf vm_mmap: Remove obsolete code and comments from vm_mmap()
In preparation for removing OBJT_DEFAULT, eliminate some stale/unhelpful
comments from vm_mmap(), and remove an unused case.  In particular, the
remaining callers of vm_mmap() in the tree do not specify OBJT_DEFAULT.

It's much more common to use vm_map_find() to map an object into user
memory, so rather than adjusting vm_mmap() to handle OBJT_SWAP objects,
let's further discourage its use and simply remove OBJT_DEFAULT
handling.

Reviewed by:	dougm, alc, kib
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit eee9aab9cb)
2022-07-27 09:50:55 -04:00
Mark Johnston
d529f396b7 vm_fault: Fix some nits in vm_fault_copy_entry()
- Correct the description (vm_fault_copy_entry() does not create a
  shadow object).
- Move some initialization and assertions out of the scope of the object
  locks, when doing so makes sense.
- Merge a pair of conditional blocks.
- Use __unused when appropriate.

No functional change intended.

Reviewed by:	alc
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit b57be759d0)
2022-07-25 09:44:45 -04:00
Mark Johnston
adc4dcada3 uma: Use a taskqueue to execute uma_timeout()
uma_timeout() has several responsibilities; it visits every UMA zone and
as of recently will drain underutilized caches, so is rather expensive
(>1ms in some cases).  Currently it is executed by softclock threads
and so will preempt most other CPU activity.  None of this work requires
a high scheduling priority, though, so defer it to a taskqueue so as to
avoid stalling higher-priority work.

Reviewed by:	rlibby, alc, mav, kib
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 93cd28ea82)
2022-07-25 09:43:44 -04:00
Mark Johnston
0a356f1eb9 vm_object: Assert that overcommit charge is released in the object dtor
Reviewed by:	alc, kib
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit e1979b45b6)
2022-07-19 09:36:32 -04:00
Mark Johnston
709550b451 vm_map: Simplify a call to vm_object_allocate_anon()
vm_object_allocate_anon() automatically sets "charge" to 0 if no cred
reference is provided, so the caller doesn't need any conditional logic.

No functional change intended.

Reviewed by:	alc, kib
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 70b2996120)
2022-07-19 09:36:21 -04:00
Doug Moore
48d01e24f9 vm_addr_ok: add power2 invariant check
With INVARIANTS defined, have vm_addr_align_ok and vm_addr_bound_ok
panic when passed an alignment/boundary parameter that is not a power
of two.

Reviewed by:	alc
Suggested by:	kib, se
Differential Revision:	https://reviews.freebsd.org/D33725

(cherry picked from commit ae13829ddc)
2022-07-12 11:26:12 -05:00
Doug Moore
6f387a5632 vm_reserv: #include vm_extern.h explicitly, for arm.
Fixes:	c606ab59e7 vm_extern: use standard address checkers everywhere
(cherry picked from commit f76916c095)
2022-07-12 11:26:06 -05:00
Doug Moore
bf27b9bc7f vm_phys: convert error back to warning
Move an assignment back to where it was before, to turn the
defined-but-not-used error back into a set-but-not-used warning.

Fixes:	01e115ab83 vm_phys: #include vm_extern
(cherry picked from commit e6930b1c5f)
2022-07-12 11:26:05 -05:00
Doug Moore
87e6f3d27e vm_phys: #include vm_extern
Arm64 and powerpc don't include vm_extern.h indirectly in vm_phys.c, which
means that for the sake of those architectures, it must be included explicitly.

Also, fix a set-unused warning that jenkins also found.

Reported by:	Jenkins
Fixes:	c606ab59e7 vm_extern: use standard address checkers everywhere

(cherry picked from commit 01e115ab83)
2022-07-12 11:26:04 -05:00
Doug Moore
c5a5a9dbcf vm_extern: use standard address checkers everywhere
Define simple functions for alignment and boundary checks and use them
everywhere instead of having slightly different implementations
scattered about. Define them in vm_extern.h and use them where
possible where vm_extern.h is included.

Reviewed by:	kib, markj
Differential Revision:	https://reviews.freebsd.org/D33685

(cherry picked from commit c606ab59e7)
2022-07-12 11:26:03 -05:00
Doug Moore
b1290f4746 vm_reserv: use enhanced bitstring for popmaps
vm_reserv.c uses its own bitstring implemenation for popmaps. Using
the bitstring_t type from a standard header eliminates the code
duplication, allows some bit-at-a-time operations to be replaced with
more efficient bitstring range operations, and, in
vm_reserv_test_contig, allows bit_ffc_area_at to more efficiently
search for a big-enough set of consecutive zero-bits.

Make bitstring changes improve the vm_reserv code.  Define a bit_ntest
method to test whether a range of bits is all set, or all clear.
Define bit_ff_at and bit_ff_area_at to implement the ffs and ffc
versions with a parameter to choose between set- and clear- bits.
Improve the area_at implementation.  Modify the bit_nset and
bit_nclear implementations to allow code optimization in the cases
when start or end are multiples of _BITSTR_BITS.

Add a few new cases to bitstring_test.

Discussed with:	alc
Reviewed by:	markj
Tested by:	pho (earlier version)
Differential Revision:	https://reviews.freebsd.org/D33312

(cherry picked from commit 84e2ae64c5)
2022-07-11 00:54:06 -05:00
Doug Moore
88a5d20e90 vm: alloc pages from reserv before breaking it
Function vm_reserv_reclaim_contig breaks a reservation with enough
free space to satisfy an allocation request and returns the free space
to the buddy allocator. Change the function to allocate the request
memory from the reservation before breaking it, and return that memory
to the caller. That avoids a second call to the buddy allocator and
guarantees successful allocation after breaking the reservation, where
that success is not currently guaranteed.

Reviewed by:	alc, kib (previous version)
Differential Revision:	https://reviews.freebsd.org/D33644

(cherry picked from commit 0d5fac2872)
2022-07-11 00:41:07 -05:00
Doug Moore
b52d35520c Fix clerical error in page alloc
Fix a very recent change that introduced a page accounting error in
case of a reserveration being broken.
Reviewed by:	alc
Fixes:	fb38b29b56 (page_alloc_br) vm_page: Remove extra test, dup code from page alloc
Differential Revision:	https://reviews.freebsd.org/D33645

(cherry picked from commit 184c63db3c)
2022-07-11 00:41:06 -05:00
Doug Moore
a8d3ef5bc6 vm_page: Remove extra test from page alloc
Extract code from vm_page_alloc_contig_domain into a new function.  Do
so in a way that eliminates a bound-to-fail reservation test after a
reservation is broken by a call from vm_page_alloc_contig_domain.

Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D33551

(cherry picked from commit fb38b29b56)
2022-07-11 00:41:05 -05:00
Doug Moore
86299ec1c4 vm_phys: hide vm_phys_set_pool
It is only called in the file that defines it, so make it static and
remove the declaration from the header.

Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D33688

(cherry picked from commit 8119cdd38b)
2022-07-11 00:41:04 -05:00
Mark Johnston
de0b1239df vm: Fix racy checks for swap objects
Commit 4b8365d752 introduced the ability to dynamically register
VM object types, for use by tmpfs, which creates swap-backed objects.
As a part of this, checks for such objects changed from

  object->type == OBJT_DEFAULT || object->type == OBJT_SWAP

to

  object->type == OBJT_DEFAULT || (object->flags & OBJ_SWAP) != 0

In particular, objects of type OBJT_DEFAULT do not have OBJ_SWAP set;
the swap pager sets this flag when converting from OBJT_DEFAULT to
OBJT_SWAP.

A few of these checks are done without the object lock held.  It turns
out that this can result in false negatives since the swap pager
converts objects like so:

  object->type = OBJT_SWAP;
  object->flags |= OBJ_SWAP;

Fix the problem by adding explicit tests for OBJT_SWAP objects in
unlocked checks.

PR:		258932
Fixes:		4b8365d752 ("Add OBJT_SWAP_TMPFS pager")
Reported by:	bdrewery
Reviewed by:	kib
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit e123264e4d)
2022-07-04 09:06:55 -04:00
Mark Johnston
cc81b8661d vm_fault: Fix a racy copy of page valid bits
We do not hold the object lock or a page busy lock when copying src_m's
validity state.  Prior to commit 45d72c7d7f we marked dst_m as fully
valid.

Use the source object's read lock to ensure that valid bits are not
concurrently cleared.

Reviewed by:	alc, kib
Fixes:		45d72c7d7f ("vm_fault_copy_entry: accept invalid source pages.")
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit d0443e2b98)
2022-06-29 10:12:34 -04:00
Mark Johnston
3fe539651a vm_fault: Avoid unnecessary object relocking in vm_fault_copy_entry()
Suggested by:	alc
Reviewed by:	alc, kib
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 1f88394b7f)
2022-06-29 10:12:34 -04:00
Mark Johnston
c75a5bc2f6 vm_object: Use the vm_object_(set|clear)_flag() helpers
... rather than setting and clearing flags inline.  No functional change
intended.

Reviewed by:	alc, kib
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 630f633f2a)
2022-06-21 08:53:24 -04:00
Gordon Bergling
d44793af7e vm_page: Fix a typo in a source code comment
- s/consistancy/consistency/

(cherry picked from commit f77a88c855)
2022-06-10 14:30:17 +02:00
Gordon Bergling
59f3ff80f5 vm: Fix a common typo in a source code comment
- s/independant/independent/

(cherry picked from commit 860740ae0f)
2022-06-10 14:25:56 +02:00
John Baldwin
0c1258e707 Add a VA_IS_CLEANMAP() macro.
This macro returns true if a provided virtual address is contained
in the kernel's clean submap.

In CHERI kernels, the buffer cache and transient I/O map are allocated
as separate regions.  Abstracting this check reduces the diff relative
to FreeBSD.  It is perhaps slightly more readable as well.

Reviewed by:	kib
Obtained from:	CheriBSD
Sponsored by:	DARPA
Differential Revision:	https://reviews.freebsd.org/D28710

(cherry picked from commit 67932460c7)
2022-05-10 10:47:07 -07:00
Mark Johnston
11eac05a40 vm: Move the "vm_wait in early boot" assertion to the proper place
The assertion was added in commit 1771e987ca.  After that, vm_wait()
and friends were refactored such that the actual sleep happens
elsewhere.  Now the assertion condition is not checked when
vm_wait_doms() is called directly, and it is checked even if we are not
going to sleep (because vm_page_count_min_set(wdoms) is false).

Reviewed by:	alc, kib
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 6fb7c42d59)
2022-04-21 09:18:14 -04:00
Mark Johnston
9a4e701578 vm: Initialize the transient buffer mapping arena with M_WAITOK
The wait flag is passed to UMA when allocating boundary tags for the
initial span, and UMA expects either M_WAITOK or M_NOWAIT to be present.

Reported by:	cperciva
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit f82177b8cf)
2022-04-21 09:18:04 -04:00
Mark Johnston
f9677b7e74 uma: Don't allow a limit to be set in a warm zone
The limit accounting in UMA does not tolerate this.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit d53927b0ba)
2022-04-13 08:10:35 -04:00
Gordon Bergling
6265d53f90 memguard(9): Fix two typos in source code comments
- s/comparsion/comparison/

(cherry picked from commit f167c46e79)
2022-04-09 08:08:00 +02:00
Mark Johnston
229eff21b7 uma: Use the correct type for a return value
zone_alloc_bucket() returns a pointer, not a bool.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 54361f9020)
2022-04-06 20:30:45 -04:00
Mark Johnston
13ba1d2836 vm_pageout: Print a more accurate message to the console before an OOM kill
Previously we'd always print "out of swap space."  This can be
misleading, as there are other reasons an OOM kill can be triggered.  In
particular, it's entirely possible to trigger an OOM kill on a system
with plenty of free swap space.

Reviewed by:	kib
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 4a864f624a)
2022-02-28 09:06:58 -05:00
Hans Petter Selasky
6bf4f9268f uma: Add UMA_ZONE_UNMANAGED
Allow a zone to opt out of cache size management.  In particular,
uma_reclaim() and uma_reclaim_domain() will not reclaim any memory from
the zone, nor will uma_timeout() purge cached items if the zone is idle.
This effectively means that the zone consumer has control over when
items are reclaimed from the cache.  In particular, uma_zone_reclaim()
will still reclaim cached items from an unmanaged zone.

Reviewed by:	hselasky, kib
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D34142

(cherry picked from commit 389a3fa693)
2022-02-24 10:59:28 +01:00