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 37F24C48260 for ; Fri, 16 Feb 2024 11:18:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BCF738D0006; Fri, 16 Feb 2024 06:18:34 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B57B08D0001; Fri, 16 Feb 2024 06:18:34 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9D01E8D0006; Fri, 16 Feb 2024 06:18:34 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 87E1E8D0001 for ; Fri, 16 Feb 2024 06:18:34 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id C3B421204E7 for ; Fri, 16 Feb 2024 11:18:33 +0000 (UTC) X-FDA: 81797418906.15.888A90C Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf09.hostedemail.com (Postfix) with ESMTP id D7F1B140010 for ; Fri, 16 Feb 2024 11:18:31 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf09.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708082312; a=rsa-sha256; cv=none; b=lwXBWkEymoX2ilQlKOzTdQarndhRbco3n7eagNnuO1e+bdZaFBcGxUbFdbzvdajxoP/0b8 8CBhYmqOVnNmP+sgbNSEIpNkFQ+qWGp5V3UNgDJtjg8qnLPN3q9nf/UTaMMYRkCMNb1Oob m6wzZ7FNlPzEdAwLXAp3mphMQQ/3v9U= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf09.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708082312; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QE/gphbVRj83lSk45cRT2VLceedunZ1vmfyNltGNY0M=; b=JL13GpPYw0OtQg+KVTPPvfsLzxvAfcOhUQqkP8FI8b92W15zPnlwG/qudanGwA4FxpEp87 dezhxUU9Jvgpalc3nar3p10olLrN99npa4pEfuszYB7+fgFcauViwbU+EftTdPIrQ9ixts 1Q1+FzT6jr/DO0oyRMWXamVrLW+3fzw= 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 8EDEE1FB; Fri, 16 Feb 2024 03:19:11 -0800 (PST) Received: from [192.168.68.110] (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id ABDD73F766; Fri, 16 Feb 2024 03:18:28 -0800 (PST) Message-ID: <58a67051-6d61-4d16-b073-266522907e05@arm.com> Date: Fri, 16 Feb 2024 11:18:27 +0000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] mm/filemap: Allow arch to request folio size for exec memory Content-Language: en-GB To: Dave Chinner Cc: Catalin Marinas , Will Deacon , Mark Rutland , "Matthew Wilcox (Oracle)" , Andrew Morton , David Hildenbrand , Barry Song <21cnbao@gmail.com>, John Hubbard , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org References: <20240215154059.2863126-1-ryan.roberts@arm.com> From: Ryan Roberts In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: D7F1B140010 X-Stat-Signature: nzm7ahbo5s4ixp8j9yhmdmujq1xz9nhg X-Rspam-User: X-HE-Tag: 1708082311-235066 X-HE-Meta: U2FsdGVkX18OrR3I1zLMu2GN3z41Kkj7eZCQET1aq+hdILV4ojblaI5gR3GwCPC1Q75cdRmBPhbuc77Xl1UIzHxij33KG+qfwhxae3JeaKwH6L/TraiFo2cmw0g443QbmhyqfsyrlmQqFgV45LRz2l1PVECwDgxnvFbvkstIV0JDIgfNophT59xqowh4iQQnRfcMDfLaAtd3vLe8FuE6MQRQECl1Macyf2sJFGsmaN9jcCWO9Zh+z+iWCUrblNDD9RlBFUScdp0VNUNz2uWNykikLdFUhVq3WqPXyM3QR9Q2kuepcYfQyMbznn1Y02fgIZ5Zx9mMWBxUJ1RPD3tiF2nWk81VR7X1UaqQ6FvQEFXeiSHsLG0KvuMcC16zXLjpSN7ceBf6LhcLBcwUtoumdUjqnn5YoumD5E+oK2ZpMSA18SIVblgzqPFiSFgwZ8axdoSOa1yVa7j0x7eZteByq2OlWMViXGC6wByuLUSqH+3HLZPexM6CLw27m4cTyV6w+LMq6eIT/ydZTAcqfmWo2+6tVeCcKdonpM3rDvlApInFvax7N4MPQcMnkbZANizwV3gRGWM+AEh3Kqh7zMMi8a5JrmCfy5rXqtFeWMNGzW65A+/iDA/GHHNu8+uQZD2qiMLECEmBNT3524wq55gLJd0H1coXS9EVp76OH9WXd/YP/EmnkIiOV9QFvMzLZlUXn3y1teZKNEn86z77/RX6FOwhe1W4qkhUyoegJqJ2eXnTg9gfjdYE3tGp5Lhj3/4wtIXXQ01wW3S1q2aW01E4RVmGQeoCvjTxv0VyW4xQZev+l9nwJHg5/Rhykm53Lqur/v6i66Vzq23NCXWdsRa0I/VXtKY5A9FI 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 Dave, Thanks for taking a look at this! Some comments below... On 16/02/2024 00:04, Dave Chinner wrote: > On Thu, Feb 15, 2024 at 03:40:59PM +0000, Ryan Roberts wrote: >> Change the readahead config so that if it is being requested for an >> executable mapping, do a synchronous read of an arch-specified size in a >> naturally aligned manner. >> >> On arm64 if memory is physically contiguous and naturally aligned to the >> "contpte" size, we can use contpte mappings, which improves utilization >> of the TLB. When paired with the "multi-size THP" changes, this works >> well to reduce dTLB pressure. However iTLB pressure is still high due to >> executable mappings having a low liklihood of being in the required >> folio size and mapping alignment, even when the filesystem supports >> readahead into large folios (e.g. XFS). >> >> The reason for the low liklihood is that the current readahead algorithm >> starts with an order-2 folio and increases the folio order by 2 every >> time the readahead mark is hit. But most executable memory is faulted in >> fairly randomly and so the readahead mark is rarely hit and most >> executable folios remain order-2. > > Yup, this is a bug in the readahead code, and really has nothing to > do with executable files, mmap or the architecture. We don't want > some magic new VM_EXEC min folio size per architecture thingy to be > set - we just want readahead to do the right thing. It sounds like we agree that there is a bug but we don't agree on what the bug is? My view is that executable segments are accessed in a ~random manner and therefore readahead (as currently configured) is not very useful. But data may well be accessed more sequentially and therefore readahead is useful. Given both data and text can come from the same file, I don't think this can just be a mapping setting? (my understanding is that there is one "mapping" for the whole file?) So we need to look to VM_EXEC for that decision. > > Indeed, we are already adding a mapping minimum folio order > directive to the address space to allow for filesystem block sizes > greater than PAGE_SIZE. That's the generic mechanism that this > functionality requires. See here: > > https://lore.kernel.org/linux-xfs/20240213093713.1753368-5-kernel@pankajraghav.com/ Great, I'm vaguely aware of this work, but haven't looked in detail. I'll go read it. But from your brief description, IIUC, this applies to the whole file, and is a constraint put in place by the filesystem? Applying to the whole file may make sense - that means more opportunity for contpte mappings for data pages too, although I guess this adds more scope for write amplificaiton because data tends to be writable, and text isn't. But for my use case, its not a hard constraint, its just a preference which can improve performance. And the filesystem is the wrong place to make the decision; its the arch that knows about the performacne opportunities with different block mapping sizes. As a side note, concerns have been expressed about the possibility of physical memory fragmentation becoming problematic, meaning we degrade back to small folios over time with my mTHP work. The intuituon is that if the whole system is using a few folio sizes in ~equal quantities then we might be ok, but I don't have any data yet. Do you have any data on fragmentation? I guess this could be more concerning for your use case? > > (Probably worth reading some of the other readahead mods in that > series and the discussion because readahead needs to ensure that it > fill entire high order folios in a single IO to avoid partial folio > up-to-date states from partial reads.) > > IOWs, it seems to me that we could use this proposed generic mapping > min order functionality when mmap() is run and VM_EXEC is set to set > the min order to, say, 64kB. Then the readahead code would simply do > the right thing, as would all other reads and writes to that > mapping. Ahh yes, hooking into your new logic to set a min order based on VM_EXEC sounds perfect... > > We could trigger this in the ->mmap() method of the filesystem so > that filesysetms that can use large folios can turn it on, whilst > other filesystems remain blissfully unaware of the functionality. > Filesystems could also do smarter things here, too. eg. enable PMD > alignment for large mapped files.... ...but I don't think the filesystem is the right place. The size preference should be driven by arch IMHO. Thanks, Ryan > > -Dave.