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 C3E4FC4829E for ; Thu, 15 Feb 2024 22:49:10 +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:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=qNyw82uziXM4gECuLZxkD6Qj+eFnIiNtG6qf+ZtOg/k=; b=yyFzYuwYg21vvf BEzVEdDW0DX/bnJHnQ5WvbD66DTJQBeD4fQ3WMpvLDI4ouHuE3ic+UD179xgxPvJhkgl7LX4lq7eG M1lDNp7FZmN9SxEnz88PWJvzsxS/EZiWAhhuEwifcb371vvgnIiPcY1iAMr2FzG6oE7VtdcN/cncU n1UKzLl2q/+mLrRk7H3Af1O1oj7/LRw/ROQMB0wenpiTqH3ax29m/WtWQP3TyyD7KgGTauRjB56Yv qLquw8NbXY05Tk6SxiYiu1goqbdtiRmLRUhVaDG1abyHUyeAbemaGKtFwUhTqzvaXAxSI6ZdKA+/Z d0RBtNLa1EM5pTf1KAZA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rakXH-00000000NmD-2p4n; Thu, 15 Feb 2024 22:48:55 +0000 Received: from sin.source.kernel.org ([2604:1380:40e1:4800::1]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rakXF-00000000NlU-2KFi for linux-arm-kernel@lists.infradead.org; Thu, 15 Feb 2024 22:48:55 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id C26F7CE18AB; Thu, 15 Feb 2024 22:48:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8B9DAC433C7; Thu, 15 Feb 2024 22:48:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1708037331; bh=O2YipuwbWV1YLastP336dH3q8Zkm6CgW4TI5yh0PFMM=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=DARco0iCdfuae92XExh7ksU1jOCySljoFJvUjTDn6qsullpN+UZD19SQnJFqhMYAZ oOm+fymLMFt8D+F9JZKcJYJsu3fAkB0Xfg6t5w4Y8bHGlrMdP//45q1dE8IjOYoDXb P21Fkvnul+Og6eWw2GUVO+Duw3g99sqJQjsFXikQ= Date: Thu, 15 Feb 2024 14:48:49 -0800 From: Andrew Morton To: Ryan Roberts Cc: Catalin Marinas , Will Deacon , Mark Rutland , "Matthew Wilcox (Oracle)" , 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 Subject: Re: [PATCH v2] mm/filemap: Allow arch to request folio size for exec memory Message-Id: <20240215144849.aba06863acc08b8ded09a187@linux-foundation.org> In-Reply-To: <20240215154059.2863126-1-ryan.roberts@arm.com> References: <20240215154059.2863126-1-ryan.roberts@arm.com> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Mime-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240215_144853_956285_D75CF4E6 X-CRM114-Status: GOOD ( 29.47 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, 15 Feb 2024 15:40:59 +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. Some nits: > --- a/arch/arm64/include/asm/pgtable.h > +++ b/arch/arm64/include/asm/pgtable.h > @@ -1115,6 +1115,18 @@ static inline void update_mmu_cache_range(struct vm_fault *vmf, > */ > #define arch_wants_old_prefaulted_pte cpu_has_hw_af > > +/* > + * Request exec memory is read into pagecache in at least 64K folios. The > + * trade-off here is performance improvement due to storing translations more > + * effciently in the iTLB vs the potential for read amplification due to reading "efficiently" > + * data from disk that won't be used. The latter is independent of base page > + * size, so we set a page-size independent block size of 64K. This size can be > + * contpte-mapped when 4K base pages are in use (16 pages into 1 iTLB entry), > + * and HPA can coalesce it (4 pages into 1 TLB entry) when 16K base pages are in > + * use. > + */ > +#define arch_wants_exec_folio_order() ilog2(SZ_64K >> PAGE_SHIFT) > + To my eye, "arch_wants_foo" and "arch_want_foo" are booleans. Either this arch wants a particular treatment or it does not want it. I suggest a better name would be "arch_exec_folio_order". > static inline bool pud_sect_supported(void) > { > return PAGE_SIZE == SZ_4K; > diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h > index aab227e12493..6cdd145cbbb9 100644 > --- a/include/linux/pgtable.h > +++ b/include/linux/pgtable.h > @@ -407,6 +407,18 @@ static inline bool arch_has_hw_pte_young(void) > } > #endif > > +#ifndef arch_wants_exec_folio_order > +/* > + * Returns preferred minimum folio order for executable file-backed memory. Must > + * be in range [0, PMD_ORDER]. Negative value implies that the HW has no > + * preference and mm will not special-case executable memory in the pagecache. > + */ I think this comment contains material which would be useful above the other arch_wants_exec_folio_order() implementation - the "must be in range" part. So I suggest all this material be incorporated into a single comment which describes arch_wants_exec_folio_order(). Then this comment can be removed entirely. Assume the reader knows to go seek the other definition for the commentary. > +static inline int arch_wants_exec_folio_order(void) > +{ > + return -1; > +} > +#endif > + > #ifndef arch_check_zapped_pte > static inline void arch_check_zapped_pte(struct vm_area_struct *vma, > pte_t pte) > diff --git a/mm/filemap.c b/mm/filemap.c > index 142864338ca4..7954274de11c 100644 > --- a/mm/filemap.c > +++ b/mm/filemap.c > @@ -3118,6 +3118,25 @@ static struct file *do_sync_mmap_readahead(struct vm_fault *vmf) > } > #endif > > + /* > + * Allow arch to request a preferred minimum folio order for executable > + * memory. This can often be beneficial to performance if (e.g.) arm64 > + * can contpte-map the folio. Executable memory rarely benefits from > + * read-ahead anyway, due to its random access nature. "readahead" > + */ > + if (vm_flags & VM_EXEC) { > + int order = arch_wants_exec_folio_order(); > + > + if (order >= 0) { > + fpin = maybe_unlock_mmap_for_io(vmf, fpin); > + ra->size = 1UL << order; > + ra->async_size = 0; > + ractl._index &= ~((unsigned long)ra->size - 1); > + page_cache_ra_order(&ractl, ra, order); > + return fpin; > + } > + } > + > /* If we don't want any read-ahead, don't bother */ > if (vm_flags & VM_RAND_READ) > return fpin; _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel