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: 140761 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp1378030vqi; Fri, 15 Sep 2023 16:24:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEZUCVzR+ODTKc74u9DbOh6MDBxrLkl+sSUTomG+fX46//XPNkGPhGb8731Fl/OlGTKuJxM X-Received: by 2002:a17:90b:386:b0:268:1be1:745a with SMTP id ga6-20020a17090b038600b002681be1745amr2578613pjb.29.1694820299269; Fri, 15 Sep 2023 16:24:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694820299; cv=none; d=google.com; s=arc-20160816; b=s78dIje+mIc7ErAS/qU29g7J8fDxTFqojhqgJw2D6LdN4XUQ6KsZuqPVjqcqopDw2a qa7PMoX3LZb+lIhv1eFCq2tBRgwZieZ5ng+IL0YjD8nw6eJu6KgK9+HGKVWFwtF1lGrT EaaqruMY/jkisEdac3FgRT046kQ5gX541h6kQCNPZ815qhNPaAZEgHt5wG88m2g1iWuZ aParAuCGje6bdpJE6JBZpozC9cdtXkd1EYyca8QG4IoAJ4AlMvVa5R3rj3T8Pr8PXifB QU4U1mvJLNWooZ3eHM53UYt+BDNW3QChH5BMSKX1gKW2aTySkVTrVsUw1Dj8M2RRpF4t DouA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=rV9SUN768+vUSf43/qCLKk3hEIsfVKLWNcCU7V4zUtQ=; fh=kl+S4GAUWD1kOeoqBopscteh2mu3DZslcHc01dOJ6TI=; b=PSGmcuhRgROVYYClrufbGWE6HEiY3bF8+3csYXEQ7IaqUt5um6y37LUoeXhi3uVWsL xEXaAprqjk+blVTllNRL/nN6a6Hg6vAhNrc9eoW2D03l9SuygG0s6S2d0EDcjMjagzLC vhT67sp9B/fcAKGWkTT2zXcOFJXKFs7CkWJjsthK9xm2NPxMa82z2v0Llf8sHstf4PyH NYogcRJI/RP4iEZzuC9eqtAj3W54xGeAyJhglIPSMFdoRAccyHQB6Y6/leggV4ynh5Mi OaLXDXG8h9jNsBw3nhZOMImtcOcT9WalZ4gKRlmtY5UJk6CTweWa3zi6z9+bpZWS207U Fn+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@pankajraghav.com header.s=MBO0001 header.b="eI+gl/BN"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id lk6-20020a17090b33c600b0026800178358si4340137pjb.144.2023.09.15.16.24.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 16:24:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@pankajraghav.com header.s=MBO0001 header.b="eI+gl/BN"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id A39748225CBE; Fri, 15 Sep 2023 11:42:32 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236815AbjIOSmG (ORCPT + 30 others); Fri, 15 Sep 2023 14:42:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46578 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236866AbjIOSlq (ORCPT ); Fri, 15 Sep 2023 14:41:46 -0400 Received: from mout-p-101.mailbox.org (mout-p-101.mailbox.org [IPv6:2001:67c:2050:0:465::101]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B93D12D4B; Fri, 15 Sep 2023 11:40:16 -0700 (PDT) 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-Rspamd-Queue-Id: 4RnNJx3l54z9sTN X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Fri, 15 Sep 2023 11:42:32 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777147889877825542 X-GMAIL-MSGID: 1777147889877825542 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))