From patchwork Fri Mar 1 16:44:32 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: 13578739 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 721EEC5478C for ; Fri, 1 Mar 2024 16:44:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 029F96B0081; Fri, 1 Mar 2024 11:44:58 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id F1C646B0082; Fri, 1 Mar 2024 11:44:57 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DE4E06B0083; Fri, 1 Mar 2024 11:44:57 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id CBBC36B0081 for ; Fri, 1 Mar 2024 11:44:57 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id AB5FC1C1761 for ; Fri, 1 Mar 2024 16:44:57 +0000 (UTC) X-FDA: 81849044634.17.9C62ECA Received: from mout-p-201.mailbox.org (mout-p-201.mailbox.org [80.241.56.171]) by imf17.hostedemail.com (Postfix) with ESMTP id 145F940018 for ; Fri, 1 Mar 2024 16:44:55 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=fNWUnrtg; spf=pass (imf17.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.171 as permitted sender) smtp.mailfrom=me@pankajraghav.com; dmarc=pass (policy=quarantine) header.from=pankajraghav.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709311496; a=rsa-sha256; cv=none; b=pJawqD8ydjeGLAIGWA95LFuXdryESCZdpbwRHMX01u30MUBlyZrnkZSOn/LdQf/zX29uTo yO4D3tfgjGPw4QA753qsgS6HXHbESt99nc9O9CnAgHBmQLhoSJPW6KNnmMBddpBPqIGvEQ qB3D1HSLb9YbXvkEO48VVdGDUGEEwmQ= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=fNWUnrtg; spf=pass (imf17.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.171 as permitted sender) smtp.mailfrom=me@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=1709311496; 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=O82T73AIK6qGhlYorGzOupTzei7wEk6+FPA8o3URJUE=; b=wAsdmEpncDO+FqjSlpaw9Y1CVaRu3DA0dQKlwId20eMerDYq2nYR2Ds3Ft+aooeccNFGqK M2UklbjoVWT7m44EtaO6N+KLdo1tSKKtrRDTo57lOJamo6TxN2rRmn0pui95Xe+1wV073w mp9F3v0UHLmqWgzBTxqiDgAIVV2AF5Q= 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 4TmYpr21J9z9t8W; Fri, 1 Mar 2024 17:44:52 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1709311492; 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=O82T73AIK6qGhlYorGzOupTzei7wEk6+FPA8o3URJUE=; b=fNWUnrtgSvHwlKswQCDBdMZ99aHEG9IE0hNSW5jexFvvQkpzgpzjuETR588Aq25oYo7zKm 8/eeN0UkSi/gyP8pjyFHWVKgnqR3ti1wvcPmdX3uCpNLcdx7pAw4DTQ/lkD/MWS4JI7jCc lWQn7nG2EGhY3dAQjA0kSFrC6IVJyl6Kx/V1NZAN5ZMSUU8rpTjjNQ68eAgTbbYXLDlU+D nunEh6RLwLQd9tGcIVuB9KmtTSEiCFBkw/cg0DX8LZECOWq5I6YzTySOTqCL7PStVsWUB/ V3TcSHJAm7jDZ6M3hPNRYHqx5COZfIg5tVkt5O731DxQR8wWHdF2+4rgwYKw7A== From: "Pankaj Raghav (Samsung)" To: linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org Cc: djwong@kernel.org, mcgrof@kernel.org, linux-mm@kvack.org, hare@suse.de, david@fromorbit.com, akpm@linux-foundation.org, gost.dev@samsung.com, linux-kernel@vger.kernel.org, chandan.babu@oracle.com, willy@infradead.org Subject: [PATCH v2 01/13] mm: Support order-1 folios in the page cache Date: Fri, 1 Mar 2024 17:44:32 +0100 Message-ID: <20240301164444.3799288-2-kernel@pankajraghav.com> In-Reply-To: <20240301164444.3799288-1-kernel@pankajraghav.com> References: <20240301164444.3799288-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 145F940018 X-Stat-Signature: dxpdxo97g53xs4yfhcdgdumdakwirfwz X-Rspam-User: X-HE-Tag: 1709311495-252991 X-HE-Meta: U2FsdGVkX19vVEO6kNWlrRgq2MUckMYCOZ0XAfz4jJJuA49V3I6lCoi/pCn+cWyBs/lMRtxYrUPbSx933gHHTn1wDNXSjy2Q6Qjj81Bn76pSJGRHIT0MViEtKk9EofmQ5zOEwmHooPCeIR4NkuJEDixSKeM4M+VEa60KjFESQD3iEOLPZK5gn69ROBn0lPeFlLOEpVl2tN49Z8Bf7UK2ESqJikAJtrxys6Jgf/tPqqpLkTrqwqs/Q+HOuV3cYvicOEYFsdpg3QdQi5azExEqDvWysatWrHASkiCuJFOoEKUdCe7EjpVQWvOFiPBUSJ19Iq/plwdilBf0SwxgnnkjInx2nJL06qlmhEcGd1zcaaNlrll4oKksx0F9X03Z5GnzF/nVU8QtvfzUG7qXmpQdYQvqqYUA+rA8tR4ASCCWbbH/fK9Jq5DVILIuhY2Cg9O0kVq87eeFMUOajQ4G+g+oC1nqi5qDNghlBBoaoml47adB/HLzxJn3UZCnKNLFdop16uSR4ndY+3zgwxtxeYDfwJwbH2MY1dw9qSjAdyWWVM01jfKcOGT1c3xFqL0ZchdD/7zmW1v1pOcMdGZlKReyNbTmfFtR0xiPMTBg/Td+hnz46YpkOYDcOKaSdLrErvVQjiFOwfvVFM4GQrufEAcpSIcEnUy3ibYbCRy5ln8ueGqqrnnZBZce/hUU7fFIkWOoKj3lGW9cODds6mXF41OXABtWU+aiAexiS3kikptYpjHyKXC1nNY3oUCpOxXjWGPNcXI5eKE0CXaGmFDrFK4PZBAEGKpLzG55LxL4rCk7ZO1iNrxv36V0F2ccs9HMiJB2mOvU+P9Y8Au0LUBSG1elHeqtmX7M1BhUcPEhJrm4QhOIDnSFjNYxNLXgEy+2XlhHo+CcS4XsAEeT5+2JC/NtsrpcENjg5WECuiuf6eX4tIyT9qJR9gJ/PJtwtwSnIC6c61RA3RhWc59CUAXgFwF GxAwtmcZ 7Rju6jVM1N43xRpOxi31oDppQgkHv8WU9dFUJmgV84aGOkDT8MDrHiWJYfGQl/zbC+fcKB+OZOSEOOusshqdTZFqzyrvTlr8zXHnS X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: "Matthew Wilcox (Oracle)" Folios of order 1 have no space to store the deferred list. This is not a problem for the page cache as file-backed folios are never placed on the deferred list. All we need to do is prevent the core MM from touching the deferred list for order 1 folios and remove the code which prevented us from allocating order 1 folios. Link: https://lore.kernel.org/linux-mm/90344ea7-4eec-47ee-5996-0c22f42d6a6a@google.com/ Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Hannes Reinecke --- include/linux/huge_mm.h | 7 +++++-- mm/filemap.c | 2 -- mm/huge_memory.c | 23 ++++++++++++++++++----- mm/internal.h | 4 +--- mm/readahead.c | 3 --- 5 files changed, 24 insertions(+), 15 deletions(-) diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h index 5adb86af35fc..916a2a539517 100644 --- a/include/linux/huge_mm.h +++ b/include/linux/huge_mm.h @@ -263,7 +263,7 @@ unsigned long thp_vma_allowable_orders(struct vm_area_struct *vma, unsigned long thp_get_unmapped_area(struct file *filp, unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags); -void folio_prep_large_rmappable(struct folio *folio); +struct folio *folio_prep_large_rmappable(struct folio *folio); bool can_split_folio(struct folio *folio, int *pextra_pins); int split_huge_page_to_list(struct page *page, struct list_head *list); static inline int split_huge_page(struct page *page) @@ -410,7 +410,10 @@ static inline unsigned long thp_vma_allowable_orders(struct vm_area_struct *vma, return 0; } -static inline void folio_prep_large_rmappable(struct folio *folio) {} +static inline struct folio *folio_prep_large_rmappable(struct folio *folio) +{ + return folio; +} #define transparent_hugepage_flags 0UL diff --git a/mm/filemap.c b/mm/filemap.c index 750e779c23db..2b00442b9d19 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -1912,8 +1912,6 @@ struct folio *__filemap_get_folio(struct address_space *mapping, pgoff_t index, gfp_t alloc_gfp = gfp; err = -ENOMEM; - if (order == 1) - order = 0; if (order > 0) alloc_gfp |= __GFP_NORETRY | __GFP_NOWARN; folio = filemap_alloc_folio(alloc_gfp, order); diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 94c958f7ebb5..81fd1ba57088 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -788,11 +788,15 @@ struct deferred_split *get_deferred_split_queue(struct folio *folio) } #endif -void folio_prep_large_rmappable(struct folio *folio) +struct folio *folio_prep_large_rmappable(struct folio *folio) { - VM_BUG_ON_FOLIO(folio_order(folio) < 2, folio); - INIT_LIST_HEAD(&folio->_deferred_list); + if (!folio || !folio_test_large(folio)) + return folio; + if (folio_order(folio) > 1) + INIT_LIST_HEAD(&folio->_deferred_list); folio_set_large_rmappable(folio); + + return folio; } static inline bool is_transparent_hugepage(struct folio *folio) @@ -3082,7 +3086,8 @@ int split_huge_page_to_list(struct page *page, struct list_head *list) /* Prevent deferred_split_scan() touching ->_refcount */ spin_lock(&ds_queue->split_queue_lock); if (folio_ref_freeze(folio, 1 + extra_pins)) { - if (!list_empty(&folio->_deferred_list)) { + if (folio_order(folio) > 1 && + !list_empty(&folio->_deferred_list)) { ds_queue->split_queue_len--; list_del(&folio->_deferred_list); } @@ -3133,6 +3138,9 @@ void folio_undo_large_rmappable(struct folio *folio) struct deferred_split *ds_queue; unsigned long flags; + if (folio_order(folio) <= 1) + return; + /* * At this point, there is no one trying to add the folio to * deferred_list. If folio is not in deferred_list, it's safe @@ -3158,7 +3166,12 @@ void deferred_split_folio(struct folio *folio) #endif unsigned long flags; - VM_BUG_ON_FOLIO(folio_order(folio) < 2, folio); + /* + * Order 1 folios have no space for a deferred list, but we also + * won't waste much memory by not adding them to the deferred list. + */ + if (folio_order(folio) <= 1) + return; /* * The try_to_unmap() in page reclaim path might reach here too, diff --git a/mm/internal.h b/mm/internal.h index f309a010d50f..5174b5b0c344 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -419,9 +419,7 @@ static inline struct folio *page_rmappable_folio(struct page *page) { struct folio *folio = (struct folio *)page; - if (folio && folio_order(folio) > 1) - folio_prep_large_rmappable(folio); - return folio; + return folio_prep_large_rmappable(folio); } static inline void prep_compound_head(struct page *page, unsigned int order) diff --git a/mm/readahead.c b/mm/readahead.c index 2648ec4f0494..369c70e2be42 100644 --- a/mm/readahead.c +++ b/mm/readahead.c @@ -516,9 +516,6 @@ void page_cache_ra_order(struct readahead_control *ractl, /* Don't allocate pages past EOF */ while (index + (1UL << order) - 1 > limit) order--; - /* THP machinery does not support order-1 */ - if (order == 1) - order = 0; err = ra_alloc_folio(ractl, index, mark, order, gfp); if (err) break; From patchwork Fri Mar 1 16:44:33 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: 13578740 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 D096BC5478C for ; Fri, 1 Mar 2024 16:45:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 645C96B0083; Fri, 1 Mar 2024 11:45:01 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5CDC76B0085; Fri, 1 Mar 2024 11:45:01 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 42A7B6B0087; Fri, 1 Mar 2024 11:45:01 -0500 (EST) 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 2A1726B0083 for ; Fri, 1 Mar 2024 11:45:01 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id EB86912033A for ; Fri, 1 Mar 2024 16:45:00 +0000 (UTC) X-FDA: 81849044760.10.C91FB55 Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [80.241.56.172]) by imf16.hostedemail.com (Postfix) with ESMTP id 4EBE8180017 for ; Fri, 1 Mar 2024 16:44:59 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=bL8wu3wN; spf=pass (imf16.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.172 as permitted sender) smtp.mailfrom=me@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=1709311499; 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=1cELEozXOYCd1Af2ZXfddDuv3Odm1CWuSBqyYDa15DQ=; b=3lqkQ6fab48S4+OGcMbwJ+Azr+XOg4K9RoHb6tXXZkZgUBX7XP85v6z2qV0QJ/TLUDXeDA 6qIRB/AgSyK6tXsGiPLUclmpudQJrwIUsvPuBbgZNK8ulNi28b0OCWOh/oSKu/KYt0LDxv 2FcHwexvIGDLfMyZliC7MLhsLCr0epw= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709311499; a=rsa-sha256; cv=none; b=i6t0+uPE1qbGb814mLTajSFFuYvsT10YqTQW4lzo8zPSjLjpEwBcbjWl+fGfKFTCc/AxML DJp0hNAaN30AT+8zzGuPltFaR2WKG8j7sNfqdk/FiE0WKOxiSpmj3g+ekfcdej2iGReZIj xbAzJnsk/9beQuQ2rzuJlsqy/hEz0xA= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=bL8wu3wN; spf=pass (imf16.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.172 as permitted sender) smtp.mailfrom=me@pankajraghav.com; dmarc=pass (policy=quarantine) header.from=pankajraghav.com 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 4TmYpv5Blmz9tW4; Fri, 1 Mar 2024 17:44:55 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1709311495; 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=1cELEozXOYCd1Af2ZXfddDuv3Odm1CWuSBqyYDa15DQ=; b=bL8wu3wNKf1pmc8SzUQPy23UfUZ0BwEQ8+fDKjHUH8N+j2+VBUy1OSkewMRkC5mKZ/EWvp rQuqv1J8e6Vp3ePcwqreNd8Np8dNup0i92iIQy96VkqcjsyAawLjiJLYav4gsGGdCUNmcA 2lGI++nSQTqWERFoQA7n7WWLsY9t5UfQJiaX3aM0PHMZ1pJ+ckJtG93Tf9a5Cm/n06wnT9 r0yuN/PlrhcScbNCXn5iUOCg5Nt2ipmOpo8lK8BVQhqzgMJWClHr3TjBA7+wIS08h+1l3a s22J69b1C9/Y8dEvw0GLItEqLOMZw1U5cE+ygJdpzWGZ+pPT5Kpw6pzwE1ZHZA== From: "Pankaj Raghav (Samsung)" To: linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org Cc: djwong@kernel.org, mcgrof@kernel.org, linux-mm@kvack.org, hare@suse.de, david@fromorbit.com, akpm@linux-foundation.org, gost.dev@samsung.com, linux-kernel@vger.kernel.org, chandan.babu@oracle.com, willy@infradead.org, Pankaj Raghav Subject: [PATCH v2 02/13] fs: Allow fine-grained control of folio sizes Date: Fri, 1 Mar 2024 17:44:33 +0100 Message-ID: <20240301164444.3799288-3-kernel@pankajraghav.com> In-Reply-To: <20240301164444.3799288-1-kernel@pankajraghav.com> References: <20240301164444.3799288-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 4EBE8180017 X-Rspam-User: X-Stat-Signature: 7ndhj4zw5et4ufpph8wre9ry8d4epcyg X-Rspamd-Server: rspam03 X-HE-Tag: 1709311499-352479 X-HE-Meta: U2FsdGVkX1+T5QCAcTAeLXQqo9u1NDyHd2gfl+LENTv7JzWk3NFtRDIeEskPfXPBpXB38O75TVoL5Zib/QX20kpLRTYqTFDIjsNqEEWDppKYT0kGU8zixPV3Q8NWdP+HWBkuupVcrhQrlvnlJuAntx4/EkV9qihUCN9bnCyM/VO7PV+qdBmBJGhk2SecsEKUG1MAnqlhpEQpyfaijyIK5gy9iC2ge2ji3q2bhFeYIHYdhNOqvHbntGq8XwqBKXRrqbFVjo0wd3yeAzaS3eFxJD2/blRZlBoKN48DzVfky0LVOIIbt7uqy2B7jGd+FwMvWkfNHIdAm+FKeUz+dmyjscnFHXX5goONbfFS6G2K7p4E6xGNL3PHxaQb02F8/VCFqihHQg4lDNmiRo/M+PggLTCQMy0I0Pzs/djghOyHqRgomoG8GVMA7XsUjPZ4tsA+NIc1bDwHnhy6k16rIlGpgHg+1bec0tBecSia9kzH6y9yI9BRk+sf/6+YOvt7rixtjjBIIxso7HQxyPCSDrGdtZZ5n7vyL1ZFR0TJGNaHd9yKORhJLMzPyXIoONztWNe8L04ijOaQnIzBVH5IeEC0ORFGtRdNO5+5sR14WULeU9S5QIrUAUYjStDVgrYaPReY/S+K/sk95nNQVQf2q56xrs5lQI6rFa7zDjfMZC5kCpgilpgZ5TJYhOqfNajCn9ua6Q0gnaWjjI6v7IT2hAMAaUYrbGclOe+VjqODk1b8ewoZ//ecj9bF500WVIp4fwsGYBWRG1bbuVIm+UZj5M8hsSbd39Wr2HoeGtmvxxdZoCvfZPn7fr8VHy3S1WD1ttqVdFaRQhzyih4ac/vTmZ+EHq3YYFWx9l1gSVTHd5ESoa/ls1H+cLozX24di4K6i5ih4R26UZ91bkJxOWdINwWXseEdPWheXQFTXJD0gAucpFwWKcKjzaorH8YtpsnfrNq5XR+e8AB2B8T73nIzOSh ViiszYjC JhtoejBH40aRW9tX0uMfuyq81pSOyy46MJwpVCXT/AcUf/AmvIUWr1HELMIcXbU9sRSLF010ccJQxAWgDDXlfPGEZxBvegU/I9Wnv X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: "Matthew Wilcox (Oracle)" Some filesystems want to be able to ensure that folios that are added to the page cache are at least a certain size. Add mapping_set_folio_min_order() to allow this level of control. Signed-off-by: Matthew Wilcox (Oracle) Co-developed-by: Pankaj Raghav Signed-off-by: Pankaj Raghav Signed-off-by: Luis Chamberlain Reviewed-by: Hannes Reinecke --- include/linux/pagemap.h | 100 ++++++++++++++++++++++++++++++++-------- 1 file changed, 80 insertions(+), 20 deletions(-) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index 2df35e65557d..fc8eb9c94e9c 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -202,13 +202,18 @@ enum mapping_flags { AS_EXITING = 4, /* final truncate in progress */ /* writeback related tags are not used */ AS_NO_WRITEBACK_TAGS = 5, - AS_LARGE_FOLIO_SUPPORT = 6, - AS_RELEASE_ALWAYS, /* Call ->release_folio(), even if no private data */ - AS_STABLE_WRITES, /* must wait for writeback before modifying + AS_RELEASE_ALWAYS = 6, /* Call ->release_folio(), even if no private data */ + AS_STABLE_WRITES = 7, /* must wait for writeback before modifying folio contents */ - AS_UNMOVABLE, /* The mapping cannot be moved, ever */ + AS_FOLIO_ORDER_MIN = 8, + AS_FOLIO_ORDER_MAX = 13, /* Bit 8-17 are used for FOLIO_ORDER */ + AS_UNMOVABLE = 18, /* The mapping cannot be moved, ever */ }; +#define AS_FOLIO_ORDER_MIN_MASK 0x00001f00 +#define AS_FOLIO_ORDER_MAX_MASK 0x0003e000 +#define AS_FOLIO_ORDER_MASK (AS_FOLIO_ORDER_MIN_MASK | AS_FOLIO_ORDER_MAX_MASK) + /** * mapping_set_error - record a writeback error in the address_space * @mapping: the mapping in which an error should be set @@ -344,9 +349,47 @@ static inline void mapping_set_gfp_mask(struct address_space *m, gfp_t mask) m->gfp_mask = mask; } +/* + * There are some parts of the kernel which assume that PMD entries + * are exactly HPAGE_PMD_ORDER. Those should be fixed, but until then, + * limit the maximum allocation order to PMD size. I'm not aware of any + * assumptions about maximum order if THP are disabled, but 8 seems like + * a good order (that's 1MB if you're using 4kB pages) + */ +#ifdef CONFIG_TRANSPARENT_HUGEPAGE +#define MAX_PAGECACHE_ORDER HPAGE_PMD_ORDER +#else +#define MAX_PAGECACHE_ORDER 8 +#endif + +/* + * mapping_set_folio_min_order() - Set the minimum folio order + * @mapping: The address_space. + * @min: Minimum folio order (between 0-MAX_PAGECACHE_ORDER inclusive). + * + * The filesystem should call this function in its inode constructor to + * indicate which base size 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_min_order(struct address_space *mapping, + unsigned int min) +{ + if (min > MAX_PAGECACHE_ORDER) + min = MAX_PAGECACHE_ORDER; + + mapping->flags = (mapping->flags & ~AS_FOLIO_ORDER_MASK) | + (min << AS_FOLIO_ORDER_MIN) | + (MAX_PAGECACHE_ORDER << AS_FOLIO_ORDER_MAX); +} + /** * mapping_set_large_folios() - Indicate the file supports large folios. - * @mapping: The file. + * @mapping: The address_space. * * The filesystem should call this function in its inode constructor to * indicate that the VFS can use large folios to cache the contents of @@ -357,7 +400,37 @@ static inline void mapping_set_gfp_mask(struct address_space *m, gfp_t mask) */ static inline void mapping_set_large_folios(struct address_space *mapping) { - __set_bit(AS_LARGE_FOLIO_SUPPORT, &mapping->flags); + mapping_set_folio_min_order(mapping, 0); +} + +static inline unsigned int mapping_max_folio_order(struct address_space *mapping) +{ + return (mapping->flags & AS_FOLIO_ORDER_MAX_MASK) >> AS_FOLIO_ORDER_MAX; +} + +static inline unsigned int mapping_min_folio_order(struct address_space *mapping) +{ + return (mapping->flags & AS_FOLIO_ORDER_MIN_MASK) >> AS_FOLIO_ORDER_MIN; +} + +static inline unsigned long mapping_min_folio_nrpages(struct address_space *mapping) +{ + return 1UL << mapping_min_folio_order(mapping); +} + +/** + * mapping_align_start_index() - Align starting index based on the min + * folio order of the page cache. + * @mapping: The address_space. + * + * Ensure the index used is aligned to the minimum folio order when adding + * new folios to the page cache by rounding down to the nearest minimum + * folio number of pages. + */ +static inline pgoff_t mapping_align_start_index(struct address_space *mapping, + pgoff_t index) +{ + return round_down(index, mapping_min_folio_nrpages(mapping)); } /* @@ -367,7 +440,7 @@ static inline void mapping_set_large_folios(struct address_space *mapping) static inline bool mapping_large_folio_support(struct address_space *mapping) { return IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE) && - test_bit(AS_LARGE_FOLIO_SUPPORT, &mapping->flags); + (mapping_max_folio_order(mapping) > 0); } static inline int filemap_nr_thps(struct address_space *mapping) @@ -528,19 +601,6 @@ static inline void *detach_page_private(struct page *page) return folio_detach_private(page_folio(page)); } -/* - * There are some parts of the kernel which assume that PMD entries - * are exactly HPAGE_PMD_ORDER. Those should be fixed, but until then, - * limit the maximum allocation order to PMD size. I'm not aware of any - * assumptions about maximum order if THP are disabled, but 8 seems like - * a good order (that's 1MB if you're using 4kB pages) - */ -#ifdef CONFIG_TRANSPARENT_HUGEPAGE -#define MAX_PAGECACHE_ORDER HPAGE_PMD_ORDER -#else -#define MAX_PAGECACHE_ORDER 8 -#endif - #ifdef CONFIG_NUMA struct folio *filemap_alloc_folio(gfp_t gfp, unsigned int order); #else From patchwork Fri Mar 1 16:44:34 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: 13578741 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 5B59AC5475B for ; Fri, 1 Mar 2024 16:45:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C5F3A6B0087; Fri, 1 Mar 2024 11:45:04 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C0F736B0088; Fri, 1 Mar 2024 11:45:04 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A61626B0089; Fri, 1 Mar 2024 11:45:04 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 93FA06B0087 for ; Fri, 1 Mar 2024 11:45:04 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 5DF7F1606E5 for ; Fri, 1 Mar 2024 16:45:04 +0000 (UTC) X-FDA: 81849044928.06.A459559 Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [80.241.56.172]) by imf23.hostedemail.com (Postfix) with ESMTP id 9D27B140023 for ; Fri, 1 Mar 2024 16:45:02 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b="HN/hGMWj"; dmarc=pass (policy=quarantine) header.from=pankajraghav.com; spf=pass (imf23.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.172 as permitted sender) smtp.mailfrom=me@pankajraghav.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1709311502; 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=BCQodYVgPvK7zJztO22OSwzZBWMPBsGjwa0dIcNZkr8=; b=jeWH444rmJ1FWsF7nMg1avRoFtKH3efwbvHHaNI0gkI1JAFSAcYOXlNAs+YZbbGO7XD4be 2otpKkVDrGKPfp7A+9Nr//LbR46TsA4Gb/a/kOLfHEE9jXRUxsMBmDDfTQFUQgIuRmFYXw plvjm7U3iBTxDocNIszC/AzCE3cV0Lg= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b="HN/hGMWj"; dmarc=pass (policy=quarantine) header.from=pankajraghav.com; spf=pass (imf23.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.172 as permitted sender) smtp.mailfrom=me@pankajraghav.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709311502; a=rsa-sha256; cv=none; b=6eoks9q59vXtoHl2oEz49yei0WP0pxKbxYDcG3UxNbtqoe/l6KxPuM/rPlEtc67hQZj0va /O2YXv1iZ5E6mjnANeTksx15EHxp6pbsYp6z+SawHGWGZos23+E8VOnTxF726mULhyzKZk ylEfPmNa+ZfnyFBd/GLQqwgW1BPgXRU= 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-202.mailbox.org (Postfix) with ESMTPS id 4TmYpz35Y1z9t7Z; Fri, 1 Mar 2024 17:44:59 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1709311499; 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=BCQodYVgPvK7zJztO22OSwzZBWMPBsGjwa0dIcNZkr8=; b=HN/hGMWj2gC5ZojLre62sCdhsS18t89JR0BD9LJzX7iJ/Hqx9zmSsQtDrhYImhyoAxGAO/ ruoKmN06+/h7LtqfkBwARYmoZ0+J8PfLGGkOmqyqs2wo8Ib04XGqutAvFrw9JWq1uMImwZ 5J4jlTrgdOVujUjaWDNOgaDR6C9KMlCIw/5oCv6ERInUn8FOInxxcRlA0aZecyczCv1d9D MkEyl3pqTJHM2TU2ErxfE3hE5dV3hL3yj/GVot+TyNb6m9tcmVWrVLRdLf/Pd3C7qUD5UW 3Dv2OCudXJiZqfb5sxfmf6tQheb+gjipAbANPdwH71pSHy4a3Jgu/Ikv8G8i+g== From: "Pankaj Raghav (Samsung)" To: linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org Cc: djwong@kernel.org, mcgrof@kernel.org, linux-mm@kvack.org, hare@suse.de, david@fromorbit.com, akpm@linux-foundation.org, gost.dev@samsung.com, linux-kernel@vger.kernel.org, chandan.babu@oracle.com, willy@infradead.org, Pankaj Raghav Subject: [PATCH v2 03/13] filemap: align the index to mapping_min_order in the page cache Date: Fri, 1 Mar 2024 17:44:34 +0100 Message-ID: <20240301164444.3799288-4-kernel@pankajraghav.com> In-Reply-To: <20240301164444.3799288-1-kernel@pankajraghav.com> References: <20240301164444.3799288-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 9D27B140023 X-Stat-Signature: 3akrqewquqydr7ck8kaog5agsppkq66x X-Rspam-User: X-HE-Tag: 1709311502-847331 X-HE-Meta: U2FsdGVkX1/rYTo9MyxzL7h9lZpCM3F3yQIgv0BSzHL5ijF6FetcnBUpytOu24ukBgO6LNw95eFdxSKIo0wh4bbIEp9FvNRErin7TqoklyFDKOwfnykpLAQWVN8dvHZGReH+SblDP0F4CIiVZAEWb1m+/Vd73KQbUuRoH8085eEu7vg6Xh6CiHv3/YOhswhmaE2yWELonqvYI0vVxWCl3Y5MWhVefvRD7jkyob8gBkxq2CRy93SGGr8KRISMYOyd0pxkIpsejJoKdqYr67/Y29kelQpXGntMy/HhVapPoCxRGWfy26idZHJ1A/KPEImbXe2a8DdlTp9c8rMO5injNwArto4G4Vzzeir08UrjiX/19n7Mr2hw8gA6N6eLmEev5k4TQXAswGmWrGHeAFg6AEqxzff5MHJB+tGi5yb1M6SzpDa1FLxSXtcrykeJ4c4KW/6whw87aO5WN22JO94o4LoJiGdQ1QhlaeG/AkCCqOV3iBb+w0OvUhqBYq3iCFyDcu8hJCgp5VYA0D36hGIxaAZLHu9CQ3/XrX3hrcu/7/HL9fiVs3JVCeR04ze/5ik8vhUP99V/IQpvyFRhx9eg67rHN4+/aG5N91elyBEZn4VMo2vFJG4XO6XPzDyA22yVi/uwnwjAx7rzrurROmBrRTt2MwAtb2VVOs1poLTUctHP/YAOCI9f4bQFuCo2OK7/saqQQ1ezmQ2sKzvtoyl1vIpfxmCz6EMFvhleRVP/zp0ajIC8Bc4ggY/RjmmjY+IhO6GFzJlekwCvbRQCS6LpBYAwAtXqCW0c6xvz1E/nNPM9akP6KFTgwTWPTLIBc+6JX8UQwjElq1ODTKeeL4/YOcM5/9Zw1oPxVBCH6Gp8dJsSl4q6TgAkV6We9ou8qZTSlb28qTfiMgGFbj0m4nCVFNPT9pI2gi5Vh6QC7d+mD655JJ6hLa2N0d1bTUG22JZVd3UhkfuBS40BQciodmi rbKbxFxF G6BPUQ8y+2KKUOXzH47yn79nbhEUhCeZHzHTDgRM63O5lV/Wos/pY3nXSAX5eNsKEXZAmc8Xdx+iNWa6bewilyHgyjZnlW15FVe6TeyPQEgenIZyhUuqiWs42IVTBBD/8mEWbKcQ+e4ypGs8= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Luis Chamberlain Supporting mapping_min_order implies that we guarantee each folio in the page cache has at least an order of mapping_min_order. So when adding new folios to the page cache we must ensure the index used is aligned to the mapping_min_order as the page cache requires the index to be aligned to the order of the folio. A higher order folio than min_order by definition is a multiple of the min_order. If an index is aligned to an order higher than a min_order, it will also be aligned to the min order. This effectively introduces no new functional changes when min order is not set other than a few rounding computations that should result in the same value. Signed-off-by: Luis Chamberlain Signed-off-by: Pankaj Raghav --- include/linux/pagemap.h | 10 +++++++++- mm/filemap.c | 16 ++++++++++------ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index fc8eb9c94e9c..b3cf8ef89826 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -1328,6 +1328,14 @@ struct readahead_control { ._index = i, \ } +#define DEFINE_READAHEAD_ALIGNED(ractl, f, r, m, i) \ + struct readahead_control ractl = { \ + .file = f, \ + .mapping = m, \ + .ra = r, \ + ._index = mapping_align_start_index(m, i), \ + } + #define VM_READAHEAD_PAGES (SZ_128K / PAGE_SIZE) void page_cache_ra_unbounded(struct readahead_control *, @@ -1356,7 +1364,7 @@ void page_cache_sync_readahead(struct address_space *mapping, struct file_ra_state *ra, struct file *file, pgoff_t index, unsigned long req_count) { - DEFINE_READAHEAD(ractl, file, ra, mapping, index); + DEFINE_READAHEAD_ALIGNED(ractl, file, ra, mapping, index); page_cache_sync_ra(&ractl, req_count); } diff --git a/mm/filemap.c b/mm/filemap.c index 2b00442b9d19..96fe5c7fe094 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2416,11 +2416,13 @@ 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); if (!folio) @@ -2440,6 +2442,8 @@ static int filemap_create_folio(struct file *file, * well to keep locking rules simple. */ filemap_invalidate_lock_shared(mapping); + /* index in PAGE units but aligned to min_order number of pages. */ + index = (pos >> (PAGE_SHIFT + min_order)) << min_order; error = filemap_add_folio(mapping, folio, index, mapping_gfp_constraint(mapping, GFP_KERNEL)); if (error == -EEXIST) @@ -2500,8 +2504,7 @@ static int filemap_get_pages(struct kiocb *iocb, size_t count, if (!folio_batch_count(fbatch)) { if (iocb->ki_flags & (IOCB_NOWAIT | IOCB_WAITQ)) return -EAGAIN; - err = filemap_create_folio(filp, mapping, - iocb->ki_pos >> PAGE_SHIFT, fbatch); + err = filemap_create_folio(filp, mapping, iocb->ki_pos, fbatch); if (err == AOP_TRUNCATED_PAGE) goto retry; return err; @@ -3093,7 +3096,7 @@ static struct file *do_sync_mmap_readahead(struct vm_fault *vmf) struct file *file = vmf->vma->vm_file; struct file_ra_state *ra = &file->f_ra; struct address_space *mapping = file->f_mapping; - DEFINE_READAHEAD(ractl, file, ra, mapping, vmf->pgoff); + DEFINE_READAHEAD_ALIGNED(ractl, file, ra, mapping, vmf->pgoff); struct file *fpin = NULL; unsigned long vm_flags = vmf->vma->vm_flags; unsigned int mmap_miss; @@ -3147,7 +3150,7 @@ static struct file *do_sync_mmap_readahead(struct vm_fault *vmf) ra->start = max_t(long, 0, vmf->pgoff - ra->ra_pages / 2); ra->size = ra->ra_pages; ra->async_size = ra->ra_pages / 4; - ractl._index = ra->start; + ractl._index = mapping_align_start_index(mapping, ra->start); page_cache_ra_order(&ractl, ra, 0); return fpin; } @@ -3162,7 +3165,7 @@ static struct file *do_async_mmap_readahead(struct vm_fault *vmf, { struct file *file = vmf->vma->vm_file; struct file_ra_state *ra = &file->f_ra; - DEFINE_READAHEAD(ractl, file, ra, file->f_mapping, vmf->pgoff); + DEFINE_READAHEAD_ALIGNED(ractl, file, ra, file->f_mapping, vmf->pgoff); struct file *fpin = NULL; unsigned int mmap_miss; @@ -3657,6 +3660,7 @@ static struct folio *do_read_cache_folio(struct address_space *mapping, struct folio *folio; int err; + index = mapping_align_start_index(mapping, index); if (!filler) filler = mapping->a_ops->read_folio; repeat: From patchwork Fri Mar 1 16:44:35 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: 13578742 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 E9FF6C5475B for ; Fri, 1 Mar 2024 16:45:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 77D8B6B0089; Fri, 1 Mar 2024 11:45:08 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 72DEB6B008A; Fri, 1 Mar 2024 11:45:08 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 580406B008C; Fri, 1 Mar 2024 11:45:08 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 470A86B0089 for ; Fri, 1 Mar 2024 11:45:08 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id F033741367 for ; Fri, 1 Mar 2024 16:45:07 +0000 (UTC) X-FDA: 81849045054.26.9084575 Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [80.241.56.172]) by imf06.hostedemail.com (Postfix) with ESMTP id 1108A18001D for ; Fri, 1 Mar 2024 16:45:05 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=gLQIhxE+; dmarc=pass (policy=quarantine) header.from=pankajraghav.com; spf=pass (imf06.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.172 as permitted sender) smtp.mailfrom=me@pankajraghav.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1709311506; 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=TofXuty2ThUTVbSRpvzx3fKuxbhJgVt2hgC/1tt8iys=; b=QpxXqEddiXAax0gU9eZQNKKfORDGW7bczSLisS50S8ZUgAi9lZpVwpacoNdGdhVooQL8Iw QXwN05teapwtAiOc8mPjQtRAbtq5x1HHJIPOnqyhrix4in/cj2BJQ1QEeyal757VCmkzrr 0Er+GDEyZq7++ZDwCb+/zlW/IQGWjCg= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=gLQIhxE+; dmarc=pass (policy=quarantine) header.from=pankajraghav.com; spf=pass (imf06.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.172 as permitted sender) smtp.mailfrom=me@pankajraghav.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709311506; a=rsa-sha256; cv=none; b=aGSBQ3CpBV2ruWrK94pbx01e/gX6XjmX3hrU7wc1IG4FTMHx13Q8Q1iDQZmPUV5JTh16/F BJWA91fVZI7IWtf4JvbBcdWRT9y0xPwG+6tKnsRHXnXH4Jp8MTKGdV/xR3/91aL59qVvyx LDhOspSwgpQ26sKZbNOn03XCU22yixI= 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-202.mailbox.org (Postfix) with ESMTPS id 4TmYq26jcYz9tWM; Fri, 1 Mar 2024 17:45:02 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1709311502; 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=TofXuty2ThUTVbSRpvzx3fKuxbhJgVt2hgC/1tt8iys=; b=gLQIhxE+TRtwfuu+rkDGqXs9WJziHw+JgFYbs09TJNFTQr/gW51opLqv2FzJyRdjGXp4D+ ne65X9oZMlHrjtB7n2NoVfWLB7HRk8vf4R2509Dwyk0M0ewQllhPja9qtmtoL4b8sPFTQ+ nkXNSyx3ulIxKLLguMd3aSVWP1dyntFOl0MdffdljoNDzvM11kcYKpKwACEbRaRp/XCnWk 3OVsBFM2dylNmecH3BKcdEkp8R+JtceQH/tuSiOi2Mxn50YFHT3Dhlceayzt6YF/1p9wYQ 959x+3MJa2eWXaXbDEZx1+NDiBkzsl0pBsLvjOU/sWouTcpNx5vpkjIcz7zGbA== From: "Pankaj Raghav (Samsung)" To: linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org Cc: djwong@kernel.org, mcgrof@kernel.org, linux-mm@kvack.org, hare@suse.de, david@fromorbit.com, akpm@linux-foundation.org, gost.dev@samsung.com, linux-kernel@vger.kernel.org, chandan.babu@oracle.com, willy@infradead.org, Pankaj Raghav Subject: [PATCH v2 04/13] filemap: use mapping_min_order while allocating folios Date: Fri, 1 Mar 2024 17:44:35 +0100 Message-ID: <20240301164444.3799288-5-kernel@pankajraghav.com> In-Reply-To: <20240301164444.3799288-1-kernel@pankajraghav.com> References: <20240301164444.3799288-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: r8deoyq8ho7nokkxfhogerwmtzwd6tjg X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 1108A18001D X-HE-Tag: 1709311505-179235 X-HE-Meta: U2FsdGVkX1+XGM22g/8CavEA6aQsjeqzAXRQXRpg0sEoPytbHNCk06EFJmdPnTMiVildGPNoLJGafGw+NFI2/AbZ7xPCztgqntFiWXxaeu/B6QQYoKfvVJ6RWXLwu/5t8JNl0uwM6NdFsshHdA5ji3uuGQomiFOVwzXNxf1HbWTaY9+kkGN0FTHfnmpcXXEMDynf1IoOgFNM/kRmAVMLQOKFNjyCyMaGWkNe2hKzOfN7EVgoevxDSK+kvN1d97Z2iV5TRjQoB2OrTiAfdTVADEJ23El4A/NyOdsFPCZwBX86aAdiw+1PpjfGxQR0mkRgEBREvFV3klqFkZcatlfe8fxZQiaXmdcfcQzWEPpaV0Fy0h0tf6GhKu5kwV/zQxmPx5QfwpEqKW6I88b1pWQDHNtz1PpD5aR3GeJE3EFhgydZAr8caWShCQLGgaWRbzjTpdx4MYTtQbx4htcG8SvWD8ecIOC4HtNVGZUibxKTPQzDN1XCpynh+wxDhrjlSJO9+de3BGHMNrAErvaFk1omflqo9MHtUyoY7cN9UZKD48b2TjN2nzLb624Ogzx5AmhFMPjx7623WKhAcvxdKV5gMgdmGqE0wgQD3QRjIVu5XlfPwkCu43FTUxIehrkt/fazQXaK5LGgGi4SFfcybRRldAy8gG9fgX2FOkMUl6Vtn+tzbtsXe0s9ZQwLpfPnCEQWHitSkRh6xuVGPAEg1kL70Tit2auNBA8mqMhLCv66qGgcd9BiANrwXKTTVRZ0ZIfz9zzog7wIyhe2A5uw4/vH4mhJWncrtq+MAhQ/XBvMzaqhZhDnlTlRi0MQTcvBJheTxGJTjx+eznzknfCWvk8LZqVEDX5yvk3EvdFbKffMeK8GwNf3E3DgayWLs/g/bd9E+h1r6AwhhSHpGzmWh3eSV+NaxCtKcISUTxQvJGdn+JBWCTEmY826LEU5Pr8n2a138ImRXU0a2mCFlS7smAX 3MK8HGwv sWFQUOg9FrIxq6owBbf4idqF3jqmxgLnJym+WJGccYeCuvB4yJVqz+mdi8+dN9XVZGn93WkT0Modi+L+wtfCnxd6XYvrEjqS/xUspPOXn6zu8QKKxFXcSeTgNYTsuLOLLWMFqgONCzNE2jhw= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Pankaj Raghav filemap_create_folio() and do_read_cache_folio() were always allocating folio of order 0. __filemap_get_folio was trying to allocate higher order folios when fgp_flags had higher order hint set but it will default to order 0 folio if higher order memory allocation fails. As we bring the notion of mapping_min_order, make sure these functions allocate at least folio of mapping_min_order as we need to guarantee it in the page cache. Add some additional VM_BUG_ON() in __filemap_add_folio to catch errors where we add folios that has order less than min_order. Signed-off-by: Pankaj Raghav Signed-off-by: Luis Chamberlain Reviewed-by: Hannes Reinecke Acked-by: Darrick J. Wong --- mm/filemap.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/mm/filemap.c b/mm/filemap.c index 96fe5c7fe094..3e621c6344f7 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -849,6 +849,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); if (!huge) { @@ -1886,8 +1888,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_start_index(mapping, index); if ((fgp_flags & FGP_WRITE) && mapping_can_writeback(mapping)) gfp |= __GFP_WRITE; @@ -1912,8 +1916,11 @@ struct folio *__filemap_get_folio(struct address_space *mapping, pgoff_t index, gfp_t alloc_gfp = gfp; err = -ENOMEM; + if (order < min_order) + order = min_order; if (order > 0) alloc_gfp |= __GFP_NORETRY | __GFP_NOWARN; + folio = filemap_alloc_folio(alloc_gfp, order); if (!folio) continue; @@ -1927,7 +1934,7 @@ struct folio *__filemap_get_folio(struct address_space *mapping, pgoff_t index, break; folio_put(folio); folio = NULL; - } while (order-- > 0); + } while (order-- > min_order); if (err == -EEXIST) goto repeat; @@ -2424,7 +2431,8 @@ static int filemap_create_folio(struct file *file, 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; @@ -3666,7 +3674,8 @@ static struct folio *do_read_cache_folio(struct address_space *mapping, repeat: folio = filemap_get_folio(mapping, index); if (IS_ERR(folio)) { - folio = filemap_alloc_folio(gfp, 0); + folio = filemap_alloc_folio(gfp, + mapping_min_folio_order(mapping)); if (!folio) return ERR_PTR(-ENOMEM); err = filemap_add_folio(mapping, folio, index, gfp); From patchwork Fri Mar 1 16:44:36 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: 13578743 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 D2D52C5478C for ; Fri, 1 Mar 2024 16:45:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5AACD6B008C; Fri, 1 Mar 2024 11:45:11 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 532626B0092; Fri, 1 Mar 2024 11:45:11 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3ADD26B0093; Fri, 1 Mar 2024 11:45:11 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 1FA736B008C for ; Fri, 1 Mar 2024 11:45:11 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id CEAD881450 for ; Fri, 1 Mar 2024 16:45:10 +0000 (UTC) X-FDA: 81849045180.22.A4E4F9D Received: from mout-p-201.mailbox.org (mout-p-201.mailbox.org [80.241.56.171]) by imf18.hostedemail.com (Postfix) with ESMTP id 492A81C0028 for ; Fri, 1 Mar 2024 16:45:08 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=EhcDjdG9; dmarc=pass (policy=quarantine) header.from=pankajraghav.com; spf=pass (imf18.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.171 as permitted sender) smtp.mailfrom=me@pankajraghav.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1709311509; 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=wBvRRAph/60/h4V+RTLg/hSlbvygSXk8WrjV0xu5/4g=; b=gpK4GTyYP8X0CkHDx7WbJxtxkHWKY0Lh0uRpw35qv9N50UvpM233/WbnrMYEoKSFq6+UYB WWdONOYU5PKXq07ZUjJScKrZLwu+tu5J3EotpR/XDgZdzmrcPCH8u8YBDsv8DSEog/LmeG OWrsdBQJHHdWRYJU9xf+ncxVe8YyTl8= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=EhcDjdG9; dmarc=pass (policy=quarantine) header.from=pankajraghav.com; spf=pass (imf18.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.171 as permitted sender) smtp.mailfrom=me@pankajraghav.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709311509; a=rsa-sha256; cv=none; b=n1qX591ByvKnchTnQ8s75XyWTqNuzM3+ST7YY+1Zdn4zr4SqQTQujyRADWzPw30f3AFioJ ALHz7A3dNXzYTIFsoIXJQGEnGtRocsWR+cq6E88qmuzLMnwyV6qFbt2Inuug5RTKqSch/8 cjV3fOTpOGUnja8UrhECY1yTrU3IMw0= 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 4TmYq56x6Dz9t7g; Fri, 1 Mar 2024 17:45:05 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1709311506; 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=wBvRRAph/60/h4V+RTLg/hSlbvygSXk8WrjV0xu5/4g=; b=EhcDjdG9qiZTG+V3uYtrOsPK0UUvzb17ipja6U+/IY0HDDnkY+HkPMp6p0u2+FSKecvqMu iWT8AtwgnLDakHtg95b2lJHGfk+s2XyJPWYikTnuC3BK/QjQRJMmqqOAPqBWr3IoSls4mW q19/nic1+DfHfZHR7JZTV1HpciObH2ScYT+9tgsK2vmAPUsIfP+bPAJRYxen4YAMvdN2kC SIAdF3SlBhG3Mqe/v2I/i2CCBekZQdagyrgkf3dcQFHgQZK6Na1PLH3v3csGAqLmSH04IG 9DZNFKUyvPqqe/5Ne7SHmLPq54ZL9V7gnXR0jla2EERn/u2BZBYnEczSx/YJzA== From: "Pankaj Raghav (Samsung)" To: linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org Cc: djwong@kernel.org, mcgrof@kernel.org, linux-mm@kvack.org, hare@suse.de, david@fromorbit.com, akpm@linux-foundation.org, gost.dev@samsung.com, linux-kernel@vger.kernel.org, chandan.babu@oracle.com, willy@infradead.org, Pankaj Raghav Subject: [PATCH v2 05/13] readahead: round up file_ra_state->ra_pages to mapping_min_nrpages Date: Fri, 1 Mar 2024 17:44:36 +0100 Message-ID: <20240301164444.3799288-6-kernel@pankajraghav.com> In-Reply-To: <20240301164444.3799288-1-kernel@pankajraghav.com> References: <20240301164444.3799288-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 492A81C0028 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: e35gcn6igjoa64szctw4fx75xxe3t3hk X-HE-Tag: 1709311508-702781 X-HE-Meta: U2FsdGVkX1+E4CP3nv7X5fDDzUX+p2eu/l4YtgI2ftKS2IGomiWkHjep/XM17P8aWA19ZNO321Y10X/uVdSV4FD6SYmC5KTBnEnrfZGejLoqRgOKY7s1uvDsTz6f1JHfrRhJeLkhhVwDPYq+GhdO6lHl0FSfkWr/YVxH1swSON5p+/Q9SjBZsGtiPILcmA78sNxuJ9Gm1v08CVZjtMD1BYtu1yzDV6xdjtlkMG535iMHvr38DwJP6nwh6VWePqf9/OT/mRIkq+dQvEUc7Hoe0XOQmwVvuprU7zJdhTelXg/w/nhx78CKrPJbqQXkLb1sQY7X+D9E5LN4S24TurHQDLNx67W6xJRNm3VYJ1YtndcZYMn5GO0bKBGuWyc5scxvswolENwJw0cUb9lHI6Cq3PEOnS0EvIQFvf0h7+nGpgX8hJ6fjJPe8zMY3/0LGLZiVgQ+KN5GTea4SFgH6kxOC/DW5CdGNoYoP7LWt7vqAQRPX+yuKko6ByUuC525gNrUZIeDEwf0M6ropqgrbqVcncRyy+d6Dei0aLxxkAniG6AVoJDA+5WbXkOJj3HYngQebKgBJLUtTp6YgiWE5c1/eBXeQYrRuj66u5iEvIhICo2CHpLVl2xsv4AvVmF3WkkCwTo879iS+jhzXUk7BATAxWW8adDLpMPDnNBxm/Nq6rSdM4DSwRz+3GIfAF3K2aNWMiNci2moetENZrQVvdQIxH5yhX/657Zy8Q4Uh0S11Pyv7NJ6BNIXox8l9/1EVcvCu+3RnpeqgqbEjQGLMauA4eT3sJTVstRKF8+QXE6O73/yK1gdeuzZkTjfQz0m6lZ0Mh/DMIQp1qOqocO+7cbgR1/IizLUITlwae2plt0FjCT/GSDmHVuYktBqvMUe9MfH858GJEgDAw5mqL2isONyDEdRL43ZtZYMdqPxkp0XrMICFF1JzrR60NrHhFkPjJVep6zpqXX0UcHvhQEKhUX 0j7w1zO9 HSSJ2vCaP1dfo7LsDn5hiEPrI+F31tMryhc3zPNMl7r2oTayVB3mUAsJzgHUZAMoJJbJ9BISfQleEzHZh0F/fnN1GdyzoECanqEEUM6CFaBfWeI5QPsvuFn0rEf+2l8epLZTZiyDJ20OhSL0= 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 As we will be adding multiples of mapping_min_nrpages to the page cache, initialize file_ra_state->ra_pages with bdi->ra_pages rounded up to the nearest mapping_min_nrpages. Signed-off-by: Luis Chamberlain Signed-off-by: Pankaj Raghav --- mm/readahead.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mm/readahead.c b/mm/readahead.c index 369c70e2be42..6336c1736cc9 100644 --- a/mm/readahead.c +++ b/mm/readahead.c @@ -138,7 +138,8 @@ void file_ra_state_init(struct file_ra_state *ra, struct address_space *mapping) { - ra->ra_pages = inode_to_bdi(mapping->host)->ra_pages; + ra->ra_pages = round_up(inode_to_bdi(mapping->host)->ra_pages, + mapping_min_folio_nrpages(mapping)); ra->prev_pos = -1; } EXPORT_SYMBOL_GPL(file_ra_state_init); From patchwork Fri Mar 1 16:44:37 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: 13578744 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 4902AC5478C for ; Fri, 1 Mar 2024 16:45:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C87FD6B0093; Fri, 1 Mar 2024 11:45:14 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C36F56B0095; Fri, 1 Mar 2024 11:45:14 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AD7906B0096; Fri, 1 Mar 2024 11:45:14 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 9B4656B0093 for ; Fri, 1 Mar 2024 11:45:14 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 5B6DD1A0176 for ; Fri, 1 Mar 2024 16:45:14 +0000 (UTC) X-FDA: 81849045348.14.94EB620 Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [80.241.56.172]) by imf01.hostedemail.com (Postfix) with ESMTP id 9D0824001A for ; Fri, 1 Mar 2024 16:45:12 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=sy87xrj0; spf=pass (imf01.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.172 as permitted sender) smtp.mailfrom=me@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=1709311512; 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=fyszdUSBCFtEWqaMFYCTrgSY4YVZLc+Vs7TuxxQjQl4=; b=ES1X+j1XZbZFj0SsFP3UahUUAUj5jjauS9XBkY6Abnt3LY5xQrV1RkTFhQh7FvkCTijA8M DkYRbLm7pDsjVqnx8Dp+JZt7kSHxesZVc6xmTq9MpKRy0vLFwn8ucCvgVW+CB0e/pAOjpf a80g3WvqGx/37K6HV9CIoBXUGz1dgIg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709311512; a=rsa-sha256; cv=none; b=TIgUtCP6Hx72mRAfk3Ji6fwGqCjXAMYRxqna9GcD1llvJAqf7SOzK1TF7n++a+1TYPrgAp vN/7+ASdmn085fbOGWLsUPRL2hQoA5wpiJ9Wx5GmkqNMcnC9GbziplOq3/Mpgmcu9lquhS Nk6Eao+3L+AXT93jNYBnX3LS7JQ8XjY= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=sy87xrj0; spf=pass (imf01.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.172 as permitted sender) smtp.mailfrom=me@pankajraghav.com; dmarc=pass (policy=quarantine) header.from=pankajraghav.com 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 4TmYq94WM6z9t2l; Fri, 1 Mar 2024 17:45:09 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1709311509; 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=fyszdUSBCFtEWqaMFYCTrgSY4YVZLc+Vs7TuxxQjQl4=; b=sy87xrj0yXtold9KEo0HbYK8U8fwRqeLzMnk/2gqJnegYhfzQ3WYLFoP+gKh5jVg1lArg7 fdvBQ/UZr6BWq1qkEe8pVninsVe5DywCu19kITPvxIcx9Vack4ssHwRyzuRaD6lB1jC7BQ uTbBKafIzaN4RXOHoJ1rzeP6f4AufeVRjLDYHxKwlvj43YJ6QFoKnvZ+64+iUVUOvlm/8e cWxdREnG6S6nfRUGvJWdO0s95pIgZWmt7I76Q/tgXIulymt3CuLsbAF7hA1QD8/PNc/0PC sqv72BLNDr5q3jgNBxoz2RpihfmZAFSOIg0/3k52B5oukRPUxhIRfIEheiIRow== From: "Pankaj Raghav (Samsung)" To: linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org Cc: djwong@kernel.org, mcgrof@kernel.org, linux-mm@kvack.org, hare@suse.de, david@fromorbit.com, akpm@linux-foundation.org, gost.dev@samsung.com, linux-kernel@vger.kernel.org, chandan.babu@oracle.com, willy@infradead.org, Pankaj Raghav Subject: [PATCH v2 06/13] readahead: align index to mapping_min_order in ondemand_ra and force_ra Date: Fri, 1 Mar 2024 17:44:37 +0100 Message-ID: <20240301164444.3799288-7-kernel@pankajraghav.com> In-Reply-To: <20240301164444.3799288-1-kernel@pankajraghav.com> References: <20240301164444.3799288-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 9D0824001A X-Rspam-User: X-Stat-Signature: zffbkye7jea4k13ku9cm4x9fyzx5bu44 X-Rspamd-Server: rspam03 X-HE-Tag: 1709311512-805928 X-HE-Meta: U2FsdGVkX198vBOSBhJHeapa4ZA6IQefIrCRQ6L+Liu/pscFfIAaQk+t+hrD9XgKhbS5O9lYIlZ1BjDI/WRHm7C2tA72PjLXPCm88KtNb/Gw28UXF1O51CQk3MOO+7Oa4EyHQjfnxk6JkqevfgepV28hBWmgCRameqqkPSRFAAT/dqqSXFYNyzgky7wD+p1OPg9dU6jldcHgUxSPUSwevqqePA4SsIkBVHbjPZZC7TUl7F14ILOQ2MjzWxOhojWVhjv5IVwBhLToIL6Na9Ld4KEgzsVKSjTQDgANXrxYy4qZ2HBcOVPYf9XyrTGsDeNFRnNh9D+9ELJxpFS14y+5oqDyUAFoyi34s5WvvMMmZjFtd/jR/YbJf4YH2cophjHWIt5XJ6K2z0z3MDfPKQqiDFimpeZtbxPPhrUkLjUDlJGlEh+u5fItIcEFrETM9aItMg+MvxDnK+sxX94998mvF1IXZZCRkJtNrXt9LesgQ5xsSFLKxg5CnO5BXQ8IcFolIb25keZWVZoENm5kcSm61emzTUBTlHEN4f3EhY9CKV4t3iSMhi+W9id8VotdhIKDS8nkRI1lLZ+TGeWqwRrUA/n4fwR2Fqd3ClBibudxbXwuCrci4mZsj8MHAYLdoosX9ytjlWzdxXu+OGChh8POLKqP4W3fS/7OguOA8n7GKZj1ZAId1Yf4n2MmIEL0joVfcJIKzHrykNJB2eycce+D8AqSXCDtqtV70Xh096bIiC75i17Z/ykeVq0nMvNAX45SS5tA9bPC7KpwSWGz4KZ7eDcU53cKq7TNOr7s3sghQuuHZSUispSf/OSqnoWyKBEzrW2tb1n7UHhLq34WH6X2p37pyL1I5VdBF/eaPgpo8UWSFD2F9p0itwWVD7OtzwS9hPJw3ga34mAeaYOmHdUnjy5gzmoiwfKMe93rOfL6q39oAPBmJaJ92hDcm7ExO+thJvmXsmrHkqA22QauHbO lB/iV1W5 IB72q0umqRko8Z3zo4G+oxePHaH6TbLPKs0E3GyVi6DHAGOKnNusn7yFu91Lso1xHUAdIt8wrIO184MJAK09vRneo5UoomiB0KefdTWmwdOeOBwif0i74SWR18QDE7Ja69GQ7LTTw2tcsaAw= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Luis Chamberlain Align the ra->start and ra->size to mapping_min_order in ondemand_readahead(), and align the index to mapping_min_order in force_page_cache_ra(). This will ensure that the folios allocated for readahead that are added to the page cache are aligned to mapping_min_order. Signed-off-by: Luis Chamberlain Signed-off-by: Pankaj Raghav --- mm/readahead.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/mm/readahead.c b/mm/readahead.c index 6336c1736cc9..0197cb91cf85 100644 --- a/mm/readahead.c +++ b/mm/readahead.c @@ -310,7 +310,9 @@ void force_page_cache_ra(struct readahead_control *ractl, struct address_space *mapping = ractl->mapping; struct file_ra_state *ra = ractl->ra; struct backing_dev_info *bdi = inode_to_bdi(mapping->host); - unsigned long max_pages, index; + unsigned long max_pages; + pgoff_t index, new_index; + unsigned long min_nrpages = mapping_min_folio_nrpages(mapping); if (unlikely(!mapping->a_ops->read_folio && !mapping->a_ops->readahead)) return; @@ -320,7 +322,14 @@ void force_page_cache_ra(struct readahead_control *ractl, * be up to the optimal hardware IO size */ index = readahead_index(ractl); + new_index = mapping_align_start_index(mapping, index); + if (new_index != index) { + nr_to_read += index - new_index; + index = new_index; + } + max_pages = max_t(unsigned long, bdi->io_pages, ra->ra_pages); + max_pages = max_t(unsigned long, max_pages, min_nrpages); nr_to_read = min_t(unsigned long, nr_to_read, max_pages); while (nr_to_read) { unsigned long this_chunk = (2 * 1024 * 1024) / PAGE_SIZE; @@ -328,6 +337,7 @@ void force_page_cache_ra(struct readahead_control *ractl, if (this_chunk > nr_to_read) this_chunk = nr_to_read; ractl->_index = index; + VM_BUG_ON(!IS_ALIGNED(index, min_nrpages)); do_page_cache_ra(ractl, this_chunk, 0); index += this_chunk; @@ -554,8 +564,11 @@ static void ondemand_readahead(struct readahead_control *ractl, unsigned long add_pages; pgoff_t index = readahead_index(ractl); pgoff_t expected, prev_index; - unsigned int order = folio ? folio_order(folio) : 0; + unsigned int min_order = mapping_min_folio_order(ractl->mapping); + unsigned int min_nrpages = mapping_min_folio_nrpages(ractl->mapping); + unsigned int order = folio ? folio_order(folio) : min_order; + VM_BUG_ON(!IS_ALIGNED(index, min_nrpages)); /* * If the request exceeds the readahead window, allow the read to * be up to the optimal hardware IO size @@ -577,7 +590,7 @@ static void ondemand_readahead(struct readahead_control *ractl, 1UL << order); if (index == expected || index == (ra->start + ra->size)) { ra->start += ra->size; - ra->size = get_next_ra_size(ra, max_pages); + ra->size = max(get_next_ra_size(ra, max_pages), min_nrpages); ra->async_size = ra->size; goto readit; } @@ -602,7 +615,7 @@ static void ondemand_readahead(struct readahead_control *ractl, ra->start = start; ra->size = start - index; /* old async_size */ ra->size += req_size; - ra->size = get_next_ra_size(ra, max_pages); + ra->size = max(get_next_ra_size(ra, max_pages), min_nrpages); ra->async_size = ra->size; goto readit; } @@ -639,7 +652,7 @@ static void ondemand_readahead(struct readahead_control *ractl, initial_readahead: ra->start = index; - ra->size = get_init_ra_size(req_size, max_pages); + ra->size = max(min_nrpages, get_init_ra_size(req_size, max_pages)); ra->async_size = ra->size > req_size ? ra->size - req_size : ra->size; readit: @@ -650,7 +663,7 @@ static void ondemand_readahead(struct readahead_control *ractl, * Take care of maximum IO pages as above. */ if (index == ra->start && ra->size == ra->async_size) { - add_pages = get_next_ra_size(ra, max_pages); + add_pages = max(get_next_ra_size(ra, max_pages), min_nrpages); if (ra->size + add_pages <= max_pages) { ra->async_size = add_pages; ra->size += add_pages; @@ -660,7 +673,7 @@ static void ondemand_readahead(struct readahead_control *ractl, } } - ractl->_index = ra->start; + ractl->_index = mapping_align_start_index(ractl->mapping, ra->start); page_cache_ra_order(ractl, ra, order); } From patchwork Fri Mar 1 16:44:38 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: 13578745 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 D792FC5478C for ; Fri, 1 Mar 2024 16:45:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 708D36B0096; Fri, 1 Mar 2024 11:45:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 693CD940007; Fri, 1 Mar 2024 11:45:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 517C96B0096; Fri, 1 Mar 2024 11:45:18 -0500 (EST) 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 3DF3A6B0096 for ; Fri, 1 Mar 2024 11:45:18 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id CC11E1C1761 for ; Fri, 1 Mar 2024 16:45:17 +0000 (UTC) X-FDA: 81849045474.28.B2657C0 Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [80.241.56.172]) by imf13.hostedemail.com (Postfix) with ESMTP id 34A392002C for ; Fri, 1 Mar 2024 16:45:15 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=VkAMxpfa; spf=pass (imf13.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.172 as permitted sender) smtp.mailfrom=me@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=1709311516; 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=467JnvYp6xZwSrqHVz6JwGG/B+XhREWQAJ9IMIxeQus=; b=TMN/zKQhcDaAuln2QiNBsxcTR4pgkF+z/paP50OQcGGAJzGptqkfP9z9Z3ZK6RIxGy0F8p /sfxIBxv6dZG8IFEm7Ix6j1het0G3+iZmCHMqXwUvtYF3aZ+Xqk/k7K/AXQDyGswXN1Rt6 nPvqYpLp+ec3Krqo4M8rFZ+YzqxRPJg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709311516; a=rsa-sha256; cv=none; b=1qi8HG0Kv1e7SxbDKJNRdnIRtP1vvea2SCXXYA9a7XtNiadiq59BQnFKsVDLxk86NKrDi7 g36mKk8YDbRlxOeRgpbTfMagW8YLaaauUoNd4frtZAg6qELb5KuR0zt6fTkxst0UwRqTtg P8PCpIdMA2y1HsiSnLLyjYlhh4NFaQA= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=VkAMxpfa; spf=pass (imf13.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.172 as permitted sender) smtp.mailfrom=me@pankajraghav.com; dmarc=pass (policy=quarantine) header.from=pankajraghav.com Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:b231:465::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-202.mailbox.org (Postfix) with ESMTPS id 4TmYqF1lVsz9tWG; Fri, 1 Mar 2024 17:45:13 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1709311513; 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=467JnvYp6xZwSrqHVz6JwGG/B+XhREWQAJ9IMIxeQus=; b=VkAMxpfaEVmgbBcyuWtw1txdyYcbaIt4sqlGeJGp4avK/yPIQcy8to9fJZZ3qScgjLTMG0 zZ9hNEFp/oojel/WDhiyAb0dUct7HpNi+jJfzLbKNIueuEmbxVJyZbUht4rQxyC5lh8sMS HT6uu3rN9e8yCRwtkb60yJuBlBx8yoAQTlAbKLMMQDdxFUhoa6mKOfD0v3iZ/6pYAYxmVe Lb60kYjxTwQ5MKjEw4kbxCiUHOFuNB1Ojc9L6Jm6wAx5rq7lhFCLV8t0rmZZF8lVDx9g6W 5GNu5Ozk7Sxh5HXX22l8nX0Ko7gEP5moqmlTnADLEs0uHQPFY4rDTa4vNBGg7A== From: "Pankaj Raghav (Samsung)" To: linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org Cc: djwong@kernel.org, mcgrof@kernel.org, linux-mm@kvack.org, hare@suse.de, david@fromorbit.com, akpm@linux-foundation.org, gost.dev@samsung.com, linux-kernel@vger.kernel.org, chandan.babu@oracle.com, willy@infradead.org, Pankaj Raghav Subject: [PATCH v2 07/13] readahead: rework loop in page_cache_ra_unbounded() Date: Fri, 1 Mar 2024 17:44:38 +0100 Message-ID: <20240301164444.3799288-8-kernel@pankajraghav.com> In-Reply-To: <20240301164444.3799288-1-kernel@pankajraghav.com> References: <20240301164444.3799288-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Stat-Signature: r7zqsnucbyehgxu1475ewwr45xop414z X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 34A392002C X-Rspam-User: X-HE-Tag: 1709311515-778042 X-HE-Meta: U2FsdGVkX1+r7tisKHQx3PPVZCImnsRH0mCatLbnzv6bxxfNrO5nWLTXHVLnn1nQQH94QuT9fRIbxxKnmauv7twNEoHF8QdiFL6iQYyK6fwOMWbWCHoR/oInRdPHqxbBQ0HIigP0pygg5LbYC3mj4OpYrm+Dx9YfvP6gICCNsgCqooNoEYE3zlxgJpb8EUfJkIiiK+vUEh1QVTWOuo/yS4BLKz0vbVQWA5Rua6F+OMACOIpdjrek6e4vyQSxv4H/w3noY4ncS5s5lr2SPGwYA2YlPQz/yHW6xzkxdU1gCzMfPcZkgReglbVwtQmaKEtLmajPN9zY4fnyOcA63eR4V3nAMYUbsn0WoNJ9T6JFrc2SoCMo4CO4ea2oJSjPzheQYXKgC5/UGV4Iusq67mOTJ2TyqcZi8+Mbw5a6JULlNROW8LFb9z2mWUNdEr2jSsATyGDY+Z/d+zhjon0bI0IqYAo7axDbZbx9Pih+S6LnUJGbLzW+Qp1NKvqREluVGAAX8sfkOmTG7GjiHnyOm2jpY3KWLaSwnug5MWcJKiNqqUhgY21HaJrtcXmFTw3yJJYAfkqENjKMrgW3roMPCYYn4UCXI5LL5JWer63GHz4k++b7LAgzJI9g+2M+pQxtRdWLhPOFCpM0APK4MDic8GSMaxtZbHCm4uAcTHw+0x1QrBaAl2YouIKiFzI0/mLkNiBPNM/0LrlRmrBJJ/G20W6mgV8MVqAU7VFksHruum/ziLJLbF1xj/j9CVax1T/V8rMp1yhJr/uZABl4RAQHzPsOXUFh/acllTcneo0yUVOMepvFCWmT8RbyClCD2utA9XeUBvZdTPXkNpH8KOS3zYZfBwU6kQbcBPFSJWYNVGbZLFXxc/eD9r0jyuEwjX41c4RTsfCA/FEFlWBI87cgv4nmJad2WBJ+ECIwapMxpnAkt105rsOfuOBgOMz0YHTsAPDw5wFF7/lSlJn+5y/MtmH G9W5xXtJ osIcpcoLYzWAMpXm7Rl7Z5t1Hqv94x+Sy51NBVe+J48g/NM6xnOdCXZrFVVg4Rh5lIffq8w3oj3MwOX+iVUgCqu7Unwj32vnBuJhx/tmBgotcye9nwirvgZkyENA1PlxERMUaKy6rUtES9ENwx5tvBlyPpjqt6dJ+3rZHIwQB4+tiGuj8ldcRzdXZaBIxoMT92/JvYYlyLn9KNcvKE08HuZkGfA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Hannes Reinecke Rework the loop in page_cache_ra_unbounded() to advance with the number of pages in a folio instead of just one page at a time. Signed-off-by: Hannes Reinecke Co-developed-by: Pankaj Raghav Signed-off-by: Pankaj Raghav Acked-by: Darrick J. Wong --- mm/readahead.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/mm/readahead.c b/mm/readahead.c index 0197cb91cf85..65fbb9e78615 100644 --- a/mm/readahead.c +++ b/mm/readahead.c @@ -209,7 +209,7 @@ void page_cache_ra_unbounded(struct readahead_control *ractl, struct address_space *mapping = ractl->mapping; unsigned long index = readahead_index(ractl); gfp_t gfp_mask = readahead_gfp_mask(mapping); - unsigned long i; + unsigned long i = 0; /* * Partway through the readahead operation, we will have added @@ -227,7 +227,7 @@ void page_cache_ra_unbounded(struct readahead_control *ractl, /* * Preallocate as many pages as we will need. */ - for (i = 0; i < nr_to_read; i++) { + while (i < nr_to_read) { struct folio *folio = xa_load(&mapping->i_pages, index + i); if (folio && !xa_is_value(folio)) { @@ -240,8 +240,8 @@ void page_cache_ra_unbounded(struct readahead_control *ractl, * not worth getting one just for that. */ read_pages(ractl); - ractl->_index++; - i = ractl->_index + ractl->_nr_pages - index - 1; + ractl->_index += folio_nr_pages(folio); + i = ractl->_index + ractl->_nr_pages - index; continue; } @@ -253,13 +253,14 @@ void page_cache_ra_unbounded(struct readahead_control *ractl, folio_put(folio); read_pages(ractl); ractl->_index++; - i = ractl->_index + ractl->_nr_pages - index - 1; + i = ractl->_index + ractl->_nr_pages - index; continue; } if (i == nr_to_read - lookahead_size) folio_set_readahead(folio); ractl->_workingset |= folio_test_workingset(folio); - ractl->_nr_pages++; + ractl->_nr_pages += folio_nr_pages(folio); + i += folio_nr_pages(folio); } /* From patchwork Fri Mar 1 16:44:39 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: 13578746 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 D02CEC5475B for ; Fri, 1 Mar 2024 16:45:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5FC0A6B0099; Fri, 1 Mar 2024 11:45:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 58094940008; Fri, 1 Mar 2024 11:45:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3D3E4940007; Fri, 1 Mar 2024 11:45:21 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 273DD6B0099 for ; Fri, 1 Mar 2024 11:45:21 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id ECCB2A1CDC for ; Fri, 1 Mar 2024 16:45:20 +0000 (UTC) X-FDA: 81849045600.23.2C664BA Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [80.241.56.172]) by imf17.hostedemail.com (Postfix) with ESMTP id 337D540021 for ; Fri, 1 Mar 2024 16:45:18 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=GTvMRiJf; dmarc=pass (policy=quarantine) header.from=pankajraghav.com; spf=pass (imf17.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.172 as permitted sender) smtp.mailfrom=me@pankajraghav.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1709311519; 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=zvw2rzk11TxuiUv97J3TlgZt9xwdAbT4PmWWnU5r0+0=; b=gSMC3CcqcniaA20VlP5SozhcW9b69bgbFLjYjF7zBbr5p9sFjKKuzrzo4cq/ivO4qbm4TI 8Lvpp7piA7Vyxs3rPj94O4LH410WB7yDwtpk3WheZRC5j/V8yDFO/hiBG3ePLh8egWyqd5 +cp4wum3lPOXrlExeBPqPV+fkuA0Abc= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=GTvMRiJf; dmarc=pass (policy=quarantine) header.from=pankajraghav.com; spf=pass (imf17.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.172 as permitted sender) smtp.mailfrom=me@pankajraghav.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709311519; a=rsa-sha256; cv=none; b=kSuBcK1bz7W6eVHqKk2N520OUHiQWqIcHaSYf+GdAgDTaFYFIpnKZtWX1yPZzhy/+qh1Ng dXw2rtW+rDMpwJm9aNlmL2zCsdmZpR0+3it7MBhER/fxc7iJYEsYMcHHQK+BZM0OGTeUGG zvDx83dr/tc3xs9/HpuG/fbXfQiRSC0= Received: from smtp202.mailbox.org (smtp202.mailbox.org [10.196.197.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-202.mailbox.org (Postfix) with ESMTPS id 4TmYqJ1Kr0z9tWS; Fri, 1 Mar 2024 17:45:16 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1709311516; 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=zvw2rzk11TxuiUv97J3TlgZt9xwdAbT4PmWWnU5r0+0=; b=GTvMRiJfwP1CM9YGAN8fjl3pwLxOZk9Gjl/t9vwy8fr7jW+Wufva3/mOFVv/mPJ1wAqh/X 2XKnWTgFH/VlymrO7JqlRSExaN9oXj2IOFhR7Y6qPalDbQtLS6T/oWq4uXm3kHimID0E7i XfGjXVaUhu6kbuAvHHGrVKvfk7wBZiOMHKUB1jxvSNAGa6OxwxT5bmwHB/hjAmTZLipfiZ pkU2S8yLNWUOZ1HtCb5FiUBq/8oK4BURcysJPANZhPHgBabo3bLhcWu89AgRmDqb0SXsDb wKOCAZ1pTj+fuvYcuMhbu40x5DSNsukW4ZietZo/NSJfFBrXmRMcDA99zOCd2A== From: "Pankaj Raghav (Samsung)" To: linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org Cc: djwong@kernel.org, mcgrof@kernel.org, linux-mm@kvack.org, hare@suse.de, david@fromorbit.com, akpm@linux-foundation.org, gost.dev@samsung.com, linux-kernel@vger.kernel.org, chandan.babu@oracle.com, willy@infradead.org, Pankaj Raghav Subject: [PATCH v2 08/13] readahead: allocate folios with mapping_min_order in ra_(unbounded|order) Date: Fri, 1 Mar 2024 17:44:39 +0100 Message-ID: <20240301164444.3799288-9-kernel@pankajraghav.com> In-Reply-To: <20240301164444.3799288-1-kernel@pankajraghav.com> References: <20240301164444.3799288-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 337D540021 X-Stat-Signature: wqy7owkqhs6bmux6h1krnw3p44ri16r5 X-Rspam-User: X-HE-Tag: 1709311518-238294 X-HE-Meta: U2FsdGVkX1/HMsnclmxbagEXp86E7ugXMHGJ0GmmWde1XeaxD6ijuysQqAbtR+hvZ20aDiiNwnbeNb4qtl58iVTv917ADhhEw3zuufhdXTHAWLhfZVGpp3AB0lF8cT5kSeKoLnVjMMz7QJalWj6VTYnqlvMVCqJE8qCWi+HgaWm2vixj09zhOI1b9amOCmZNGgCGajFoHlSOyiKX2AVhU6qOc/NVIEWTBGfMRx+4Wwhwzo+VKRfUBI/ngoxHhEu1kZIypMCMr2Rx1HuO4TUsUonpNG0DjW6dJf8o8I3KZJf09opKjludLLj3OZI+zGm9ZthYnPs7qnoZLHdO9iNJ6G+sB0EbfnlE+rDPkdWq1QnoQL0OMQHNT1gC/ZW3+UGZOYVRlxKy35HsqNOV58iVGTgK+KQI0+jJSt848NuAPLxeytwuDRNn1CtaJIWQvTwMRNsF6hx6pf0h47YE0ynDcNOeQdU2aD1FrBiHuuzB9drIRGoJeHQdWCBXozD7xDHkvlo0JQmiHaZ0wdho/9LKx1oQXZCjRbvDP7FRs7l3seTGNBBFWIt+5vXWXWFedew3ZjF4KWnOZgZVJTQ+l/hv14e8qu808XwwJCvoUCxru/7QhfWhfPFizqTSOGAQ91PwroVvp2EH6LhoWUdlXkEaBZqhEz53zRfZNMVSMrQSqNqjp158xTHjlV/edi3sTMr82te0fVK9JFwH5G1vzt9oExwql/p28sn0r2JvK87pAq05FAwBqALw5/fEOyMNPvLzybNLm0c5ZzUsQC1kOlMNrSLPmdH+8GwnNRAEfc7GeWjDGjjfK1KbUJGVIoOfxdwp2v39sw71ys46eRyNuQQB6679+O8iaRxAdnen6fCEhwHbmMsvSC3Hmexq+r839J7DDIFhfFM4dOe3QA8eXe0d0Duweu3Fss9moVFMYQVnWxLzfNzg0PrV65E3svDNNm+hbuROEBQIbIX8GPd9yE/ 4kjwwSVf QzFhq6MEvhtnZZw1tnyzlcyr0NS8PKJFbz6W3s9yHmFpQNEzzUXZ3cFsm6sPRcssntjFZz9K9VCr0wwu8+YdtuhdfKlABV9bb+frZsUaWiDuiovmh+obgX7O4McYYekF0OvZQDVt7OTKn19E= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Pankaj Raghav Allocate folios with at least mapping_min_order in page_cache_ra_unbounded() and page_cache_ra_order() as we need to guarantee a minimum order in the page cache. Signed-off-by: Pankaj Raghav Signed-off-by: Luis Chamberlain Acked-by: Darrick J. Wong Reviewed-by: Hannes Reinecke --- mm/readahead.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/mm/readahead.c b/mm/readahead.c index 65fbb9e78615..4e3a6f763f5c 100644 --- a/mm/readahead.c +++ b/mm/readahead.c @@ -210,6 +210,7 @@ void page_cache_ra_unbounded(struct readahead_control *ractl, unsigned long index = readahead_index(ractl); gfp_t gfp_mask = readahead_gfp_mask(mapping); unsigned long i = 0; + unsigned int min_nrpages = mapping_min_folio_nrpages(mapping); /* * Partway through the readahead operation, we will have added @@ -231,6 +232,8 @@ void page_cache_ra_unbounded(struct readahead_control *ractl, struct folio *folio = xa_load(&mapping->i_pages, index + i); if (folio && !xa_is_value(folio)) { + long nr_pages = folio_nr_pages(folio); + /* * Page already present? Kick off the current batch * of contiguous pages before continuing with the @@ -240,19 +243,31 @@ void page_cache_ra_unbounded(struct readahead_control *ractl, * not worth getting one just for that. */ read_pages(ractl); - ractl->_index += folio_nr_pages(folio); + + /* + * Move the ractl->_index by at least min_pages + * if the folio got truncated to respect the + * alignment constraint in the page cache. + * + */ + if (mapping != folio->mapping) + nr_pages = min_nrpages; + + VM_BUG_ON_FOLIO(nr_pages < min_nrpages, folio); + ractl->_index += nr_pages; i = ractl->_index + ractl->_nr_pages - index; continue; } - folio = filemap_alloc_folio(gfp_mask, 0); + folio = filemap_alloc_folio(gfp_mask, + mapping_min_folio_order(mapping)); if (!folio) break; if (filemap_add_folio(mapping, folio, index + i, gfp_mask) < 0) { folio_put(folio); read_pages(ractl); - ractl->_index++; + ractl->_index += min_nrpages; i = ractl->_index + ractl->_nr_pages - index; continue; } @@ -500,6 +515,7 @@ void page_cache_ra_order(struct readahead_control *ractl, { struct address_space *mapping = ractl->mapping; pgoff_t index = readahead_index(ractl); + unsigned int min_order = mapping_min_folio_order(mapping); pgoff_t limit = (i_size_read(mapping->host) - 1) >> PAGE_SHIFT; pgoff_t mark = index + ra->size - ra->async_size; int err = 0; @@ -526,8 +542,13 @@ 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--; + + if (order < min_order) + order = min_order; + + VM_BUG_ON(index & ((1UL << order) - 1)); err = ra_alloc_folio(ractl, index, mark, order, gfp); if (err) break; From patchwork Fri Mar 1 16:44: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: 13578747 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 C5E6EC5478C for ; Fri, 1 Mar 2024 16:45:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2EED2940008; Fri, 1 Mar 2024 11:45:24 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 29BBF940007; Fri, 1 Mar 2024 11:45:24 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0F175940008; Fri, 1 Mar 2024 11:45:24 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id EC4AE940007 for ; Fri, 1 Mar 2024 11:45:23 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id CABADA1CEE for ; Fri, 1 Mar 2024 16:45:23 +0000 (UTC) X-FDA: 81849045726.17.EBB561F Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [80.241.56.172]) by imf10.hostedemail.com (Postfix) with ESMTP id 535B4C0005 for ; Fri, 1 Mar 2024 16:45:22 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=OZmI+l81; dmarc=pass (policy=quarantine) header.from=pankajraghav.com; spf=pass (imf10.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.172 as permitted sender) smtp.mailfrom=me@pankajraghav.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1709311522; 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=F3Xg5bE7lOUEiWrLgvJkawBGempm7FqinU/8gfujPB8=; b=AuqCYJv0G4nWFdTvmBsbAplSUMEUCNGCle4WbadC7mv8afE5i3k5Lfdpb7AtNS1xp73fXn fgKy8lJ7kFZjRnGYhFkLoTl5/MgNBJRBKVIe2NQOV3pMLDJef2nXCyjwFUQ9cK9jWxrO+g CJu4Ud/HY7ZefSJ+gB60l/D5c+FwN4g= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=OZmI+l81; dmarc=pass (policy=quarantine) header.from=pankajraghav.com; spf=pass (imf10.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.172 as permitted sender) smtp.mailfrom=me@pankajraghav.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709311522; a=rsa-sha256; cv=none; b=N/jSMTQWBtS2FdKMfkH8hxM8Jz22lOQjr0JAgGzjo11+HM5scWC0I4UsXP5KSLVSFfsthB wP3X1S3xIwKP7VVBkraV2YL7f/N4BZVYixItoG9R6Qp0INdDpM1PTKeLdpefOWmyKMBwGY QIXoUSH+pSq+ye/ML3f8cf9W3zwpCHs= 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-202.mailbox.org (Postfix) with ESMTPS id 4TmYqM2l4gz9tW7; Fri, 1 Mar 2024 17:45:19 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1709311519; 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=F3Xg5bE7lOUEiWrLgvJkawBGempm7FqinU/8gfujPB8=; b=OZmI+l81//odOBAskdE4zl6fx7Y7LVheQ+0p8xiXpuBz9P7DZyU0Im1meut9eKMfMmB788 ipb6Wl0H30SzQq2hEQaq4wH35pYRxjMogRPWpnm6QhSPE9TbIn+hTafnbjpS+iJtUnffxl iByU4+WZ1caxuiG+BaPAA2sBfuzOzdtyly45fU418II1VmVRcZPFnjSmTSR7MBN+Bf8Rmy 6xDC4IVUbgGFmFkd1gcKMP/OesDKMF0KZuJoxLbYn2fZzWoMyuXP5Rvy3PNFfH7pRm2kuH C5UnREMrQiygk+CwzFIbQGQ6JDso3LOU+7kPNg4LV/P1QBLntDzO3hfnOUyagg== From: "Pankaj Raghav (Samsung)" To: linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org Cc: djwong@kernel.org, mcgrof@kernel.org, linux-mm@kvack.org, hare@suse.de, david@fromorbit.com, akpm@linux-foundation.org, gost.dev@samsung.com, linux-kernel@vger.kernel.org, chandan.babu@oracle.com, willy@infradead.org, Pankaj Raghav Subject: [PATCH v2 09/13] mm: do not split a folio if it has minimum folio order requirement Date: Fri, 1 Mar 2024 17:44:40 +0100 Message-ID: <20240301164444.3799288-10-kernel@pankajraghav.com> In-Reply-To: <20240301164444.3799288-1-kernel@pankajraghav.com> References: <20240301164444.3799288-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 535B4C0005 X-Stat-Signature: 96tb7zho1en8gfk8px85c5t1unk59cci X-Rspam-User: X-HE-Tag: 1709311522-926522 X-HE-Meta: U2FsdGVkX1+1tqqM1AuNEiQbGqkuxqDGd9X6oW+pIWCnBGxoguaC1klpGbBD6A2nskYXM/nxWTNHY1/06AWAmhJaKOy5epT8FdLGl5rnASLVcNdwXIYTNbD950jcY+w4gKTr75S3ANTiZ7XGiLidWUjQKZqVgQTispdNWq5at1Xr1MbjckPsWiINJdIeCX4wCz/tAMJ1nSK4m9Cz50yEoxEybPiyp+PEHY7axzoEzxBzRf4FI8NuR8LvbzF73e39rAdnsjg9+AanDYCYl3bZFGVyWUvQHvYuKLj1ZNkNRcOF9T70NRkZEAo1UOFeEyqxYPhUKhPxrIEXTTQfLtKpM4AJvlhIUAouANx+fRZVZhCy1DFlsTvsLWEcIjtp4Wv7+9kpJkLV7iN0y+70K9i2hYJrYGNtP9x9WDmIPodyNqo7vBO5q7C1IQMgIaEPXGOYOEWKR3YXNN+GQB55Aoyj1Z3wR2QYjvIHXFvxYOQkLJ9ZfJBgqGRCdGZ21ORVAFG92TmIyOfFCdGJ+oFmtO1KIWVPZ1NBpKeDaSXU/zY5jKDlbalcgJOioHQ6mmMgEHUfB8cfNqkQmgpiFrXpU1Dd86Q/g4HGBdwrroSh9u1mTSxl5K3Ikp2mN+vaHmw3h7Jmftf0t25IbBSKAB9oIn4exLKPL7JKTgy6zhhEIQPQWK84BiNTpAw1tgPVWXn5ncIU7O+yLl9gDBKF55O/syd1y/TwpGwzCb1PDJY+MavANekyvMwDbf24yVPYr5Lj7CaBqg0EmQcvk43wEJ8af76UBygy/lv5r2I2O7CfEDsmBurlm7OoGLa8jSYLA/xwxIik73rdf7JqNESRv73csp0+Qjser3gkoOenyhrhwo/rf+9LJFD9PaIeiNjkxbB2wrb30LtB/1n6BsLnbUevHE8KkjzVEJxINyv26tp/TLPW0JYRM2UHzBAM64jT+nhb1TODe7J24kNXB8/5OgCJk/w u0UhhAzz E9MDJJpygE3lQHFEfxybws5MVLmTbnLhPtniSh4chluA+X2PU5FtnVCMVfDK8cnAcrkDSSv+P2a/ald5LvI8fxNTVYA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Pankaj Raghav As we don't have a way to split a folio to a any given lower folio order yet, avoid splitting the folio in split_huge_page_to_list() if it has a minimum folio order requirement. Signed-off-by: Pankaj Raghav Signed-off-by: Luis Chamberlain Reviewed-by: Hannes Reinecke --- mm/huge_memory.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 81fd1ba57088..6ec3417638a1 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -3030,6 +3030,19 @@ int split_huge_page_to_list(struct page *page, struct list_head *list) goto out; } + /* + * Do not split if mapping has minimum folio order + * requirement. + * + * XXX: Once we have support for splitting to any lower + * folio order, then it could be split based on the + * min_folio_order. + */ + if (mapping_min_folio_order(mapping)) { + ret = -EAGAIN; + goto out; + } + gfp = current_gfp_context(mapping_gfp_mask(mapping) & GFP_RECLAIM_MASK); From patchwork Fri Mar 1 16:44: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: 13578748 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 0EBBBC5475B for ; Fri, 1 Mar 2024 16:45:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 90823940009; Fri, 1 Mar 2024 11:45:27 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 88DDF940007; Fri, 1 Mar 2024 11:45:27 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6E1DF940009; Fri, 1 Mar 2024 11:45:27 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 59D52940007 for ; Fri, 1 Mar 2024 11:45:27 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 30A9C120502 for ; Fri, 1 Mar 2024 16:45:27 +0000 (UTC) X-FDA: 81849045894.07.4B56F7F Received: from mout-p-201.mailbox.org (mout-p-201.mailbox.org [80.241.56.171]) by imf18.hostedemail.com (Postfix) with ESMTP id 7260A1C0013 for ; Fri, 1 Mar 2024 16:45:25 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=Rf4VH7so; dmarc=pass (policy=quarantine) header.from=pankajraghav.com; spf=pass (imf18.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.171 as permitted sender) smtp.mailfrom=me@pankajraghav.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1709311525; 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=CoSlfuEyGkiaGErrLwm5tBbxdIgWjqVT8F2G+alxKAU=; b=tYsmH4uRNhjNUrMsMHcWujK80cxCUUwqFKjGErj3wiPxthr/BDiv1paRzNAW5u+CaAhQF5 zMyQS/543zS335Uege/tbcaIUDGGwq1HbB9mYr/83hWI8KbXJ/sNeA9k5DSSoCcI2A51rD 0toQ8qi31wxY6SxahCC+esWuSJBdB68= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=Rf4VH7so; dmarc=pass (policy=quarantine) header.from=pankajraghav.com; spf=pass (imf18.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.171 as permitted sender) smtp.mailfrom=me@pankajraghav.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709311525; a=rsa-sha256; cv=none; b=QtF1Zw1jFh4MnFmvVsNMeqanUEdOyLTSOYPB2WnLSrcX0GPbS/KfuE+4kuLYw+86g7EmXk 4DPTPZKVxm5PqT+CGnrcH9Jf+nm+HwbusG5JF3QrPdpskq8Oz69k39OuHUJFiMxTcOrs6K tNyYVuXgo1duNZgEw5SN303ZyHx6K7Q= Received: from smtp202.mailbox.org (smtp202.mailbox.org [IPv6:2001:67c:2050:b231:465::202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-201.mailbox.org (Postfix) with ESMTPS id 4TmYqQ3Hk7z9tCB; Fri, 1 Mar 2024 17:45:22 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1709311522; 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=CoSlfuEyGkiaGErrLwm5tBbxdIgWjqVT8F2G+alxKAU=; b=Rf4VH7soZ/cgnAGRXcTEcKIV/sG+KQuBxSpjF53mjWkAVL6sw+HKmLZew6ousle6MJeTUR IHe7T5isExiLl34phOmLhBwfhIZEFdlgboAhxkyuZgZuf5NaxXrr27uqubaNFYdGVJD9SI L4yen1nde0OHzhSgMHHVPvrT5AK0WDQ6MA9eXSGNzhILjZ1fr5/v8PTxoP/MEiJ5ivl7kA d9Q+olVPgC8eTnAA4azyQ/pNJveDrQS69Ks+aTtNNlTHuVnAlQxPKoYb6QV6h/XK+zmD07 PfFk8VJkOPsqMYrsi/y++OTMIKetmkWOleeP43XvHi+QSCDr2GUPbuDuaMwb8g== From: "Pankaj Raghav (Samsung)" To: linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org Cc: djwong@kernel.org, mcgrof@kernel.org, linux-mm@kvack.org, hare@suse.de, david@fromorbit.com, akpm@linux-foundation.org, gost.dev@samsung.com, linux-kernel@vger.kernel.org, chandan.babu@oracle.com, willy@infradead.org, Pankaj Raghav Subject: [PATCH v2 10/13] iomap: fix iomap_dio_zero() for fs bs > system page size Date: Fri, 1 Mar 2024 17:44:41 +0100 Message-ID: <20240301164444.3799288-11-kernel@pankajraghav.com> In-Reply-To: <20240301164444.3799288-1-kernel@pankajraghav.com> References: <20240301164444.3799288-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 7260A1C0013 X-Stat-Signature: wdyhij5uc6dthrfrqfjwmsd4a5g1htrq X-Rspam-User: X-HE-Tag: 1709311525-114209 X-HE-Meta: U2FsdGVkX19nFM0lugBYCsJnua6WiI+sG5e3RGmyqhbpBpFmo9MsmbfN9lgZT2PoYoA0yHH7dfIPScNjeZzqS6PT2WAiBTM1qpWuR1j8FIEB0rGCy0bRfW9VfjJ80qsBLaef4SpNb3VknVHG+6Gl4UhNrK+Ij/X9a6V/kSoWOVJdfC1OtSEH8UlieXPTjaE5c9zOn0rCe/SAQJJH4Y8DhbeJPIlLamYEs2Y0nlYuoTFvrTKsi1M/yaF26MjyAw5tBD9Z8d8QZYi3GK4eRJk5Rb6j5boQ0KcMxWqHkT/goeT0OwZzE1SLhx7aWI3mk/DUe24VaskyzlW4MbBPpSxX6UI7+JRjyzWmL473HGv3Yy/J+SyWWVF2m1TdxHwD5TdEy5P3qH98y+keBHPwrVZ+jyVi0a5dJMtdVNh5jAjSdqb24lPjfgMLE0h02cf9wq9tVy4mOb5t49ev6yyZBrv12BAccYmsqvM57jyIRfcfkuRSVxyA/ydXvo6TOfPhEjbEgehb0cJ3Ei83IH4ss4Q6QB7365BXs5bl4mWMBBchXICXua8bxt3Rmg7dtkgcwU0FbLZ+EceCFQGt+nQ+7z7t+OeNTjBVQDb0mkVovJWLqKh6bfBQfEVy9ivYXbOGamtzViPgxz2B2U5p/a1CE9XAIVwwusq1e0WD6S+0Vw/14xNwTIktfp+1913pkZuvwvCnFbGTBNWwNRl52qP/9mlc+qDEIhGatC6xDHwMJL0l/aTPvHyAN37wAZX/i1HOsopReXL02XazmRpGy1zsUsDITHPY8o+W1Zsu25bTu1hStzNxkxmKO9ER6zQOKzJPz3FUnI7KqeogC03nM2iOuAhpueBeGRnswA6sEnzPsUh1YsnTtDoNEKLWm6IvxJZCeD83bkFDqqEGUck4lvRHHXtlqgY+3ZoDteBeQ5R6IaQPwbAJ8XdKFKnaX4SKVadFmNYOVohXYnwyiCcakF6eio4 pQGy1UXX YxNukYDgKAEIbeMDwChsDNoTPXamGwS0yfM5gZtOb6ygp7GhSyKEDmmQ1gC4IuSe9qDtyiCB1abJDE+1WhivRjqL+ck+2GhrZleE3FCb5fvJdep2ebmlVPxZlkE5lWXj4pKAXUXNkKJqSABQgCKTNwwylKSwuhRUL6hpyFF9gsJjwixQ48kKm9JzIFEGUzI48NsXSmDFNoGtIr9qHs0a6LTjuBEsbasrB4M10uA2gxLPX8A7Uz2iLIPNi6EUG2hLuMte0jpboFndLIU2P1cpdZPg3nZE/tNGSYwIbxEUnSF/YJrxVo4xayoxeoTfw6aLm+fYBw6bAlakPRT8VmdIjdR6bfZe+XukaAUKh25K50I+R/UIGt4S5upwMjQ8DAykSfoWZ5O4zQvbwkCcLadH0I88zNYnhtCJpytiowSwLiL/wYbREjXe+YMgAz5oI6Y3DQhsDf25kw/T+L0xLHAOrG/qq10OEnsUlCf3hMXkjLw2yBus= 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: Darrick J. Wong --- fs/iomap/direct-io.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c index bcd3f8cf5ea4..04f6c5548136 100644 --- a/fs/iomap/direct-io.c +++ b/fs/iomap/direct-io.c @@ -239,14 +239,23 @@ static void iomap_dio_zero(const struct iomap_iter *iter, struct iomap_dio *dio, struct page *page = ZERO_PAGE(0); struct bio *bio; - bio = iomap_dio_alloc_bio(iter, dio, 1, REQ_OP_WRITE | REQ_SYNC | REQ_IDLE); + WARN_ON_ONCE(len > (BIO_MAX_VECS * PAGE_SIZE)); + + bio = iomap_dio_alloc_bio(iter, dio, BIO_MAX_VECS, + REQ_OP_WRITE | REQ_SYNC | REQ_IDLE); fscrypt_set_bio_crypt_ctx(bio, inode, pos >> inode->i_blkbits, GFP_KERNEL); + bio->bi_iter.bi_sector = iomap_sector(&iter->iomap, pos); bio->bi_private = dio; bio->bi_end_io = iomap_dio_bio_end_io; - __bio_add_page(bio, page, len, 0); + while (len) { + unsigned int io_len = min_t(unsigned int, len, PAGE_SIZE); + + __bio_add_page(bio, page, io_len, 0); + len -= io_len; + } iomap_dio_submit_bio(iter, dio, bio, pos); } From patchwork Fri Mar 1 16:44: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: 13578749 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 E4BDFC5478C for ; Fri, 1 Mar 2024 16:45:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 77F9A94000A; Fri, 1 Mar 2024 11:45:31 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 71147940007; Fri, 1 Mar 2024 11:45:31 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5815694000A; Fri, 1 Mar 2024 11:45:31 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 4475E940007 for ; Fri, 1 Mar 2024 11:45:31 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 1A4AFA1CF1 for ; Fri, 1 Mar 2024 16:45:31 +0000 (UTC) X-FDA: 81849046062.29.21FDC90 Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [80.241.56.172]) by imf25.hostedemail.com (Postfix) with ESMTP id 4D7BBA0006 for ; Fri, 1 Mar 2024 16:45:29 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=0NCEvPJd; spf=pass (imf25.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.172 as permitted sender) smtp.mailfrom=me@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=1709311529; 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=hTTuIiANd5kCHMpVIcnhOGjU1SgMYOpCUNpWo+aN5OQ=; b=06gyFpvSvxwjK6nm8V7lCCm4n5U3TfGPZtgMerxc/Vnb33UxKFI47worv1XHtHjJrRD7KG Y3XATe3G7wrG5vXwmA30XIQLxyKERJAoPTf6YQW3RGILeHyx89PQloevKe9qbqSK9qnpfa Buh79oGA/KJPeTgMGvMQlfFXnYVUbTM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709311529; a=rsa-sha256; cv=none; b=vgN/NNRKUUBCuK0neRB/l60zCAmCANT+tGm+HhMAnM7Y1VUR6ap+ecKgwnGsMRct1PXyxM e/lpO4M4rs719lnz2tHpmp8LNJ1N9YkqR3QHNvvZfiA5KKr7/ZgXT1q++OocylAZh8ZzWr TI4fo5hYUwDUHwPvLyoS69aNpaRXfDo= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=0NCEvPJd; spf=pass (imf25.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.172 as permitted sender) smtp.mailfrom=me@pankajraghav.com; dmarc=pass (policy=quarantine) header.from=pankajraghav.com 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 4TmYqV0SbKz9tWG; Fri, 1 Mar 2024 17:45:26 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1709311526; 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=hTTuIiANd5kCHMpVIcnhOGjU1SgMYOpCUNpWo+aN5OQ=; b=0NCEvPJdd4ZEm/pZAZuCWy9XIlnUOtlWaauKypZe9P5F5ntCE+g/+PjzImbecph0YYvig/ ERtH1tJPJuP+IrQy6srtTTxprCqpcpCGn12/P3rnfM+5AeV85UHGbuOkGW2gU1OVRKk0TS AaNkqKsh2FVbzE6I+1mHAdaQ0qoI6iY503orVDqX4dRohCWWfIns0Us+KJjTPSDrK9a3ds QItylujWub7PPZL3dHm41Z62PDEAIDyDdhyAJ7dFh83D7M1CeEJ3ubndtJYyVGAIPZnljT wEGdXx5kF3MyLmOY8wEKjccltT0TtyWGBJSpVeCtz1Aif3/oRTY6yUVQr+1oaQ== From: "Pankaj Raghav (Samsung)" To: linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org Cc: djwong@kernel.org, mcgrof@kernel.org, linux-mm@kvack.org, hare@suse.de, david@fromorbit.com, akpm@linux-foundation.org, gost.dev@samsung.com, linux-kernel@vger.kernel.org, chandan.babu@oracle.com, willy@infradead.org, Pankaj Raghav Subject: [PATCH v2 11/13] xfs: expose block size in stat Date: Fri, 1 Mar 2024 17:44:42 +0100 Message-ID: <20240301164444.3799288-12-kernel@pankajraghav.com> In-Reply-To: <20240301164444.3799288-1-kernel@pankajraghav.com> References: <20240301164444.3799288-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 4D7BBA0006 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: nxo8etoud8mnnx6siu4mfrx3fmc4xpap X-HE-Tag: 1709311529-990237 X-HE-Meta: U2FsdGVkX1/ujI0I42r7xbVVazxda6isQjzVk9b2SyBlEV4oV7RdViNA5KDbvljHKQiC/T/l1oeQx8gt7h5SfcGpm1ejpTP6RaTgmH80H3x14v1ebIuuflU6zzaww4pFH71i8lJN/d/G9OTFCfWeBcTMfN3ag4NdJzqNYFVmaTJXiNlxXN+KmZnM4qNKS4ER0wNOaWCBcIvQobEUAg8W6MmLg9RMb3c4bWJ9SMvZmUa0Q58ZjoqnUCOqsgMW5pkEOhuxwzKl/802qVP2c3JukAqoSyoHE9547xgkop+IkATs6RA3hY+QqIYrfp35hSqK8ySqUk+yE2os6dSTiWw38kOGfew4e6EeOoyunFhLq3ltDkR0y0bJ55p0jixI/0gsrdUVWvkAzWLEjP1zTxjCdt79ZZFusWSynggSZgs8MDsKjMQRsjl9GMfE6u3osD2sv7RI+GD6viNtPbDV/hvcfR3iqbekGMJfgUoQVdhW6/WgfnXxkrpbGH+o4pVEJaLeGjDuwDywUjJpStMEC40RHAv4c5iTWLZ5EkLBRI7NXXB0tZ1S4bFX9QMBFsvpKPbl4EQArHhln395pQtFll5zDsQbH6MAvdNjJ92+/SoQvuwGFRsC+gauZto2Y0vja2oHAaWETc4MEW3Tg36Tui/WFL80e+CzaQuWN2hH2OeUOJrUi/xEzMHMwZEs4m7iZL6sL9fJfnptHGcdAO/s1qheP93s6XdM8uCFij7VPUiZvcpWemtF9XyAkVUvt3m92jP6ADshaOMpkv+jZdfO9W+N7Em0V5BHzlj/rNTJn0nWYn3l1pQCOGvohfj5aBNzxUs5T+6WA2imE3xKrNJJDzl7Gt6DGfY4a9y9d1mCnm/uSFFDbqa5VTild1ub2RlO63L5H61Tm5CXdFd9AzpPQa3IEIL5EVeTFK+5qU72zSH9akwN7+sz5OjIZjM56ggXX3/sYwqcYKyLGuVwSd7I2G7 kLbtAmcc p5u24788REed4MNK4XxEYcaVvfoCw6dYi73s/e9Fg8qut0193mh4pUq2jxbeIllhy+sVre6gUsNhpcV24kADR5/mYjfNcW1E7FL/w187f9Ge5LWN5sbf///vTxsUxCsrV1TUg2LF1sC+cT9TcEq6oVInWnrIjRe/R7bAS5a0uinvfl72kUw07tl4G3ldhEDQpjVG2Btl7hXvV1WKqaD0+nS8esov57v3fiJM7bmVS2vtCpx0z6ynQgYU6a1alh9zEU5OpRWFmudOA4nFL/1anKSB2MYVEHDmGcocZF02BEQ03O8UWtbe5OfkmXosOit2U2FRA7NJspWpm1AFJErDvDGXkqBWyu31FalprXKYuMUZBy5VCObYg7QPKmw/Z6eRmhp/sSjXa55jJQqw1oWzdcX2nEvEFHptUo7oUj4LgWARm8wsDWIZBjVKSgXS5RB7FG/hMbOCf3UrgMZ/hIdOjMzjOTLVYCpGS8z3Dk1HXm191DK/SnwQQqY3eXT8e843X0GQPngePAceAPEeoF5hz6J/afs9amXrSD00aRKNUGJ+dTft61uIWWNiwNA== 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 --- 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 a0d77f5f512e..7ee829f7d708 100644 --- a/fs/xfs/xfs_iops.c +++ b/fs/xfs/xfs_iops.c @@ -543,7 +543,7 @@ xfs_stat_blksize( return 1U << mp->m_allocsize_log; } - return PAGE_SIZE; + return max_t(uint32_t, PAGE_SIZE, mp->m_sb.sb_blocksize); } STATIC int From patchwork Fri Mar 1 16:44: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: 13578750 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 DE055C5475B for ; Fri, 1 Mar 2024 16:45:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6BEB394000B; Fri, 1 Mar 2024 11:45:34 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 66A10940007; Fri, 1 Mar 2024 11:45:34 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4E44194000B; Fri, 1 Mar 2024 11:45:34 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 39728940007 for ; Fri, 1 Mar 2024 11:45:34 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 129E941383 for ; Fri, 1 Mar 2024 16:45:34 +0000 (UTC) X-FDA: 81849046188.24.6291A8B Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [80.241.56.172]) by imf01.hostedemail.com (Postfix) with ESMTP id 7DF9B4001A for ; Fri, 1 Mar 2024 16:45:32 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=nwU+P+9a; dmarc=pass (policy=quarantine) header.from=pankajraghav.com; spf=pass (imf01.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.172 as permitted sender) smtp.mailfrom=me@pankajraghav.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1709311532; 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=jHOAd9x0YRVSd/dvnN0auN+I3KtosAxaAU4ZYQzup9I=; b=6U5vFveMFCO1EqjhkXfpYTivN5VcwluPQjlVw5JPIhE+AtAfYpk9FY6W+3FMuWF9GrtHOf COegWtLu76pDvJIkPBvOBxP0humD2AFaaBaNtacXiVnRKGWQTS5/DrX6IHXP8h8NPmsQ4J y74ucVIuCEYQ8wIdD6TtQZ6hsAIecyU= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=nwU+P+9a; dmarc=pass (policy=quarantine) header.from=pankajraghav.com; spf=pass (imf01.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.172 as permitted sender) smtp.mailfrom=me@pankajraghav.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709311532; a=rsa-sha256; cv=none; b=8ScBfIUfzD/zxN6tJ4c6M9gkrAGfnbxRAdGgsBaBegezb35vw4l+9zVweTDB2qcr2IKplt M5k6PlqVpSo2YYoj3tNQzAcXQpAbrT5tIeGgKfD+q1oR8tkT2MkxfkKKd0nOybSzijsYvw C7ja3lC2GtBRaHvelHr7iHMBXLVASTM= 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 4TmYqY3ft9z9tW7; Fri, 1 Mar 2024 17:45:29 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1709311529; 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=jHOAd9x0YRVSd/dvnN0auN+I3KtosAxaAU4ZYQzup9I=; b=nwU+P+9a3uF5NA7u6ijpi6mGj8WO2v/jjNlHzx7ZxLokEZE5PEgAPYYwNjrPK+Tms9wLwQ Pyz3Y6zKfMOGrh0h2VqWh2Xebs6ECkTHOJxrSP7lJmYSxooolgOm898sH7IfMtja4+xGbf QGn8iUq+WZZldhVy+gb1dxTa7Ny3C2BlNxq8eJnkFSDSoR0286+8t8p0UrDuC+8w/zds3S J+TgIDqaXHtYS/JGkjQDAQcq9WsaFH8ovt/DcyClf+Qc4mFxK3M8JiIMBwy0/MNjgfSVTg I9Fss6QCWHr13cCBIdBsFbx2KvYCliOGQ3dKcsxyAWzBWPURp+SXGtiqkS2XGA== From: "Pankaj Raghav (Samsung)" To: linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org Cc: djwong@kernel.org, mcgrof@kernel.org, linux-mm@kvack.org, hare@suse.de, david@fromorbit.com, akpm@linux-foundation.org, gost.dev@samsung.com, linux-kernel@vger.kernel.org, chandan.babu@oracle.com, willy@infradead.org, Pankaj Raghav Subject: [PATCH v2 12/13] xfs: make the calculation generic in xfs_sb_validate_fsb_count() Date: Fri, 1 Mar 2024 17:44:43 +0100 Message-ID: <20240301164444.3799288-13-kernel@pankajraghav.com> In-Reply-To: <20240301164444.3799288-1-kernel@pankajraghav.com> References: <20240301164444.3799288-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 7DF9B4001A X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: fwmirigortyi1b8r6fkxcizm1tgg7qxn X-HE-Tag: 1709311532-237216 X-HE-Meta: U2FsdGVkX1870QBWjXkOg+PKeuGGCjQdRoeVOTjt+WC8eZOMBxTQal8xIDSgv03iZ96DTUgNZFpHBuWM2JNgbX4r0XWICzVHlpA74wW4eK4Fqt8KTROrsMBy7WMzrqzZAHEe3AOadsq12UnDsS7CwqpYUArUHE+LxQLKLGKDJJLgfjX72kl7Akv9DtOc0Acgyh0NLmHloNDqNUnxrCQDtfBcg/HvrPTnFxAakOCJ2fuWTVTzOf34LdrI4tySjnQjADKC5sKC3/EfnfMCyY2QsYMsFKkoN6IK7BjlQNxI5HpX1KjfLwfWnvSgRVOXEdedIJ7h2QKsLxjmp6M7Tfy7Gfm2OZ68j9sMtrY438vYjQTuJ5v2xmmAmsSYhamwy1CUOxcQk8j5z7xL9dQBUbNc8K9d8F4klfRA1sttvpJzMCTYHf+HqEE+QUpY7t/lRRolOW1gxEf9yWf24m7De9ZKVD5EoucbfbuCYMJE/CDUvzrG5kEUbTGK4NMJRZujZixmP0egsW8+SNpkz9ZdbbaflX/2hvifd3+CuzzmSdspfTXx942p0A4m6T2oQf9V3WgRcVzAMHCGgTn0Nbu0GB6GNKslFcTeH+d5sWI2nwlaACscdgQr1y/emukssyviNaTFqyLytN7K8+sPENNxQW3/ZgCMu2LpuU6byOV2C9uoHpNvXR2X/rZrttpHaARdqSyKWtc7NmTxVYDJ+BvRODJDajTaJY8SrefgAG+8y/W/i1lNWuDLk/wmTIb2foa5dlaev3j3KTDZu8oXdUP/9mSC0ReiF+tSRl0rcOsR7IuV7o1jBUDZxExxqTVcsWqoyOXO6bA66KitV5vA1EakobqPmfLapQlyCOqDHA9y8Y6U1XiNF3cRKIY5pnCnMH1Xr79reyEFGIXfPq41PRIJsEaafrXXV0H7LV18RJuAfsI61CkzRckyXxc3bi5EjfW56HC6p161onhT1rTX9e/LOPp RPkwX+K4 y05LfrYM21YjmggXKYF93ZGMyqfClORC+mv+B46L8eVxa9NqLubjVWx3ibWxc+TQOdTMla/TEH8HV+sYepiQmPL9D5s0nnoAw2fXlbhaD6qjMQFWWtdv42UG4dx5c5EvvCuw1OfAO1X9IU3s= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000013, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Pankaj Raghav Instead of assuming that PAGE_SHIFT is always higher than the blocklog, make the calculation generic so that page cache count can be calculated correctly for LBS. Signed-off-by: Pankaj Raghav --- fs/xfs/xfs_mount.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/fs/xfs/xfs_mount.c b/fs/xfs/xfs_mount.c index aabb25dc3efa..9cf800586da7 100644 --- a/fs/xfs/xfs_mount.c +++ b/fs/xfs/xfs_mount.c @@ -133,9 +133,16 @@ xfs_sb_validate_fsb_count( { ASSERT(PAGE_SHIFT >= sbp->sb_blocklog); ASSERT(sbp->sb_blocklog >= BBSHIFT); + uint64_t max_index; + uint64_t max_bytes; + + 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) + max_index = max_bytes >> PAGE_SHIFT; + + if (max_index > ULONG_MAX) return -EFBIG; return 0; } From patchwork Fri Mar 1 16:44: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: 13578751 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 9B520C5475B for ; Fri, 1 Mar 2024 16:45:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 29C6394000C; Fri, 1 Mar 2024 11:45:38 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 24C00940007; Fri, 1 Mar 2024 11:45:38 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0A02F94000C; Fri, 1 Mar 2024 11:45:38 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id EA2F3940007 for ; Fri, 1 Mar 2024 11:45:37 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id C9D6F140513 for ; Fri, 1 Mar 2024 16:45:37 +0000 (UTC) X-FDA: 81849046314.17.37B1F7C Received: from mout-p-201.mailbox.org (mout-p-201.mailbox.org [80.241.56.171]) by imf21.hostedemail.com (Postfix) with ESMTP id 344671C0023 for ; Fri, 1 Mar 2024 16:45:35 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=rMBOipsj; dmarc=pass (policy=quarantine) header.from=pankajraghav.com; spf=pass (imf21.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.171 as permitted sender) smtp.mailfrom=me@pankajraghav.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1709311536; 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=5wzUd/M7ghnUlsNiIWLrpCm78wsb6uIwk5Sv3jrhDE4=; b=QbvqLsFLN6FutsogYpDI0zTsxk7qMEqPuvRkJbNv6L3NII+pXRm5RjfY60mVlYMMtS03rk u/QC02xZTdNOgVgzI0hnHLqXN8tYNxVRtM8HTavOjVzfh41BfZirXJA0qo+tAynh5D6xjR 6Art+puDncvwkvaXQRQpYJ8SAJXdNjE= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=rMBOipsj; dmarc=pass (policy=quarantine) header.from=pankajraghav.com; spf=pass (imf21.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.171 as permitted sender) smtp.mailfrom=me@pankajraghav.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709311536; a=rsa-sha256; cv=none; b=uKYU3N8DE3m2lAyDscTuTaLdLd5kga37ghMYKpz+XK8mm/nbN5okand87MbOqbadzOeO5r BB/TONvq3uCZRn0I9S7BSRmRWWVrplA6Jtp90vsc7BsTfYsjJwulB/QGfF3irbGxWGSxJJ vav10Ro8sBGPVTcKpS0zz46b+4ea2to= Received: from smtp102.mailbox.org (smtp102.mailbox.org [10.196.197.102]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-201.mailbox.org (Postfix) with ESMTPS id 4TmYqc6nYkz9t8H; Fri, 1 Mar 2024 17:45:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1709311532; 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=5wzUd/M7ghnUlsNiIWLrpCm78wsb6uIwk5Sv3jrhDE4=; b=rMBOipsj2b50Vol+/PLPN13o213KX6Sgu4s0nw+xplKlK/aVb/eFPsgk0UgrZLst5NUnYW k7Cin8vOiTKFSHGKdhKHNxiiQnBbPZ/xOvRoIOozm0vRrDAZR0ivPF2OrA/Ahch6UutPr9 kELko29pYXU4rzAKp13u4BCCV0VMMTTIqQh4ejEPaMlEA3dRoSV60Gjw23hKzMeqH0d+tA 2NrlE4euJ9rYg5nglYG1aSRTkTdFTypuO423WTy6PT4qu3eOZpJ3FteUVUiA1NbDSNcoup XO1K1DNBNb8zy27CqmMtnKkkwSNOPs7SPGEMgxquqNsqTsxis0jqCRQqqyTSUA== From: "Pankaj Raghav (Samsung)" To: linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org Cc: djwong@kernel.org, mcgrof@kernel.org, linux-mm@kvack.org, hare@suse.de, david@fromorbit.com, akpm@linux-foundation.org, gost.dev@samsung.com, linux-kernel@vger.kernel.org, chandan.babu@oracle.com, willy@infradead.org, Pankaj Raghav Subject: [PATCH v2 13/13] xfs: enable block size larger than page size support Date: Fri, 1 Mar 2024 17:44:44 +0100 Message-ID: <20240301164444.3799288-14-kernel@pankajraghav.com> In-Reply-To: <20240301164444.3799288-1-kernel@pankajraghav.com> References: <20240301164444.3799288-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 344671C0023 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: iibn8pac1ep5rrrbqz75p4e75cst8t1c X-HE-Tag: 1709311535-903546 X-HE-Meta: U2FsdGVkX19CNeL9XkKp2zVZyOHnYXQl0di3MCliNOs72gv4T/qPKYnIfyChkYM2LwWbd3TbuNDHL4U0l0YUIHRWuscx7/QgbQqTF/D9FZDv7ovVwocccbFZ6/dRc/RjA+IDthHGjrVSzGMQ6Y9Q+6D7O5I9lQEr4x8jaeKLJ8mML0MI94wSMNrxqGjRC2esELPocw0k5cCVV/FZnm9Gl6eAJhnSKsej3MeFTlBjfBUZbQ+IXvQehcgTmlMMp0sENAJEyyWJKiZh4YmWN5904zL3x1NjuXL18kEZjbkIukfEs7yc1Ct4oHs2y8M6f9uR6yTTNGUBcPUFoPNVZ/CCaroIh4JPEU8/Oila2aqOfTxY3h3PYQI/w/JYd29ziPmYrV2Kba6e2smt/vixCix/qZoDw8jFFfcL3KXDMm8VRMrjIcL5XbNjzJLamWSnK0Sj7BWkUW2nrqABlwRn3VZ1rhHSW94gtS2Q31pX47Wo4cN/iL+VHjfggQ5MNllwsjLp2QA6fktjkpOKBJClwm3ASvrsJeLPfggnMvf/3FYXLGc9vbBPgYQldXKeMyfxeMDrd5G1jTEOMPFhpRrgYj+ffIBqI5Iw4NDkyLUf1RF917n8kty082SzEi360k1eHg9I78NERZ83vxA9pty/eC0m6nNlUTt2IGbLJ3F8O0W7EjGMB5nG4+2LXXM2k4FB+jdHUqbfgRwn3Nat190c24XB99PTZdJowvz1Uwt3Ik2chR70vHr9bROJLNldBHj7Hx8FYRc1NIJfnrle642T0gUL0pSFBYRi1gLn2YeXVH/PtEAeSgZ+XCf3YlpkrzIHNkfXIjaUxIDtKesanF5tXUAfIM2oA75GpkIRqRZj6ucZoHbREYEksQ+Kvk5B93un1FBvclGu9eP6nF41+oONUHcQZSa3KBOh2QpBrzKt/zBSsFCx1TxW2VNdJ8YeszjcXGb7DU/P7uFl2WiGzpYv1Xg igLKJdHa zBPL1vWHVgErxJxe6+zQBxdn0kOxJQ2vi9dA7FB9Q/07H2hGm0rtUgR6U947TrL2JIn+DjvrAQit0g/BFrLRYryPfrQ== 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 --- 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 | 10 ++-------- 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/fs/xfs/libxfs/xfs_ialloc.c b/fs/xfs/libxfs/xfs_ialloc.c index 2361a22035b0..c040bd6271fd 100644 --- a/fs/xfs/libxfs/xfs_ialloc.c +++ b/fs/xfs/libxfs/xfs_ialloc.c @@ -2892,6 +2892,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 4220d3584c1b..67ed406e7a81 100644 --- a/fs/xfs/libxfs/xfs_shared.h +++ b/fs/xfs/libxfs/xfs_shared.h @@ -188,6 +188,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 dba514a2c84d..a1857000e2cd 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 or i_state! */ VFS_I(ip)->i_mode = 0; VFS_I(ip)->i_state = 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); @@ -323,7 +324,8 @@ xfs_reinit_inode( inode->i_rdev = dev; inode->i_uid = uid; inode->i_gid = gid; - 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 9cf800586da7..a77e927807e5 100644 --- a/fs/xfs/xfs_mount.c +++ b/fs/xfs/xfs_mount.c @@ -131,7 +131,6 @@ xfs_sb_validate_fsb_count( xfs_sb_t *sbp, uint64_t nblocks) { - ASSERT(PAGE_SHIFT >= sbp->sb_blocklog); ASSERT(sbp->sb_blocklog >= BBSHIFT); uint64_t max_index; uint64_t max_bytes; diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c index 5a2512d20bd0..685ce7bf7324 100644 --- a/fs/xfs/xfs_super.c +++ b/fs/xfs/xfs_super.c @@ -1625,16 +1625,10 @@ 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.", - mp->m_sb.sb_blocksize, PAGE_SIZE); - error = -ENOSYS; - goto out_free_sb; +"EXPERIMENTAL: Filesystem with Large Block Size (%d bytes) enabled.", + mp->m_sb.sb_blocksize); } /* Ensure this filesystem fits in the page cache limits */