From nobody Thu Dec 21 03:42:38 2023 X-Original-To: dev-commits-src-all@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 4Swbq23d5dz54DQF; Thu, 21 Dec 2023 03:42:38 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Swbq2384Rz4TmT; Thu, 21 Dec 2023 03:42:38 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1703130158; 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=j89ygOW3pYeEVx+0VQ3RlJSqq88leN6aKInIZ2XgqMQ=; b=oSgu1f7vFxPK3OMjdUnbh8nRRVlabXWzxX0yPFI5TkCCPFgeD6kIldTBPXIM2cHxyY9S3E Aul8d8Oz54pB3kmpvAZ6EJ2Ht3w2fihuC4/WW2c3T0vI80C/p/myq/VIjbkfTGuxU2PSDv BPaw+PS7t/zYFRZDy5oeSpRv3xJqW3UzgOiYNhRTQqfGUjcNpe68Irk4mMeNWTHNsavLdX tJF0L3anGsKXNX/ueG7HcxtPadQ10RQnlv4PM5jWUd4BuWm40f0/KWF9w0GMdTf/pn3oGG qVBGpAV5288qCFIvxCKiZnDRtTI085GzmF2hj9D1fMfkvwp+YP5kVSmGGcAiNw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1703130158; a=rsa-sha256; cv=none; b=ttBv6/oKj48wgn0gMLnzrSEIRhr8zw3lpe66aVPPL7Y+F4QJOIHWyVyCrpVvycP3G5VSTL JaxYs2WjPGsyJPjrewKFcVjKfQ6fyYue5tbvrsbG/jFfpa2pjPFOjygew26PGpQnIrNDma /XNL9lGogRQ/6//p8plYHczr9SjXKEZLexZoa/6l6zjyPOzySuiDGkD380bucU7piE1f/a AH1xAPtKLKmR5p7MsZHB609y/g8vCiq/V+x366c3W8y6M4hH5coflmWvIdnO7zC1oIpEqR cWwTFAe+YENqO+U7A8VjzksFuMnDGYgzikrW+urXHUTnGsjDTrCq+TrqFEuWTg== 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=1703130158; 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=j89ygOW3pYeEVx+0VQ3RlJSqq88leN6aKInIZ2XgqMQ=; b=Q1vrcAGpzMD6DOThwyMuCuW+I8MIr7QzHCR26ACG7Vo7cyLNCiLWLt3vK4V3FVl/9BSnn8 IOOIgkgIlOtoJVrltENkM7eRxC0u1Fyjp3jB6fi8KApqJTbE/Jo9I4uyEyhYDHfdyWyZgZ zNO1jG8p7n/4vrpBbFEe7+6XPGErPVB+e/tzUy0INTBdSGv23h6WppTRg9f243/Y1Z37L/ 7ZS3uoQCcXgMnmCpkSU+rYfA0n7Cu72vPFPKo3OX6U3ORxELR5M9r44PLv6aXzXeISSOa1 Qjuyqv6fC0fvtlNy5VJp/+Vz1gvFM9gkvc3HXclJrmoCAWzBT/0jiiocxQocnA== 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 4Swbq22Ccqz2PW; Thu, 21 Dec 2023 03:42:38 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 3BL3gcWa072201; Thu, 21 Dec 2023 03:42:38 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3BL3gcmN072198; Thu, 21 Dec 2023 03:42:38 GMT (envelope-from git) Date: Thu, 21 Dec 2023 03:42:38 GMT Message-Id: <202312210342.3BL3gcmN072198@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: 6dd15b7a233a - main - vm_phys; fix uncalled free_contig List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@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: 6dd15b7a233a87d0895cb6806ae13cfaf814b44c Auto-Submitted: auto-generated The branch main has been updated by dougm: URL: https://cgit.FreeBSD.org/src/commit/?id=6dd15b7a233a87d0895cb6806ae13cfaf814b44c commit 6dd15b7a233a87d0895cb6806ae13cfaf814b44c Author: Doug Moore AuthorDate: 2023-12-21 03:37:47 +0000 Commit: Doug Moore CommitDate: 2023-12-21 03:37:47 +0000 vm_phys; fix uncalled free_contig Function vm_phys_free_contig does not always free memory properly when the npages parameter is less than max block size. Change it so that it does. Note that this function is not currently invoked, and this error was not triggered in earlier versions of the code. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D42891 --- sys/vm/vm_phys.c | 38 ++++++++++++-------------------------- 1 file changed, 12 insertions(+), 26 deletions(-) diff --git a/sys/vm/vm_phys.c b/sys/vm/vm_phys.c index cd75ed092691..8c15f107c2f9 100644 --- a/sys/vm/vm_phys.c +++ b/sys/vm/vm_phys.c @@ -1169,24 +1169,6 @@ vm_phys_free_pages(vm_page_t m, int order) vm_freelist_add(fl, m, order, 1); } -/* - * Return the largest possible order of a set of pages starting at m. - */ -static int -max_order(vm_page_t m) -{ - - /* - * Unsigned "min" is used here so that "order" is assigned - * "VM_NFREEORDER - 1" when "m"'s physical address is zero - * or the low-order bits of its physical address are zero - * because the size of a physical address exceeds the size of - * a long. - */ - return (min(ffsll(VM_PAGE_TO_PHYS(m) >> PAGE_SHIFT) - 1, - VM_NFREEORDER - 1)); -} - /* * Free a contiguous, arbitrarily sized set of physical pages, without * merging across set boundaries. @@ -1211,7 +1193,7 @@ vm_phys_enqueue_contig(vm_page_t m, u_long npages) fl = (*seg->free_queues)[m->pool]; m_end = m + npages; /* Free blocks of increasing size. */ - lo = VM_PAGE_TO_PHYS(m) >> PAGE_SHIFT; + lo = atop(VM_PAGE_TO_PHYS(m)); if (m < m_end && (diff = lo ^ (lo + npages - 1)) != 0) { order = min(flsll(diff) - 1, VM_NFREEORDER - 1); @@ -1239,18 +1221,22 @@ vm_phys_enqueue_contig(vm_page_t m, u_long npages) void vm_phys_free_contig(vm_page_t m, u_long npages) { - int order_start, order_end; + vm_paddr_t lo; vm_page_t m_start, m_end; + unsigned max_order, order_start, order_end; vm_domain_free_assert_locked(vm_pagequeue_domain(m)); + lo = atop(VM_PAGE_TO_PHYS(m)); + max_order = min(flsll(lo ^ (lo + npages)) - 1, VM_NFREEORDER - 1); + m_start = m; - order_start = max_order(m_start); - if (order_start < VM_NFREEORDER - 1) + order_start = ffsll(lo) - 1; + if (order_start < max_order) m_start += 1 << order_start; m_end = m + npages; - order_end = max_order(m_end); - if (order_end < VM_NFREEORDER - 1) + order_end = ffsll(lo + npages) - 1; + if (order_end < max_order) m_end -= 1 << order_end; /* * Avoid unnecessary coalescing by freeing the pages at the start and @@ -1258,9 +1244,9 @@ vm_phys_free_contig(vm_page_t m, u_long npages) */ if (m_start < m_end) vm_phys_enqueue_contig(m_start, m_end - m_start); - if (order_start < VM_NFREEORDER - 1) + if (order_start < max_order) vm_phys_free_pages(m, order_start); - if (order_end < VM_NFREEORDER - 1) + if (order_end < max_order) vm_phys_free_pages(m_end, order_end); }