From patchwork Fri Jul 26 11:59:47 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: 13742700 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 75FE1C3DA7F for ; Fri, 26 Jul 2024 12:00:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D32626B00A6; Fri, 26 Jul 2024 08:00:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CBA986B00A9; Fri, 26 Jul 2024 08:00:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B334D6B00A6; Fri, 26 Jul 2024 08:00:16 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 913786B00A4 for ; Fri, 26 Jul 2024 08:00:16 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 52E9712186D for ; Fri, 26 Jul 2024 12:00:16 +0000 (UTC) X-FDA: 82381760832.23.7A4FCEB Received: from mout-p-101.mailbox.org (mout-p-101.mailbox.org [80.241.56.151]) by imf16.hostedemail.com (Postfix) with ESMTP id 6F41818001A for ; Fri, 26 Jul 2024 12:00:13 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=0i2cHUhO; spf=pass (imf16.hostedemail.com: domain of kernel@pankajraghav.com designates 80.241.56.151 as permitted sender) smtp.mailfrom=kernel@pankajraghav.com; dmarc=pass (policy=quarantine) header.from=pankajraghav.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721995188; a=rsa-sha256; cv=none; b=kl38ywRiqT/dJIr20oIVuquOmwG3QhLpgrI600ezNKzz+6QpHuIQ/0ccAFwZzdyDda3OLv UVsK75z5rqCNkaRz31Y1N7bz9dSYuboNp9yTcxcLuuBLZ4pwI+vwl1QOcG9qtJWRxe/1p+ t5eeodyKgk9jdSkOke7sElpm3eXJxLg= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=0i2cHUhO; spf=pass (imf16.hostedemail.com: domain of kernel@pankajraghav.com designates 80.241.56.151 as permitted sender) smtp.mailfrom=kernel@pankajraghav.com; dmarc=pass (policy=quarantine) header.from=pankajraghav.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1721995188; 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=Ufb0UjugC6W3KB84Hi3fjqZ2+tzYpkkK1QUCP+GQMoc=; b=Vbtp1PIvN9TwJLIzIfHXvCrIuy12t9VJXnfWPuX8Cs07eAjjVZ7tkH0iQwxVt0BRfKVi6U iMpQ3BocpKohZd74kTBrsFMpHPEsCTju6tB/FPBMRfKgVJuwIfWyZgetOv40uxbNtxIekO v7sJYj1efceNxPJdlP8t+dxEc1TIZks= 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-101.mailbox.org (Postfix) with ESMTPS id 4WVmXV0jJcz9sSs; Fri, 26 Jul 2024 14:00:10 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1721995210; 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=Ufb0UjugC6W3KB84Hi3fjqZ2+tzYpkkK1QUCP+GQMoc=; b=0i2cHUhOqzjAf+wAofaj0KbVZVTptuFYIhU2MgraqWTKOu/C19Vaumn/RcnCHMmonK/vxF HzNy6imtVzivN9Mar+7UkeAPAigHMU/30CMMS24/Dz3LbnRQSvFMwyakkcMcdOG7hrz6wz o2jwIpZQNcLBfFaq/frp5Yt8kAVX0NXlSDx58sWiPd5NH6frRr58Q0tBdpyD3eo/R4ArI6 TFI2KoBd4gzouAeUU0gXPq2C41tIedKQ9wwgvFsHkLxJUpkSRkuW3K3fhppK7Ms8vHa+3o eCP9/RA2lB6N2NrFa61FeeKHgpflSkjYNnA604Fv4zB/WTo1jmeP5chWLkYO+g== From: "Pankaj Raghav (Samsung)" To: david@fromorbit.com, willy@infradead.org, chandan.babu@oracle.com, djwong@kernel.org, brauner@kernel.org, akpm@linux-foundation.org Cc: yang@os.amperecomputing.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, john.g.garry@oracle.com, linux-fsdevel@vger.kernel.org, hare@suse.de, p.raghav@samsung.com, mcgrof@kernel.org, gost.dev@samsung.com, cl@os.amperecomputing.com, linux-xfs@vger.kernel.org, kernel@pankajraghav.com, ryan.roberts@arm.com, hch@lst.de, Zi Yan Subject: [PATCH v11 01/10] fs: Allow fine-grained control of folio sizes Date: Fri, 26 Jul 2024 13:59:47 +0200 Message-ID: <20240726115956.643538-2-kernel@pankajraghav.com> In-Reply-To: <20240726115956.643538-1-kernel@pankajraghav.com> References: <20240726115956.643538-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Stat-Signature: szh7m45cui6bkjr1a8e31uxak3i4zxwd X-Rspamd-Queue-Id: 6F41818001A X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1721995213-466652 X-HE-Meta: U2FsdGVkX1/HnaSjZ812r3lJBmvkEUkxsaZw9/06stm8HvmmDFTFbfE0JsDfmxgA9hLvaFJvLV390aBO6Lbx+SCEIGJb3iOjEYwYCqTpNn1hOri45Up+0P9Jv9TfeGbyMzkgaIReYJ5OCxytGP20eLlyVjzLcpAeQ0VG1rPnesRB/annYvxyApKLFpVRsqx+b4pAogxrtu/8cLadLhRUp5RAMZZod2D1UCyGGybC8BbATDXzVXkvsjP/mHg0yAt3w0x4u7bmYmGHzomAPJx1N1hpJoHLjxouiJ27SzTubImnRHVKwbrXdleGyMiDe7PWqmYXYamuYnlB8DEgPUYNUhfgDK+zMdtH9DVBL4L/iV/Bzf896ZZSCus3sZn5k4q2pDo7NiS1um4H8znHglSZJcsLfO7pPM7gu6pdJgF4Dn8CllOdlAVe6YC4yFxclf4ucJUSg9v8z9ERnBhcrLpofZaNNlhrnB8KVthgyPzQx+hlY32lk2ilKod2jwDtpQ2EtjAKjFdfPq7RZis87xC4FvO1sgH4kz9Dsr8uSHSEHoJNvEOMA4NzlHaHKRrkg/cz5m1JTCRxd74la2Yks/Co0C/9bBvTQlZk3JUIWrsHadgom6/oYsLAOgQPgCYH4jL4gMZhcbYdfY6Ivc6uFWhNJI9MsHSJiuJmsDPTzyT/i7I+lpXq+BP1qI0Q4Awy8Ig6pYXElR4VBTAWuL25uU+cQX/WxY9LWArEWNzQ2zP8lljKfLUGYFnacLHuko8mQHyrVL3FMwB67BkpujkBgE+kk2J8W/7cZbMe+KSSxJoB3kyeMyPaAslYyyA2OJs292Bf6uTFsW/RASJdjq0OmgX3TYM2UPNYUjI2p1Uge0bWKj2SSBQf0e5eAfrjfTHesSEN5VDURh9yWzDMhR3jVR9wn4HOjfONKq7JLuB9c3lfwT3ASgLU85bL5L31V6QbNOW45gr7kwr8ApNrZ5bJ14Y lkFsFvaE PsMzMNE86VYRk4t6kOr4i2rf7Q7yVEfJVLhfawu6h1YRsVAbaEZ6rGnQFaSbU2tGyYDTQkNA5hzdEIbnYyFxGI8St2dT+C4kqNg4XKJvvRoKl3MtXeV1NjOj7+Lm0K81oSKc8gDK1JPwAmAQUtgykt9DSTPdSZr6jxIs4svd8q6Z73y6QhzOqpxXwzV4y7LhIhKdhiUVNn2qwzdTiqXQVmZ1wGp6kqjUMGN7XPzPtHIqtlLNkjaJXBqYG4hBFjjiX5LZ95nXWZYdpyLmi/B0uDpU8yNNe/C9YYPbRy2wJyIUpCgEkRauO5t2EyW6aqHFICYW7E8G3YTLybo8LEMHi92O7ogjCQPSqdYRNZGaMLrgXu5M= 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)" We need filesystems to be able to communicate acceptable folio sizes to the pagecache for a variety of uses (e.g. large block sizes). Support a range of folio sizes between order-0 and order-31. Signed-off-by: Matthew Wilcox (Oracle) Co-developed-by: Pankaj Raghav Signed-off-by: Pankaj Raghav Reviewed-by: Hannes Reinecke Reviewed-by: Darrick J. Wong --- include/linux/pagemap.h | 89 ++++++++++++++++++++++++++++++++++------- mm/filemap.c | 6 +-- mm/readahead.c | 4 +- 3 files changed, 79 insertions(+), 20 deletions(-) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index d9c7edb6422bd..75bbe88b89904 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -204,14 +204,20 @@ 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_INACCESSIBLE, /* Do not attempt direct R/W access to the mapping, - including to move the mapping */ + AS_INACCESSIBLE = 8, /* Do not attempt direct R/W access to the mapping */ + /* Bits 16-25 are used for FOLIO_ORDER */ + AS_FOLIO_ORDER_BITS = 5, + AS_FOLIO_ORDER_MIN = 16, + AS_FOLIO_ORDER_MAX = AS_FOLIO_ORDER_MIN + AS_FOLIO_ORDER_BITS, }; +#define AS_FOLIO_ORDER_MASK ((1u << AS_FOLIO_ORDER_BITS) - 1) +#define AS_FOLIO_ORDER_MIN_MASK (AS_FOLIO_ORDER_MASK << AS_FOLIO_ORDER_MIN) +#define AS_FOLIO_ORDER_MAX_MASK (AS_FOLIO_ORDER_MASK << AS_FOLIO_ORDER_MAX) + /** * mapping_set_error - record a writeback error in the address_space * @mapping: the mapping in which an error should be set @@ -367,9 +373,51 @@ static inline void mapping_set_gfp_mask(struct address_space *m, gfp_t mask) #define MAX_XAS_ORDER (XA_CHUNK_SHIFT * 2 - 1) #define MAX_PAGECACHE_ORDER min(MAX_XAS_ORDER, PREFERRED_MAX_PAGECACHE_ORDER) +/* + * mapping_set_folio_order_range() - Set the orders supported by a file. + * @mapping: The address space of the file. + * @min: Minimum folio order (between 0-MAX_PAGECACHE_ORDER inclusive). + * @max: Maximum folio order (between @min-MAX_PAGECACHE_ORDER inclusive). + * + * The filesystem should call this function in its inode constructor to + * indicate which base size (min) and maximum size (max) of folio the VFS + * can use to cache the contents of the file. This should only be used + * if the filesystem needs special handling of folio sizes (ie there is + * something the core cannot know). + * Do not tune it based on, eg, i_size. + * + * Context: This should not be called while the inode is active as it + * is non-atomic. + */ +static inline void mapping_set_folio_order_range(struct address_space *mapping, + unsigned int min, + unsigned int max) +{ + if (!IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE)) + return; + + if (min > MAX_PAGECACHE_ORDER) + min = MAX_PAGECACHE_ORDER; + + if (max > MAX_PAGECACHE_ORDER) + max = MAX_PAGECACHE_ORDER; + + if (max < min) + max = min; + + mapping->flags = (mapping->flags & ~AS_FOLIO_ORDER_MASK) | + (min << AS_FOLIO_ORDER_MIN) | (max << AS_FOLIO_ORDER_MAX); +} + +static inline void mapping_set_folio_min_order(struct address_space *mapping, + unsigned int min) +{ + mapping_set_folio_order_range(mapping, min, MAX_PAGECACHE_ORDER); +} + /** * mapping_set_large_folios() - Indicate the file supports large folios. - * @mapping: The file. + * @mapping: The address space of the file. * * The filesystem should call this function in its inode constructor to * indicate that the VFS can use large folios to cache the contents of @@ -380,7 +428,23 @@ static inline void mapping_set_gfp_mask(struct address_space *m, gfp_t mask) */ static inline void mapping_set_large_folios(struct address_space *mapping) { - __set_bit(AS_LARGE_FOLIO_SUPPORT, &mapping->flags); + mapping_set_folio_order_range(mapping, 0, MAX_PAGECACHE_ORDER); +} + +static inline unsigned int +mapping_max_folio_order(const struct address_space *mapping) +{ + if (!IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE)) + return 0; + return (mapping->flags & AS_FOLIO_ORDER_MAX_MASK) >> AS_FOLIO_ORDER_MAX; +} + +static inline unsigned int +mapping_min_folio_order(const struct address_space *mapping) +{ + if (!IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE)) + return 0; + return (mapping->flags & AS_FOLIO_ORDER_MIN_MASK) >> AS_FOLIO_ORDER_MIN; } /* @@ -389,20 +453,17 @@ static inline void mapping_set_large_folios(struct address_space *mapping) */ static inline bool mapping_large_folio_support(struct address_space *mapping) { - /* AS_LARGE_FOLIO_SUPPORT is only reasonable for pagecache folios */ + /* AS_FOLIO_ORDER is only reasonable for pagecache folios */ VM_WARN_ONCE((unsigned long)mapping & PAGE_MAPPING_ANON, "Anonymous mapping always supports large folio"); - return IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE) && - test_bit(AS_LARGE_FOLIO_SUPPORT, &mapping->flags); + return mapping_max_folio_order(mapping) > 0; } /* Return the maximum folio size for this pagecache mapping, in bytes. */ -static inline size_t mapping_max_folio_size(struct address_space *mapping) +static inline size_t mapping_max_folio_size(const struct address_space *mapping) { - if (mapping_large_folio_support(mapping)) - return PAGE_SIZE << MAX_PAGECACHE_ORDER; - return PAGE_SIZE; + return PAGE_SIZE << mapping_max_folio_order(mapping); } static inline int filemap_nr_thps(struct address_space *mapping) diff --git a/mm/filemap.c b/mm/filemap.c index d62150418b910..ad5e4a848070e 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -1933,10 +1933,8 @@ struct folio *__filemap_get_folio(struct address_space *mapping, pgoff_t index, if (WARN_ON_ONCE(!(fgp_flags & (FGP_LOCK | FGP_FOR_MMAP)))) fgp_flags |= FGP_LOCK; - if (!mapping_large_folio_support(mapping)) - order = 0; - if (order > MAX_PAGECACHE_ORDER) - order = MAX_PAGECACHE_ORDER; + if (order > mapping_max_folio_order(mapping)) + order = mapping_max_folio_order(mapping); /* If we're not aligned, allocate a smaller folio */ if (index & ((1UL << order) - 1)) order = __ffs(index); diff --git a/mm/readahead.c b/mm/readahead.c index 517c0be7ce665..3e5239e9e1777 100644 --- a/mm/readahead.c +++ b/mm/readahead.c @@ -449,10 +449,10 @@ void page_cache_ra_order(struct readahead_control *ractl, limit = min(limit, index + ra->size - 1); - if (new_order < MAX_PAGECACHE_ORDER) + if (new_order < mapping_max_folio_order(mapping)) new_order += 2; - new_order = min_t(unsigned int, MAX_PAGECACHE_ORDER, new_order); + new_order = min(mapping_max_folio_order(mapping), new_order); new_order = min_t(unsigned int, new_order, ilog2(ra->size)); /* See comment in page_cache_ra_unbounded() */ From patchwork Fri Jul 26 11:59:48 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: 13742701 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 A5380C3DA7F for ; Fri, 26 Jul 2024 12:00:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 011876B00A9; Fri, 26 Jul 2024 08:00:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F03B26B00AA; Fri, 26 Jul 2024 08:00:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D7F696B00AB; Fri, 26 Jul 2024 08:00:22 -0400 (EDT) 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 ADB746B00A9 for ; Fri, 26 Jul 2024 08:00:22 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 1274A1617FF for ; Fri, 26 Jul 2024 12:00:22 +0000 (UTC) X-FDA: 82381761084.24.5FD85AD Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [80.241.56.172]) by imf01.hostedemail.com (Postfix) with ESMTP id 9C0154000D for ; Fri, 26 Jul 2024 12:00:19 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=FT5iL9QN; spf=pass (imf01.hostedemail.com: domain of kernel@pankajraghav.com designates 80.241.56.172 as permitted sender) smtp.mailfrom=kernel@pankajraghav.com; dmarc=pass (policy=quarantine) header.from=pankajraghav.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1721995195; 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=deQPnnwd6TDzRj/A268eQqMo7O4raj6JQhQivX0nI/U=; b=heW3sHI89UE7Ez/Uw8s9L0jVBXywl49o4608vp4I7lW+xfpHQWTTGfbkIaa16/AACzRBrf ZpDCmishH0tiFY4BE+cQdOUKyv3OR1Xumts7jiEi0FouDueEcYKpu/ka+c0jZbU5VLagEv 33jUK+mHbKB1hyUOAR4vDaKeOZOY1II= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=FT5iL9QN; spf=pass (imf01.hostedemail.com: domain of kernel@pankajraghav.com designates 80.241.56.172 as permitted sender) smtp.mailfrom=kernel@pankajraghav.com; dmarc=pass (policy=quarantine) header.from=pankajraghav.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721995195; a=rsa-sha256; cv=none; b=Xb0GM9Ax0XcLTGm697Te74nTBi5Ii/ZNRIWjJlqfQI/3Ou78jOJTkShTbyiw5EX172PDBT NucHcen6QFqhbL4EiHsSCgkV1p0okpGWJw7d7Qg7PMIP6G67rhOjGsQy9ZMuqiJ3wvA5dC FmWOO2SbsY/r7yz6ZIhvrTxovcokmTc= 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-202.mailbox.org (Postfix) with ESMTPS id 4WVmXZ2yfvz9t5k; Fri, 26 Jul 2024 14:00:14 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1721995214; 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=deQPnnwd6TDzRj/A268eQqMo7O4raj6JQhQivX0nI/U=; b=FT5iL9QN/v9EXF+rksj3tSAbWcJwXkYgSvV3GM6fcW2n6dMSgjEZ9H+ImoP+KySY4TgPeg MRNyoYgh6AYlpch7HLKG3z9v2XzT059u7m/7wqC/kwv6YdlguxYP0JnSRaRgkiHaUenVuc +jxDZWzzMk3qTottcCJt8V6Q82cY+mNzI9rPD6GiOLoPGUesqbDoXN3yUvV+EcuQR0DMPk UdDflMdJyTXG+Ba5cm6R+0ZahTzUb9FVikHzHIAB48qyHIW9TIZ4kOfBLgyRVM++USEAgd 72JYL6K7ER8VlQzoFhpIQmnXoZDcbm0Ux+AjLem8yMHxBZzJbJJqxrlHMTn2Nw== From: "Pankaj Raghav (Samsung)" To: david@fromorbit.com, willy@infradead.org, chandan.babu@oracle.com, djwong@kernel.org, brauner@kernel.org, akpm@linux-foundation.org Cc: yang@os.amperecomputing.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, john.g.garry@oracle.com, linux-fsdevel@vger.kernel.org, hare@suse.de, p.raghav@samsung.com, mcgrof@kernel.org, gost.dev@samsung.com, cl@os.amperecomputing.com, linux-xfs@vger.kernel.org, kernel@pankajraghav.com, ryan.roberts@arm.com, hch@lst.de, Zi Yan Subject: [PATCH v11 02/10] filemap: allocate mapping_min_order folios in the page cache Date: Fri, 26 Jul 2024 13:59:48 +0200 Message-ID: <20240726115956.643538-3-kernel@pankajraghav.com> In-Reply-To: <20240726115956.643538-1-kernel@pankajraghav.com> References: <20240726115956.643538-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 9C0154000D X-Stat-Signature: 1unsjzbft8ojbn9dtsp14qnf7pdz1gba X-HE-Tag: 1721995219-767844 X-HE-Meta: U2FsdGVkX193iG5Td679LbJqOvjlHxt6qSqyh0zWeDGu+U2nGgXCjtKMStiOUrZ7FDgu5/1LvtlcOIxXoyCbR+0IjzIUSgsP4gBsYdIXYp+r9sxrdb1GQmzc/sWylWpvku1HFuVHeqY0ex/HyWw/qK+n89cmiOrfl7PG8Tfn+cuA1/i/AoZJ2JCUSP4bvz0rtueOko+n2ekyRyEzY4zcY3z+H2BWSrFINhSEKuXJ6wGh3c3VkwonNYxKLSW3JjeGCliAE+obqPvs/EF94ga6vyN1PFFA4+p9qgkWwYEcpMPVmQwIKTc4KNZ8WCbsm+y6XvXsjwgqSV0U6eil+pYd7Qg8sz0yOTuotBbQcExWHZ6PU3N/poHZGFO3V4y/e8TQd53Y6pT8vjLUyoKPCqUuflrWgIxDuoU4VP11xxSOLEojp4csdEkjlKvzmpSYb8Bfs3vNYbfEjAtvVtjJuDNTRXoiGmh4y8ddyHxFo3ZBiUJ6fowdAJhzsNMgWWGA9BJdJX2JZjpcZG41gW5gDOtWgIGEuk0t/1lyqPmb9XUOuM+iUKSYDjx49pcBbJyFA/25NpF3SmMiBB2j3h9o+/YJG/UJHU+I+h4cBREsa0fRVLb8ruT1MU3r7bgQVMXaeo5qtmuCcrlsWBYZmBwCPHzYAvbSN/CjLWURBSuXmjzTvUU3NaoSVr++HHQVB/5PNHWDWUV4z7VRiD5j+TKPXs09z3d6kzuAVIM/PeIc1HsFzby14QmXdBYZz/Gl9lJqVjAxiGNJTFf12SN7n7D79LtCBfAK+33pMLNXnsFRwEHfgjUDREKUj8N/QDX1c4ct742F0SQMDqQhcgyN5nbCEMKKP6PsIztDXZmXWi7pwqTIeO5lwy6AfGoiyhouw7fD5XZ1pKIK3q+Ch3bGrOhvS3zoPGu3YRDoEH0rvk6M4tRS0KFEwJaWtQ6x4X39i1VkyBzE7NyDb/f3v4yU7mNVIHT i3l384rn oQMCrgHRK9gp2J+MNsipZEcBM0X6iZtsDN8duATLizlqb+DiLFv7CkHUKMbZASzUongaSN/V20SlTUaibS8qK0WTnl5BVDAaSBeFdgeBTlLyb+9MGzo4fKni4Q9TxMDM/XCVdvku3l89bZ/s0/4VlinQ8iglAv3JnUQI/iCuPK1wN2loVW3827Ml+9+pTM/W4bEa17uGLpi6LfgLQAhNp9CYZ2P0AxIhOsjqiYsiLWkdThjYufrUyFdy1/h4u694cDDp9QbhibqEhkFrbEq6bjVla+aWaYGSC/rDU9jMrs6Zm+ZBbHF+kMRYKJiQUtNKnPCyyBiMyaK6afQJhlPB816+wMFGPWlLAS6x0qlYXHqCtKywkjrDDAi3/8rI/P76+Xo1CBeG/B6QhGZzSYffjxJIQca3z0gy6miEC+urCpBdcaDDF1GLc5I6L0Eu2UoCQmD8gt7nlf01z4rh96L7tgvv/Xh4G5CpDjT864nvPLZl73lM1U1NLG2KB9KsQSU8QeaVN 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. Supporting mapping_min_order implies that we guarantee each folio in the page cache has at least an order of mapping_min_order. When adding new folios to the page cache we must also 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. Co-developed-by: Luis Chamberlain Signed-off-by: Luis Chamberlain Signed-off-by: Pankaj Raghav Reviewed-by: Hannes Reinecke Reviewed-by: Darrick J. Wong Reviewed-by: Matthew Wilcox (Oracle) --- include/linux/pagemap.h | 20 ++++++++++++++++++++ mm/filemap.c | 24 ++++++++++++++++-------- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index 75bbe88b89904..3a876d6801a90 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -447,6 +447,26 @@ mapping_min_folio_order(const struct address_space *mapping) return (mapping->flags & AS_FOLIO_ORDER_MIN_MASK) >> AS_FOLIO_ORDER_MIN; } +static inline unsigned long +mapping_min_folio_nrpages(struct address_space *mapping) +{ + return 1UL << mapping_min_folio_order(mapping); +} + +/** + * mapping_align_index() - Align index for this mapping. + * @mapping: The address_space. + * + * The index of a folio must be naturally aligned. If you are adding a + * new folio to the page cache and need to know what index to give it, + * call this function. + */ +static inline pgoff_t mapping_align_index(struct address_space *mapping, + pgoff_t index) +{ + return round_down(index, mapping_min_folio_nrpages(mapping)); +} + /* * Large folio support currently depends on THP. These dependencies are * being worked on but are not yet fixed. diff --git a/mm/filemap.c b/mm/filemap.c index ad5e4a848070e..d27e9ac54309d 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -859,6 +859,8 @@ noinline int __filemap_add_folio(struct address_space *mapping, VM_BUG_ON_FOLIO(!folio_test_locked(folio), folio); VM_BUG_ON_FOLIO(folio_test_swapbacked(folio), folio); + VM_BUG_ON_FOLIO(folio_order(folio) < mapping_min_folio_order(mapping), + folio); mapping_set_update(&xas, mapping); VM_BUG_ON_FOLIO(index & (folio_nr_pages(folio) - 1), folio); @@ -1919,8 +1921,10 @@ 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 min_order = mapping_min_folio_order(mapping); + unsigned int order = max(min_order, FGF_GET_ORDER(fgp_flags)); int err; + index = mapping_align_index(mapping, index); if ((fgp_flags & FGP_WRITE) && mapping_can_writeback(mapping)) gfp |= __GFP_WRITE; @@ -1943,7 +1947,7 @@ struct folio *__filemap_get_folio(struct address_space *mapping, pgoff_t index, gfp_t alloc_gfp = gfp; err = -ENOMEM; - if (order > 0) + if (order > min_order) alloc_gfp |= __GFP_NORETRY | __GFP_NOWARN; folio = filemap_alloc_folio(alloc_gfp, order); if (!folio) @@ -1958,7 +1962,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; @@ -2447,13 +2451,15 @@ static int filemap_update_page(struct kiocb *iocb, } static int filemap_create_folio(struct file *file, - struct address_space *mapping, pgoff_t index, + struct address_space *mapping, loff_t pos, struct folio_batch *fbatch) { struct folio *folio; int error; + unsigned int min_order = mapping_min_folio_order(mapping); + pgoff_t index; - folio = filemap_alloc_folio(mapping_gfp_mask(mapping), 0); + folio = filemap_alloc_folio(mapping_gfp_mask(mapping), min_order); if (!folio) return -ENOMEM; @@ -2471,6 +2477,7 @@ static int filemap_create_folio(struct file *file, * well to keep locking rules simple. */ filemap_invalidate_lock_shared(mapping); + index = (pos >> (PAGE_SHIFT + min_order)) << min_order; error = filemap_add_folio(mapping, folio, index, mapping_gfp_constraint(mapping, GFP_KERNEL)); if (error == -EEXIST) @@ -2531,8 +2538,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, iocb->ki_pos, fbatch); if (err == AOP_TRUNCATED_PAGE) goto retry; return err; @@ -3748,9 +3754,11 @@ 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); + index = mapping_align_index(mapping, index); err = filemap_add_folio(mapping, folio, index, gfp); if (unlikely(err)) { folio_put(folio); From patchwork Fri Jul 26 11:59:49 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: 13742702 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 F0F86C3DA49 for ; Fri, 26 Jul 2024 12:00:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3965C6B00AA; Fri, 26 Jul 2024 08:00:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 31E9A6B00AB; Fri, 26 Jul 2024 08:00:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 16FD26B00AC; Fri, 26 Jul 2024 08:00:25 -0400 (EDT) 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 DF3296B00AA for ; Fri, 26 Jul 2024 08:00:24 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 8B854417F6 for ; Fri, 26 Jul 2024 12:00:24 +0000 (UTC) X-FDA: 82381761168.21.5E2EB23 Received: from mout-p-101.mailbox.org (mout-p-101.mailbox.org [80.241.56.151]) by imf11.hostedemail.com (Postfix) with ESMTP id 9BFB540007 for ; Fri, 26 Jul 2024 12:00:22 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=vn9UpSWj; spf=pass (imf11.hostedemail.com: domain of kernel@pankajraghav.com designates 80.241.56.151 as permitted sender) smtp.mailfrom=kernel@pankajraghav.com; dmarc=pass (policy=quarantine) header.from=pankajraghav.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1721995156; 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=+r0q1aMOVXTo8fjQ8nnAWfzQgFhULOwQhra2cgoZxE8=; b=QsMeRQ5PugWPxKPMK0RD2qKOdtmzp42kUNwsYMXdhvK6sR5wAxP65R1vS2NRtkPu1ig1Q2 +FkCpY+Kf0oTX7ukImljy8saJylclDP9V0qtEhqFhnqMBUEMghYfnW+nbx2ROezeiyU8my YerH1Y+mp8ET12y4k9yK6DkKYlYtMJg= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=vn9UpSWj; spf=pass (imf11.hostedemail.com: domain of kernel@pankajraghav.com designates 80.241.56.151 as permitted sender) smtp.mailfrom=kernel@pankajraghav.com; dmarc=pass (policy=quarantine) header.from=pankajraghav.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721995156; a=rsa-sha256; cv=none; b=bS2NXvqVgBXf0lI3tKT3A98QAsHUCdacf3j947kRaud40E02C2t3kETWMBWXT9sG7Qvo6G Nfgh866SRhhhEaI/bU6auHaZLFeQGl+XZg54fLsBBD1BtEF4a9l+bywwPAuda6QDZQWd1m /JoKjrAzRdm0ZoxI2RKKhzBs3mlsWCA= 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-101.mailbox.org (Postfix) with ESMTPS id 4WVmXg21h0z9sbL; Fri, 26 Jul 2024 14:00:19 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1721995219; 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=+r0q1aMOVXTo8fjQ8nnAWfzQgFhULOwQhra2cgoZxE8=; b=vn9UpSWjQnJToJQ7MgvGmCbdIjddckWODqQGbZPTylDwxHKMk9MXVR61Qq5VmVG3p+P7aD p7sCN8oJRuQhZSxuwZFxkDZf+SEJPSwBdWveJYsJl602XwnFTf0+gItBPXTnzTKIyYVQuk 31EoyZ69rRBYcJQVnJE5diO8vYbHHfVSkPbwkVfqWNcNedBQZJTREruAhGuiDKCtU2qiOa pqym1ALogrgFsCO+IwniBBWTXPnS6K8nx33ZJH6nsPiSxnji4BtimUWwke01ulb3ezIwx3 Ag2VS/vF7dWywBDZrBykQiDqLYIiA/L/TEOdven9iu8VKXa+3k95y0UlNqApWA== From: "Pankaj Raghav (Samsung)" To: david@fromorbit.com, willy@infradead.org, chandan.babu@oracle.com, djwong@kernel.org, brauner@kernel.org, akpm@linux-foundation.org Cc: yang@os.amperecomputing.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, john.g.garry@oracle.com, linux-fsdevel@vger.kernel.org, hare@suse.de, p.raghav@samsung.com, mcgrof@kernel.org, gost.dev@samsung.com, cl@os.amperecomputing.com, linux-xfs@vger.kernel.org, kernel@pankajraghav.com, ryan.roberts@arm.com, hch@lst.de, Zi Yan Subject: [PATCH v11 03/10] readahead: allocate folios with mapping_min_order in readahead Date: Fri, 26 Jul 2024 13:59:49 +0200 Message-ID: <20240726115956.643538-4-kernel@pankajraghav.com> In-Reply-To: <20240726115956.643538-1-kernel@pankajraghav.com> References: <20240726115956.643538-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 9BFB540007 X-Stat-Signature: 1s4149811495j8cei3iir6k3iexpmtqr X-Rspam-User: X-HE-Tag: 1721995222-247745 X-HE-Meta: U2FsdGVkX18ESiEl5URKYVnWM5KMqHd0u6xRK2X+qFYxTwgspcI/FDOckWgPaULJgyrQ5lyCaRBYoTmo5BFFY1x9v70GaJNHVoNKEjJH3yTpaPU+esY/SqbTDFqFy27M9lDkJOk31CX4yoLHlEltHiYU2ntc3m2vcOWYWZe9BMTq8mY2G7JfKIiogeEU20Agdy5yATlftZ+CSwgl2stqPJw5j1sE7G1Yr/5iekip9zwzlvGh63Ryb7nPUUU9mni11IiHsCuMB7fCJoOfk6jQuRMltjDpXUfTTjhUWe085CGr/QAeK18StvbKtnepV4k+FjerS+s/E2FL8qdfIujHhnRVgMo3J0rrvlUXZrbyyss2EWPPGTPRyRmOHZ8hA7GfgDECTdaInqlekDaf/ILDXGgnYSoPoO6YjEIsTzjAbYgxYxATyXbL1dg2nkwkELpktgNOPodoGbRX3WWeMRI5/yucpWqKt0wEYRQoakAAO4LuRnp6si3cltBVsq2RT+JIpoat3Z7mEDri4AarBs3xsk4zUemcoplRfKfSIizI8Qr1RUTOK+fypTUqcOJ7KrHYEsyvSy3xgzFjQiskHjoHY6jrZ/JWXrimkkPt/67MWIti1BydrVGdWk0+FsSJDcmeYKdsBNFjh8Ld/RnGJo2pm4AE48o9vv8LF7SmOflWsfIX9+G4zd0GKfzbtKrPIPgAxhySBHJH+sMTwGqjhU3OsbUG3WU38FmTUl4bB44npnnvUgEw9DAF56hs1sMgZp/AnaPRK7CgOjKfoXFAR8NE73KutIJtonRAzTZmOVTVHDZLI8BzVkwwOW2o7hdq1EQSZBfplWdZimGUqc6WXbR5QGdwrKecGpcpgqp3Zx7vUzkdza9xn+6tGfwyfCK4NrJ3LYDCc90xZyHmi+tLLnWhmng03DzxVGqyBiPVPnf29Co+oGvJ/SAxLeOfd7Dd6sjFxYZdcCD3I53X8NsZjN2 pczXwYfy acjuX4/qgp1nCmz9jBIVvjTiEPGappiRoVVR3fe0ZXkJNPuOw6YJkLkGEHTMNbaNO8Lc93DL3/SqiSt0V1DvJaEFqQiMkTpHcn9+jUE6ycCxd2GoqNi9NtAH0F2OlhJU7uDltqYHtCNMEOcO0IKz9hUUtMN4sUH8wq3ssrbG+tyFrzYGi+QhbOJxfmIIkJlQpGZIMpUOCwGONrLJWp9iknz8YcqdeZK9g6uqXfZqojnaG1mQpo/inHfMoMQgefmXEWktzrIeam/tPlpXF1rIscPMu8aYtYA8NBrA3Hc7Sf/kYHUIwI/rkNaUH1PkWdIsMJJAwQgv3sCe0AOP1YyoTHeYbxqAM9XZT00Iu 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 page_cache_ra_unbounded() was allocating single pages (0 order folios) if there was no folio found in an index. Allocate mapping_min_order folios as we need to guarantee the minimum order if it is set. page_cache_ra_order() tries to allocate folio to the page cache with a higher order if the index aligns with that order. Modify it so that the order does not go below the mapping_min_order requirement of the page cache. This function will do the right thing even if the new_order passed is less than the mapping_min_order. When adding new folios to the page cache we must also 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. readahead_expand() is called from readahead aops to extend the range of the readahead so this function can assume ractl->_index to be aligned with min_order. Signed-off-by: Pankaj Raghav Co-developed-by: Hannes Reinecke Signed-off-by: Hannes Reinecke Acked-by: Darrick J. Wong --- mm/readahead.c | 79 ++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 61 insertions(+), 18 deletions(-) diff --git a/mm/readahead.c b/mm/readahead.c index 3e5239e9e1777..2078c42777a62 100644 --- a/mm/readahead.c +++ b/mm/readahead.c @@ -206,9 +206,10 @@ void page_cache_ra_unbounded(struct readahead_control *ractl, unsigned long nr_to_read, unsigned long lookahead_size) { struct address_space *mapping = ractl->mapping; - unsigned long index = readahead_index(ractl); + unsigned long ra_folio_index, index = readahead_index(ractl); gfp_t gfp_mask = readahead_gfp_mask(mapping); - unsigned long i; + unsigned long mark, i = 0; + unsigned int min_nrpages = mapping_min_folio_nrpages(mapping); /* * Partway through the readahead operation, we will have added @@ -223,10 +224,24 @@ void page_cache_ra_unbounded(struct readahead_control *ractl, unsigned int nofs = memalloc_nofs_save(); filemap_invalidate_lock_shared(mapping); + index = mapping_align_index(mapping, index); + + /* + * As iterator `i` is aligned to min_nrpages, round_up the + * difference between nr_to_read and lookahead_size to mark the + * index that only has lookahead or "async_region" to set the + * readahead flag. + */ + ra_folio_index = round_up(readahead_index(ractl) + nr_to_read - lookahead_size, + min_nrpages); + mark = ra_folio_index - index; + nr_to_read += readahead_index(ractl) - index; + ractl->_index = index; + /* * 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); int ret; @@ -240,12 +255,13 @@ 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 += min_nrpages; + 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; @@ -255,14 +271,15 @@ void page_cache_ra_unbounded(struct readahead_control *ractl, if (ret == -ENOMEM) break; read_pages(ractl); - ractl->_index++; - i = ractl->_index + ractl->_nr_pages - index - 1; + ractl->_index += min_nrpages; + i = ractl->_index + ractl->_nr_pages - index; continue; } - if (i == nr_to_read - lookahead_size) + if (i == mark) folio_set_readahead(folio); ractl->_workingset |= folio_test_workingset(folio); - ractl->_nr_pages++; + ractl->_nr_pages += min_nrpages; + i += min_nrpages; } /* @@ -438,13 +455,19 @@ void page_cache_ra_order(struct readahead_control *ractl, struct address_space *mapping = ractl->mapping; pgoff_t start = readahead_index(ractl); pgoff_t index = start; + 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; unsigned int nofs; int err = 0; gfp_t gfp = readahead_gfp_mask(mapping); + unsigned int min_ra_size = max(4, mapping_min_folio_nrpages(mapping)); - if (!mapping_large_folio_support(mapping) || ra->size < 4) + /* + * Fallback when size < min_nrpages as each folio should be + * at least min_nrpages anyway. + */ + if (!mapping_large_folio_support(mapping) || ra->size < min_ra_size) goto fallback; limit = min(limit, index + ra->size - 1); @@ -454,10 +477,19 @@ void page_cache_ra_order(struct readahead_control *ractl, new_order = min(mapping_max_folio_order(mapping), new_order); new_order = min_t(unsigned int, new_order, ilog2(ra->size)); + new_order = max(new_order, min_order); /* See comment in page_cache_ra_unbounded() */ nofs = memalloc_nofs_save(); filemap_invalidate_lock_shared(mapping); + /* + * If the new_order is greater than min_order and index is + * already aligned to new_order, then this will be noop as index + * aligned to new_order should also be aligned to min_order. + */ + ractl->_index = mapping_align_index(mapping, index); + index = readahead_index(ractl); + while (index <= limit) { unsigned int order = new_order; @@ -465,7 +497,7 @@ 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--; err = ra_alloc_folio(ractl, index, mark, order, gfp); if (err) @@ -703,8 +735,15 @@ void readahead_expand(struct readahead_control *ractl, struct file_ra_state *ra = ractl->ra; pgoff_t new_index, new_nr_pages; gfp_t gfp_mask = readahead_gfp_mask(mapping); + unsigned long min_nrpages = mapping_min_folio_nrpages(mapping); + unsigned int min_order = mapping_min_folio_order(mapping); new_index = new_start / PAGE_SIZE; + /* + * Readahead code should have aligned the ractl->_index to + * min_nrpages before calling readahead aops. + */ + VM_BUG_ON(!IS_ALIGNED(ractl->_index, min_nrpages)); /* Expand the leading edge downwards */ while (ractl->_index > new_index) { @@ -714,9 +753,11 @@ void readahead_expand(struct readahead_control *ractl, if (folio && !xa_is_value(folio)) return; /* Folio apparently present */ - folio = filemap_alloc_folio(gfp_mask, 0); + folio = filemap_alloc_folio(gfp_mask, min_order); if (!folio) return; + + index = mapping_align_index(mapping, index); if (filemap_add_folio(mapping, folio, index, gfp_mask) < 0) { folio_put(folio); return; @@ -726,7 +767,7 @@ void readahead_expand(struct readahead_control *ractl, ractl->_workingset = true; psi_memstall_enter(&ractl->_pflags); } - ractl->_nr_pages++; + ractl->_nr_pages += min_nrpages; ractl->_index = folio->index; } @@ -741,9 +782,11 @@ void readahead_expand(struct readahead_control *ractl, if (folio && !xa_is_value(folio)) return; /* Folio apparently present */ - folio = filemap_alloc_folio(gfp_mask, 0); + folio = filemap_alloc_folio(gfp_mask, min_order); if (!folio) return; + + index = mapping_align_index(mapping, index); if (filemap_add_folio(mapping, folio, index, gfp_mask) < 0) { folio_put(folio); return; @@ -753,10 +796,10 @@ void readahead_expand(struct readahead_control *ractl, ractl->_workingset = true; psi_memstall_enter(&ractl->_pflags); } - ractl->_nr_pages++; + ractl->_nr_pages += min_nrpages; if (ra) { - ra->size++; - ra->async_size++; + ra->size += min_nrpages; + ra->async_size += min_nrpages; } } } From patchwork Fri Jul 26 11:59:50 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: 13742703 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 6D086C3DA7F for ; Fri, 26 Jul 2024 12:00:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EDFB76B00AD; Fri, 26 Jul 2024 08:00:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E8E316B00AE; Fri, 26 Jul 2024 08:00:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D2F186B00AF; Fri, 26 Jul 2024 08:00:30 -0400 (EDT) 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 B47EC6B00AD for ; Fri, 26 Jul 2024 08:00:30 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 56787C17E7 for ; Fri, 26 Jul 2024 12:00:30 +0000 (UTC) X-FDA: 82381761420.02.A313116 Received: from mout-p-201.mailbox.org (mout-p-201.mailbox.org [80.241.56.171]) by imf14.hostedemail.com (Postfix) with ESMTP id EDA96100026 for ; Fri, 26 Jul 2024 12:00:26 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=ebxtZ3WP; spf=pass (imf14.hostedemail.com: domain of kernel@pankajraghav.com designates 80.241.56.171 as permitted sender) smtp.mailfrom=kernel@pankajraghav.com; dmarc=pass (policy=quarantine) header.from=pankajraghav.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1721995188; 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=H7rWLiCMk4lxgxSKZFr+zzX4eLbJPbbhmvYIIxBW16M=; b=KjDxoMR85KvfngxrH4mYGimz/ZWhWJ98F6kV5q+d1I2sUxsD0lxWk4+J8lFhTG7KCIotcL q3Y7aRcIyce8fUCKNA9/QX5POTAvxqDHV7ctXybqVO4y7QFCSv976E2vThiPevIFLv0SiX z295leUutmHgxfV2L0SavqI4wJhwy1U= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=ebxtZ3WP; spf=pass (imf14.hostedemail.com: domain of kernel@pankajraghav.com designates 80.241.56.171 as permitted sender) smtp.mailfrom=kernel@pankajraghav.com; dmarc=pass (policy=quarantine) header.from=pankajraghav.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721995188; a=rsa-sha256; cv=none; b=qDfVFjH8NQJdiyNPSaZP+Yp/7LMKyLx9rO8QcNd5Nmdk8rhqWUNGxFYpjKgTYdz3fnJ3Mc vM/NohpYXf9YctWLbU4Az8MTWmjJBhEJsCEFJQeXyzxw27q5vCoIAHEGk4ZimdOmbc3/0d ISPVcW0ESucCIhIxZ0KsIhIQ8K5zcQ8= 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 4WVmXl1b8kz9t3P; Fri, 26 Jul 2024 14:00:23 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1721995223; 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=H7rWLiCMk4lxgxSKZFr+zzX4eLbJPbbhmvYIIxBW16M=; b=ebxtZ3WPq8tl0BSuDEGx8mZY4cTvzgF3Eo6nFoNccLPR/HxTkWwX0elN95mQqBgCsxPq9T oASrkb3RS9W5q88YBIbTQ7F4a+QwLNQid6U5nVsHQXeQKG7h/DtwjeIY3yUbSNmao+57FU JNau+DBqLg6eQ6mjd/KySkEwQLZAd+Ds0f+v4FFhwaILAmDDS6HUMQAOGdXSEw6obvZfuX 192YkvGgthTtajv4X4L9znREHJaPqcSgTgjjgHw6qyDfqpZ720GlfZvYHT+NaRTBKGbrB/ eKrr0a6IAgLMt//l3cruFnKy3Hy3bE4x++6vyxjIuY45udBxPXDCr/2u0k+sHA== From: "Pankaj Raghav (Samsung)" To: david@fromorbit.com, willy@infradead.org, chandan.babu@oracle.com, djwong@kernel.org, brauner@kernel.org, akpm@linux-foundation.org Cc: yang@os.amperecomputing.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, john.g.garry@oracle.com, linux-fsdevel@vger.kernel.org, hare@suse.de, p.raghav@samsung.com, mcgrof@kernel.org, gost.dev@samsung.com, cl@os.amperecomputing.com, linux-xfs@vger.kernel.org, kernel@pankajraghav.com, ryan.roberts@arm.com, hch@lst.de, Zi Yan Subject: [PATCH v11 04/10] mm: split a folio in minimum folio order chunks Date: Fri, 26 Jul 2024 13:59:50 +0200 Message-ID: <20240726115956.643538-5-kernel@pankajraghav.com> In-Reply-To: <20240726115956.643538-1-kernel@pankajraghav.com> References: <20240726115956.643538-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Stat-Signature: ja1bqffpsb89kh9uspab6txcnc5dg7gp X-Rspam-User: X-Rspamd-Queue-Id: EDA96100026 X-Rspamd-Server: rspam02 X-HE-Tag: 1721995226-230442 X-HE-Meta: U2FsdGVkX1+f80GI+G1H6M/coD+F5LQpjKqaVjhCVgudGT3GLtcjW1CBBd9zmp0CPiXK6fAzcn0c9qjG5ufWwETgXgIa7Fw0lKZlUQCmcHPkJyQGtckcvwi2OXEabQWK/rjjx6Zyv0UNxdovElBNtVJOln+nBIzw5NprdhMGeymoYFYYPJAHlsp/LAT63T4yNYdQPGgsA64AC3BVUUiXCu2sUYJDyhNgNcodCsZMNQmxxk5/XmfYMt3TYr7ZVqnu2rP0bhNQUR/SEHEXvpIHDtZVlkuPVy/TFs0HGxHDcdH5nvI0XNaE9wbmfizzLwrk7IvWOE28uNoTXCkKmQrWPlRw4+MSehFm2pNUA6TOQ8UnoFf5EbVyct63dDVY/OXuELbfDlBzI0XIF9J1J/S76TZbPno7e5+M6kR1FJ3M2f7O5iKBCQ/rB6xWMv9itStt5B9Ex23J364LuFXmJj22H52JaqK5X0lxb/IT+BgrfnOZxMgeyKd2XwI4f8WVaTHgDjkWy4wXlIDTQ/X+HM6aHmwmLeqR7WUiETPsj0P0kmlo1oLh3araEpJt6ZOmF6CzbuqdjqK7hEJZgzQ1U4q6Boh4mAwmPCdvNXd9siR2GaH31aqs8vB/EZjqdXx76sjQ5t0xImsKv5rgMePvHaEzf2mGPcVKKY9qN0cT44uv8UmIgKt8PCLgD6KRbSxFl0Uq0xNAMN85aFDV0twKD4otWGd0fnDSpuxjWiEzlyeYhF2Hm5/7m5DSQYpZaHu8RYiJGG4CKvZ0EdsTSooRwbtC+D5cHY42QqZFYUrZIWx8P2RICCZZsnITSyhABhyDnYoniXcJpGdx76cyXsN/Nq84S0Bju/DzDj3ePHLOnUbGBm1sZ7/ORiM7HKI5xegQ6JhXPGk1U3CEDBQnZT+9/Jj4Hwv11/MteZE2qpFh1/QtyYW9acPRraUK9O5F7f/WCj0TjcxabXIOa9wXxBrm3Fa 19Kg2wqm H7ET2TSXiJMGbLr3ap6iLzVdFIiwKKCj9JLD5ucn8YKPbslBrTgT7rNcuvA1T2oVGWFknjejhscRkItPIXdVaqldMFAYWvEhkKpLRJ1p5q7sovpH58qluEhMM5N5GlqFsTumsvf9rNZ1S1HrDikpBfKoftkg0hpc9igUxoalxGnC2IZmjoz5p2fq7CbIjKxgqIcHfIeSkVF6Sybz7vjqWQW+mXVu0QZSSpLUfO9XwJUbGlMHF20zLpnibSdidFJoSLS0r8HEjYeTcogX+YD4JAn0fk0CxlnyK93GfXz5HwcT8ufARSyI225MKqsVW8ZRIjDf5 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 split_folio() and split_folio_to_list() assume order 0, to support minorder for non-anonymous folios, we must expand these to check the folio mapping order and use that. Set new_order to be at least minimum folio order if it is set in split_huge_page_to_list() so that we can maintain minimum folio order requirement in the page cache. Update the debugfs write files used for testing to ensure the order is respected as well. We simply enforce the min order when a file mapping is used. Signed-off-by: Luis Chamberlain Signed-off-by: Pankaj Raghav Reviewed-by: Hannes Reinecke Reviewed-by: Zi Yan --- include/linux/huge_mm.h | 14 +++++++--- mm/huge_memory.c | 59 ++++++++++++++++++++++++++++++++++++++--- 2 files changed, 65 insertions(+), 8 deletions(-) diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h index e25d9ebfdf89a..7c50aeed05228 100644 --- a/include/linux/huge_mm.h +++ b/include/linux/huge_mm.h @@ -96,6 +96,8 @@ extern struct kobj_attribute thpsize_shmem_enabled_attr; #define thp_vma_allowable_order(vma, vm_flags, tva_flags, order) \ (!!thp_vma_allowable_orders(vma, vm_flags, tva_flags, BIT(order))) +#define split_folio(f) split_folio_to_list(f, NULL) + #ifdef CONFIG_PGTABLE_HAS_HUGE_LEAVES #define HPAGE_PMD_SHIFT PMD_SHIFT #define HPAGE_PUD_SHIFT PUD_SHIFT @@ -317,9 +319,10 @@ unsigned long thp_get_unmapped_area_vmflags(struct file *filp, unsigned long add bool can_split_folio(struct folio *folio, int *pextra_pins); int split_huge_page_to_list_to_order(struct page *page, struct list_head *list, unsigned int new_order); +int split_folio_to_list(struct folio *folio, struct list_head *list); static inline int split_huge_page(struct page *page) { - return split_huge_page_to_list_to_order(page, NULL, 0); + return split_folio(page_folio(page)); } void deferred_split_folio(struct folio *folio); @@ -484,6 +487,12 @@ static inline int split_huge_page(struct page *page) { return 0; } + +static inline int split_folio_to_list(struct folio *folio, struct list_head *list) +{ + return 0; +} + static inline void deferred_split_folio(struct folio *folio) {} #define split_huge_pmd(__vma, __pmd, __address) \ do { } while (0) @@ -598,7 +607,4 @@ static inline int split_folio_to_order(struct folio *folio, int new_order) return split_folio_to_list_to_order(folio, NULL, new_order); } -#define split_folio_to_list(f, l) split_folio_to_list_to_order(f, l, 0) -#define split_folio(f) split_folio_to_order(f, 0) - #endif /* _LINUX_HUGE_MM_H */ diff --git a/mm/huge_memory.c b/mm/huge_memory.c index f4be468e06a49..1a273625eb507 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -3082,6 +3082,9 @@ bool can_split_folio(struct folio *folio, int *pextra_pins) * released, or if some unexpected race happened (e.g., anon VMA disappeared, * truncation). * + * Callers should ensure that the order respects the address space mapping + * min-order if one is set for non-anonymous folios. + * * Returns -EINVAL when trying to split to an order that is incompatible * with the folio. Splitting to order 0 is compatible with all folios. */ @@ -3163,6 +3166,7 @@ int split_huge_page_to_list_to_order(struct page *page, struct list_head *list, mapping = NULL; anon_vma_lock_write(anon_vma); } else { + unsigned int min_order; gfp_t gfp; mapping = folio->mapping; @@ -3173,6 +3177,14 @@ int split_huge_page_to_list_to_order(struct page *page, struct list_head *list, goto out; } + min_order = mapping_min_folio_order(folio->mapping); + if (new_order < min_order) { + VM_WARN_ONCE(1, "Cannot split mapped folio below min-order: %u", + min_order); + ret = -EINVAL; + goto out; + } + gfp = current_gfp_context(mapping_gfp_mask(mapping) & GFP_RECLAIM_MASK); @@ -3285,6 +3297,25 @@ int split_huge_page_to_list_to_order(struct page *page, struct list_head *list, return ret; } +int split_folio_to_list(struct folio *folio, struct list_head *list) +{ + unsigned int min_order = 0; + + if (folio_test_anon(folio)) + goto out; + + if (!folio->mapping) { + if (folio_test_pmd_mappable(folio)) + count_vm_event(THP_SPLIT_PAGE_FAILED); + return -EBUSY; + } + + min_order = mapping_min_folio_order(folio->mapping); +out: + return split_huge_page_to_list_to_order(&folio->page, list, + min_order); +} + void __folio_undo_large_rmappable(struct folio *folio) { struct deferred_split *ds_queue; @@ -3515,6 +3546,8 @@ static int split_huge_pages_pid(int pid, unsigned long vaddr_start, struct vm_area_struct *vma = vma_lookup(mm, addr); struct page *page; struct folio *folio; + struct address_space *mapping; + unsigned int target_order = new_order; if (!vma) break; @@ -3535,7 +3568,13 @@ static int split_huge_pages_pid(int pid, unsigned long vaddr_start, if (!is_transparent_hugepage(folio)) goto next; - if (new_order >= folio_order(folio)) + if (!folio_test_anon(folio)) { + mapping = folio->mapping; + target_order = max(new_order, + mapping_min_folio_order(mapping)); + } + + if (target_order >= folio_order(folio)) goto next; total++; @@ -3551,9 +3590,13 @@ static int split_huge_pages_pid(int pid, unsigned long vaddr_start, if (!folio_trylock(folio)) goto next; - if (!split_folio_to_order(folio, new_order)) + if (!folio_test_anon(folio) && folio->mapping != mapping) + goto unlock; + + if (!split_folio_to_order(folio, target_order)) split++; +unlock: folio_unlock(folio); next: folio_put(folio); @@ -3578,6 +3621,7 @@ static int split_huge_pages_in_file(const char *file_path, pgoff_t off_start, pgoff_t index; int nr_pages = 1; unsigned long total = 0, split = 0; + unsigned int min_order; file = getname_kernel(file_path); if (IS_ERR(file)) @@ -3591,9 +3635,11 @@ static int split_huge_pages_in_file(const char *file_path, pgoff_t off_start, file_path, off_start, off_end); mapping = candidate->f_mapping; + min_order = mapping_min_folio_order(mapping); for (index = off_start; index < off_end; index += nr_pages) { struct folio *folio = filemap_get_folio(mapping, index); + unsigned int target_order = new_order; nr_pages = 1; if (IS_ERR(folio)) @@ -3602,18 +3648,23 @@ static int split_huge_pages_in_file(const char *file_path, pgoff_t off_start, if (!folio_test_large(folio)) goto next; + target_order = max(new_order, min_order); total++; nr_pages = folio_nr_pages(folio); - if (new_order >= folio_order(folio)) + if (target_order >= folio_order(folio)) goto next; if (!folio_trylock(folio)) goto next; - if (!split_folio_to_order(folio, new_order)) + if (folio->mapping != mapping) + goto unlock; + + if (!split_folio_to_order(folio, target_order)) split++; +unlock: folio_unlock(folio); next: folio_put(folio); From patchwork Fri Jul 26 11:59:51 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: 13742704 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 8DDCCC3DA49 for ; Fri, 26 Jul 2024 12:00:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 877656B00AE; Fri, 26 Jul 2024 08:00:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 800476B00AF; Fri, 26 Jul 2024 08:00:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 62B416B00B0; Fri, 26 Jul 2024 08:00:33 -0400 (EDT) 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 3D2CE6B00AE for ; Fri, 26 Jul 2024 08:00:33 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id C18B1141812 for ; Fri, 26 Jul 2024 12:00:32 +0000 (UTC) X-FDA: 82381761504.19.7FDD18B Received: from mout-p-102.mailbox.org (mout-p-102.mailbox.org [80.241.56.152]) by imf14.hostedemail.com (Postfix) with ESMTP id E7E34100025 for ; Fri, 26 Jul 2024 12:00:30 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=S8zUd4b9; spf=pass (imf14.hostedemail.com: domain of kernel@pankajraghav.com designates 80.241.56.152 as permitted sender) smtp.mailfrom=kernel@pankajraghav.com; dmarc=pass (policy=quarantine) header.from=pankajraghav.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1721995180; 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=xbld/pizLMEJfrPYBqwQ81gjcSKIsZj5n7TDu8kDUY0=; b=Hj5ecUL4YMcAqWliT5RifxpD5abT425NjgrVMOme/U19gXepzj1shWPRWZHnOVBhP8ZRxa P/NLl4hvemso4RiE9as9CpPiW+q8++qTq3ciN30KFwY0n0oxYWOy/3MXS2NktxV703zOZb vJjR/cDoRfLBEFyIUV3TK9pXD1SxEGY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721995180; a=rsa-sha256; cv=none; b=iHbqB4lc8mEOTOpLIgAd2l8+PVyjfMXlvo+jbQJypV71FZnzwjdLtgrEqKO4ecib66mrD9 vGFWxqB76d2YlvzoT9flG/iUOq6+il9dJ9a3i4HcTESqD95XL5Tas99gd9gv2sehGq1TVu COkB9xiWOBlkG3+WON+kzual+1USmM0= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=S8zUd4b9; spf=pass (imf14.hostedemail.com: domain of kernel@pankajraghav.com designates 80.241.56.152 as permitted sender) smtp.mailfrom=kernel@pankajraghav.com; dmarc=pass (policy=quarantine) header.from=pankajraghav.com 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 4WVmXq3GNbz9t61; Fri, 26 Jul 2024 14:00:27 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1721995227; 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=xbld/pizLMEJfrPYBqwQ81gjcSKIsZj5n7TDu8kDUY0=; b=S8zUd4b9nleV0856IBngGbMzeTPCVO64N152k7I1ao1Q2BDdzmiasjo0YlYJL+9SwYI8wy M3i5xAWMFzqlDmscQeIVxcpJoPByQaD3IXZmK52GN545FLNaNDQk4H0L3lDlQmM34Top1e N+n3N6SGuiX+swJCDr46SdKD5KUZjO/Te2HdnlGFz7755gYEr7X81lnN89zn/4krjtDCOl 7RtCx0LhczAUhqqUN6NtYT41BVWmzZU3BVrJiIeos7oOhlIMWJ2QbS4fWd/R8bobyqRKkp 2JDiKib9LAcrI3iZJ20YkPeq9vc4Yj4C8T68oXLWo8XigGJ23I13gZ2XhjpceA== From: "Pankaj Raghav (Samsung)" To: david@fromorbit.com, willy@infradead.org, chandan.babu@oracle.com, djwong@kernel.org, brauner@kernel.org, akpm@linux-foundation.org Cc: yang@os.amperecomputing.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, john.g.garry@oracle.com, linux-fsdevel@vger.kernel.org, hare@suse.de, p.raghav@samsung.com, mcgrof@kernel.org, gost.dev@samsung.com, cl@os.amperecomputing.com, linux-xfs@vger.kernel.org, kernel@pankajraghav.com, ryan.roberts@arm.com, hch@lst.de, Zi Yan Subject: [PATCH v11 05/10] filemap: cap PTE range to be created to allowed zero fill in folio_map_range() Date: Fri, 26 Jul 2024 13:59:51 +0200 Message-ID: <20240726115956.643538-6-kernel@pankajraghav.com> In-Reply-To: <20240726115956.643538-1-kernel@pankajraghav.com> References: <20240726115956.643538-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Stat-Signature: mxwjjmo1wju1j5uno1ujh3i1iqr6mnnd X-Rspamd-Queue-Id: E7E34100025 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1721995230-828509 X-HE-Meta: U2FsdGVkX1+GcitfpSCl5t1VU1Ln6DSLkt2UxmkYfeHezymhYZwIQ0n9ojhonz4VVpVaj04FLU+NjAP6UL8JUfpSQHzpuaWPny6luJom7Q/Bn7YFA1X3tMZ0Z6hmmngjuZeciJ26+JEXLJPUu2E/r300+oEsYPj72SufqUaqJ1SbmDM6pQDLuj/4N+tYUqXoMkW+TS4jBEuXbQSE9Wd9B+dbXhzLtH8kO4x/5pJIB6TlJjhmonD2+9g3+oVEfGNiyoEE3k800PSEzUzr/Ms60O8ZCFBgJOINhZPPCmHEl927cQ+H3be1V8mtKZDvDQOKIh+oOENoVSui8XdChEKLZo0WhM52BxJIqkmvO5tDxiqkN1fpmICVd57EUK6sBA3gim8rvb993x21YJRTUM5vBKfan8JU7Wgkw6Zme+1j0WHBMIeKrGwos9D9lNRoIvMVwEBbOoF9IRCUUxqxLWir81Qexe3Tkstp8Gvkk9HEHLMWshhk7o6epsgFnHs9HiT5s27DzfJs09D6AxtWdX34cgyw2LgCTTjwU+IsqjoLJFPXw96xt+Oy9vArc/ZBak6O86zEaJ9kgIq8p8RUvqnNGDiMnB2Z7jjvtiXSz/IxEm8J3q2O1KoV5BEW1sFGa8Ox9eZ497i6Q7fVgrtBvM2mfYGPn1+yGm7lb0OxdkRfZ8PfQcqhOueI5bTUy9Lg9rRTWviyHyiVIs4fd87CWyo6Ie+8fCEVlYLthtT3+BdwKl2QeMcYBKMMaP867SUyUGyVy3JP6rCiL4+pFkmy7Usr4/giqfolyQ6hN09YmYlnMr4OwDQvTHr2ink37pliwBpzoY5Ql5tLdHmTXW8/wQHFethY6abCbCT8q4+Kb5uCK2IUtobv983xvJiiUfk9bokDu1XMFqwNi2qvvWeEnDVio3HLFGT7X/VeOrWeuyoq/FPQwXkJyJeqkmY20uBj0axsaZVHlgEKRsHuKpEosXO AS7p8euy BeH4LZhJyu7NDrG8T5hsk6y8UWZdFwvW0sPOzvaUOwKJPi9Fp77yHC9jVVRWfrl2utHyXlq4c9ETt54j92/T1dleQKMB2URd6n06jWL7ynJHEhJNQHYE+R77jgE5c4zfBszBai4v5v+qCxfnpJKrF+YwgDtWFCmG5o+Gfb/vBdk0I2NmnnDBeBSaWVHOqCSMMv1mIzwUYENe57Xy8N+pbge4Zi8bIZYrHey1uAJowNC/uXgIAi4UQHXMgMBGZaBHXCw8YvYUnq1DuFMbU+l/ilBXfTu3iSd4A9587OfFj/Nyxw2+t1j4/BDzvddHw1+kwa+IEqdG9/vYv1Cbq/ID1r/ROCycOJRvOBfjO/MPWSbEhtObgyyLukWMH0CLR4HD/IXlFAZn9PHJnHuXE8Ov1ww2hjzmZH5e8i8GdAdNxJJVk+FM= 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 Usually the page cache does not extend beyond the size of the inode, therefore, no PTEs are created for folios that extend beyond the size. But with LBS support, we might extend page cache beyond the size of the inode as we need to guarantee folios of minimum order. While doing a read, do_fault_around() can create PTEs for pages that lie beyond the EOF leading to incorrect error return when accessing a page beyond the mapped file. Cap the PTE range to be created for the page cache up to the end of file(EOF) in filemap_map_pages() so that return error codes are consistent with POSIX[1] for LBS configurations. generic/749(currently in xfstest-dev patches-in-queue branch [0]) has been created to trigger this edge case. This also fixes generic/749 for tmpfs with huge=always on systems with 4k base page size. [0] https://lore.kernel.org/all/20240615002935.1033031-3-mcgrof@kernel.org/ [1](from mmap(2)) SIGBUS Attempted access to a page of the buffer that lies beyond the end of the mapped file. For an explanation of the treatment of the bytes in the page that corresponds to the end of a mapped file that is not a multiple of the page size, see NOTES. Signed-off-by: Luis Chamberlain Signed-off-by: Pankaj Raghav Reviewed-by: Hannes Reinecke Reviewed-by: Matthew Wilcox (Oracle) Reviewed-by: Darrick J. Wong --- mm/filemap.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mm/filemap.c b/mm/filemap.c index d27e9ac54309d..d322109274532 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -3608,7 +3608,7 @@ vm_fault_t filemap_map_pages(struct vm_fault *vmf, struct vm_area_struct *vma = vmf->vma; struct file *file = vma->vm_file; struct address_space *mapping = file->f_mapping; - pgoff_t last_pgoff = start_pgoff; + pgoff_t file_end, last_pgoff = start_pgoff; unsigned long addr; XA_STATE(xas, &mapping->i_pages, start_pgoff); struct folio *folio; @@ -3634,6 +3634,10 @@ vm_fault_t filemap_map_pages(struct vm_fault *vmf, goto out; } + file_end = DIV_ROUND_UP(i_size_read(mapping->host), PAGE_SIZE) - 1; + if (end_pgoff > file_end) + end_pgoff = file_end; + folio_type = mm_counter_file(folio); do { unsigned long end; From patchwork Fri Jul 26 11:59:52 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: 13742705 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 C7693C3DA7F for ; Fri, 26 Jul 2024 12:00:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 568D76B00B0; Fri, 26 Jul 2024 08:00:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4F26D6B00B1; Fri, 26 Jul 2024 08:00:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 36DC36B00B2; Fri, 26 Jul 2024 08:00:39 -0400 (EDT) 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 154B06B00B0 for ; Fri, 26 Jul 2024 08:00:39 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id AF550141805 for ; Fri, 26 Jul 2024 12:00:38 +0000 (UTC) X-FDA: 82381761756.07.E20B901 Received: from mout-p-103.mailbox.org (mout-p-103.mailbox.org [80.241.56.161]) by imf20.hostedemail.com (Postfix) with ESMTP id C05131C002E for ; Fri, 26 Jul 2024 12:00:35 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=JdIOde58; spf=pass (imf20.hostedemail.com: domain of kernel@pankajraghav.com designates 80.241.56.161 as permitted sender) smtp.mailfrom=kernel@pankajraghav.com; dmarc=pass (policy=quarantine) header.from=pankajraghav.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1721995234; 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=92ifPOSk+9xMdQXjuWHjR+cARiQXMVhXQNki2unPXuQ=; b=jb6Ao7dHE3ds5d5odVkO2KaPzN4qbWRMrCg7KHn67pVrkXXYRQqQp/W0LrxPrYkpzwcN7Z d0ChCwjhF0aCkcE/ZYPfPQrxN8cC2XnOvo0wp1y6Kt8hOIkMs67ig+F/cTy9DO+N5V0/Sl z5mb3b0njnsPBxd0N1vVB5h/zz8pFpI= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=JdIOde58; spf=pass (imf20.hostedemail.com: domain of kernel@pankajraghav.com designates 80.241.56.161 as permitted sender) smtp.mailfrom=kernel@pankajraghav.com; dmarc=pass (policy=quarantine) header.from=pankajraghav.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721995234; a=rsa-sha256; cv=none; b=xU2IAzD2wD3InI3KPhhFNxSrE1sWX/br/0LoZbHJLDZOYvjyMr7rn3CiB7X71yPUYHjpGV KXDLkdSnP2Ms3OuPSXKhn3Yj+eT6hoJgcLeuW581kUYgn3rHXKjBdz79PQnFntxVUv4UzC pQXLOarqssRuoGlQ8zNWuGaX++YtCW8= 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-103.mailbox.org (Postfix) with ESMTPS id 4WVmXw2Gq6z9scY; Fri, 26 Jul 2024 14:00:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1721995232; 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=92ifPOSk+9xMdQXjuWHjR+cARiQXMVhXQNki2unPXuQ=; b=JdIOde58VBAj2fkp/TpLSqvA4CB7syv6NihQWUQIPHWoe1mCge7hwFXUnes0Ts6ZSjKVGG W6YN1FaIHWe8VMN3FfrRoa8z9AZgUiH1qaZIrT7XkEzvDNGcCOC3WOb03+vl346+GUeyjc KEqK7oSuGPLmQDIrYgIjGXlqY7aaO59QbVgWeZem9CkKWmKWzF9nGRg96mtW5wc8mIL/M0 5mIz769OOStN7yKtnverR+89bsHtms8eD97GIGfPjcJvn16IS0eUjCJcINvkO/0VTfn28N 7MuFZWwaLgJRw32CHpeKgmHS5QsGaAzmWpYwn5YH4Ymj2/29hBakOE4tVN1aEQ== From: "Pankaj Raghav (Samsung)" To: david@fromorbit.com, willy@infradead.org, chandan.babu@oracle.com, djwong@kernel.org, brauner@kernel.org, akpm@linux-foundation.org Cc: yang@os.amperecomputing.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, john.g.garry@oracle.com, linux-fsdevel@vger.kernel.org, hare@suse.de, p.raghav@samsung.com, mcgrof@kernel.org, gost.dev@samsung.com, cl@os.amperecomputing.com, linux-xfs@vger.kernel.org, kernel@pankajraghav.com, ryan.roberts@arm.com, hch@lst.de, Zi Yan , Dave Chinner Subject: [PATCH v11 06/10] iomap: fix iomap_dio_zero() for fs bs > system page size Date: Fri, 26 Jul 2024 13:59:52 +0200 Message-ID: <20240726115956.643538-7-kernel@pankajraghav.com> In-Reply-To: <20240726115956.643538-1-kernel@pankajraghav.com> References: <20240726115956.643538-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: 8jq86zt84xp7bedrjjafm7gp338mywzn X-Rspamd-Queue-Id: C05131C002E X-Rspamd-Server: rspam11 X-HE-Tag: 1721995235-686337 X-HE-Meta: U2FsdGVkX1/+WJ/ladvdfkx+m1iwAMt8jxTbUzumt2JshCklZW8JOeUhRK1Zi7vs0tkPLZvNrtrt0EMbKZukpWL2F8DSYFr6bOfGj+tThkQt6Zx6zsDlbeZlbANtjb1HdZYte3xBugp48l+3bB7JQtuZ+Rntkc8atNZyuaK1oasgZqcPx8TJN3JMeLeWVYTFXUCPzXRy9+5HTvaeyGMHRLJ99F0Ty+C6wvEWexZjs21itwwgLG4oQHOeNNOjTV+GkeiCmEZrw0oph0HIirdX4TtQPgIunYgLrNevfAjys9TSCF+nv2Rfo37dOPyh7Gxfpn+533fRwSX7oQfBdeM44kIMQkUfTLSlFPckVyHmV8TWthsR66URvLrlFI93Q0arcNVLqe9W7xS0ofqf9XEd2+eI5b/zqpOttZoegUsoWMJoK1v2K2pYebIUTgeTGgQWgxtd+5I+vuPxOmpi+bUsYFB+wNSOTrMnEfRfPRFuuJiGBspIoKyX1ju4HnbpsR97ozlbIxFCUtMAqPnz1oc99MFH2iWy441a6DCNhNUKWF2fhkkazGMIupAt/zH7rxWOtHdWz0+aBprwY5cal1EW3Xuh2mmz9NAbVI8jVCuaYuXaIPri05bjg7kpe8QXbQSblLafaP4mHf2FPHerhPo+XPdezsdQbdXUJIR80GwE8Hpmx/xTBG0Qxj+uqP5LdCri4wJySIeGqlYkKYSSkZ5wrFrgmVHvr//P/cSQQCIsqK4tVhxma7nKOl6NPuCO6sLwyksYaZzNQrWwuOQmBN41jAg64K4lfvn/7LjdBrg5cfIolAqRnItIniTw6BBlijWwTOeGpVyq9Guu1mzK/CCaw5mQWxTvaFwteeKhHptMdZCm1eKwAxcC3THXcu9+RKJe6S33lIM+dS/VYxCHtZIS66yiPmV+ok0HB3U5tHnymQ3IB7YGnXEmMRYSXKw3a5ic45pgpkRRbFGbQe3WY/x 5PwlXGzf ty0PqDUf7OGSpGvMHjvDi9kvelgwO6jqzoBpQah2vkd6B+g6zZKgrgKNUNqeI2hcLzvgvanBWeB2CbUC1ly9QmJXeKZ3b7wz6K4TeWV2uMwzIeZf9EAISLr7Sa+Oule12VE40QLr6jFwI2OfaMZwwKTCfq55Z3Gwz5lq9EWgwGT7akCopoX+eIwC9O6B/CKny45thm9RMqiPbZ5AINuz9JsEM3+nGsg2K2fmDa5VQ2ywPidjyq0TQpP+lRWIQ9EAb5USpUIrDRYFszHs3WW4DIoi6tzKPib/2gU73L6cewp0FCHZuJlKSvvWKRf9LzZbI8VwopcVhi0iibKnGROc9R3ztEJ3t6pn5lMlrPhjCjh3Y+iJ0a6LZpsmCxp5AlrBGvSfNX49y0iXcBow= 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 Reviewed-by: Dave Chinner --- fs/iomap/buffered-io.c | 4 ++-- fs/iomap/direct-io.c | 45 ++++++++++++++++++++++++++++++++++++------ 2 files changed, 41 insertions(+), 8 deletions(-) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index f420c53d86acc..d745f718bcde8 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -2007,10 +2007,10 @@ iomap_writepages(struct address_space *mapping, struct writeback_control *wbc, } EXPORT_SYMBOL_GPL(iomap_writepages); -static int __init iomap_init(void) +static int __init iomap_buffered_init(void) { return bioset_init(&iomap_ioend_bioset, 4 * (PAGE_SIZE / SECTOR_SIZE), offsetof(struct iomap_ioend, io_bio), BIOSET_NEED_BVECS); } -fs_initcall(iomap_init); +fs_initcall(iomap_buffered_init); diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c index f3b43d223a46e..c02b266bba525 100644 --- a/fs/iomap/direct-io.c +++ b/fs/iomap/direct-io.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include "trace.h" @@ -27,6 +28,13 @@ #define IOMAP_DIO_WRITE (1U << 30) #define IOMAP_DIO_DIRTY (1U << 31) +/* + * Used for sub block zeroing in iomap_dio_zero() + */ +#define IOMAP_ZERO_PAGE_SIZE (SZ_64K) +#define IOMAP_ZERO_PAGE_ORDER (get_order(IOMAP_ZERO_PAGE_SIZE)) +static struct page *zero_page; + struct iomap_dio { struct kiocb *iocb; const struct iomap_dio_ops *dops; @@ -232,13 +240,20 @@ void iomap_dio_bio_end_io(struct bio *bio) } EXPORT_SYMBOL_GPL(iomap_dio_bio_end_io); -static void iomap_dio_zero(const struct iomap_iter *iter, struct iomap_dio *dio, +static int iomap_dio_zero(const struct iomap_iter *iter, struct iomap_dio *dio, loff_t pos, unsigned len) { struct inode *inode = file_inode(dio->iocb->ki_filp); - struct page *page = ZERO_PAGE(0); struct bio *bio; + if (!len) + return 0; + /* + * Max block size supported is 64k + */ + if (WARN_ON_ONCE(len > IOMAP_ZERO_PAGE_SIZE)) + return -EINVAL; + bio = iomap_dio_alloc_bio(iter, dio, 1, REQ_OP_WRITE | REQ_SYNC | REQ_IDLE); fscrypt_set_bio_crypt_ctx(bio, inode, pos >> inode->i_blkbits, GFP_KERNEL); @@ -246,8 +261,9 @@ static void iomap_dio_zero(const struct iomap_iter *iter, struct iomap_dio *dio, bio->bi_private = dio; bio->bi_end_io = iomap_dio_bio_end_io; - __bio_add_page(bio, page, len, 0); + __bio_add_page(bio, zero_page, len, 0); iomap_dio_submit_bio(iter, dio, bio, pos); + return 0; } /* @@ -356,8 +372,10 @@ static loff_t iomap_dio_bio_iter(const struct iomap_iter *iter, if (need_zeroout) { /* zero out from the start of the block to the write offset */ pad = pos & (fs_block_size - 1); - if (pad) - iomap_dio_zero(iter, dio, pos - pad, pad); + + ret = iomap_dio_zero(iter, dio, pos - pad, pad); + if (ret) + goto out; } /* @@ -431,7 +449,8 @@ static loff_t iomap_dio_bio_iter(const struct iomap_iter *iter, /* zero out from the end of the write to the end of the block */ pad = pos & (fs_block_size - 1); if (pad) - iomap_dio_zero(iter, dio, pos, fs_block_size - pad); + ret = iomap_dio_zero(iter, dio, pos, + fs_block_size - pad); } out: /* Undo iter limitation to current extent */ @@ -753,3 +772,17 @@ iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, return iomap_dio_complete(dio); } EXPORT_SYMBOL_GPL(iomap_dio_rw); + +static int __init iomap_dio_init(void) +{ + zero_page = alloc_pages(GFP_KERNEL | __GFP_ZERO, + IOMAP_ZERO_PAGE_ORDER); + + if (!zero_page) + return -ENOMEM; + + set_memory_ro((unsigned long)page_address(zero_page), + 1U << IOMAP_ZERO_PAGE_ORDER); + return 0; +} +fs_initcall(iomap_dio_init); From patchwork Fri Jul 26 11:59:53 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: 13742706 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 E9D2EC3DA49 for ; Fri, 26 Jul 2024 12:00:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 47F666B00B2; Fri, 26 Jul 2024 08:00:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 409F66B00B3; Fri, 26 Jul 2024 08:00:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2829D6B00B4; Fri, 26 Jul 2024 08:00:43 -0400 (EDT) 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 0062F6B00B2 for ; Fri, 26 Jul 2024 08:00:42 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id B33AB1617E9 for ; Fri, 26 Jul 2024 12:00:42 +0000 (UTC) X-FDA: 82381761924.26.E6F3F45 Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [80.241.56.172]) by imf13.hostedemail.com (Postfix) with ESMTP id DA30A20041 for ; Fri, 26 Jul 2024 12:00:40 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=m8OIhx4v; spf=pass (imf13.hostedemail.com: domain of kernel@pankajraghav.com designates 80.241.56.172 as permitted sender) smtp.mailfrom=kernel@pankajraghav.com; dmarc=pass (policy=quarantine) header.from=pankajraghav.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721995215; a=rsa-sha256; cv=none; b=rwLqgQGpARX1rY9fFxQUJtj86Gle6N1SfutGFpdOCOf03/TfBdg8GsDuIk+EoKrVMnY2RU K2xaPlbMZM9rY7pFYNlp3aQ5ls6yzmsOUw2/X+gSFlfi71wn8PXrr8UVdqCgXt+1Pk/b7R 9yzCPQFxp32L4EuDuNnT5+bJrv+JgWg= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=m8OIhx4v; spf=pass (imf13.hostedemail.com: domain of kernel@pankajraghav.com designates 80.241.56.172 as permitted sender) smtp.mailfrom=kernel@pankajraghav.com; dmarc=pass (policy=quarantine) header.from=pankajraghav.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1721995215; 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=D613TVQCptAW9VynAGuVSOK0s4oeJXQu1SypShzHmM4=; b=Vtmgcwv8VAWyC3iKjlFnGJ4xcUJZeVkRpHTKtI91JWEf1S6FzihLnMteJ4anO2FmXDdt2r golhGKTzcdw/PEK8ezQEUc4VTBI2lH0VKyVtiW2LO56kRyLIFXbUOnPuuMOR7fDKWVA0d9 IC+gBILoXASAOJgRKjqIHvflIBw+cdo= 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-202.mailbox.org (Postfix) with ESMTPS id 4WVmY152KXz9t5k; Fri, 26 Jul 2024 14:00:37 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1721995237; 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=D613TVQCptAW9VynAGuVSOK0s4oeJXQu1SypShzHmM4=; b=m8OIhx4vQkeOLF8y08Q0KTEgePfhq6CQ2dg6JHoWh+YM7TqCvvOBtpwEXUEdYyEfI/D+/O Sl5a3UufWE0H/KBMqwFsalNbKnfh5qKJNC1JzXqS4+ne10mXzdVzWf6nV/TBgjheEQ0D0b pTYTpsTnlXbqBUXpGUE1ooGiUbYe/Ht4QSWCkWX4oSvfsc1wf9yWcSS5r3jp/iBXnhSH2/ /cfQolFTUywEp2DRPtHYm7qg3ZceAHcQ5GGFbCdLnjA0bMUIE2b02v8faOCBCeumDGHkfF xLHaMxRHIRrgKrEPYW13wMa8LT8p5Y7b8BQOWKVPJitjWvCvBU6g8473romXdQ== From: "Pankaj Raghav (Samsung)" To: david@fromorbit.com, willy@infradead.org, chandan.babu@oracle.com, djwong@kernel.org, brauner@kernel.org, akpm@linux-foundation.org Cc: yang@os.amperecomputing.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, john.g.garry@oracle.com, linux-fsdevel@vger.kernel.org, hare@suse.de, p.raghav@samsung.com, mcgrof@kernel.org, gost.dev@samsung.com, cl@os.amperecomputing.com, linux-xfs@vger.kernel.org, kernel@pankajraghav.com, ryan.roberts@arm.com, hch@lst.de, Zi Yan , Dave Chinner Subject: [PATCH v11 07/10] xfs: use kvmalloc for xattr buffers Date: Fri, 26 Jul 2024 13:59:53 +0200 Message-ID: <20240726115956.643538-8-kernel@pankajraghav.com> In-Reply-To: <20240726115956.643538-1-kernel@pankajraghav.com> References: <20240726115956.643538-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Stat-Signature: a9ocq6ufxk6orquyt8yypixa5ccht49s X-Rspamd-Queue-Id: DA30A20041 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1721995240-763586 X-HE-Meta: U2FsdGVkX1+0seKdONgJaZqZb+YWI03vDdKKyBF6OOT9pk8zBxH73DIr4emu8CfBA/agBABlwij3O/ONY56YZtHzXaiIpxeTHgHyIDZoJbBKwRPvSEMvrV/Xh4hSkiGrGUHxDttBqQSsCivjlqWH8Az8vMoKXTW+bH/UHaFPs5uG6GRy9mP/23BorKmBzzKxmnJezW2ZhoqIEzW3NdnBYk6fjHhU9d+6rGTo/YT8Am51AkF5Q1/5IHNnyPtwRnzX1rRgtXUxh+LWrwePZYR4B/lVLL2SmSMAmCMk666dL91yXDgaUttEt4/SoRDdiyATlZGOAsWvHEL70A5rJbe/cvMTcXoS47PYJe5RcoG4gyP9xU8aPR+qOTBIdUg1o6GPImiAZjlvdudSY0JfDB/5YTzDmc6ysRfFNyxQ3JwcEzeto+YtgM3KPduWHQL/vP+D7j5pZJxcqjoU42TDIQ7o3L2oxVkus4kziMZmUykNc+VvVndA8XM2tEVatqkx7oIFS69LNHVeriBEfSiOpPXQTvvcV4q4VriDnx0lmfsQGLqwMw0h4vsbDtzhp+MWbfItfGnyfG2JC4ExpmE5s4tXc7H+XlWPir8792FbN+t+GKTvdvcGfUU3I88cJTWsym1U6FXlZVScXgxU8z7XgQRZV8nfVdM+NsCocpEAA8nbwpfPK6JOxcA5TMZLDHFfcRzJYboEoTYCsrtdjkGUiz215S0H8A5hhNcqQk9dROOPPHsnuFaLUCTvRWJ81TAzIpDcvJMStsAlvX83QVwUlEKkhbOajh5rVRIktKKN47kGxnEbJTVCg99CeBjzzjpHLtAeXBVOFqD2uS4voauu5TnRK1VnKX0LYId/sCa2jgXME5hysVqt1aYTgzaS5+tbIdsdsbratwIp9PxtL87pRPeQd7xxBjGrOVFJgTwC/EjBUGXJbYvNY7k5mEfoGSgpBP4YuBRmJjROGxJcZSUXpH8 0osfe1Ef yWZJRvX3B7WOw1mx+YqK0TIebY8vTqsLYOd0VSR7rFEW3FH9PC6TsMYzArCzzkva37oDecCFdfSL8uuzSODqpZ6bhsr3uZr9hy3oG6MQfOyh9uT8IJLL8rVU5ae+iCaQl7diyqUelUT0SytRK7xHDZGntZ0Nx3/w6GfDCuUVArQsPRznDPyV8MMV+uX0aaRAVxYWHifO8/Tx4NmElBG1YE1+g8noPXfYCYksszAECjMRSmT06nvasJxOXTLQNJswa6KJqzMPVIsgKGm0kygcVGQ5v/tLmJ+FPzel3TJ2GIzjPUr/FKj1BE8LgdF7fPHQ1J9CHOAGimqcwRxItlsAof2gZ/4eAPAlPXHfGSG7pDN0dAA07xyYiLdH1NxBDH1EjrllaVGAOkvLL5lHJMdLi6WvdXg== 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 Pankaj Raghav reported that when filesystem block size is larger than page size, the xattr code can use kmalloc() for high order allocations. This triggers a useless warning in the allocator as it is a __GFP_NOFAIL allocation here: static inline struct page *rmqueue(struct zone *preferred_zone, struct zone *zone, unsigned int order, gfp_t gfp_flags, unsigned int alloc_flags, int migratetype) { struct page *page; /* * We most definitely don't want callers attempting to * allocate greater than order-1 page units with __GFP_NOFAIL. */ >>>> WARN_ON_ONCE((gfp_flags & __GFP_NOFAIL) && (order > 1)); ... Fix this by changing all these call sites to use kvmalloc(), which will strip the NOFAIL from the kmalloc attempt and if that fails will do a __GFP_NOFAIL vmalloc(). This is not an issue that productions systems will see as filesystems with block size > page size cannot be mounted by the kernel; Pankaj is developing this functionality right now. Reported-by: Pankaj Raghav Fixes: f078d4ea8276 ("xfs: convert kmem_alloc() to kmalloc()") Signed-off-by: Dave Chinner Reviewed-by: Darrick J. Wong Reviewed-by: Pankaj Raghav --- fs/xfs/libxfs/xfs_attr_leaf.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/fs/xfs/libxfs/xfs_attr_leaf.c b/fs/xfs/libxfs/xfs_attr_leaf.c index b9e98950eb3d8..09f4cb061a6e0 100644 --- a/fs/xfs/libxfs/xfs_attr_leaf.c +++ b/fs/xfs/libxfs/xfs_attr_leaf.c @@ -1138,10 +1138,7 @@ xfs_attr3_leaf_to_shortform( trace_xfs_attr_leaf_to_sf(args); - tmpbuffer = kmalloc(args->geo->blksize, GFP_KERNEL | __GFP_NOFAIL); - if (!tmpbuffer) - return -ENOMEM; - + tmpbuffer = kvmalloc(args->geo->blksize, GFP_KERNEL | __GFP_NOFAIL); memcpy(tmpbuffer, bp->b_addr, args->geo->blksize); leaf = (xfs_attr_leafblock_t *)tmpbuffer; @@ -1205,7 +1202,7 @@ xfs_attr3_leaf_to_shortform( error = 0; out: - kfree(tmpbuffer); + kvfree(tmpbuffer); return error; } @@ -1613,7 +1610,7 @@ xfs_attr3_leaf_compact( trace_xfs_attr_leaf_compact(args); - tmpbuffer = kmalloc(args->geo->blksize, GFP_KERNEL | __GFP_NOFAIL); + tmpbuffer = kvmalloc(args->geo->blksize, GFP_KERNEL | __GFP_NOFAIL); memcpy(tmpbuffer, bp->b_addr, args->geo->blksize); memset(bp->b_addr, 0, args->geo->blksize); leaf_src = (xfs_attr_leafblock_t *)tmpbuffer; @@ -1651,7 +1648,7 @@ xfs_attr3_leaf_compact( */ xfs_trans_log_buf(trans, bp, 0, args->geo->blksize - 1); - kfree(tmpbuffer); + kvfree(tmpbuffer); } /* @@ -2330,7 +2327,7 @@ xfs_attr3_leaf_unbalance( struct xfs_attr_leafblock *tmp_leaf; struct xfs_attr3_icleaf_hdr tmphdr; - tmp_leaf = kzalloc(state->args->geo->blksize, + tmp_leaf = kvzalloc(state->args->geo->blksize, GFP_KERNEL | __GFP_NOFAIL); /* @@ -2371,7 +2368,7 @@ xfs_attr3_leaf_unbalance( } memcpy(save_leaf, tmp_leaf, state->args->geo->blksize); savehdr = tmphdr; /* struct copy */ - kfree(tmp_leaf); + kvfree(tmp_leaf); } xfs_attr3_leaf_hdr_to_disk(state->args->geo, save_leaf, &savehdr); From patchwork Fri Jul 26 11:59:54 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: 13742707 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 80139C3DA7F for ; Fri, 26 Jul 2024 12:00:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0FC746B00B5; Fri, 26 Jul 2024 08:00:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0ACD46B00B6; Fri, 26 Jul 2024 08:00:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E67F76B00B7; Fri, 26 Jul 2024 08:00:49 -0400 (EDT) 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 C5FB76B00B5 for ; Fri, 26 Jul 2024 08:00:49 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 7B18AA17B4 for ; Fri, 26 Jul 2024 12:00:49 +0000 (UTC) X-FDA: 82381762218.08.D257B29 Received: from mout-p-101.mailbox.org (mout-p-101.mailbox.org [80.241.56.151]) by imf08.hostedemail.com (Postfix) with ESMTP id 8FD9C160033 for ; Fri, 26 Jul 2024 12:00:45 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=RpBM3Xd9; dmarc=pass (policy=quarantine) header.from=pankajraghav.com; spf=pass (imf08.hostedemail.com: domain of kernel@pankajraghav.com designates 80.241.56.151 as permitted sender) smtp.mailfrom=kernel@pankajraghav.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1721995190; 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=ndnSuxu0rcgI+ZEpYzFfnAXwgKuKHjCIUBMGSEb9FZY=; b=A1E91nSDoKZG8ACHZpxpz3ZVJzUE0Q1JxU9jR1618VGKleyXt+OKZd98+suj6hRmhUsWkD 3+ZXHIaFET422iBw7A0uTbgqNePfa8e1/qOwJ+qxjJ49nl8BFxUutsGWqQESsK/h+brppC B+jcHxvIC4Q3ZkJilGN7vVoDFoERajI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721995190; a=rsa-sha256; cv=none; b=bYAXsMsULcsl3SPOrGs9v0e6D1bw140aAkXyFX3kMb9uvibChopKw4DUgipiFL4HMl02h+ LGX/Qarz9Mc3/hOI+PjBTquTb8vVdkGxo1W5GZAFHy/wz1w6YbYFv1a7OiRKwputIjqqu3 xIJiUuU3wZ+KqQPXAN14k8EM9GsiOm0= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=RpBM3Xd9; dmarc=pass (policy=quarantine) header.from=pankajraghav.com; spf=pass (imf08.hostedemail.com: domain of kernel@pankajraghav.com designates 80.241.56.151 as permitted sender) smtp.mailfrom=kernel@pankajraghav.com 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-101.mailbox.org (Postfix) with ESMTPS id 4WVmY60pGjz9sbL; Fri, 26 Jul 2024 14:00:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1721995242; 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=ndnSuxu0rcgI+ZEpYzFfnAXwgKuKHjCIUBMGSEb9FZY=; b=RpBM3Xd9hnXdfE7erL4HrWZmKKBLxwOcMTt3SFH3QB1WFE0iLXt34fNrq38jDaAE+2vQo5 8OJ8H4Ko0fAuOd9NV3+1GdbOqIpJtMxhi2RAuhxGYqJ7NUkkn+IfO3o1LAwgNxNNde80SD psMGOYNGXTFTvWZO2Jr66T8q/sbZn6Cua/enZaGy2jn33nyW3o1gfHMYtYG/aV8eU+EWeu B2HAwF7XS6ocx6yL91QlXSF8ciD1u2bLJinHblTkKys02Xd4mPQ4QdDZBoxw9JI3KcymmJ EgTqVEKd/kfA5s/RnC9s0tbezcFFJ3/SlbwPr2hBfVGM6j/BwRHs1Y2I9feqUA== From: "Pankaj Raghav (Samsung)" To: david@fromorbit.com, willy@infradead.org, chandan.babu@oracle.com, djwong@kernel.org, brauner@kernel.org, akpm@linux-foundation.org Cc: yang@os.amperecomputing.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, john.g.garry@oracle.com, linux-fsdevel@vger.kernel.org, hare@suse.de, p.raghav@samsung.com, mcgrof@kernel.org, gost.dev@samsung.com, cl@os.amperecomputing.com, linux-xfs@vger.kernel.org, kernel@pankajraghav.com, ryan.roberts@arm.com, hch@lst.de, Zi Yan , Dave Chinner Subject: [PATCH v11 08/10] xfs: expose block size in stat Date: Fri, 26 Jul 2024 13:59:54 +0200 Message-ID: <20240726115956.643538-9-kernel@pankajraghav.com> In-Reply-To: <20240726115956.643538-1-kernel@pankajraghav.com> References: <20240726115956.643538-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 8FD9C160033 X-Stat-Signature: sax3abeiajitig71kbhf3cajjbui1w3o X-Rspam-User: X-HE-Tag: 1721995245-128772 X-HE-Meta: U2FsdGVkX18JvkhiajM3VdvSDNGcEgzndKPUVGd6LlGqIatEzXi8bv6/Ba+Xkp0nptIbBnvxyx4/PWmcYjCbAaJEIdQqtzg0J+t04QdN5IpE7h60iDPVSBi40/Sp2w5uk5oxm703MU1AeyHZVl0+deeDeDfI3V24I/KaMf1NbgEzHj4hfizbuWtRbtJUpg1a2C9p/AMqkDmoi0tf7wKigdkn7fr1YAUmMSumgyJ+N+xJul4lWwd0os/ykRpl6rWirwc/MGx6TVM5RIJsuIR2O5RCvreFiMnUn7x5HWSyWIfAskAxFQ7kBBo8Wn3Zi5WU+nJybQ9RJ5s7drSjSML6WlScSfAxLTfRpIpCXWZnVvihuG5D8K0yQdesimgOleJzQYKQtAWud+Oe192FQTM5Zzqg6xhjTOdyApolWAls3hVtkdgpygspkJIiBLwVEuDGvmVNVoA2MmGGVBs/nZalTIEtvw42TtpULBgsLtp+p8QYBKJnejkyTBqENjyrS6FrUQsoKzEvZprFL6EZcLXWPddlUtbCg2bV9B2dUKmp4ifFdQx5WkGUBdQk45JhMsqWa4NofrFylWOMmvVZBUNhBSwmxEMBs5UbYbSndjuBCMPC8wS1pqc7js2Wq3uzxAbXS38+GczbtukSUH+Sw/UZWNNUQrSrVvewnXovmdw3F8O/+eaXBrC3CLSmBfTir+cOKnw7MEIoNBg89LhFbEZSGFQuGnKfXWM7/qO3I1UYuKjZGM9reMgPGa9DHIeDvkyxKa34l6Vf2WrqcrPbkdGU52gS2MbwaQTHGq71VmCCB0aglGLH4X/6LwRcohz4tX8z2U1uI/oBkEvUcQq59xP4C/0XYyJqlXcYog7GCbTadhK3fi12zVLrAwD5+ucifu+15xnABMbVpdqVt3r91/smztaEh//WgUJRq9l382M359c2pQNaR7h8h9qTXzPs3f2Yrjo65T6x1IYxYQnwfig bBXxi61U okeJp/pUobdNOPRmfXiY1xkGFzbh4lYh6/5GmDwn+i7BCcpo4R5tPrWBRDEk3Jbibu0WdiT2ottkmjN9yZu90ZmXnmbqtBtV/JSfbMqsA3cIDJnlw3brfLvN03LO2kHCQUKcVzLiDRoCT/mKeKhjVAAyWMZpqKzcfYn6UAr3q51lh1zcJY+U+DeUyMba+p0yql6htOootQqOpvCPzjs7OVn7ZT2LtHig2IIAHo4RTlln3vpKi4PVele93wAMmPFaM2ha9o1YrgbDiDu+CnFxwoKX58HW5UoQ5vuCXlbPgAfFbhcTzjlH4KC4ZBrJpoTZ3/tBM2ar6ICrvmRy/u4/0ax2w17cvPjUl3muvHTK1N9msUAoDDjNbu+2OrJJ2eqTTbe6YfrAofVofjzic869AUh8W8DPIG0/BBBASl1S4vlXaUvax8ZkTQ037PerUxKIUU+Xk 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 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. This change is based on a patch originally from Dave Chinner.[1] [1] https://lwn.net/ml/linux-fsdevel/20181107063127.3902-16-david@fromorbit.com/ Signed-off-by: Pankaj Raghav Signed-off-by: Luis Chamberlain Reviewed-by: Darrick J. Wong Reviewed-by: Dave Chinner --- fs/xfs/xfs_iops.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c index 1cdc8034f54d9..6483b4c4cf355 100644 --- a/fs/xfs/xfs_iops.c +++ b/fs/xfs/xfs_iops.c @@ -567,7 +567,7 @@ xfs_stat_blksize( return 1U << mp->m_allocsize_log; } - return PAGE_SIZE; + return max_t(uint32_t, PAGE_SIZE, mp->m_sb.sb_blocksize); } STATIC int From patchwork Fri Jul 26 11:59:55 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: 13742708 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 8FD07C3DA7F for ; Fri, 26 Jul 2024 12:00:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2F9E76B00B6; Fri, 26 Jul 2024 08:00:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 281196B00B7; Fri, 26 Jul 2024 08:00:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 121446B00B8; Fri, 26 Jul 2024 08:00:52 -0400 (EDT) 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 E49306B00B6 for ; Fri, 26 Jul 2024 08:00:51 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 880D51C1318 for ; Fri, 26 Jul 2024 12:00:51 +0000 (UTC) X-FDA: 82381762302.25.1CF4D76 Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [80.241.56.172]) by imf10.hostedemail.com (Postfix) with ESMTP id ACA58C0030 for ; Fri, 26 Jul 2024 12:00:49 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=qj6gQzzY; spf=pass (imf10.hostedemail.com: domain of kernel@pankajraghav.com designates 80.241.56.172 as permitted sender) smtp.mailfrom=kernel@pankajraghav.com; dmarc=pass (policy=quarantine) header.from=pankajraghav.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1721995200; 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=8rdOu+47Xth5hXKbmOu06fRFiMFY0Pwf2tkrEBizRPk=; b=5pxFAAjn24zwjo//fjtjdxxaSomIS1TQ02PtzegMNpC5K/sSa3SYzH3FEQI3+1HzilqwuY 2JdZLHThEQefIFYAvd4MHaTQPfUfVGj7aeA1YrNyZR8BCsee6DqvRFRs5eSj7HeGt7far4 QboJScvLxRmVg6wavb+qLPIuPt02uh8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721995200; a=rsa-sha256; cv=none; b=QrUReior9yA9oEYRoj/19z+Jer594RDkL6rQGwPfNWhN6h3+dhB8O4ZwkySvoOht34ViLV 0oajUAzv/oyWwnmmKt1JvASzGOX1nzIFjiS1aCTBRV+CeEj+Nxvhky80HHMGMFqxgyfH6q YgC3tNjGOP39rxURIvWsfA4GBzTplYs= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=qj6gQzzY; spf=pass (imf10.hostedemail.com: domain of kernel@pankajraghav.com designates 80.241.56.172 as permitted sender) smtp.mailfrom=kernel@pankajraghav.com; dmarc=pass (policy=quarantine) header.from=pankajraghav.com 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-202.mailbox.org (Postfix) with ESMTPS id 4WVmYB3Fs6z9t0P; Fri, 26 Jul 2024 14:00:46 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1721995246; 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=8rdOu+47Xth5hXKbmOu06fRFiMFY0Pwf2tkrEBizRPk=; b=qj6gQzzYjN9Zakp2rV1btHRBF4MwxpplHYSFNtQ3E+vJk34EKw5Sp8/mrqhBBwj1McnfKu GBxMa28j4v9xwaS6NioIYBZOh2Df0NSrn+lZrtJyyHecW9F9GX5guzxEYav+Hijg7/Re3S Ozy2tLCNgKiVA/H32MKmTQQlN55sZ00Q5fRsEe8nzr01Xj7jELk//lcCP2Dyf0SqIIxzmt DMGClEnuHQQnmK8cwbZLuOeB7iqtTwvAEy8BHwzQFS2RuHetelvNnHCoaN4dsiUKxVm4jR egGJEghTAqte+Qm9c5NzXkWMAeMQ6p0CAXgJsbt94fT/rGImaNC4iyCCAmgdlw== From: "Pankaj Raghav (Samsung)" To: david@fromorbit.com, willy@infradead.org, chandan.babu@oracle.com, djwong@kernel.org, brauner@kernel.org, akpm@linux-foundation.org Cc: yang@os.amperecomputing.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, john.g.garry@oracle.com, linux-fsdevel@vger.kernel.org, hare@suse.de, p.raghav@samsung.com, mcgrof@kernel.org, gost.dev@samsung.com, cl@os.amperecomputing.com, linux-xfs@vger.kernel.org, kernel@pankajraghav.com, ryan.roberts@arm.com, hch@lst.de, Zi Yan , Dave Chinner Subject: [PATCH v11 09/10] xfs: make the calculation generic in xfs_sb_validate_fsb_count() Date: Fri, 26 Jul 2024 13:59:55 +0200 Message-ID: <20240726115956.643538-10-kernel@pankajraghav.com> In-Reply-To: <20240726115956.643538-1-kernel@pankajraghav.com> References: <20240726115956.643538-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: ACA58C0030 X-Stat-Signature: mcmy8ij3wjjijkxc68apkt1spxs9cnqi X-HE-Tag: 1721995249-334870 X-HE-Meta: U2FsdGVkX195fIW8d93bSY5u+JZe0vc56cwbqmiySOsIHufQdK8hYMlwIVLPtKUaqdlyhBXwWR8PMypgeymPQW3a/IAWa08mc4S28L7At6GHNoFUiwdn1CrFzD7Og/q4zLcIgsfmCbIAMyY+VLCMbVjLO8tt6If1xrHXEB7OTe9ipFVCiWIyjJqsFIoiNPAqqh0LjZ/0GCTwfhMM0b9gQ3H+ggqDL+oAb2F3yRkIll+0+tFeykntOsgQwHSy2Aqkyqxzp08SJiJELx2JUhya/ovnLRQ9B/idgE+p0YsUHLRN2gl2lsW7SGN+scDTYdUT+hGsdqRjGiyyT8TapyBXqAiKSUPdKDmZ8A06dwUuyMJ5H4kXhYHRsoqUQXu/CPl3Btq6vWsnWasqbQsytU0P2QO/v+dJA14jFBWqNnipY5D5p91C8sKjSFIylgEkEVtrCOhAzDwzHmvekLUqqs4WQC5bcq4taybiads0KbAp6XWHCAXZ8VjVeJsjoe3GV02V/VvglGzCenpLrfFQ1ZYtw/FC93ZkJJs3pad5HlEnuf7dni10BT/1Xb33AaEnGAvgENIZ215+uWzLesaDQZD9/4/Eo4i/cqRNAYh9yFfAqwuKcpkvZWihcDarD5af+uy/6ojfM4tm5ezVRorCgZ+erhUFRWvUBE6mcfcVC8qL4tzfNsP+g5GuX1sJt22UFML8eWbcK1r/cR5mLT3vaBMhWFxJz1+lugtCEEIZRJIgYnPHgavvWVIrZiwOgXqycZEvnVB3VIq0lJMEMv42KMfSr2Yo3Jwgbn5u+ZCrhc4du36evNBQ7Uw5gM9jgLEU2+gUgklJDGqUEHb77eezV+WOpBQANeTNRE7kMyitZlGYaKRB5YDvYfn8f6gA7EpF38T5PEjbvq76BXVi4XdPYkKwxgYp5PbZxsR1kVGg7ZnhgF09Wp1fZYVp/FR4gWJ6rE1gdumqE7AFHuZ3TltPYmH aqK0eoNh 2R1LWRRI0hvcyAswm6BA3a8ufW1BQ59C0VTvR+ZFJs4a/dPgczrkXyk16C8Zk5CmuHXkLrbvSe98RtiqV0Utfpuf6LAeM7hFIc+TOFm/YskFoSy7V2qG/rwi1OwU6EE+kqveALLYrMgkVxIiew10l8b19ybfUeUGTF6eQAFMlSb0ui1BeW09BBEEp7fksKd2+bIUd2n4IVV6RV01LTU9L03DzuztFsP239V1uAsYmT35EKIE7u7jaPEySJfpR85JcnKHi3WmUyHOVTsfLovHcqkg0NJHVQyFdOEvMVteUIW4qiPOOYbOqmVkrns7SQkfLimtjLEjIkWjUiOw5hIesIi7F0ggZUaQPFik1j+bgOoCv5hBwCxyNWAgDCg== 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 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 Reviewed-by: Darrick J. Wong Reviewed-by: Dave Chinner --- fs/xfs/xfs_mount.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/fs/xfs/xfs_mount.c b/fs/xfs/xfs_mount.c index 09eef1721ef4f..3949f720b5354 100644 --- a/fs/xfs/xfs_mount.c +++ b/fs/xfs/xfs_mount.c @@ -132,11 +132,16 @@ xfs_sb_validate_fsb_count( xfs_sb_t *sbp, uint64_t nblocks) { + uint64_t max_bytes; + ASSERT(PAGE_SHIFT >= sbp->sb_blocklog); ASSERT(sbp->sb_blocklog >= BBSHIFT); + if (check_shl_overflow(nblocks, sbp->sb_blocklog, &max_bytes)) + return -EFBIG; + /* Limited by ULONG_MAX of page cache index */ - if (nblocks >> (PAGE_SHIFT - sbp->sb_blocklog) > ULONG_MAX) + if (max_bytes >> PAGE_SHIFT > ULONG_MAX) return -EFBIG; return 0; } From patchwork Fri Jul 26 11:59:56 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: 13742709 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 E6B80C3DA7F for ; Fri, 26 Jul 2024 12:00:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7B42D6B00B9; Fri, 26 Jul 2024 08:00:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 763236B00BA; Fri, 26 Jul 2024 08:00:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5B5656B00BB; Fri, 26 Jul 2024 08:00:57 -0400 (EDT) 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 39CF56B00B9 for ; Fri, 26 Jul 2024 08:00:57 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id C4C7E8181C for ; Fri, 26 Jul 2024 12:00:56 +0000 (UTC) X-FDA: 82381762512.01.7775A0A Received: from mout-p-201.mailbox.org (mout-p-201.mailbox.org [80.241.56.171]) by imf20.hostedemail.com (Postfix) with ESMTP id D58051C002E for ; Fri, 26 Jul 2024 12:00:54 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=WhYRX2zo; spf=pass (imf20.hostedemail.com: domain of kernel@pankajraghav.com designates 80.241.56.171 as permitted sender) smtp.mailfrom=kernel@pankajraghav.com; dmarc=pass (policy=quarantine) header.from=pankajraghav.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1721995216; 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=F5f9Z6yQ2HFDvQ0pXyKnZ1CF8pk601QiTcma43W9nDA=; b=mQMXU5ZoU6WM8s/tN1Ir1zfdO6ZfOsqX3X7SW2N12HyCOAX+f4+N13iGbePM7jWsTCm1r7 U2I/+jEYgIFXPBAJpWe3Ap5eUHE4EV6Uz3xxG3ONhKM+HuOGvDFuKzVn1aizcKujmGgEH6 XNu+zqZCsqXcslhp01YdsxgVBH7ttXs= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=WhYRX2zo; spf=pass (imf20.hostedemail.com: domain of kernel@pankajraghav.com designates 80.241.56.171 as permitted sender) smtp.mailfrom=kernel@pankajraghav.com; dmarc=pass (policy=quarantine) header.from=pankajraghav.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721995216; a=rsa-sha256; cv=none; b=uPpazZo/BjHnN/dCVKTuopqm2ctcQry5IvJ26/f9EO0KEz3/uDQk+Dr7TlgfVTf3oe589M FklZVRSpOJ95bjjrrGYedtGv8Vq/GH1n+Bk7YB8mt1Zv4PBOAxKgRpF4baxi7iQ4H+o+y6 gIgPQ25VQ6OfD2GTvAoVRzlWBoNG+xw= Received: from smtp1.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:b231:465::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 4WVmYH3fHRz9tCK; Fri, 26 Jul 2024 14:00:51 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1721995251; 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=F5f9Z6yQ2HFDvQ0pXyKnZ1CF8pk601QiTcma43W9nDA=; b=WhYRX2zoWCyU64ct7fWgdmTh0apq/E/Lo9f4nPIwy1jVr1lBXETBOP9sCtAyvGXLYY64Kf ACFyhbhl58Pq/6UVIJUEUMxXpZOaxv2wxOOOQJBt0wjTLAccoVhwQBdBsAPOlqxrkW1F4B OKmo+ew6Nbny60i6utNWuB8Wy/rj1DZg6+kNImhyghxzGAscWxe9ZxcYh2lFTNDSu+Pos6 lTphduaqav0l2aMCgBJe7ubQ5wiv1VTqkOeIg2c+WYTYF4oF5G/C1DESw7UkFVJoO3ak8H 54roaIrREc2n52i6R/5gl84b4437MmrABkWiUEonTikoaixiAkTo2AXmyKbGWQ== From: "Pankaj Raghav (Samsung)" To: david@fromorbit.com, willy@infradead.org, chandan.babu@oracle.com, djwong@kernel.org, brauner@kernel.org, akpm@linux-foundation.org Cc: yang@os.amperecomputing.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, john.g.garry@oracle.com, linux-fsdevel@vger.kernel.org, hare@suse.de, p.raghav@samsung.com, mcgrof@kernel.org, gost.dev@samsung.com, cl@os.amperecomputing.com, linux-xfs@vger.kernel.org, kernel@pankajraghav.com, ryan.roberts@arm.com, hch@lst.de, Zi Yan Subject: [PATCH v11 10/10] xfs: enable block size larger than page size support Date: Fri, 26 Jul 2024 13:59:56 +0200 Message-ID: <20240726115956.643538-11-kernel@pankajraghav.com> In-Reply-To: <20240726115956.643538-1-kernel@pankajraghav.com> References: <20240726115956.643538-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Stat-Signature: f84cjh459ydydhpze535gqsx1aj66o1s X-Rspam-User: X-Rspamd-Queue-Id: D58051C002E X-Rspamd-Server: rspam02 X-HE-Tag: 1721995254-62116 X-HE-Meta: U2FsdGVkX19fVo6TGlq4WksdwIFxxJ0SUK4Qo0aXGcuqs208CNK87rfkb3VBZpQj98XI2PyBOkZpsO8kx445GIMkFQxoOmQKHsb5e9C/f1RN6Y7Lw8ImlQUQ8aTbphivFKbX4R4hy+x9ffoMfYBLHubJlyNxJlJraB+hrs2bIJUGGoVd6ooTl0aU7l/0HQQZPE83O3unMqfY9olAM73rduDDTH0q/rCSwdxoMX98HshWfj/O+FuUXOiI5HKGWKiuuq0504eJZD2SgDOMKM3bqeRrCpibO8XNIV/zY/Wfj+bJvvaa+ttvD3TxXkWwmzDr3c2cIcKVgSX2dOlnk2TGS3hnoQ/xE73hqH3I6YuHxrasXeuFBpi50B/DKjk8NWYqgQbwUWavon4YIAoLwIi5RIrdErXJmZsIj1o6hyEx3Zbs8sWjVznyFmk4cL72/RQjHiRTkZfaLPFSXufd5iEJiU7y0I2gVa8FgsxrpG/APCjFv6LfvgjkUxee2YqyxYfyAACMCSMH7noAxuQWqvaQiKk/8BwGebb/ylu9UxZUiICtKLrMJMoLaA47KkG/YcjXJHdo304iOeaxH9jKd/32xfxmVSWJ2sDzb0Ws/2cbcOdQzrT9t0kPDPSsbDF1qrrBy/tKNxxuCLOBKALYxsJLNa/icb9SdxFchHuWD7pww5d0zpMHYVrnIgcqbc5dAA600leM28UYCqzkevRbSPMLiaMi7GMdDKMCSEnQz34jjzfviesXSYbwr/HYxziql9gaweUFZTJ9qi5rfDxgbBaRGlSSLewKzFeQouqZEcyZiDQAok88uiWAdZwsi81pNP5WfYcLO4CXDinaDnv6P+o4OSKYuwWLpgXl7JylYWAOaxwYrIMMkfvjR1Obg/d8CHI1LI4xwzwwkZo0xv24at92PSp+16NnOhHmqxuFkHq4S7ltzOvi81o3AId/t4seHR5emNAEa3ae/sGd+OoKRXC GtfSg96L cdJ/bmUvUNnze7K08tCoorNs8P8G/DyGo11IsyqrZoS0eetOUTxb9K/TotOQaY2usV6OIiYUrLpwBnqM1Ij/s14SHxWW1wEVnPyNJLEDfMb0XUzpqqBmeNW3/7AFTTQMdFTMqD052G1GiCgOd6WLwOkGi+VzqmFcRnLfxTHoIFMSrIyrgJuSWH2cElcxG34FV/h2PdUjiuQvFpF2ObP86nwzW6rnDxaoNpZW20my2j6OKk8MTzdCaWTwFH6bn5avEZoSkCQJYGgG4tUSy29ZThszKtNxKUGg53bYfCLuxYFhEkkVGHoSsfeNWAMhQEmqkPJg1 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 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. Signed-off-by: Pankaj Raghav Signed-off-by: Luis Chamberlain Reviewed-by: Darrick J. Wong Reviewed-by: Dave Chinner --- fs/xfs/libxfs/xfs_ialloc.c | 5 +++++ fs/xfs/libxfs/xfs_shared.h | 3 +++ fs/xfs/xfs_icache.c | 6 ++++-- fs/xfs/xfs_mount.c | 1 - fs/xfs/xfs_super.c | 28 ++++++++++++++++++++-------- include/linux/pagemap.h | 13 +++++++++++++ 6 files changed, 45 insertions(+), 11 deletions(-) diff --git a/fs/xfs/libxfs/xfs_ialloc.c b/fs/xfs/libxfs/xfs_ialloc.c index 0af5b7a33d055..1921b689888b8 100644 --- a/fs/xfs/libxfs/xfs_ialloc.c +++ b/fs/xfs/libxfs/xfs_ialloc.c @@ -3033,6 +3033,11 @@ xfs_ialloc_setup_geometry( igeo->ialloc_align = mp->m_dalign; else igeo->ialloc_align = 0; + + if (mp->m_sb.sb_blocksize > PAGE_SIZE) + igeo->min_folio_order = mp->m_sb.sb_blocklog - PAGE_SHIFT; + else + igeo->min_folio_order = 0; } /* Compute the location of the root directory inode that is laid out by mkfs. */ diff --git a/fs/xfs/libxfs/xfs_shared.h b/fs/xfs/libxfs/xfs_shared.h index 2f7413afbf46c..33b84a3a83ff6 100644 --- a/fs/xfs/libxfs/xfs_shared.h +++ b/fs/xfs/libxfs/xfs_shared.h @@ -224,6 +224,9 @@ struct xfs_ino_geometry { /* precomputed value for di_flags2 */ uint64_t new_diflags2; + /* minimum folio order of a page cache allocation */ + unsigned int min_folio_order; + }; #endif /* __XFS_SHARED_H__ */ diff --git a/fs/xfs/xfs_icache.c b/fs/xfs/xfs_icache.c index cf629302d48e7..0fcf235e50235 100644 --- a/fs/xfs/xfs_icache.c +++ b/fs/xfs/xfs_icache.c @@ -88,7 +88,8 @@ xfs_inode_alloc( /* VFS doesn't initialise i_mode! */ VFS_I(ip)->i_mode = 0; - mapping_set_large_folios(VFS_I(ip)->i_mapping); + mapping_set_folio_min_order(VFS_I(ip)->i_mapping, + M_IGEO(mp)->min_folio_order); XFS_STATS_INC(mp, vn_active); ASSERT(atomic_read(&ip->i_pincount) == 0); @@ -325,7 +326,8 @@ xfs_reinit_inode( inode->i_uid = uid; inode->i_gid = gid; inode->i_state = state; - mapping_set_large_folios(inode->i_mapping); + mapping_set_folio_min_order(inode->i_mapping, + M_IGEO(mp)->min_folio_order); return error; } diff --git a/fs/xfs/xfs_mount.c b/fs/xfs/xfs_mount.c index 3949f720b5354..c6933440f8066 100644 --- a/fs/xfs/xfs_mount.c +++ b/fs/xfs/xfs_mount.c @@ -134,7 +134,6 @@ xfs_sb_validate_fsb_count( { uint64_t max_bytes; - ASSERT(PAGE_SHIFT >= sbp->sb_blocklog); ASSERT(sbp->sb_blocklog >= BBSHIFT); if (check_shl_overflow(nblocks, sbp->sb_blocklog, &max_bytes)) diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c index 27e9f749c4c7f..b2f5a1706c59d 100644 --- a/fs/xfs/xfs_super.c +++ b/fs/xfs/xfs_super.c @@ -1638,16 +1638,28 @@ 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) { - xfs_warn(mp, - "File system with blocksize %d bytes. " - "Only pagesize (%ld) or less will currently work.", + size_t max_folio_size = mapping_max_folio_size_supported(); + + if (!xfs_has_crc(mp)) { + xfs_warn(mp, +"V4 Filesystem with blocksize %d bytes. Only pagesize (%ld) or less is supported.", mp->m_sb.sb_blocksize, PAGE_SIZE); - error = -ENOSYS; - goto out_free_sb; + error = -ENOSYS; + goto out_free_sb; + } + + if (mp->m_sb.sb_blocksize > max_folio_size) { + xfs_warn(mp, +"block size (%u bytes) not supported; Only block size (%ld) or less is supported", + mp->m_sb.sb_blocksize, max_folio_size); + error = -ENOSYS; + goto out_free_sb; + } + + xfs_warn(mp, +"EXPERIMENTAL: V5 Filesystem with Large Block Size (%d bytes) enabled.", + mp->m_sb.sb_blocksize); } /* Ensure this filesystem fits in the page cache limits */ diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index 3a876d6801a90..61a7649d86e57 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -373,6 +373,19 @@ static inline void mapping_set_gfp_mask(struct address_space *m, gfp_t mask) #define MAX_XAS_ORDER (XA_CHUNK_SHIFT * 2 - 1) #define MAX_PAGECACHE_ORDER min(MAX_XAS_ORDER, PREFERRED_MAX_PAGECACHE_ORDER) +/* + * mapping_max_folio_size_supported() - Check the max folio size supported + * + * The filesystem should call this function at mount time if there is a + * requirement on the folio mapping size in the page cache. + */ +static inline size_t mapping_max_folio_size_supported(void) +{ + if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE)) + return 1U << (PAGE_SHIFT + MAX_PAGECACHE_ORDER); + return PAGE_SIZE; +} + /* * mapping_set_folio_order_range() - Set the orders supported by a file. * @mapping: The address space of the file.