From nobody Tue Oct 7 12:29:46 2025 Received: from mx10.didiglobal.com (mx10.didiglobal.com [111.202.70.125]) by smtp.subspace.kernel.org (Postfix) with SMTP id C53AE2D6616; Thu, 10 Jul 2025 10:14:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=111.202.70.125 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752142488; cv=none; b=CwnaX9PP9LuIDxdQHM659USWMOV9GVIS9XzM10R6bVp9fxjMmH0jVWrFkvBWBXxN2gXoK86D7HYh7NUEREJlmLMuP1jzA68GHZOQLicvAbVUoCHH9L5+Ilmbj7nyTdaqHoHiO3swg1mqd4dzMozc2vhTZNqAEwqzdXtxFpjJ7BU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752142488; c=relaxed/simple; bh=e+n/6AlPUc3DbRhJD+hzg5MV5KYpldOkq0RvjNrxVUY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:Content-Type: MIME-Version; b=ZiPIupBcdc9dW1/f1u+DgvPrV33GjjEY3SNlwib2S1yOhFIc95VK4tJPWRO3rKWJjDktwKPfhvCHOt0wNu3pEoN4/k/+PY0eWrhxUQFWMZ8+B/l2C1PZibolzJsd2su7kKsA4bCWUBvBSsqiQ6kvI5UXwrEZaR33WMfbc+a7rT4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=didiglobal.com; spf=pass smtp.mailfrom=didiglobal.com; dkim=pass (1024-bit key) header.d=didiglobal.com header.i=@didiglobal.com header.b=d0xbnjYw; arc=none smtp.client-ip=111.202.70.125 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=didiglobal.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=didiglobal.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=didiglobal.com header.i=@didiglobal.com header.b="d0xbnjYw" Received: from mail.didiglobal.com (unknown [10.79.71.38]) by mx10.didiglobal.com (MailData Gateway V2.8.8) with ESMTPS id 0FA4D18387BC5E; Thu, 10 Jul 2025 18:13:29 +0800 (CST) Received: from BJ03-ACTMBX-08.didichuxing.com (10.79.71.35) by BJ03-ACTMBX-02.didichuxing.com (10.79.71.38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1748.10; Thu, 10 Jul 2025 18:14:13 +0800 Received: from BJ03-ACTMBX-07.didichuxing.com (10.79.71.34) by BJ03-ACTMBX-08.didichuxing.com (10.79.71.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1748.10; Thu, 10 Jul 2025 18:14:12 +0800 Received: from BJ03-ACTMBX-07.didichuxing.com ([fe80::2e1a:dd47:6d25:287e]) by BJ03-ACTMBX-07.didichuxing.com ([fe80::2e1a:dd47:6d25:287e%7]) with mapi id 15.02.1748.010; Thu, 10 Jul 2025 18:14:12 +0800 X-MD-Sfrom: chentaotao@didiglobal.com X-MD-SrcIP: 10.79.71.38 From: =?gb2312?B?s8LMzszOIFRhb3RhbyBDaGVu?= To: "tytso@mit.edu" , "hch@infradead.org" , "adilger.kernel@dilger.ca" , "willy@infradead.org" , "brauner@kernel.org" , "jani.nikula@linux.intel.com" , "rodrigo.vivi@intel.com" , "tursulin@ursulin.net" , "airlied@gmail.com" CC: "linux-fsdevel@vger.kernel.org" , "linux-ext4@vger.kernel.org" , "linux-block@vger.kernel.org" , "intel-gfx@lists.freedesktop.org" , "dri-devel@lists.freedesktop.org" , "linux-mm@kvack.org" , "linux-doc@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "chentao325@qq.com" , "frank.li@vivo.com" , =?gb2312?B?s8LMzszOIFRhb3RhbyBDaGVu?= Subject: [PATCH v5 4/5] mm/pagemap: add write_begin_get_folio() helper function Thread-Topic: [PATCH v5 4/5] mm/pagemap: add write_begin_get_folio() helper function Thread-Index: AQHb8YNhNDn+fEJVz0y29k3GEMiAYg== Date: Thu, 10 Jul 2025 10:14:12 +0000 Message-ID: <20250710101404.362146-5-chentaotao@didiglobal.com> In-Reply-To: <20250710101404.362146-1-chentaotao@didiglobal.com> Accept-Language: zh-CN, en-US Content-Language: zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: Content-Transfer-Encoding: quoted-printable Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=didiglobal.com; s=2025; t=1752142431; bh=e+n/6AlPUc3DbRhJD+hzg5MV5KYpldOkq0RvjNrxVUY=; h=From:To:CC:Subject:Date:Message-ID:Content-Type; b=d0xbnjYwkUwSNQGtY0jrMsDrePpkcnpXrxO+wIbgEaLulQs8BdiUykm3SLjqEELeb EMU81Lts5cS8gI5uG+fU7WeoedfsduBXpJscvPkIzAK5uWgpx7kqom43oSIJyMzH7n ZcbyIi6HdG3CzUJhB3nHvUmqFc/07rS9XFLbMAP8= Content-Type: text/plain; charset="utf-8" From: Taotao Chen Add write_begin_get_folio() to simplify the common folio lookup logic used by filesystem ->write_begin() implementations. This helper wraps __filemap_get_folio() with common flags such as FGP_WRITEBEGIN, conditional FGP_DONTCACHE, and set folio order based on the write length. Part of a series refactoring address_space_operations write_begin and write_end callbacks to use struct kiocb for passing write context and flags. Signed-off-by: Taotao Chen --- include/linux/pagemap.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index e63fbfbd5b0f..ce2bcdcadb73 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -750,6 +750,33 @@ struct folio *__filemap_get_folio(struct address_space= *mapping, pgoff_t index, struct page *pagecache_get_page(struct address_space *mapping, pgoff_t ind= ex, fgf_t fgp_flags, gfp_t gfp); =20 +/** + * write_begin_get_folio - Get folio for write_begin with flags. + * @iocb: The kiocb passed from write_begin (may be NULL). + * @mapping: The address space to search. + * @index: The page cache index. + * @len: Length of data being written. + * + * This is a helper for filesystem write_begin() implementations. + * It wraps __filemap_get_folio(), setting appropriate flags in + * the write begin context. + * + * Return: A folio or an ERR_PTR. + */ +static inline struct folio *write_begin_get_folio(const struct kiocb *iocb, + struct address_space *mapping, pgoff_t index, size_t len) +{ + fgf_t fgp_flags =3D FGP_WRITEBEGIN; + + fgp_flags |=3D fgf_set_order(len); + + if (iocb && iocb->ki_flags & IOCB_DONTCACHE) + fgp_flags |=3D FGP_DONTCACHE; + + return __filemap_get_folio(mapping, index, fgp_flags, + mapping_gfp_mask(mapping)); +} + /** * filemap_get_folio - Find and get a folio. * @mapping: The address_space to search. --=20 2.34.1