From nobody Mon Mar 31 04:02:16 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 4ZQyBc6xL4z5sYsV; Mon, 31 Mar 2025 04:02: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 4ZQyBc4D1rz3r27; Mon, 31 Mar 2025 04:02:16 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1743393736; 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=6irpxaR4+g9Un9aWaPUBS/ZCd54824fsQqxNmMAV9y4=; b=hcdT3UYv0EPsEpnTD0c0y1y9II2a81abTP4bCpcMXZw+bOwWdox1qE1iHEFxbbHNLA8Xw6 TnouOf8ZC34ykn3RDqM28T+q0J0C3sIyLXq1swPqE5iU/mjlnFfbve0aX4bdnDwbRlK5Fy lMppwoUA/Y5HhCmlJms/uZON7R+8bB6WhHYGIHBQ0z7mZVGB6ykmrewHkOGbgKiVIMiHRI FSOQkNFjJxH89ConqceEu29hc8tNPgRa8GTVDPMckNgKO2aynjiFahJybyOJ39nyaKgrUO JiKr79kzNgvRrUegBEjg9UbsC40a3/Z4AtnlCyerhSTALPuRjYRP3hTt9l88gw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1743393736; a=rsa-sha256; cv=none; b=TL5hpjze6FUNMhD46YbptYOeDwJWlRhZ2RmCqCRFCKAoCTU5a+iecCd1AZbZrbf9h4FW6m xM3ihTDfPGL/Sp3MNfAkwUPmCShtojnCGDpCD0U1h54DRX4ggvnXYGW33M24f2UFFSiYZ4 Fiu/A3NGInpF+9i6XxRR7TleNrCN26Nx4k0S3F+msSeVsMFjVBqUNH1R4zpLvCvj2pp7Ve RKlwkCRGfdDYsnfepUo8CWe4WewijztMxqOQ8SyzUQEcpXWnOU34g+L/CFXqIZ1LAqDQh6 sHAOznNjPSIgjqQU7pZf1oFOF7STLdef7RhvLuYEzR2dBeIM9I+m1hKp+phWGw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1743393736; 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=6irpxaR4+g9Un9aWaPUBS/ZCd54824fsQqxNmMAV9y4=; b=ZgjwfSL7BAYAAoj6Oe7LCPU29isCoMCsp81UwffbZdmivVAjIP35RPK9aVwGzgg6v4zL+e b1ZtwSOqf/RcXiDptWQW4gJzzTnhYLO5EdWFbOffoBROdNc9hjb/mWgty3zeNEg9zaRWJK 2wQIr0R+2ZSM1Knr+alj+U5Ce7L3hA5aJkqfV/juIOGuuu1LmiMPI/3ZbdCurXO11swZRo OYCCN32O8K0lkT3q1uL9Ak1uopQQ6VPICFgFhbT54HEnhqBZOLzsHsKBHPaqhiZ8XjrdnU YMW0VpRPyWBxvl9pWcV15UQ7MDzH230MfPyEf0nybDNSR0I2oq8N5bZ+40ACfw== 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 4ZQyBc3fjbzDLk; Mon, 31 Mar 2025 04:02:16 +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 52V42Ghp016938; Mon, 31 Mar 2025 04:02:16 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 52V42G5A016935; Mon, 31 Mar 2025 04:02:16 GMT (envelope-from git) Date: Mon, 31 Mar 2025 04:02:16 GMT Message-Id: <202503310402.52V42G5A016935@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Doug Moore Subject: git: b68c7ebf5e63 - main - vm_reserv: extract common gap-checking code 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: dougm X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: b68c7ebf5e633549dfda1cfa25991b097dfbcdce Auto-Submitted: auto-generated The branch main has been updated by dougm: URL: https://cgit.FreeBSD.org/src/commit/?id=b68c7ebf5e633549dfda1cfa25991b097dfbcdce commit b68c7ebf5e633549dfda1cfa25991b097dfbcdce Author: Doug Moore AuthorDate: 2025-03-31 04:00:53 +0000 Commit: Doug Moore CommitDate: 2025-03-31 04:00:53 +0000 vm_reserv: extract common gap-checking code vm_reserv_alloc_contig and vm_reserv_alloc_page both have code to determine whether a new reservation will fit between the predecessor and successor. Extract this code into a separate function rather than having it appear twice. Optimize slightly to avoid checking object size limit when there is a successor, and to avoid checking the upper bound at all when the size to be allocated is a multiple of reservation size. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D49460 --- sys/vm/vm_reserv.c | 175 ++++++++++++++++++++++++----------------------------- 1 file changed, 80 insertions(+), 95 deletions(-) diff --git a/sys/vm/vm_reserv.c b/sys/vm/vm_reserv.c index 3dc278851cc9..e553d115a6d4 100644 --- a/sys/vm/vm_reserv.c +++ b/sys/vm/vm_reserv.c @@ -549,6 +549,73 @@ vm_reserv_has_pindex(vm_reserv_t rv, vm_pindex_t pindex) return (((pindex - rv->pindex) & ~(VM_LEVEL_0_NPAGES - 1)) == 0); } +/* + * How many pages should be in a new allocation that starts at the first page of + * the reservation superpage that contains 'first', fits between the allocations + * that include 'mpred' and 'msucc', fits within 'object', includes at least + * 'minpages' pages, and tries to include every allocated page in a superpage? + * + * We must synchronize with the reserv object lock to protect the pindex/object + * of the resulting reservations against rename while we are inspecting. + */ +static u_long +vm_reserv_num_alloc_pages(vm_object_t object, vm_pindex_t first, + u_long minpages, vm_page_t mpred, vm_page_t msucc) +{ + vm_pindex_t leftcap, rightcap; + vm_reserv_t rv; + u_int allocpages; + + allocpages = roundup2(minpages, VM_LEVEL_0_NPAGES); + + vm_reserv_object_lock(object); + if (mpred != NULL) { + if ((rv = vm_reserv_from_page(mpred))->object != object) + leftcap = mpred->pindex + 1; + else + leftcap = rv->pindex + VM_LEVEL_0_NPAGES; + if (leftcap > first) + allocpages = 0; + } + if (minpages < allocpages) { + if (msucc == NULL) { + /* + * Would the last new reservation extend past the end of + * the object? + * + * If the object is unlikely to grow don't allocate a + * reservation for the tail. + */ + if ((object->flags & OBJ_ANON) == 0) + rightcap = object->size; + else + rightcap = OBJ_MAX_SIZE; + } else { + /* + * Would the last new reservation extend past the start + * of another page or reservation? + * + * If the object would, don't allocate a reservation for + * the tail. + */ + if ((rv = vm_reserv_from_page(msucc))->object != object) + rightcap = msucc->pindex; + else + rightcap = rv->pindex; + } + if (first + allocpages > rightcap) { + /* + * A reservation for the last of the requested pages + * will not fit. Reduce the size of the upcoming + * allocation accordingly. + */ + allocpages = minpages; + } + } + vm_reserv_object_unlock(object); + return (allocpages); +} + /* * Increases the given reservation's population count. Moves the reservation * to the tail of the partially populated reservation queue. @@ -623,9 +690,9 @@ vm_reserv_alloc_contig(vm_object_t object, vm_pindex_t pindex, int domain, struct vm_domain *vmd; vm_paddr_t pa, size; vm_page_t m, m_ret, msucc; - vm_pindex_t first, leftcap, rightcap; + vm_pindex_t first; vm_reserv_t rv; - u_long allocpages, maxpages, minpages; + u_long allocpages; int i, index, n; VM_OBJECT_ASSERT_WLOCKED(object); @@ -690,63 +757,14 @@ out: } /* - * Could at least one reservation fit between the first index to the - * left that can be used ("leftcap") and the first index to the right - * that cannot be used ("rightcap")? - * - * We must synchronize with the reserv object lock to protect the - * pindex/object of the resulting reservations against rename while - * we are inspecting. + * Check whether an allocation including at least one reservation can + * fit between mpred and msucc. */ first = pindex - VM_RESERV_INDEX(object, pindex); - minpages = VM_RESERV_INDEX(object, pindex) + npages; - maxpages = roundup2(minpages, VM_LEVEL_0_NPAGES); - allocpages = maxpages; - vm_reserv_object_lock(object); - if (mpred != NULL) { - if ((rv = vm_reserv_from_page(mpred))->object != object) - leftcap = mpred->pindex + 1; - else - leftcap = rv->pindex + VM_LEVEL_0_NPAGES; - if (leftcap > first) { - vm_reserv_object_unlock(object); - return (NULL); - } - } - if (msucc != NULL) { - if ((rv = vm_reserv_from_page(msucc))->object != object) - rightcap = msucc->pindex; - else - rightcap = rv->pindex; - if (first + maxpages > rightcap) { - if (maxpages == VM_LEVEL_0_NPAGES) { - vm_reserv_object_unlock(object); - return (NULL); - } - - /* - * At least one reservation will fit between "leftcap" - * and "rightcap". However, a reservation for the - * last of the requested pages will not fit. Reduce - * the size of the upcoming allocation accordingly. - */ - allocpages = minpages; - } - } - vm_reserv_object_unlock(object); - - /* - * Would the last new reservation extend past the end of the object? - * - * If the object is unlikely to grow don't allocate a reservation for - * the tail. - */ - if ((object->flags & OBJ_ANON) == 0 && - first + maxpages > object->size) { - if (maxpages == VM_LEVEL_0_NPAGES) - return (NULL); - allocpages = minpages; - } + allocpages = vm_reserv_num_alloc_pages(object, first, + VM_RESERV_INDEX(object, pindex) + npages, mpred, msucc); + if (allocpages < VM_LEVEL_0_NPAGES) + return (NULL); /* * Allocate the physical pages. The alignment and boundary specified @@ -817,7 +835,7 @@ vm_reserv_alloc_page(vm_object_t object, vm_pindex_t pindex, int domain, { struct vm_domain *vmd; vm_page_t m, msucc; - vm_pindex_t first, leftcap, rightcap; + vm_pindex_t first; vm_reserv_t rv; int index; @@ -859,45 +877,12 @@ out: } /* - * Could a reservation fit between the first index to the left that - * can be used and the first index to the right that cannot be used? - * - * We must synchronize with the reserv object lock to protect the - * pindex/object of the resulting reservations against rename while - * we are inspecting. + * Check whether an allocation including reservations can fit + * between mpred and msucc. */ first = pindex - VM_RESERV_INDEX(object, pindex); - vm_reserv_object_lock(object); - if (mpred != NULL) { - if ((rv = vm_reserv_from_page(mpred))->object != object) - leftcap = mpred->pindex + 1; - else - leftcap = rv->pindex + VM_LEVEL_0_NPAGES; - if (leftcap > first) { - vm_reserv_object_unlock(object); - return (NULL); - } - } - if (msucc != NULL) { - if ((rv = vm_reserv_from_page(msucc))->object != object) - rightcap = msucc->pindex; - else - rightcap = rv->pindex; - if (first + VM_LEVEL_0_NPAGES > rightcap) { - vm_reserv_object_unlock(object); - return (NULL); - } - } - vm_reserv_object_unlock(object); - - /* - * Would the last new reservation extend past the end of the object? - * - * If the object is unlikely to grow don't allocate a reservation for - * the tail. - */ - if ((object->flags & OBJ_ANON) == 0 && - first + VM_LEVEL_0_NPAGES > object->size) + if (vm_reserv_num_alloc_pages(object, first, 1, mpred, msucc) < + VM_LEVEL_0_NPAGES) return (NULL); /*