From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mta1.migadu.com (out-87.mta1.migadu.com [95.215.58.87]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 465353D9557 for ; Tue, 22 Sep 2026 03:33:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.87 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790048018; cv=none; b=oa8l+Z9zldeuxg7pnOzyttvw8DffFnd5EUhyDobAE9ZI/mDun0BCli+OFUlWMTFKxIkvb1fTpk1lcPd+MdkuHARPJkGfFFBQ1DBmPqvCmPFQ86M0QsCDdT3a0HCbFmQfzJMmSLTbjpFJOORa7EsyqnlfKf5ogACBhT/3yeqtr5g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790048018; c=relaxed/simple; bh=jsmJwRa/fQr2fXpiMozTq7dippLPIT6++tb7uYe4CZE=; h=Content-Type:Mime-Version:Subject:From:In-Reply-To:Date:Cc: Message-Id:References:To; b=MWw0X26MS/JhFEKrjA4BGYMG5QZkJVfpefiSmUW8XXPWCUeDa4MAxqS5L0ovIAbo8hX9uK1elStj4IC1dRWYPYW6hknZUcq5dog/EY37AbIDOdeO5+mwKHdhQ+GzWlXLoGJ3OhPPPHtlZufOZLE1TxZWkIPZVVimNomv1qb6Ehg= 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=PyinaneN; arc=none smtp.client-ip=95.215.58.87 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="PyinaneN" X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=jsmJwRa/fQr2fXpiMozTq7dippLPIT6++tb7uYe4CZE=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1790048007; v=1; x=1790652807; b=PyinaneNp/XpGDaHQIlQpL471UlwEOAap2oJYMCTviFmmrdENTlFKEHVeEQm4iLUbmNGPJTY AjSlcZjNZn7P1J7xPamK+Uze2TJWmBNB21GfDDBNJ08fg1wHYRrmLM7ZhHaD6BNvr0CmQjJzhuB 8wz79WE4egnxmh0kh8lNJM8Q= X-Envelope-To: linux-kernel@vger.kernel.org Received: by mta10.migadu.com with ESMTPS id c0aae00e32e5a8cf; Tue, 22 Sep 2026 03:33:26 +0000 X-Mizu-Trace-ID: c0aae00e32e5a8cf X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset=us-ascii 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.700.51.1.1\)) Subject: Re: [PATCH 1/2] mm/hugetlb: account migration target folio in per-node NR_HUGETLB vmstat From: Muchun Song In-Reply-To: <20260921-for-hugetlb_state-v1-1-8a6eec92661f@kylinos.cn> Date: Tue, 22 Sep 2026 11:33:08 +0800 Cc: Oscar Salvador , David Hildenbrand , Andrew Morton , Shakeel Butt , Michal Hocko , Roman Gushchin , Nhat Pham , Chris Down , Johannes Weiner , Michal Hocko , Joshua Hahn , linux-mm@kvack.org, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, Hongfu Li , stable@vger.kernel.org Content-Transfer-Encoding: 7bit Message-Id: <3534C571-DD8F-4FEF-8206-3CA4D783322D@linux.dev> References: <20260921-for-hugetlb_state-v1-0-8a6eec92661f@kylinos.cn> <20260921-for-hugetlb_state-v1-1-8a6eec92661f@kylinos.cn> To: Hongfu Li X-Mailer: Apple Mail (2.3864.700.51.1.1) > On Sep 21, 2026, at 17:12, Hongfu Li wrote: > > From: Hongfu Li > > The NR_HUGETLB vmstat counter is maintained per folio's node: incremented > when a huge page is handed to a user via hugetlb_alloc_folio() and > decremented when it is returned to the pool via free_huge_folio(). > > A folio obtained by alloc_hugetlb_folio_nodemask() never goes through > hugetlb_alloc_folio(), so it is never accounted, while its free always > is. For a migration target this means the target node gets no matching > increment for the decrement on the old node, so the global nr_hugetlb in > /proc/vmstat drops by nr_pages for each migration. The same asymmetry > affects the failed migration path, which frees the target again right > away, and the temporary folio hugetlb_mfill_atomic_pte() takes from the > same helper. > > alloc_hugetlb_folio_reserve(), used to preallocate the memfd page cache > folios, has the same asymmetry: the folio is handed to a user without > being accounted, while its free is accounted through free_huge_folio(). > > Account the folio where it is obtained, in alloc_hugetlb_folio_nodemask() > and alloc_hugetlb_folio_reserve(), so that the increment pairs with the > decrement in free_huge_folio(): a successful migration hands the folio > to a user, a failed one frees it again. > > Fixes: 05d4532b60e3 ("memcg/hugetlb: add hugeTLB counters to memcg") > Cc: stable@vger.kernel.org > Signed-off-by: Hongfu Li Acked-by: Muchun Song Thanks.