From patchwork Thu Aug 22 03:35:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 13772576 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 58EFCC3DA4A for ; Thu, 22 Aug 2024 03:35:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6EFB76B0295; Wed, 21 Aug 2024 23:35:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6743E6B0296; Wed, 21 Aug 2024 23:35:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4EE476B0297; Wed, 21 Aug 2024 23:35:43 -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 269056B0295 for ; Wed, 21 Aug 2024 23:35:43 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 9EE9FA8152 for ; Thu, 22 Aug 2024 03:35:42 +0000 (UTC) X-FDA: 82478466924.19.916D72E Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) by imf12.hostedemail.com (Postfix) with ESMTP id C40B640005 for ; Thu, 22 Aug 2024 03:35:40 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Cg62PaOw; spf=pass (imf12.hostedemail.com: domain of asml.silence@gmail.com designates 209.85.221.47 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=1724297660; 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=coYbv4PcaCiw3s7iKLGpr0JKeDXM/58rHgT2Op2hXlo=; b=rfIbKjcbkMJnNmz6TLmlLhda056eMQOlW5KwZMzAfBelomyNX5prgiIktiR11CiEmMbYJl m6j815KIORmNUF6Hkaj7KLO6AT60VbwxiJzHgkQDOKQ4JSE00qwpQ7AjlZrMRU45Mmh3RN FmyQYhUQCWu2U+MzPxsZkQLA1mox09o= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724297660; a=rsa-sha256; cv=none; b=jVLOI4OKg331gv+34sXr+ZyckBMxF9Jou0hvnUMLTh+vfSbVvGExMx6P+/yawjNOP0kusr nXQnQHmR3mc+GwelRqTwtJAw7gk0F/X/dArrnpyHkJCY7kmUvAb0lN/ZpO5pAuX+iLVFI+ M8d4WIKBvtytVfNydXwHqjOTu92Rs+g= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Cg62PaOw; spf=pass (imf12.hostedemail.com: domain of asml.silence@gmail.com designates 209.85.221.47 as permitted sender) smtp.mailfrom=asml.silence@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-wr1-f47.google.com with SMTP id ffacd0b85a97d-371893dd249so100848f8f.2 for ; Wed, 21 Aug 2024 20:35:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724297739; x=1724902539; 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=coYbv4PcaCiw3s7iKLGpr0JKeDXM/58rHgT2Op2hXlo=; b=Cg62PaOwEYQ8D72DySoJ0VrL6AEgD7TqBCQNnPXVSaSvyY88Vmt1g0LNhZrJa/nPjB M1smnYuO4O6sxP0Xi6cQn5/3k/V7CQosbW/u4aeiq3yOE0BEsiW5o8TTJzKS8i/1mtPY sA2vhIIgpT/oWTjCF6zyjYZ4u47f0/TTowMaBE0fOAyzF0I+HVQSLTIhBYuF4uchAaOb HPB2b3Cl+07UA8jn/1HjCWFrE33fq2yQfTxKFvMil43e0ZhV6R6xrQS6+Nusy+azVARJ xA+C0QtZFhHz1GmfjezlzIOQMEL6RpCXISYSSWFZSn9I5Kdc0NeRBZOTZAQkZ5E/HopS PJjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724297739; x=1724902539; 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=coYbv4PcaCiw3s7iKLGpr0JKeDXM/58rHgT2Op2hXlo=; b=TeYgiasdxikhEniU0cMfBH4GFE59n1mTNGTOXFIjghWi7J0OxvrbJdZEH0fmADMH1z Kwq1Hp+KOr9+W20lOAH/mMLXZWiX+Yo9DWp8kJgu/eX5nWcJzglULaLNTsejlmDUqWyH 8SQdD8B0qUeR3O23n+fxmHIjpg/ZY/XPGZKpBjBVdR/N38XF2Ebi4jgcwW54QQtDgx5r w3FEvuE58xZCMrDVt1wO90+fmEM+4mEv21QvAREtE/3F7m6GIrXqZ86/+7cxpbC8la8v 5jzR5wU0n/zJo3+wwZb8bdHVffQxOgwE/Szm9fI2KFv/CU1LnZtAbcKavJu+7J1GMLTS Q+qg== X-Forwarded-Encrypted: i=1; AJvYcCXjY92BoCzvZdOIm1HTpsV9rCMtKfK6cxLUMFhxzcEXydhMWVr94Gq2KTJe7kZAr2wFf06X4FMtTA==@kvack.org X-Gm-Message-State: AOJu0Yyj2uysNT5O77wMUtqMMC2EXdqPz9O4R1lduPeeBPm+iF92dmwc Ulvo0lKtD0nQH1BYS6nK7H491pS/Kbrd1ctUdi14QPaK4gOjK7rT X-Google-Smtp-Source: AGHT+IHP7tOkU4byOXFqX59kqg4UjLfQGE6iQhOnMRCrdta+ni4FkcLFL3OtNWEW+YJSDoGtQ2G8Gw== X-Received: by 2002:adf:ef0b:0:b0:371:8763:763c with SMTP id ffacd0b85a97d-372fd5a45d5mr2872795f8f.33.1724297738908; Wed, 21 Aug 2024 20:35:38 -0700 (PDT) Received: from 127.0.0.1localhost ([148.252.128.6]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42abefc626fsm45491995e9.31.2024.08.21.20.35.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Aug 2024 20:35:38 -0700 (PDT) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: Jens Axboe , asml.silence@gmail.com, Conrad Meyer , linux-block@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v2 3/7] filemap: introduce filemap_invalidate_pages Date: Thu, 22 Aug 2024 04:35:53 +0100 Message-ID: <5bf2b0f08ec25fa649f04c0847722c6b028f660c.1724297388.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: MIME-Version: 1.0 X-Stat-Signature: p8ewqdasckafoqgd9o68xu45byzk7ugu X-Rspamd-Queue-Id: C40B640005 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1724297740-324141 X-HE-Meta: U2FsdGVkX19xs4OeGe3HrGetyb15vZgWswTIMD9E7lZ1o6LHXUaTZtL7cQBhmHQk/rBGzpIj9I1LBpOgayCBg4J9tJ/TcCikBtm1yy4y+UlP/CUbCDD5oGmgwSQv6bHlMvbvfqzM7xz7FDSAj/3vVDNR+J56Gc6B1d8cOLm/I6sl6YxoNIiUX+QZa9gKp7z332S9bKKTXn6Z92JgbK86J+QAJNTRzBPminCiBKDL4/twbNh9Mnu66+RzpVumbh0u1F1tQK6eZ7nzyphcaMyI5l+3e2aOI7+fHNxMhmi5/QH3qt/Oqsx+tCIq2br0DYWbpCRnYvxysA9RDb1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RgoFYncnQOAYHJHFPlcMWfsRaXQatU8k5r6Sh1PR2ACAl70e5sOnxPGF2Hg5C9klLV6BN3ZTpYKkNw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000626, 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 | 18 +++++++++++++----- 2 files changed, 15 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..74baec119239 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,16 @@ 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; + loff_t pos = iocb->ki_pos; + loff_t end = pos + count - 1; + + return filemap_invalidate_pages(mapping, pos, end, + iocb->ki_flags & IOCB_NOWAIT); +} EXPORT_SYMBOL_GPL(kiocb_invalidate_pages); /**