From patchwork Mon Nov 11 23:37:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13871489 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 B49F6D3ABFA for ; Mon, 11 Nov 2024 23:49:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 710476B00DC; Mon, 11 Nov 2024 18:49:00 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 670856B00DD; Mon, 11 Nov 2024 18:49:00 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 49A676B00DE; Mon, 11 Nov 2024 18:49:00 -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 2AEC06B00DC for ; Mon, 11 Nov 2024 18:49:00 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id CD576A1B57 for ; Mon, 11 Nov 2024 23:48:59 +0000 (UTC) X-FDA: 82775456274.05.AD384B9 Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) by imf03.hostedemail.com (Postfix) with ESMTP id 24D102001D for ; Mon, 11 Nov 2024 23:48:38 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=kernel-dk.20230601.gappssmtp.com header.s=20230601 header.b=OmPBwuEX; dmarc=none; spf=pass (imf03.hostedemail.com: domain of axboe@kernel.dk designates 209.85.210.171 as permitted sender) smtp.mailfrom=axboe@kernel.dk ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731368763; 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=CL+fLnGK0BaMmMKm57rghb0D3nDN7TOwfaAxP5ktg80=; b=DB6YNE7ogRXbm/JY02FDjA5UfpXk5hWW0Qs3bdO45NHOZ0PzAo3k1/zfreeELbZBY4tHdB /ex8MQzn1ElPkRpVzH2LnTTGNkusiuvKORi7LG03yM1QNYWLm6TkvS6emuvTt1f4CQAhWF vQsBQa3lcgR1C1NahFhBe6EO9z4e1sw= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=kernel-dk.20230601.gappssmtp.com header.s=20230601 header.b=OmPBwuEX; dmarc=none; spf=pass (imf03.hostedemail.com: domain of axboe@kernel.dk designates 209.85.210.171 as permitted sender) smtp.mailfrom=axboe@kernel.dk ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731368763; a=rsa-sha256; cv=none; b=2BP+NAjujBAEOOHJqFHBBBcKMbjf/803Tohs1n2qPcC00dQRhk/fRI1deO42T34h8cwvTe 5aRH5D+5zwGI4ItPd9WZePO8AOLKUdJSeOKgUMqCHsRWpfnmcuj29QCXDdSXfdqqcioLYD OJULPYJYMr2zOksarWcRavyoTksY3SU= Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-720d5ada03cso5128578b3a.1 for ; Mon, 11 Nov 2024 15:48:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1731368936; x=1731973736; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=CL+fLnGK0BaMmMKm57rghb0D3nDN7TOwfaAxP5ktg80=; b=OmPBwuEXz6spXEaQ7hjpWtiLHDwQrXdiP7cwLhZivKC5fXYsK69gGVWFCty9POQygW 3LZVnxhGJDGTM0SxAQ6CtvPcOMrPGzqxZ9ZrwJ8f/d0qmEkte5kGK3tu7D6ETgcbZN3s 1O2lyt2hoeC8HS4U2gQaeIHVHEWvab8dCh6wEQF+Kto92U2syIl6sz3uZNvjEyz4SOrp ldErnlvMuxVV12X6ev59GUN3LnykUObe5rq7a6M4palAULeIdObEpVTBawettLB2u3vZ HWX+7bDnLUSXpx++LE9CvlgW/Cuu89lhPtIi+YiYlC2y6lo9yX2Tzg8w7jCKsVUaZ41f c6Ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731368936; x=1731973736; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CL+fLnGK0BaMmMKm57rghb0D3nDN7TOwfaAxP5ktg80=; b=QDmeZsxg0gILQtVChBx89rJphNdZCIPgWkQnQW3nAAbvnxfz9pNst1uwtJhr5XQXjC lfGF3mvIMMGsUsd/Zgq6QTAfHZt2LcYWYAkpqX59i2npKE254Awglgn4JCwpn3H+C5pa +25okjoOk+WAdbkEZZ6D/2tEuOF/v1+ghL5sDvpSIRJ9Hp25eh1oNgRVzhG1rUPaylLk IZAHleeeDmsywWMXTL1s171ocT2yrlXYM7IfJ/FWbTsQmGf7tKf+isg2y9hd4c27lN/u /W38YTV864Yh983H9OsKWlvaU4qmsMdELQB1nG9yzKNTXuqdL5zy4P8YMrM8NdVNkdMs 0zBg== X-Gm-Message-State: AOJu0YzguIIU7dAZfI764LM8u+xdrVWOfpsKVbuPnfLqnCKV83q3CZcG XfhujG7QfUltiyqzh41MtposTlFGKRVX7S8I2weT87gXw6cbkj0X9A7C+gvX6rHxWoRE9yjwNan QK2U= X-Google-Smtp-Source: AGHT+IGkT/vleDHQ8M3Hw8Ha2+EPGBpXcHS4Q/PdXfOEbEN6KEGRSFgIDbBBEJ7VgYq4tyZ3FLhGBg== X-Received: by 2002:a05:6a00:3cd1:b0:71e:64fe:965f with SMTP id d2e1a72fcca58-72413350e9cmr19827356b3a.20.1731368936369; Mon, 11 Nov 2024 15:48:56 -0800 (PST) Received: from localhost.localdomain ([198.8.77.157]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-724078a7ee9sm10046057b3a.64.2024.11.11.15.48.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Nov 2024 15:48:55 -0800 (PST) From: Jens Axboe To: linux-mm@kvack.org, linux-fsdevel@vger.kernel.org Cc: hannes@cmpxchg.org, clm@meta.com, linux-kernel@vger.kernel.org, willy@infradead.org, kirill@shutemov.name, linux-btrfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-xfs@vger.kernel.org, Jens Axboe Subject: [PATCH 06/16] mm/truncate: add folio_unmap_invalidate() helper Date: Mon, 11 Nov 2024 16:37:33 -0700 Message-ID: <20241111234842.2024180-7-axboe@kernel.dk> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241111234842.2024180-1-axboe@kernel.dk> References: <20241111234842.2024180-1-axboe@kernel.dk> MIME-Version: 1.0 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 24D102001D X-Stat-Signature: obcjdes88ye1m7ynfakbpxmugmu8k87q X-Rspam-User: X-HE-Tag: 1731368918-335832 X-HE-Meta: U2FsdGVkX1923YhhfpxwQvKu3VbXVCfFJPZOxI1HGJAz847t1nuZ4jGB298Lzpf0DXaPy4feR+Ws4dn0Qzd35RbfQaDMPzrGxT7ZCsealv33DqHjsiNveSwmjP+L+wmfLsJVXaBmohxsZS1Zb8U+dkGfJA5Dqotd4g0ciPF0j8FdyNeXN7aAG/lxlAzFNG+gTtw8dHNpoxbDJVihY0dU+JqJoG5LV5eL1mMNPNn4chDnEYwSesQ8V0ZBA8RLkIDfGvgsokw7sryGAVdYaVjcFDT2JB342ww6sBBVnQrA85CeHgjFd4tEy65+jXI7Pc9kTmTGQtdzGUpAoT3lvj8TT+5L3Rqy5FlZaIMZ2dkMs9CZqB+p+WIYnv91/xFFgnYu+bVrccbYqM6R9gW/PgSKDbcFQykhFGU8AGwNnSqLe9OLoZsYZuHhfGc6V635Bvcy0uIk39I8uOr7qC+VNqFtUtTw5I/ft4m4IdsemIiV4/7Se4/pjibzBsCW5fJAQ27HTmBA10qN6tl5q3cFxBropyK9T/TnXQ1XrSA0VBeohqHBoVBSfkviCSp4zMnXKvsjTxlrB6L9OKjoNEa1OIu/9gDWMAR80GaGZVTNbWx71kZloxsdlBq5RReEye6GJ+//rdgRh7f3cRSCegl+F/01hIQwYWKQos9FavWlesP0m/DbTBdpkEF3PBnd24H//YquoGpWx4XFtHGGq77AdH5qpbzxfWmApxlkAZ3ahsVOb2ENvS8xfpciThEjBMwSHwV1VqyECv1QYgfu4UlMkMfoU7zZjY6MGefbb2eqcLrwK23IpJXKUBbVirqwJFyu4zmDUSKJ7So3UT4Gq+PsIOZ6CZ46d0h98HyUcH12X2CwiQN5DMzKVU9d4XQm5fRJKAV/r+wQLuhxAMkM6qqmbrMZ0O/lhvqpzb0BLoTmUpF0W3eAtABIHvlqEvjh7PJ17kSVhHk7CyVafxxXHrp5XGA 7VlzxsXR 9a875sbjv6J2FOLNGLAE1hIiHJcCCJNDK/UCKuCCsdFeIxJqCezqA/DsBssPvwJ0sdX4Rp725RY+66d+2jgIegNor46lNoTWyrvzR3ZFrZVtOtRsThYbC20gNvkaWhuwbp6dVxkdwae51WEKOvNKvsGPsW+YypMUNP4+IvGSp14ySxzckutPdO61IG3Lq6PRS2VkCVwvCwvhAQCmHE4GHoLfJYnyTfxYyhqN/WnDbrmfW6nSGaT8gSqmDf+RTiV2gYj0U7ofT71sa4b4axJ4N452RHSoKKQZjp4wzjyOOGpFWqwNkkJO6gWmWZkoBIX6DpF49OlruRluWCSaV+QkfieXoFc21fvNGPu4B 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: Add a folio_unmap_invalidate() helper, which unmaps and invalidates a given folio. The caller must already have locked the folio. Use this new helper in invalidate_inode_pages2_range(), rather than duplicate the code there. In preparation for using this elsewhere as well, have it take a gfp_t mask rather than assume GFP_KERNEL is the right choice. This bubbles back to invalidate_complete_folio2() as well. Signed-off-by: Jens Axboe --- include/linux/pagemap.h | 2 ++ mm/truncate.c | 33 ++++++++++++++++++++------------- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index 8afacb7520d4..d55bf995bd9e 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -34,6 +34,8 @@ int kiocb_invalidate_pages(struct kiocb *iocb, size_t count); void kiocb_invalidate_post_direct_write(struct kiocb *iocb, size_t count); int filemap_invalidate_pages(struct address_space *mapping, loff_t pos, loff_t end, bool nowait); +int folio_unmap_invalidate(struct address_space *mapping, struct folio *folio, + gfp_t gfp); int write_inode_now(struct inode *, int sync); int filemap_fdatawrite(struct address_space *); diff --git a/mm/truncate.c b/mm/truncate.c index 0668cd340a46..5663c3f1d548 100644 --- a/mm/truncate.c +++ b/mm/truncate.c @@ -547,12 +547,12 @@ EXPORT_SYMBOL(invalidate_mapping_pages); * sitting in the folio_add_lru() caches. */ static int invalidate_complete_folio2(struct address_space *mapping, - struct folio *folio) + struct folio *folio, gfp_t gfp_mask) { if (folio->mapping != mapping) return 0; - if (!filemap_release_folio(folio, GFP_KERNEL)) + if (!filemap_release_folio(folio, gfp_mask)) return 0; spin_lock(&mapping->host->i_lock); @@ -584,6 +584,23 @@ static int folio_launder(struct address_space *mapping, struct folio *folio) return mapping->a_ops->launder_folio(folio); } +int folio_unmap_invalidate(struct address_space *mapping, struct folio *folio, + gfp_t gfp) +{ + int ret; + + VM_BUG_ON_FOLIO(!folio_test_locked(folio), folio); + + if (folio_mapped(folio)) + unmap_mapping_folio(folio); + BUG_ON(folio_mapped(folio)); + + ret = folio_launder(mapping, folio); + if (!ret && !invalidate_complete_folio2(mapping, folio, gfp)) + return -EBUSY; + return ret; +} + /** * invalidate_inode_pages2_range - remove range of pages from an address_space * @mapping: the address_space @@ -641,18 +658,8 @@ int invalidate_inode_pages2_range(struct address_space *mapping, folio_unlock(folio); continue; } - VM_BUG_ON_FOLIO(!folio_contains(folio, indices[i]), folio); folio_wait_writeback(folio); - - if (folio_mapped(folio)) - unmap_mapping_folio(folio); - BUG_ON(folio_mapped(folio)); - - ret2 = folio_launder(mapping, folio); - if (ret2 == 0) { - if (!invalidate_complete_folio2(mapping, folio)) - ret2 = -EBUSY; - } + ret2 = folio_unmap_invalidate(mapping, folio, GFP_KERNEL); if (ret2 < 0) ret = ret2; folio_unlock(folio);