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 66A043A16BD for ; Mon, 13 Apr 2026 09:19:50 +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=1776071990; cv=none; b=RV0zdih3MoPV4eW7xloPC1JUKUpmM7j33VMyrr7YGz8t7ebbcd95kK/AQL2X/iT1B1z5KIEQ29JwK0PzZ7MFw535MnYMsrXlTfICDk/dfsa6g9/xmeTCW/6wfkrd5I1nQDBD1byjTmcFgmb1lC7Ohd+a5YPs007w2+7vZM+V/lY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776071990; c=relaxed/simple; bh=2kr+EhMgMQkHVA7iNdaf14YX9cd4ab4OO+SsmIGEbRU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=P8cLRfjyRAwStl6rvkzsk+jMkdmL2FgC2FB3qco5WZghdbmIzxsJekEhXlTFuM657dqJr5i3lx4laz+21nsP3bTrgfkx0zLLRRxUB4RV5kh6sR8/wktQSG9CgTtKWQuU8iyAlOniEVT9uLqtgXtvOMW1zvTOI/Wm7GfyyEDUUI8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bNCjDuM+; 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="bNCjDuM+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8A895C2BCAF; Mon, 13 Apr 2026 09:19:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776071990; bh=2kr+EhMgMQkHVA7iNdaf14YX9cd4ab4OO+SsmIGEbRU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=bNCjDuM+e/DnQ3gdIUmaMsSzHbtpAX1fNz8FDMsrhCBz/Zx234Yd2VLPGUFxItza8 AGkMDnomVyAINuiid0nMJwgViqv6xnF0ti5KODcY4pyAGB0gvsbzVtAdAUc5GmMZbE 4k1neV8aNrD6Lpn60QOG7yrpG4PiWQyK1Ti9YnbZoMEYnDCKAVSCXhsDBQqsR3+UWr pxPdV/KIztvfBFdZiRSYDKR4uD8+uS7NbfzM3NXA+lJTQGp1iZtA8VqoX2Of8xzSq1 Mtx68qhJuw2Bg363XiG/wIQEmy4oZ5Zp99fI74eCFh4iiBcHG3vA+W8vlfZZ4hwfwX yQuDf3Qdn3Rwg== Date: Mon, 13 Apr 2026 12:19:41 +0300 From: Mike Rapoport To: Muchun Song Cc: Andrew Morton , David Hildenbrand , Muchun Song , 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 Subject: Re: [PATCH 01/49] mm/sparse: fix vmemmap accounting imbalance on memory hotplug error Message-ID: References: <20260405125240.2558577-1-songmuchun@bytedance.com> <20260405125240.2558577-2-songmuchun@bytedance.com> 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: <20260405125240.2558577-2-songmuchun@bytedance.com> 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. > > 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 tracking. > > 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 offsetting > the increment and maintaining balance. > > 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(-) > > 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); > > memmap = populate_section_memmap(pfn, nr_pages, nid, altmap, pgmap); > + memmap_pages_add(DIV_ROUND_UP(nr_pages * sizeof(struct page), PAGE_SIZE)); 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 all. > if (!memmap) { > section_deactivate(pfn, nr_pages, altmap); > return ERR_PTR(-ENOMEM); > } > - memmap_pages_add(DIV_ROUND_UP(nr_pages * sizeof(struct page), PAGE_SIZE)); > > return memmap; > } > -- > 2.20.1 > -- Sincerely yours, Mike.