From nobody Fri Dec 24 19:04:44 2021 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 3B5FE190623D; Fri, 24 Dec 2021 19:04:45 +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 4JLGhX6Rjpz3KWy; Fri, 24 Dec 2021 19:04:44 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 BCD02EC3; Fri, 24 Dec 2021 19:04:44 +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 1BOJ4iRW059307; Fri, 24 Dec 2021 19:04:44 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1BOJ4iBE059306; Fri, 24 Dec 2021 19:04:44 GMT (envelope-from git) Date: Fri, 24 Dec 2021 19:04:44 GMT Message-Id: <202112241904.1BOJ4iBE059306@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: 0d5fac287294 - main - vm: alloc pages from reserv before breaking it 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: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: 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: 0d5fac287294490ac488d74e598e019334610bdb Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1640372684; 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=pyTaRBXwc4xkpwRrRuH5Qxc6Q8ZmGqydwD+ta80RgMU=; b=qNj7nu3N/5mf6xf8krsHg2yhFXwdhXSMLdOh1gHHOP1pRlzEE+MFa4fTjqhrWDAS583tZa ghmEm1GLUwLiY58/mrbVq3wpCV5Ou7UwR9xCAMs7oIoWl/D3nzVl7g/GGpg6hERpLlJ5GM tC/3PiNWTdcG4G6YqvWgdVt5nofoHy6goEpS3MZzCguELAIufpjCdsYbVUlTqfiFsu3s0B fytGAp7BXVUqhrsN7A6IZEww8n61TFXyWAmw65YQAEOJX5H+w4dZt7yjLJiiZSeCLTusKA 7ggxCpP/FrTy4+NLZWI2YuUB10+XVZiRAkENhpmpo/jC/wOR1AM9Uf6GJ+EiKQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1640372684; a=rsa-sha256; cv=none; b=grQDvfZdb54f5BCdyIVCR1O+A6KPgld+LouZ4uxiHtrgRiaPiGY+IRFmDkXSvG4a/D4FVR 1lUdzifPFK2mH0skNvJUh2lTqbXARYqgo7UQvhI2l+ih310YjDBHpV5yKFVcWk0sS+DFmW /nvvAj0z2i6IMCrm49lcmdYXgIhm7FMg1tbdLMIK1QDDZ1ZvXMo+37ACTpcCWi0vcKzIMq pDYKzba/4L9blZUKaretjKAHv1o1RXKjrkXPNBGWFOXE1aCpV4+dUFtTXaH0XL7Rm80PB3 1wyXo8UeOZLQ1w6tGj7pqIrhSGFkxlo5yQcT2CF8J1HHisYqAYwMqK5f0ZDLSw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by dougm: URL: https://cgit.FreeBSD.org/src/commit/?id=0d5fac287294490ac488d74e598e019334610bdb commit 0d5fac287294490ac488d74e598e019334610bdb Author: Doug Moore AuthorDate: 2021-12-24 18:59:16 +0000 Commit: Doug Moore CommitDate: 2021-12-24 18:59:16 +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 --- sys/vm/vm_page.c | 20 +++++++++----------- sys/vm/vm_reserv.c | 23 ++++++++++++++--------- sys/vm/vm_reserv.h | 2 +- 3 files changed, 24 insertions(+), 21 deletions(-) diff --git a/sys/vm/vm_page.c b/sys/vm/vm_page.c index 03351b0ad3dd..89fa9df9ef42 100644 --- a/sys/vm/vm_page.c +++ b/sys/vm/vm_page.c @@ -2186,9 +2186,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); /* @@ -2200,18 +2197,19 @@ 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 ((req & VM_ALLOC_NORECLAIM) == 0 && - vm_reserv_reclaim_contig(domain, npages, low, - high, alignment, boundary)) - goto again; + if ((req & VM_ALLOC_NORECLAIM) == 0) { + m_ret = vm_reserv_reclaim_contig(domain, npages, low, + high, alignment, boundary); + if (m_ret != 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 d578d67dbe59..3709283c5556 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) - return (false); + return (NULL); marker = &vm_rvd[domain].marker; queue = &vm_rvd[domain].partpop; /* @@ -1386,18 +1387,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); @@ -1405,7 +1410,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);