From nobody Mon Jul 11 05:41:26 2022 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 F34C01D03937; Mon, 11 Jul 2022 05:41:26 +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 4LhCRp6dp1z404x; Mon, 11 Jul 2022 05:41:26 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1657518086; 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=YsBShOq64lCqeuXYIniET23K9VAhA7KquesiUedzPn0=; b=gptUKm1yNde1jyum8P85d2akDll8TB5N4FPMf1LDRhr7tEOpBjZkw4XQp9uPc/otH9bHaS 04cK9oXVPc18aWMpHf4J5MPIwhJ4NSbbCZ27M+1AfM5+CXje69P99jWTzV8hedLJ+q71A8 wnypgZ4SeMcUL/IwKXkK0AyC54ntNy46XEqd2x5BQD/F2VKql4Ml4SW4uZ4HdHFSbGObpC BjFjNyNHZ+cJSl6AJSglAoui5cti2J+myr+APB/KqL03c7BkUesJLmDzhWunVNsdsUd3IY t3AaDMuFDODlJt+FxiLp7v9oOMrlXEiikxWmJ6Qh7dbbP3P2zeEM8iUKSmfhmw== 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 4LhCRp5l03zsWv; Mon, 11 Jul 2022 05:41:26 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 26B5fQG7048626; Mon, 11 Jul 2022 05:41:26 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 26B5fQKk048625; Mon, 11 Jul 2022 05:41:26 GMT (envelope-from git) Date: Mon, 11 Jul 2022 05:41:26 GMT Message-Id: <202207110541.26B5fQKk048625@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Doug Moore Subject: git: 88a5d20e9043 - stable/13 - vm: alloc pages from reserv before breaking it 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/stable/13 X-Git-Reftype: branch X-Git-Commit: 88a5d20e90438735cb456ba04055c26073c12057 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1657518086; 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=YsBShOq64lCqeuXYIniET23K9VAhA7KquesiUedzPn0=; b=flKtWBL08+//EfRvZZ3wD6uCpvmrdHP7g07kk4nGYtnPuWvitqr9eYxHUKWwk7Sc/4f0la Y9gZuuI+/8R0EPCiHYUzviPXz/LIiQXAJQKh0KaMvDHnvguaSsbcbB7aiUQqxlbasVB0a4 TYixO1RsO5nxakdDWdSxlpdwy+mMVH9E3qWC0w1CHyfNqK9b32c3X9T3XRbh50Cab4PHBf L61rRD9KPMZwSYOTTamUM7l1XU3iqGQ3G2zXwpp8cYOlnnhS60VKn4BL/VPjFZa0UwDh/9 IIOoVXyqjWw/wNb3c9t782Jq75TPKLjY3FMJm/pOmNPS+Mfg0Iwuu7lD2FVK9Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1657518086; a=rsa-sha256; cv=none; b=M2cDyxO8vmwuYbGqUca9PD15obrGKS4Uux0WGPeRjV7yqqSDL1cNR7RbB34I69Rq8Vs2fo BX8wnsTP9m2lwkpQ7+0Z6Tbo5IrLSs4yycz2DCbmtt8+XjlxW2DTdZMGl4/XZir/RtNQEY VQnq31RrcsXsu5DTP+SM45rSeilEGErlisk6aeZ3YKWAINYrTy3tbxscZBFVqEpBs17n0L RsPxi5bUOONJFEXezSzRISGNw6lCq3fp1Dm0v+Dc7ZCZduyyd6Iwb57jvqtVcHch0r/p2Q 9OgaEQXMjpSBA71GbWHoS1ELXLzeXWJQ2wbxxLCEy9QztB7ev0KFiOzaI4NO1A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by dougm: URL: https://cgit.FreeBSD.org/src/commit/?id=88a5d20e90438735cb456ba04055c26073c12057 commit 88a5d20e90438735cb456ba04055c26073c12057 Author: Doug Moore AuthorDate: 2021-12-24 18:59:16 +0000 Commit: Doug Moore CommitDate: 2022-07-11 05:41:07 +0000 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 0d5fac287294490ac488d74e598e019334610bdb) --- sys/vm/vm_page.c | 16 ++++++---------- sys/vm/vm_reserv.c | 23 ++++++++++++++--------- sys/vm/vm_reserv.h | 2 +- 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/sys/vm/vm_page.c b/sys/vm/vm_page.c index 4db88c91cba4..546d2ad1997d 100644 --- a/sys/vm/vm_page.c +++ b/sys/vm/vm_page.c @@ -2195,9 +2195,6 @@ vm_page_find_contig_domain(int domain, int req, u_long npages, vm_paddr_t low, vm_page_t m_ret; vmd = VM_DOMAIN(domain); -#if VM_NRESERVLEVEL > 0 -again: -#endif if (!vm_domain_allocate(vmd, req, npages)) return (NULL); /* @@ -2209,17 +2206,16 @@ again: vm_domain_free_unlock(vmd); if (m_ret != NULL) return (m_ret); - vm_domain_freecnt_inc(vmd, npages); #if VM_NRESERVLEVEL > 0 /* - * Try to break a reservation to replenish free page queues - * in a way that allows the allocation to succeed. + * Try to break a reservation to allocate the pages. */ - if (vm_reserv_reclaim_contig(domain, npages, low, - high, alignment, boundary)) - goto again; + if ((m_ret = vm_reserv_reclaim_contig(domain, npages, low, + high, alignment, boundary)) != NULL) + return (m_ret); #endif - return (m_ret); + vm_domain_freecnt_inc(vmd, npages); + return (NULL); } vm_page_t diff --git a/sys/vm/vm_reserv.c b/sys/vm/vm_reserv.c index f3344f8a9cd2..b4902942224d 100644 --- a/sys/vm/vm_reserv.c +++ b/sys/vm/vm_reserv.c @@ -1312,12 +1312,13 @@ vm_reserv_find_contig(vm_reserv_t rv, int npages, int lo, * contiguous physical memory. If a satisfactory reservation is found, it is * broken. Returns true if a reservation is broken and false otherwise. */ -bool +vm_page_t vm_reserv_reclaim_contig(int domain, u_long npages, vm_paddr_t low, vm_paddr_t high, u_long alignment, vm_paddr_t boundary) { struct vm_reserv_queue *queue; vm_paddr_t pa, size; + vm_page_t m_ret; vm_reserv_t marker, rv, rvn; int hi, lo, posn, ppn_align, ppn_bound; @@ -1333,7 +1334,7 @@ vm_reserv_reclaim_contig(int domain, u_long npages, vm_paddr_t low, * no boundary-constrained allocation is possible. */ if (size > boundary && boundary > 0) - return (false); + return (NULL); marker = &vm_rvd[domain].marker; queue = &vm_rvd[domain].partpop; /* @@ -1387,18 +1388,22 @@ vm_reserv_reclaim_contig(int domain, u_long npages, vm_paddr_t low, posn = vm_reserv_find_contig(rv, (int)npages, lo, hi, ppn_align, ppn_bound); if (posn >= 0) { - pa = VM_PAGE_TO_PHYS(&rv->pages[posn]); + vm_reserv_domain_scan_unlock(domain); + /* Allocate requested space */ + rv->popcnt += npages; + while (npages-- > 0) + popmap_set(rv->popmap, posn + npages); + vm_reserv_reclaim(rv); + vm_reserv_unlock(rv); + m_ret = &rv->pages[posn]; + pa = VM_PAGE_TO_PHYS(m_ret); KASSERT((pa & (alignment - 1)) == 0, ("%s: adjusted address does not align to %lx", __func__, alignment)); KASSERT(((pa ^ (pa + size - 1)) & -boundary) == 0, ("%s: adjusted address spans boundary to %jx", __func__, (uintmax_t)boundary)); - - vm_reserv_domain_scan_unlock(domain); - vm_reserv_reclaim(rv); - vm_reserv_unlock(rv); - return (true); + return (m_ret); } vm_reserv_domain_lock(domain); rvn = TAILQ_NEXT(rv, partpopq); @@ -1406,7 +1411,7 @@ vm_reserv_reclaim_contig(int domain, u_long npages, vm_paddr_t low, } vm_reserv_domain_unlock(domain); vm_reserv_domain_scan_unlock(domain); - return (false); + return (NULL); } /* diff --git a/sys/vm/vm_reserv.h b/sys/vm/vm_reserv.h index bb6175f2f464..18377fb98cf1 100644 --- a/sys/vm/vm_reserv.h +++ b/sys/vm/vm_reserv.h @@ -59,7 +59,7 @@ void vm_reserv_init(void); bool vm_reserv_is_page_free(vm_page_t m); int vm_reserv_level(vm_page_t m); int vm_reserv_level_iffullpop(vm_page_t m); -bool vm_reserv_reclaim_contig(int domain, u_long npages, +vm_page_t vm_reserv_reclaim_contig(int domain, u_long npages, vm_paddr_t low, vm_paddr_t high, u_long alignment, vm_paddr_t boundary); bool vm_reserv_reclaim_inactive(int domain);