From patchwork Tue Feb 13 09:37:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Pankaj Raghav (Samsung)" X-Patchwork-Id: 13554782 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 D8226C48260 for ; Tue, 13 Feb 2024 09:37:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 720A76B0074; Tue, 13 Feb 2024 04:37:27 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6A9A96B0075; Tue, 13 Feb 2024 04:37:27 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5718A6B007B; Tue, 13 Feb 2024 04:37:27 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 485416B0074 for ; Tue, 13 Feb 2024 04:37:27 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id DBEEDC0B13 for ; Tue, 13 Feb 2024 09:37:26 +0000 (UTC) X-FDA: 81786277692.02.1A5A60D Received: from mout-p-201.mailbox.org (mout-p-201.mailbox.org [80.241.56.171]) by imf16.hostedemail.com (Postfix) with ESMTP id 1AFB0180005 for ; Tue, 13 Feb 2024 09:37:24 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b="0mK9WM/E"; spf=pass (imf16.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.171 as permitted sender) smtp.mailfrom=me@pankajraghav.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707817045; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=IYsJ32qMRCtWIP7xXM7OP+qt3qi8RVhOs/HaC3Mhi1k=; b=rGESVAmAFojBZxDOVTu7DeiRya8e5SBTpNAocnc6+GLd+0vpNVnsufslP4IIf6FIvD9B+/ jUrsOs03WxqT7dbo7IcMxM7xYrkb95IcqITXmUqkiAKpvWwxfLWqzHjS77h8w7nyi+u10k KvPio87AdGiDJBqiJNUQUKB79zMQkds= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707817045; a=rsa-sha256; cv=none; b=hHHkuLmb/7GnRl//0ykI3AN9dP1B1RSs16hm6R2yAsle1rbBYKQQqY35zZiuU4vdqqmtkR 3c7Qpui++hS96dxDaTwVAvb+3G2JXDOvnALV+YP2SKkeNehV1sVHQrjD3M84wAijNfOPi6 BoPEK6h3TH4M0TmP9DaFN35i0GvfRuY= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b="0mK9WM/E"; spf=pass (imf16.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.171 as permitted sender) smtp.mailfrom=me@pankajraghav.com; dmarc=none Received: from smtp202.mailbox.org (smtp202.mailbox.org [10.196.197.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-201.mailbox.org (Postfix) with ESMTPS id 4TYx7P5TQGz9sTM; Tue, 13 Feb 2024 10:37:21 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1707817041; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IYsJ32qMRCtWIP7xXM7OP+qt3qi8RVhOs/HaC3Mhi1k=; b=0mK9WM/EFBtMl+dbpHA5NndcygMmv6RRM66I83fovGzWHIsnV7/2VPdQm8kcB3euYKZSFX UatwkePCcSp/Lzf0q+P8t99PuCfm8y7LsDJ0RhTt7Mh+11SSEqyFtQxXyHmbsXW8YXXsnw nQX/tG65TSJ/9vVVm/LW8DSW5GATIO5FBux0ZARu9/qrlU/C6PUxh6YE3l+j1jP5QY70yw ppe/kcPhJTO6Cpl8yT2bPB8K2n3jJXPahl9kOH8NLS+jdVgubCwhPrSbxCg0X/40NgdFXC ptJxZqX4UXs21l8Me8WCfP+0NXi0g5N0JTA/flhbb9ayDk+o55DciZOM3XGHWw== From: "Pankaj Raghav (Samsung)" To: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: mcgrof@kernel.org, gost.dev@samsung.com, akpm@linux-foundation.org, kbusch@kernel.org, djwong@kernel.org, chandan.babu@oracle.com, p.raghav@samsung.com, linux-kernel@vger.kernel.org, hare@suse.de, willy@infradead.org, linux-mm@kvack.org, david@fromorbit.com Subject: [RFC v2 01/14] fs: Allow fine-grained control of folio sizes Date: Tue, 13 Feb 2024 10:37:00 +0100 Message-ID: <20240213093713.1753368-2-kernel@pankajraghav.com> In-Reply-To: <20240213093713.1753368-1-kernel@pankajraghav.com> References: <20240213093713.1753368-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 1AFB0180005 X-Rspam-User: X-Stat-Signature: xnt1tu8tgiwuaok9k1bky9mnx9u3saxi X-Rspamd-Server: rspam03 X-HE-Tag: 1707817044-71946 X-HE-Meta: U2FsdGVkX1/VoNd5Ob+AuDOWfTrGK9VIjrrup8xZSRiDed4eaPLOBcrX5jx5hbC2dChDZLRJndNczZ0/GaIA1qNJMkEh74jaRHtmUe5aDQP+2cnYezuq92u5RqZjFNFf5iUXXSN0EBGowV3E1qn8wdWhMSkBAhcIp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H702yGIB3wKAwo2UY5jhf/y0E+ZLxUYD1uOi/jfokm0ndAEXpIQxIku1Ex9QgSnj2u6mSSlFb+2zOPXVy8BUpOXClnBM1QFVX4xi7z9MDjju6P6y19M3xYwOIWlHBgV7+/lVBShINwWFJqzciqsHV/Ixg6z/WvVZG3TmehiUUkQlzPNP2osG4clc33rj8qEkgmlkPBd2HhAyPDZg== 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: From: "Matthew Wilcox (Oracle)" Some filesystems want to be able to limit the maximum size of folios, and some want to be able to ensure that folios are at least a certain size. Add mapping_set_folio_orders() to allow this level of control. The max folio order parameter is ignored and it is always set to MAX_PAGECACHE_ORDER. Signed-off-by: Matthew Wilcox (Oracle) Signed-off-by: Pankaj Raghav Signed-off-by: Luis Chamberlain Reviewed-by: Hannes Reinecke --- include/linux/pagemap.h | 92 ++++++++++++++++++++++++++++++++--------- 1 file changed, 73 insertions(+), 19 deletions(-) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index 2df35e65557d..5618f762187b 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,6 +349,53 @@ 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_orders() - Set the range of folio sizes supported. + * @mapping: The file. + * @min: Minimum folio order (between 0-MAX_PAGECACHE_ORDER inclusive). + * @max: Maximum folio order (between 0-MAX_PAGECACHE_ORDER inclusive). + * + * The filesystem should call this function in its inode constructor to + * indicate which sizes 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_orders(struct address_space *mapping, + unsigned int min, unsigned int max) +{ + if (min == 1) + min = 2; + if (max < min) + max = min; + if (max > MAX_PAGECACHE_ORDER) + max = MAX_PAGECACHE_ORDER; + + /* + * XXX: max is ignored as only minimum folio order is supported + * currently. + */ + mapping->flags = (mapping->flags & ~AS_FOLIO_ORDER_MASK) | + (min << AS_FOLIO_ORDER_MIN) | + (MAX_PAGECACHE_ORDER << AS_FOLIO_ORDER_MAX); +} + /** * mapping_set_large_folios() - Indicate the file supports large folios. * @mapping: The file. @@ -357,7 +409,22 @@ 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_orders(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 int mapping_min_folio_nrpages(struct address_space *mapping) +{ + return 1U << mapping_min_folio_order(mapping); } /* @@ -367,7 +434,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 +595,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 From patchwork Tue Feb 13 09:37:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Pankaj Raghav (Samsung)" X-Patchwork-Id: 13554783 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 9321BC4829A for ; Tue, 13 Feb 2024 09:37:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2DC7A6B007D; Tue, 13 Feb 2024 04:37:33 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 265246B0080; Tue, 13 Feb 2024 04:37:33 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0DDF06B0081; Tue, 13 Feb 2024 04:37:33 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id F27616B007D for ; Tue, 13 Feb 2024 04:37:32 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 4570AA093A for ; Tue, 13 Feb 2024 09:37:32 +0000 (UTC) X-FDA: 81786277944.24.BC7B92E Received: from mout-p-101.mailbox.org (mout-p-101.mailbox.org [80.241.56.151]) by imf17.hostedemail.com (Postfix) with ESMTP id 7457240011 for ; Tue, 13 Feb 2024 09:37:30 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=aXtgjhd1; dmarc=none; spf=pass (imf17.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.151 as permitted sender) smtp.mailfrom=me@pankajraghav.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707817050; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=D1pKcMbFRFRAPVwFIcuNop7Fe4l/PLjOYcOBcxoLFyo=; b=vDOeC8MbOiAbsa0sjYWEDa3CY0mI/ZLzo5nc9S2cPM/ttHNbLksLuXqCh066Xjsxu/s/LC jt7b8oSPnwHiv0XHc8uNhjmWbrpak/+aC3Ml4xMeorHUkfQ/67WiVuLAVhlkbYxtxOpW6F cXKnRXqGjGZihTOkosCXCbo70c/Atn8= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=aXtgjhd1; dmarc=none; spf=pass (imf17.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.151 as permitted sender) smtp.mailfrom=me@pankajraghav.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707817050; a=rsa-sha256; cv=none; b=FALosbmJyDCkjBm8LdBMkElFddbzz1BRvyg74IJeD/WKUMAg3xYbkw9QdHXGBSM/HkoI2N WxzlnmO5oFkYVP/xDEFMsbCmiGkv7I7YxIShUXkL7tkTg/zZ5dzPoakw8KjeM/vb0x8iOR QQ+0Q9234FbTVIOQKN7e6aDxWfDzdzk= Received: from smtp102.mailbox.org (smtp102.mailbox.org [IPv6:2001:67c:2050:b231:465::102]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-101.mailbox.org (Postfix) with ESMTPS id 4TYx7V3jchz9smV; Tue, 13 Feb 2024 10:37:26 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1707817046; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=D1pKcMbFRFRAPVwFIcuNop7Fe4l/PLjOYcOBcxoLFyo=; b=aXtgjhd1b//XRwpHD3/R1kk0mMTstSjUb1ouVBf6fckgb8rZuNI8zTh5DEfERSatuEP7pk 8r5YZ81b978D/uP1iocDT3hJ0DAMvsePx0hbDmXJc9fXVhf/Umqd3qoeywBTAMUWEkLzBc vtPR/X4NoIYAa+boy6TQjlTNfkn8RNxra5BUp+2y9fcjIv/1CtJ/6sZEPGCZgSCQqAxIvE 3thP6Rsg48Qm50MXNeztGsGj45DAUmbTwN4x4ViCWqPcJT8qc7mVogI7IwJNiQjIzN9/1H Z+3XDCrnf0weMSLu5URLoEZIWi8/LyMh3ZET8GObGX6Kn0hq/Rz6GqEnzMZ0iw== From: "Pankaj Raghav (Samsung)" To: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: mcgrof@kernel.org, gost.dev@samsung.com, akpm@linux-foundation.org, kbusch@kernel.org, djwong@kernel.org, chandan.babu@oracle.com, p.raghav@samsung.com, linux-kernel@vger.kernel.org, hare@suse.de, willy@infradead.org, linux-mm@kvack.org, david@fromorbit.com Subject: [RFC v2 02/14] filemap: align the index to mapping_min_order in the page cache Date: Tue, 13 Feb 2024 10:37:01 +0100 Message-ID: <20240213093713.1753368-3-kernel@pankajraghav.com> In-Reply-To: <20240213093713.1753368-1-kernel@pankajraghav.com> References: <20240213093713.1753368-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 7457240011 X-Stat-Signature: ofhogf57gbjh3gaw5b1dcijkwq43njgx X-Rspam-User: X-HE-Tag: 1707817050-19110 X-HE-Meta: U2FsdGVkX19PH4+l4YqNjUhj2o/d+95jYIOQjZwBF/TgFIauPFOQBCvKp2Xn6sKUPLZpZsNJjgaYUZNXpYfufjDlWGB30AkuCOo1Z8MynUBrvBBOWgTiubTbW6kvbH6v8SfMwFSN4CvowTVDdxlp0ya0VV2uoDNK+hs1hJupOMq24xOSykaLjXJ1sGlUr4u1KUW/YAgAlGl1nlaxcO4n/lyu/opgcfTVpI+tyhzqDimeNbOe+SW8vm09F/hoInDbsgddGkFJQWumsJb8xKHLQg31nGI7K1ImszUTDKo9yptcPSb8noMM9Z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gizhpXm8lF5wwmsCST2cGnXnn+xk4XEHW0DtQ== 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: From: Luis Chamberlain Supporting mapping_min_order implies that we guarantee each folio in the page cache has at least an order of mapping_min_order. So when adding new folios to the page cache we must ensure the index used is aligned to the mapping_min_order as the page cache requires the index to be aligned to the order of the folio. A higher order folio than min_order by definition is a multiple of the min_order. If an index is aligned to an order higher than a min_order, it will also be aligned to the min order. This effectively introduces no new functional changes when min order is not set other than a few rounding computations that should result in the same value. Signed-off-by: Luis Chamberlain Signed-off-by: Pankaj Raghav --- mm/filemap.c | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/mm/filemap.c b/mm/filemap.c index 750e779c23db..323a8e169581 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2479,14 +2479,16 @@ static int filemap_get_pages(struct kiocb *iocb, size_t count, { struct file *filp = iocb->ki_filp; struct address_space *mapping = filp->f_mapping; + unsigned int min_nrpages = mapping_min_folio_nrpages(mapping); struct file_ra_state *ra = &filp->f_ra; - pgoff_t index = iocb->ki_pos >> PAGE_SHIFT; + pgoff_t index = round_down(iocb->ki_pos >> PAGE_SHIFT, min_nrpages); pgoff_t last_index; struct folio *folio; int err = 0; /* "last_index" is the index of the page beyond the end of the read */ last_index = DIV_ROUND_UP(iocb->ki_pos + count, PAGE_SIZE); + last_index = round_up(last_index, min_nrpages); retry: if (fatal_signal_pending(current)) return -EINTR; @@ -2502,8 +2504,7 @@ static int filemap_get_pages(struct kiocb *iocb, size_t count, if (!folio_batch_count(fbatch)) { if (iocb->ki_flags & (IOCB_NOWAIT | IOCB_WAITQ)) return -EAGAIN; - err = filemap_create_folio(filp, mapping, - iocb->ki_pos >> PAGE_SHIFT, fbatch); + err = filemap_create_folio(filp, mapping, index, fbatch); if (err == AOP_TRUNCATED_PAGE) goto retry; return err; @@ -3095,7 +3096,10 @@ static struct file *do_sync_mmap_readahead(struct vm_fault *vmf) struct file *file = vmf->vma->vm_file; struct file_ra_state *ra = &file->f_ra; struct address_space *mapping = file->f_mapping; - DEFINE_READAHEAD(ractl, file, ra, mapping, vmf->pgoff); + unsigned int min_order = mapping_min_folio_order(mapping); + unsigned int min_nrpages = mapping_min_folio_nrpages(file->f_mapping); + pgoff_t index = round_down(vmf->pgoff, min_nrpages); + DEFINE_READAHEAD(ractl, file, ra, mapping, index); struct file *fpin = NULL; unsigned long vm_flags = vmf->vma->vm_flags; unsigned int mmap_miss; @@ -3147,10 +3151,11 @@ static struct file *do_sync_mmap_readahead(struct vm_fault *vmf) */ fpin = maybe_unlock_mmap_for_io(vmf, fpin); ra->start = max_t(long, 0, vmf->pgoff - ra->ra_pages / 2); + ra->start = round_down(ra->start, min_nrpages); ra->size = ra->ra_pages; ra->async_size = ra->ra_pages / 4; ractl._index = ra->start; - page_cache_ra_order(&ractl, ra, 0); + page_cache_ra_order(&ractl, ra, min_order); return fpin; } @@ -3164,7 +3169,9 @@ static struct file *do_async_mmap_readahead(struct vm_fault *vmf, { struct file *file = vmf->vma->vm_file; struct file_ra_state *ra = &file->f_ra; - DEFINE_READAHEAD(ractl, file, ra, file->f_mapping, vmf->pgoff); + unsigned int min_nrpages = mapping_min_folio_nrpages(file->f_mapping); + pgoff_t index = round_down(vmf->pgoff, min_nrpages); + DEFINE_READAHEAD(ractl, file, ra, file->f_mapping, index); struct file *fpin = NULL; unsigned int mmap_miss; @@ -3212,13 +3219,17 @@ vm_fault_t filemap_fault(struct vm_fault *vmf) struct file *file = vmf->vma->vm_file; struct file *fpin = NULL; struct address_space *mapping = file->f_mapping; + unsigned int min_order = mapping_min_folio_order(mapping); + unsigned int nrpages = 1UL << min_order; struct inode *inode = mapping->host; - pgoff_t max_idx, index = vmf->pgoff; + pgoff_t max_idx, index = round_down(vmf->pgoff, nrpages); struct folio *folio; vm_fault_t ret = 0; bool mapping_locked = false; max_idx = DIV_ROUND_UP(i_size_read(inode), PAGE_SIZE); + max_idx = round_up(max_idx, nrpages); + if (unlikely(index >= max_idx)) return VM_FAULT_SIGBUS; @@ -3317,13 +3328,17 @@ vm_fault_t filemap_fault(struct vm_fault *vmf) * We must recheck i_size under page lock. */ max_idx = DIV_ROUND_UP(i_size_read(inode), PAGE_SIZE); + max_idx = round_up(max_idx, nrpages); + if (unlikely(index >= max_idx)) { folio_unlock(folio); folio_put(folio); return VM_FAULT_SIGBUS; } - vmf->page = folio_file_page(folio, index); + VM_BUG_ON_FOLIO(folio_order(folio) < min_order, folio); + + vmf->page = folio_file_page(folio, vmf->pgoff); return ret | VM_FAULT_LOCKED; page_not_uptodate: @@ -3658,6 +3673,9 @@ static struct folio *do_read_cache_folio(struct address_space *mapping, { struct folio *folio; int err; + unsigned int min_nrpages = mapping_min_folio_nrpages(mapping); + + index = round_down(index, min_nrpages); if (!filler) filler = mapping->a_ops->read_folio; From patchwork Tue Feb 13 09:37:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Pankaj Raghav (Samsung)" X-Patchwork-Id: 13554784 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 3EEDAC48260 for ; Tue, 13 Feb 2024 09:37:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C023C6B0081; Tue, 13 Feb 2024 04:37:35 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BB3876B0082; Tue, 13 Feb 2024 04:37:35 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A2EF86B0085; Tue, 13 Feb 2024 04:37:35 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 8DB536B0081 for ; Tue, 13 Feb 2024 04:37:35 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 1FB7E1202B3 for ; Tue, 13 Feb 2024 09:37:35 +0000 (UTC) X-FDA: 81786278070.30.5C3FC95 Received: from mout-p-101.mailbox.org (mout-p-101.mailbox.org [80.241.56.151]) by imf03.hostedemail.com (Postfix) with ESMTP id 6032F20003 for ; Tue, 13 Feb 2024 09:37:33 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=MssUC8Ev; spf=pass (imf03.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.151 as permitted sender) smtp.mailfrom=me@pankajraghav.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707817053; a=rsa-sha256; cv=none; b=PfErESljeV3SHR4Fzb48ZBE0v2vwFv8rawv5DocZgM3Rv0fFT62dr06zoH6OHITh3MMQDB 6kn28alD5IxcfBN65H9s3n9/fF/CZaV/7MFKBgQlQEapAYk8E9b3V/cReXhURJ2QcskKsA p/wCbrXpLi/GJQEs03nJwwgbnlo2vWE= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=MssUC8Ev; spf=pass (imf03.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.151 as permitted sender) smtp.mailfrom=me@pankajraghav.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707817053; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=w9ziATPUggPlhgislum4xTFLvTMOz0MhHtv1RpfgBms=; b=8CzoIpp42h+RIceH3uJk9x49fhpN7aaS3xOouZ1Jrt1yfvhaKHhKVmt+dMsCSsOjKhd+Fw 0PXlU2Q5t3eakuF6+C8egbjid3l1U9Hymq3stbHOjwp8Dg/98LURWoqragvpeqoOzDLP3Y p9E0bFUjDNatAd4SnOo+9SzmTrNlUH4= Received: from smtp1.mailbox.org (smtp1.mailbox.org [10.196.197.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-101.mailbox.org (Postfix) with ESMTPS id 4TYx7Z18lWz9swL; Tue, 13 Feb 2024 10:37:30 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1707817050; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=w9ziATPUggPlhgislum4xTFLvTMOz0MhHtv1RpfgBms=; b=MssUC8EvZXGuZKgwffeP8hZBO3/nI8BUTOn+lQ37ROHXeTh/hED181KRtCHW6PELMLF0UE DEYwufaeT4jV1tuqEVGeSMTaAwMDle5ktiI2EYlKQPjJTQp/vX6/rgh4t8muYPfvrXpcjV hl09EmSpiojQVTrmt2iVgR6ncEJxJK4SW2dbrCqna7p8ayxhpiMmQpfs1UXv1lF/PX5iP4 m8xTmQzMzVSGJz1P+oVrwsTiU4/m/f9+f8Im/vqTieSDlf28XAOIkW0Qd8LCWRGkPeNIvu z48iIrv01XiHn1kxa2oJFgIu9wdVvN1Un6+RzVnIo1BkcnvB0SUBi8zi64m4MA== From: "Pankaj Raghav (Samsung)" To: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: mcgrof@kernel.org, gost.dev@samsung.com, akpm@linux-foundation.org, kbusch@kernel.org, djwong@kernel.org, chandan.babu@oracle.com, p.raghav@samsung.com, linux-kernel@vger.kernel.org, hare@suse.de, willy@infradead.org, linux-mm@kvack.org, david@fromorbit.com Subject: [RFC v2 03/14] filemap: use mapping_min_order while allocating folios Date: Tue, 13 Feb 2024 10:37:02 +0100 Message-ID: <20240213093713.1753368-4-kernel@pankajraghav.com> In-Reply-To: <20240213093713.1753368-1-kernel@pankajraghav.com> References: <20240213093713.1753368-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 6032F20003 X-Stat-Signature: 7iorarodmkzo1mb11ixz8ejnc9aysc71 X-Rspam-User: X-HE-Tag: 1707817053-91802 X-HE-Meta: U2FsdGVkX1/rjWOjuVChVlHI+3vwRBgnbB2FGFv61TVmXoyqx6Wi42IUp33XzeE5Uq2aEGq8nj8NqCrOCW6fFZpb/fxuYF14ccO9Wt5sKQlzKF7py0ohLdTGXVe6xy2ep1BhMzNaCHvhbBGl7lxIF5M7SOH586t7VBFSBXVGAQ1LJMGBciI8Qy4pO5Rqqv0MgSgJr2NT1QxY8TOIHeRRh74ZmxA7eqDdtvMLgUiXmyb6kZ1nCJ7GqUHfeX7AIKxMDNnDcq2vjIZA4GOlfsLlINgp+fgpmTv1BrWgNXbCSwmwE5AsW49b7FgNgmkB4DveasQ7NoXirFkLhBn3MNVBT64tMlf6luu1SMLVZdFqy3+8qf5ZKa8YF4VKHHxlflU9tvJw3FkFSy9WfnhdY68pRUI8EjOsf/AIUlQUmsJBgcbg39XqbGOsyCo66u3/uK/dYxrM8Gv0id2u6rixs47aPb6u7ohjuHpzp4fR12RrBQTj1s89DoG+0jAkRPZfxtcX+cgbJdjOqLLP0iqQA3HBhQVczRxwhecbuda6oNQ9cIgyQT1M0tsk+yT8KkljwtqUx8n5P+kF7aFd4Xp3uaimc5mopAS6nClSWuwzfq+fdLaqvmcNVctgKItU5o4XiQwNBUUmCWCjjtitJMhlp9n9Xo1OpF2Zf19XGytJ3xeqxom8KhIDGxHEpRj5cf82eIY6xoLgayF7cH3v1HAv5ZnWpR6mY4o093F1MjhnEfc1C84BsIiVt6N1+sVDmPCTBqAOHu1N2aSkwCqSF1GsXl5pYbxcJfkHvgrEjJuYyN4QM6yicwpdorSvyK8JGMUZC53yjwtqd7UZRQdea+U7CWmCtx2ZFRKk6mchHvLRAdfNiXFHjU1YbtwExlr6rcpcRfF7/kd79CantMgC3GSL7NG1qSkWSvW/HDlxSi2Ym9hVJ+Q85EoaxsNOHb7FVz+fU7CSsHXxNzyY6RGUOldDKa9 mQ/rFY1B qWlJdmDXiyT5Nzbx4+uGr+54/MTQsOqwO1Nq5MpT7LHV0y6tcd2alfJDUtaNV9XGiJcgxb1rOnFl42UpAsP98+NbcyA8/7wpR5rBSWYEbO3uM9rN0H1+9NzepiNKO1eZyfyiz7E3hHVDJSw0voBLYHPEW3/g3uXKaZ7+pHnzGiyT7UUEj23sVzsSc6LomdCnoBd34r6pQetsQ6WFnbTLt56m6OD6xw4g5dvTA/NrOjNBxCe00uYpFUaSOd7TvceFzZc47jpbs11gVRPnRcb5B2D0YThwIWTS5IcWkYmnvFSS4rwjrrAq3fj+tRgOBnZh5efKyCmv3gqv564naygD40FbDAiPygWHRxZOUcUvINLrbGtYHggzVKKYdcp/mZ62gUWukyN4CN2Y6E650F7ON7SdBjalYi+yVjbCf 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: From: Pankaj Raghav filemap_create_folio() and do_read_cache_folio() were always allocating folio of order 0. __filemap_get_folio was trying to allocate higher order folios when fgp_flags had higher order hint set but it will default to order 0 folio if higher order memory allocation fails. As we bring the notion of mapping_min_order, make sure these functions allocate at least folio of mapping_min_order as we need to guarantee it in the page cache. Add some additional VM_BUG_ON() in page_cache_delete[batch] and __filemap_add_folio to catch errors where we delete or add folios that has order less than min_order. Signed-off-by: Pankaj Raghav Signed-off-by: Luis Chamberlain Reviewed-by: Hannes Reinecke Acked-by: Darrick J. Wong --- mm/filemap.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/mm/filemap.c b/mm/filemap.c index 323a8e169581..7a6e15c47150 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -127,6 +127,7 @@ static void page_cache_delete(struct address_space *mapping, struct folio *folio, void *shadow) { + unsigned int min_order = mapping_min_folio_order(mapping); XA_STATE(xas, &mapping->i_pages, folio->index); long nr = 1; @@ -135,6 +136,7 @@ static void page_cache_delete(struct address_space *mapping, xas_set_order(&xas, folio->index, folio_order(folio)); nr = folio_nr_pages(folio); + VM_BUG_ON_FOLIO(folio_order(folio) < min_order, folio); VM_BUG_ON_FOLIO(!folio_test_locked(folio), folio); xas_store(&xas, shadow); @@ -277,6 +279,7 @@ void filemap_remove_folio(struct folio *folio) static void page_cache_delete_batch(struct address_space *mapping, struct folio_batch *fbatch) { + unsigned int min_order = mapping_min_folio_order(mapping); XA_STATE(xas, &mapping->i_pages, fbatch->folios[0]->index); long total_pages = 0; int i = 0; @@ -305,6 +308,7 @@ static void page_cache_delete_batch(struct address_space *mapping, WARN_ON_ONCE(!folio_test_locked(folio)); + VM_BUG_ON_FOLIO(folio_order(folio) < min_order, folio); folio->mapping = NULL; /* Leave folio->index set: truncation lookup relies on it */ @@ -846,6 +850,7 @@ noinline int __filemap_add_folio(struct address_space *mapping, int huge = folio_test_hugetlb(folio); bool charged = false; long nr = 1; + unsigned int min_order = mapping_min_folio_order(mapping); VM_BUG_ON_FOLIO(!folio_test_locked(folio), folio); VM_BUG_ON_FOLIO(folio_test_swapbacked(folio), folio); @@ -896,6 +901,7 @@ noinline int __filemap_add_folio(struct address_space *mapping, } } + VM_BUG_ON_FOLIO(folio_order(folio) < min_order, folio); xas_store(&xas, folio); if (xas_error(&xas)) goto unlock; @@ -1847,6 +1853,10 @@ struct folio *__filemap_get_folio(struct address_space *mapping, pgoff_t index, fgf_t fgp_flags, gfp_t gfp) { struct folio *folio; + unsigned int min_order = mapping_min_folio_order(mapping); + unsigned int min_nrpages = mapping_min_folio_nrpages(mapping); + + index = round_down(index, min_nrpages); repeat: folio = filemap_get_entry(mapping, index); @@ -1886,7 +1896,7 @@ struct folio *__filemap_get_folio(struct address_space *mapping, pgoff_t index, folio_wait_stable(folio); no_page: if (!folio && (fgp_flags & FGP_CREAT)) { - unsigned order = FGF_GET_ORDER(fgp_flags); + unsigned int order = max(min_order, FGF_GET_ORDER(fgp_flags)); int err; if ((fgp_flags & FGP_WRITE) && mapping_can_writeback(mapping)) @@ -1914,8 +1924,13 @@ struct folio *__filemap_get_folio(struct address_space *mapping, pgoff_t index, err = -ENOMEM; if (order == 1) order = 0; + if (order < min_order) + order = min_order; if (order > 0) alloc_gfp |= __GFP_NORETRY | __GFP_NOWARN; + + VM_BUG_ON(index & ((1UL << order) - 1)); + folio = filemap_alloc_folio(alloc_gfp, order); if (!folio) continue; @@ -1929,7 +1944,7 @@ struct folio *__filemap_get_folio(struct address_space *mapping, pgoff_t index, break; folio_put(folio); folio = NULL; - } while (order-- > 0); + } while (order-- > min_order); if (err == -EEXIST) goto repeat; @@ -2424,7 +2439,8 @@ static int filemap_create_folio(struct file *file, struct folio *folio; int error; - folio = filemap_alloc_folio(mapping_gfp_mask(mapping), 0); + folio = filemap_alloc_folio(mapping_gfp_mask(mapping), + mapping_min_folio_order(mapping)); if (!folio) return -ENOMEM; @@ -3682,7 +3698,8 @@ static struct folio *do_read_cache_folio(struct address_space *mapping, repeat: folio = filemap_get_folio(mapping, index); if (IS_ERR(folio)) { - folio = filemap_alloc_folio(gfp, 0); + folio = filemap_alloc_folio(gfp, + mapping_min_folio_order(mapping)); if (!folio) return ERR_PTR(-ENOMEM); err = filemap_add_folio(mapping, folio, index, gfp); From patchwork Tue Feb 13 09:37:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Pankaj Raghav (Samsung)" X-Patchwork-Id: 13554785 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 77B1BC48260 for ; Tue, 13 Feb 2024 09:37:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 092288D0002; Tue, 13 Feb 2024 04:37:39 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 027C88D0001; Tue, 13 Feb 2024 04:37:38 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D62688D0002; Tue, 13 Feb 2024 04:37:38 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id C0A738D0001 for ; Tue, 13 Feb 2024 04:37:38 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 854B3120AB6 for ; Tue, 13 Feb 2024 09:37:38 +0000 (UTC) X-FDA: 81786278196.06.652E10D Received: from mout-p-201.mailbox.org (mout-p-201.mailbox.org [80.241.56.171]) by imf06.hostedemail.com (Postfix) with ESMTP id DBAEA180019 for ; Tue, 13 Feb 2024 09:37:36 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=uCtQvXEu; spf=pass (imf06.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.171 as permitted sender) smtp.mailfrom=me@pankajraghav.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707817057; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=nJez9lFGKNHHqjTBT9OvccGI+MEPxelY3zNT/AM7wII=; b=eE6s9+bMwq0WyqA1k44HH+R8HajP9vS1QwKmAghqL1T9jjm/Atjaqx4OBi5GEI5EWl3RND QzchgpNEl62KsGdvIeZEZvOfaFcx93tdGdUDglay8AWzAcMtTcRGwnlO8ZOCMaCtHzAAO7 Y0YquKFyuU6iwT1ybEHT9wQ1haJfiGA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707817057; a=rsa-sha256; cv=none; b=BpvPrNuGNqb3JxKAewkyMqWHIXeyqFnlWtCcIfj/Vb6THEpRjd3Ii3/CnPm6gMjBMDXdX+ YAYec6je2JNvC/7oPk6aYHkvGNe+K2+uFEJoSxBejEVzzIilToVRd9jjAZ7TqIa4yjM3hp 1H0EGqOod6ONilbB6+F81aXYcPoZLpM= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=uCtQvXEu; spf=pass (imf06.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.171 as permitted sender) smtp.mailfrom=me@pankajraghav.com; dmarc=none Received: from smtp1.mailbox.org (smtp1.mailbox.org [10.196.197.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-201.mailbox.org (Postfix) with ESMTPS id 4TYx7d50r9z9sTM; Tue, 13 Feb 2024 10:37:33 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1707817053; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nJez9lFGKNHHqjTBT9OvccGI+MEPxelY3zNT/AM7wII=; b=uCtQvXEu+6KQlQCiuGw+WSyYea5LbyMcA82MG5gzxpXLndb1cSZu4/VRzPnge4R8I+K8Vv NZYcRK9/bHhRkukWeUhawuEyT7UQoBTZC6FyPTvux6qdgEkJRSaHWjRtW4ro1AkXkTAVYT b55DDYovZ7PBIf5u/a+N56W/LqXlxCoA8gdeOXImwC/a+P5TrtScQQAr9bWyzAu0aHAE4R +oYYuJSkshcJIBYSWUaP265Asnsqute1j4NgcbXErxl+PUNN63BcuLk2DfZLLQiC8PRKf/ C0JlKO3C/DVbujCqHYe28d3whLpp37YQNKOSWJP8AVdWPnpx2/mbjEOXTMKMFQ== From: "Pankaj Raghav (Samsung)" To: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: mcgrof@kernel.org, gost.dev@samsung.com, akpm@linux-foundation.org, kbusch@kernel.org, djwong@kernel.org, chandan.babu@oracle.com, p.raghav@samsung.com, linux-kernel@vger.kernel.org, hare@suse.de, willy@infradead.org, linux-mm@kvack.org, david@fromorbit.com Subject: [RFC v2 04/14] readahead: set file_ra_state->ra_pages to be at least mapping_min_order Date: Tue, 13 Feb 2024 10:37:03 +0100 Message-ID: <20240213093713.1753368-5-kernel@pankajraghav.com> In-Reply-To: <20240213093713.1753368-1-kernel@pankajraghav.com> References: <20240213093713.1753368-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Stat-Signature: b11yzcnwcptrsg5aqxkbojpzqak3g7bb X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: DBAEA180019 X-Rspam-User: X-HE-Tag: 1707817056-354733 X-HE-Meta: U2FsdGVkX19TdAsLWuzh14I0o1cYvK1zOCQJrOVnuQ+7b4RaKkAgJvONd9UhccKhjivWNLszjcxtNzEbklMRSd86naxYCQo1UoHmyBXCHbOWVDubsqZYGqwlxBoBRdZKp5XHYFUy6zvxVU8+jvmCatvlLCCWE395MZzMpuaMjmUjsvblagVBujX8xLAcXSIGhKyt99RlqEI1TAT+WhBhk4n3Z1z5xJNN3fgC9RN6HoBGJiaz5cQh7fmJZEj17yY2v/X+PQHJNzI9mOky9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15q6o+jBBn4ECgxqkhHNZvYiQzrFXlGo= 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: From: Luis Chamberlain Set the file_ra_state->ra_pages in file_ra_state_init() to be at least mapping_min_order of pages if the bdi->ra_pages is less than that. Signed-off-by: Luis Chamberlain Reviewed-by: Hannes Reinecke Acked-by: Darrick J. Wong --- mm/readahead.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/mm/readahead.c b/mm/readahead.c index 2648ec4f0494..4fa7d0e65706 100644 --- a/mm/readahead.c +++ b/mm/readahead.c @@ -138,7 +138,12 @@ void file_ra_state_init(struct file_ra_state *ra, struct address_space *mapping) { + unsigned int min_nrpages = mapping_min_folio_nrpages(mapping); + unsigned int max_pages = inode_to_bdi(mapping->host)->io_pages; + ra->ra_pages = inode_to_bdi(mapping->host)->ra_pages; + if (ra->ra_pages < min_nrpages && min_nrpages < max_pages) + ra->ra_pages = min_nrpages; ra->prev_pos = -1; } EXPORT_SYMBOL_GPL(file_ra_state_init); From patchwork Tue Feb 13 09:37:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Pankaj Raghav (Samsung)" X-Patchwork-Id: 13554786 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 BFDBEC48260 for ; Tue, 13 Feb 2024 09:37:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 488518D0003; Tue, 13 Feb 2024 04:37:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4395C8D0001; Tue, 13 Feb 2024 04:37:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2B33C8D0003; Tue, 13 Feb 2024 04:37:42 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 16EDB8D0001 for ; Tue, 13 Feb 2024 04:37:42 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id DA09C1A052D for ; Tue, 13 Feb 2024 09:37:41 +0000 (UTC) X-FDA: 81786278322.15.174D5E7 Received: from mout-p-102.mailbox.org (mout-p-102.mailbox.org [80.241.56.152]) by imf26.hostedemail.com (Postfix) with ESMTP id 3817D140003 for ; Tue, 13 Feb 2024 09:37:39 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=q+QdcRp9; dmarc=none; spf=pass (imf26.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.152 as permitted sender) smtp.mailfrom=me@pankajraghav.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707817060; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=G2fO/D/MPNOVLZ/qHSRb69SYJGOgunRGzbPIdUcBFeY=; b=Lxd8l7dro5gciKyBhDDTOSXAfBVhNfJRh4LO7IBm+vSo7DtW9TQ5LCjCoP+CWrIKS4f/EB StiwNfQwl5lmpK2djElvNR1iADMEaQW/GZTcVAtavs3/yadew2YRBl9Rz/+JtOe8uh6utm BdElM9E5ZuQMW/NezYnqx3LIgeIZ57k= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=q+QdcRp9; dmarc=none; spf=pass (imf26.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.152 as permitted sender) smtp.mailfrom=me@pankajraghav.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707817060; a=rsa-sha256; cv=none; b=f/2KtrpYjtMoUVv/conZmta/+KhoiaD+uTFESKOCViXkhlFADyJQE8S4CwlcKSvn1DpEbx IYdJfJDPxA9/xEx7obqpe4eWZHkTWdwvlOKHIDopEL2CV6ehAYyWuRb4k5cwX8xtRRdPbh 5G/8PjBykdfRqAlGsg7FETXgNMy/u9g= Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:b231:465::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-102.mailbox.org (Postfix) with ESMTPS id 4TYx7h610nz9sp2; Tue, 13 Feb 2024 10:37:36 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1707817056; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=G2fO/D/MPNOVLZ/qHSRb69SYJGOgunRGzbPIdUcBFeY=; b=q+QdcRp9VMFfzBuHWmwG0y4c6GTja5nXRvH9aAJ/+ewY7aP/tIt9Dp0+UfOMBoqce1hD6r 4Jr9W7xXq0c5XSbK3Y2hbZrDNo/2DpL4R/2wGRvMP0RY1PSm+kdlNNZopEmK/dOkqMb5CQ QTAmRx5ZdiGchLWnc+Dw0wyZ6d5eD6QTsN5x23PoMUnXNKkk0pbacHYf/5S1hQFRYemGuR 9i+kZrTl/z6yLaQCs78brNS7z1wN+GvZgsWUiCXs3qO0ElouvrUdzXa0IKodiwYR5QLZ59 gBxcaEjI6JuH8GEXz/8F7YnQUXYe9S3rD1b7DEMAcw07PdMjtyAMdrCImC2L8g== From: "Pankaj Raghav (Samsung)" To: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: mcgrof@kernel.org, gost.dev@samsung.com, akpm@linux-foundation.org, kbusch@kernel.org, djwong@kernel.org, chandan.babu@oracle.com, p.raghav@samsung.com, linux-kernel@vger.kernel.org, hare@suse.de, willy@infradead.org, linux-mm@kvack.org, david@fromorbit.com Subject: [RFC v2 05/14] readahead: align index to mapping_min_order in ondemand_ra and force_ra Date: Tue, 13 Feb 2024 10:37:04 +0100 Message-ID: <20240213093713.1753368-6-kernel@pankajraghav.com> In-Reply-To: <20240213093713.1753368-1-kernel@pankajraghav.com> References: <20240213093713.1753368-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 3817D140003 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: itkw9hphf6iieae6dibbfrb6sediarit X-HE-Tag: 1707817059-591079 X-HE-Meta: U2FsdGVkX1+3OO3I7RNNJtOxCSIMvAfbCIana4QdZWHDs140r6dZ7Ut41hbgDc76hjkcSsA5UFfq+P+EKCY23nEfDeFFd9ZdOY7Atm/0ZFvAlupFd0gJb1REbwwsx3cYdbsNqu3hb/ymDUh/FvAVNbyddqVRmJGOtXzgG0uMhv1BUUdJWb/B5HN+cCXnU6Xv67TDPQk4h1GhjTg53uMPT9/tYfPcBTPquLUZJUVCyRSh4dTlOiiekjOLij18RTjcMxcyr2AETLZiPrUFHcR2/sUwKoDCmZPzseJYSWNr94j4mfY2wZaxxz7Mgq7Tl2SYSREQ5AOlNscEDCUNZTHBRLl/sKFLYqYXw+qK672TwEGrRnlCzv+g7aPafl16FMBGas+f63ufGQlO18bY7UYRRg+5g7PuYuu23L5Rfa84TgNoeNJRKD9Sx0lBk+3QzOUcln8BhXUl7pIvwFO0aRaGWOKKiFCidUi7a3s9HcFSsJpmYlBk9hQYnfuGV2CNm9nopOszltsa306OfpUim+ZojyoNy8VEptnxZ/aVUrBP4zjsGZxUSfWF/ifxs2Az5YUvdLo6VT0kForQUNtsmiz+XTJbi329qvE/rnmBHeo8B/1lmR5Wvn2yc2n3CH3fmxF3fZ/mXpTE9FvrDuWmfNXPKhBaxkf9Lr/Y0vlS/7mJAWoz+pBYsu39jrk5oepZcFfLd9J5fhptIyy8/F1XPElq9zyQ7L3KBe9oyKnL+7heg8bUH277ccQ2quGnQpQLf5sVl9EmZF5kOubj4jLqzH4VR854zzTazMZzECLlJifteWq8eGpaOrJcq8bcO5mLSSOkr2KRYYcpEuw75wZ7Ley5oaIof+5Tnsr/WN3eALkV/PXxdi+0zARdj1np53BYrlqRSFOSNuRHoxW/RNJQuPcX08yOAYN0NVC8o4U29zgpjn3H5NZCugoh0mpyfH+6r0EjLRPYYYsy1v6fw3d98CQ iXl4KRtE uTzwYVUlFmhLYyH+dc39QKUQt2n6IMhT8CS2RVe4/cVu+obwLA+z/Za2BNzVldojtESh7S7TxxYDq1hTn/wDdSFzCF/Bu64U7Si/RUorXWZ9Kito= 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: From: Luis Chamberlain Align the ra->start and ra->size to mapping_min_order in ondemand_readahead(), and align the index to mapping_min_order in force_page_cache_ra(). This will ensure that the folios allocated for readahead that are added to the page cache are aligned to mapping_min_order. Signed-off-by: Luis Chamberlain Signed-off-by: Pankaj Raghav Acked-by: Darrick J. Wong --- mm/readahead.c | 48 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 40 insertions(+), 8 deletions(-) diff --git a/mm/readahead.c b/mm/readahead.c index 4fa7d0e65706..5e1ec7705c78 100644 --- a/mm/readahead.c +++ b/mm/readahead.c @@ -315,6 +315,7 @@ void force_page_cache_ra(struct readahead_control *ractl, struct file_ra_state *ra = ractl->ra; struct backing_dev_info *bdi = inode_to_bdi(mapping->host); unsigned long max_pages, index; + unsigned int min_nrpages = mapping_min_folio_nrpages(mapping); if (unlikely(!mapping->a_ops->read_folio && !mapping->a_ops->readahead)) return; @@ -324,6 +325,13 @@ void force_page_cache_ra(struct readahead_control *ractl, * be up to the optimal hardware IO size */ index = readahead_index(ractl); + if (!IS_ALIGNED(index, min_nrpages)) { + unsigned long old_index = index; + + index = round_down(index, min_nrpages); + nr_to_read += (old_index - index); + } + max_pages = max_t(unsigned long, bdi->io_pages, ra->ra_pages); nr_to_read = min_t(unsigned long, nr_to_read, max_pages); while (nr_to_read) { @@ -332,6 +340,7 @@ void force_page_cache_ra(struct readahead_control *ractl, if (this_chunk > nr_to_read) this_chunk = nr_to_read; ractl->_index = index; + VM_BUG_ON(!IS_ALIGNED(index, min_nrpages)); do_page_cache_ra(ractl, this_chunk, 0); index += this_chunk; @@ -344,11 +353,20 @@ void force_page_cache_ra(struct readahead_control *ractl, * for small size, x 4 for medium, and x 2 for large * for 128k (32 page) max ra * 1-2 page = 16k, 3-4 page 32k, 5-8 page = 64k, > 8 page = 128k initial + * + * For higher order address space requirements we ensure no initial reads + * are ever less than the min number of pages required. + * + * We *always* cap the max io size allowed by the device. */ -static unsigned long get_init_ra_size(unsigned long size, unsigned long max) +static unsigned long get_init_ra_size(unsigned long size, + unsigned int min_nrpages, + unsigned long max) { unsigned long newsize = roundup_pow_of_two(size); + newsize = max_t(unsigned long, newsize, min_nrpages); + if (newsize <= max / 32) newsize = newsize * 4; else if (newsize <= max / 4) @@ -356,6 +374,8 @@ static unsigned long get_init_ra_size(unsigned long size, unsigned long max) else newsize = max; + VM_BUG_ON(newsize & (min_nrpages - 1)); + return newsize; } @@ -364,14 +384,16 @@ static unsigned long get_init_ra_size(unsigned long size, unsigned long max) * return it as the new window size. */ static unsigned long get_next_ra_size(struct file_ra_state *ra, + unsigned int min_nrpages, unsigned long max) { - unsigned long cur = ra->size; + unsigned long cur = max(ra->size, min_nrpages); if (cur < max / 16) return 4 * cur; if (cur <= max / 2) return 2 * cur; + return max; } @@ -561,7 +583,11 @@ static void ondemand_readahead(struct readahead_control *ractl, unsigned long add_pages; pgoff_t index = readahead_index(ractl); pgoff_t expected, prev_index; - unsigned int order = folio ? folio_order(folio) : 0; + unsigned int min_order = mapping_min_folio_order(ractl->mapping); + unsigned int min_nrpages = mapping_min_folio_nrpages(ractl->mapping); + unsigned int order = folio ? folio_order(folio) : min_order; + + VM_BUG_ON(!IS_ALIGNED(ractl->_index, min_nrpages)); /* * If the request exceeds the readahead window, allow the read to @@ -583,8 +609,8 @@ static void ondemand_readahead(struct readahead_control *ractl, expected = round_down(ra->start + ra->size - ra->async_size, 1UL << order); if (index == expected || index == (ra->start + ra->size)) { - ra->start += ra->size; - ra->size = get_next_ra_size(ra, max_pages); + ra->start += round_down(ra->size, min_nrpages); + ra->size = get_next_ra_size(ra, min_nrpages, max_pages); ra->async_size = ra->size; goto readit; } @@ -603,13 +629,18 @@ static void ondemand_readahead(struct readahead_control *ractl, max_pages); rcu_read_unlock(); + start = round_down(start, min_nrpages); + + VM_BUG_ON(folio->index & (folio_nr_pages(folio) - 1)); + if (!start || start - index > max_pages) return; ra->start = start; ra->size = start - index; /* old async_size */ + ra->size += req_size; - ra->size = get_next_ra_size(ra, max_pages); + ra->size = get_next_ra_size(ra, min_nrpages, max_pages); ra->async_size = ra->size; goto readit; } @@ -646,7 +677,7 @@ static void ondemand_readahead(struct readahead_control *ractl, initial_readahead: ra->start = index; - ra->size = get_init_ra_size(req_size, max_pages); + ra->size = get_init_ra_size(req_size, min_nrpages, max_pages); ra->async_size = ra->size > req_size ? ra->size - req_size : ra->size; readit: @@ -657,7 +688,7 @@ static void ondemand_readahead(struct readahead_control *ractl, * Take care of maximum IO pages as above. */ if (index == ra->start && ra->size == ra->async_size) { - add_pages = get_next_ra_size(ra, max_pages); + add_pages = get_next_ra_size(ra, min_nrpages, max_pages); if (ra->size + add_pages <= max_pages) { ra->async_size = add_pages; ra->size += add_pages; @@ -668,6 +699,7 @@ static void ondemand_readahead(struct readahead_control *ractl, } ractl->_index = ra->start; + VM_BUG_ON(!IS_ALIGNED(ractl->_index, min_nrpages)); page_cache_ra_order(ractl, ra, order); } From patchwork Tue Feb 13 09:37:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Pankaj Raghav (Samsung)" X-Patchwork-Id: 13554787 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 7C2C0C48260 for ; Tue, 13 Feb 2024 09:37:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 108358D0005; Tue, 13 Feb 2024 04:37:45 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0BA9C8D0001; Tue, 13 Feb 2024 04:37:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E4D1A8D0005; Tue, 13 Feb 2024 04:37:44 -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 C91918D0001 for ; Tue, 13 Feb 2024 04:37:44 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 903AE4036A for ; Tue, 13 Feb 2024 09:37:44 +0000 (UTC) X-FDA: 81786278448.27.FBF3D0C Received: from mout-p-102.mailbox.org (mout-p-102.mailbox.org [80.241.56.152]) by imf07.hostedemail.com (Postfix) with ESMTP id EC75A40011 for ; Tue, 13 Feb 2024 09:37:42 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=x6CfVQAW; dmarc=none; spf=pass (imf07.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.152 as permitted sender) smtp.mailfrom=me@pankajraghav.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707817063; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=s3+v+1l0sQIYfL9D8O6cM5bMDlwybIjei48bqSTyWjw=; b=0aQoHKC33dKMKk/fsyNJ1Ke+bRSp8OL5B5zVQIuhYt3l7xXsDhMWzzWX8c/CljwLfjwN1E S/oQwxzNT8o/wZtV5f0HYseNjFXQE7uaXmLCOrDfEy8q8o/FLr5DtAjPCl7Pu0lOKT/y2G eErosg+DkVAQZQICtx46TuSCs8a8sos= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=x6CfVQAW; dmarc=none; spf=pass (imf07.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.152 as permitted sender) smtp.mailfrom=me@pankajraghav.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707817063; a=rsa-sha256; cv=none; b=ugDuRiWfQySVdkjbfdN0+1cnwDG436kY8GzBAaXleluC1/kDO8ewKYVJQpcOHNu7471o2r gFdYi1tMoRvOjHhPaV2uAHHef8tlDNx1pG4o2NFqvrjN61q/nnAqf1wnRUgiYspJKMPUUD g0LnFH0jUhxn7GfOuN82YzGFWS/gOF4= Received: from smtp202.mailbox.org (smtp202.mailbox.org [IPv6:2001:67c:2050:b231:465::202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-102.mailbox.org (Postfix) with ESMTPS id 4TYx7l4ntmz9t2m; Tue, 13 Feb 2024 10:37:39 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1707817059; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=s3+v+1l0sQIYfL9D8O6cM5bMDlwybIjei48bqSTyWjw=; b=x6CfVQAW4rNsG3L+k95kHbFRenuHprAKwdKZE4SqzOwOs2L6aGmZ1ZQVD8/dJoBhJywTa7 6y8PrO1+vcd3D+x0Iqy3adhK62udO+kGv47JGmZGPVG7qqwA+gbeU/NJnY92pbJuF1EY0l JUstg7eTNj265zR9KXR68yLq9hPsVt7JMoLc8i9Yuiv2JGdztsLselFJepClTBB/njp9tI RG6HjSx+PGhFCUnsXbC9mYVgrbZ+ICPlPMhuKs9iRc8QUGmTUZSCWlB/fNXayyoq4+anHk uone6GAIEb5xnuUWMx9ouMcbT5CHsJzw8G3PIZcC8sKASsD5Z5GQy5wGcDz+jQ== From: "Pankaj Raghav (Samsung)" To: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: mcgrof@kernel.org, gost.dev@samsung.com, akpm@linux-foundation.org, kbusch@kernel.org, djwong@kernel.org, chandan.babu@oracle.com, p.raghav@samsung.com, linux-kernel@vger.kernel.org, hare@suse.de, willy@infradead.org, linux-mm@kvack.org, david@fromorbit.com Subject: [RFC v2 06/14] readahead: rework loop in page_cache_ra_unbounded() Date: Tue, 13 Feb 2024 10:37:05 +0100 Message-ID: <20240213093713.1753368-7-kernel@pankajraghav.com> In-Reply-To: <20240213093713.1753368-1-kernel@pankajraghav.com> References: <20240213093713.1753368-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: EC75A40011 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: wsbp5fsqkt8k9pqsdunt5if1u11jdjsh X-HE-Tag: 1707817062-446886 X-HE-Meta: U2FsdGVkX19NVkrSM5+xdeZgxmqqBL5NT/2x9IsZ4Zy7S9aI9RlT43CHHqzgZaGzmTtvkJSRCQdFvoN4b8Lt7PD+Vk3IhZdMX8fIA6F28Gj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9O7RgT/DhXCPH0tWRyeFccsIiSrZHllVhQNXpU0hXUTrJO+HsBAFUXQsSdgYiQbVQ2wJDAdCET10jyQXnl1bW4G9B6DuszPUh6nyH53e6QD/2ezV2n344L1i+3LsSs5GA608elJMQQ/6VUmCsCNSTJ5WZPUjyUT504CkK4TWOQ4OFMR5SgrTgpjIVZAz+k 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: From: Hannes Reinecke Rework the loop in page_cache_ra_unbounded() to advance with the number of pages in a folio instead of just one page at a time. Signed-off-by: Hannes Reinecke Co-developed-by: Pankaj Raghav Signed-off-by: Pankaj Raghav Acked-by: Darrick J. Wong --- mm/readahead.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/mm/readahead.c b/mm/readahead.c index 5e1ec7705c78..13b62cbd3b79 100644 --- a/mm/readahead.c +++ b/mm/readahead.c @@ -213,7 +213,7 @@ void page_cache_ra_unbounded(struct readahead_control *ractl, struct address_space *mapping = ractl->mapping; unsigned long index = readahead_index(ractl); gfp_t gfp_mask = readahead_gfp_mask(mapping); - unsigned long i; + unsigned long i = 0; /* * Partway through the readahead operation, we will have added @@ -231,7 +231,7 @@ void page_cache_ra_unbounded(struct readahead_control *ractl, /* * Preallocate as many pages as we will need. */ - for (i = 0; i < nr_to_read; i++) { + while (i < nr_to_read) { struct folio *folio = xa_load(&mapping->i_pages, index + i); if (folio && !xa_is_value(folio)) { @@ -244,8 +244,8 @@ void page_cache_ra_unbounded(struct readahead_control *ractl, * not worth getting one just for that. */ read_pages(ractl); - ractl->_index++; - i = ractl->_index + ractl->_nr_pages - index - 1; + ractl->_index += folio_nr_pages(folio); + i = ractl->_index + ractl->_nr_pages - index; continue; } @@ -257,13 +257,14 @@ void page_cache_ra_unbounded(struct readahead_control *ractl, folio_put(folio); read_pages(ractl); ractl->_index++; - i = ractl->_index + ractl->_nr_pages - index - 1; + i = ractl->_index + ractl->_nr_pages - index; continue; } if (i == nr_to_read - lookahead_size) folio_set_readahead(folio); ractl->_workingset |= folio_test_workingset(folio); - ractl->_nr_pages++; + ractl->_nr_pages += folio_nr_pages(folio); + i += folio_nr_pages(folio); } /* From patchwork Tue Feb 13 09:37:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Pankaj Raghav (Samsung)" X-Patchwork-Id: 13554788 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 DD155C4829A for ; Tue, 13 Feb 2024 09:37:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 685648D0006; Tue, 13 Feb 2024 04:37:49 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 634888D0001; Tue, 13 Feb 2024 04:37:49 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4D6628D0006; Tue, 13 Feb 2024 04:37:49 -0500 (EST) 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 3A0578D0001 for ; Tue, 13 Feb 2024 04:37:49 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 157FD40284 for ; Tue, 13 Feb 2024 09:37:49 +0000 (UTC) X-FDA: 81786278658.30.DA754CD Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [80.241.56.172]) by imf17.hostedemail.com (Postfix) with ESMTP id 4E73240015 for ; Tue, 13 Feb 2024 09:37:47 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=iOQgIoOS; spf=pass (imf17.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.172 as permitted sender) smtp.mailfrom=me@pankajraghav.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707817067; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=+mCWMwP5wq3JUiJEv3CmIbOYWUCSLRs7oy3y/VAxBqA=; b=iA6T+t/DPYBWjikAsxGZjuyNfrW7PN0qeo30rCOekwVmRZk/O00NKkz/ncS6LZ+aAQummp NGdFealjLdElu/vvaGhv8u5t8c2Stib7XJITePF+FY2hH8BofU/Z9VSRylqNNRJJ4oC9CZ BMR1pCVmfRkeG0CxoaBMlnM43BmiVkg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707817067; a=rsa-sha256; cv=none; b=wG76VfyU7sAUZTy3t2TinZJWAtzNj07n3LuMkj3xulDy796UIVeyMJgn4fJu+0kX1pmoMz lotVzstfxYNh5TbVxInnKZ4BE5oKbYXIyAgkusxVJ+MvIG8w+CRtej7r8cYB0DRSTOE3vo YBN6An9b96QChYqC45QEhBFyOQl+xlY= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=iOQgIoOS; spf=pass (imf17.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.172 as permitted sender) smtp.mailfrom=me@pankajraghav.com; dmarc=none Received: from smtp102.mailbox.org (smtp102.mailbox.org [10.196.197.102]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-202.mailbox.org (Postfix) with ESMTPS id 4TYx7q6TR8z9sQ6; Tue, 13 Feb 2024 10:37:43 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1707817063; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+mCWMwP5wq3JUiJEv3CmIbOYWUCSLRs7oy3y/VAxBqA=; b=iOQgIoOS6MNE5AoCAkHWB9G4sH1HUqNrseAIr0UHMHOFKgN7X/i+sSLh14ZYjJ2VfVFoVD xEnCZpOimSmqDL3bsXvjRAwCjcpL4t0fpM7v0+a7NpzQ42OVb5XKUPN4Pe1yuaQzlQg510 9+GAiYGfjY4aRVJ8IhjdFc1qFraRZoin7df2vI6gb5P7s9bDaqDLapMAqTGaNHPabkP8jG 9EDznjuSuLHv8D6U3BuOBiHgpe9P5VKhmdvy9UShqKWr+81MrlafvnKcCyxnZS7ekoFiTv AsIwPvDH6bnGLovC6E5hxc34cSXEfFiEBW/VvDrEK/Um/6t5hMDmGu+a5nYQnw== From: "Pankaj Raghav (Samsung)" To: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: mcgrof@kernel.org, gost.dev@samsung.com, akpm@linux-foundation.org, kbusch@kernel.org, djwong@kernel.org, chandan.babu@oracle.com, p.raghav@samsung.com, linux-kernel@vger.kernel.org, hare@suse.de, willy@infradead.org, linux-mm@kvack.org, david@fromorbit.com Subject: [RFC v2 07/14] readahead: allocate folios with mapping_min_order in ra_(unbounded|order) Date: Tue, 13 Feb 2024 10:37:06 +0100 Message-ID: <20240213093713.1753368-8-kernel@pankajraghav.com> In-Reply-To: <20240213093713.1753368-1-kernel@pankajraghav.com> References: <20240213093713.1753368-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 4E73240015 X-Rspam-User: X-Stat-Signature: bt1wwsuzihyrauaecxeu9bw8zp93hqo9 X-Rspamd-Server: rspam03 X-HE-Tag: 1707817067-114063 X-H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S8a9YOCxDkS72vN678HSfqVpCn6FAycIIF2jBm95pPhevv9+nlHgB6Ii8MWrVg06vMQbCgOjUWPUWH6+xrAL9Q6OiJsrnc7/wOFXuhSc7YcmVetikg8dg5QYwlPR15r0AyX3bxijDQ9cpm80xs93ZRIIFLRWuobCRj0k8dYxdk5ZFc19sqJzbwHI1jsY3/vYQHprpOeXnnwjhEHH3Uc2F7JHlyhta5q+FJ1pbNVzlY9qjtpjvqv/faTca8nwFf/QHZq6iE8KY+M/117ZB60fpAP7WEDEDNuOJZnjYNrtfl18Fq7tJiiW8I035a5lI/E03NULBeAgbzMd2 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: From: Pankaj Raghav Allocate folios with at least mapping_min_order in page_cache_ra_unbounded() and page_cache_ra_order() as we need to guarantee a minimum order in the page cache. Signed-off-by: Pankaj Raghav Signed-off-by: Luis Chamberlain Reviewed-by: Hannes Reinecke Acked-by: Darrick J. Wong --- mm/readahead.c | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/mm/readahead.c b/mm/readahead.c index 13b62cbd3b79..a361fba18674 100644 --- a/mm/readahead.c +++ b/mm/readahead.c @@ -214,6 +214,7 @@ void page_cache_ra_unbounded(struct readahead_control *ractl, unsigned long index = readahead_index(ractl); gfp_t gfp_mask = readahead_gfp_mask(mapping); unsigned long i = 0; + unsigned int min_nrpages = mapping_min_folio_nrpages(mapping); /* * Partway through the readahead operation, we will have added @@ -235,6 +236,8 @@ void page_cache_ra_unbounded(struct readahead_control *ractl, struct folio *folio = xa_load(&mapping->i_pages, index + i); if (folio && !xa_is_value(folio)) { + long nr_pages = folio_nr_pages(folio); + /* * Page already present? Kick off the current batch * of contiguous pages before continuing with the @@ -244,19 +247,31 @@ void page_cache_ra_unbounded(struct readahead_control *ractl, * not worth getting one just for that. */ read_pages(ractl); - ractl->_index += folio_nr_pages(folio); + + /* + * Move the ractl->_index by at least min_pages + * if the folio got truncated to respect the + * alignment constraint in the page cache. + * + */ + if (mapping != folio->mapping) + nr_pages = min_nrpages; + + VM_BUG_ON_FOLIO(nr_pages < min_nrpages, folio); + ractl->_index += nr_pages; i = ractl->_index + ractl->_nr_pages - index; continue; } - folio = filemap_alloc_folio(gfp_mask, 0); + folio = filemap_alloc_folio(gfp_mask, + mapping_min_folio_order(mapping)); if (!folio) break; if (filemap_add_folio(mapping, folio, index + i, gfp_mask) < 0) { folio_put(folio); read_pages(ractl); - ractl->_index++; + ractl->_index += min_nrpages; i = ractl->_index + ractl->_nr_pages - index; continue; } @@ -516,6 +531,7 @@ void page_cache_ra_order(struct readahead_control *ractl, { struct address_space *mapping = ractl->mapping; pgoff_t index = readahead_index(ractl); + unsigned int min_order = mapping_min_folio_order(mapping); pgoff_t limit = (i_size_read(mapping->host) - 1) >> PAGE_SHIFT; pgoff_t mark = index + ra->size - ra->async_size; int err = 0; @@ -542,11 +558,17 @@ void page_cache_ra_order(struct readahead_control *ractl, if (index & ((1UL << order) - 1)) order = __ffs(index); /* Don't allocate pages past EOF */ - while (index + (1UL << order) - 1 > limit) + while (order > min_order && index + (1UL << order) - 1 > limit) order--; /* THP machinery does not support order-1 */ if (order == 1) order = 0; + + if (order < min_order) + order = min_order; + + VM_BUG_ON(index & ((1UL << order) - 1)); + err = ra_alloc_folio(ractl, index, mark, order, gfp); if (err) break; From patchwork Tue Feb 13 09:37:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Pankaj Raghav (Samsung)" X-Patchwork-Id: 13554789 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 10D7EC48260 for ; Tue, 13 Feb 2024 09:37:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 91DB28D0007; Tue, 13 Feb 2024 04:37:53 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8CDEC8D0001; Tue, 13 Feb 2024 04:37:53 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 76DB28D0007; Tue, 13 Feb 2024 04:37:53 -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 620508D0001 for ; Tue, 13 Feb 2024 04:37:53 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id F3520120AB6 for ; Tue, 13 Feb 2024 09:37:52 +0000 (UTC) X-FDA: 81786278784.02.CD28095 Received: from mout-p-102.mailbox.org (mout-p-102.mailbox.org [80.241.56.152]) by imf21.hostedemail.com (Postfix) with ESMTP id 521831C0018 for ; Tue, 13 Feb 2024 09:37:51 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=PYSoXXZF; dmarc=none; spf=pass (imf21.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.152 as permitted sender) smtp.mailfrom=me@pankajraghav.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707817071; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=vOt507Ijo5nyZ5wUX3vXhvqctlR5/JOvafIYIWSMCPU=; b=jFUnaOGGfiqjIwaWabLGlOUFEG089T7souFCZwISMuDIMvQ1ea8yCSPBpjXbwc1GCZ38uB NqelfAU4QBt9UvXx0TC6JR76k/qG5L9x9bjeANUTYeERYB8VSprynbvaWyfzYS8t4l+wEY fxLY1oNoo5fREwXSW8pZ4oeEvLVFVfc= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=PYSoXXZF; dmarc=none; spf=pass (imf21.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.152 as permitted sender) smtp.mailfrom=me@pankajraghav.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707817071; a=rsa-sha256; cv=none; b=B3CCYpMUAnG7/YnhS44AdBQ2Lqzd8dAz2Q8Uogs7gpCWvPGlkv9JykLdNVVfUdRLojC6dP AuVPGEGet3PQ2btLt2zN3eeP050pporWRsYN0Im44POQu5cmo9GJNOIOg1I4XJax8Rj2bq yQdCv4dOXRyz5XoI7KNpyh96MYSpjWA= Received: from smtp102.mailbox.org (smtp102.mailbox.org [IPv6:2001:67c:2050:b231:465::102]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-102.mailbox.org (Postfix) with ESMTPS id 4TYx7v6WyGz9sp2; Tue, 13 Feb 2024 10:37:47 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1707817067; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vOt507Ijo5nyZ5wUX3vXhvqctlR5/JOvafIYIWSMCPU=; b=PYSoXXZF27fQan8sPatQHAhpAqM4cF203+dvlg+l2btfVaBSRRZiJ1MzdG7gxXCdw/x1xv zyTcd5oYO6PhI3ZFTTCL+6yiaM+Y6yFqYDrBTpKbEIBodE2d741iRoZELCaE88A++S1DY4 rTb77WTAkP4yb3+9A/L0UsVRr/+EI8CsZdN/tVRk429O3hpuT4W5VPTqeszPTncLWrnDU0 7UA6a6QW14Jlo99OKaM/RQfdVcRG6UsIp0cSAOQ7vP8EVJfGVRCfZwh+Jcy59vj6v6E1ie USql3iBXYGMEmlth5qx6Id4J6beIAHNMU9q3QOpfjtUTd+FbUH7EXaWS074UEQ== From: "Pankaj Raghav (Samsung)" To: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: mcgrof@kernel.org, gost.dev@samsung.com, akpm@linux-foundation.org, kbusch@kernel.org, djwong@kernel.org, chandan.babu@oracle.com, p.raghav@samsung.com, linux-kernel@vger.kernel.org, hare@suse.de, willy@infradead.org, linux-mm@kvack.org, david@fromorbit.com Subject: [RFC v2 08/14] mm: do not split a folio if it has minimum folio order requirement Date: Tue, 13 Feb 2024 10:37:07 +0100 Message-ID: <20240213093713.1753368-9-kernel@pankajraghav.com> In-Reply-To: <20240213093713.1753368-1-kernel@pankajraghav.com> References: <20240213093713.1753368-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 521831C0018 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: rrzusydwd5zkdwnzneiknsbaf6in8em4 X-HE-Tag: 1707817071-89133 X-HE-Meta: U2FsdGVkX1+MQz+Mq1A2zk9OdkmP23XikHyzKx9j2Xf9kANqCdOpl3vg6fwoJmt4QlqdWtP48Z3RewibqfodIEw4KnALYaKzIUB6mVi9u3Euc79oraqLaVrWE3XzWlaV4AZINF8qfD6KDFHBPaWgUhY7l/oUl4gz53SKW8+Suf1TWZ//WJ014EdKWmL3Ffqg57WhaQY4G3xonXGDQRlKl3BV+Esd7ujbcaV0araGLPqntOcP4sxW6ySgVElQOzW+eRaq1F2DJuh/qBzweVIFaYMJzaMlPn63fkOX9r9n7HtfmmuZh99HIm2qAtxL1li2fZTYZ69z2DJd2OB1iGtSmfPd+HATYvKb/i3MvzyucaKsl2AJVwtyb1cukQXJ+AK3zMztBSCU0nDJKSdQB76fMxm5ufvqlYFcPPXbQPNwt+xMQ7lRyseUf1uFXiC2qO0D3NG9KEFSRuv8iRG8DG4VTtNt6h4wjW+WoWein++XZOXKMWshHjBr9M8j2UAJsFv4SZB5oZhMdxVLtRZzsYfMb49eS2vPJuFS5Zh+7llqs4hpFKDYF9/grXtZBfd4GOMdJOsPdHmIPfGEbyV8Rt5W8zky7Sw18kZT7vt2wwTiOJNx5DwkMOW6HYUL1lH7mGwkLcC6wzvEtizuetzwAvgfIiFEPz2eJ3Rg6r/qUEaHhK/SzvYz2x01RCbCImMB0tr6IhjTGoo0cX9mxsX+1F3oAYdmHqdA02N6VyXMgl58o/3XNSqqgfn9BBorTeId8+yvbiAc4zYwjcuNG/o44M/CZtIV/UIb2/K0n6aZ0nVQV5ejqYxnXQYLPlP+94PYZvnkcv5s09da7Q6v1B1cNm5oZx4dmCLTG1V1B9KDYznoMUU3U3Xfktt7q/55GGXoACF6oqhKIhV+Wckzoda2l7AfdIwCMCYMGNtXRoh90nWCR0Q3toQ+96qOqpeoh6xXcU4t4rLSukbQhF3zXe/V7u8 kFBo+UC2 6l/7U+iCdMKzHK240mNErFIwRew0msRHiZ7fTZE2QJIcaoHv9IK66pJfh75vyXxxX7cH4lRFR/VhlCVKt0Z6OkGjwlxFtt7l6VD8vjxr0278A8j1VZ/fSCn2siLyr/g9kHJJx+J4UcgFc/jV/vnJ8Dmp/pJe2FN0BSNDpqdmPwoLUJMKHeCPY3O4oYkvldVtLA+l3L6x/b5zxPQYAcpuZiyuLkJ3tRD1UeyoGtq6QYXp1uONJbmtxzeh3hGp4MXZI8flb9k3xZHACPQl4mUbGqlGXIWcp53OX7LNaRJUOpHtUogSFYZZUGbDuXsgnj/pPigZqwJPmMYJRwk86IcN0W3ewdgtLlp/epMhvTEpWTd9z8xeCvdjhQtf1QFNtWTLfmd1yOKlFdSuYks4= 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: From: Pankaj Raghav As we don't have a way to split a folio to a any given lower folio order yet, avoid splitting the folio in split_huge_page_to_list() if it has a minimum folio order requirement. Signed-off-by: Pankaj Raghav Signed-off-by: Luis Chamberlain Reviewed-by: Hannes Reinecke --- mm/huge_memory.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 94c958f7ebb5..d897efc51025 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -3026,6 +3026,19 @@ int split_huge_page_to_list(struct page *page, struct list_head *list) goto out; } + /* + * Do not split if mapping has minimum folio order + * requirement. + * + * XXX: Once we have support for splitting to any lower + * folio order, then it could be split based on the + * min_folio_order. + */ + if (mapping_min_folio_order(mapping)) { + ret = -EAGAIN; + goto out; + } + gfp = current_gfp_context(mapping_gfp_mask(mapping) & GFP_RECLAIM_MASK); From patchwork Tue Feb 13 09:37:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Pankaj Raghav (Samsung)" X-Patchwork-Id: 13554790 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 3FC05C4829A for ; Tue, 13 Feb 2024 09:37:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C52FA8D0008; Tue, 13 Feb 2024 04:37:58 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C00B78D0001; Tue, 13 Feb 2024 04:37:58 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AA1CF8D0008; Tue, 13 Feb 2024 04:37:58 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 97C518D0001 for ; Tue, 13 Feb 2024 04:37:58 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 59524A1D9E for ; Tue, 13 Feb 2024 09:37:58 +0000 (UTC) X-FDA: 81786279036.30.A34630C Received: from mout-p-103.mailbox.org (mout-p-103.mailbox.org [80.241.56.161]) by imf22.hostedemail.com (Postfix) with ESMTP id 83E61C0005 for ; Tue, 13 Feb 2024 09:37:56 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=vk8rNVHr; dmarc=none; spf=pass (imf22.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.161 as permitted sender) smtp.mailfrom=me@pankajraghav.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707817076; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=WTxYFw2wNX7P5ZclG9FyVzbP0PebvoXLD7s4qqN4OLQ=; b=m1zRHIG2o1gdpbtPeUOrub1Pu8OymhHgo6TonHYwREYWLX7IC+rMwK8B+ES66J8e/C6PQe f15ivcYCGCwX6e92fAMIW+MbkgvaFBFkB03IvbUalUFUd8FAzBlUVWcbogE92ZofuU0LtA STS9bqxhSFfwO31Keu+GOIbFmF7E4XY= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=vk8rNVHr; dmarc=none; spf=pass (imf22.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.161 as permitted sender) smtp.mailfrom=me@pankajraghav.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707817076; a=rsa-sha256; cv=none; b=q/67+4tVVivg4IlGI+/C2zmDeXtYzDsty5TVOPpypAQbQhN8uoVCQRVa6pX7AdhcIAEbWm iaz1YH3VosC57tr//T43AEDVb0WgqSM8sqe0R7gXSdThe/qN57YxoTUJpmQNJbAQyJBUGH CZfZW/6p/4jGx6XvYwO43BlKZuCR6+0= Received: from smtp102.mailbox.org (smtp102.mailbox.org [10.196.197.102]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-103.mailbox.org (Postfix) with ESMTPS id 4TYx805XGYz9t7w; Tue, 13 Feb 2024 10:37:52 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1707817072; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WTxYFw2wNX7P5ZclG9FyVzbP0PebvoXLD7s4qqN4OLQ=; b=vk8rNVHrH9GnDjyMJds3YOI6FHkGLa5jobWuxpBSfDc8eim75cFZeal2zSOqMPmtRTP7Lt jiU1XTqkGbKSf4FyAvu8y5Kv3XT7peTK4JTd40qH112YpZ5MhTZqagUFznvuEPJGLeRzDO 1nvCvtEaI6Vb2cmva8byqNu3rPyCcR7y8jkug7J5YUuPwYCi6zhpTo6lN4rddW3W0Zq4xX 9jeP4tpx214SFXzzjp5l3ltv5glok+YytXEQGtoCIdhdlUkbWSpyoosppXs3wr6iTUM87n zVspg8aNshEzNRnan6HsNc0cCrqVf/Ti1mskfH4RqObvWYjl2B4tNvGSyEDuuA== From: "Pankaj Raghav (Samsung)" To: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: mcgrof@kernel.org, gost.dev@samsung.com, akpm@linux-foundation.org, kbusch@kernel.org, djwong@kernel.org, chandan.babu@oracle.com, p.raghav@samsung.com, linux-kernel@vger.kernel.org, hare@suse.de, willy@infradead.org, linux-mm@kvack.org, david@fromorbit.com Subject: [RFC v2 09/14] mm: Support order-1 folios in the page cache Date: Tue, 13 Feb 2024 10:37:08 +0100 Message-ID: <20240213093713.1753368-10-kernel@pankajraghav.com> In-Reply-To: <20240213093713.1753368-1-kernel@pankajraghav.com> References: <20240213093713.1753368-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 83E61C0005 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: sf6w5oi8tshgi8i5cj89s375xjii3dst X-HE-Tag: 1707817076-488241 X-HE-Meta: U2FsdGVkX1+cL1PD7imJjkvE1SsP0OU/iBXbGlQDHKg2QAP5qeYddZq4AVNXkve0X7fdZDuwF1zGuP+2NH1nvq8fbgtbB7Pqd5Xz1cuAQxI9Gv+aKPyPe0W9w0vAL25G3kn/YurVlMXMiB0e/8+bIWUluqwtNIt3ojt7qdLaUzQwEj5EcQz/dUkgg9VSB53HTOU4IgIoFtE2KCsbDFx4rojisz1/qutpJ8IpcVPP/wfXgHrWJZ2CD7RFe4L9Nl8rbTYoFwz40EvuakVSPK6Bmf0hVVilUZSVO6cS5yCKjwvt96QX4bNidonJu0bUJMQfU00XmrtVw84fGSyVNM65cw4Tia4/3lTn0CJq4B9aFj0l+MoZn5x8TCAsjc3PG6mvtd31xBa50x1jHeM+yId21z+DfBLtvzPKVmFtkHvKi5OlBKnOd2f0YGGCNeDglb1zzHyvP6KaETh9Kz6wKnfFj9UEWPQiKr6YDXwIwivzL5HOAjbeYZ0NnO8bNiZVM+dyTAxGWuGirXTV9o3aaNBDSxsTmRE0Mx4VuxXOM/+6DvOoQp6vbg2nZv8TpcbvbDJYOuBFp3tXBOmZgyosNiKD5ucJQ1XV/FGXQpEADsA5o3UFkjuL68xzyC7NcV75zdXJBxAR4u4CqaG7eLNYhyH7WeWpxPqVAsR+qJ+ZWp4lt/g0Jy/lmrrb21nJoqMy7s0nAo37SnJExj/sksxw8xGbMFcHGfkx0c10myP0xufEFULWEzzFtxjTG50xVNDiLRyHzkCwyaQtAIvgKFdzrN8VANy2GKIGGyOdY6LPSmCFv7TJW3DkZZMdJYETtzycvQPQJi5mBOc5L22VxiMbsuGn6Sszl9FY/7FA7j0RcJbySB6GKqFGy0pgHcnvGPBNb8zNccC0eh1VE8EbOcMcDQH2dgf8yR5iB8z7c/8Mu1NA0rY3rXGyCpjZ4EfGnNgb3sMb5aslRGgR8lKSUwJuKBx MdMq8rEI DUhABzzByv8yYsgb+cv24N6I1v2M+1zJ873RyyBvyJ7I+lMT9xg/3vNlZTyYbWSTJkj4jNBfeloSZ+Lt8cM29vOYOgf1TcK+pFeFCOpx0ZRnh8hLjbCL7/a1HwzWULGG82Q3ChevQoUB+hOk2WepI7jvMOU2Sd9zUV7mAZyNHz5rOPuACpEslMql4EQ7wkdxfBAM7MquA3epUMW/1F/dGH7h7dQFcvfCYV1qwXLSyyDAuDfRdjyetKEUdNbsG8IyxPOeuWmCcqOLWvUU1oGMGoOhhriRU7MAratH8QBxUFUdQB8TW9dsEaUEOXpuHR55umLsLmYmjw4tJnGSwaBCcD3bbCBhOW+sT1gqtsWQqTDnYnkTSDsGjErgTGaHcy1Gvejpib7ijvfhYaRxZ8dovONGiM9VObwnmYwPp2Bi1dNQInadls0YyuMzPvw== 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: From: "Matthew Wilcox (Oracle)" Folios of order 1 have no space to store the deferred list. This is not a problem for the page cache as file-backed folios are never placed on the deferred list. All we need to do is prevent the core MM from touching the deferred list for order 1 folios and remove the code which prevented us from allocating order 1 folios. Link: https://lore.kernel.org/linux-mm/90344ea7-4eec-47ee-5996-0c22f42d6a6a@google.com/ Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Hannes Reinecke --- include/linux/huge_mm.h | 7 +++++-- mm/filemap.c | 2 -- mm/huge_memory.c | 23 ++++++++++++++++++----- mm/internal.h | 4 +--- mm/readahead.c | 3 --- 5 files changed, 24 insertions(+), 15 deletions(-) diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h index 5adb86af35fc..916a2a539517 100644 --- a/include/linux/huge_mm.h +++ b/include/linux/huge_mm.h @@ -263,7 +263,7 @@ unsigned long thp_vma_allowable_orders(struct vm_area_struct *vma, unsigned long thp_get_unmapped_area(struct file *filp, unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags); -void folio_prep_large_rmappable(struct folio *folio); +struct folio *folio_prep_large_rmappable(struct folio *folio); bool can_split_folio(struct folio *folio, int *pextra_pins); int split_huge_page_to_list(struct page *page, struct list_head *list); static inline int split_huge_page(struct page *page) @@ -410,7 +410,10 @@ static inline unsigned long thp_vma_allowable_orders(struct vm_area_struct *vma, return 0; } -static inline void folio_prep_large_rmappable(struct folio *folio) {} +static inline struct folio *folio_prep_large_rmappable(struct folio *folio) +{ + return folio; +} #define transparent_hugepage_flags 0UL diff --git a/mm/filemap.c b/mm/filemap.c index 7a6e15c47150..c8205a534532 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -1922,8 +1922,6 @@ struct folio *__filemap_get_folio(struct address_space *mapping, pgoff_t index, gfp_t alloc_gfp = gfp; err = -ENOMEM; - if (order == 1) - order = 0; if (order < min_order) order = min_order; if (order > 0) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index d897efc51025..6ec3417638a1 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -788,11 +788,15 @@ struct deferred_split *get_deferred_split_queue(struct folio *folio) } #endif -void folio_prep_large_rmappable(struct folio *folio) +struct folio *folio_prep_large_rmappable(struct folio *folio) { - VM_BUG_ON_FOLIO(folio_order(folio) < 2, folio); - INIT_LIST_HEAD(&folio->_deferred_list); + if (!folio || !folio_test_large(folio)) + return folio; + if (folio_order(folio) > 1) + INIT_LIST_HEAD(&folio->_deferred_list); folio_set_large_rmappable(folio); + + return folio; } static inline bool is_transparent_hugepage(struct folio *folio) @@ -3095,7 +3099,8 @@ int split_huge_page_to_list(struct page *page, struct list_head *list) /* Prevent deferred_split_scan() touching ->_refcount */ spin_lock(&ds_queue->split_queue_lock); if (folio_ref_freeze(folio, 1 + extra_pins)) { - if (!list_empty(&folio->_deferred_list)) { + if (folio_order(folio) > 1 && + !list_empty(&folio->_deferred_list)) { ds_queue->split_queue_len--; list_del(&folio->_deferred_list); } @@ -3146,6 +3151,9 @@ void folio_undo_large_rmappable(struct folio *folio) struct deferred_split *ds_queue; unsigned long flags; + if (folio_order(folio) <= 1) + return; + /* * At this point, there is no one trying to add the folio to * deferred_list. If folio is not in deferred_list, it's safe @@ -3171,7 +3179,12 @@ void deferred_split_folio(struct folio *folio) #endif unsigned long flags; - VM_BUG_ON_FOLIO(folio_order(folio) < 2, folio); + /* + * Order 1 folios have no space for a deferred list, but we also + * won't waste much memory by not adding them to the deferred list. + */ + if (folio_order(folio) <= 1) + return; /* * The try_to_unmap() in page reclaim path might reach here too, diff --git a/mm/internal.h b/mm/internal.h index f309a010d50f..5174b5b0c344 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -419,9 +419,7 @@ static inline struct folio *page_rmappable_folio(struct page *page) { struct folio *folio = (struct folio *)page; - if (folio && folio_order(folio) > 1) - folio_prep_large_rmappable(folio); - return folio; + return folio_prep_large_rmappable(folio); } static inline void prep_compound_head(struct page *page, unsigned int order) diff --git a/mm/readahead.c b/mm/readahead.c index a361fba18674..7d5f6a8792a8 100644 --- a/mm/readahead.c +++ b/mm/readahead.c @@ -560,9 +560,6 @@ void page_cache_ra_order(struct readahead_control *ractl, /* Don't allocate pages past EOF */ while (order > min_order && index + (1UL << order) - 1 > limit) order--; - /* THP machinery does not support order-1 */ - if (order == 1) - order = 0; if (order < min_order) order = min_order; From patchwork Tue Feb 13 09:37:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Pankaj Raghav (Samsung)" X-Patchwork-Id: 13554791 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 8B38EC4829F for ; Tue, 13 Feb 2024 09:38:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 17C7C8D0009; Tue, 13 Feb 2024 04:38:01 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 108188D0001; Tue, 13 Feb 2024 04:38:01 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EC2CA8D0009; Tue, 13 Feb 2024 04:38:00 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id D44B78D0001 for ; Tue, 13 Feb 2024 04:38:00 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id AEE0080892 for ; Tue, 13 Feb 2024 09:38:00 +0000 (UTC) X-FDA: 81786279120.17.281D60F Received: from mout-p-201.mailbox.org (mout-p-201.mailbox.org [80.241.56.171]) by imf03.hostedemail.com (Postfix) with ESMTP id 070E420016 for ; Tue, 13 Feb 2024 09:37:58 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=BmByWoGm; dmarc=none; spf=pass (imf03.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.171 as permitted sender) smtp.mailfrom=me@pankajraghav.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707817079; a=rsa-sha256; cv=none; b=Y3OSjDAf1V1c3YOtOdED+Di3BVgMy5SegH57dFwzjtAUNct85yk1Df7FV152WzDCW5s3Kq t1G7kgG8m0qHgZr+Zd/TtdKDozt6ckrDZJsM9F9iZpchAcKbXQTKxn9mw1eMRBQpamWYxk ac0n/EFDTNyEJldNG2XhIv6QHUGEX9I= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=BmByWoGm; dmarc=none; spf=pass (imf03.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.171 as permitted sender) smtp.mailfrom=me@pankajraghav.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707817079; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=TZW5dJ0nv7fo+LI90ijtR+d2/ZkIfNS9bRkcnAAFJTI=; b=irefFZkpI5vl8Uelyp0ThTGwwsuEfo1yvdWRL++sTC244kkvxhkRRWx4qmJlZFtNedIqqt r7awbu8oSHxtEKv3g8vUcangvvbYo8d9/1tGYGAcRXSQSBwP/Bz7lRhZUqX7cJVD9AvU9I G90DOrEYsfwCYTSBgstCUpO6jMU7fS0= Received: from smtp202.mailbox.org (smtp202.mailbox.org [IPv6:2001:67c:2050:b231:465::202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-201.mailbox.org (Postfix) with ESMTPS id 4TYx8347SMz9stR; Tue, 13 Feb 2024 10:37:55 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1707817075; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TZW5dJ0nv7fo+LI90ijtR+d2/ZkIfNS9bRkcnAAFJTI=; b=BmByWoGmvp+kEWIRd+4bCnx1c2aolG8l1MFYl3diqfPl1tqcl9YnuViapkcDsVIqIxJBzY QXT/YcPpK9B3nuaFEVuFdW5R6AlwojOALukyjqK/Yy3Te36bjXCR40bUAM+uoMezT5lgKn NC+RH4zuH3m2XBI4ZPaWaxWn/2hQpPmmrP0HjKHmzPORWmz+z4fAA3h98UmbZDvBT2S2Vk isdlWNDiTRE+qpjyeeVHFzn5lQttGKmWNJ2UkMcSSryAvZdDhvlh337EwDRWCUh4cfyLwr x0EH5x4x/v33DNXaAiV4YYn1JWJnST4sjQeqW1JYK0nqjGowTU6abq3eQaKg2g== From: "Pankaj Raghav (Samsung)" To: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: mcgrof@kernel.org, gost.dev@samsung.com, akpm@linux-foundation.org, kbusch@kernel.org, djwong@kernel.org, chandan.babu@oracle.com, p.raghav@samsung.com, linux-kernel@vger.kernel.org, hare@suse.de, willy@infradead.org, linux-mm@kvack.org, david@fromorbit.com Subject: [RFC v2 10/14] iomap: fix iomap_dio_zero() for fs bs > system page size Date: Tue, 13 Feb 2024 10:37:09 +0100 Message-ID: <20240213093713.1753368-11-kernel@pankajraghav.com> In-Reply-To: <20240213093713.1753368-1-kernel@pankajraghav.com> References: <20240213093713.1753368-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 070E420016 X-Stat-Signature: c8rybhry4xw8atabxh5e6mduk675rmf5 X-HE-Tag: 1707817078-38223 X-HE-Meta: U2FsdGVkX1/x3oMNtkz9cHqi1L4AT8SlFFF6dCuThNIJBtITy2fcAH+9HbaClXgdyNXAPSXWDBSXk3EH5bGV8AmsUmJ/AF9igeK8pY3Qhw7+pYXlmI43AO+jnXXRefjc6yg92DfEz3zppcAELvPbiB9KD9yi+k3VGNl/nDQgY0lOe2mdmobLAgGS5dFP1yAshGAOO/cbi833OP34iwLgS0dEPVGF2QyfpTZWp95oODcDuNv3oDaXth426zfRNU9uaT62MVbHbeTMf+domqRtPCQ0b3Bndw4L0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iRqMovuf 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: From: Pankaj Raghav iomap_dio_zero() will pad a fs block with zeroes if the direct IO size < fs block size. iomap_dio_zero() has an implicit assumption that fs block size < page_size. This is true for most filesystems at the moment. If the block size > page size, this will send the contents of the page next to zero page(as len > PAGE_SIZE) to the underlying block device, causing FS corruption. iomap is a generic infrastructure and it should not make any assumptions about the fs block size and the page size of the system. Signed-off-by: Pankaj Raghav Reviewed-by: Hannes Reinecke Reviewed-by: Darrick J. Wong --- fs/iomap/direct-io.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c index bcd3f8cf5ea4..04f6c5548136 100644 --- a/fs/iomap/direct-io.c +++ b/fs/iomap/direct-io.c @@ -239,14 +239,23 @@ static void iomap_dio_zero(const struct iomap_iter *iter, struct iomap_dio *dio, struct page *page = ZERO_PAGE(0); struct bio *bio; - bio = iomap_dio_alloc_bio(iter, dio, 1, REQ_OP_WRITE | REQ_SYNC | REQ_IDLE); + WARN_ON_ONCE(len > (BIO_MAX_VECS * PAGE_SIZE)); + + bio = iomap_dio_alloc_bio(iter, dio, BIO_MAX_VECS, + REQ_OP_WRITE | REQ_SYNC | REQ_IDLE); fscrypt_set_bio_crypt_ctx(bio, inode, pos >> inode->i_blkbits, GFP_KERNEL); + bio->bi_iter.bi_sector = iomap_sector(&iter->iomap, pos); bio->bi_private = dio; bio->bi_end_io = iomap_dio_bio_end_io; - __bio_add_page(bio, page, len, 0); + while (len) { + unsigned int io_len = min_t(unsigned int, len, PAGE_SIZE); + + __bio_add_page(bio, page, io_len, 0); + len -= io_len; + } iomap_dio_submit_bio(iter, dio, bio, pos); } From patchwork Tue Feb 13 09:37:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Pankaj Raghav (Samsung)" X-Patchwork-Id: 13554792 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 73111C4829A for ; Tue, 13 Feb 2024 09:38:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 01D828D000A; Tue, 13 Feb 2024 04:38:04 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id F0E9C8D0001; Tue, 13 Feb 2024 04:38:03 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DB02F8D000A; Tue, 13 Feb 2024 04:38:03 -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 C64478D0001 for ; Tue, 13 Feb 2024 04:38:03 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 985861A0156 for ; Tue, 13 Feb 2024 09:38:03 +0000 (UTC) X-FDA: 81786279246.21.37540E1 Received: from mout-p-102.mailbox.org (mout-p-102.mailbox.org [80.241.56.152]) by imf20.hostedemail.com (Postfix) with ESMTP id E8AB91C0002 for ; Tue, 13 Feb 2024 09:38:01 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=LJLR6r+3; dmarc=none; spf=pass (imf20.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.152 as permitted sender) smtp.mailfrom=me@pankajraghav.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707817082; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=MO0EI8w5WbkUQtm6TaQ0DQo1nNqS6QPeZXjuQJSUGbE=; b=zccjDZM0IA8A5Q+xFCQgnLvkBioFDAdjc4EsBr5D1ST9KH2SSKWGVjZFnWHAIwjcwRpX2r DO58/djauSs9ikCO9MwqV32AEWmZBCa08jSRQZtdrRPn/WtMUbcJPr9NPtIQd0l+R3RQER pX88BzpQpzCTTlCNNarhpkNx9dA8YCc= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=LJLR6r+3; dmarc=none; spf=pass (imf20.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.152 as permitted sender) smtp.mailfrom=me@pankajraghav.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707817082; a=rsa-sha256; cv=none; b=ML6P8eH/zLgyNyH+7+ZAkK2rpawW4mskxezZAa9VRcGNabbcKRMxXVISRQC0gSjUERB6k2 VKEl2ZZ5ZiO0mwmhpJ436IIUG4eyE1MqRr+eexVh1MNMKD0Dc2uF1sXLUR0Uv1Yr3KBGS/ NogY0Bv7g+g44ndjci0xv4juekVE+HI= Received: from smtp202.mailbox.org (smtp202.mailbox.org [10.196.197.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-102.mailbox.org (Postfix) with ESMTPS id 4TYx864DCXz9sp2; Tue, 13 Feb 2024 10:37:58 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1707817078; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MO0EI8w5WbkUQtm6TaQ0DQo1nNqS6QPeZXjuQJSUGbE=; b=LJLR6r+34CoFzdv2J3qP5MfDOQ6MMnj0VOgb57gkDihAt/g5yljWgrPF5I+ZK4MfCqdLSi vBMvmgP3hTSxUlA4ch0+pC0vjX+MdsTWc5PiIjFGjau9gw7S/J33U5ddWn4cjiM6DlMG0W Ur98/ltE05ZvGCzVpgYzQrW3OcQxJZP+oR1H5YbatkY+28PnDdNEeZSZ2gCzVWtzSnF5Q1 YJGWDOj6+sAm2G6B++jG9Yh5Hun13hydNfMq8aFAgAB9nouxcBdVpJXDifnxYLgegAPikF o8MBpLKXTY6q6zwboZzhre51ySyXG0YGTKSCzYXVfa+9HC40mLev/vudl4ahOg== From: "Pankaj Raghav (Samsung)" To: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: mcgrof@kernel.org, gost.dev@samsung.com, akpm@linux-foundation.org, kbusch@kernel.org, djwong@kernel.org, chandan.babu@oracle.com, p.raghav@samsung.com, linux-kernel@vger.kernel.org, hare@suse.de, willy@infradead.org, linux-mm@kvack.org, david@fromorbit.com, Dave Chinner Subject: [RFC v2 11/14] xfs: expose block size in stat Date: Tue, 13 Feb 2024 10:37:10 +0100 Message-ID: <20240213093713.1753368-12-kernel@pankajraghav.com> In-Reply-To: <20240213093713.1753368-1-kernel@pankajraghav.com> References: <20240213093713.1753368-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: E8AB91C0002 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: xfoapy13fyptseims97pnmwdkdfqiyqx X-HE-Tag: 1707817081-298741 X-HE-Meta: U2FsdGVkX1876hDCv3tQorznHmauKfCqlm2faBpaP//BfUoVZIY2VHGya+JMfHFlOEapBOqS2T10/bkUK7v869Ss3MAMHxGK0cjkgWHbz0Nb+iKroUYF8PhbPtvQtyd0N/33e9JYkMu6vxYT2PrwhbghDDxl8Zn0o+Szfs02+F2VNo1IKFeaEjs8v9ozf/P1oeg8hPUkTfAHoEjuvghZIhT86Y+qkAm4xUFK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QBJbiMlSRgu2j7aOzw33Po/UFYaagfLfbhWLQ1Sbk1kjWLUO6+zvJdQWXbF3S31jg== 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: From: Dave Chinner For block size larger than page size, the unit of efficient IO is the block size, not the page size. Leaving stat() to report PAGE_SIZE as the block size causes test programs like fsx to issue illegal ranges for operations that require block size alignment (e.g. fallocate() insert range). Hence update the preferred IO size to reflect the block size in this case. Signed-off-by: Dave Chinner [mcgrof: forward rebase in consideration for commit dd2d535e3fb29d ("xfs: cleanup calculating the stat optimal I/O size")] Signed-off-by: Luis Chamberlain --- fs/xfs/xfs_iops.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c index a0d77f5f512e..8791a9d80897 100644 --- a/fs/xfs/xfs_iops.c +++ b/fs/xfs/xfs_iops.c @@ -515,6 +515,8 @@ xfs_stat_blksize( struct xfs_inode *ip) { struct xfs_mount *mp = ip->i_mount; + unsigned long default_size = max_t(unsigned long, PAGE_SIZE, + mp->m_sb.sb_blocksize); /* * If the file blocks are being allocated from a realtime volume, then @@ -543,7 +545,7 @@ xfs_stat_blksize( return 1U << mp->m_allocsize_log; } - return PAGE_SIZE; + return default_size; } STATIC int From patchwork Tue Feb 13 09:37:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Pankaj Raghav (Samsung)" X-Patchwork-Id: 13554793 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 87986C4829A for ; Tue, 13 Feb 2024 09:38:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1CB898D000B; Tue, 13 Feb 2024 04:38:07 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 12D358D0001; Tue, 13 Feb 2024 04:38:07 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EE9C38D000B; Tue, 13 Feb 2024 04:38:06 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id D81938D0001 for ; Tue, 13 Feb 2024 04:38:06 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id B7DD840284 for ; Tue, 13 Feb 2024 09:38:06 +0000 (UTC) X-FDA: 81786279372.28.FFD1679 Received: from mout-p-201.mailbox.org (mout-p-201.mailbox.org [80.241.56.171]) by imf22.hostedemail.com (Postfix) with ESMTP id 1AFAAC0025 for ; Tue, 13 Feb 2024 09:38:04 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b="WxRaE/Va"; dmarc=none; spf=pass (imf22.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.171 as permitted sender) smtp.mailfrom=me@pankajraghav.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707817085; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=vzZe/GhW0AKuEEGxmrsisVmOwc1fDz2jZ00nW20jdYY=; b=RcGt6r7rGxbO+Et6dlARiHEHg4nA4mq+Z0n1X69ORFiyedx/yLy0rU5BSEdiTWHL0xsOVV pbarTx5AbIj2Ko7SJnCYVPLATjzO9V1MqR9qE1zYI9XDeFZ9XEjmDxnqEAwI32qI4qH1rz 5KCT3To/oxqsy59wVNSS/KjE+95J8ic= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b="WxRaE/Va"; dmarc=none; spf=pass (imf22.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.171 as permitted sender) smtp.mailfrom=me@pankajraghav.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707817085; a=rsa-sha256; cv=none; b=VoDTgUparMYM/E1HFCW5AHoPm3OjfQPVr03uRyB9fUAAmuteQ9Rqw/nFKwIfW3B1MmjgKc MCkrNrmr/rzofR1Doq/dIAyGWAOktmm5uXcZgKZ0buIGHkovbdfst02jzKFN0F127IJ1lN 8PFyitm4+f7/Qx5PB3J9O0WcfYrXspc= Received: from smtp202.mailbox.org (smtp202.mailbox.org [IPv6:2001:67c:2050:b231:465::202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-201.mailbox.org (Postfix) with ESMTPS id 4TYx894brXz9sq8; Tue, 13 Feb 2024 10:38:01 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1707817081; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vzZe/GhW0AKuEEGxmrsisVmOwc1fDz2jZ00nW20jdYY=; b=WxRaE/VaFusCFl5KQNguCwied061qANl5HTR9V9OJtzJe7ZG6mjmEis1M1BAnz6yvnvEHC Nzf87hlFBc4f43/BSJaMthC/KNrvWMe4PJaq0ITrrMSZgEwSJkSKiPG4hjT8OYYNVT1U05 5ckop88rRS+YSwN0H/gTEa2H+P1LDxjxKr4efXJ9CIgXLF4TUZHddADytDu7kvt01z+2VT GdFqmNf7DPnSJu4Tame5pp+JQjC4DSsYSHACxPoPkZFDSKwCrsSdshkNN9EgvAgYFytnql Leiu+FIkvhBgHBxs8VORK/8FPFWm2a6oCwlNjL0S2A9yNcrXB4yCGzHqPGEWGw== From: "Pankaj Raghav (Samsung)" To: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: mcgrof@kernel.org, gost.dev@samsung.com, akpm@linux-foundation.org, kbusch@kernel.org, djwong@kernel.org, chandan.babu@oracle.com, p.raghav@samsung.com, linux-kernel@vger.kernel.org, hare@suse.de, willy@infradead.org, linux-mm@kvack.org, david@fromorbit.com Subject: [RFC v2 12/14] xfs: make the calculation generic in xfs_sb_validate_fsb_count() Date: Tue, 13 Feb 2024 10:37:11 +0100 Message-ID: <20240213093713.1753368-13-kernel@pankajraghav.com> In-Reply-To: <20240213093713.1753368-1-kernel@pankajraghav.com> References: <20240213093713.1753368-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 1AFAAC0025 X-Stat-Signature: jsijabffmhqmd1jjzuabbfty4w5h7bzc X-HE-Tag: 1707817084-953157 X-HE-Meta: U2FsdGVkX19VvuQLERgpce0t5ngMuyReieI6uCjcsrhZJE7+2ptUokFrNGhC/fvonHeigbWSTSHQ4V59BFS5/Mm/3Z3MSP3TP6g7uVtz209ReRmdRuAieEg5mcAADoDXGjo803Pggz6opz0MG5KuMcA7n8h97eP0TKFRJ+OP8d6RY2/YUaGR1ZytgtXuZNndkqj0XWgdyOjbGfUrPBvbetEw2BOxQ8NzgIY80CXg+TrJQW4wsxllWBFkeERmcRmFrjJlSqF8IG5ZFxWutC2YgL3qIJQNhnYlzHQW3j8UZskSN2a2/vhnIH3FciRQzMq7WVFUeDatMkvbLSdEv9x17EMgpk/X3N5b8Fde1+5ZQaUiwSWqJUXs3mCbSxqsxdI3lOOY8AtSPT/HxjZipRbqaWXJJy5tlbO/7H+mToi/O0JKMTlajbua4V4mUV9tOMs5kGJAp1vXcqlxN8ABFeObojMhF6pDrOMEX66d0lxFvI1mI40Fit+ZCrPHOYEOVdBCDOQlb538wMR1exkVtKaAAbAy2nbWSKhebLLrCbTx4S5PkxIkrHVL4iESVXtzBGtFZD0dJW1GaMfX4lYbEBHXjGIm7Ku0gSBvz43LNyRu2s4Q1etxhCKzcepuAM7Dhvz7MSlLRIZJqCMwO2MCWGdMApM176mjSSQyaA4T2vUUrC/GNSI16+jAI/EezVzUMzRH3U658RiZ8QrqqQcbXVTxSWLoxpVlDW9B/K860wY0mj44d9ETYwWSc30/YPuF3VJ3VM97D6gnmnC05rBFn5fOJgFa7X0C8b5Cpy7RLcOiQ4R7nLgG+0+ese/ZcV26e1sxHm4xS+HqMtpScd53RykoKp1KPN3F15aat1bmy9m2sWCSTziKBpmM/7GfeDm8AmN//RxyDqheQZKT6dUvFypfQxqhdkt52kKXMdpzpDxzMwd9qZjzIOCgRoZ7S13FhRm1ISxGbD2Lnt9pNBDoZOb xn7sf9tS toaClnyQGr0zzbccNdMUGJxr9kIXL82COOR2EcT3wE6mwluI/yscCxHmMAfMNOYeILVakcUJEHsyftXyvcy0vBogRZ6yxHRttZ4iJT7iC40VLfeBZyr6XRMdZuxKwldVB4uStxKB5fSivJ+CKUbIsyimW+zLaYV8d8QK6uPY3+HETDFCnkJrUAEAf+BXiXzj6X6sDlDEFQoRB+6RD1Ac+MZJPRZ5/lrkFdFxJaMUD5aSdnQgli8O3k5Ree+rPn9812CcTxdCMHIy/jeIa+25f54wlO8ACA8GIQePBIFAIQ1vTy5k3pDSy+RhLrUr3cLOy6EzioyiB38s5tNn8LodepC+xbzC7bZdR89GRjRgsBD8CtofoVhzhKx8smur0pykZdVaJ X-Bogosity: Ham, tests=bogofilter, spamicity=0.000311, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Pankaj Raghav Instead of assuming that PAGE_SHIFT is always higher than the blocklog, make the calculation generic so that page cache count can be calculated correctly for LBS. Signed-off-by: Pankaj Raghav --- fs/xfs/xfs_mount.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/fs/xfs/xfs_mount.c b/fs/xfs/xfs_mount.c index aabb25dc3efa..bfbaaecaf668 100644 --- a/fs/xfs/xfs_mount.c +++ b/fs/xfs/xfs_mount.c @@ -133,9 +133,13 @@ xfs_sb_validate_fsb_count( { ASSERT(PAGE_SHIFT >= sbp->sb_blocklog); ASSERT(sbp->sb_blocklog >= BBSHIFT); + unsigned long mapping_count; + uint64_t bytes = nblocks << sbp->sb_blocklog; + + mapping_count = bytes >> PAGE_SHIFT; /* Limited by ULONG_MAX of page cache index */ - if (nblocks >> (PAGE_SHIFT - sbp->sb_blocklog) > ULONG_MAX) + if (mapping_count > ULONG_MAX) return -EFBIG; return 0; } From patchwork Tue Feb 13 09:37:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Pankaj Raghav (Samsung)" X-Patchwork-Id: 13554794 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 14329C4829A for ; Tue, 13 Feb 2024 09:38:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9B9968D000C; Tue, 13 Feb 2024 04:38:09 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 96A098D0001; Tue, 13 Feb 2024 04:38:09 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 795B98D000C; Tue, 13 Feb 2024 04:38:09 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 64AAA8D0001 for ; Tue, 13 Feb 2024 04:38:09 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 43A11A0B15 for ; Tue, 13 Feb 2024 09:38:09 +0000 (UTC) X-FDA: 81786279498.06.DBA6B2B Received: from mout-p-201.mailbox.org (mout-p-201.mailbox.org [80.241.56.171]) by imf12.hostedemail.com (Postfix) with ESMTP id B5F1840020 for ; Tue, 13 Feb 2024 09:38:07 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=lAJKQkv8; spf=pass (imf12.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.171 as permitted sender) smtp.mailfrom=me@pankajraghav.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707817087; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=+2ss5SlGBbWn5UCkRFfS2rrVeqSyvxI6jrmUJVBEXU4=; b=P2PHZZ+7ILDf7dCMBlYjK3sp6gqsk4ElTv5Qpid90gah2BXP2rMqPe4cTXpN6jXxKAvSMb rgIn8jpgu5M6HfFKWMG87/6upNxGEgFl3hDZGcKm8vd2sVYTXQEm71JFPRauErpwGEswRG lDvh8LQ6B7FD+382/QqWC8kmcVfwaDo= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707817087; a=rsa-sha256; cv=none; b=cqupNaSG+Plti8tkiRZdneRo1CDFFwgroIHy4OtLEM854noxbrZc7HbHsZmUAgF+f4bQOI ag3+Kq28pxOliNpU9BSujkAXhO+xJYtnZOyQyZUryT3UJjKm7NuBanYzCGmGn3/XrJ2rYq 8btByKBdSgBZf4E6tRPgex+ytxroxhI= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=lAJKQkv8; spf=pass (imf12.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.171 as permitted sender) smtp.mailfrom=me@pankajraghav.com; dmarc=none Received: from smtp2.mailbox.org (smtp2.mailbox.org [10.196.197.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-201.mailbox.org (Postfix) with ESMTPS id 4TYx8D3Xykz9t40; Tue, 13 Feb 2024 10:38:04 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1707817084; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+2ss5SlGBbWn5UCkRFfS2rrVeqSyvxI6jrmUJVBEXU4=; b=lAJKQkv8JFUfAalsowcHUM0qevPxPDym9zxQEdcsGZ1QD34oloukLEkuEh9wYi/vwk3vTz 88MWHR5ma60yh6fcF9kNUWOoPzhytLjV6Ujqkm3NEpqVKXssY+AJ7VmlsSzPHrbWqiHHA/ nnbX4EV4Fhls9o8I6ajQX4wDUiZx29RHWX8bCkX0wpri4sldWbDFrGm1ryQp5raRgie1qr Lqsie4oCOj0gEl5zUVTbX8ms0OBr8KlMQBHEY4+8qUfqB3zPYcRNxXNbTgt3YZGojnJJEv sgKHAUiic9WDKzyryMjZWH9/hR/YdqHkJvfMwSZBVuLypx3foevRXAeEudMk+A== From: "Pankaj Raghav (Samsung)" To: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: mcgrof@kernel.org, gost.dev@samsung.com, akpm@linux-foundation.org, kbusch@kernel.org, djwong@kernel.org, chandan.babu@oracle.com, p.raghav@samsung.com, linux-kernel@vger.kernel.org, hare@suse.de, willy@infradead.org, linux-mm@kvack.org, david@fromorbit.com Subject: [RFC v2 13/14] xfs: add an experimental CONFIG_XFS_LBS option Date: Tue, 13 Feb 2024 10:37:12 +0100 Message-ID: <20240213093713.1753368-14-kernel@pankajraghav.com> In-Reply-To: <20240213093713.1753368-1-kernel@pankajraghav.com> References: <20240213093713.1753368-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Stat-Signature: cbmgon4nuxjcz96b5ryzxtuouthghmtb X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: B5F1840020 X-Rspam-User: X-HE-Tag: 1707817087-121631 X-HE-Meta: U2FsdGVkX1/OgUxW32fRpI8tnEL4qOX6hsBIUvjVNIXTz6Z5wvPZekuzzb9KojcilKfm8PKYekEDgR8RL09X557cFdcBiny8bRTRuV4kfQQShqy94T9gHHZptyE+D4XCv0WHAMUVnB2jhLYq9T4x1YPrsiEBktoRB4HN8Y7AJEAmr0kc9+j1rMc9e9pFc75hJ5UiTX32JYqeORtHeTcgu1gK54AVP0mZ21U6I61ORasulY5d++dz5g0eGzXN+6ZgkHoM1eJpqDmWlqvVbR+Nk6sTOB3w4P6dK0RJLWbeUjOkps8sia8xo8yitxhSH2hO+eEcJ0XmhY/mFXOD0FtJi8nmc+rcYK2vUlH48QUl0e0boW03FpZeDd9u7D4k9wTo9SU4Eid/8+uXNY5EmA04VXGa2x7IQQqWY5hJB24y6lqN/xyOumB48ak0M9+9wfrdKZqqs85nmSvS2xK6lk0r6R7STSe8Essl98AQqMGxutUr+U/9I3T3RVqjCFsUcL8+Vr8vbs+gnvGUVu35i8y6POhF5QRQRFhplyFgCLkl+6baubPRa+54al+iNYDYdmwM4JEO01FFNPs40rmXrpll4kg+bl9QjL+howRZ09vdr/oMFgPZVwg/jyuvvWaRP21zOJEfzb8FmJ/a0oudZmQe0ip5FVbMBhRwolP2guQwc+VkvwoHuYnZBJAdqCUtwIyloOOlzGMonLMReh5b5k7FWDHiUForSHtYBFhGu0BdyB22Tr2XgEc97Hj8G77QdH5yQNs7ogwCo3KWudRlRFXeIYcfhrgsFLBl7TZLO62N7V6kCYobg3pS1L7aoDVn363+57dLeQKPptXYGIfnw/ZEpc7WUWlUy+ZPnx1WhwzR3gPKVmiXyQQFsS7M72xJg0q/4qPEGMRira1qoeTVDv8yH5pG5ug7mz1oi/alVTVY4wWTcJ12ejwrTL59pkKq7X8AjyY0k2IUxefqu/vC1E8 CWnYB9pR g2A2J43h1Yzs/CX1oUjlk9lwssb+/e4iDOJlsuy1PScgf2PeCS/rTSkFNh8zDT6KRPZxjPTEHrCUH0IT8nzbvWUQv3U6e7R6JhqiylhwxDDiUzvo= 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: From: Pankaj Raghav Add an experimental CONFIG_XFS_LBS option to enable LBS support in XFS. Retain the ASSERT for PAGE_SHIFT if CONFIG_XFS_LBS is not enabled. Signed-off-by: Pankaj Raghav Reviewed-by: Darrick J. Wong --- fs/xfs/Kconfig | 11 +++++++++++ fs/xfs/xfs_mount.c | 4 +++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/fs/xfs/Kconfig b/fs/xfs/Kconfig index 567fb37274d3..6b0db2f7dc13 100644 --- a/fs/xfs/Kconfig +++ b/fs/xfs/Kconfig @@ -216,3 +216,14 @@ config XFS_ASSERT_FATAL result in warnings. This behavior can be modified at runtime via sysfs. + +config XFS_LBS + bool "XFS large block size support (EXPERIMENTAL)" + depends on XFS_FS + help + Set Y to enable support for filesystem block size > system's + base page size. + + This feature is considered EXPERIMENTAL. Use with caution! + + If unsure, say N. diff --git a/fs/xfs/xfs_mount.c b/fs/xfs/xfs_mount.c index bfbaaecaf668..596aa2cdefbc 100644 --- a/fs/xfs/xfs_mount.c +++ b/fs/xfs/xfs_mount.c @@ -131,11 +131,13 @@ xfs_sb_validate_fsb_count( xfs_sb_t *sbp, uint64_t nblocks) { - ASSERT(PAGE_SHIFT >= sbp->sb_blocklog); ASSERT(sbp->sb_blocklog >= BBSHIFT); unsigned long mapping_count; uint64_t bytes = nblocks << sbp->sb_blocklog; + if (!IS_ENABLED(CONFIG_XFS_LBS)) + ASSERT(PAGE_SHIFT >= sbp->sb_blocklog); + mapping_count = bytes >> PAGE_SHIFT; /* Limited by ULONG_MAX of page cache index */ From patchwork Tue Feb 13 09:37:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Pankaj Raghav (Samsung)" X-Patchwork-Id: 13554795 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 3217BC48260 for ; Tue, 13 Feb 2024 09:38:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B8F4D8D000D; Tue, 13 Feb 2024 04:38:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B3E978D0001; Tue, 13 Feb 2024 04:38:12 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 96AC18D000D; Tue, 13 Feb 2024 04:38:12 -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 813358D0001 for ; Tue, 13 Feb 2024 04:38:12 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 592A6C0B11 for ; Tue, 13 Feb 2024 09:38:12 +0000 (UTC) X-FDA: 81786279624.17.87DB127 Received: from mout-p-101.mailbox.org (mout-p-101.mailbox.org [80.241.56.151]) by imf30.hostedemail.com (Postfix) with ESMTP id B824080009 for ; Tue, 13 Feb 2024 09:38:10 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=ENbwnnNB; dmarc=none; spf=pass (imf30.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.151 as permitted sender) smtp.mailfrom=me@pankajraghav.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707817091; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ydvUqzYBcKzyH4ZGo5x0A9m5vNe3qnV9Z0vpVQaGpLg=; b=IL7AzQ2IpddhVIW2EBq33d7syuOUzs0RGGaXk4E4gSEdx9I8H/kyVQMW/Nufg927FoBD/P geW6rpQB7zv/bLkdO+Soz8B/bvnYnYXJ6p7lNMPAbE/CrKsyn4BYTxi5CSeeV7NIY+5mA4 aGXz8uOt3O2VzkEsE1a/WxOZX50gKn8= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=ENbwnnNB; dmarc=none; spf=pass (imf30.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.151 as permitted sender) smtp.mailfrom=me@pankajraghav.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707817091; a=rsa-sha256; cv=none; b=QR4G3TnCx1n50K7Wko0P+GNScteVlyRK10fRS/5n5b9DlN/g+eecnsWuzsKvLhYgHlF0st foe7aTu1K0NYgKcimu/E5LDqO9Lq7SoEHcuvDgQSdE+Y7BeRGYdYQYxeM5OG3zdHskXbVO /3A7FOGPJcnFjlRcNDDv0LJ6numBar0= Received: from smtp202.mailbox.org (smtp202.mailbox.org [IPv6:2001:67c:2050:b231:465::202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-101.mailbox.org (Postfix) with ESMTPS id 4TYx8H2fChz9sSH; Tue, 13 Feb 2024 10:38:07 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1707817087; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ydvUqzYBcKzyH4ZGo5x0A9m5vNe3qnV9Z0vpVQaGpLg=; b=ENbwnnNBjOlMkTNsWgmN/QeJZ4bByf9vXC2SH9MWslItb5E3wLNJdxS5OYwgUczoQQxGFa jJLfvCUFWE4S4XIaf/gyJsxDpV54gpCGO6Q09Hr3W1Zl8hpSte2SCg/NxBVzt13u5b+rtn u9QhTF7FnDJlW3xsb7G6zptXw5QVnwjAOVIogxhjlYniqe0K1ORrtaGBSqFIq7XIZecY9G asCnrkLcVOePpZAFLxRLQb3P4hXMoiEeVmElnhxfjx+/5h/OFo9SJwBVx77eiPLb+MoeAw aa/PQKwI9st5rNiozYJhatwuGinu3iv/klvwOtrhhlSPwM2BtJQuDhCzDDR5jA== From: "Pankaj Raghav (Samsung)" To: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: mcgrof@kernel.org, gost.dev@samsung.com, akpm@linux-foundation.org, kbusch@kernel.org, djwong@kernel.org, chandan.babu@oracle.com, p.raghav@samsung.com, linux-kernel@vger.kernel.org, hare@suse.de, willy@infradead.org, linux-mm@kvack.org, david@fromorbit.com Subject: [RFC v2 14/14] xfs: enable block size larger than page size support Date: Tue, 13 Feb 2024 10:37:13 +0100 Message-ID: <20240213093713.1753368-15-kernel@pankajraghav.com> In-Reply-To: <20240213093713.1753368-1-kernel@pankajraghav.com> References: <20240213093713.1753368-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: B824080009 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 55kuig4q9x1ztrggxjztz4dkqs5rq61x X-HE-Tag: 1707817090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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: From: Pankaj Raghav Page cache now has the ability to have a minimum order when allocating a folio which is a prerequisite to add support for block size > page size. Enable it in XFS under CONFIG_XFS_LBS. Signed-off-by: Luis Chamberlain Signed-off-by: Pankaj Raghav --- fs/xfs/xfs_icache.c | 8 ++++++-- fs/xfs/xfs_super.c | 8 +++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/fs/xfs/xfs_icache.c b/fs/xfs/xfs_icache.c index dba514a2c84d..9de81caf7ad4 100644 --- a/fs/xfs/xfs_icache.c +++ b/fs/xfs/xfs_icache.c @@ -73,6 +73,7 @@ xfs_inode_alloc( xfs_ino_t ino) { struct xfs_inode *ip; + int min_order = 0; /* * XXX: If this didn't occur in transactions, we could drop GFP_NOFAIL @@ -88,7 +89,8 @@ xfs_inode_alloc( /* VFS doesn't initialise i_mode or i_state! */ VFS_I(ip)->i_mode = 0; VFS_I(ip)->i_state = 0; - mapping_set_large_folios(VFS_I(ip)->i_mapping); + min_order = max(min_order, ilog2(mp->m_sb.sb_blocksize) - PAGE_SHIFT); + mapping_set_folio_orders(VFS_I(ip)->i_mapping, min_order, MAX_PAGECACHE_ORDER); XFS_STATS_INC(mp, vn_active); ASSERT(atomic_read(&ip->i_pincount) == 0); @@ -313,6 +315,7 @@ xfs_reinit_inode( dev_t dev = inode->i_rdev; kuid_t uid = inode->i_uid; kgid_t gid = inode->i_gid; + int min_order = 0; error = inode_init_always(mp->m_super, inode); @@ -323,7 +326,8 @@ xfs_reinit_inode( inode->i_rdev = dev; inode->i_uid = uid; inode->i_gid = gid; - mapping_set_large_folios(inode->i_mapping); + min_order = max(min_order, ilog2(mp->m_sb.sb_blocksize) - PAGE_SHIFT); + mapping_set_folio_orders(inode->i_mapping, min_order, MAX_PAGECACHE_ORDER); return error; } diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c index 5a2512d20bd0..6a3f0f6727eb 100644 --- a/fs/xfs/xfs_super.c +++ b/fs/xfs/xfs_super.c @@ -1625,13 +1625,11 @@ xfs_fs_fill_super( goto out_free_sb; } - /* - * Until this is fixed only page-sized or smaller data blocks work. - */ - if (mp->m_sb.sb_blocksize > PAGE_SIZE) { + if (!IS_ENABLED(CONFIG_XFS_LBS) && mp->m_sb.sb_blocksize > PAGE_SIZE) { xfs_warn(mp, "File system with blocksize %d bytes. " - "Only pagesize (%ld) or less will currently work.", + "Only pagesize (%ld) or less will currently work. " + "Enable Experimental CONFIG_XFS_LBS for this support", mp->m_sb.sb_blocksize, PAGE_SIZE); error = -ENOSYS; goto out_free_sb;