From patchwork Fri Sep 15 18:38:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Pankaj Raghav (Samsung)" X-Patchwork-Id: 13387480 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 83F10EED61A for ; Fri, 15 Sep 2023 18:39:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B24D06B03D2; Fri, 15 Sep 2023 14:39:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AAF4C6B03D5; Fri, 15 Sep 2023 14:39:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8FF5B6B03D6; Fri, 15 Sep 2023 14:39:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 763056B03D2 for ; Fri, 15 Sep 2023 14:39:50 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 58C331CA0E0 for ; Fri, 15 Sep 2023 18:39:50 +0000 (UTC) X-FDA: 81239695740.27.6692D85 Received: from mout-p-101.mailbox.org (mout-p-101.mailbox.org [80.241.56.151]) by imf18.hostedemail.com (Postfix) with ESMTP id 889DD1C0008 for ; Fri, 15 Sep 2023 18:39:48 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b="eI+gl/BN"; dmarc=none; spf=pass (imf18.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.151 as permitted sender) smtp.mailfrom=me@pankajraghav.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1694803188; 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=rV9SUN768+vUSf43/qCLKk3hEIsfVKLWNcCU7V4zUtQ=; b=eOcEOJvCyrTKSXs6V6jzh9bMA4XHqtx2iAPEjGKnj5qZgv7KQUNBDCY9Df/pmftw2dhG0g W7PP46+Z7iuEijhILcNw8muHF0juPVx8KHEvRJW5ZhrwWDKEe0dy+tWnW9SgAca5GGRWmJ 76TM2nGnxDnrQ2A3EIi+ksIl+41ymJs= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b="eI+gl/BN"; dmarc=none; spf=pass (imf18.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.151 as permitted sender) smtp.mailfrom=me@pankajraghav.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694803188; a=rsa-sha256; cv=none; b=ViP4Mynlus4QGs1AoeFA1pyOpq/Q9ZRTbO0Sk1APk83P4B/Ru9Ta77bj3kJick1o6Zv5ng T7Tuiq30T6VIPNn44ISC1DW5+n5Wdb3CvTht/YlyqjJ6iJsb4jexqvR/EMSsRhFIAiPr+N HqvEPWywyY5aNJbBB+vwrQRps4TxHi0= 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 ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-101.mailbox.org (Postfix) with ESMTPS id 4RnNJx3l54z9sTN; Fri, 15 Sep 2023 20:39:45 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1694803185; 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=rV9SUN768+vUSf43/qCLKk3hEIsfVKLWNcCU7V4zUtQ=; b=eI+gl/BNfS9Dhty41um4KR+wRrFDQO+mDTbD65wgK9zPsLejVpU804xRIAjk7oY4J+Azil IVzX5dngUXpyfVClHiUUCaBnCc+02/4pud5dgOX6JQnyg72eUcxNj6QU8Sc/dnYHpcWObe paf2iuxl+EBFXfzLebEiH8GmUnBXq2RbfhMZtDylytHzq6bcq/Gpwf9XOVdf78jI04ETB+ xT7AyyaXTYUNMDkeQe91i2XK/OSfmotxpNcOTnfyY/W3bQz1zAy50mXsvOq+rw1ZgADZ8w TPwbbIX4YN/46fNwwcoiCqVkUIJwiBKy2eunAvqT3IHljCII7Tbs1TqQdCUCGg== From: Pankaj Raghav To: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: p.raghav@samsung.com, david@fromorbit.com, da.gomez@samsung.com, akpm@linux-foundation.org, linux-kernel@vger.kernel.org, willy@infradead.org, djwong@kernel.org, linux-mm@kvack.org, chandan.babu@oracle.com, mcgrof@kernel.org, gost.dev@samsung.com Subject: [RFC 19/23] truncate: align index to mapping_min_order Date: Fri, 15 Sep 2023 20:38:44 +0200 Message-Id: <20230915183848.1018717-20-kernel@pankajraghav.com> In-Reply-To: <20230915183848.1018717-1-kernel@pankajraghav.com> References: <20230915183848.1018717-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 889DD1C0008 X-Stat-Signature: 87xxbw33ncrdn5hcd4sau6wq5k1kprqx X-HE-Tag: 1694803188-638456 X-HE-Meta: U2FsdGVkX18crDJ72HNErUJmKssWSoM3b4L2ZvYg/kzZmkF/t4dY1BHfD0/99/JfrVh9sIHat4cY2xTKV6w7beeiN+U4W31Vm1yZn/eRFY10ANs0cPVPfiNqK4hzbQ3BJ4Dw2zlOVRTGZgBq310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qsK3hrRV709ZV+CdJZ6HpzPE0PGxHX1uN3oc8esXAmwpsXqaGNy0AEtq+2iwNXsQC9Yd94yg5Yc7ThMn816KG9VCT/PjuUNaV8wvX217KIB7xLo6slKl2ZEZCjVnG0vhxSIj3OHMiSSmh1WenTj28X+O2WA66bZ0Jn3paPXJI/7ScmEEF2wLTRhKTdqEB6+tOwTbRxwOe7n 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: From: Luis Chamberlain Align indices to mapping_min_order in invalidate_inode_pages2_range(), mapping_try_invalidate() and truncate_inode_pages_range(). This is necessary to keep the folios added to the page cache aligned with mapping_min_order. Signed-off-by: Luis Chamberlain Signed-off-by: Pankaj Raghav --- mm/truncate.c | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/mm/truncate.c b/mm/truncate.c index 8e3aa9e8618e..d5ce8e30df70 100644 --- a/mm/truncate.c +++ b/mm/truncate.c @@ -337,6 +337,8 @@ void truncate_inode_pages_range(struct address_space *mapping, int i; struct folio *folio; bool same_folio; + unsigned int order = mapping_min_folio_order(mapping); + unsigned int nrpages = 1U << order; if (mapping_empty(mapping)) return; @@ -347,7 +349,9 @@ void truncate_inode_pages_range(struct address_space *mapping, * start of the range and 'partial_end' at the end of the range. * Note that 'end' is exclusive while 'lend' is inclusive. */ - start = (lstart + PAGE_SIZE - 1) >> PAGE_SHIFT; + start = (lstart + (nrpages * PAGE_SIZE) - 1) >> PAGE_SHIFT; + start = round_down(start, nrpages); + if (lend == -1) /* * lend == -1 indicates end-of-file so we have to set 'end' @@ -356,7 +360,7 @@ void truncate_inode_pages_range(struct address_space *mapping, */ end = -1; else - end = (lend + 1) >> PAGE_SHIFT; + end = round_down((lend + 1) >> PAGE_SHIFT, nrpages); folio_batch_init(&fbatch); index = start; @@ -372,8 +376,9 @@ void truncate_inode_pages_range(struct address_space *mapping, cond_resched(); } - same_folio = (lstart >> PAGE_SHIFT) == (lend >> PAGE_SHIFT); - folio = __filemap_get_folio(mapping, lstart >> PAGE_SHIFT, FGP_LOCK, 0); + same_folio = round_down(lstart >> PAGE_SHIFT, nrpages) == + round_down(lend >> PAGE_SHIFT, nrpages); + folio = __filemap_get_folio(mapping, start, FGP_LOCK, 0); if (!IS_ERR(folio)) { same_folio = lend < folio_pos(folio) + folio_size(folio); if (!truncate_inode_partial_folio(folio, lstart, lend)) { @@ -387,7 +392,8 @@ void truncate_inode_pages_range(struct address_space *mapping, } if (!same_folio) { - folio = __filemap_get_folio(mapping, lend >> PAGE_SHIFT, + folio = __filemap_get_folio(mapping, + round_down(lend >> PAGE_SHIFT, nrpages), FGP_LOCK, 0); if (!IS_ERR(folio)) { if (!truncate_inode_partial_folio(folio, lstart, lend)) @@ -497,15 +503,18 @@ EXPORT_SYMBOL(truncate_inode_pages_final); unsigned long mapping_try_invalidate(struct address_space *mapping, pgoff_t start, pgoff_t end, unsigned long *nr_failed) { + unsigned int min_order = mapping_min_folio_order(mapping); + unsigned int nrpages = 1UL << min_order; pgoff_t indices[PAGEVEC_SIZE]; struct folio_batch fbatch; - pgoff_t index = start; + pgoff_t index = round_up(start, nrpages); + pgoff_t end_idx = round_down(end, nrpages); unsigned long ret; unsigned long count = 0; int i; folio_batch_init(&fbatch); - while (find_lock_entries(mapping, &index, end, &fbatch, indices)) { + while (find_lock_entries(mapping, &index, end_idx, &fbatch, indices)) { for (i = 0; i < folio_batch_count(&fbatch); i++) { struct folio *folio = fbatch.folios[i]; @@ -618,9 +627,11 @@ static int folio_launder(struct address_space *mapping, struct folio *folio) int invalidate_inode_pages2_range(struct address_space *mapping, pgoff_t start, pgoff_t end) { + unsigned int min_order = mapping_min_folio_order(mapping); + unsigned int nrpages = 1UL << min_order; pgoff_t indices[PAGEVEC_SIZE]; struct folio_batch fbatch; - pgoff_t index; + pgoff_t index, end_idx; int i; int ret = 0; int ret2 = 0; @@ -630,8 +641,9 @@ int invalidate_inode_pages2_range(struct address_space *mapping, return 0; folio_batch_init(&fbatch); - index = start; - while (find_get_entries(mapping, &index, end, &fbatch, indices)) { + index = round_up(start, nrpages); + end_idx = round_down(end, nrpages); + while (find_get_entries(mapping, &index, end_idx, &fbatch, indices)) { for (i = 0; i < folio_batch_count(&fbatch); i++) { struct folio *folio = fbatch.folios[i]; @@ -660,6 +672,8 @@ int invalidate_inode_pages2_range(struct address_space *mapping, continue; } VM_BUG_ON_FOLIO(!folio_contains(folio, indices[i]), folio); + VM_BUG_ON_FOLIO(folio_order(folio) < min_order, folio); + VM_BUG_ON_FOLIO(folio->index & (nrpages - 1), folio); folio_wait_writeback(folio); if (folio_mapped(folio))