lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aXINUc0ZJSJusel2@kernel.org>
Date: Thu, 22 Jan 2026 13:43:13 +0200
From: Mike Rapoport <rppt@...nel.org>
To: Tianyou Li <tianyou.li@...el.com>
Cc: David Hildenbrand <david@...nel.org>,
	Oscar Salvador <osalvador@...e.de>,
	Wei Yang <richard.weiyang@...il.com>,
	Michal Hocko <mhocko@...e.com>, linux-mm@...ck.org,
	Yong Hu <yong.hu@...el.com>, Nanhai Zou <nanhai.zou@...el.com>,
	Yuan Liu <yuan1.liu@...el.com>,
	Tim Chen <tim.c.chen@...ux.intel.com>,
	Qiuxu Zhuo <qiuxu.zhuo@...el.com>, Yu C Chen <yu.c.chen@...el.com>,
	Pan Deng <pan.deng@...el.com>, Chen Zhang <zhangchen.kidd@...com>,
	linux-kernel@...r.kernel.org
Subject: Re: [PATCH v8 3/3] mm/memory hotplug/unplug: Optimize
 zone->contiguous update when changes pfn range

Hi,

On Tue, Jan 20, 2026 at 10:33:46PM +0800, Tianyou Li wrote:
> When invoke move_pfn_range_to_zone or remove_pfn_range_from_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 |
> |                +------+---------------+--------------+----------------+
> | Plug Memory    | 256G |      10s      |      2s      |       80%      |
> |                +------+---------------+--------------+----------------+
> |                | 512G |      33s      |      6s      |       81%      |
> +----------------+------+---------------+--------------+----------------+
> 
> +----------------+------+---------------+--------------+----------------+
> |                | Size | Time (before) | Time (after) | Time Reduction |
> |                +------+---------------+--------------+----------------+
> | Unplug Memory  | 256G |      10s      |      2s      |       80%      |
> |                +------+---------------+--------------+----------------+
> |                | 512G |      34s      |      6s      |       82%      |
> +----------------+------+---------------+--------------+----------------+
> 
> [1] Qemu commands to hotplug 256G/512G memory for a VM:
>     object_add memory-backend-ram,id=hotmem0,size=256G/512G,share=on
>     device_add virtio-mem-pci,id=vmem1,memdev=hotmem0,bus=port1
>     qom-set vmem1 requested-size 256G/512G (Plug Memory)
>     qom-set vmem1 requested-size 0G (Unplug Memory)
> 
> [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 <nanhai.zou@...el.com>
> Reported-by: Chen Zhang <zhangchen.kidd@...com>
> Tested-by: Yuan Liu <yuan1.liu@...el.com>
> Reviewed-by: Tim Chen <tim.c.chen@...ux.intel.com>
> Reviewed-by: Qiuxu Zhuo <qiuxu.zhuo@...el.com>
> Reviewed-by: Yu C Chen <yu.c.chen@...el.com>
> Reviewed-by: Pan Deng <pan.deng@...el.com>
> Reviewed-by: Nanhai Zou <nanhai.zou@...el.com>
> Reviewed-by: Yuan Liu <yuan1.liu@...el.com>
> Signed-off-by: Tianyou Li <tianyou.li@...el.com>
> ---

...

> +int online_memory_block_pages(unsigned long start_pfn, unsigned long nr_pages,
> +			unsigned long nr_vmemmap_pages, struct zone *zone,
> +			struct memory_group *group)
>  {
> +	const bool contiguous = zone->contiguous;
> +	enum zone_contig_state new_contiguous_state;
>  	int ret;
>  
> +	/*
> +	 * Calculate the new zone contig state before move_pfn_range_to_zone()
> +	 * sets the zone temporarily to non-contiguous.
> +	 */
> +	new_contiguous_state = zone_contig_state_after_growing(zone, start_pfn,
> +							       nr_pages);
> +
>  	if (nr_vmemmap_pages) {
>  		ret = mhp_init_memmap_on_memory(start_pfn, nr_vmemmap_pages, zone);
>  		if (ret)
> -			return ret;
> +			goto restore_zone_contig;

But zone_contig_state_after_growing() does not change zone->contiguous. Why
do we need to save and restore it?

>  	}
>  
>  	ret = online_pages(start_pfn + nr_vmemmap_pages,
> @@ -1271,7 +1320,7 @@ int online_memory_block_pages(unsigned long start_pfn,
>  	if (ret) {
>  		if (nr_vmemmap_pages)
>  			mhp_deinit_memmap_on_memory(start_pfn, nr_vmemmap_pages);
> -		return ret;
> +		goto restore_zone_contig;
>  	}
>  
>  	/*
> @@ -1282,6 +1331,15 @@ int online_memory_block_pages(unsigned long start_pfn,
>  		adjust_present_page_count(pfn_to_page(start_pfn), group,
>  					  nr_vmemmap_pages);
>  
> +	/*
> +	 * Now that the ranges are indicated as online, check whether the whole
> +	 * zone is contiguous.
> +	 */
> +	set_zone_contiguous(zone, new_contiguous_state);
> +	return 0;
> +
> +restore_zone_contig:
> +	zone->contiguous = contiguous;
>  	return ret;
>  }

-- 
Sincerely yours,
Mike.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ