From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-179.mta1.migadu.com (out-179.mta1.migadu.com [95.215.58.179]) (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 DB9853909BF for ; Wed, 15 Jul 2026 14:45:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784126743; cv=none; b=FV9V4OC82KM/Mm2zZFC1lcm5u7E9GpuZf3J5YLQo1+moubO3ORpa1NE2+clJ2D3TB8eG9Oo6EOjm8kgIjahqkgWIh8LvFJdj5uss60Pgm7KMiLgWQkpOltYcpCQEzPb9MQUf3JWtk2q7vQdgTFQADpMf5UG/jISGakXwji7cCQc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784126743; c=relaxed/simple; bh=d4rcJbkMBAbGlC/dze3vMcl4MxXToQpU/zjhwQYrwRE=; h=Content-Type:Mime-Version:Subject:From:In-Reply-To:Date:Cc: Message-Id:References:To; b=KKU81tvA1rjc+++J6M+24R7QlAujkoKm1geU7VNpVJxoKfxeN3lJRbmLQqDHs2w5BGaRJssnc1vxkKzcgzwydU9Wvcf1UPvaMB2bzlnj/0LdkYPTYPlb2FoVqVXeemotuduXcFTy0orhtwckaqJNit9ewnVCY2uCK2PyS3AGAyw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=efPFpHYQ; arc=none smtp.client-ip=95.215.58.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="efPFpHYQ" Content-Type: text/plain; charset=us-ascii DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1784126738; h=from:from: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; bh=keIhINC+VA871Ln1KapohfRN71O/agbmMSX+dc5P8RE=; b=efPFpHYQe/nSz9XdIyoENtn8+CdURuOUWYnl95+Lftg7pdhFI2N8/wyWn4+j9MBc0PBS3y e489GVrwECSeqDhkTe2o8MY97hrD/z5/ft5LWbz3tTnMEJDeTbbSmMpiOnlQpyPMKHFAkr y6DSNcll+WXtdS9cptLkCNGSTlozjqY= Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3864.400.21\)) Subject: Re: [PATCH 06/17] mm/sparse-vmemmap: support section-based vmemmap accounting X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Muchun Song In-Reply-To: <178409212283.638342.6610895811767474932.b4-review@b4> Date: Wed, 15 Jul 2026 22:44:51 +0800 Cc: Muchun Song , Andrew Morton , Oscar Salvador , David Hildenbrand , linux-mm@kvack.org, Vlastimil Babka , Lorenzo Stoakes , Michal Hocko , linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Message-Id: References: <20260702093821.2740183-1-songmuchun@bytedance.com> <20260702093821.2740183-7-songmuchun@bytedance.com> <178409212283.638342.6610895811767474932.b4-review@b4> To: Mike Rapoport X-Migadu-Flow: FLOW_OUT > On Jul 15, 2026, at 13:08, Mike Rapoport wrote: >=20 >> section_nr_vmemmap_pages() is used to account the vmemmap pages = consumed by a >> memory section, but it currently only understands the ordinary case = and the >> pgmap-provided optimization case. That is not enough for = section-based vmemmap >> optimization, where the compound page order is carried by the memory = section >> itself and tail vmemmap pages may be shared. >>=20 >> Make the helper report the actual vmemmap footprint of a section, so = it can be >> used as the common accounting path for both ordinary and optimized = sections. >>=20 >> Teach section_nr_vmemmap_pages() to use the section order when there = is no >> pgmap, and to account only the vmemmap pages that are actually needed = for an >> optimizable section. This keeps the accounting consistent with = section-based >> vmemmap optimization. >>=20 >> Signed-off-by: Muchun Song >>=20 >> diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h >> index 6fa6e7f0abf9..41a1ebbe5e85 100644 >> --- a/include/linux/mmzone.h >> +++ b/include/linux/mmzone.h >> @@ -2403,6 +2403,14 @@ static inline unsigned int section_order(const = struct mem_section *section) >> } >> #endif >>=20 >> +static inline bool section_vmemmap_optimizable(const struct = mem_section *section) >> +{ >> + if (!is_power_of_2(sizeof(struct page))) >> + return false; >> + >> + return section_order(section) >=3D OPTIMIZABLE_FOLIO_MIN_ORDER; >=20 > Like with page_vmemmap_optimizable() I think it's not obvious that > section_order() is enough to gate vmemmap optimization. page_vmemmap_optimizable() checks the optimizability of an individual = page. section_vmemmap_optimizable() checks whether the optimization can be = applied to a section. Some people may think that section_vmemmap_optimizable() = checks the optimizability of all pages within an entire section. You are = referring to that ambiguity, right? What do you think about renaming it to = section_vmemmap_optimization_eligible()? Would that clear up the ambiguity? Or should we add a comment to section_vmemmap_optimizableto explain its purpose? >=20 >> +} >> + >> /* >> * Fallback case for when the architecture provides its own = pfn_valid() but >> * not a corresponding for_each_valid_pfn(). >> diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c >> index 77154e9da08c..99f59394feab 100644 >> --- a/mm/sparse-vmemmap.c >> +++ b/mm/sparse-vmemmap.c >> @@ -645,24 +645,29 @@ void offline_mem_sections(unsigned long = start_pfn, unsigned long end_pfn) >> static int __meminit section_nr_vmemmap_pages(unsigned long pfn, = unsigned long nr_pages, >> struct vmem_altmap *altmap, struct dev_pagemap *pgmap) >> { >> - const unsigned int order =3D pgmap ? pgmap->vmemmap_shift : 0; >> + const struct mem_section *ms =3D __pfn_to_section(pfn); >> + const unsigned int order =3D pgmap ? pgmap->vmemmap_shift : = section_order(ms); >> const unsigned long pages_per_compound =3D 1UL << order; >> + unsigned int vmemmap_pages =3D OPTIMIZED_FOLIO_VMEMMAP_PAGES; >>=20 >> VM_WARN_ON_ONCE(!IS_ALIGNED(pfn | nr_pages, = PAGES_PER_SUBSECTION)); >> VM_WARN_ON_ONCE(nr_pages > PAGES_PER_SECTION); >>=20 >> - if (!vmemmap_can_optimize(altmap, pgmap)) >> + if (vmemmap_can_optimize(altmap, pgmap)) >> + vmemmap_pages =3D VMEMMAP_RESERVE_NR; >=20 > I'd put it below the next if ... Make sense. Will do. Thanks for your review. Muchun >=20 >> + >> + if (!vmemmap_can_optimize(altmap, pgmap) && = !section_vmemmap_optimizable(ms)) >> return DIV_ROUND_UP(nr_pages * sizeof(struct page), = PAGE_SIZE); >=20 > ... and make it >=20 > vmmemap_pages =3D vmemmap_can_optimize() ? VMEMMAP_RESERVE_NR : 1; >=20 > --=20 > Sincerely yours, > Mike. >=20