From patchwork Wed Sep 4 14:18:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 13790933 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 9AF10CD484A for ; Wed, 4 Sep 2024 14:17:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D28F38D0259; Wed, 4 Sep 2024 10:17:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CD8088D0253; Wed, 4 Sep 2024 10:17:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A8DA18D0259; Wed, 4 Sep 2024 10:17:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 89C508D0253 for ; Wed, 4 Sep 2024 10:17:51 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 1E879161611 for ; Wed, 4 Sep 2024 14:17:51 +0000 (UTC) X-FDA: 82527259542.05.67C15A7 Received: from mail-ej1-f48.google.com (mail-ej1-f48.google.com [209.85.218.48]) by imf05.hostedemail.com (Postfix) with ESMTP id 36E3D100008 for ; Wed, 4 Sep 2024 14:17:48 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=D4WSbmTc; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf05.hostedemail.com: domain of asml.silence@gmail.com designates 209.85.218.48 as permitted sender) smtp.mailfrom=asml.silence@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725459445; a=rsa-sha256; cv=none; b=xeCzNQG+25szIa9868MfGh82R20WIBa0nHlR6BIubwLDF/dBUep3Uozkh2WQqDg/QxCbBX xFlYe2RDb9u6a6Sux1D0zn+g2YsoLjiJzxfJCoKzQ4MXLAS/+16SNWHpNA6yalqT+iVq/1 ysPrvZ2uWQjc6HrVaoho9bmVWsW4rBo= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=D4WSbmTc; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf05.hostedemail.com: domain of asml.silence@gmail.com designates 209.85.218.48 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=1725459445; 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=pjYA929/RYUIe30bSJovFELR6prJj1vi6P+luEkzhCYotMI8En8loxwV+LT2U3ocb/maFW RGCyFCtZIpZ7REiJyglE2LK2uNCgZEu1laN0QLI2nas7XeZAvGcbh5dPdOsKbyE1IXY18m U7ixB6jGgw3YtfEnENpA61wXLFid8Fc= Received: by mail-ej1-f48.google.com with SMTP id a640c23a62f3a-a7a81bd549eso611147966b.3 for ; Wed, 04 Sep 2024 07:17:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725459468; x=1726064268; 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=D4WSbmTcGiMn0qDdrp2rBv9E/fiMIeuViCB3i//BfE3ckn7ROO5Fyi1C+wZkDEjNvO DFRO3hp0wrzeK6lm0i/9vUPu7rWwKjJ/U3FitnZeH4ywMTEL7SRyDee6q03Bt/+30k8l +6cEdckiPO8pPZT/EwOskr3IRHwa8WHBxPcWahqcpiggoAKQ3m+BcrW9BT8CLwGsQYp0 qoY3sOPLNOQCSytnNUwPzQzQk39PJbsiNcU0P79NqOm5c2PexYKJ14+/qy57dkpjCjuK q9lAmeWiqP6znUqzEhBUunm+eIgze3ewAlIoIvAf4X4B3eS4uLAWk7efG1yZ3iLEQ0fy b1CQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725459468; x=1726064268; 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=ugAGfxuulCqWPYMeBGBAcytyc3E37Ag6REWznM3iG3Qr5LKJEDSuwaUe1neXplwAyp 5FW7kkA9XPh8tc62uuecQFylNF1MQJsZUVZkmCmwapBXB76Y+wdFlIXQQrPSmIaj42vF A8IJm+U2Q7umN1HM95yezDX1pUIwj1EGVsSe4kXxNXU4wuKfxT2YCvyXrhxfy/ch6peb 7COdld1ZdeqGVQavHkNzBJbGukfdExPXUJts87FzaoPzRuxGEa6C9QjqUZZ0j6Ez0XiA kYelH/S30g+CdKZz3zELLaAnmY2nwmEBgmFPrx2qOYBLJObL3h8ShWEdja7saAJyxs2G 2NDA== X-Forwarded-Encrypted: i=1; AJvYcCXeDry9SK5wvVE8QDKpGsnKtSJYeZOW5dhsWu2QL8vupImNGKF13I7AngZCiEZlmqB0a/KTH0Fv1Q==@kvack.org X-Gm-Message-State: AOJu0YzCtbBOKrESlT8CslAmuyoL8L8DcpG3Y3M79WeFDQ2IsXh8sjH2 NKfhbSfuGmdvUs9GzvZkVOblMtJwQygqc7IX6X/jRVNFihoAXhFO X-Google-Smtp-Source: AGHT+IEYnlE2jE9AeI30LzbXw8Pi928CHHZ2cfjLj3+Sl10dnyCa2YAie/Zh3flyVcceULOyKSQ8nA== X-Received: by 2002:a17:907:1ca4:b0:a77:c080:11fa with SMTP id a640c23a62f3a-a8a1d4d2201mr484969666b.48.1725459467509; Wed, 04 Sep 2024 07:17:47 -0700 (PDT) Received: from 127.0.0.1localhost ([163.114.131.193]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8989196c88sm811160766b.102.2024.09.04.07.17.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2024 07:17:46 -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 v3 3/8] filemap: introduce filemap_invalidate_pages Date: Wed, 4 Sep 2024 15:18:02 +0100 Message-ID: X-Mailer: git-send-email 2.45.2 In-Reply-To: References: MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: 36E3D100008 X-Rspamd-Server: rspam01 X-Stat-Signature: sq1pw5rdkehgkxpo9brdxw5sb9cfed9u X-HE-Tag: 1725459468-384231 X-HE-Meta: U2FsdGVkX1+O3BVyJI6VwHF0S6utNmW733o5+fYOnrQdZQmUSSPz/43sLyLMfnvDgofO0C3RVQaSgrrJuddNuvvJ01ZRPBQcctItMkAcD76C53NJYyKsMNw2msL0uFlsog34jA8gjDdOaDHgtg6oSc8wy+qCupM5n39bEkhgOdc9noSxGcvZioPnmL0w/DMwQ7XkJxI47uYmlESMa8Lei313LS6YJ+eawGqmqNcIooWEL+PHH64We3vyZrV6BUBRgZTZWA1QL7JTu8i7rb7kZ4Moeudz2fRbHvPT2oi8Th/7bwhXmQaG9VSSe4pyE/3opNG9La3/6Z1I4Fad/dWqE3qk2MaL4LjHobdF/bmXc+YAGhZL/YmEu7wbuOvHOCd0elwy+s10iWHOltUzuPoPUE6udFotGI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QguUezf6cWe5ofY/N1dy1XqR8= 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); /**