Received: by 2002:a05:7412:1e0b:b0:fc:a2b0:25d7 with SMTP id kr11csp380449rdb; Thu, 15 Feb 2024 03:09:06 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCX/f10Q0Eqfoka89C/JCzG4pMfRNDs4zTuBOEaYj5NctzlnrT+F9LcGdjPhPmo0aaKRKUeDYdymC2/v1/f5JCpkc3kDxa5+ZEdVrD1eMw== X-Google-Smtp-Source: AGHT+IFFQcilDXCJ8P88O/1Tvr0DGhheF4C89YE1ji/fd1Cv5GpdI85wSqrsmnCPScZnsllG5KXH X-Received: by 2002:a05:6871:1cc:b0:21e:459a:1fb6 with SMTP id q12-20020a05687101cc00b0021e459a1fb6mr424838oad.23.1707995346116; Thu, 15 Feb 2024 03:09:06 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707995346; cv=pass; d=google.com; s=arc-20160816; b=eg7AlElEErw3LAmGiut86gcxsRJo+lK9szJqHUcXcWkC8OSw/ePtSCLkRGta+T/3qo WnjGgV1USoq2qOUXPpUnYFAj9Qy6SAwi2SZ/6wmAKRp/BxZ27NEf/YWhuK8ZLwM6+9HX Jmja5hGZGNUh8vtOh+Zvu9nOJgEApBRf9nnH4/NvLpOf2m7DWm2GVF6/4vvR3r6gpA9R krfs5uCfZHg+GcZN42opFdlpPmFi7uK3fPihe3b5o96F/PMa19ZpJNVHTowq99dBfzp7 2QJjQ7Vgga0xgrRQWK5uTMHkKQvRP1xq59YkF36fNP9jdbOMnqUmBR6bu0SU9l8cydoa QbpQ== 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-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-66636-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id e28-20020a63745c000000b005dc4fca7d3csi953539pgn.200.2024.02.15.03.09.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 03:09:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-66636-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; 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-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-66636-linux.lists.archive=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 08040B31078 for ; Thu, 15 Feb 2024 10:34:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B34E612AAE9; Thu, 15 Feb 2024 10:32:29 +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 Content-Transfer-Encoding: 8bit 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); -- 2.25.1