From patchwork Fri Sep 6 22:57:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 13794833 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 1620EE6FE4C for ; Fri, 6 Sep 2024 22:57:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C1F876B0092; Fri, 6 Sep 2024 18:57:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B599A6B0093; Fri, 6 Sep 2024 18:57:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9D3BF6B0095; Fri, 6 Sep 2024 18:57:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 7D8866B0092 for ; Fri, 6 Sep 2024 18:57:03 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 261931C5E3E for ; Fri, 6 Sep 2024 22:57:03 +0000 (UTC) X-FDA: 82535825526.13.607AFBD Received: from mail-ej1-f53.google.com (mail-ej1-f53.google.com [209.85.218.53]) by imf04.hostedemail.com (Postfix) with ESMTP id 4969340006 for ; Fri, 6 Sep 2024 22:57:01 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=ci92UBGT; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf04.hostedemail.com: domain of asml.silence@gmail.com designates 209.85.218.53 as permitted sender) smtp.mailfrom=asml.silence@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725663348; a=rsa-sha256; cv=none; b=ErK8Vwp6ybOW/8R1Po7v6S7Z/ZWumlgDAjf/KznUTF+qyQb370WJzalP9/FgIoo8Z4HnPY bO3MNoCpTewni02u3rItfTjRA4F70uK9oa6/mkgAEE+SKdebix1o8h4yx5wBQ6R/SqPHyb Hpf3jp79/tiFQZBpHt0ygCotzr0hEAs= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=ci92UBGT; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf04.hostedemail.com: domain of asml.silence@gmail.com designates 209.85.218.53 as permitted sender) smtp.mailfrom=asml.silence@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725663348; 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=QKXgo6Wd58l956KDWoPssKWLE2sE1H4pNLC62sk4XtsQ8ib9PKhCViCfMQaDxQxarduz0j zew/cd6aF+hpUKzriJsfiyv5oUR9cQWafHL81anxPKYDgYmzbv/Udj+dd5bUOzd9qbj1NT GlZUukNasnDo2HNITVbzjaNVL/88iX8= Received: by mail-ej1-f53.google.com with SMTP id a640c23a62f3a-a8a7929fd64so286558166b.0 for ; Fri, 06 Sep 2024 15:57:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725663420; x=1726268220; 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=ci92UBGTS+FDr7aU7Z4a/i9KSiv1sM8IZlTBkGDm5Rs/gzJC82XkjY+G4LQusffuE8 ZNM6cnuFMVlrkjop2XXWWofSf1IFCLscQunyl5IansE8ZrmRvd4s8pbXCqF1WED2Ex5P Lfb82sRWV+ZL9+X5LslcSp+FvRcXLyNAnRykdxP8149tioLrIeoEaCWUIYWM7SbHi3QK zACvKBtPLmpTXarfogblWsgbMswt6ZPqUxQjSpwg98pqH7dDDUeu20E5/L7K61tRFqYB ek9Xv3RMxFF+CRBC0ynhvMWoO4zvagGrRaEXAOPLIKxwC7Annnmfu0l0uhZER3oM/Zge a+uA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725663420; x=1726268220; 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=qzPk3MoFu8cOiy2IpDmiddky0la+H4n53yKEzLayntJo/5d7gN4otGZtzCXfe+L+3b 0H9M5dcrCY2/HlkgapTC6+tCjNbUiYHPMG4+yxuR9/SVzPi4UZgN/8qr6D8DuCGj+Q5c rl1NvZX9uSA/+nLDijZ9LGXTJSLMdEeH+uxW7epkNDKHfhzvolCd1hztH7x/Nf+Vl0PL WxUZjaRfbUFgvg3JT1y43hEiq4i/lfCTLfQMLubA18pywtcZTfNsGNlzz8p/vFO1+M0h lZpPMRwh939T+uUv2aV9C5Uii3JKtQzPPnOEB1p5Rr7PV6H/LwFQ5OLkW+IaY/Lp3AFe L41w== X-Forwarded-Encrypted: i=1; AJvYcCVzp82eni7AxK5SzUX+qwZsMVPAL8zEYPMUmUYdBggvfMCgtEO0vPoPoxISxLNry/uvL/6cyc8fFw==@kvack.org X-Gm-Message-State: AOJu0YzOd95rORlIy2fei1Bg62NNPXn5M68q1HiGDdwrzkWrBoJvmQ6P eKeyCGpVNJR+f2Sh+FNcP1rtgWvtl0QUz8kFqCAzQtewbICIQeTD X-Google-Smtp-Source: AGHT+IElFIAZCS4JhFrJt5ylxD7009i496r/jtdVHC3NBh65yo7l8qVQPQsC4GCBaH1S1XbN+0jHTA== X-Received: by 2002:a17:906:f59f:b0:a86:b32f:eee6 with SMTP id a640c23a62f3a-a8a88858b21mr338191766b.54.1725663419302; Fri, 06 Sep 2024 15:56:59 -0700 (PDT) Received: from 127.0.0.1localhost ([148.252.146.236]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8d25d54978sm2679566b.199.2024.09.06.15.56.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Sep 2024 15:56:58 -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, Christoph Hellwig Subject: [PATCH v4 3/8] filemap: introduce filemap_invalidate_pages Date: Fri, 6 Sep 2024 23:57:20 +0100 Message-ID: X-Mailer: git-send-email 2.45.2 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 4969340006 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: o5nqqnznbhooaoionqr4k75y6658zkme X-HE-Tag: 1725663421-469559 X-HE-Meta: U2FsdGVkX18qodL7XqKVRpAooBQrGEaqNEMCj2AODPz8tj9BomHfWte2IbN/WTII2ozG7PexmqfgQtDJWfCO843qXT8AdSle/PIB2p9a4q0MEsTO2LqyJ8c/9IJ5H/o4bIgGZcFFw8pYCpcE0pFA/HqyyTTfm5SaXBc+S4LsKwfwjYcT7HDHV2Dtzp1YCF67LRdI+d4yBRbjj+l5Ok4YBgl+mVkPQ2LahtrCIgHNGRqMtR+AGDbSZDJ0QJnYYw2dvYRRvQQylqH2DDcO8Vjsp+DXZbJuhDl38mpWCZZ90dpA5uzdXP7pdHnyCDbV9Ov/rY89Qj5xenFqzeHF86D+NSU56KCcGGyNPX2Fng2ksKv9T+yGKfeEexjQoR2317Q08vH6nPj+SPSMi5dKH+dEmtE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AW2QkHfnz4lWgWi9LzJ6ieo22+nr710039+Y= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000178, 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); /**