From mboxrd@z Thu Jan 1 00:00:00 1970 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 AE9E1C282EC for ; Sat, 8 Mar 2025 18:14:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 649B66B0082; Sat, 8 Mar 2025 13:14:07 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5F8D26B0083; Sat, 8 Mar 2025 13:14:07 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4C2296B0085; Sat, 8 Mar 2025 13:14:07 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 2B8F56B0082 for ; Sat, 8 Mar 2025 13:14:07 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id CC7271CCE2D for ; Sat, 8 Mar 2025 18:14:07 +0000 (UTC) X-FDA: 83199182934.07.DD7640E Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf14.hostedemail.com (Postfix) with ESMTP id 24CF710000A for ; Sat, 8 Mar 2025 18:14:05 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=eaczmgbF; spf=pass (imf14.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1741457646; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=fLrSKwue5C1MCptHWGtsU/YopXHH7rH2f48GnXOUdLE=; b=jGtyhBY0RWcrVDhIU8vTMWpXGdwiMRh/lZiQqmGJwtgO39tozgFyuwU910o607jwCrR772 l/6qK09AfMJjwKMqy/SXgqywW700LeL4GBRtGT4hRYoZ196ILXUymJ4jFImhFyHVon8yT6 tAI2F7mNxDmyp+Fkci7o3RWVs9RmfAY= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=eaczmgbF; spf=pass (imf14.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1741457646; a=rsa-sha256; cv=none; b=yBNYv4zEaFR1lndpzBB1xWyFqCh5u32K3uWsh8nq3NJYJ+WFKGXZajmuLiIdaXean6YBrn C/i0017ka0+Xu8rGKWqRYGJqQIblIqMyveNgbI1lBnJ/LyuzTbex5smVAFylDswytVTQDX 2bd+VG4YwF2eSCXAPEYoA3PZKuF9QRQ= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 281F95C60E5; Sat, 8 Mar 2025 18:11:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6C789C4CEE0; Sat, 8 Mar 2025 18:14:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741457644; bh=/DztjNlgTwuVOyV43hgm+/GQtxBZDAlcw654hm2YE5A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eaczmgbFwScBH4+O9vOHrmVBUaSICMoLMaXdTFJk2xBze9yDs9GB2xea5i8XLaIMi A29V4tq0rL9BL9kiXdrirtOkDhuFTSsc7k0xK0zwoJZ+6ph6r6tCwhT1LkYl/XN1Sp 8Q35ZCFpIl/0O1mC1B0TMo4zA6mRhHEEfm3G26nm+nv0vhgyunR9X79lctzU9++u8Q iKlnygEq5P0y1y26dxLBDb9UDJUrUPmZUJs9vnATJ7FR88yDk6mbYYCvxmFCrP6cBl guHOicAuDTmLH8pR2DXZ9Z828qziEk3K5IrduFp6DGtO3oiDNcBNVbJ9XfsvVGF+FD 2eboWApInBghg== From: SeongJae Park To: Zi Yan Cc: SeongJae Park , Baolin Wang , Matthew Wilcox , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, Andrew Morton , Hugh Dickins , Kairui Song , Miaohe Lin , linux-kernel@vger.kernel.org, David Hildenbrand , John Hubbard , Kefeng Wang , "Kirill A. Shuemov" , Ryan Roberts , Yang Shi , Yu Zhao Subject: Re: [PATCH v3 1/2] mm/filemap: use xas_try_split() in __filemap_add_folio() Date: Sat, 8 Mar 2025 10:14:02 -0800 Message-Id: <20250308181402.95667-1-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250226210854.2045816-2-ziy@nvidia.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 24CF710000A X-Stat-Signature: 63yq4m15tafp4cukgot9rmg1dyno66ce X-Rspam-User: X-HE-Tag: 1741457645-662234 X-HE-Meta: U2FsdGVkX1/zZ/hmwWYfvOU+Ib8CHIyToCmEAKAxKHdrdlzhu6q8XfgGAmYwsUZz0s+UlOK1xdrFzlqpdc9t59RJZy5TQWWNZdONLxgatwgGfS9//xprbVCKMGmOisNphObInRvPWzPAI7rpn6STwi4dHs4m3bzeCCcB5xuPAxhOESfulp3/WGDFMLwpdxLFQb2lc/9HWmpp9VKgiXiOSX0xnZ4Hi8RYJUwkrUVAK44BtUQpIWcNfVK1+xED9ehNEBOO85evH1BRmshG6rUq85A2PgMN7ajXa3M5KLp5SdrDcT0mAwpoBAN56JQocswB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S1kRnOna55PMKsMQbUfmLLguSz1AefNQqzgv5pEO8XPBHGpCTcby1zyQc3s8HqIz2whwe/pQ59rOIpQg19WNK4vswkRazDFYw6JL97DB3E/1vDyKA8kGXlq8eqTyh0NwymCJe1VGowBWOi0lxoWRMtAvhP30o4vAcaaogepsy8MSIzZs+MUHYZm4yH572E/52gRj9T/jpsrGTB57d7UZk9cBfZk0ovxB8WCRKx5FOIpiWi2v+dbCwx9E1Bed9Lu0i 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: Hello, On Wed, 26 Feb 2025 16:08:53 -0500 Zi Yan wrote: > During __filemap_add_folio(), a shadow entry is covering n slots and a > folio covers m slots with m < n is to be added. Instead of splitting all > n slots, only the m slots covered by the folio need to be split and the > remaining n-m shadow entries can be retained with orders ranging from m to > n-1. This method only requires > > (n/XA_CHUNK_SHIFT) - (m/XA_CHUNK_SHIFT) > > new xa_nodes instead of > (n % XA_CHUNK_SHIFT) * ((n/XA_CHUNK_SHIFT) - (m/XA_CHUNK_SHIFT)) > > new xa_nodes, compared to the original xas_split_alloc() + xas_split() > one. For example, to insert an order-0 folio when an order-9 shadow entry > is present (assuming XA_CHUNK_SHIFT is 6), 1 xa_node is needed instead of > 8. > > xas_try_split_min_order() is introduced to reduce the number of calls to > xas_try_split() during split. > > Signed-off-by: Zi Yan > Cc: Baolin Wang > Cc: Hugh Dickins > Cc: Kairui Song > Cc: Miaohe Lin > Cc: Mattew Wilcox > Cc: David Hildenbrand > Cc: John Hubbard > Cc: Kefeng Wang > Cc: Kirill A. Shuemov > Cc: Ryan Roberts > Cc: Yang Shi > Cc: Yu Zhao > --- > include/linux/xarray.h | 7 +++++++ > lib/xarray.c | 25 +++++++++++++++++++++++ > mm/filemap.c | 45 +++++++++++++++++------------------------- > 3 files changed, 50 insertions(+), 27 deletions(-) > > diff --git a/include/linux/xarray.h b/include/linux/xarray.h > index 4010195201c9..78eede109b1a 100644 > --- a/include/linux/xarray.h > +++ b/include/linux/xarray.h > @@ -1556,6 +1556,7 @@ int xas_get_order(struct xa_state *xas); > void xas_split(struct xa_state *, void *entry, unsigned int order); > void xas_split_alloc(struct xa_state *, void *entry, unsigned int order, gfp_t); > void xas_try_split(struct xa_state *xas, void *entry, unsigned int order); > +unsigned int xas_try_split_min_order(unsigned int order); > #else > static inline int xa_get_order(struct xarray *xa, unsigned long index) > { > @@ -1582,6 +1583,12 @@ static inline void xas_try_split(struct xa_state *xas, void *entry, > unsigned int order) > { > } > + > +static inline unsigned int xas_try_split_min_order(unsigned int order) > +{ > + return 0; > +} > + > #endif > > /** > diff --git a/lib/xarray.c b/lib/xarray.c > index bc197c96d171..8067182d3e43 100644 > --- a/lib/xarray.c > +++ b/lib/xarray.c > @@ -1133,6 +1133,28 @@ void xas_split(struct xa_state *xas, void *entry, unsigned int order) > } > EXPORT_SYMBOL_GPL(xas_split); > > +/** > + * xas_try_split_min_order() - Minimal split order xas_try_split() can accept > + * @order: Current entry order. > + * > + * xas_try_split() can split a multi-index entry to smaller than @order - 1 if > + * no new xa_node is needed. This function provides the minimal order > + * xas_try_split() supports. > + * > + * Return: the minimal order xas_try_split() supports > + * > + * Context: Any context. > + * > + */ > +unsigned int xas_try_split_min_order(unsigned int order) > +{ > + if (order % XA_CHUNK_SHIFT == 0) > + return order == 0 ? 0 : order - 1; > + > + return order - (order % XA_CHUNK_SHIFT); > +} > +EXPORT_SYMBOL_GPL(xas_try_split_min_order); > + I found this makes build fails when CONFIG_XARRAY_MULTI is unset, like below. /linux/lib/xarray.c:1251:14: error: redefinition of ‘xas_try_split_min_order’ 1251 | unsigned int xas_try_split_min_order(unsigned int order) | ^~~~~~~~~~~~~~~~~~~~~~~ In file included from /linux/lib/xarray.c:13: /linux/include/linux/xarray.h:1587:28: note: previous definition of ‘xas_try_split_min_order’ with type ‘unsigned int(unsigned int)’ 1587 | static inline unsigned int xas_try_split_min_order(unsigned int order) | ^~~~~~~~~~~~~~~~~~~~~~~ I think we should have the definition only when CONFIG_XARRAY_MULTI? Thanks, SJ [...]