From nobody Thu Oct 13 14:09:54 2022 X-Original-To: dev-commits-src-branches@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 4MpBH65yG6z4g2jd; Thu, 13 Oct 2022 14:09:54 +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 4MpBH65R7Gz3KfH; Thu, 13 Oct 2022 14:09:54 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1665670194; 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=Gx8cysozuLVuDyG9U+CoBeSR3JOFAPCdxdqisXpITLQ=; b=PuM4i0DzaGBZUhq8Cpiv/VrkSzcH5eCnOjvkXCy4zYmollJofC1ZWE5tNj9R4TMGYnylng /18J5VDWlvci8vAoeTnG3tmiQu1R7kPx+Hkdfu0O2Yy7aAGzASEP2oHJTVLRIv5ZdusVFy RPTGE4hPOebqsFdPRtnF++rFp1lXDWlAXdVr3ovTY09vQQ+BlsiQ7+UNcr6zDvasMQrysQ WSYBjRWwimpOJ/v9LQBY+LOM6dRakd6XtRNlIq841G62vzQ3kr2GXWD6C9q5SsRhWSV9OC ZETxMeoDrFnnOkZo77bU8nF+RVFgzakNYg/siljQfXShIEYEdCVsoxF7krJFfA== 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 4MpBH64PgBzRMk; Thu, 13 Oct 2022 14:09:54 +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 29DE9s9l099308; Thu, 13 Oct 2022 14:09:54 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 29DE9sjO099307; Thu, 13 Oct 2022 14:09:54 GMT (envelope-from git) Date: Thu, 13 Oct 2022 14:09:54 GMT Message-Id: <202210131409.29DE9sjO099307@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mitchell Horne Subject: git: 3562dcf3290a - stable/13 - riscv: optimize MADV_WILLNEED on existing superpages List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@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/stable/13 X-Git-Reftype: branch X-Git-Commit: 3562dcf3290a25dd87ddbb762f2a73e32b2eb8f3 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1665670194; 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=Gx8cysozuLVuDyG9U+CoBeSR3JOFAPCdxdqisXpITLQ=; b=xCNi3TSQIQ48HZrHRNHgNHyoGYEAE/utFdJHpW3v0dJGgQ7VZrPF2gqtyTcvEbNRUblqYx cyF3ph7TxlK9NeQojkVPfDVnqgYxPt8JGLOWy0AyXw+9JKlHQTVKSUOTm/+HRfNSZQ6nrz oFNH3Wz5+CKpfiGsdXda5X7OvXNHZhDXsvE5exjPZ9+0e/8X0pYm8d1lTLo10quBxqHB2U Or1HhxoPvIxhQFIP5mKNJUe9ypIN2kOvb4ZoQzO+nEYwQMvAgDtsCatdalZJYAxm4RiB6V 228YYIkq3ekX+7TJEkRah41pusm2pKWf9RUtgROh6aOX1WGjpyOOX/i0Cw9XWg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1665670194; a=rsa-sha256; cv=none; b=Gq1e79rT1qcXDWMqf0n3lZ7BToyipY5y5QaaXUluKmyZWPsIrHWAuGh/7/DpViQCotc1yQ fGjXfGqMnDd9yU0l/kcqEPrgIfENp+idaP3BVZPNo3R+GkZwZTXB3mCX3YcjLV8jY8jLWA /XScrpeWcTdRrgNiRFVlnssjpXz17NMguUuxF5nLKdlQzbzPtag5KVVxjlVe7WVbjgSUwu sBLTfZQTbsT9UspX4GxfbmSi8uP4aVEssT6fn2/fktH3HMIdHptzk2R3/1nEqHIZ1gSRPt w+Cg6LyaLv4VzNRJxa02HDljUrxhsOBclQ8L4M6yBY0BFrC4tTa3w69CH/ZgZA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by mhorne: URL: https://cgit.FreeBSD.org/src/commit/?id=3562dcf3290a25dd87ddbb762f2a73e32b2eb8f3 commit 3562dcf3290a25dd87ddbb762f2a73e32b2eb8f3 Author: Mitchell Horne AuthorDate: 2022-10-05 17:10:45 +0000 Commit: Mitchell Horne CommitDate: 2022-10-13 14:05:20 +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 (cherry picked from commit 95b1c27069775dd969cd045888b4ea5aeb53cb7f) --- 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 e925beb91c14..9ca06968b1d6 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,