From patchwork Thu Aug 15 09:08:40 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: 13764594 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 691FBC52D7D for ; Thu, 15 Aug 2024 09:09:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BEAEF6B00A2; Thu, 15 Aug 2024 05:09:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BA19B6B00A3; Thu, 15 Aug 2024 05:09:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A644B6B00A4; Thu, 15 Aug 2024 05:09:12 -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 8999A6B00A2 for ; Thu, 15 Aug 2024 05:09:12 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 0AD114146C for ; Thu, 15 Aug 2024 09:09:12 +0000 (UTC) X-FDA: 82453905744.17.C6046C5 Received: from mout-p-101.mailbox.org (mout-p-101.mailbox.org [80.241.56.151]) by imf16.hostedemail.com (Postfix) with ESMTP id 43800180007 for ; Thu, 15 Aug 2024 09:09:09 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=umcQCzS1; 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=1723712893; 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=u0tiHABEgqhnV2gJwGru6HzUMC13qjezx2teK4ST2MU=; b=4b1duTfGI087W3CasaemIyLobk2ftV1Wj7iAfo1zMOi0iP0sXiGW15SX32l7fWoR4X/8fM 0tZGg9cwgzyO+NWQyXV2DT501pRHyDjCmUny7grj1ejWg1NjBLzT105INGbGP8UYMNuxFW cfvTQFpYKd2OROVp5vu/6sAhxR6xS4U= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=umcQCzS1; 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=1723712893; a=rsa-sha256; cv=none; b=RU93MJ/DCY9Yke8F/HL5S2cgjR5ivxohEkD08I0iH73wUwW8M8QAyvbvYjp5KYRv2pmNl2 jO+won03tltH0kgNwLJquUXnq5nC0y4xnlNHAL9oripFsC5Sx5SRImLNNDtWWfIZ+HcT0G 3/oieyNkbJoRvrlb40lYOsJGQY7bTH4= Received: from smtp202.mailbox.org (smtp202.mailbox.org [IPv6:2001:67c:2050:b231:465::202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-101.mailbox.org (Postfix) with ESMTPS id 4Wkznt3Q2Xz9sm9; Thu, 15 Aug 2024 11:09:06 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1723712946; 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=u0tiHABEgqhnV2gJwGru6HzUMC13qjezx2teK4ST2MU=; b=umcQCzS10ETZJ+vn2ckCDLs8A5gkT0UZedyMv0JpzUg6/E2Y2ORvjR4fM1eeOd439Haz3P 4jtm4CfmeqiAKB1Jctal9IQPXfLXavMCijHrxHM0kwWIyUSt0GufMeM385p8mjG5lywqba LQwBEBdNuPPy/z+dXUowbp9q3ldoslJiihUdNjV6BXohNMYDO6O1bLubMoP9yiS0CeJ4AI 20Ys9ujUnK+xNe11hhS4eYaT4htBiAR/Bp6cUXwQH//Rf/saS3G3FOs8fHDitFWMGGwje/ g2fZTgLpt3d8KECr3UsZvqLV4bM1FQpiiLj0BSQqah1cLAM2/nhG5xTmwm7jWA== From: "Pankaj Raghav (Samsung)" To: brauner@kernel.org, akpm@linux-foundation.org Cc: chandan.babu@oracle.com, linux-fsdevel@vger.kernel.org, djwong@kernel.org, hare@suse.de, gost.dev@samsung.com, linux-xfs@vger.kernel.org, kernel@pankajraghav.com, hch@lst.de, david@fromorbit.com, Zi Yan , yang@os.amperecomputing.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, willy@infradead.org, john.g.garry@oracle.com, cl@os.amperecomputing.com, p.raghav@samsung.com, mcgrof@kernel.org, ryan.roberts@arm.com Subject: [PATCH v12 01/10] fs: Allow fine-grained control of folio sizes Date: Thu, 15 Aug 2024 11:08:40 +0200 Message-ID: <20240815090849.972355-2-kernel@pankajraghav.com> In-Reply-To: <20240815090849.972355-1-kernel@pankajraghav.com> References: <20240815090849.972355-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Stat-Signature: tsmfyxmprtdtajk497mxgykampbsojoc X-Rspam-User: X-Rspamd-Queue-Id: 43800180007 X-Rspamd-Server: rspam02 X-HE-Tag: 1723712949-147173 X-HE-Meta: U2FsdGVkX1/mQvjvBOw4nc9YiCd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Q23SuJd+qqZpoYeVocaWMAMIkDMEBZI9ufXp+uTXibEwxf+wcOD0vaKRT/sJzrHkD+lYsCoKvg38/1FkcpHFJvXe32MwwyaXDm9WFKjfMtzER7IoTm42z5QvrOaLQ3cO6nDZfQ/q+3125hq6yiuhs+t3DETAH9BUY/UHdTIJKMeUMsBbI+PspWn/VsMfFw9Vbjw6OEYhGYzfZMQeAAt5MrGG2et8cdKJ1RK+Q5HvRM22PYeBswvhpjAmDfP1+nqL 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 29fec1fccd0a6..6c4489ada3ecc 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 Thu Aug 15 09:08:41 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: 13764595 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 46A35C3DA7F for ; Thu, 15 Aug 2024 09:09:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9A1296B00A4; Thu, 15 Aug 2024 05:09:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 951396B00A5; Thu, 15 Aug 2024 05:09:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 81B5F6B00A6; Thu, 15 Aug 2024 05:09:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 62B1B6B00A4 for ; Thu, 15 Aug 2024 05:09:17 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id D97A6C13A5 for ; Thu, 15 Aug 2024 09:09:16 +0000 (UTC) X-FDA: 82453905912.02.E5884FA Received: from mout-p-201.mailbox.org (mout-p-201.mailbox.org [80.241.56.171]) by imf23.hostedemail.com (Postfix) with ESMTP id 1AE54140012 for ; Thu, 15 Aug 2024 09:09:14 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=UW42QgFo; dmarc=pass (policy=quarantine) header.from=pankajraghav.com; spf=pass (imf23.hostedemail.com: domain of kernel@pankajraghav.com designates 80.241.56.171 as permitted sender) smtp.mailfrom=kernel@pankajraghav.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723712942; a=rsa-sha256; cv=none; b=xbnQKV/9G2UqovJ8GhONJFgWwxHyQRzQoPuH4NdoByBXtbHc9I1cPZD1Gncpwjha5665yc dTsUEd5rZk4Bqc1dO0Q9uk66qK+HEsXkkJ23dNgZG3TVq78xZo3Oho0Wnn4rQd8GOy1j+f CXr3Xc0hPpv5EHUGfHoyVnwlM8ViIJ4= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=UW42QgFo; dmarc=pass (policy=quarantine) header.from=pankajraghav.com; spf=pass (imf23.hostedemail.com: domain of kernel@pankajraghav.com designates 80.241.56.171 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=1723712942; 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=HuI7fVPMlfsEpgPxKValH+cep7FGGOgEqF+LLd6h+EY=; b=Zl5sZDF/OgO+3TyvCtijZkCSp2fQFAhamFr+yKT/WyAVDbsLx8fKuBm8NIf8DUBtesjhQ6 eEgURBVWaraDtm/0iVNc2Uw8ezdcbBt+6zI8mYZwYyJLap2DDLNgceVPPdEcLq8t3d7z8s vPcbL520qu2YKLHam/i0DtmSLBOeQTU= 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 4Wkznz6MBnz9sSJ; Thu, 15 Aug 2024 11:09:11 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1723712951; 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=HuI7fVPMlfsEpgPxKValH+cep7FGGOgEqF+LLd6h+EY=; b=UW42QgFoOK84Vd0PpRAiSW72YyDcY6HrA3zsBOCM2B5h890yjK3m1ac1P8wXsG/VrXiz+/ OAe+LynBFrdhdmX/PiWHMFSbkTK94soDSHdrs/zWsJ0nrgtlGN+rBTtD3gcAFk0CYKrhHr wyaf4O7IpLOaoQ9RWqsjn0boxcNDHet5v9yMUYbpWjkQ/OJZLq2ShNygzy3iT+70CJ32Rl NkIEwkiqDTGqfJ8zbZwEJ0tZTia2TCn5ZttkKSiTea/vS59m1hfJFljwDHrJ4tjHuYslng j4lAzWPJT2C0zUspOGe6/ZVamBXeBhG3SUngSWxNL77wV/H1sBlltqRX/dEkcw== From: "Pankaj Raghav (Samsung)" To: brauner@kernel.org, akpm@linux-foundation.org Cc: chandan.babu@oracle.com, linux-fsdevel@vger.kernel.org, djwong@kernel.org, hare@suse.de, gost.dev@samsung.com, linux-xfs@vger.kernel.org, kernel@pankajraghav.com, hch@lst.de, david@fromorbit.com, Zi Yan , yang@os.amperecomputing.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, willy@infradead.org, john.g.garry@oracle.com, cl@os.amperecomputing.com, p.raghav@samsung.com, mcgrof@kernel.org, ryan.roberts@arm.com Subject: [PATCH v12 02/10] filemap: allocate mapping_min_order folios in the page cache Date: Thu, 15 Aug 2024 11:08:41 +0200 Message-ID: <20240815090849.972355-3-kernel@pankajraghav.com> In-Reply-To: <20240815090849.972355-1-kernel@pankajraghav.com> References: <20240815090849.972355-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: 1AE54140012 X-Rspamd-Server: rspam01 X-Stat-Signature: 63s4y7epstmox8gq9dsz6q4biniagcuy X-HE-Tag: 1723712954-942127 X-HE-Meta: U2FsdGVkX19w8zjp/yJlgXS40d6bobwBWWD04sekDhkYaAF3SvBP1r6obGP3wx/ObYxHV/nhJUKkoHgv5QT1A2xWtybpC2iw2Cz3gcitjqozcAVgDPGuKqFp/cf1QkZsUVt67CKrINiyb1jJh1k2KRscoZa2mgY4gAWqNiIlwunuclOXL5NPetSgEpMKRYVmhqJpgGS5ox/BNNR6EMfGlkOyg0nZhIWm50QdN+xk6qtZjZ/HkbH+L1ScmbU6aX+eMWR2ZwmbZ2I2gYSns3a275w5kBQWxBfeIG9P9BN1sZIJoGq9bEiFbqzNZj18gb9jP+oTnVMdZKP4Doc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dNFIEu7eiA== 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 6c4489ada3ecc..623c0f988da79 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 Thu Aug 15 09:08:42 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: 13764596 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 09AD9C52D7D for ; Thu, 15 Aug 2024 09:09:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 92D176B00A6; Thu, 15 Aug 2024 05:09:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8DC836B00A7; Thu, 15 Aug 2024 05:09:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 77D166B00A8; Thu, 15 Aug 2024 05:09:24 -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 578296B00A6 for ; Thu, 15 Aug 2024 05:09:24 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id D265412141C for ; Thu, 15 Aug 2024 09:09:23 +0000 (UTC) X-FDA: 82453906206.03.106F473 Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [80.241.56.172]) by imf07.hostedemail.com (Postfix) with ESMTP id 15B684000F for ; Thu, 15 Aug 2024 09:09:21 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=QXBQrA3P; spf=pass (imf07.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=1723712905; 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=WDAjNQPLdTVA9OVdz1JrJsTSteMPaQ1doY95LfK1OKzrAg9chGqj9YAix7P4xfB+yEL9Ib TvAxKtpCx1X5dcGh8dohQ8PMbx7HKuHcMj7EZNQl+y1rB4rHMcIGuUJzkQaaC2IuQL7TfS JweTQyye7UIX4YDvy20gHg9tkGLc/5o= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=QXBQrA3P; spf=pass (imf07.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=1723712905; a=rsa-sha256; cv=none; b=NSBwEc3QVqdQ7+thdAC5PiUF6aZCaSC+9op1lzpLvBrJ7E38IV/JAoK26N3vMKFmkXHiiI zH7WEA7EeXUl5b4J0WH84S3no1eMJsX2yhCc+LvLiNkr7Az6KmS8MSRzBjJHs/IfUfwfDn RSmjdmxAGGL8eZuimExyu2K9cHEVlyo= 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 4Wkzp65kdfz9sRJ; Thu, 15 Aug 2024 11:09:18 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1723712958; 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=QXBQrA3PvzJe5fSY+q2g2T+sBJO6QUTu2eBgXVzjWIVNmz1XlU26ZlNead8Yr1GDkHXqpO ZFQ50RwpE4sDUC/YLKKvMcPoo8qa7LO4bgCl3OCIV/k/TtOgumrsjw0KDmSY2U2B6Sbf4m F6EeNpHCYzmZDvB5pPckw2AALW2VGYAjSVdqw9N2rZbmywUjvNMItrIvHADus2d+79aSQT WQf7Ke6c2yT4wYMrVCYwZSFEIaUDbSDXkOBwSAoFXj3iE7cHavnXv6Nn0WchGL4BZuLd2k gHGBV7PBFdZfRPFBl1xwqWbBNVPAA2OKBQZDMHm0hBENGQnlj4uK0bjM7WJDnQ== From: "Pankaj Raghav (Samsung)" To: brauner@kernel.org, akpm@linux-foundation.org Cc: chandan.babu@oracle.com, linux-fsdevel@vger.kernel.org, djwong@kernel.org, hare@suse.de, gost.dev@samsung.com, linux-xfs@vger.kernel.org, kernel@pankajraghav.com, hch@lst.de, david@fromorbit.com, Zi Yan , yang@os.amperecomputing.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, willy@infradead.org, john.g.garry@oracle.com, cl@os.amperecomputing.com, p.raghav@samsung.com, mcgrof@kernel.org, ryan.roberts@arm.com Subject: [PATCH v12 03/10] readahead: allocate folios with mapping_min_order in readahead Date: Thu, 15 Aug 2024 11:08:42 +0200 Message-ID: <20240815090849.972355-4-kernel@pankajraghav.com> In-Reply-To: <20240815090849.972355-1-kernel@pankajraghav.com> References: <20240815090849.972355-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Stat-Signature: z6dgfrs1yzu37hycg5b54q17zgra96uj X-Rspam-User: X-Rspamd-Queue-Id: 15B684000F X-Rspamd-Server: rspam02 X-HE-Tag: 1723712961-445206 X-HE-Meta: U2FsdGVkX18Vom4pa9xWH31uNH2rZqiu9TcXy/nf8h585hBpJEPFI50DprXDwJS1ODu1O5G+nj6bioPBhm/6aVIckww0lEsRBLAF8ztZHbfI6IMz5FMSbmHZK/BQ57bWAdcCx/zj8lcdfb23lfYvQDFbiU3NfQyjVj9TFrAGWY+zri2ttlkL4JUb5aZmNMsMSg2Rf5btJW7sVGkJts/kACFnWcNc1jJ/j724VdpfIgn/wpNrnLOA+BMHGnG7GHaV/PcRvDMCieofLo3DRSKgNsI9S0y1UFV8mmYIkrVTb3mEBmTmzDvh0KYGy41PkkWHYcqJNvbyMCZBE9iaQ3y8f4jkpHIFCb0IrKylsF03kgL273QnAohPmhivk3xLzcVpkqbJVxHpQBit31ficcQ3jY9x4NgTcICY1xDc/UMbxz3MJ66WRffi2xwrm7ZhRk2CcGeU6ppRvTVXBULv5GmKfjb7Qfv+kj9J1MB2trXPUY8FRLJ2YcCWo7eb4LIldXuMgBkmhk6oRiRTckQBGfNqvQVxI2jc8mmlUANEvZpwf54W7T38Nw6zvuccgveryqmKaFD4KiKKvOX6QLw58117NxVEokus6h9zXEqmJXBZP6kS/n8cnX917p8NxaRHlHN9FPwA6ebYN3HMe2gqHUu3KHf09vog9wOmQFZ1F0ZAFiKjBqcNlNJBrTWYa5aFBIKvi9GcNi+h+mHAn7xJMpRpn1dt6R5PcjQXHNz5O0499VY0RbioWu0Z81WnNc5SFY1FDBoUQthH6Cd9S3OvFo2uTmmMN875GHKx/v9HxHUnanoR8gF5WpqQ8sxi4GKdHt/W/uIyBZWZoT+5cRKsaEHDSX+CoZwjBu8EFdMAl0VDszkyk8LXnG4LEMPVq/0jipR1PLTjV4g530XoYfamKgvfAfTwOvQdvtAm1+8jSSzT8hwEnwGgzQn8RTtse9+ulnC8dvO8QNIuKYh7tOeZUls NHs1MzpF tDRs5LoPWlmLJ3chHqx0SRTbpyroo58Hgpt3DY1eEBF/u+0LFtgMGSmtu994wDG23I0TCjS96+MMVUl8jT8mEArpN4DrithCo10oAnngZZtB6igmXeRAIp97yWElAMXxDkjXPTBXlDCHVgC665lNY/qWxKfv3iQwdVghtF0xYV3DmGJFxO32YHw9HligS80lb7aUboKAptoXOdgSzizz5hnzI8zPyeGilqa10Y/71woUU+xKAPWUaUGav1Mvk3I9m+Pmgp7O4shrpEW4zRmWUMO9vDQngxhHQhkVjjpxO0vbcyOq4B3yMUbwpU2/Q19XHhUMY83l4bn6rzZRcYIlDm/cSRr6xTz9802jgUSJY1xis7DtvB2OcjRH/oQ== 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 Thu Aug 15 09:08:43 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: 13764597 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 24503C3DA7F for ; Thu, 15 Aug 2024 09:09:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 904A96B00A8; Thu, 15 Aug 2024 05:09:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8B5676B00A9; Thu, 15 Aug 2024 05:09:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 77CF96B00AA; Thu, 15 Aug 2024 05:09:29 -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 5B7676B00A8 for ; Thu, 15 Aug 2024 05:09:29 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id DEE7B4143D for ; Thu, 15 Aug 2024 09:09:28 +0000 (UTC) X-FDA: 82453906416.12.1E3F9A0 Received: from mout-p-101.mailbox.org (mout-p-101.mailbox.org [80.241.56.151]) by imf21.hostedemail.com (Postfix) with ESMTP id 25AA51C0017 for ; Thu, 15 Aug 2024 09:09:26 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=yMRjZUSU; spf=pass (imf21.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=1723712954; 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=u8XsuW6rfw99LrazhkgxDb/jMaRX449aVMUl4e5Q8A7P/4BPvU5p0HtmP6KtPQz+rYm0C8 kaYsnP1d3AKAcaA7IMQnlZedZbv5iIts9f66IbCByyNdNceJ0/enX1V1mGLEgLE5/R/CPB 3LVwLbc1yZyIv7U0D0IEv+fs4N23QS0= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=yMRjZUSU; spf=pass (imf21.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=1723712954; a=rsa-sha256; cv=none; b=4i4/B6yjMRLawaFtQkyCHbuVD67VCSECFWRbJKey9hbpyDM1okAxJLNdfqgVIq+NT6M5pl Rl/5Lfjn8zrXSiAJNRrH8/Ji4LOlW3mGbeNBNCYn1KD+igN9jyvsP/qUAAmDk85pceyI50 6B1Fse1UFqRfb4zuVibCWGeYE41pTSc= Received: from smtp1.mailbox.org (smtp1.mailbox.org [10.196.197.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-101.mailbox.org (Postfix) with ESMTPS id 4WkzpC6TlNz9sq4; Thu, 15 Aug 2024 11:09:23 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1723712963; 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=yMRjZUSUQXF3Rda1rlgQdRKTREHf0kEK87df0GQFEuTKR9jkjxv5/+nEzFABFSjMvua9OZ VvfQ2gD0Sehtvv+nB3rAHNcMroi9LuZxFx85wMNlyrC63JpuY492TrqNtX3X1GrKBoWJuj ghvHzH5UH9RXe7CBoNVs19Ra61LdDUkFa/I+p9wqKCpX7TZp9p5w3P2UQUQO5ts8bw9DHG yrHcsiTr8kgioUsas89xbTK0YEUrNCNCnVHUN5UqqrDrPxQtBS2uvtboqNoCSVMOnP3uc2 /v89huMTzWt9fVm4uAAAKX8f/0xR3p5BSdkC0rt4TbwRxvBMUiQ8Iba3Et1xSg== From: "Pankaj Raghav (Samsung)" To: brauner@kernel.org, akpm@linux-foundation.org Cc: chandan.babu@oracle.com, linux-fsdevel@vger.kernel.org, djwong@kernel.org, hare@suse.de, gost.dev@samsung.com, linux-xfs@vger.kernel.org, kernel@pankajraghav.com, hch@lst.de, david@fromorbit.com, Zi Yan , yang@os.amperecomputing.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, willy@infradead.org, john.g.garry@oracle.com, cl@os.amperecomputing.com, p.raghav@samsung.com, mcgrof@kernel.org, ryan.roberts@arm.com Subject: [PATCH v12 04/10] mm: split a folio in minimum folio order chunks Date: Thu, 15 Aug 2024 11:08:43 +0200 Message-ID: <20240815090849.972355-5-kernel@pankajraghav.com> In-Reply-To: <20240815090849.972355-1-kernel@pankajraghav.com> References: <20240815090849.972355-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: 7fbpxb54shb7sum6nt6h7ixbkbnzrrk1 X-Rspamd-Queue-Id: 25AA51C0017 X-Rspamd-Server: rspam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XR2YJYIjpVKnd3ae9Q8FZrNU0Y/MBWm3Xk5p8GvCX77v3Z6gzMlFYjiP3p84adbZvoVHwlGXNEZJ+XbQM2++EEKQU34JVFZ7ddesQdda3aKuPDq7Qd7c082dhlSuAdOIGLZZ2GouiPM7ZpxE5q3uAmqJmjrt/jfDY9yTopy3hu6mwEi44+zotUnqFuW7J2E76kxavZ7BWoUehBzxKl0ERv3to6Rsv+W37sC8+rI32U4DNSmlYJiyyXIzUp0i+0ghHi+MPpW 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 Thu Aug 15 09:08:44 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: 13764598 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 8F3FAC3DA7F for ; Thu, 15 Aug 2024 09:09:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1D95B6B00AA; Thu, 15 Aug 2024 05:09:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 18A976B00AB; Thu, 15 Aug 2024 05:09:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 029EC6B00AC; Thu, 15 Aug 2024 05:09:33 -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 D96196B00AA for ; Thu, 15 Aug 2024 05:09:33 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 9CBB6A7CE7 for ; Thu, 15 Aug 2024 09:09:33 +0000 (UTC) X-FDA: 82453906626.25.C26E5E0 Received: from mout-p-102.mailbox.org (mout-p-102.mailbox.org [80.241.56.152]) by imf20.hostedemail.com (Postfix) with ESMTP id D497A1C0025 for ; Thu, 15 Aug 2024 09:09:31 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=h0itYGBR; dmarc=pass (policy=quarantine) header.from=pankajraghav.com; spf=pass (imf20.hostedemail.com: domain of kernel@pankajraghav.com designates 80.241.56.152 as permitted sender) smtp.mailfrom=kernel@pankajraghav.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723712913; a=rsa-sha256; cv=none; b=Y63+9tnGgDxSoywM1/zgQTGGn+gfkdFDpUd8Mjpv78fLGipSfTGQ3nZXJgVkb7+fmzg4Rf lj25qIY59Kc/DMideMvQl/CB5pSyUCaHRaQLWK4BCEqm1cX/5uus6hqG7vxre4EeFDoo+A EWCYds030WPEycu/Gzoem14rt1zY+0A= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=h0itYGBR; dmarc=pass (policy=quarantine) header.from=pankajraghav.com; spf=pass (imf20.hostedemail.com: domain of kernel@pankajraghav.com designates 80.241.56.152 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=1723712913; 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=uyP45Kb7uBDSBwQgasBASrViJg6ERuo2M5WpPhAgxr4=; b=U0rbnEVHTuWfvfm5QF0nQC3w6a98FNPgX+ZZNSe6kL9NRC3zKTHyofgt1TkUg86hmAWRxV 5xyf6Mom5gPk28iPFEIUPS6t3ifQUcecnl83m8b3biaAksa+QJoDLI+xVFJXV3K72qxVZF 2d1LNCoFQdUzEHVDlVEi53mz4+zbGqo= Received: from smtp1.mailbox.org (smtp1.mailbox.org [10.196.197.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-102.mailbox.org (Postfix) with ESMTPS id 4WkzpJ4rC9z9tH1; Thu, 15 Aug 2024 11:09:28 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1723712968; 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=uyP45Kb7uBDSBwQgasBASrViJg6ERuo2M5WpPhAgxr4=; b=h0itYGBR7U+eC3xJ2So8OH0XdSTYBdmL35lQJMwkKF+iuOzPpkOY+ABh+helnpAAAYjPxB nVXT4JJpXSfCLV7fZSCcjLv8XmQaubCtfdBrlyehhLz42F6N98P9j3xsHbyVZZS64K2WrW wImghDfD/gq8n8QqqP58PqtoNmQC8HJpgB1SDaC4wa2Fb0zGe3qh/Fro+VmwaIVbH1bWrk HL+K612QaE0qBAWtOyZPZwlgA4iQHFDNkVgYbuFUuIRoLDsc/Dr2gGgj4+i3N68a7fpflh rRlzgGphpd0taYzgyKwhcVwZnY4xcEMK3ZjpmT0U/irphQ2jMAQIK5Nykxy8YA== From: "Pankaj Raghav (Samsung)" To: brauner@kernel.org, akpm@linux-foundation.org Cc: chandan.babu@oracle.com, linux-fsdevel@vger.kernel.org, djwong@kernel.org, hare@suse.de, gost.dev@samsung.com, linux-xfs@vger.kernel.org, kernel@pankajraghav.com, hch@lst.de, david@fromorbit.com, Zi Yan , yang@os.amperecomputing.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, willy@infradead.org, john.g.garry@oracle.com, cl@os.amperecomputing.com, p.raghav@samsung.com, mcgrof@kernel.org, ryan.roberts@arm.com Subject: [PATCH v12 05/10] filemap: cap PTE range to be created to allowed zero fill in folio_map_range() Date: Thu, 15 Aug 2024 11:08:44 +0200 Message-ID: <20240815090849.972355-6-kernel@pankajraghav.com> In-Reply-To: <20240815090849.972355-1-kernel@pankajraghav.com> References: <20240815090849.972355-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: D497A1C0025 X-Stat-Signature: tgoyedudeefxz7fxyqct6wx9b3kef8g1 X-Rspam-User: X-HE-Tag: 1723712971-120847 X-HE-Meta: U2FsdGVkX1/MaQDijbKhUm1sHmMcCnQ1GDOUYmPgmv70nSkZnTvCY5LNznFRwwZ3h4FErmVVoHUeAjSf39ybNTK69UedJzZFNnvm5J4ZtHd8HZVTk6yz6AakQy2vRslsxsHwB3YsKNGMjMJJWmInha5wow7JlBHpPrbF6Gama0E3HG1ITRyWGB26I3U/KQKBF1Xf/SJ3mouilMopAywSEpBuOusjBRttz4BYSdfCDqbiE5uL55qTyUZ72iy5QqQLCptj5VFbzuy7wRLTJViqTuupQDeQKnQ6OHglnc8YZNQUA/Cz96vzMokKlh+mY+SFZih2vRIkiUiDTg7cruplP2Dnf6hTzeEzRet2RDzn7z7n5JCoHG1OiIe2FFFoSGvQlpilMLuAu6Ce5nZnibQmvCZadCbkgEsTE/1Ip1hKXNGFSqAlmUituTCRCWao2YExDjE68xI1OOf3qklclynNDBA3ZVoDHF2szJBUZr5gh4keAT+kQiERqwuWnx1R+KDWpPXXEQ2q0xDEvElJmv8kKUFo+veS8BfunaSslLtWdOt/+0R0zCHr6zaev5ZLQ0yxVeHKkfl+NcsWZJyIMRPSqUOsdcSMevRpikl1Pww1Yv3fHUnMQCrcqjuk/MQMEQQ7C1hiIsx5woMVrAxoPNDKJ/5EpwhJV0CCsZwkAQoQP2R02mtddqteb0/bvI4YE2WGUZM9rFyWvULOKfD40rkPd4dA+ioLMjLWUjec+44UAnLL1RkisYbq58EDCMAirpxJTyDRYuggxMRcRpVhwf0y+tltiU0CUZS2F5VlSX/RseH29DRSmk1u6mPeDWSXvgEh11Kyem5IIOtLZ+139PIYbo/B5FeY9+V4cFn52W2jnhIAxAbz6XqZpjNX9ZBVq+z/+7l/vmfKeYapJy4Bllm9kbNYkk4TgYZ1i4cQcg/IY1behOi1X+ONXg/0drXdEEDqhN/uwPO+ps2IkOX4ALS uwXT9Q8k HHcnA2jH3lhyTrt/PDSFxw2TI0gkh7LJfTa1POTvL3cfsSz43MSn2rtSz9byNZB/1znaDAhXaPgOeAYK7owpvzomIIdQfK2eDS9fvdC2/IpqQRjSUpahnp9Xwzi2LJLqSTOA2+HTurDRcvFX0ata1vksgwUVyi8Wa4azCF8sgOz7Yp9zhQeeXT6Hm/R9qz9D7FBOV9lUpW/7migPY3lhLnE5QQbUanliAVaj2cDyAORg3lPRzc5FiC9MFAU59Ip/23b3rNEQqyNpdPDk8PgWShcRXd7fqYFSmd+fR8qQC/ttZM4CY2zVpB3wUlSrsOm7pR583uXBYzgXuWXP/bimfjaB6Yog5sDO7y8fRwNOo+Mt8gA5IMtH2qZfNU7lp86HMqZtyTQ+9fe4rof4= 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 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. [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 623c0f988da79..77b583a7aabd1 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 Thu Aug 15 09:08:45 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: 13764599 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 5E465C52D7D for ; Thu, 15 Aug 2024 09:09:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E5D756B00AC; Thu, 15 Aug 2024 05:09:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E0C796B00AD; Thu, 15 Aug 2024 05:09:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CD5076B00AE; Thu, 15 Aug 2024 05:09:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id ACAF96B00AC for ; Thu, 15 Aug 2024 05:09:38 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 66D4CC141C for ; Thu, 15 Aug 2024 09:09:38 +0000 (UTC) X-FDA: 82453906836.01.43C3A44 Received: from mout-p-103.mailbox.org (mout-p-103.mailbox.org [80.241.56.161]) by imf03.hostedemail.com (Postfix) with ESMTP id 96AA820025 for ; Thu, 15 Aug 2024 09:09:36 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=g5YsTPzC; spf=pass (imf03.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=1723712904; 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=pD3Ip9aPdQ9e51emhRiUmYHymg6Mc2qCEYPgRqwWlxo=; b=TEeO5btmd1wqAzlviEQHSKonkcmbF/LMx8C7J83KGkNMpz4rZeTJAReGSN0m6+q89Bw0yw gSzs+q07vs6dMyxuH/ynM/iwAkKDEmVOlFu9SLXnrBxstPkFVw+wW4dlDlL6uJjNzZfC3O 9zsIGmbwu8QnfOoH3SRCv6eFaT39sxM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723712904; a=rsa-sha256; cv=none; b=aMs9wtUw623MFnGHJAzPxVQNqvwU14gRoO52Q6SETSsvJZN8NOF2VRz7fpWphwcm7eX0Tb C2X7CvHvPQ0AZhTVF8aHVGQyUNro4UVaYIxs1u63nJP2Jh5XsGrAG9cGyuPU5WDRH99J0G A5UXvHE6hsYOlnMltvu/VWNZyBtJAgs= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=g5YsTPzC; spf=pass (imf03.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 Received: from smtp1.mailbox.org (smtp1.mailbox.org [10.196.197.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-103.mailbox.org (Postfix) with ESMTPS id 4WkzpP3gpKz9sJ5; Thu, 15 Aug 2024 11:09:33 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1723712973; 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=pD3Ip9aPdQ9e51emhRiUmYHymg6Mc2qCEYPgRqwWlxo=; b=g5YsTPzCJdXMe2XqBBy5uwNDho3d0T0MASOfQB/BuSmN0Jw9inUNRVS8yAatpBqD+mdGIi ncUDQjk/x9hdDzqlrrU7PT0F5UXY4msksN4AJfteMn832+L8jKdYKJpGCc1RKivDW6ZGS5 io1vkhJxCHZ5QeGFXkaxumijXUZFKPAlvJboRRVwJAuy/5QOqXrSGWyUOEu9aYmyCRL1H0 PjbiY2nlpKa6LdXLymv9wSy0u5S5BmceZdrwJDQDEjCgSVoIPW3s9/A1l4pajqiBZqCLMZ 0Qz1L5esq4Sr9SngwjMo5at0QUXsn1IUReWYpQErZw7wkbj6KoIvxm3gkLMw3g== From: "Pankaj Raghav (Samsung)" To: brauner@kernel.org, akpm@linux-foundation.org Cc: chandan.babu@oracle.com, linux-fsdevel@vger.kernel.org, djwong@kernel.org, hare@suse.de, gost.dev@samsung.com, linux-xfs@vger.kernel.org, kernel@pankajraghav.com, hch@lst.de, david@fromorbit.com, Zi Yan , yang@os.amperecomputing.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, willy@infradead.org, john.g.garry@oracle.com, cl@os.amperecomputing.com, p.raghav@samsung.com, mcgrof@kernel.org, ryan.roberts@arm.com, Dave Chinner Subject: [PATCH v12 06/10] iomap: fix iomap_dio_zero() for fs bs > system page size Date: Thu, 15 Aug 2024 11:08:45 +0200 Message-ID: <20240815090849.972355-7-kernel@pankajraghav.com> In-Reply-To: <20240815090849.972355-1-kernel@pankajraghav.com> References: <20240815090849.972355-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 96AA820025 X-Stat-Signature: zo9fptrjzq9rt8rwykmabpwkysteeiuj X-HE-Tag: 1723712976-35795 X-HE-Meta: U2FsdGVkX180C1oDx2Dxy1oH873qb0g3ULG2jhghIVBfTYtonwb/aMR5v5UzIWVXJQORjAQFhihb/qPohql2P5IeV1kXI656sAU2Iq5PVbSY0XOS1unlKlI/wW3nsK/rvy+IrUb8/4a/zWjw7sdb2TE+kAFi81qDHaES94S/fm4xpbgEPisyma3K+vi8aS8k3ruV9MoHOH/eKLMJACBYNf0n8WaEv/I7BpxMNduQEIyu4Lyib/WxQPXV7ftcBT7BPeDPfes+a8vJSTcEHYaiqmhz1X8pL/FqVihHN5UY/Z++EdpS+NdJ9zPFp9DPB5bUftfK7X5d0uGW3wnm6RLxWWGV63VzbOWEM5Q4JCyNzEY6xcBS25iw3CZvCiBupFmj6JRcQ0KET5hiWUqUWm5rpWx+ak6itEW8ZT4tA6CrboThglgyNk8lJQXq4PxoRDhskBb6gST2+bRLiVIxuNNhDSbeWZh+pezl+v6eI9v2IJwKLb/kBYzeA7ZoXU3QF3XKVhjQg9EkzOTKTp7z2vPo/Pi8pcvGq+hhVA0lSk5KjW/yceMMwGVxpZh3NyfJzU5WcOANYCtiT4TnN16egQlVTsLYwEF1joAoHxaG1HgHqsjaCrVKmXI4x3ZcoC/TlFoQkMm0ccF9SUkOBhSljTHv3HwLo/FEpG7doQsYVxWJlFVfo/HxwiXZhXHaZol5ImLyIGB6znmt4xyC8CEOj9+f3aKtDoPOtytrYStVitOS6jeCxrRqj+XBkpGFTkl8CD5WDfqQuYzzIbPYFscugxT8zNhfDo7NBomZnkTPPsIgzadiO8jBt6ZxjsvuDrzm6MiNGZDHWl5omU5uxPS/h3KK8yKO2Ssw00SVfsxZVfo9I/VZYF6gShPE7HGfOeMR7HOo1gVEL8/ek+c0bS2u9buINFCaA1P5BXb7oXgzJdhTndBVqPvlYfiSEHG3A9zUfCIMPr1MSDQ33bVHx5McCWO LSsuHgH2 epS3VuRnSvgeBCJYPmWVikk/gSnyTnIRM8wFJpWvs+AbYjzYx6PjWTpK5gv2nFQCdy3AC1/DPkiN8tHtmVhUUC3fshPyxmjv26eendpZp7I+2V4If9cGtvUpRACa7m2mld0vd1s523Dfelj0GNKeuC02pfbmU/j1KKm81qcJw0mnmxPNg5erxqNlf+bTwarTg/9rm/mJUErb3Mgk7UxHD7rw0Z5O5mZRYsYjAl9IXYoP1rmv2vH0SJO2MTjPgwcZfQxD0hhhjZConBxRDKd5XFssB6o17Q/hq0yiaqCq5jtZKc+TesVGi6cfYUTLAeR0Gjr1G7/21e253i1SDbDbbk8QUyCinNHdes4v9u7eGFN+DQBjlYZ0qfIw9nA== 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 9b4ca3811a242..cdab801e9d635 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 Thu Aug 15 09:08:46 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: 13764600 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 E4887C3DA7F for ; Thu, 15 Aug 2024 09:09:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 77FFF6B00AE; Thu, 15 Aug 2024 05:09:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 72EBA6B00AF; Thu, 15 Aug 2024 05:09:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5F6116B00B0; Thu, 15 Aug 2024 05:09: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 42AD16B00AE for ; Thu, 15 Aug 2024 05:09:43 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id B70BF14137C for ; Thu, 15 Aug 2024 09:09:42 +0000 (UTC) X-FDA: 82453907004.27.0700151 Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [80.241.56.172]) by imf02.hostedemail.com (Postfix) with ESMTP id E9C158001F for ; Thu, 15 Aug 2024 09:09:40 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=kDAMcgZw; spf=pass (imf02.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=1723712945; 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=RF1+EqUrrDTKJUmrTUijzur9qT2UQhc5doN0Sx+Rh9WkhC3/Hd7KTky766rjFZjYd2Q38I BUObZCXgb3gOS7zlD54DGobhvz8pn52a2UjSVgVEc+qtzoWrhT4z7UxSIxVi2YiY3u9mKW xDN2FIdOSPlZYQaQgpimoxUk5riWibM= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=kDAMcgZw; spf=pass (imf02.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=1723712945; a=rsa-sha256; cv=none; b=ULmw2BAl4xEr2h1qnluY0DmHQeB1BfIarug3XkvvK73RvchvRs4fVkR2e2Bndrfi0XD6NX 5/iVYNNPIDXhuWjrknuVslg+ceizRc2fcBLQPQ5WUFbG776J5pPMt6XZF2bZ0bKN3OXGhq Ka75HtCzziu0iahV1qnacUIMvncuXY4= 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 4WkzpT42Qbz9sWd; Thu, 15 Aug 2024 11:09:37 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1723712977; 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=kDAMcgZweQ0Bnu/S+QiyFuf0x+LiYm8/+zNP/SNOMkulmMCghzRCdWiM9gDS39eTc1PUdN ROxyw1J3DTm7hSUB7YLwZAaVcv04gs/+2quOPaXWLj4x92lH7Uhc4D1hPtUFF0t38M1F7H FH14Zshstp4/00yVytPxrMlgOTpBd0zrXZp/DyHSgdueQZrmiQpx3PUQbf0e1fzoxaiwY/ B7OPvZxCGTp+GgR6YisGSCCXmnw6Qr6TWS9kI1kqouF6LSASD1/TDdYWvZJyCUZh/gA3UP 35GHOtJbIRHxs4Jykd16PlN9CB88JThH+BepMJ8LbEwdC2phQhCsnP3xx1bV0w== From: "Pankaj Raghav (Samsung)" To: brauner@kernel.org, akpm@linux-foundation.org Cc: chandan.babu@oracle.com, linux-fsdevel@vger.kernel.org, djwong@kernel.org, hare@suse.de, gost.dev@samsung.com, linux-xfs@vger.kernel.org, kernel@pankajraghav.com, hch@lst.de, david@fromorbit.com, Zi Yan , yang@os.amperecomputing.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, willy@infradead.org, john.g.garry@oracle.com, cl@os.amperecomputing.com, p.raghav@samsung.com, mcgrof@kernel.org, ryan.roberts@arm.com, Dave Chinner Subject: [PATCH v12 07/10] xfs: use kvmalloc for xattr buffers Date: Thu, 15 Aug 2024 11:08:46 +0200 Message-ID: <20240815090849.972355-8-kernel@pankajraghav.com> In-Reply-To: <20240815090849.972355-1-kernel@pankajraghav.com> References: <20240815090849.972355-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: E9C158001F X-Stat-Signature: sdbaupcnmxap3ym8iepbd84tr4r4gxwf X-HE-Tag: 1723712980-655963 X-HE-Meta: U2FsdGVkX18nrEw9cG0gDv8NK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MyAuINiyjFWNiu4nc3D++HTOcwYIlG3r4S9hASF5J0CRGU3Qxdxmym/rOKdWP+9IZQghe3j1HX+ZRdVFMXpHKkwmc5O0l9/shPhEPC3B2n6LgVU8Lv6Cp/PhCTg9kB0dZ4fpu8nFlmfAlEMszg+fMggp0X2M6a11fmLkEpKupSEnyjt0m99mFjNGNRFFo3bCsCBaW9IlDOXhUIcyulCxsV0mDUYExoCQqxkL8jlMWnF+hfJaxYDmVgVA7axmq4YsQct/6g34x88jsGGgjYmfqSw59TDHMCeKKfn0g== 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 Thu Aug 15 09:08: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: 13764601 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 76E5CC52D7D for ; Thu, 15 Aug 2024 09:09:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 009786B00B0; Thu, 15 Aug 2024 05:09:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EF7E06B00B2; Thu, 15 Aug 2024 05:09:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D99596B00B3; Thu, 15 Aug 2024 05:09:46 -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 B95D86B00B0 for ; Thu, 15 Aug 2024 05:09:46 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 8260C411D2 for ; Thu, 15 Aug 2024 09:09:46 +0000 (UTC) X-FDA: 82453907172.24.79AE0C1 Received: from mout-p-102.mailbox.org (mout-p-102.mailbox.org [80.241.56.152]) by imf26.hostedemail.com (Postfix) with ESMTP id D60C3140005 for ; Thu, 15 Aug 2024 09:09:44 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=bmHxN5xn; dmarc=pass (policy=quarantine) header.from=pankajraghav.com; spf=pass (imf26.hostedemail.com: domain of kernel@pankajraghav.com designates 80.241.56.152 as permitted sender) smtp.mailfrom=kernel@pankajraghav.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723712926; a=rsa-sha256; cv=none; b=34dEEtuRlvTRZq1tpZGAJrAXJmTnhnHiXNLSNjV8aAHNOR/lqZDKgRAcwg3v8R2UYn/Q4V hfaeY2gt0U7oh3wH+vXrKxLwmoGjoL2bR4fUPSEhaz/krrGAiK7ENzqniFEAN9RLSQT2UR 3XnzTMdy//YQxuNcpnI4bDmtqfCr1ZU= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=bmHxN5xn; dmarc=pass (policy=quarantine) header.from=pankajraghav.com; spf=pass (imf26.hostedemail.com: domain of kernel@pankajraghav.com designates 80.241.56.152 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=1723712926; 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=OFCQeRoYKCpIwc/V7VVfVT8xrzJ1wqzaVy/cCyGH2d4=; b=s2JcU9Qz9SkyZ8hS/yCPUFKzKeAbMqDg8BS/NZafXM+2RHDZOsJGO0oYOHX6PZvkiVy3Ka 3PsVM4T8a1hlcADRUfW/OgDINQjaLeI/DaTl7sDCs/iQaB2XjDoq5xCvj4O1LdbTyK/b34 WNNqNeR3BpVZ+3fxlZBYu+Rq7WZkjEU= Received: from smtp202.mailbox.org (smtp202.mailbox.org [IPv6:2001:67c:2050:b231:465::202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-102.mailbox.org (Postfix) with ESMTPS id 4WkzpY3KLZz9tHx; Thu, 15 Aug 2024 11:09:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1723712981; 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=OFCQeRoYKCpIwc/V7VVfVT8xrzJ1wqzaVy/cCyGH2d4=; b=bmHxN5xnLg35Iz86PnXix1HzhYebVNPB+WjyRU4E3jgDRG4++HgKyq6jFbdDZJ5G9DcfMx npD2ioepW1fqtg7r0lLJF0fudyKYiqkBvKa7Yi+unwvJD5rwOCuMyvg1L8uZ3JTQAoH+Qx ieLj0l8s6ki0jkk2Z6Elh2HLY8V4hqDrdq8TjaMG9lrguXfSLcL9oYNR6ZdRJX8WF3wI88 W+DTZGv97zZ5dZnVhePG6YoQmnz9SoYBBXNwIJN8Dq7m+kdH+nWX0Udc5RmmPySxtaofTk Bfy5kmT/sVmIsG1933qAxTMREHPS0yGV7y3ON1WyPtNVrAj7y+qto8+oiBTlBg== From: "Pankaj Raghav (Samsung)" To: brauner@kernel.org, akpm@linux-foundation.org Cc: chandan.babu@oracle.com, linux-fsdevel@vger.kernel.org, djwong@kernel.org, hare@suse.de, gost.dev@samsung.com, linux-xfs@vger.kernel.org, kernel@pankajraghav.com, hch@lst.de, david@fromorbit.com, Zi Yan , yang@os.amperecomputing.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, willy@infradead.org, john.g.garry@oracle.com, cl@os.amperecomputing.com, p.raghav@samsung.com, mcgrof@kernel.org, ryan.roberts@arm.com, Dave Chinner Subject: [PATCH v12 08/10] xfs: expose block size in stat Date: Thu, 15 Aug 2024 11:08:47 +0200 Message-ID: <20240815090849.972355-9-kernel@pankajraghav.com> In-Reply-To: <20240815090849.972355-1-kernel@pankajraghav.com> References: <20240815090849.972355-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: D60C3140005 X-Stat-Signature: e9kgq7d98d8zbq8azesg15jkt3auxhun X-Rspam-User: X-HE-Tag: 1723712984-510348 X-HE-Meta: U2FsdGVkX1/6yDC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ys2pVLAy+2QMu4ja28Ne9Dt7hjTPJhoWrmz5darG3T1o/0bIFHywJjJz+W50bNpxN0DO5arwWO1mx81jkDRDYBdlbdDxGqh34LWZq1hv+Q/ueShz/MQqBr+L5bV31ZDQ1q+eNWy9zj3cTiEhKe3X9yyaVTa1MU/zmQ8F2Jkj56jzO8DI6m0Of8xB80pSyiKyxJEF/NRvU0LsKqX30fqfmQXztv3VVP1u2EwOalcg0mfntac6IM/PBpRW5b8cArqyJwLhUzzOb+v872m1gTxP968qpqU5n+2CxnhUiA5T9znBqHzD+2os/s3jYH/NFK7W3+dOMJHDW+yMJmJhHE03Mvc5AeY8MHAQsIrX16BZl7zZnyVZmudya+LP6Zzg== 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 a1c4a350a6dbf..2b8dbe8bf1381 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 Thu Aug 15 09:08: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: 13764602 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 72197C3DA7F for ; Thu, 15 Aug 2024 09:09:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AB4746B00B3; Thu, 15 Aug 2024 05:09:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A63466B00B4; Thu, 15 Aug 2024 05:09:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 903E36B00B5; Thu, 15 Aug 2024 05:09:50 -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 707E56B00B3 for ; Thu, 15 Aug 2024 05:09:50 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 2DF481A13E5 for ; Thu, 15 Aug 2024 09:09:50 +0000 (UTC) X-FDA: 82453907340.22.98C2796 Received: from mout-p-101.mailbox.org (mout-p-101.mailbox.org [80.241.56.151]) by imf28.hostedemail.com (Postfix) with ESMTP id 78FDCC000A for ; Thu, 15 Aug 2024 09:09:48 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b="c/Cm76OC"; dmarc=pass (policy=quarantine) header.from=pankajraghav.com; spf=pass (imf28.hostedemail.com: domain of kernel@pankajraghav.com designates 80.241.56.151 as permitted sender) smtp.mailfrom=kernel@pankajraghav.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723712929; a=rsa-sha256; cv=none; b=1150ai76UAiUzSWG4l75D1KUklsiXql7EoDBctTE0ywCbykwFepGSN5KGG4kGbP3z9lx+F TpDVST55MV8TS1+ptn+/oD6uY7hW4rmrVPeN99it7w+qXbvQAIaD0fZkeN/+AKOXJUwAsd sdmBqOK8Uht3q6Kapo/PHer8+uePfdY= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b="c/Cm76OC"; dmarc=pass (policy=quarantine) header.from=pankajraghav.com; spf=pass (imf28.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=1723712929; 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=6bkHkkZtAV+DG4IWlq79Eu9R2bG2bBzOuWYizM/QYF9Vzp7dZ7RYc7FjVCpFjxXA7lBDQP YuJsEMIytWF+Wtp3L5jtpN9OugKXxPLDf1E5ProzRitR3I4E0ZRUL7kt2zry0vEVvYzoy9 7au33T5CmgC+HZbb63BgoLE6kIRvBsM= 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-101.mailbox.org (Postfix) with ESMTPS id 4Wkzpd2nKNz9sm9; Thu, 15 Aug 2024 11:09:45 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1723712985; 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=c/Cm76OCsVt/jPPWiybltnErHwWq1YcAHCumkSV/l5LKaePNcC2BzBsm8KQ6L0X8fdfyn8 EeBOSKS8RDJjFGfJ75F7VMmHGKAAdolGxU6fzaXPbt52fdYHipcBlC79eAtGJCTKXBO/bY MFnXDpERLCOsPUS71Crm9Sc2s9EgbAGYskJDH8MzKHDEtR57r1yW+izLXkszYZYVwaODlj wVM8cbzkXGLidGKw+PGYDsfFbIxwBSDUlbWqOwnvWDdkBmPhI9GTHo3QZyEDOHc6uqa64h mE0P2ifINx+h2Xtmwb9M0l4xCapVFXOjIamAyb0if99OqJgLW8lTsaT7s9z8BA== From: "Pankaj Raghav (Samsung)" To: brauner@kernel.org, akpm@linux-foundation.org Cc: chandan.babu@oracle.com, linux-fsdevel@vger.kernel.org, djwong@kernel.org, hare@suse.de, gost.dev@samsung.com, linux-xfs@vger.kernel.org, kernel@pankajraghav.com, hch@lst.de, david@fromorbit.com, Zi Yan , yang@os.amperecomputing.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, willy@infradead.org, john.g.garry@oracle.com, cl@os.amperecomputing.com, p.raghav@samsung.com, mcgrof@kernel.org, ryan.roberts@arm.com, Dave Chinner Subject: [PATCH v12 09/10] xfs: make the calculation generic in xfs_sb_validate_fsb_count() Date: Thu, 15 Aug 2024 11:08:48 +0200 Message-ID: <20240815090849.972355-10-kernel@pankajraghav.com> In-Reply-To: <20240815090849.972355-1-kernel@pankajraghav.com> References: <20240815090849.972355-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 78FDCC000A X-Stat-Signature: t7i7z7ssjay8qsgbii61eccbw5zseg7g X-Rspam-User: X-HE-Tag: 1723712988-26065 X-HE-Meta: U2FsdGVkX1+0L+D3cRcGIf8gQlLQq55dh+n/t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M31ohkgqwgKOpKBUR/RZ87FVLtR/ScwcveZXaQj/S2JHouWA6u5cGJLGOHQ/XZTR41ZmXg6JWTZFUj3wcVIty206BkFIba/RSTzLkfY32IqhlVmmQ6fRDDe90L3/3CzclMwrr173U78BQqP0v6fJIwj3tMDk8S1ctseqZTCa1nKUhAtw5XFAUnaDgMr5LlgtfH4c90j6ueD3ECOq7AdEbhpe87/lMKPceOC6ktgtU04RGmv1sLoYT2T0/zAwmyG8I9SYJehASepihc= 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 Thu Aug 15 09:08: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: 13764603 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 1BAD4C52D7D for ; Thu, 15 Aug 2024 09:09:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A17B86B00B5; Thu, 15 Aug 2024 05:09:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9C7C96B00B6; Thu, 15 Aug 2024 05:09:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8417E6B00B7; Thu, 15 Aug 2024 05:09:54 -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 634A46B00B5 for ; Thu, 15 Aug 2024 05:09:54 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id D429DC140C for ; Thu, 15 Aug 2024 09:09:53 +0000 (UTC) X-FDA: 82453907466.23.9B94194 Received: from mout-p-201.mailbox.org (mout-p-201.mailbox.org [80.241.56.171]) by imf08.hostedemail.com (Postfix) with ESMTP id EBD52160025 for ; Thu, 15 Aug 2024 09:09:51 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=0TB37fgt; spf=pass (imf08.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=1723712919; 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=YXkoBosXMLIYgJIKlAekj9Nug/tJBjbP9UExZYT9KcY=; b=WBm71gCGbltu1qrIiDsxrMGMH/umBC3n71KObkc5xMWtFFxZ95icEf0SlU8Oiyy8JFUzPv A4IbPW9sWox6UGwkQRWF7l5ft3OotROffsR70t964YE/zCKTRJBCKmd68TH+sf7UiqaGnf m6JqIkb7cDu1E+EtQcljXC+fAT8rqYE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723712919; a=rsa-sha256; cv=none; b=bwPS4UdIkqs8o42JVlmiYUSk3ewaATA3s6viPHcFGFioVXrjC9hs8VOLJczsajSHwTpPji au+zibuEHPToG7NgI3un9OfYpUejNHCGEUOVjz9HGt8JmNDbFZU0TAI8k4TWWk661Yx9lc xBhUOadfXXQOYYN7t2YDYDms9lWRXQE= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=0TB37fgt; spf=pass (imf08.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 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 4Wkzph4P1Lz9t1S; Thu, 15 Aug 2024 11:09:48 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1723712988; 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=YXkoBosXMLIYgJIKlAekj9Nug/tJBjbP9UExZYT9KcY=; b=0TB37fgtNhiVqU/8NCdQbFcB3fK7yAm735qgwS0jp0y3MyV6bZyZtOtOOXR83wYXC63RAC M6c7Ycpkxz1Yt/SOM7wWXHEhBKPQbzbKo3aJTvHG1TTORTkLayMmUXPi93ZpWMlHgh7cZG FAXhAWGN6Ow/T+mUNQfHospGnJETKbNfcxRN4vvCr8x/7HD9dWOFzqEGhHqLFVLgXJ7zWc 3LPqXX6gNzI8O/99IAOV1DQYdfmjkrvAInhmUhS7QxyQKaSIMi7RG3VvIA8Unn3pOabwVP i1sB1ogTdacmzF7rGGHuYZ1rndTt3AZ7VEzcpqQl9iWcyoi4OVm3+YHs49kupw== From: "Pankaj Raghav (Samsung)" To: brauner@kernel.org, akpm@linux-foundation.org Cc: chandan.babu@oracle.com, linux-fsdevel@vger.kernel.org, djwong@kernel.org, hare@suse.de, gost.dev@samsung.com, linux-xfs@vger.kernel.org, kernel@pankajraghav.com, hch@lst.de, david@fromorbit.com, Zi Yan , yang@os.amperecomputing.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, willy@infradead.org, john.g.garry@oracle.com, cl@os.amperecomputing.com, p.raghav@samsung.com, mcgrof@kernel.org, ryan.roberts@arm.com, Dave Chinner Subject: [PATCH v12 10/10] xfs: enable block size larger than page size support Date: Thu, 15 Aug 2024 11:08:49 +0200 Message-ID: <20240815090849.972355-11-kernel@pankajraghav.com> In-Reply-To: <20240815090849.972355-1-kernel@pankajraghav.com> References: <20240815090849.972355-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Stat-Signature: 675916xnjn6wah54cet4915cwz4566ui X-Rspamd-Queue-Id: EBD52160025 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1723712991-476814 X-HE-Meta: U2FsdGVkX1+/EnTk8Jd6QqUKSzOdQnlja9CsXnN2j7u7Rw0zzEzyi2TKQkYD+Bq0BBvVMOUE9c6vVhwrsE+bJJDdC1c1Nrj3nA8I0+1XMulwUw699t3i0IvIScXCy1ihPeOp02hTfhsDwug2U0qozc70zRPyP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fLahuEcQIAerTmzHBOGv8UtFZkQZDiW+aziUNuiHYBCMdGHqAASJxT5WFvUkj7vGY18DfRag== 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 210481b03fdb4..8cd76a01b543f 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.