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 753B8CA4E for ; Mon, 13 Apr 2026 17:20:17 +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=1776100817; cv=none; b=pbCt+DnxUc5y9eGq4S5xol4I1BQH9BaHWaoLD0LZZDbqGiuQ71POc7LIBTXjEqhpomvEGjKfsycGjARMRZJaON/aPiknJ8FybnfQ2/R1hnPw7doAEXt5TUylf7GEzXVXc8D8CV58jwnSqArhcktK/uN47Lcr4BicFr8go6R+afQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776100817; c=relaxed/simple; bh=8c7V38SjK4hMjN4VLoVwMlqjL2MnquDxEbG/Q9cUQfE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=WqURSyGnl4OI5/OMhRL4aNcEejIO1UjExGEUnHyc7d2YDaIZr/nvls9cUbPSiQU8OMlwyT6WWJW15/aIWtbNK8Vfnw764zh3gCf2P3Lt5QuYQ/83ZfyWG8OK9gm+j/3mZu4O5AUfQ4/Qb2HVia+S4mcHygZRCV0Xoqr6j95EzB4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=EF338F78; 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="EF338F78" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7AD74C2BCB0; Mon, 13 Apr 2026 17:20:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776100817; bh=8c7V38SjK4hMjN4VLoVwMlqjL2MnquDxEbG/Q9cUQfE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=EF338F78QTuHgoJy8BYFIqHIHuMOS7IvI+KpVJdIq5DJt08ZKKW5ojcKBSqziV0LO 7odSFMS3yPcPUZpqvCVxvWTxuKuOs8q1B+/yCUbOl+HGWkNiJEITAtyK57z+sDLxIa 2HS5VaBo0FO/vMGzM7ipr7diKa0CG9ei7DVD/mCwPaEBTknm0NPA3gpUe91TY02eUH fet15Ow7PqmtN0VT6hQ04ed0RK8KfT+U7BikPEX9ivE8Q1QwQdGkx+Qf5cwpwi4Ng/ xK/1oCPstSEbYi/NOFu+HI+lMho0VU3/YQnYwzBPoal+G1JXSlEQbv+0u8Dc1JkYE7 S8n1mTyfgsBtA== Date: Mon, 13 Apr 2026 20:20:07 +0300 From: Mike Rapoport To: Muchun Song 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 Subject: Re: [PATCH 01/49] mm/sparse: fix vmemmap accounting imbalance on memory hotplug error Message-ID: References: <9642F4D9-8F1B-47A4-90BE-C72BB8DE9A11@linux.dev> <48CF5603-D8E1-4C86-8554-E8BA03D195FB@linux.dev> 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=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <48CF5603-D8E1-4C86-8554-E8BA03D195FB@linux.dev> On Mon, Apr 13, 2026 at 10:16:20PM +0800, Muchun Song wrote: > >> +++ b/mm/sparse-vmemmap.c > >> @@ -656,7 +656,13 @@ static struct page * __meminit populate_section_memmap(unsigned long pfn, > >> unsigned long nr_pages, int nid, struct vmem_altmap *altmap, > >> struct dev_pagemap *pgmap) > >> { > >> - return __populate_section_memmap(pfn, nr_pages, nid, altmap, pgmap); > >> + struct page *p = __populate_section_memmap(pfn, nr_pages, nid, altmap, > >> + pgmap); > >> + > >> + if (p) > >> + memmap_pages_add(DIV_ROUND_UP(nr_pages * sizeof(struct page), PAGE_SIZE)); > > > > We don’t increase the counter on failure, then > > > >> + > >> + return p; > >> } > >> > >> static void depopulate_section_memmap(unsigned long pfn, unsigned long nr_pages, > >> @@ -826,7 +832,6 @@ static struct page * __meminit section_activate(int nid, unsigned long pfn, > >> section_deactivate(pfn, nr_pages, altmap); > > > > here section_deactivate() is called, which decrease the counter unconditionally, > > the issue still exists. We didn't fix anything. You are right, I missed it :/ > >> return ERR_PTR(-ENOMEM); > >> } > >> - memmap_pages_add(DIV_ROUND_UP(nr_pages * sizeof(struct page), PAGE_SIZE)); > >> > >> return memmap; > >> } > >> > >> > >> Then we'll better follow "all or nothing" principle and won't have > >> exceptional cases in section_deactivate(). > > To follow "all or nothing" principle here, I think we should not call > section_deactivate() to do the cleanup in section_activate(). > > After all, if section_activate() didn't succeed, how can we use > section_deactivate() to release the resources? What do you think? Yeah, if we could pull "upopulate" from section_deactivate() that would be great. > Thanks. -- Sincerely yours, Mike.