From patchwork Fri Sep 6 23:05:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shakeel Butt X-Patchwork-Id: 13794860 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 D009BE6FE49 for ; Fri, 6 Sep 2024 23:05:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5E50B6B009F; Fri, 6 Sep 2024 19:05:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 59DA16B00A0; Fri, 6 Sep 2024 19:05:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 45BAD6B00A1; Fri, 6 Sep 2024 19:05:36 -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 26F786B009F for ; Fri, 6 Sep 2024 19:05:36 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id CBB1C1212DD for ; Fri, 6 Sep 2024 23:05:35 +0000 (UTC) X-FDA: 82535847030.10.7EC66A9 Received: from out-179.mta0.migadu.com (out-179.mta0.migadu.com [91.218.175.179]) by imf14.hostedemail.com (Postfix) with ESMTP id F3DAB10000C for ; Fri, 6 Sep 2024 23:05:33 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=UwaGGXZk; spf=pass (imf14.hostedemail.com: domain of shakeel.butt@linux.dev designates 91.218.175.179 as permitted sender) smtp.mailfrom=shakeel.butt@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725663836; 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:references:dkim-signature; bh=UXsA7JIUtdewb9efDW2qtqZcJCZNaaCVs6rSPdPNFlk=; b=gQw9fzakjoLQgMjZwrxNPh0qRKv3leOTE13/ouGEkKWwB8am5ePqVZwNIppy8pgLRGMorT SiO/R+xTt3N9E4lvZbZpdLY+CFYapjGlrw+0Ds3B+fU1PR+hK/NzZlO6waIUXZ09H8Lq55 qQI2I0QOnEi6zFJrsOrmlBO0/5nknVc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725663836; a=rsa-sha256; cv=none; b=L/ecYXCczJkfeX7e4AZAvwHiEjDhKFN14qsCS6ELeiCCDKuRbdowyzCM8mDQJsthmg7q3Q r5ePX4iheJNpPiD4jX+fFCPxd6bhIq3FzJxpfJq+n5W1LKeqmn0TmibrEPsnlet+Jxcj5w yTUENPstFmfML3vv0kr0NYpvovXO2jU= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=UwaGGXZk; spf=pass (imf14.hostedemail.com: domain of shakeel.butt@linux.dev designates 91.218.175.179 as permitted sender) smtp.mailfrom=shakeel.butt@linux.dev; dmarc=pass (policy=none) header.from=linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1725663930; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=UXsA7JIUtdewb9efDW2qtqZcJCZNaaCVs6rSPdPNFlk=; b=UwaGGXZksKdpWGS/XwT8uzeptMqy69/DEemlXIe3a0cnaLw4fR6ucXBGs67wwJgfBv4umB QGyr36p8W/4UutTAmBMO1FAkadXRxsBmSUa53FAV7DjfBgfJSdEUA08gUPhl4MdjwFuBDU K0RNWcV7rQDJ7YA+rEER0FyisbeiATc= From: Shakeel Butt To: Andrew Morton Cc: Matthew Wilcox , Hugh Dickins , Nhat Pham , Baolin Wang , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Meta kernel team , linux-fsdevel@vger.kernel.org Subject: [PATCH] mm: replace xa_get_order with xas_get_order where appropriate Date: Fri, 6 Sep 2024 16:05:12 -0700 Message-ID: <20240906230512.124643-1-shakeel.butt@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Queue-Id: F3DAB10000C X-Stat-Signature: tytzur9xfsnuqqf1kwitkywnrkhqbx65 X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1725663933-304661 X-HE-Meta: U2FsdGVkX18E5niwtldiUch4+hQekqRu0PNBE8x/8VtsvzUkLbqq0V+mCjuet+wiKS88rM+wSAFoyZ/0bXu0TKsalJlJHsUsg4edldutId/d04BVkxlvDrgbjUbVa6QnXYi9EvGHBociArahfMsDMT/SraQG9eiVgQhG6a+cPFGR/gco0wa+fFg5v4zka1gaCmiNJcY70Ilz09PzOlszMqrZg9Kh/k5beOAH+59RHl9N69mPJKtiAmUhiqaelip171P4Bu2KQvO3ejo2IbMMHeKn28NE6riAI27AEZjnvRVkJC9c+KyAzMN3HIAspwbNItigtioD52/KN3UrS36SB2gXmApi5drrcw31Z+QB3YVgk4kWxuB3WQ7BOb1ZZGpDH3DUAlAEfkQeVoEyPbnONq3KHqdQfIJqqnrIdtUE/7/1CXNRJHRxnW8CNcGcE4tGbxL9tp/X3zflTr+y/6lN5FiZfcfOrQJor9txicERs5AfiBCoTRhYyRL+SBPyvVs+jaxbBydgFytQumQ1MkTmTFh6GcGshy1vXdohJ8rY6fbDJ6RIWAxs2RRC7xOFiJPKrWB0v4PuODjb/uwYqCw3/yThUn7SOkP0aKSwESFuSsrCgrue9MLKGS+sQWgWpCX3OpHrghMIDpZ1gkfE2oHR4xuMkUxKVNepG1KZCQ3T5pz7U7yd2sQAbMbqejScdoLxKfYnA8auLGXMD5eCz1ei/uKfewi9jh3GMF2rSUdRBkBe3Vs5AzDZyezDye6aWD+sCx4mRziTVpAz7oakrTE6oBz6D7eFFKtx6hdHBNv3eRH2aGvnO5BaJ95FnZ5iytbpV9ZsMaWVZpa0AtywHmDiiFw+M8kMdyerue92J/2DHfuEHTgjgExAgt9xT+a8eMGDdrN2/TkgqE/LTPtx1lrR2a803EfOKZ566nRlTdMv3VBaEWaq16LSL9VW2LnND5DAUgRSx2oTIjkDaV2qf7+ tPdDC1nK i2ZSAuJ82yHuKFZgP0Bhxog7ItW5TrcjpASjdicS7goH8cdRV5fF98gZD3JrYzPGVG5dnk4sxrPgOHjDbz77OdeWmgRLcqi7bAKeq4ZIj6+njkn2EenqczTJZuhrpZ/Sxk9srHIcHJZxTEwzfXjeLL/RS2YJFPcZ2GcgOgJ2QSK3b+3P1qYlZAFSe3g== 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: The tracing of invalidation and truncation operations on large files showed that xa_get_order() is among the top functions where kernel spends a lot of CPUs. xa_get_order() needs to traverse the tree to reach the right node for a given index and then extract the order of the entry. However it seems like at many places it is being called within an already happening tree traversal where there is no need to do another traversal. Just use xas_get_order() at those places. Signed-off-by: Shakeel Butt Reviewed-by: Liam R. Howlett Reviewed-by: Baolin Wang Reviewed-by: Nhat Pham --- mm/filemap.c | 6 +++--- mm/shmem.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/mm/filemap.c b/mm/filemap.c index 070dee9791a9..7e3412941a8d 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2112,7 +2112,7 @@ unsigned find_lock_entries(struct address_space *mapping, pgoff_t *start, VM_BUG_ON_FOLIO(!folio_contains(folio, xas.xa_index), folio); } else { - nr = 1 << xa_get_order(&mapping->i_pages, xas.xa_index); + nr = 1 << xas_get_order(&xas); base = xas.xa_index & ~(nr - 1); /* Omit order>0 value which begins before the start */ if (base < *start) @@ -3001,7 +3001,7 @@ static inline loff_t folio_seek_hole_data(struct xa_state *xas, static inline size_t seek_folio_size(struct xa_state *xas, struct folio *folio) { if (xa_is_value(folio)) - return PAGE_SIZE << xa_get_order(xas->xa, xas->xa_index); + return PAGE_SIZE << xas_get_order(xas); return folio_size(folio); } @@ -4297,7 +4297,7 @@ static void filemap_cachestat(struct address_space *mapping, if (xas_retry(&xas, folio)) continue; - order = xa_get_order(xas.xa, xas.xa_index); + order = xas_get_order(&xas); nr_pages = 1 << order; folio_first_index = round_down(xas.xa_index, 1 << order); folio_last_index = folio_first_index + nr_pages - 1; diff --git a/mm/shmem.c b/mm/shmem.c index 866d46d0c43d..4002c4f47d4d 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -893,7 +893,7 @@ unsigned long shmem_partial_swap_usage(struct address_space *mapping, if (xas_retry(&xas, page)) continue; if (xa_is_value(page)) - swapped += 1 << xa_get_order(xas.xa, xas.xa_index); + swapped += 1 << xas_get_order(&xas); if (xas.xa_index == max) break; if (need_resched()) {