From nobody Wed Jun 25 19:10:15 2025 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4bSBGc3p54z60Pbj; Wed, 25 Jun 2025 19:10:16 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4bSBGc29hfz3fgR; Wed, 25 Jun 2025 19:10:16 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1750878616; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=fmNsZ7OiybNIg6u4aAP0ysJdBC4SnXQwIcg1zW62tJE=; b=cdeUNXog/MGCYA20jUK7marT77wig0x6+5cSltEV/PsyYaFcJr4/9ULLsIkgMGYleG6pd7 qp1fKXhlJOUArK5atP8dhVeSOr/yzmV5DqU6o+lKthDx1CgTgjdTHVxyyObHQpWoeixOrH wmCS1mTL5bLBYmneV+IoQNsWO2guOWRn2UMWuPatjiItFdZv7OagAiQH1Jw5Jztx4GWokT mM//QYWM24tyfOcN14uupQqgXdNnnUy9beoG4PLSbXmdj49Pvy2tpyvZUtkcnN2lTItvcA 0whSyCWDiE8qUN0NhGaacVsU9C2tkIQudZUxJSP56B744kKcyEwtEiahByrBaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1750878616; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=fmNsZ7OiybNIg6u4aAP0ysJdBC4SnXQwIcg1zW62tJE=; b=Kph4LmIewe/T4pRS79Y817Z65NeyfY3Be8oQhZMFXX7DZxZx++2I9P2rlXLB+v/V0tGT5t 0amVV9lSWdICi0NwlqDiLLBkY8Zmu0uNNUe695eCDrnEocgHbenWTceFvPtB0ctHu6RlOT q5OBlyhM6wjzEfcLkcbv0CBDzGJ+x3zMQa173a1Ygcel9y1oQkZJAukoikZGYnS26I3FHg gD6RzyK+7z0ccZI+GPS8w1oFJTBBKWtgbBmIcl/pLFjPr5WzB/8cNWyiy4fKagBzu4/RCD bEcZws9SUUvoJQx1NRryTj37k/R0kkhiYJjNKo2ejjjx9CiIie6CluMpS6lpNQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1750878616; a=rsa-sha256; cv=none; b=mEbH38Ceq/O/QXetkPVsaWe2l088VKS8rReAr4MhCaTvHWk6iPMplqn8L5T8HWn/Wb40qg yo3B6KYH3bfWuRjSKEjQytrUz+Lalby38rmul9MP7PN+mEe2Wu+IIBh6/Eh0yR++/UXCVZ rr1vb/jVgzy7xMCkeaxuqcAQVu2s6RtWPwgC11n0/F9ZrbhDQJygTLDYg9DwAAsveEaHNM kcFgYLHAckH5rtRqDqe5Qx73cU82z4xdfb8MzqUvBSyLQwGiUCry/kAqaYYdXDVvWGukL3 PCyvMuFGQ2YkRYO0867zCHChIES9zVOUBKvm5iwJL4a4glDtUj7ynUTkhg7qYw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4bSBGb72LCzVFH; Wed, 25 Jun 2025 19:10:15 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 55PJAFaO076813; Wed, 25 Jun 2025 19:10:15 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 55PJAF9S076800; Wed, 25 Jun 2025 19:10:15 GMT (envelope-from git) Date: Wed, 25 Jun 2025 19:10:15 GMT Message-Id: <202506251910.55PJAF9S076800@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Alan Cox Subject: git: 07297aee35f2 - main - vm_page: update comments and KASSERT()s concerning page allocation List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: alc X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 07297aee35f26cfd37aef078ff6c0cbe67bbba15 Auto-Submitted: auto-generated The branch main has been updated by alc: URL: https://cgit.FreeBSD.org/src/commit/?id=07297aee35f26cfd37aef078ff6c0cbe67bbba15 commit 07297aee35f26cfd37aef078ff6c0cbe67bbba15 Author: Alan Cox AuthorDate: 2025-06-19 05:45:42 +0000 Commit: Alan Cox CommitDate: 2025-06-25 19:09:49 +0000 vm_page: update comments and KASSERT()s concerning page allocation Update the legend describing the arguments to the most commonly used page allocation functions. Notably, eliminate a reference to a function that no longer exists; and update to reflect the elimination of VM_ALLOC_NOOBJ, specifically, VM_ALLOC_WAITOK is no longer a legal option to vm_page_alloc{,_contig}(). Eliminate a nonsensical KASSERT(). VM_ALLOC_SBUSY is forbidden as an argument to vm_page_alloc_noobj{,_contig,}_domain() by a KASSERT(), so having a different KASSERT() that tests for it is nonsensical. Strengthen other KASSERT()s involving VM_ALLOC_NOBUSY and VM_ALLOC_NOFREE. Reviewed by: kib, markj, dougm (an earlier version) Differential Revision: https://reviews.freebsd.org/D49391 --- sys/vm/vm_page.c | 55 ++++++++++++++++++++++++++++++++----------------------- sys/vm/vm_page.h | 36 +++++++++++++++++++----------------- 2 files changed, 51 insertions(+), 40 deletions(-) diff --git a/sys/vm/vm_page.c b/sys/vm/vm_page.c index 5b05f0dc11c9..bbae55895c2c 100644 --- a/sys/vm/vm_page.c +++ b/sys/vm/vm_page.c @@ -1983,7 +1983,10 @@ vm_page_iter_rename(struct pctrie_iter *old_pages, vm_page_t m, * intends to allocate * VM_ALLOC_NOBUSY do not exclusive busy the page * VM_ALLOC_NODUMP do not include the page in a kernel core dump + * VM_ALLOC_NOFREE page will never be freed + * VM_ALLOC_NOWAIT ignored (default behavior) * VM_ALLOC_SBUSY shared busy the allocated page + * VM_ALLOC_WAITFAIL in case of failure, sleep before returning * VM_ALLOC_WIRED wire the allocated page * VM_ALLOC_ZERO prefer a zeroed page */ @@ -2081,11 +2084,12 @@ vm_page_alloc_domain_iter(vm_object_t object, vm_pindex_t pindex, int domain, vm_page_t m; int flags; -#define VPA_FLAGS (VM_ALLOC_CLASS_MASK | VM_ALLOC_WAITFAIL | \ - VM_ALLOC_NOWAIT | VM_ALLOC_NOBUSY | \ - VM_ALLOC_SBUSY | VM_ALLOC_WIRED | \ - VM_ALLOC_NODUMP | VM_ALLOC_ZERO | \ - VM_ALLOC_NOFREE | VM_ALLOC_COUNT_MASK) +#define VM_ALLOC_COMMON (VM_ALLOC_CLASS_MASK | VM_ALLOC_NODUMP | \ + VM_ALLOC_NOWAIT | VM_ALLOC_WAITFAIL | \ + VM_ALLOC_WIRED | VM_ALLOC_ZERO) +#define VPA_FLAGS (VM_ALLOC_COMMON | VM_ALLOC_COUNT_MASK | \ + VM_ALLOC_NOBUSY | VM_ALLOC_NOFREE | \ + VM_ALLOC_SBUSY) KASSERT((req & ~VPA_FLAGS) == 0, ("invalid request %#x", req)); KASSERT(((req & (VM_ALLOC_NOBUSY | VM_ALLOC_SBUSY)) != @@ -2234,15 +2238,18 @@ found: * * allocation classes: * VM_ALLOC_NORMAL normal process request - * VM_ALLOC_SYSTEM system *really* needs a page + * VM_ALLOC_SYSTEM system *really* needs the pages * VM_ALLOC_INTERRUPT interrupt time request * * optional allocation flags: - * VM_ALLOC_NOBUSY do not exclusive busy the page - * VM_ALLOC_NODUMP do not include the page in a kernel core dump - * VM_ALLOC_SBUSY shared busy the allocated page - * VM_ALLOC_WIRED wire the allocated page - * VM_ALLOC_ZERO prefer a zeroed page + * VM_ALLOC_NOBUSY do not exclusive busy the pages + * VM_ALLOC_NODUMP do not include the pages in a kernel core dump + * VM_ALLOC_NORECLAIM do not reclaim after initial failure + * VM_ALLOC_NOWAIT ignored (default behavior) + * VM_ALLOC_SBUSY shared busy the allocated pages + * VM_ALLOC_WAITFAIL in case of failure, sleep before returning + * VM_ALLOC_WIRED wire the allocated pages + * VM_ALLOC_ZERO prefer zeroed pages */ vm_page_t vm_page_alloc_contig(vm_object_t object, vm_pindex_t pindex, int req, @@ -2321,7 +2328,9 @@ vm_page_alloc_contig_domain(vm_object_t object, vm_pindex_t pindex, int domain, vm_page_t m, m_ret, mpred; u_int busy_lock, flags, oflags; -#define VPAC_FLAGS (VPA_FLAGS | VM_ALLOC_NORECLAIM) +#define VPAC_FLAGS (VM_ALLOC_COMMON | VM_ALLOC_COUNT_MASK | \ + VM_ALLOC_NOBUSY | VM_ALLOC_NORECLAIM | \ + VM_ALLOC_SBUSY) KASSERT((req & ~VPAC_FLAGS) == 0, ("invalid request %#x", req)); KASSERT(((req & (VM_ALLOC_NOBUSY | VM_ALLOC_SBUSY)) != @@ -2422,11 +2431,8 @@ vm_page_alloc_noobj_domain(int domain, int req) vm_page_t m; int flags; -#define VPAN_FLAGS (VM_ALLOC_CLASS_MASK | VM_ALLOC_WAITFAIL | \ - VM_ALLOC_NOWAIT | VM_ALLOC_WAITOK | \ - VM_ALLOC_NOBUSY | VM_ALLOC_WIRED | \ - VM_ALLOC_NODUMP | VM_ALLOC_ZERO | \ - VM_ALLOC_NOFREE | VM_ALLOC_COUNT_MASK) +#define VPAN_FLAGS (VM_ALLOC_COMMON | VM_ALLOC_COUNT_MASK | \ + VM_ALLOC_NOFREE | VM_ALLOC_WAITOK) KASSERT((req & ~VPAN_FLAGS) == 0, ("invalid request %#x", req)); @@ -2624,15 +2630,13 @@ vm_page_alloc_noobj_contig_domain(int domain, int req, u_long npages, vm_page_t m, m_ret; u_int flags; -#define VPANC_FLAGS (VPAN_FLAGS | VM_ALLOC_NORECLAIM) +#define VPANC_FLAGS (VM_ALLOC_COMMON | VM_ALLOC_COUNT_MASK | \ + VM_ALLOC_NORECLAIM | VM_ALLOC_WAITOK) KASSERT((req & ~VPANC_FLAGS) == 0, ("invalid request %#x", req)); KASSERT((req & (VM_ALLOC_WAITOK | VM_ALLOC_NORECLAIM)) != (VM_ALLOC_WAITOK | VM_ALLOC_NORECLAIM), ("invalid request %#x", req)); - KASSERT(((req & (VM_ALLOC_NOBUSY | VM_ALLOC_SBUSY)) != - (VM_ALLOC_NOBUSY | VM_ALLOC_SBUSY)), - ("invalid request %#x", req)); KASSERT(npages > 0, ("vm_page_alloc_contig: npages is zero")); while ((m_ret = vm_page_find_contig_domain(domain, req, npages, @@ -5141,15 +5145,20 @@ vm_page_grab_valid_unlocked(vm_page_t *mp, vm_object_t object, * allocation classes: * VM_ALLOC_NORMAL normal process request * VM_ALLOC_SYSTEM system *really* needs the pages + * VM_ALLOC_INTERRUPT interrupt time request * * The caller must always specify that the pages are to be busied and/or * wired. * * optional allocation flags: * VM_ALLOC_IGN_SBUSY do not sleep on soft busy pages - * VM_ALLOC_NOBUSY do not exclusive busy the page + * VM_ALLOC_NOBUSY do not exclusive busy the pages + * VM_ALLOC_NODUMP do not include the pages in a kernel core dump + * VM_ALLOC_NOFREE pages will never be freed * VM_ALLOC_NOWAIT do not sleep - * VM_ALLOC_SBUSY set page to sbusy state + * VM_ALLOC_SBUSY set pages to sbusy state + * VM_ALLOC_WAITFAIL in case of failure, sleep before returning + * VM_ALLOC_WAITOK ignored (default behavior) * VM_ALLOC_WIRED wire the pages * VM_ALLOC_ZERO zero and validate any invalid pages * diff --git a/sys/vm/vm_page.h b/sys/vm/vm_page.h index ba3f88864661..8f2d5aee3cd4 100644 --- a/sys/vm/vm_page.h +++ b/sys/vm/vm_page.h @@ -462,13 +462,15 @@ extern long first_page; /* first physical page number */ vm_page_t PHYS_TO_VM_PAGE(vm_paddr_t pa); /* - * Page allocation parameters for vm_page for the functions - * vm_page_alloc(), vm_page_grab(), vm_page_alloc_contig() and - * vm_page_alloc_freelist(). Some functions support only a subset - * of the flags, and ignore others, see the flags legend. + * vm_page allocation arguments for the functions vm_page_alloc(), + * vm_page_alloc_contig(), vm_page_alloc_noobj(), vm_page_grab(), and + * vm_page_grab_pages(). Each function supports only a subset of the flags. + * See the flags legend. * - * The meaning of VM_ALLOC_ZERO differs slightly between the vm_page_alloc*() - * and the vm_page_grab*() functions. See these functions for details. + * The meaning of VM_ALLOC_ZERO varies: vm_page_alloc_noobj(), vm_page_grab(), + * and vm_page_grab_pages() guarantee that the returned pages are zeroed; in + * contrast vm_page_alloc() and vm_page_alloc_contig() do not, leaving it to + * the caller to test the page's flags for PG_ZERO. * * Bits 0 - 1 define class. * Bits 2 - 15 dedicated for flags. @@ -476,7 +478,7 @@ vm_page_t PHYS_TO_VM_PAGE(vm_paddr_t pa); * (a) - vm_page_alloc() supports the flag. * (c) - vm_page_alloc_contig() supports the flag. * (g) - vm_page_grab() supports the flag. - * (n) - vm_page_alloc_noobj() and vm_page_alloc_freelist() support the flag. + * (n) - vm_page_alloc_noobj() supports the flag. * (p) - vm_page_grab_pages() supports the flag. * Bits above 15 define the count of additional pages that the caller * intends to allocate. @@ -485,26 +487,26 @@ vm_page_t PHYS_TO_VM_PAGE(vm_paddr_t pa); #define VM_ALLOC_INTERRUPT 1 #define VM_ALLOC_SYSTEM 2 #define VM_ALLOC_CLASS_MASK 3 -#define VM_ALLOC_WAITOK 0x0008 /* (acn) Sleep and retry */ -#define VM_ALLOC_WAITFAIL 0x0010 /* (acn) Sleep and return error */ +#define VM_ALLOC_WAITOK 0x0008 /* (gnp) Sleep and retry */ +#define VM_ALLOC_WAITFAIL 0x0010 /* (acgnp) Sleep and return error */ #define VM_ALLOC_WIRED 0x0020 /* (acgnp) Allocate a wired page */ #define VM_ALLOC_ZERO 0x0040 /* (acgnp) Allocate a zeroed page */ #define VM_ALLOC_NORECLAIM 0x0080 /* (c) Do not reclaim after failure */ -#define VM_ALLOC_NOFREE 0x0100 /* (an) Page will never be released */ +#define VM_ALLOC_NOFREE 0x0100 /* (agnp) Page will never be freed */ #define VM_ALLOC_NOBUSY 0x0200 /* (acgp) Do not excl busy the page */ -#define VM_ALLOC_NOCREAT 0x0400 /* (gp) Don't create a page */ +#define VM_ALLOC_NOCREAT 0x0400 /* (gp) Do not allocate a page */ #define VM_ALLOC_AVAIL1 0x0800 -#define VM_ALLOC_IGN_SBUSY 0x1000 /* (gp) Ignore shared busy flag */ -#define VM_ALLOC_NODUMP 0x2000 /* (ag) don't include in dump */ +#define VM_ALLOC_IGN_SBUSY 0x1000 /* (gp) Ignore shared busy state */ +#define VM_ALLOC_NODUMP 0x2000 /* (acgnp) Do not include in dump */ #define VM_ALLOC_SBUSY 0x4000 /* (acgp) Shared busy the page */ #define VM_ALLOC_NOWAIT 0x8000 /* (acgnp) Do not sleep */ #define VM_ALLOC_COUNT_MAX 0xffff #define VM_ALLOC_COUNT_SHIFT 16 #define VM_ALLOC_COUNT_MASK (VM_ALLOC_COUNT(VM_ALLOC_COUNT_MAX)) -#define VM_ALLOC_COUNT(count) ({ \ - KASSERT((count) <= VM_ALLOC_COUNT_MAX, \ - ("%s: invalid VM_ALLOC_COUNT value", __func__)); \ - (count) << VM_ALLOC_COUNT_SHIFT; \ +#define VM_ALLOC_COUNT(count) ({ /* (acgn) Additional pages */ \ + KASSERT((count) <= VM_ALLOC_COUNT_MAX, \ + ("%s: invalid VM_ALLOC_COUNT value", __func__)); \ + (count) << VM_ALLOC_COUNT_SHIFT; \ }) #ifdef M_NOWAIT