From patchwork Wed Aug 23 13:13:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Elisei X-Patchwork-Id: 13362354 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1B9E3EE49B2 for ; Wed, 23 Aug 2023 13:17:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=aQSguhu21cC0627SbDYSWgFLaFbnYphHkwWPQWU9vak=; b=ku/Zx0fpq3F1LY BsRv+u3vwvBY/occNSpcDB3rciTATLw/5rNS9q5LyPwNHqy8FeLeuvTiHAg/B0UqgB2eI4M8fsjP/ 1tiDGcbpMMzrP3oBDnXc9MQnURNuXyUKtFfXXhVB1yo9h5tYNvMXdZjrWU7wFCGrYI/FfcZc4YrHr hUyFMy0xvL/iFrsRsO9bCM373RjaxwdMlCOK+ZtaC5x/MNNj8zRn4TUWYtbxPzDPHuxH2FUkVOkjA ITiaGNwCGOSQhVhnC210EziPISbMqg4hTBQ8O/z5E4gtRx58smLWIJdDXnX6PAlmCevaqAYIgpDiN PO5ZxaTXcX0OcUEyDiaA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qYnjT-000dwc-2n; Wed, 23 Aug 2023 13:17:11 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qYnii-000dPw-0R for linux-arm-kernel@lists.infradead.org; Wed, 23 Aug 2023 13:16:26 +0000 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 C95B2168F; Wed, 23 Aug 2023 06:17:03 -0700 (PDT) Received: from e121798.cable.virginm.net (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id B4A793F740; Wed, 23 Aug 2023 06:16:16 -0700 (PDT) From: Alexandru Elisei To: catalin.marinas@arm.com, will@kernel.org, oliver.upton@linux.dev, maz@kernel.org, james.morse@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, arnd@arndb.de, akpm@linux-foundation.org, mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com, vschneid@redhat.com, mhiramat@kernel.org, rppt@kernel.org, hughd@google.com Cc: pcc@google.com, steven.price@arm.com, anshuman.khandual@arm.com, vincenzo.frascino@arm.com, david@redhat.com, eugenis@google.com, kcc@google.com, hyesoo.yu@samsung.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kvmarm@lists.linux.dev, linux-fsdevel@vger.kernel.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, linux-trace-kernel@vger.kernel.org Subject: [PATCH RFC 21/37] mm: khugepaged: Handle metadata-enabled VMAs Date: Wed, 23 Aug 2023 14:13:34 +0100 Message-Id: <20230823131350.114942-22-alexandru.elisei@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230823131350.114942-1-alexandru.elisei@arm.com> References: <20230823131350.114942-1-alexandru.elisei@arm.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230823_061624_284505_16501328 X-CRM114-Status: GOOD ( 11.96 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Both madvise(MADV_COLLAPSE) and khugepaged can collapse a contiguous THP-sized memory region mapped as PTEs into a THP. If metadata is enabled for the VMA where the PTEs are mapped, make sure to allocate metadata storage for the compound page that will be replacing them. Signed-off-by: Alexandru Elisei --- arch/arm64/include/asm/memory_metadata.h | 7 +++++++ include/asm-generic/memory_metadata.h | 4 ++++ mm/khugepaged.c | 7 +++++++ 3 files changed, 18 insertions(+) diff --git a/arch/arm64/include/asm/memory_metadata.h b/arch/arm64/include/asm/memory_metadata.h index 1b18e3217dd0..ade37331a5c8 100644 --- a/arch/arm64/include/asm/memory_metadata.h +++ b/arch/arm64/include/asm/memory_metadata.h @@ -5,6 +5,8 @@ #ifndef __ASM_MEMORY_METADATA_H #define __ASM_MEMORY_METADATA_H +#include + #include #include @@ -40,6 +42,11 @@ static inline int reserve_metadata_storage(struct page *page, int order, gfp_t g static inline void free_metadata_storage(struct page *page, int order) { } + +static inline bool vma_has_metadata(struct vm_area_struct *vma) +{ + return vma && (vma->vm_flags & VM_MTE); +} #endif /* CONFIG_MEMORY_METADATA */ #endif /* __ASM_MEMORY_METADATA_H */ diff --git a/include/asm-generic/memory_metadata.h b/include/asm-generic/memory_metadata.h index 111d6edc0997..35a0d6a8b5fc 100644 --- a/include/asm-generic/memory_metadata.h +++ b/include/asm-generic/memory_metadata.h @@ -35,6 +35,10 @@ static inline bool folio_has_metadata(struct folio *folio) { return false; } +static inline bool vma_has_metadata(struct vm_area_struct *vma) +{ + return false; +} #endif /* !CONFIG_MEMORY_METADATA */ #endif /* __ASM_GENERIC_MEMORY_METADATA_H */ diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 78c8d5d8b628..174710d941c2 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -20,6 +20,7 @@ #include #include +#include #include #include #include "internal.h" @@ -96,6 +97,7 @@ static struct kmem_cache *mm_slot_cache __read_mostly; struct collapse_control { bool is_khugepaged; + bool has_metadata; /* Num pages scanned per node */ u32 node_load[MAX_NUMNODES]; @@ -1069,6 +1071,9 @@ static int alloc_charge_hpage(struct page **hpage, struct mm_struct *mm, int node = hpage_collapse_find_target_node(cc); struct folio *folio; + if (cc->has_metadata) + gfp |= __GFP_TAGGED; + if (!hpage_collapse_alloc_page(hpage, gfp, node, &cc->alloc_nmask)) return SCAN_ALLOC_HUGE_PAGE_FAIL; @@ -2497,6 +2502,7 @@ static unsigned int khugepaged_scan_mm_slot(unsigned int pages, int *result, if (khugepaged_scan.address < hstart) khugepaged_scan.address = hstart; VM_BUG_ON(khugepaged_scan.address & ~HPAGE_PMD_MASK); + cc->has_metadata = vma_has_metadata(vma); while (khugepaged_scan.address < hend) { bool mmap_locked = true; @@ -2838,6 +2844,7 @@ int madvise_collapse(struct vm_area_struct *vma, struct vm_area_struct **prev, if (!cc) return -ENOMEM; cc->is_khugepaged = false; + cc->has_metadata = vma_has_metadata(vma); mmgrab(mm); lru_add_drain_all();