From patchwork Mon Dec 18 10:50:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Roberts X-Patchwork-Id: 13496565 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 DF76DC35274 for ; Mon, 18 Dec 2023 10:51:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7580E6B0089; Mon, 18 Dec 2023 05:51:25 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7070B6B008C; Mon, 18 Dec 2023 05:51:25 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5A7CA6B0092; Mon, 18 Dec 2023 05:51:25 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 47D636B0089 for ; Mon, 18 Dec 2023 05:51:25 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 0F439121038 for ; Mon, 18 Dec 2023 10:51:25 +0000 (UTC) X-FDA: 81579622530.26.28DB535 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf19.hostedemail.com (Postfix) with ESMTP id 464EF1A0011 for ; Mon, 18 Dec 2023 10:51:23 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf19.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=1702896683; 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=nHYd6pL2au0ylISSnRYYRDrN6i/JAMSJRS7tvhKFDUA=; b=j3OCoglEgHyKXxTQ8f5qP16xkcjY/Wq+FaJMYorMOEIZKKOGJw+IR3oCCAaR0JI8ixwGOW vO2oXIu35IeqwRI8zO3o3/MaeD+3AaR/zcgO7ktDPg6lTYlzWnV3o+3TaZV7gtlr7RpVTT YA4fLG3mVdbtP+68vtdI8v0VElj7Xxs= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf19.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=1702896683; a=rsa-sha256; cv=none; b=HeT4Jj3qUzx6GGzr4VQTEdaPZofWk8MeksEK5pVed7t17vWfUdHyiYcIOuSjdvxkXA34Xf MaFnB3uBAFyZ9j66pIGoB/jqpUfXr9yu/m58xq1kqkjqfZn2EENmGkShh+6trS+v8nfxSh bcY+hwx1TxCttirKulkMpR3TJt42DsE= 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 754E92F4; Mon, 18 Dec 2023 02:52: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 9BE873F738; Mon, 18 Dec 2023 02:51:18 -0800 (PST) From: Ryan Roberts To: Catalin Marinas , Will Deacon , Ard Biesheuvel , Marc Zyngier , Oliver Upton , James Morse , Suzuki K Poulose , Zenghui Yu , Andrey Ryabinin , Alexander Potapenko , Andrey Konovalov , Dmitry Vyukov , Vincenzo Frascino , Andrew Morton , Anshuman Khandual , Matthew Wilcox , Yu Zhao , Mark Rutland , David Hildenbrand , Kefeng Wang , John Hubbard , Zi Yan , Barry Song <21cnbao@gmail.com>, Alistair Popple , Yang Shi Cc: Ryan Roberts , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 01/16] mm: thp: Batch-collapse PMD with set_ptes() Date: Mon, 18 Dec 2023 10:50:45 +0000 Message-Id: <20231218105100.172635-2-ryan.roberts@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231218105100.172635-1-ryan.roberts@arm.com> References: <20231218105100.172635-1-ryan.roberts@arm.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 464EF1A0011 X-Stat-Signature: taeaadrfpumgwkopazkm5knf3adep64r X-HE-Tag: 1702896682-619285 X-HE-Meta: U2FsdGVkX18JFI2jhaJUD2ahuW3lFLtt06yzgSMTbXkXxQwDdCa4ZbDC+i9b1iZypoiWv+lKo3OIaqnIrY8VMe0CiAMb0XPtE0VJiDA++x6KWn+2Mf6yS3uQf3Jmym9cnuGeaLkPhVjFTHIvsnNKJ/c0CSiUwFDmpvcpW1666C6UBX63+o+CLD9Z9PP/7HTzSiK9FBo0qYw9/XytJIs/tW22bteahVcRWnRLKOYhsXHdr9hFRrbVAcm0jlyPOuGuVlFX7xT+57KmKTvPzW9dq4tvKmcgI0C8Efd3ePwiBHUDm84mi+c8vJKQODLoxs6MpHYTOq4pNdp0WiqzRt3JFrhyfTJp8SVtcllWMqwj0gk97lE/p8KbS/s6LkjVrWgPcPvKrEF655kfQxK4e4F7/JzrUyCF7WN/m2R9dw97t/+hdvU5aC0fiT/jxaN8H/RgbNeNqkW4Gth5GAcWVa6FuKKg3fVuT9WuxslL06Dmj8g2iqbQoIjXRl8aV1z7GELG36hohsjfb3lcNFZiRymr251ekKXEA0Q3OT3f41VU6YaEVfwYV/Xo/ye7C9IVsh28y7U8GuQ6FOelSYKcrGrpMZ96f2SFJuzBWzCh0DZx2UP/DuBaapX2u/d8QjeUoBlGNskF8PM38u7IX2BVfjo9zuyEPHW1ShBqgyJ3yDoEO7fUioVVSYmKk1EYdIZ1M4ryA1ex8aNS48oHQR1y3Pa6MLz44vMBOQbLO4ke9fF1C8oK8+ON1nO9slYgRootBSDOcKDMvI9DmVgpjXzBCrAjAflCQvoV0+H/n81R+DuXLReJqDV63h4W1yDRCbTHzvSFMADJH4nCvw6TkVlWblAYZRCFygmh6oj8h+8idrwYg4eWE01om355/rv8msl6Bi7Lyr9NOBekybBMyCSl9PmAs6UJUmpb025YUyR9ocV0HwlPqE7xw1H/WR3dF5Nv02woACYW459uBZ/fx1ydDMd 3ui+h/zI 2iUkMpJsv7H1JsHPhWyVUkMMxrU1cTU9JsbTx0ItPPpagb3y6w3Z8hqjYW1baW6xHDb2JngLUH9K194TTacqc/9t6KVKsSSMiTSxGvEgXmD5qcdozaO844UdVi+U27vpcz3MrTw/WDI8O8S0iGZ6k/P2zd4kwSuoVBA0Li03jRHoidFa31shZWuyUI+8uuQm4DOtwbr7yQRmt/SRlf+xrX6CeVZkxQqPI7S44nA5HJ7W9Z1t05I+5Sd2FHUOwsLPEEAEq1vvNZa6E4UDxoEt2QxD5/Q== 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(). It also provides a future opportunity to batch-add the folio to the rmap using David's new batched rmap APIs. 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. Signed-off-by: Ryan Roberts Acked-by: David Hildenbrand --- mm/huge_memory.c | 59 ++++++++++++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 25 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 6be1a380a298..fbf7e95ea983 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2535,15 +2535,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)); @@ -2562,28 +2563,36 @@ 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); + + VM_WARN_ON(!pte_none(ptep_get(pte + i))); + set_pte_at(mm, addr, pte + i, entry); + } + } 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, addr = haddr; i < HPAGE_PMD_NR; i++, addr += PAGE_SIZE) { if (anon_exclusive) SetPageAnonExclusive(page + i); - 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); page_add_anon_rmap(page + i, vma, addr, RMAP_NONE); + VM_WARN_ON(!pte_none(ptep_get(pte + i))); } - VM_BUG_ON(!pte_none(ptep_get(pte))); - set_pte_at(mm, addr, pte, entry); - pte++; + + set_ptes(mm, haddr, pte, entry, HPAGE_PMD_NR); } - pte_unmap(pte - 1); + pte_unmap(pte); if (!pmd_migration) page_remove_rmap(page, vma, true);