From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 41A8D2EE617 for ; Sun, 7 Dec 2025 13:30:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765114205; cv=none; b=tZHkj4bby6uq4Ay3pcLjfu6VsD6qYtArBg1RoQouMSlm+MsGs5cQxcSVmteYVEB0MK9OQ05iWaoEGWXZOBQ7arC1sPDWK4IFJEZLdeVc3ytJxlxq9j4f2CE5lOQ41DJGv+2BjUEt6GyBW28T3kT/6Gwxa2toZenvhbdKcdN6FWw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765114205; c=relaxed/simple; bh=vUj8g8Psox09HQaPHL5N2VH3SgGfVIcj+mdYuXo3InY=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=E60hQLFFmWrmqzEMCHtSawMfROqXvewvHsWmrAz7Kr7+8x34eskxQz7QIhPvnnV+kro1Cdb0OmB/wUmygqqPgkV75QTS6lg1r+7xa8LltbvGaWSEyq5J9BPLjPQdrRM/+NQVtQMVVzFdrdBrx/OYVf+piw6utDkVcL9beF511yg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=SBvonLGT; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="SBvonLGT" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AE1CFC4CEFB; Sun, 7 Dec 2025 13:30:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1765114204; bh=vUj8g8Psox09HQaPHL5N2VH3SgGfVIcj+mdYuXo3InY=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=SBvonLGTXqz1PcsnUePtdYKDTi9Gl02t6CD492eW1INa3wDqJ/ePv2CG0pgzezxls +M12t/nzClqfCXASGkO4k0QH8BVQuYRsWatI3sjF8kPIGY40UWGg2t5v2EAmxKQ/su aDSP+WEP3WwQwkv6NotWMjazy63GekVMNhqXySHaEi9K8ifdi8aK1x3f3AOlUDL28S OEl+uXN5uUgLVSaZNA5FcEQWt30G6mzITHgWY2X2IvsBY6kjYTbNqMuQ+O95J66MUL NIsK2O7ENzktEr6xuXEXaCZcEH3WRRJHLYB9IolEf4b/tRKuvQRvFvKDHddr9ZIepg TgWlRYxOkR0yA== Message-ID: <7cf016ec-70e4-4244-82f6-32718dc38cc6@kernel.org> Date: Sun, 7 Dec 2025 14:30:00 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] mm/memory_hotplug: Cache auto_movable stats to optimize online check To: Swaraj Gaikwad , Oscar Salvador , Andrew Morton , "open list:MEMORY HOT(UN)PLUG" , open list Cc: skhan@linuxfoundation.org, david.hunter.linux@gmail.com References: <20251206212507.135503-1-swarajgaikwad1925@gmail.com> From: "David Hildenbrand (Red Hat)" Content-Language: en-US In-Reply-To: <20251206212507.135503-1-swarajgaikwad1925@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 12/6/25 22:25, Swaraj Gaikwad wrote: > The auto_movable_can_online_movable() function currently walks all > populated zones when nid == NUMA_NO_NODE, > > Since adjust_present_page_count() is called every time memory is > onlined/offlined and already updates present page counts, we can > maintain cached global statistics that are updated incrementally. This > eliminates the need to walk all zones for the NUMA_NO_NODE case. > > This patch introduces a static global_auto_movable_stats structure that > caches kernel_early_pages and movable_pages counts. The cache is updated > in adjust_present_page_count() whenever pages are onlined/offlined, and > is read directly in auto_movable_can_online_movable() when > nid == NUMA_NO_NODE. > > Testing: Built and booted the kernel successfully. Ran the memory > management test suite in tools/testing/selftests/mm/ with > ./run_vmtests.sh - all tests passed. > > Signed-off-by: Swaraj Gaikwad > --- > mm/memory_hotplug.c | 15 +++++++++++---- > 1 file changed, 11 insertions(+), 4 deletions(-) > > diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c > index 63b9d500ec6c..ba43edba8c92 100644 > --- a/mm/memory_hotplug.c > +++ b/mm/memory_hotplug.c > @@ -50,6 +50,8 @@ enum { > > static int memmap_mode __read_mostly = MEMMAP_ON_MEMORY_DISABLE; > > +static struct auto_movable_stats global_auto_movable_stats; > + > static inline unsigned long memory_block_memmap_size(void) > { > return PHYS_PFN(memory_block_size_bytes()) * sizeof(struct page); > @@ -851,9 +853,7 @@ static bool auto_movable_can_online_movable(int nid, struct memory_group *group, > > /* Walk all relevant zones and collect MOVABLE vs. KERNEL stats. */ > if (nid == NUMA_NO_NODE) { > - /* TODO: cache values */ The TODO was a bit unspecific: should have been "cache values if walking all zones becomes a performance problem". Is there a performance impact, or are you able to show a performance difference? -- Cheers David