From patchwork Wed Sep 11 16:34:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 13800879 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 BEA65EE57C0 for ; Wed, 11 Sep 2024 16:34:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1A96F940068; Wed, 11 Sep 2024 12:34:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0D9EA940066; Wed, 11 Sep 2024 12:34:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BD8E7940067; Wed, 11 Sep 2024 12:34:29 -0400 (EDT) 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 9938A94004F for ; Wed, 11 Sep 2024 12:34:29 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 112381C42CE for ; Wed, 11 Sep 2024 16:34:29 +0000 (UTC) X-FDA: 82553005458.14.205CFF9 Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com [209.85.218.52]) by imf29.hostedemail.com (Postfix) with ESMTP id 33C76120020 for ; Wed, 11 Sep 2024 16:34:26 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=OWNqOaq3; spf=pass (imf29.hostedemail.com: domain of asml.silence@gmail.com designates 209.85.218.52 as permitted sender) smtp.mailfrom=asml.silence@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1726072439; 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=2XjW/1z5M+e5L1HlSBo37JIC76JYeYPBxc+HZavMul8=; b=WWV8Op/YB3uJjGwuSR7IUofijmZ3W4Bn027y2K1G0IpwWK66wdTFx4tTarhgXEMeLB4lJM BmlSKJgMulDKsWWRfe8WjGWu0gdOY0MDQ5NhuH0gvXGfqeH/Fux+qQfpB+4VMg1dOcnWhC XiTbeosHiY1n25m3do79Lgi/PR5snA0= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=OWNqOaq3; spf=pass (imf29.hostedemail.com: domain of asml.silence@gmail.com designates 209.85.218.52 as permitted sender) smtp.mailfrom=asml.silence@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1726072439; a=rsa-sha256; cv=none; b=OglogBiWGFDdz+mS7yDaolwh2+geY+Uv7BpQyqSlcLuiEFVOZkeBPZNonAQ3UOu473UWkk JIWGETvFIdeXXO9cdVJRuTjTHKMCsjMsMDrM01Irf86er7IHdW1uTQIxGd5MsFbi5sGSj7 egAi6QVJv4xuJyTH350AaRgkArIlHnk= Received: by mail-ej1-f52.google.com with SMTP id a640c23a62f3a-a8a789c4fc5so190240266b.0 for ; Wed, 11 Sep 2024 09:34:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726072466; x=1726677266; 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=2XjW/1z5M+e5L1HlSBo37JIC76JYeYPBxc+HZavMul8=; b=OWNqOaq3GweDp4e2lNgTvcpN2/ibO+dCe7sw2QAxDWgzkwW10xCaUGaR2wzBFigP2M kn6FGk9HP25c1206tXWW+uVPem1n97KUm7sZFNHSkTqKp5K9GDiNMQ7tuhZRcxGqdguH Kl8ntj6UvXgzfrRkC9MPdYJO4a5Bl8CtAf9J8tYftl7jfyFvk91doKyvm5GeH/M2IBiI SYUeHFAdwIL8n0po4GjHKQ0EX/mO5fdLL9uAw+55+QlfjWxV+uNMKQXPh4W4AN8AYREA u4lqFK6W7dhftxo0/TbF+1V/2Vybus27W/0n3LgGviIc2twip9FeKE2MRuRkSXRQok+I a3Zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726072466; x=1726677266; 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=2XjW/1z5M+e5L1HlSBo37JIC76JYeYPBxc+HZavMul8=; b=dSc5TVoDPJhaH6hSqJgYG1/Yca5yIHq3vkDdeVcN9PjBvfqriuglNTbxSfURMUInAA W6TClAlqJ9oMCxQi98LXs3V5+iVkhXkaQ2R+3FJH0kIQJCJaOz0T1Vbwz1KkUPHaP7PO UjS/itiXNMa65ZLZKNEIRMzY8HwVcuigQ7FFc3LGqChs2yxXWWeQbzVlf+TzAPo2LUUQ DizqRhcALg5pctviCxuZ+e3/g0aqNns4tCNpnc14zaK4Eqnr9B690BaK4TEYVBzdkt2N 2KoB+qxgcHQrnmqe6e/B/KIVYkvkN74gijA5DVWUlcEvO+gTsSZ9MioBKxrEwOTvVYVZ 74fQ== X-Forwarded-Encrypted: i=1; AJvYcCXMmADLV1cntXa/6OvFsGaNEcAeX921G/T5owy7zzbfBbTe2+BFefWTVMUe1Or+9EWW/LtcPYomkg==@kvack.org X-Gm-Message-State: AOJu0YxPTZmKFpZOZ+nb0cITaG+7y4JR6khSoatadRwWUrlIRYH9kW8u mQs+cuAPePUl2cq/gKaj1YrTco5R+JfxTjDFMHVbLhAOfbuNtFik X-Google-Smtp-Source: AGHT+IFMn90AnKpQjlSSfbL+WudXYP6lMWX8+dJQnqeRgseHvIS6DUoUvcDEA12mRbA7+KIVujg4Mw== X-Received: by 2002:a17:907:94d4:b0:a8d:141a:87cb with SMTP id a640c23a62f3a-a8ffb2459a6mr490300366b.18.1726072464867; Wed, 11 Sep 2024 09:34:24 -0700 (PDT) Received: from 127.0.0.1localhost ([163.114.131.193]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8d25c72ed3sm631820866b.135.2024.09.11.09.34.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 09:34:23 -0700 (PDT) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: Jens Axboe , asml.silence@gmail.com, linux-block@vger.kernel.org, linux-mm@kvack.org, Christoph Hellwig Subject: [PATCH v5 3/8] filemap: introduce filemap_invalidate_pages Date: Wed, 11 Sep 2024 17:34:39 +0100 Message-ID: X-Mailer: git-send-email 2.45.2 In-Reply-To: References: MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: pi86gkkrie8wu5r9eaqgypbf6b1qkxn4 X-Rspamd-Queue-Id: 33C76120020 X-Rspamd-Server: rspam11 X-HE-Tag: 1726072466-24392 X-HE-Meta: U2FsdGVkX18od/fDLPNZFyNFy9PHrjLGy5EpkthoJULpXuxFxJzNL52NaNg75tOledARxPdX3gqR3icR9KYLOh5adH/Ex4V0sijj1AUVCBlAXF3VxZ2eUzQ1nhz3gV1MU6YaFhrKXbUWhaypg8CkbI8YePBMSmxHz4/RrvHQWYor4XD+YLC7LSqnAkUufE/eBSFCUsdgJI8+oS82U+RnzLMyRdqrIwWQr7XdTLRn+miGJrTZZ+BQaLyQfgySgExhTCplVBKM8ARQq+HwRtvIw7EHUEgQgHAaAgC4oG8DrzmMLZwjK+KDCOGJA9N36RypJE9Dg51HtjMaQa4tPyuxWIAQ3fJsLuVakmL9EWFR/BQ+AMshADQodSKkX4IJi1xNTAk4SGbJGPmulwA4/MD3XQIZzyU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mGN35croBGfMlG700LqnYER8= 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: kiocb_invalidate_pages() is useful for the write path, however not everything is backed by kiocb and we want to reuse the function for bio based discard implementation. Extract and and reuse a new helper called filemap_invalidate_pages(), which takes a argument indicating whether it should be non-blocking and might return -EAGAIN. Signed-off-by: Pavel Begunkov --- include/linux/pagemap.h | 2 ++ mm/filemap.c | 17 ++++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index d9c7edb6422b..e39c3a7ce33c 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -32,6 +32,8 @@ int invalidate_inode_pages2_range(struct address_space *mapping, pgoff_t start, pgoff_t end); 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 write_inode_now(struct inode *, int sync); int filemap_fdatawrite(struct address_space *); diff --git a/mm/filemap.c b/mm/filemap.c index d62150418b91..6843ed4847d4 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2712,14 +2712,12 @@ int kiocb_write_and_wait(struct kiocb *iocb, size_t count) } EXPORT_SYMBOL_GPL(kiocb_write_and_wait); -int kiocb_invalidate_pages(struct kiocb *iocb, size_t count) +int filemap_invalidate_pages(struct address_space *mapping, + loff_t pos, loff_t end, bool nowait) { - struct address_space *mapping = iocb->ki_filp->f_mapping; - loff_t pos = iocb->ki_pos; - loff_t end = pos + count - 1; int ret; - if (iocb->ki_flags & IOCB_NOWAIT) { + if (nowait) { /* we could block if there are any pages in the range */ if (filemap_range_has_page(mapping, pos, end)) return -EAGAIN; @@ -2738,6 +2736,15 @@ int kiocb_invalidate_pages(struct kiocb *iocb, size_t count) return invalidate_inode_pages2_range(mapping, pos >> PAGE_SHIFT, end >> PAGE_SHIFT); } + +int kiocb_invalidate_pages(struct kiocb *iocb, size_t count) +{ + struct address_space *mapping = iocb->ki_filp->f_mapping; + + return filemap_invalidate_pages(mapping, iocb->ki_pos, + iocb->ki_pos + count - 1, + iocb->ki_flags & IOCB_NOWAIT); +} EXPORT_SYMBOL_GPL(kiocb_invalidate_pages); /**