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 B1480C4345F for ; Fri, 26 Apr 2024 15:09:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 476976B0096; Fri, 26 Apr 2024 11:09:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 426456B0098; Fri, 26 Apr 2024 11:09:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2EE3F6B009A; Fri, 26 Apr 2024 11:09:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 112FA6B0096 for ; Fri, 26 Apr 2024 11:09:15 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id C4BB61C0B0F for ; Fri, 26 Apr 2024 15:09:14 +0000 (UTC) X-FDA: 82052016228.22.BC7F8AA Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf28.hostedemail.com (Postfix) with ESMTP id 96CA1C002A for ; Fri, 26 Apr 2024 15:09:11 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=IAhOXheB; spf=pass (imf28.hostedemail.com: domain of djwong@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=djwong@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1714144152; 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:dkim-signature; bh=8V1ItYfrOjWOEHSCZPGFHW113wst0hDbgmXT3jq0U60=; b=7tyiwt7iRABHWgC6S+PtC3GV6I0SM0DXCUaPvbt3W3vNjR5WiCb0tSb+HF8taUhAJwQslF TWZA8H7uR/hWnPircHb0W4K9nUoJ9oFQSE2Mj+Scb1bbiyQF+bVdi5ddYmIMjcd7RH947k 3ptWl18jlIUVOBU21oJYc8CYA29FobY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1714144152; a=rsa-sha256; cv=none; b=QGbsZPT3Ap4+kt98v6sRbVuhtTe4Q4YvZBhvci+VmwNKWDvEFPZtwITxvKjAq+GvRbJdQl y+5yhhhKrX5jsoL8qZ2nTun9cfzOw4h6iHi8chbqBuoTnC2s6noWRxf7deRkkdtTdwhTMo MhYOgckdJEATUHHKyVzayaa75D9sf4E= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=IAhOXheB; spf=pass (imf28.hostedemail.com: domain of djwong@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=djwong@kernel.org; dmarc=pass (policy=none) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 4CABCCE1C8D; Fri, 26 Apr 2024 15:09:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 65DF4C113CD; Fri, 26 Apr 2024 15:09:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714144146; bh=1EfFaT2e5RgbE+xX1x4IG+RRoAmpjsYgLXgHqkDgINc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=IAhOXheBGM++yaYo+e3kZwiwfI79o2O+mL2LPAt4MbZdYEC3+usp6A5WvqG8q6VgY sNWFG1/roU/lp+Y6JgZH6fQko5jVQZJ7/JUnmuboqcjOJA1is3shxB3J0Gqoq+IgDI Sz7OkjoSVqHebxZFlPhf7t638z13ZHyD5cZRRe6V/64VITnqh97YHZ097BYzkISUC4 dENjq3lZI0pbolHnBNDOOG7HMnhtmkNxRTDetfuLBe1OqBwvEqnsOJKXMn5TDoj8d6 yLXfDi6vKi08DuoYTLDdZ+6N+oWftN/JrWdhoBNONbz+QXJNcJJApZu1CKKg+No2Sz WDFekvnZ35GFg== Date: Fri, 26 Apr 2024 08:09:05 -0700 From: "Darrick J. Wong" To: "Pankaj Raghav (Samsung)" Cc: willy@infradead.org, brauner@kernel.org, david@fromorbit.com, chandan.babu@oracle.com, akpm@linux-foundation.org, linux-fsdevel@vger.kernel.org, hare@suse.de, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-xfs@vger.kernel.org, mcgrof@kernel.org, gost.dev@samsung.com, p.raghav@samsung.com Subject: Re: [PATCH v4 02/11] fs: Allow fine-grained control of folio sizes Message-ID: <20240426150905.GC360919@frogsfrogsfrogs> References: <20240425113746.335530-1-kernel@pankajraghav.com> <20240425113746.335530-3-kernel@pankajraghav.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240425113746.335530-3-kernel@pankajraghav.com> X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 96CA1C002A X-Rspam-User: X-Stat-Signature: gti9mpb75s69fpk3aeenbynm1odapyhd X-HE-Tag: 1714144151-110722 X-HE-Meta: U2FsdGVkX18NTJuNLFDAcSYdBpHZJPS611yBQ77xtQuZW8p47BTBvYz1IVh+Ev6/x6N+JaDyvDa7S81J3NLQduNRU54UMAkKLFqTqelzGfkyTT2L+x1eUI/wsHj83BiEZdLwD8lsyHaA+q6fBLGBQKEnX5nplwFKSCcV1zs3cFodwlW9Vqxf+Ha0DYoUvCfwje7BuALsB2eqMvruZ4ubSNtzbGzFm5dJ/WYpjwCIPvm3bzRawgj5rvK8Dms5hM8PBEeWP6F91e5a8g6IwDt7Q0IQW2fvEJROCsE30Nuvk/wmYyBi7XG44wzCJLP+hmd++zpVT744d2gUgRcz5xenl0mnBlGyE2auCejRi0QCTdD2azAFvqSmSaJYmgbqrxoDiSMFK9id/pF2b/rOUA3Rkj8IX1AglCAAqOlDK+7WOhWe5wfjRRWX0txB7li2+WcO9kaYB3TYwI6n5iwIS8YitbRUjszLs/4FOyGAdAV8MRlSpG7atjF38VrMkN+k87vjRGkbcdsfiVEpfp8fMeC2iMNG631fhJuVZwXhVD5oqI7PBCuwGaC14STUyeftC5GKFo8A31jCwpAPLbpsI2N56X5lmqeeJtb/0ErollQ6Y8RPx5hCIHDHlagSLXB+3LX0daVzXIv0Hhz27tPYzjH5bpAbMkWMX/iy9aRRaCu88AiJp23icLK6uUa7ZyeMfc3CSR4HG7HvWylQ5U8iTegWJWeTqayrbvnmsIg90YmAp0bpqGCYpj7rlbQX26jcRjhdZ3c9efFyUSTpLz+Hbldo+8eklOtf+xJ52PcZyJyOHIoOaIFbBB2NZ0QqdYKFq+Gi0VtQrNTcT6Ijuk/Bs3yGXcePQuqqTH3PzpXo7z/pbpd/R5dolYUU+imSsRwzny8Kk2TljvIIUM0= 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: On Thu, Apr 25, 2024 at 01:37:37PM +0200, Pankaj Raghav (Samsung) wrote: > From: "Matthew Wilcox (Oracle)" > > Some filesystems want to be able to ensure that folios that are added to > the page cache are at least a certain size. > Add mapping_set_folio_min_order() to allow this level of control. > > Signed-off-by: Matthew Wilcox (Oracle) > Co-developed-by: Pankaj Raghav > Signed-off-by: Pankaj Raghav > Signed-off-by: Luis Chamberlain Looks good to me, Reviewed-by: Darrick J. Wong --D > --- > include/linux/pagemap.h | 116 +++++++++++++++++++++++++++++++++------- > 1 file changed, 96 insertions(+), 20 deletions(-) > > diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h > index 2df35e65557d..2e5612de1749 100644 > --- a/include/linux/pagemap.h > +++ b/include/linux/pagemap.h > @@ -202,13 +202,18 @@ enum mapping_flags { > AS_EXITING = 4, /* final truncate in progress */ > /* writeback related tags are not used */ > AS_NO_WRITEBACK_TAGS = 5, > - AS_LARGE_FOLIO_SUPPORT = 6, > - AS_RELEASE_ALWAYS, /* Call ->release_folio(), even if no private data */ > - AS_STABLE_WRITES, /* must wait for writeback before modifying > + AS_RELEASE_ALWAYS = 6, /* Call ->release_folio(), even if no private data */ > + AS_STABLE_WRITES = 7, /* must wait for writeback before modifying > folio contents */ > - AS_UNMOVABLE, /* The mapping cannot be moved, ever */ > + AS_FOLIO_ORDER_MIN = 8, > + AS_FOLIO_ORDER_MAX = 13, /* Bit 8-17 are used for FOLIO_ORDER */ > + AS_UNMOVABLE = 18, /* The mapping cannot be moved, ever */ > }; > > +#define AS_FOLIO_ORDER_MIN_MASK 0x00001f00 > +#define AS_FOLIO_ORDER_MAX_MASK 0x0003e000 > +#define AS_FOLIO_ORDER_MASK (AS_FOLIO_ORDER_MIN_MASK | AS_FOLIO_ORDER_MAX_MASK) > + > /** > * mapping_set_error - record a writeback error in the address_space > * @mapping: the mapping in which an error should be set > @@ -344,9 +349,63 @@ static inline void mapping_set_gfp_mask(struct address_space *m, gfp_t mask) > m->gfp_mask = mask; > } > > +/* > + * There are some parts of the kernel which assume that PMD entries > + * are exactly HPAGE_PMD_ORDER. Those should be fixed, but until then, > + * limit the maximum allocation order to PMD size. I'm not aware of any > + * assumptions about maximum order if THP are disabled, but 8 seems like > + * a good order (that's 1MB if you're using 4kB pages) > + */ > +#ifdef CONFIG_TRANSPARENT_HUGEPAGE > +#define MAX_PAGECACHE_ORDER HPAGE_PMD_ORDER > +#else > +#define MAX_PAGECACHE_ORDER 8 > +#endif > + > +/* > + * mapping_set_folio_order_range() - Set the folio order range > + * @mapping: The address_space. > + * @min: Minimum folio order (between 0-MAX_PAGECACHE_ORDER inclusive). > + * @max: Maximum folio order (between @min-MAX_PAGECACHE_ORDER inclusive). > + * > + * The filesystem should call this function in its inode constructor to > + * indicate which base size (min) and maximum size (max) of folio the VFS > + * can use to cache the contents of the file. This should only be used > + * if the filesystem needs special handling of folio sizes (ie there is > + * something the core cannot know). > + * Do not tune it based on, eg, i_size. > + * > + * Context: This should not be called while the inode is active as it > + * is non-atomic. > + */ > +static inline void mapping_set_folio_order_range(struct address_space *mapping, > + unsigned int min_order, > + unsigned int max_order) > +{ > + if (min_order > MAX_PAGECACHE_ORDER) > + min_order = MAX_PAGECACHE_ORDER; > + > + if (max_order > MAX_PAGECACHE_ORDER) > + max_order = MAX_PAGECACHE_ORDER; > + > + max_order = max(max_order, min_order); > + /* > + * TODO: max_order is not yet supported in filemap. > + */ > + mapping->flags = (mapping->flags & ~AS_FOLIO_ORDER_MASK) | > + (min_order << AS_FOLIO_ORDER_MIN) | > + (max_order << AS_FOLIO_ORDER_MAX); > +} > + > +static inline void mapping_set_folio_min_order(struct address_space *mapping, > + unsigned int min) > +{ > + mapping_set_folio_order_range(mapping, min, MAX_PAGECACHE_ORDER); > +} > + > /** > * mapping_set_large_folios() - Indicate the file supports large folios. > - * @mapping: The file. > + * @mapping: The address_space. > * > * The filesystem should call this function in its inode constructor to > * indicate that the VFS can use large folios to cache the contents of > @@ -357,7 +416,37 @@ static inline void mapping_set_gfp_mask(struct address_space *m, gfp_t mask) > */ > static inline void mapping_set_large_folios(struct address_space *mapping) > { > - __set_bit(AS_LARGE_FOLIO_SUPPORT, &mapping->flags); > + mapping_set_folio_order_range(mapping, 0, MAX_PAGECACHE_ORDER); > +} > + > +static inline unsigned int mapping_max_folio_order(struct address_space *mapping) > +{ > + return (mapping->flags & AS_FOLIO_ORDER_MAX_MASK) >> AS_FOLIO_ORDER_MAX; > +} > + > +static inline unsigned int mapping_min_folio_order(struct address_space *mapping) > +{ > + return (mapping->flags & AS_FOLIO_ORDER_MIN_MASK) >> AS_FOLIO_ORDER_MIN; > +} > + > +static inline unsigned long mapping_min_folio_nrpages(struct address_space *mapping) > +{ > + return 1UL << mapping_min_folio_order(mapping); > +} > + > +/** > + * mapping_align_start_index() - Align starting index based on the min > + * folio order of the page cache. > + * @mapping: The address_space. > + * > + * Ensure the index used is aligned to the minimum folio order when adding > + * new folios to the page cache by rounding down to the nearest minimum > + * folio number of pages. > + */ > +static inline pgoff_t mapping_align_start_index(struct address_space *mapping, > + pgoff_t index) > +{ > + return round_down(index, mapping_min_folio_nrpages(mapping)); > } > > /* > @@ -367,7 +456,7 @@ static inline void mapping_set_large_folios(struct address_space *mapping) > static inline bool mapping_large_folio_support(struct address_space *mapping) > { > return IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE) && > - test_bit(AS_LARGE_FOLIO_SUPPORT, &mapping->flags); > + (mapping_max_folio_order(mapping) > 0); > } > > static inline int filemap_nr_thps(struct address_space *mapping) > @@ -528,19 +617,6 @@ static inline void *detach_page_private(struct page *page) > return folio_detach_private(page_folio(page)); > } > > -/* > - * There are some parts of the kernel which assume that PMD entries > - * are exactly HPAGE_PMD_ORDER. Those should be fixed, but until then, > - * limit the maximum allocation order to PMD size. I'm not aware of any > - * assumptions about maximum order if THP are disabled, but 8 seems like > - * a good order (that's 1MB if you're using 4kB pages) > - */ > -#ifdef CONFIG_TRANSPARENT_HUGEPAGE > -#define MAX_PAGECACHE_ORDER HPAGE_PMD_ORDER > -#else > -#define MAX_PAGECACHE_ORDER 8 > -#endif > - > #ifdef CONFIG_NUMA > struct folio *filemap_alloc_folio(gfp_t gfp, unsigned int order); > #else > -- > 2.34.1 > >