From patchwork Thu Feb 15 10:31:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Roberts X-Patchwork-Id: 201379 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:b825:b0:106:860b:bbdd with SMTP id da37csp320063dyb; Thu, 15 Feb 2024 03:09:04 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCV2A1mRowtJA/WQpQHY1oV5WGbqfpC8XCezSSF1kDlIC6Etr1SrVs6EvTOyZuwgSog8ZfShF/KF+eGoU3e0wMt4RFFuvg== X-Google-Smtp-Source: AGHT+IHgSdd2puWaNAag8ivazFl8ndVOmoU3bv07HfzHFkkrdpZ0TxptBNQmg1pQSbkJeILhxz9v X-Received: by 2002:a05:6358:d090:b0:178:7556:11e6 with SMTP id jc16-20020a056358d09000b00178755611e6mr1288867rwb.27.1707995344089; Thu, 15 Feb 2024 03:09:04 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707995344; cv=pass; d=google.com; s=arc-20160816; b=Y+i3QnfeGM6VWmxZdbcPWCjKUsg/3xkRcxxs1+0zpL1v4yfQXBJzc9jjyHZl2imvLH oVZHE7U/HRUqjZdgnN1s088J8V5DY3ilMoJQVmJnM13ExtQDzfiQBUx3UURU/wt6MVuk vfsvowjZ3bD4EF9Oj6MCa7/tocWL2CcrsiuzqzPyzyAxijWTnzkV/TouKHGOGPrzD7Ot 5ciB0sUOnlVxtg77YK3ij+jJzcq+mC3qDVIV4VPCMbMOMmPilUKowrjwcVhfEjfaCx2U WCxd4RJuhHE0TsuqBvWLDWagmhLnlGG/6ZGE2AK32Ln8GKorD22jbMmngBK3RjwaxOTP fK2Q== 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=Heagowc1O8zVDXTyU76nJjOwDjz9r3Gi+0zmhF4ZELQ=; b=NBL96PaL/oTGOUZZZxHy7X8RvsQ0lqRFRQlgfLfHuBLOTMVsZ9ssGmoOekKgP+0/dA XpJm3ipr1zMjlQaMuI4/ntphNqTTcXm52rO98k5HjIyxJOFq/59Hi86EYApPqcyvZ9MF 8ndwOCEoK9dwbujf44rVG90MmCWrDShUtLJ5FacfgANidY+RWL+zC/XPaqVgOPvMEBJj nyZf9jrcE4wud+NDGOpIZN0Nf3vF+t7LS4B+tdHeun1n8NePT8d1bqi9akI83KYCBblG S5J9opcQarqeGnTWiJJMC2eq2iRI7XPBumBJ7tYL96tMSzF1PisQwui2Dahy6Gc9CCOQ 3PFA==; 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-66636-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-66636-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id lb6-20020a056a004f0600b006e0a347f6ebsi982109pfb.90.2024.02.15.03.09.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 03:09:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-66636-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; 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-66636-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-66636-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 94312B311A7 for ; Thu, 15 Feb 2024 10:34:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CA1B112AAF6; Thu, 15 Feb 2024 10:32:30 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 720D712AAD7 for ; Thu, 15 Feb 2024 10:32:27 +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=1707993149; cv=none; b=S/0OhcLO6WiEC8pB7M7/k7tE6Qm3AoM+F6HGbsGNfDXXLZi30dGzXkhOKpmGMS6YBmHlrZ6H3UrqYe0xR3nVcFBOMpY/3xEI60klmP8vT34utrYnhGDWrudmAaBsI+7dZLjIwxQ6yfUnY+7CP1NhVWI/0MFXCANNpDqZhEEs1qY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707993149; c=relaxed/simple; bh=2hkmQn4Ed8vkkGt4I+ydMlyJoDxhv4t3yUe1PaYNzQE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=laiq4LB+frTw8Lgb7diwRXB7f/oV3rwWKCxi9NElGoWluLRoRpRDr3Z4JAnF2ylsuQK64bEQCUrdZluOt8RI24l3noqCksBelGjMw5ZrUwYx1xhG9C7vKHMHpcLI//NfEuZxtIjuHpiuhNJD+mvhul40pLoemKZtQw5FWX14HCQ= 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 A52231480; Thu, 15 Feb 2024 02:33:07 -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 9BFF83F7B4; Thu, 15 Feb 2024 02:32:23 -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 , 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 v6 02/18] mm: thp: Batch-collapse PMD with set_ptes() Date: Thu, 15 Feb 2024 10:31:49 +0000 Message-Id: <20240215103205.2607016-3-ryan.roberts@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240215103205.2607016-1-ryan.roberts@arm.com> References: <20240215103205.2607016-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: 1790962926105624074 X-GMAIL-MSGID: 1790962926105624074 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);