From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-189.mta0.migadu.com (out-189.mta0.migadu.com [91.218.175.189]) (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 6B07D3C73FB for ; Mon, 13 Apr 2026 12:48:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.189 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776084496; cv=none; b=Y6QlgghE6mTFl1FYYi+5B4eQD1xBD/GmcQit2oEpRAxH9EgTfdi5JoROEKbUE/5CQ3Ms5K3LyC0OoOWoDsFRcAsLqBYm6/qiV1xA2m+MlMCU6QaViOCgSfKw1dw43OoPsVrk+trLysqKke3hBrjUuJGbubRi3u0FogYlAqpG2iU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776084496; c=relaxed/simple; bh=Dc09dxCBIOzEszxbpUlfFu/1T23V0wlqaSY6hA87tyE=; h=Content-Type:From:Mime-Version:Subject:Date:Message-Id:References: Cc:In-Reply-To:To; b=nX1vuNHyfdPFNk/mtTXE5i/mFXCvqNmnIrKHhhlUv+/Bj2AbAm/jZlcBgrXJwz+6wIHxZoVjZ41/+mBLT4sg6XCtXRWm3k/T6rgLPDzfd3YqCPtY1F6bBrBnCRWBa0YHSHJBtMg4Asssk0YhYjxG/8Hd698ujdKSvDmcepZ0Mxg= 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=nE5VYNAw; arc=none smtp.client-ip=91.218.175.189 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="nE5VYNAw" Content-Type: text/plain; charset=utf-8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1776084492; 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=zdfAjxhRsl2+AREvfePGH23u3lRiFYRNi2DHKhHln2k=; b=nE5VYNAwk/69hYOoOByq/8wh/JZBJg16bR2vH8D/XiuneHiHEafQ/FFFrao5O/GxJPSdv1 0/soNVIqBY9ziLV6FXp9cYu6u64On/Asc235Aazy8XEamU408vuxPmoSSxPdkhcsqXYf4+ 9zBfORBJFl+gW2g0jIAnGHjOPH3i/mc= Content-Transfer-Encoding: quoted-printable X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Muchun Song Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 (1.0) Subject: Re: [PATCH 01/49] mm/sparse: fix vmemmap accounting imbalance on memory hotplug error Date: Mon, 13 Apr 2026 20:47:45 +0800 Message-Id: <8AEA6BCE-570F-4095-ADCF-9699BDE0DD64@linux.dev> References: Cc: Muchun Song , Andrew Morton , David Hildenbrand , Oscar Salvador , Michael Ellerman , Madhavan Srinivasan , Lorenzo Stoakes , Liam R Howlett , Vlastimil Babka , Suren Baghdasaryan , Michal Hocko , Nicholas Piggin , Christophe Leroy , aneesh.kumar@linux.ibm.com, joao.m.martins@oracle.com, linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org In-Reply-To: To: Mike Rapoport X-Migadu-Flow: FLOW_OUT Sent from my iPad > On Apr 13, 2026, at 20:05, Mike Rapoport wrote: >=20 > =EF=BB=BFOn Mon, Apr 13, 2026 at 05:49:17PM +0800, Muchun Song wrote: >>=20 >>=20 >>>> On Apr 13, 2026, at 17:35, Mike Rapoport wrote: >>>=20 >>> On Mon, Apr 13, 2026 at 12:19:50PM +0300, Mike Rapoport wrote: >>>> On Sun, Apr 05, 2026 at 08:51:52PM +0800, Muchun Song wrote: >>>>> In section_activate(), if populate_section_memmap() fails, the error >>>>> handling path calls section_deactivate() to roll back the state. This >>>>> approach introduces an accounting imbalance. >>>>>=20 >>>>> Since the commit c3576889d87b ("mm: fix accounting of memmap pages"), >>>>> memmap pages are accounted for only after populate_section_memmap() >>>>> succeeds. However, section_deactivate() unconditionally decrements the= >>>>> vmemmap account. Consequently, a failure in populate_section_memmap() >>>>> leads to a negative offset (underflow) in the system's vmemmap trackin= g. >>>>>=20 >>>>> We can fix this by ensuring that the vmemmap accounting is incremented= >>>>> immediately before checking for the success of populate_section_memmap= (). >>>>> If populate_section_memmap() fails, the subsequent call to >>>>> section_deactivate() will decrement the accounting, perfectly offsetti= ng >>>>> the increment and maintaining balance. >>>>>=20 >>>>> Fixes: c3576889d87b ("mm: fix accounting of memmap pages") >>>>> Signed-off-by: Muchun Song >>>>> --- >>>>> mm/sparse-vmemmap.c | 2 +- >>>>> 1 file changed, 1 insertion(+), 1 deletion(-) >>>>>=20 >>>>> diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c >>>>> index 6eadb9d116e4..ee27d0c0efe2 100644 >>>>> --- a/mm/sparse-vmemmap.c >>>>> +++ b/mm/sparse-vmemmap.c >>>>> @@ -822,11 +822,11 @@ static struct page * __meminit section_activate(= int nid, unsigned long pfn, >>>>> return pfn_to_page(pfn); >>>>>=20 >>>>> memmap =3D populate_section_memmap(pfn, nr_pages, nid, altmap, pgmap);= >>>>> + memmap_pages_add(DIV_ROUND_UP(nr_pages * sizeof(struct page), PAGE_S= IZE)); >>>>=20 >>>> This logically belongs to success path in populate_section_memmap(). If= we >>>> update the counter there, we won't need to temporarily increase it at a= ll. >>>=20 >>> Not strictly related to this patchset, but it seems, we can have a singl= e >>> memmap_boot_pages_add() in memmap_alloc() rather than to update the coun= ter >>> in memmap_alloc() callers. >>=20 >> It will indeed become simpler and is a good cleanup direction, but there >> is a slight change in semantics: the page tables used for vmemmap page >> mapping will also be counted in memmap_boot_pages_add(). This might not >> be an issue (after all, the size of the page tables is very small compare= d >> to struct pages, right?). >>=20 >> Additionally, I still lean toward making no changes to this patch, becaus= e >> this is a pure bugfix patch =E2=80=94 of course, it is meant to facilitat= e backporting >> for those who need it. The cleanup would involve many more changes, so I >> prefer to do that in a separate patch. What do you think? >=20 > For this patch and easy backporting I still think that cleaner to have the= > counter incremented in populate_section_memmap() rather immediately after > it. Hi Mike, Alright, let=E2=80=99s revisit your solution. After we=E2=80=99ve moved the c= ounter into the=20 populate_section_memmap(), we still need to increase the counter temporarily= (but in populate_section_memmap()) even if we fail to populate. That=E2=80=99= s because section_deactivate() reduces the counter without exception, isn=E2=80= =99t it? Just want to make sure we are on the same page on the meaning of =E2=80=9Cte= mporarily increase=E2=80=9D. Maybe you do not mean =E2=80=9Ctemporarily=E2=80=9D in t= his case. Thanks, Muchun. >=20 >> Thanks, >> Muchun. >>=20 >>>=20 >>>>> if (!memmap) { >>>>> section_deactivate(pfn, nr_pages, altmap); >>>>> return ERR_PTR(-ENOMEM); >>>>> } >>>>> - memmap_pages_add(DIV_ROUND_UP(nr_pages * sizeof(struct page), PAGE_S= IZE)); >>>>>=20 >>>>> return memmap; >>>>> } >>>>> -- >>>>> 2.20.1 >>>>>=20 >>>>=20 >>>> -- >>>> Sincerely yours, >>>> Mike. >>>=20 >>> -- >>> Sincerely yours, >>> Mike. >>=20 >>=20 >>=20 >=20 > -- > Sincerely yours, > Mike.