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 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 03F8FCD4F54 for ; Fri, 29 May 2026 12:36:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:In-Reply-To:From:References:Cc:To:Subject:MIME-Version:Date: Message-ID:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=9lVmfgexspnKoW/3agaiDvDisr/iv75bUoYrdSLOXwE=; b=g0bK3LmzcaQ8nTp/uTpFIOK7Hf Az5j6mr7rn7pUL+C+pAwOqgWVkI+Y2wmREbF46JdhsxF341FBMJt7vMqRXFVxrxIRfQSbVRptNAbN lIAcBsjnGTL02MrI3Y9Bl/XQadY9riS8ucozcGcfVKRhZdBc0otD1AsY8FU/8XH8bKb+1tnEQnq66 lNFJ2FFc9VpzY1FZfygttWFpH4pjJaYtxLJXWGlHKWwwTgjrdVezPwfvi90NqN1ouOH+LAAfa+bF2 14As5AVPSsKhmWo3zkSqg6yXrQmbq95AAQaP2QXKsU6l+la/ehbn0ZzjAXmFouP2cGKSW2gW40vER Zt8PzLCg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wSwS5-00000007OGp-00Dj; Fri, 29 May 2026 12:36:37 +0000 Received: from out-181.mta1.migadu.com ([95.215.58.181]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1wSwS2-00000007OGI-28P9 for linux-arm-kernel@lists.infradead.org; Fri, 29 May 2026 12:36:36 +0000 Message-ID: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1780058181; h=from:from: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=9lVmfgexspnKoW/3agaiDvDisr/iv75bUoYrdSLOXwE=; b=jjsu6MlvrjBVw8EHwN0hZmMlYdVyXnIGj7OspJTJ4D6N+7yBnvman4zcAHpc1Ij97Gm08b r/smJSHm1710yMUCteZUE0tkdOltvNb2M1Yl3SZ4d9zzKBzaKOzUGwE6mp49+rBFiVdWRH JYU2SGHM12nodC78Fy/TqrlxlFyboI8= Date: Fri, 29 May 2026 13:36:10 +0100 MIME-Version: 1.0 Subject: Re: [PATCH v6 2/2] mm: use mapping_max_folio_order() for force_thp_readahead order To: Andrew Morton , david@kernel.org, willy@infradead.org, ryan.roberts@arm.com, linux-mm@kvack.org Cc: r@hev.cc, jack@suse.cz, Andrew Donnellan , apopple@nvidia.com, baohua@kernel.org, baolin.wang@linux.alibaba.com, brauner@kernel.org, catalin.marinas@arm.com, dev.jain@arm.com, kees@kernel.org, kevin.brodsky@arm.com, lance.yang@linux.dev, "Liam R. Howlett" , linux-arm-kernel@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, ljs@kernel.org, mhocko@suse.com, npache@redhat.com, pasha.tatashin@soleen.com, rmclure@linux.ibm.com, rppt@kernel.org, surenb@google.com, vbabka@kernel.org, Al Viro , ziy@nvidia.com, hannes@cmpxchg.org, kas@kernel.org, shakeel.butt@linux.dev, kernel-team@meta.com References: <20260528165635.2068012-1-usama.arif@linux.dev> <20260528165635.2068012-3-usama.arif@linux.dev> Content-Language: en-US X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Usama Arif In-Reply-To: <20260528165635.2068012-3-usama.arif@linux.dev> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260529_053634_862590_2364295A X-CRM114-Status: GOOD ( 30.38 ) 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 On 28/05/2026 17:55, Usama Arif wrote: > The force_thp_readahead path in do_sync_mmap_readahead() is gated on > HPAGE_PMD_ORDER <= MAX_PAGECACHE_ORDER and always requests > HPAGE_PMD_ORDER / HPAGE_PMD_NR. On configurations where HPAGE_PMD_ORDER > exceeds MAX_PAGECACHE_ORDER, notably arm64 with a 64K base page size, > VM_HUGEPAGE mappings cannot use this path and fall back to the non-forced > mmap readahead path even when the mapping supports useful large folios. > > Keep the existing PMD-sized behavior when HPAGE_PMD_ORDER fits in the > page cache. When it does not, enable forced readahead for mappings that > support large folios and request an order capped by both > mapping_max_folio_order(mapping) and 2MB. > > 2MB is chosen as the cap because it matches the PMD size on x86_64 > and on arm64 with 4K or 16K base pages, so the size/memory-pressure > tradeoff for folios of that size is already well understood. On arm64 > with a 64K base page size, 2MB is also the contiguous-PTE (contpte) > block size, so the resulting folios coalesce into a single TLB entry > and reduce TLB pressure on the readahead path. > > The final allocation order may still be clamped by page_cache_ra_order() > to the mapping and request geometry, but this gives VM_HUGEPAGE mappings > on such configurations a large-folio readahead request instead of > dropping back to base-page readahead. > > Signed-off-by: Usama Arif > --- > mm/filemap.c | 27 +++++++++++++++++++-------- > 1 file changed, 19 insertions(+), 8 deletions(-) > > diff --git a/mm/filemap.c b/mm/filemap.c > index a16b33e0fc71..bfb891d9da1f 100644 > --- a/mm/filemap.c > +++ b/mm/filemap.c > @@ -3312,14 +3312,23 @@ static struct file *do_sync_mmap_readahead(struct vm_fault *vmf) > struct file *fpin = NULL; > vm_flags_t vm_flags = vmf->vma->vm_flags; > bool force_thp_readahead = false; > + unsigned int thp_order = 0; > unsigned short mmap_miss; > > ractl._max_index = vmf->vma->vm_pgoff + vma_pages(vmf->vma) - 1; > > /* Use the readahead code, even if readahead is disabled */ > - if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE) && > - (vm_flags & VM_HUGEPAGE) && HPAGE_PMD_ORDER <= MAX_PAGECACHE_ORDER) > - force_thp_readahead = true; > + if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE) && (vm_flags & VM_HUGEPAGE)) { > + if (HPAGE_PMD_ORDER <= MAX_PAGECACHE_ORDER) { > + force_thp_readahead = true; > + thp_order = HPAGE_PMD_ORDER; > + } else if (mapping_large_folio_support(mapping)) { > + force_thp_readahead = true; > + thp_order = min_t(unsigned int, > + mapping_max_folio_order(mapping), > + get_order(SZ_2M)); > + } > + } > I think might be good to include the below comment to explain the decision being made here: >From 6673c04a434df01d449c1bdb9ac8de74e19d6b7e Mon Sep 17 00:00:00 2001 From: Usama Arif Date: Fri, 29 May 2026 05:31:05 -0700 Subject: [PATCH] [fixlet] mm/filemap: add comment explaining design decision Signed-off-by: Usama Arif --- mm/filemap.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/mm/filemap.c b/mm/filemap.c index bfb891d9da1f..0a3facf452b3 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -3319,6 +3319,14 @@ static struct file *do_sync_mmap_readahead(struct vm_fault *vmf) /* Use the readahead code, even if readahead is disabled */ if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE) && (vm_flags & VM_HUGEPAGE)) { + /* + * Preserve PMD-sized readahead where it already fits in + * the page cache. Otherwise cap the new fallback path at + * 2MB: this is the common PMD-sized hugepage size, and it + * avoids memory pressure from very large forced readahead + * when mapping_max_folio_order() is high (for example, + * 128MB with 64K base pages on arm64). + */ if (HPAGE_PMD_ORDER <= MAX_PAGECACHE_ORDER) { force_thp_readahead = true; thp_order = HPAGE_PMD_ORDER; -- 2.53.0-Meta