From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ej1-f50.google.com (mail-ej1-f50.google.com [209.85.218.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 733333587CC for ; Wed, 19 Nov 2025 12:44:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763556265; cv=none; b=HuMcFE+MegYNhcEM2MtKRGfKz/yghtPBkMGfdFkgFIeiYMYyJN1XxUw8onUN+jZbqlENwWsUpc/TGEG7o5KsATBJht3dBiB9kV/oCmAdGR57lR7befLkN3rG5Af1/PVNEq6jqqWzDtTkLumXHxzwNNLLKUFahyAguhkE8ZvPeVA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763556265; c=relaxed/simple; bh=zfF2IYvql11gdunNxdpML2AJw9EYigeC6cnQEWVSEMI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=V2sMtF2fWChiFZ1m1LG+TWzt54oV6MI9e5ogN1RYgEEVeujzAvWqzqhWjbdD7CmpWpWGcFt4LhOGoib38oRsjs5zEyzPJs6GU6RDP3gieUW9KaC/e0oYbuHfAaQUWzjD9sHc7c3SLNbSY5n47fwlfgmBDP8V6/Q/Hjy/h2wGcP0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=TihBe26p; arc=none smtp.client-ip=209.85.218.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="TihBe26p" Received: by mail-ej1-f50.google.com with SMTP id a640c23a62f3a-b7636c96b9aso115781866b.2 for ; Wed, 19 Nov 2025 04:44:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1763556259; x=1764161059; darn=vger.kernel.org; h=user-agent:in-reply-to:content-disposition:mime-version:references :reply-to:message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=Er5hZIqRlPa0ixIsJDMLxf9OqXoeqQqYf2QlqpDUVlY=; b=TihBe26pr43M7aGDK6OJk5ghyk1ieC/AsEvhoRVIBshGOoy2yduCTm6JiFtmOWZmug ZzCcmGs5vsFlYVq4iqJfJSz9JhKO82O49uCQoR/A+HGBRjD5WHBvd4U67pXafAJG9aBZ dlCy00anzpq5vm3agZKaUrD5sij+lBmpHcg+Etqs/IPKgMKnIPE/+jWbS8OWpEkcUV7X RL2RbZemPvsTw31EQLGOTyld9HLu0JmGWAcfQGrNkfQhVm7N8ZpcktkijxDDIBz+71nO xxSpMNAe8g0iaMHrU/R9WjSi3P6rf2iqqOOk/EzApa0kY9L5RLuuRqPEcb5x3JwxxNEs 5gYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763556259; x=1764161059; h=user-agent:in-reply-to:content-disposition:mime-version:references :reply-to:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Er5hZIqRlPa0ixIsJDMLxf9OqXoeqQqYf2QlqpDUVlY=; b=Lo/zKTxS47uFDu/1SprgSvxiX++IYkvjy10vkcVphUnImRcRTf7RlQvq5L8JvmAZ8k aqK+9sMlS0368WZe4wVFXXnWQtIZn8kdP2+VD+Iev2Fx/ykyTZvErf6jK0qjU7nehjCr Qdvura9ao1nlyJPp7RWTR4XPVJOORR53V/uD+bZsYtJhwtDxrYEL/Zd6LKuy8KdpHFo8 kU1kgPLPnBe0pxbL6Hpfpnc6d6Dys2y7I8SuflaSoPGA0RQ//lybNHcw7FKO8LcggnBu Ap0qV7Euyoug3O2s1GINu9aUKo0qCv4DC82K/5JrA3cxoKRyrQvPk6EgaAolgRfrpoYv BYeA== X-Forwarded-Encrypted: i=1; AJvYcCWo3q2sqnc/qSb7SYYdkXAFsPZ9+GfAM/XtTFkwzXBYDbYYfeRqwhhE36+rvphovOGmd05VUfz07NNKdKg=@vger.kernel.org X-Gm-Message-State: AOJu0YwNqURtrzAoWHyAYUWeZPeIy4FPu2xOA0J1OlHDlTO+au5UtBbF qqavZX+yNgAsLDFo21t1Uuvpuw2n4NoJFostfMu+OnW2rm3MQs5kvTZs X-Gm-Gg: ASbGncukz2BG7LGwCKN8rgqyUTgglIZREN83IX4W5LwAebD+gv/8rYvug9L0ibCp3Y2 KOoz3XV5rJijIan7dguH5/Myp6Zbi1Zkx1dYyDbgX0oc3wmupCQYPpGOu6MFiGKaajAonPf6ZE8 eDxDDu01keQytWS61Lv0dHOAEjTTi5nkHmBEKxmGXlH78VDosYyo67NZyxijFR4NHvuQdqoE6n8 lvrXktJZ55ujlye44IwPtGJ2bdVXZY3CLGc/+lv1nqW6PjhTF5WGRbOjw93bTmavg9PgfZGffFu PgO1pvD2uXeGGSRGtK/2st18m63bfpv4f+cC0qfuf9YDEy6k3a1xVWlfM9CDCYlnVVlWSE/41DT uUcg92EfpaF5EA9EYIvX7iQs9fW/hGAU42yBxSVxNqLk1ehn0M33re9WFunSZxyIojhmcg8C3QS fY65ZiCaStO8n+zA== X-Google-Smtp-Source: AGHT+IFd8hKmc2jM3KNaePrLrpMcefLHG/PSsZriTY72DGBaBlUfEaL+X8nYTtEzcYp1HUuhkqMWGw== X-Received: by 2002:a17:907:97d4:b0:b71:5079:9702 with SMTP id a640c23a62f3a-b736780c27fmr1940894966b.21.1763556259287; Wed, 19 Nov 2025 04:44:19 -0800 (PST) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b734fd809fasm1613908866b.45.2025.11.19.04.44.18 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 19 Nov 2025 04:44:18 -0800 (PST) Date: Wed, 19 Nov 2025 12:44:18 +0000 From: Wei Yang To: "Li, Tianyou" Cc: Wei Yang , David Hildenbrand , Oscar Salvador , Mike Rapoport , linux-mm@kvack.org, Yong Hu , Nanhai Zou , Yuan Liu , Tim Chen , Qiuxu Zhuo , Yu C Chen , Pan Deng , Chen Zhang , linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] mm/memory hotplug/unplug: Optimize zone->contiguous update when move pfn range Message-ID: <20251119124418.nhzgjweamqb6vjig@master> Reply-To: Wei Yang References: <20251119040718.2735199-1-tianyou.li@intel.com> <20251119114252.oykrczprf3ecd7ak@master> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20170113 (1.7.2) On Wed, Nov 19, 2025 at 08:41:11PM +0800, Li, Tianyou wrote: > >On 11/19/2025 7:42 PM, Wei Yang wrote: >> On Wed, Nov 19, 2025 at 12:07:18PM +0800, Tianyou Li wrote: >> > When invoke move_pfn_range_to_zone, it will update the zone->contiguous by >> > checking the new zone's pfn range from the beginning to the end, regardless >> > the previous state of the old zone. When the zone's pfn range is large, the >> > cost of traversing the pfn range to update the zone->contiguous could be >> > significant. >> > >> > Add fast paths to quickly detect cases where zone is definitely not >> > contiguous without scanning the new zone. The cases are: when the new range >> > did not overlap with previous range, the contiguous should be false; if the >> > new range adjacent with the previous range, just need to check the new >> > range; if the new added pages could not fill the hole of previous zone, the >> > contiguous should be false. >> > >> > The following test cases of memory hotplug for a VM [1], tested in the >> > environment [2], show that this optimization can significantly reduce the >> > memory hotplug time [3]. >> > >> > +----------------+------+---------------+--------------+----------------+ >> > | | Size | Time (before) | Time (after) | Time Reduction | >> > | +------+---------------+--------------+----------------+ >> > | Memory Hotplug | 256G | 10s | 2s | 80% | >> > | +------+---------------+--------------+----------------+ >> > | | 512G | 33s | 6s | 81% | >> > +----------------+------+---------------+--------------+----------------+ >> > >> Nice > > >Thanks for your time to review. > > >> > [1] Qemu commands to hotplug 512G memory for a VM: >> > object_add memory-backend-ram,id=hotmem0,size=512G,share=on >> > device_add virtio-mem-pci,id=vmem1,memdev=hotmem0,bus=port1 >> > qom-set vmem1 requested-size 512G >> > >> > [2] Hardware : Intel Icelake server >> > Guest Kernel : v6.18-rc2 >> > Qemu : v9.0.0 >> > >> > Launch VM : >> > qemu-system-x86_64 -accel kvm -cpu host \ >> > -drive file=./Centos10_cloud.qcow2,format=qcow2,if=virtio \ >> > -drive file=./seed.img,format=raw,if=virtio \ >> > -smp 3,cores=3,threads=1,sockets=1,maxcpus=3 \ >> > -m 2G,slots=10,maxmem=2052472M \ >> > -device pcie-root-port,id=port1,bus=pcie.0,slot=1,multifunction=on \ >> > -device pcie-root-port,id=port2,bus=pcie.0,slot=2 \ >> > -nographic -machine q35 \ >> > -nic user,hostfwd=tcp::3000-:22 >> > >> > Guest kernel auto-onlines newly added memory blocks: >> > echo online > /sys/devices/system/memory/auto_online_blocks >> > >> > [3] The time from typing the QEMU commands in [1] to when the output of >> > 'grep MemTotal /proc/meminfo' on Guest reflects that all hotplugged >> > memory is recognized. >> > >> > Reported-by: Nanhai Zou >> > Reported-by: Chen Zhang >> > Tested-by: Yuan Liu >> > Reviewed-by: Tim Chen >> > Reviewed-by: Qiuxu Zhuo >> > Reviewed-by: Yu C Chen >> > Reviewed-by: Pan Deng >> > Reviewed-by: Nanhai Zou >> > Reviewed-by: Yuan Liu >> > Signed-off-by: Tianyou Li >> > --- >> > mm/memory_hotplug.c | 57 ++++++++++++++++++++++++++++++++++++++++++--- >> > 1 file changed, 54 insertions(+), 3 deletions(-) >> > >> > diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c >> > index 0be83039c3b5..8f126f20ca47 100644 >> > --- a/mm/memory_hotplug.c >> > +++ b/mm/memory_hotplug.c >> > @@ -723,6 +723,57 @@ static void __meminit resize_pgdat_range(struct pglist_data *pgdat, unsigned lon >> > >> > } >> > >> > +static bool __meminit check_zone_contiguous_fast(struct zone *zone, >> > + unsigned long start_pfn, unsigned long nr_pages) >> > +{ >> > + const unsigned long end_pfn = start_pfn + nr_pages; >> > + unsigned long nr_filled_pages; >> > + >> > + /* >> > + * Given the moved pfn range's contiguous property is always true, >> > + * under the conditional of empty zone, the contiguous property should >> > + * be true. >> > + */ >> > + if (zone_is_empty(zone)) { >> > + zone->contiguous = true; >> > + return true; >> > + } >> > + >> > + /* >> > + * If the moved pfn range does not intersect with the original zone span, >> > + * the contiguous property is surely false. >> > + */ >> > + if (end_pfn < zone->zone_start_pfn || start_pfn > zone_end_pfn(zone)) { >> > + zone->contiguous = false; >> > + return true; >> > + } >> > + >> > + /* >> > + * If the moved pfn range is adjacent to the original zone span, given >> > + * the moved pfn range's contiguous property is always true, the zone's >> > + * contiguous property inherited from the original value. >> > + */ >> > + if (end_pfn == zone->zone_start_pfn || start_pfn == zone_end_pfn(zone)) >> > + return true; >> > + >> > + /* >> > + * If the original zone's hole larger than the new filled pages, the >> > + * contiguous property is surely false. >> > + */ >> > + nr_filled_pages = end_pfn - zone->zone_start_pfn; >> > + if (start_pfn > zone->zone_start_pfn) >> > + nr_filled_pages -= start_pfn - zone->zone_start_pfn; >> > + if (end_pfn > zone_end_pfn(zone)) >> > + nr_filled_pages -= end_pfn - zone_end_pfn(zone); >> > + if (nr_filled_pages < (zone->spanned_pages - zone->present_pages)) { >> > + zone->contiguous = false; >> > + return true; >> > + } >> > + >> Mike's suggestion is easier for me to understand :-) > > >OK :-), with the clear votes now, I will change it in patch v3 real quick. >Thanks. > Thanks for your effort. While maybe wait a little for v3, let's see other's comment on v2 :-) -- Wei Yang Help you, Help me