From patchwork Wed Aug 14 10:45:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 13763317 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 89BF6C3DA4A for ; Wed, 14 Aug 2024 10:45:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 911816B0089; Wed, 14 Aug 2024 06:45:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 89B796B008A; Wed, 14 Aug 2024 06:45:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 676126B0092; Wed, 14 Aug 2024 06:45: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 4359D6B0089 for ; Wed, 14 Aug 2024 06:45:29 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 07C4740E8E for ; Wed, 14 Aug 2024 10:45:29 +0000 (UTC) X-FDA: 82450519578.01.CD0FB64 Received: from mail-ej1-f44.google.com (mail-ej1-f44.google.com [209.85.218.44]) by imf22.hostedemail.com (Postfix) with ESMTP id 230A4C000B for ; Wed, 14 Aug 2024 10:45:26 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=VhpfWCAc; spf=pass (imf22.hostedemail.com: domain of asml.silence@gmail.com designates 209.85.218.44 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=1723632256; 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=PPg+lK6Y8tw+FdBAbHCV6zhdgKF87NxKSWW22w5pcnCTcQVGg2JvQSQB9PswKjtBAHeRLP wOw8cKYE5SjI9s3gaugV6xnLsLoz0zVLoiSUPSdZC2SV9bUsBaFOWq8bjyS0+QqCUxJiqS fj2lclMKt/Gy51p6WDP+/WDNbqAyap4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723632256; a=rsa-sha256; cv=none; b=cAOLBxuaWiDazN6aleubdA9PwJUGCVO/Q8QKNERyEOZXMXPCP1roGYsQQF803U2unD7GFb oITnYoww6dmKT0YBQUaqbbdQScXb7XOoCcDaS/OsvJ8Re/C0re+tVg2jvIdf87sOAZ9esV 1GfRuyXJxlNlAyaB9mccSQGPSRxKjGU= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=VhpfWCAc; spf=pass (imf22.hostedemail.com: domain of asml.silence@gmail.com designates 209.85.218.44 as permitted sender) smtp.mailfrom=asml.silence@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-ej1-f44.google.com with SMTP id a640c23a62f3a-a7a81bd549eso468129466b.3 for ; Wed, 14 Aug 2024 03:45:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723632325; x=1724237125; 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=VhpfWCAck5QNRGYT0+TImvNzMLikRF21rNh/oe5cUTNiJpfc0ZutBBH83skDbtxx8o BJf9/LAsr2/pwzAw4zW5xHryRC4x1m99rIVu/vVVWZNM6TIFJFuo5TjtfLWAIC+5O3FB Dcm6BqSwVAfl/LH2Li9QjiUfLUt3JocH8M3ROemG8TM9WES0tkxDSTRyQn9lfp31txD7 yI7NtAYXruIzrFvrUgPLtu7MLEYe6Y3ykG4VoEy+/qCc75Cl+gQHEoy8Eqe0Y95nsWLn tQuriCd/klJ88j58sdYxL8NXW/c+KMxkGNr/KbuPFlm23st7zQEQPeR98CXiKL0hHF8G II1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723632325; x=1724237125; 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=NE51JJNIZK9xrKSMR561YQ9G9YRE4kpX/nXjKGspBdvxKZ2fSaUWBxDxQytPnUq62i zoX6hzkKFOzzR8BDgwMQDqGtYofwJCiP3eeFmXY3Le/Uo5q2xhjFfIyC7/geF+12nENZ iItG/y9eTYkaqhl2ywfiMM66BP87z1rl8XUyV4+E6iIeFogjxUQz3PWY8tTh3J6OdkS0 ZAhYeS8GIAb3OgEmog1HCXuZGp0YbwZ9OutVF/yZupX9kic0x//lL42jIIAlU3HIFztN EciuTvlGOxLl6YVrJokMSo3/Pzk+vZHtyMdxQ5ncxzE1q5U9/Zuy/5skhZ2qQIOJanpO +m5w== X-Forwarded-Encrypted: i=1; AJvYcCXl0NrthaDcU8v0pNA1A5mnq/O/d1EFI/6O4j2tfU/bHbLVxsI8P4wl3xmxEl0sK441GNROBwqc0GbToA9H1KJNrbA= X-Gm-Message-State: AOJu0Yxcqcz/7us34KhhGfnec/SWokruqnyZvywsKmsQWhUJarXIQfHA g/D/OBnT9Wc9H/wuPfhHKKesk4BeGiZ2uawSqxwcWXZbAzOQKCujqlU1ZVwR X-Google-Smtp-Source: AGHT+IGfriIepvv++2PrjZ9Q9AjLepaO3ymcXMwFRj3SpDze6Sv3EXtnN23wF2rBhfZ8mcwRYC92+g== X-Received: by 2002:a17:906:cade:b0:a7a:1cfe:a262 with SMTP id a640c23a62f3a-a8367009c0emr168159466b.55.1723632325229; Wed, 14 Aug 2024 03:45:25 -0700 (PDT) Received: from 127.0.0.1localhost ([148.252.132.251]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a80f418692asm157212766b.224.2024.08.14.03.45.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Aug 2024 03:45:24 -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: [RFC 3/5] filemap: introduce filemap_invalidate_pages Date: Wed, 14 Aug 2024 11:45:52 +0100 Message-ID: X-Mailer: git-send-email 2.45.2 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 230A4C000B X-Stat-Signature: oeihjzccxamhr5roxoz3xpgfumrquoo8 X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1723632326-159376 X-HE-Meta: U2FsdGVkX1/9RKRmxy/YAV+6EezqiSkVxf099duVj7GM92OQU5Okm0VjdhcHLXjR2FiKY4/Z/DuXV4iQ6mHjten7UTCa64o8o4cW6EAeEhOfhBdIN2byV+wvh+g3t1bznmg01i25DGhDFI4J9nP3wVMdHvkxBVLp8Tys0JhFlPUXII0qiPBkvlB9lq07qrTqbQ143ZWGuoT3CvKJPgjfFNOgZX50J3jsLdtfhGX/FJwdJuMMs1i3R09CDpf6Lnc3XUPx0n86au/7LZcNjubgcvkVoXNMhIvfJ4f06zh36SiGDkhupLo6APC0KWIEb7AJLTD+ZhCpMoiYFDuDxLN3bKYkTNy3wAoGEd+ZWZd5EakLQ2MQY3Vfdu89GXvYTRxf5ZCnK1P82vO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yBM0d+IfNWQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000021, 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); /**