From patchwork Fri Feb 2 08:07:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Roberts X-Patchwork-Id: 13542337 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 75CC3C47258 for ; Fri, 2 Feb 2024 08:08:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0920D6B0075; Fri, 2 Feb 2024 03:08:27 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0421C6B0078; Fri, 2 Feb 2024 03:08:26 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E737E6B007B; Fri, 2 Feb 2024 03:08:26 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id D8A9D6B0075 for ; Fri, 2 Feb 2024 03:08:26 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 7BFD3A0EFF for ; Fri, 2 Feb 2024 08:08:26 +0000 (UTC) X-FDA: 81746136612.05.635B3D3 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf28.hostedemail.com (Postfix) with ESMTP id DB7C4C0006 for ; Fri, 2 Feb 2024 08:08:24 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf28.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706861305; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=iYGxY8gKE5MXdRT9yHHw6Vo1X8bbi/EsI1w4KtEcUbM=; b=mffPx/uNIaY+vgXLuWYPd2S27vmaaRefivauvbfDSOQVud1j6vYWg3iyg1/PcWo2B+YimL k7/smf1j5CDMCYtbwZitAQTo+bRHNu5kToi9qc1GMD0oTbezO/8EDqu2J3o4TK2EdciPwB GgXcRdlUzU+gVZf7mDy8invDr8ebKKQ= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf28.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706861305; a=rsa-sha256; cv=none; b=4LZBUvuaZyDM6ELIsVcYJZXCDFPr9qyvqSDVcHtjNPGxAZhKMGGFiwu34fPx75GROYQQZ9 8+DlSWucUckR4OqxfL8wsOhnytsyUjxEMTJ+YqvzGsD+Hp+m0h6vVX6ZpA6+/IrNgukYXc Qmpvw+DcyZv/2/pUCc9qWfVi8dGUqnY= Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 568E21042; Fri, 2 Feb 2024 00:09:06 -0800 (PST) Received: from e125769.cambridge.arm.com (e125769.cambridge.arm.com [10.1.196.26]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 6AED23F5A1; Fri, 2 Feb 2024 00:08:20 -0800 (PST) From: Ryan Roberts To: Catalin Marinas , Will Deacon , Ard Biesheuvel , Marc Zyngier , James Morse , Andrey Ryabinin , Andrew Morton , Matthew Wilcox , Mark Rutland , David Hildenbrand , Kefeng Wang , John Hubbard , Zi Yan , Barry Song <21cnbao@gmail.com>, Alistair Popple , Yang Shi , Nicholas Piggin , Christophe Leroy , "Aneesh Kumar K.V" , "Naveen N. Rao" , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" Cc: Ryan Roberts , linux-arm-kernel@lists.infradead.org, x86@kernel.org, linuxppc-dev@lists.ozlabs.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 02/25] mm: thp: Batch-collapse PMD with set_ptes() Date: Fri, 2 Feb 2024 08:07:33 +0000 Message-Id: <20240202080756.1453939-3-ryan.roberts@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240202080756.1453939-1-ryan.roberts@arm.com> References: <20240202080756.1453939-1-ryan.roberts@arm.com> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: gsoykgewipwyp39sdbidumjp1saek6w4 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: DB7C4C0006 X-HE-Tag: 1706861304-788647 X-HE-Meta: U2FsdGVkX19v1w0UWncnnaq2BMLXXW4NQhrm+Eel2nPhyZNbwxqqeoMsr6zZ9yg4TdjdcjEY0LmZN2QpwXH04F1keRQm1FqhOGLfT2SA/c9nPN5AS3Nvsp+mI2uA1psRsYAwY/EXJ6ol8AIz66wtQxQ8spVNFZCtbLyyer7lRQWo2/SQMwOBlzRpc8Em0VUz5enHMnikgft06qEUiXpCa6kBlJxxjB8jK//nT7PrvxkCMrTlfyNEy5eRisaNWpvcjHcpJE6aUtCf5GuJSbXBlI35gWP/K5Jl5M24OA9NBfI+v14pKXEUNHK02hSIbr+zmZaNsRMSvW/mdlu7k1+1oeQ+q70cy3xleGdn1zJUf/OBrox9C2ZEzbeZs1yl4irzaJsWyIRGMNz5AGnwJwa14cttvEw8QcyIKeuNDk9WV76JpLWJdinxDDgsUfy6jX7dw/wTWuDDRyXyQDUscJKCqH+alFiJl5CMOt0OdrRelGn78qSl/sLA+A+UABkyI7cCWJGjSYH/6SRx9oYa+ny6novI25iLw89lg9lZaPFLBoW6YmdTImEM72F1a3qW0xbaI0BYGIyJu2cuiO/S/2v7DmGTrnoueILh1nvPyXIpKN0o28Prv0qzbrfLvXr6J/hn4kRSEnMZqza9OFyTRBU6ftjIMeiUiww2ZpxnuiwIIckONSKu0ld/1jct5dbAKX08hx6MuJH0tXb/M/+fUSVjQQ4VfFZgbZoGCPVXAx+2jtI2RXYGRudcCQDafK02YlmWNTOkMzGHf8i7pkacNtWtt8FpeiHwn8ku4ketxMEXiw2McW5IRVSDbPzzyj4aUu65cPimDr1A2nr2w+05nF/if+tqEAJh68oAqPofjimf7VnhJ3E4LAC4TXaXbdNJrhaMh5A3N8/nYE9Gz74Hi/X95hqGMZJAZpO1F9tUYU27xioboCrPLXpu/WvitK3YasExOUiVjRpIPXKKdNtMUs8 CrA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Refactor __split_huge_pmd_locked() so that a present PMD can be collapsed to PTEs in a single batch using set_ptes(). This should improve performance a little bit, but the real motivation is to remove the need for the arm64 backend to have to fold the contpte entries. Instead, since the ptes are set as a batch, the contpte blocks can be initially set up pre-folded (once the arm64 contpte support is added in the next few patches). This leads to noticeable performance improvement during split. Acked-by: David Hildenbrand Signed-off-by: Ryan Roberts --- mm/huge_memory.c | 58 +++++++++++++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 25 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 016e20bd813e..14888b15121e 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2579,15 +2579,16 @@ static void __split_huge_pmd_locked(struct vm_area_struct *vma, pmd_t *pmd, pte = pte_offset_map(&_pmd, haddr); VM_BUG_ON(!pte); - for (i = 0, addr = haddr; i < HPAGE_PMD_NR; i++, addr += PAGE_SIZE) { - pte_t entry; - /* - * Note that NUMA hinting access restrictions are not - * transferred to avoid any possibility of altering - * permissions across VMAs. - */ - if (freeze || pmd_migration) { + + /* + * Note that NUMA hinting access restrictions are not transferred to + * avoid any possibility of altering permissions across VMAs. + */ + if (freeze || pmd_migration) { + for (i = 0, addr = haddr; i < HPAGE_PMD_NR; i++, addr += PAGE_SIZE) { + pte_t entry; swp_entry_t swp_entry; + if (write) swp_entry = make_writable_migration_entry( page_to_pfn(page + i)); @@ -2606,25 +2607,32 @@ static void __split_huge_pmd_locked(struct vm_area_struct *vma, pmd_t *pmd, entry = pte_swp_mksoft_dirty(entry); if (uffd_wp) entry = pte_swp_mkuffd_wp(entry); - } else { - entry = mk_pte(page + i, READ_ONCE(vma->vm_page_prot)); - if (write) - entry = pte_mkwrite(entry, vma); - if (!young) - entry = pte_mkold(entry); - /* NOTE: this may set soft-dirty too on some archs */ - if (dirty) - entry = pte_mkdirty(entry); - if (soft_dirty) - entry = pte_mksoft_dirty(entry); - if (uffd_wp) - entry = pte_mkuffd_wp(entry); + + VM_WARN_ON(!pte_none(ptep_get(pte + i))); + set_pte_at(mm, addr, pte + i, entry); } - VM_BUG_ON(!pte_none(ptep_get(pte))); - set_pte_at(mm, addr, pte, entry); - pte++; + } else { + pte_t entry; + + entry = mk_pte(page, READ_ONCE(vma->vm_page_prot)); + if (write) + entry = pte_mkwrite(entry, vma); + if (!young) + entry = pte_mkold(entry); + /* NOTE: this may set soft-dirty too on some archs */ + if (dirty) + entry = pte_mkdirty(entry); + if (soft_dirty) + entry = pte_mksoft_dirty(entry); + if (uffd_wp) + entry = pte_mkuffd_wp(entry); + + for (i = 0; i < HPAGE_PMD_NR; i++) + VM_WARN_ON(!pte_none(ptep_get(pte + i))); + + set_ptes(mm, haddr, pte, entry, HPAGE_PMD_NR); } - pte_unmap(pte - 1); + pte_unmap(pte); if (!pmd_migration) folio_remove_rmap_pmd(folio, page, vma);