From mboxrd@z Thu Jan 1 00:00:00 1970 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 444D4C4167B for ; Mon, 27 Nov 2023 15:01:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B78E56B02BC; Mon, 27 Nov 2023 10:01:23 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B4F2F6B02D2; Mon, 27 Nov 2023 10:01:23 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A16B26B02D5; Mon, 27 Nov 2023 10:01:23 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 9134C6B02BC for ; Mon, 27 Nov 2023 10:01:23 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 563C01602EB for ; Mon, 27 Nov 2023 15:01:23 +0000 (UTC) X-FDA: 81504047646.09.010EC14 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf06.hostedemail.com (Postfix) with ESMTP id 188211800AD for ; Mon, 27 Nov 2023 15:01:14 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf06.hostedemail.com: domain of alexandru.elisei@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=alexandru.elisei@arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1701097275; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7biW1Mw8n6QLTzXDyEdH2rMwYFOOh3ORWc6XBBSz8rI=; b=ysv8Rnc7IBp44zxirBQUECatMvWVKrgK4BD2G+Tsv3lQ78fczf9f9XTMdWKYjk0EuWmyNu jnhkvYL/yYX5aJj+Dr6ctafj6VkGhiwLjmxThURtBSH0YsBVxLye9KUNHPh4Kh/Li6q/H2 GL2EBOElIZx8ATJ/e71KVTkTuQE4U38= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf06.hostedemail.com: domain of alexandru.elisei@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=alexandru.elisei@arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1701097275; a=rsa-sha256; cv=none; b=omjdci6370fwLdLACHg6eLbNGPkpK6N1FGdhG20m2M8FqgU9bw7b9qHeVSS6qU275WZDOu A5d7MRd2J4yOcBSHNrZx/o6jR5/zAdmCqxjHO9AHA0PsZPx6DJa7/VsqiFpBvvDIZdwFo6 osFqXdDchu2Rsl5lwMsxpR4lLuk5u3k= 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 8CEEE2F4; Mon, 27 Nov 2023 07:02:01 -0800 (PST) Received: from raptor (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 947493F6C4; Mon, 27 Nov 2023 07:01:08 -0800 (PST) Date: Mon, 27 Nov 2023 15:01:05 +0000 From: Alexandru Elisei To: David Hildenbrand Cc: 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, pcc@google.com, steven.price@arm.com, anshuman.khandual@arm.com, vincenzo.frascino@arm.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: Re: [PATCH RFC v2 12/27] arm64: mte: Add tag storage pages to the MIGRATE_CMA migratetype Message-ID: References: <20231119165721.9849-1-alexandru.elisei@arm.com> <20231119165721.9849-13-alexandru.elisei@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 188211800AD X-Stat-Signature: xtqoghdrk9s9dni85qtcgdzki41s1nce X-HE-Tag: 1701097274-31738 X-HE-Meta: U2FsdGVkX188gW5oA+qCd5yuIEzz3v+Nmmdyb7ACZm3bLEvxXfqe3WYgKDKW1xelCSnUplMvqb5C5veAPkk2Jew3Zp98F4m+xA/S2cNMNBNxZ5CILpSMea9+Q/epjq1R/XW4CYkpZblBRIjIIYDGyWrqYxM99yekJP2RyF+Vwkc1KUEde6ge2PHhMf0jhedxo0dTvsmERe2YLcvtYDc0hED8snTZ0Gu+UryGTql481ZpC5ZubVjGojTjUfgq0Kj9NKfOHvlHFpK+wkR/IDdb41d0CGYSF5HC1/zqwk7HeIQBGx/913czYf47HmM9HZm/HWAjnEy1RWQMdfj1bgn4ES2WMiLbpO8fiD8ajJzTdOn7/pcaRSNRCTnW/ID+xyzHVpXECqb0A+iz2wybilOYoeDhR0iWR1UDLBOGSJvLmh6ORLVGXkuCaKasIebIj4lS8wag0/qZTOMePnDHuMGj9bzsksliG6tdFcgtnHxAlcH/qEqHlShOc70NdpA1/K0LKgJ07DJ83d41Lw72x/5II+IjIl8Y1WXCo0ijw1DkQxb9M18TPjWXm5B6V7DzPpSFIXHbNABUZvjyGxYWI0py+ZTW4YQthbAjKYrJg0108W5fQgQNBobPr0J+XQq3MZt0yVbe3tMqth7NBvyK9WRfiHiGwnwJzvM1oVXzu9b+4t/W98+wdWT+fqbraQ8+ioNB8Dqwtvq6scLJ6KdXUsNz09k5IuxhUppFp8qUZiyr1STC7bod6uuYf5yLFvcW9KEGANbiyV2l1T/TVthqi25fAGQvDm6pO09eMqOXSgFOvohTSpJ3m4QUJiF7W28pDtuqdKbSrNrMdc2a84rnaO9VXxb4DEzWxe9cCF+JB8vAn5Xf23wkLjqUTwL6CQbWymC5xVzo9ywUMKRoQqLOV4B3qohkQlu/8rPMwZ4YosSuBWZPiyRIEe5RHLWEUEuxqcjteS39v4gM6wACwKCBi6S uFdoaha5 +CEe2EW2XtLJuT7GvwHhrBjnl0BHhHl5AS68MaDP3W+mPGuemM0xj7YMyo2Hqp9LbYnzk1TCc8DqKO3F/Ttzw1R6t8+h8/Olf8XfHIxxEEE05k6lvADkReqyzcCc+t+kNaOiiWcalSv4j+wyq2o+nbVFoMf5suq7ZX9ld43lteA4FmlzHX2ah97EEVg/WSyYvGpxDm33xMayFAg9v5liLZ4LDtqRm9bKXiODQqoIDz1hZnSZa3gxfIdSy2HOVck8KhqXStl6sE+uDKT1g9Xm/2m0sag== 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: Hi David, On Fri, Nov 24, 2023 at 08:40:55PM +0100, David Hildenbrand wrote: > On 19.11.23 17:57, Alexandru Elisei wrote: > > Add the MTE tag storage pages to the MIGRATE_CMA migratetype, which allows > > the page allocator to manage them like regular pages. > > > > Ths migratype lends the pages some very desirable properties: > > > > * They cannot be longterm pinned, meaning they will always be migratable. > > > > * The pages can be allocated explicitely by using their PFN (with > > alloc_contig_range()) when they are needed to store tags. > > > > Signed-off-by: Alexandru Elisei > > --- > > arch/arm64/Kconfig | 1 + > > arch/arm64/kernel/mte_tag_storage.c | 68 +++++++++++++++++++++++++++++ > > include/linux/mmzone.h | 5 +++ > > mm/internal.h | 3 -- > > 4 files changed, 74 insertions(+), 3 deletions(-) > > > > diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig > > index fe8276fdc7a8..047487046e8f 100644 > > --- a/arch/arm64/Kconfig > > +++ b/arch/arm64/Kconfig > > @@ -2065,6 +2065,7 @@ config ARM64_MTE > > if ARM64_MTE > > config ARM64_MTE_TAG_STORAGE > > bool "Dynamic MTE tag storage management" > > + select CONFIG_CMA > > help > > Adds support for dynamic management of the memory used by the hardware > > for storing MTE tags. This memory, unlike normal memory, cannot be > > diff --git a/arch/arm64/kernel/mte_tag_storage.c b/arch/arm64/kernel/mte_tag_storage.c > > index fa6267ef8392..427f4f1909f3 100644 > > --- a/arch/arm64/kernel/mte_tag_storage.c > > +++ b/arch/arm64/kernel/mte_tag_storage.c > > @@ -5,10 +5,12 @@ > > * Copyright (C) 2023 ARM Ltd. > > */ > > +#include > > #include > > #include > > #include > > #include > > +#include > > #include > > #include > > #include > > @@ -189,6 +191,14 @@ static int __init fdt_init_tag_storage(unsigned long node, const char *uname, > > return ret; > > } > > + /* Pages are managed in pageblock_nr_pages chunks */ > > + if (!IS_ALIGNED(tag_range->start | range_len(tag_range), pageblock_nr_pages)) { > > + pr_err("Tag storage region 0x%llx-0x%llx not aligned to pageblock size 0x%llx", > > + PFN_PHYS(tag_range->start), PFN_PHYS(tag_range->end), > > + PFN_PHYS(pageblock_nr_pages)); > > + return -EINVAL; > > + } > > + > > ret = tag_storage_get_memory_node(node, &mem_node); > > if (ret) > > return ret; > > @@ -254,3 +264,61 @@ void __init mte_tag_storage_init(void) > > pr_info("MTE tag storage region management disabled"); > > } > > } > > + > > +static int __init mte_tag_storage_activate_regions(void) > > +{ > > + phys_addr_t dram_start, dram_end; > > + struct range *tag_range; > > + unsigned long pfn; > > + int i, ret; > > + > > + if (num_tag_regions == 0) > > + return 0; > > + > > + dram_start = memblock_start_of_DRAM(); > > + dram_end = memblock_end_of_DRAM(); > > + > > + for (i = 0; i < num_tag_regions; i++) { > > + tag_range = &tag_regions[i].tag_range; > > + /* > > + * Tag storage region was clipped by arm64_bootmem_init() > > + * enforcing addressing limits. > > + */ > > + if (PFN_PHYS(tag_range->start) < dram_start || > > + PFN_PHYS(tag_range->end) >= dram_end) { > > + pr_err("Tag storage region 0x%llx-0x%llx outside addressable memory", > > + PFN_PHYS(tag_range->start), PFN_PHYS(tag_range->end)); > > + ret = -EINVAL; > > + goto out_disabled; > > + } > > + } > > + > > + /* > > + * MTE disabled, tag storage pages can be used like any other pages. The > > + * only restriction is that the pages cannot be used by kexec because > > + * the memory remains marked as reserved in the memblock allocator. > > + */ > > + if (!system_supports_mte()) { > > + for (i = 0; i< num_tag_regions; i++) { > > + tag_range = &tag_regions[i].tag_range; > > + for (pfn = tag_range->start; pfn <= tag_range->end; pfn++) > > + free_reserved_page(pfn_to_page(pfn)); > > + } > > + ret = 0; > > + goto out_disabled; > > + } > > + > > + for (i = 0; i < num_tag_regions; i++) { > > + tag_range = &tag_regions[i].tag_range; > > + for (pfn = tag_range->start; pfn <= tag_range->end; pfn += pageblock_nr_pages) > > + init_cma_reserved_pageblock(pfn_to_page(pfn)); > > + totalcma_pages += range_len(tag_range); > > + } > > You shouldn't be doing that manually in arm code. Likely you want some cma.c > helper for something like that. If you referring to the last loop (the one that does ini_cma_reserved_pageblock()), indeed, there's already a function which does that, cma_init_reserved_areas() -> cma_activate_area(). > > But, can you elaborate on why you took this hacky (sorry) approach as > documented in the cover letter: No worries, it is indeed a bit hacky :) > > "The arm64 code manages this memory directly instead of using > cma_declare_contiguous/cma_alloc for performance reasons." > > What is the exact problem? I am referring to the performance degredation that is fixed in patch #26, "arm64: mte: Fast track reserving tag storage when the block is free" [1]. The issue is that alloc_contig_range() -> __alloc_contig_migrate_range() calls lru_cache_disable(), which IPIs all the CPUs in the system, and that leads to a 10-20% performance degradation on Chrome. It has been observed that most of the time the tag storage pages are free, and the lru_cache_disable() calls are unnecessary. The performance degradation is almost entirely eliminated by having the code take the tag storage page directly from the free list if it's free, instead of calling alloc_contig_range(). Do you believe it would be better to use the cma code, and modify it to use this fast path to take the page drectly from the buddy allocator? I can definitely try to integrate the code with cma_alloc(), but I think keeping the fast path for reserving tag storage is extremely desirable, since it makes such a huge difference to performance. [1] https://lore.kernel.org/linux-trace-kernel/20231119165721.9849-27-alexandru.elisei@arm.com/ Thanks, Alex > > -- > Cheers, > > David / dhildenb > >