From nobody Thu Oct 06 22:05:38 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 4Mk59H0YcZz4VBTw; Thu, 6 Oct 2022 22:05:39 +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 4Mk59G71z4z3tDP; Thu, 6 Oct 2022 22:05:38 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1665093939; 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=TtMHnYpTFJMWgmb9E7v/xTLinLRaDxk0DGZ5H2xQze0=; b=TyPCB/eE3DWT6AgqSawRWww77NXLEP/Vt1gKmQtKUROOtOYC/Aup7ZtB8d9ayjpOqkiK0k HNhmlHDDsCOnVWSJWmvXMDACrZiobsz0T5W3Gc2ZzIVhHuzSlr0Xxahvzqp8cgFT5tYWfO BA8j6/+EOobB5PjWL15JYVezdZ+1Rdd9Clzn5E6z3roKmYSXZG7I/QlMwTLU7pMvFyDZwH FyGc99VVf8KC+ER5FSY/TX3EkKapqjLbhZ2sN65RUVh7JlhBxTVAZTuBDZ4IAE9V+sezbL 1EIasQJqsZI7dHLMyxFysz067jKO7YCfiMPw9131cnwhejnwCY275S/l6EKIRw== 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 4Mk59G5v3lzNml; Thu, 6 Oct 2022 22:05:38 +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 296M5ccv056111; Thu, 6 Oct 2022 22:05:38 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 296M5ciw056110; Thu, 6 Oct 2022 22:05:38 GMT (envelope-from git) Date: Thu, 6 Oct 2022 22:05:38 GMT Message-Id: <202210062205.296M5ciw056110@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mitchell Horne Subject: git: 95b1c2706977 - main - riscv: optimize MADV_WILLNEED on existing superpages 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: mhorne X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 95b1c27069775dd969cd045888b4ea5aeb53cb7f Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1665093939; 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=TtMHnYpTFJMWgmb9E7v/xTLinLRaDxk0DGZ5H2xQze0=; b=weJ6O6EyYCG+SNiL//Bbzi0qjxzAaCRLMiFpQU+qynZk0Tyyck7u2WcOo7gqcCO13urVel 1Hm/RzMo8cDPCln1N2SDbFc2U+OXFNNczBUp6GrL1nAoqzi+wnpW1WpVVNpFwEkFzXCbiM 8kSdrQD+pgYQ18fCMsNKdwKBnTukB/cjCnijVPULLl1StlHeW3DRfvunKnFiEsN2NGmd96 /2hDL9PiInN2jsSqYJNeKumIGo26Br6HbIxvj/mEkFdmbVCrYa3mN1D8c0WBWeHtnieTf7 +fmKtZZhYgp+OhCDOqcmAwMrGtDMUqED3kHcvXxn6UrjwBNUnoyeygeOR+4UwA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1665093939; a=rsa-sha256; cv=none; b=q4LnKaqmddB6fRtexRkKAHYcAbYQr8bu49UUehJwvu8nNRlhXr7ANB4Iok33Hs/xqwVpO3 OXE1kXcLTr5pcw/MOmSxfmJcK5+cn8bEXXJNRzF1RfX14xYnKQH8PseRgbYJYWjfqB3oXm yNqksVsOmZB0PZy+nymy2cg1J0EbdkvUWH3V4Zu1gBv89W14bf7yl2kD2kkMK5JG9PdVIm jfJf0kUh5x8aLvSkxyv1vI3wQXk5jI53szeYnM8dEZPs4rwhY3oKzolnuKq3HACB+wo+tC uiqxI0lkgWlMItng1v2aXwuuIFaYQoF9S9I2XGErk+r58nas6+7SXd8RM6CPTw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by mhorne: URL: https://cgit.FreeBSD.org/src/commit/?id=95b1c27069775dd969cd045888b4ea5aeb53cb7f commit 95b1c27069775dd969cd045888b4ea5aeb53cb7f Author: Mitchell Horne AuthorDate: 2022-10-05 17:10:45 +0000 Commit: Mitchell Horne CommitDate: 2022-10-06 22:02:38 +0000 riscv: optimize MADV_WILLNEED on existing superpages Specifically, avoid pointless calls to pmap_enter_quick_locked() when madvise(MADV_WILLNEED) is applied to an existing superpage mapping. 1d5ebad06c20 made the change for amd64 and arm64. Reviewed by: markj, alc MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D36563 --- sys/riscv/riscv/pmap.c | 51 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/sys/riscv/riscv/pmap.c b/sys/riscv/riscv/pmap.c index aa9eb5255c82..69f2a9ab1522 100644 --- a/sys/riscv/riscv/pmap.c +++ b/sys/riscv/riscv/pmap.c @@ -3120,13 +3120,12 @@ out: } /* - * Tries to create a read- and/or execute-only 2MB page mapping. Returns true - * if successful. Returns false if (1) a page table page cannot be allocated - * without sleeping, (2) a mapping already exists at the specified virtual - * address, or (3) a PV entry cannot be allocated without reclaiming another - * PV entry. + * Tries to create a read- and/or execute-only 2MB page mapping. Returns + * KERN_SUCCESS if the mapping was created. Otherwise, returns an error + * value. See pmap_enter_l2() for the possible error values when "no sleep", + * "no replace", and "no reclaim" are specified. */ -static bool +static int pmap_enter_2mpage(pmap_t pmap, vm_offset_t va, vm_page_t m, vm_prot_t prot, struct rwlock **lockp) { @@ -3144,18 +3143,20 @@ pmap_enter_2mpage(pmap_t pmap, vm_offset_t va, vm_page_t m, vm_prot_t prot, if (va < VM_MAXUSER_ADDRESS) new_l2 |= PTE_U; return (pmap_enter_l2(pmap, va, new_l2, PMAP_ENTER_NOSLEEP | - PMAP_ENTER_NOREPLACE | PMAP_ENTER_NORECLAIM, NULL, lockp) == - KERN_SUCCESS); + PMAP_ENTER_NOREPLACE | PMAP_ENTER_NORECLAIM, NULL, lockp)); } /* * Tries to create the specified 2MB page mapping. Returns KERN_SUCCESS if - * the mapping was created, and either KERN_FAILURE or KERN_RESOURCE_SHORTAGE - * otherwise. Returns KERN_FAILURE if PMAP_ENTER_NOREPLACE was specified and - * a mapping already exists at the specified virtual address. Returns - * KERN_RESOURCE_SHORTAGE if PMAP_ENTER_NOSLEEP was specified and a page table - * page allocation failed. Returns KERN_RESOURCE_SHORTAGE if - * PMAP_ENTER_NORECLAIM was specified and a PV entry allocation failed. + * the mapping was created, and one of KERN_FAILURE, KERN_NO_SPACE, or + * KERN_RESOURCE_SHORTAGE otherwise. Returns KERN_FAILURE if + * PMAP_ENTER_NOREPLACE was specified and a 4KB page mapping already exists + * within the 2MB virtual address range starting at the specified virtual + * address. Returns KERN_NO_SPACE if PMAP_ENTER_NOREPLACE was specified and a + * 2MB page mapping already exists at the specified virtual address. Returns + * KERN_RESOURCE_SHORTAGE if either (1) PMAP_ENTER_NOSLEEP was specified and a + * page table page allocation failed or (2) PMAP_ENTER_NORECLAIM was specified + * and a PV entry allocation failed. * * The parameter "m" is only used when creating a managed, writeable mapping. */ @@ -3183,11 +3184,19 @@ pmap_enter_l2(pmap_t pmap, vm_offset_t va, pd_entry_t new_l2, u_int flags, KASSERT(l2pg->ref_count > 1, ("pmap_enter_l2: l2pg's ref count is too low")); if ((flags & PMAP_ENTER_NOREPLACE) != 0) { - l2pg->ref_count--; - CTR2(KTR_PMAP, - "pmap_enter_l2: failed to replace existing mapping" - " for va %#lx in pmap %p", va, pmap); - return (KERN_FAILURE); + if ((oldl2 & PTE_RWX) != 0) { + l2pg->ref_count--; + CTR2(KTR_PMAP, + "pmap_enter_l2: no space for va %#lx" + " in pmap %p", va, pmap); + return (KERN_NO_SPACE); + } else { + l2pg->ref_count--; + CTR2(KTR_PMAP, "pmap_enter_l2:" + " failed to replace existing mapping" + " for va %#lx in pmap %p", va, pmap); + return (KERN_FAILURE); + } } SLIST_INIT(&free); if ((oldl2 & PTE_RWX) != 0) @@ -3280,6 +3289,7 @@ pmap_enter_object(pmap_t pmap, vm_offset_t start, vm_offset_t end, vm_offset_t va; vm_page_t m, mpte; vm_pindex_t diff, psize; + int rv; VM_OBJECT_ASSERT_LOCKED(m_start->object); @@ -3293,7 +3303,8 @@ pmap_enter_object(pmap_t pmap, vm_offset_t start, vm_offset_t end, va = start + ptoa(diff); if ((va & L2_OFFSET) == 0 && va + L2_SIZE <= end && m->psind == 1 && pmap_ps_enabled(pmap) && - pmap_enter_2mpage(pmap, va, m, prot, &lock)) + ((rv = pmap_enter_2mpage(pmap, va, m, prot, &lock)) == + KERN_SUCCESS || rv == KERN_NO_SPACE)) m = &m[L2_SIZE / PAGE_SIZE - 1]; else mpte = pmap_enter_quick_locked(pmap, va, m, prot, mpte,