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: 195677 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp278280dyc; Fri, 2 Feb 2024 00:09:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IEfJk/sCK6qcWTPdVzMpnUv3zn4TvLaKJ2PR7ltPEdlvxel68ijDa8E8sRyc68Bq6sxfFqW X-Received: by 2002:aa7:c2d4:0:b0:55e:f52d:1825 with SMTP id m20-20020aa7c2d4000000b0055ef52d1825mr759936edp.35.1706861370335; Fri, 02 Feb 2024 00:09:30 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706861370; cv=pass; d=google.com; s=arc-20160816; b=lpLTKqPGmfv7FAPbHyvZgyAuvqBwX34lSl8/LgTYeUkM9sDncLc66ICzn2QuHyInOb M1RN8qcVjn7JKHzYxROHM+bVGNRu6a0fdWKd5sjUKMKNfkFrTJUiuLYFsP0Rrjfx6+Mp aio1kDDz9zZ6nwxo20lJM6ysDVK9MMyxuu3HugCyH4ozvS+D39l1B3aLlL1i49QUmBr9 nrNOC1kLUDo/3SF16wyCQ33IgQOj6xESW1b8AVgQxCvgCX2Q2/Y5RtMzCu0xQ0XP/DqU eAKq1dtaEFs1vIdZhs3T1gbqQMzh1V39o87L3fARpv2PntWv9Us2x2hzDkHLxJZOo4ks ywMQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=iYGxY8gKE5MXdRT9yHHw6Vo1X8bbi/EsI1w4KtEcUbM=; fh=VEeEo0tarD8dzzw2P2Ced0azk7+v1CEIBSx1oED+PBs=; b=UvLoV6wQLAF64XRN75oNJAyS/kXfVrqvGf7vmGCSLRDRMXfg20G2jq5NG1kDLfElDn WifaSjOvsBs5zwLT+0xcIeMp/owIwyQD6SWFUCM1fypqLBEAQ7oXZmYhyK1OoySh+Kym 6z81mixvir2ut5vUi92vefB2zdtWlnyiQGLmc1tfunJ4Rd/gxKoRKpvTY/pRVO9pmioZ Hn6zxZ3HxIYKJGUwV4sk68r60SFqrWIwK7tjbpQOMREWDEqGP6PMFjaxQlbx5Trs74t3 s0S5y0SWv/4IA33oPNgJ/a2Wd4t9Rcz86tJGeHHJ0h8wTLRZF/xUpM1TN1Dzm7nrbtwq zvKQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-49414-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49414-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com X-Forwarded-Encrypted: i=1; AJvYcCU7g0e7m+gOuSQrSRvGyhk6Ucsp0mmm4G/wEcI/SPAqLNHCOdykhnWjn12Af8K2MMVnF3JTOi2sv8Q/E/totABna6i7qg== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id j26-20020aa7c35a000000b0055faf2587f1si582930edr.359.2024.02.02.00.09.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 00:09:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49414-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-49414-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49414-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id E93F21F2AD9A for ; Fri, 2 Feb 2024 08:09:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 504AD18E14; Fri, 2 Feb 2024 08:08:28 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B151C182D8 for ; Fri, 2 Feb 2024 08:08:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706861306; cv=none; b=nGQ/0+T+mKudxhpM+kmv0ItYn3mDlVKYTCKGTUlScpuxXR409HyXTC73ahushmcivvrwmyMFWNwcl6P5NH9x04XH0a/4opL+awB4ZzfSsId/2fOQo2dfenVpFoVrwJmpDXMSN6Yiu/DPFm2DplX0aTImLz/7UnSSXqUlybUocMg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706861306; c=relaxed/simple; bh=2hkmQn4Ed8vkkGt4I+ydMlyJoDxhv4t3yUe1PaYNzQE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=S+pnDck4Dlei8lLoHY/66Ai7TmIw8BOmwDHuPEQA1/+WYU3/gerv6dLGdiez91jVBxHYoq4W9RYrOCTsPOmdhwTBQf+HORFqz1hp8sQM6lBJe/T0HJ0plGWeGH22EhZzWWSiAc7QbtvWe0BrHBDX9wYiL0GFa29F0NpiGr1tN8s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789773868222273050 X-GMAIL-MSGID: 1789773868222273050 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);