From nobody Sat Jul 25 05:59:51 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 AE0633B71D6 for ; Fri, 17 Jul 2026 06:44:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784270671; cv=none; b=iWQx0Zhu7xBCe2MF6lG9rxzhRYJ8PpMIZtQ9cqzXOkjibyJM6rMS3rrR8ODmA6IJuS15Iy7FzFYp4YvvxIZVUvrA5E/7gzSZH9PrWsYB8VQTKbk/4fM3Ry+xxggzJ+gQyWIOPbHKgME24gsLWK4a6mzLAXqCJDy5toESu3m05J0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784270671; c=relaxed/simple; bh=FAaotPNKWWFzbdZOjyZynp7KDOop/XRtcNz8KMqF3zM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Dk8Raj+/igP7g92v7ATWzRAJaLurq5yNhY2cSEufMxgG6aMfjn1VjW9w9mA0knB5ph7TQ42Wsl9X5W1G6h6RSIJN9vc5/ICjwGZvSbwy5UOuTjbqUfjlLLj+0yiurKD1PEGsSFG5j8cHgXya6bPV3XF1ZncCVp3Wm25QA2BEkEw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=eYDOh3GU; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="eYDOh3GU" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1784270654; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YvQD+9gys5Bjr4sehQzMMfeCVCfBYB0aLci2jGBuO4U=; b=eYDOh3GUNPxch9WnAFZfPMfbUWW0OFwQuDe57l0OcNJrLYJ7rw5Zsgka9SLaKAAejVLI93 EYxvcfdXaqV/u/wXM0NQDtWATeKAIs64v58oZ2HyCuyXj9BAyWP68dNwXXb9rOp472QQqf 4Ix/YjoNpNDMQHNxoqMKaWCSLEiHuuM= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-418-Qv6s2ih4Niee3oujVrbRRQ-1; Fri, 17 Jul 2026 02:44:10 -0400 X-MC-Unique: Qv6s2ih4Niee3oujVrbRRQ-1 X-Mimecast-MFC-AGG-ID: Qv6s2ih4Niee3oujVrbRRQ_1784270648 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C760D1955EAA; Fri, 17 Jul 2026 06:44:07 +0000 (UTC) Received: from p1.redhat.com (unknown [10.22.74.7]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id B3D3B180036E; Fri, 17 Jul 2026 06:43:57 +0000 (UTC) From: Nico Pache To: Barry Song , David Hildenbrand , linux-cxl@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: ljs@kernel.org, willy@infradead.org, Nico Pache , Zi Yan , Oscar Salvador , Andrew Morton , Matthew Brost , Joshua Hahn , Rakie Kim , Byungchul Park , Gregory Price , Ying Huang , Alistair Popple Subject: [PATCH v2 1/2] mm: decrement MTHP_STAT_NR_ANON in free_zone_device_folio() Date: Fri, 17 Jul 2026 00:44:59 -0600 Message-ID: <20260717064502.1980173-2-npache@redhat.com> In-Reply-To: <20260717064502.1980173-1-npache@redhat.com> References: <20260717064502.1980173-1-npache@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" When a zone device folio is mapped as anonymous, folio_add_new_anon_rmap() increments MTHP_STAT_NR_ANON. The corresponding decrement lives in __free_pages_prepare() in page_alloc.c, but zone device folios are freed via free_zone_device_folio() which never calls __free_pages_prepare(). This causes nr_anon to remain permanently elevated after zone device folios are freed. Add the missing mod_mthp_stat() decrement to free_zone_device_folio() so that the counter is properly balanced. Fixes: 5d65c8d758f2 ("mm: count the number of anonymous THPs per size") Reviewed-by: Zi Yan Co-developed-by: David Hildenbrand Signed-off-by: David Hildenbrand Signed-off-by: Nico Pache --- mm/memremap.c | 1 + 1 file changed, 1 insertion(+) diff --git a/mm/memremap.c b/mm/memremap.c index 81766d822400..accba23aef28 100644 --- a/mm/memremap.c +++ b/mm/memremap.c @@ -425,6 +425,7 @@ void free_zone_device_folio(struct folio *folio) mem_cgroup_uncharge(folio); =20 if (folio_test_anon(folio)) { + mod_mthp_stat(folio_order(folio), MTHP_STAT_NR_ANON, -1); for (i =3D 0; i < nr; i++) __ClearPageAnonExclusive(folio_page(folio, i)); } --=20 2.55.0 From nobody Sat Jul 25 05:59:51 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 B29B03B6C17 for ; Fri, 17 Jul 2026 06:44:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784270676; cv=none; b=KMn7A2SdB6DxUFD/B84BW2KW/O8jDnLzssxPzvh7ByTbj5bnnLkG1uVHQa320q23PdB3xtk7RmZpC8jIZQzYqVOce6NiDElI4roEp3vx7L2LcXK2iVluHOK2DJuVZ4/ujFRS35ObJhsqSDeyvGkyR81W1sMkIKNHMUL0AsKpEqU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784270676; c=relaxed/simple; bh=sORV0X+F4O0KR4Pc+tiRmUJlRF6pji9/qC/zLQyUz8o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=khAGScfHuDtCFtbPU4g4cLe9LBSsviVsy9CvZjxmpZAJX+BAu2VqFe9POXXrBrAp9NAfEiGWYJvMuPDzcKUq7vFl7EabApG8wfn1ZQzmMVTHipT0+4S8TGEpnjZAIHhY8VMuTOE1T5wojqC8CFWpVWQY2G+UuAE9C6TRH0o0Deo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=aiPFH63+; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="aiPFH63+" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1784270664; 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=MfX3Q3RbVvpkOOQ837KTiogN+xhujAPLrjvpYVR6OyQ=; b=aiPFH63+E26Hc9+cTi0iKpb3WsAlQOby2Wm6AkBY6V7swaUf4M1tT1jLTZjNHhQwof7N7J nayecasg0XSgoY5wGfV4ANlBGWRHTBj+MYOAvmci4YHPPk2PsR00VmXQHbIMNjbxI/SIrU p2/C7YMt/QMLe6jTxdXzo3gbP3hTTc8= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-213-t0hT6U0FPpu1tZ_D-cZpZQ-1; Fri, 17 Jul 2026 02:44:21 -0400 X-MC-Unique: t0hT6U0FPpu1tZ_D-cZpZQ-1 X-Mimecast-MFC-AGG-ID: t0hT6U0FPpu1tZ_D-cZpZQ_1784270658 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1AB5F18007F5; Fri, 17 Jul 2026 06:44:18 +0000 (UTC) Received: from p1.redhat.com (unknown [10.22.74.7]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 3548E180036E; Fri, 17 Jul 2026 06:44:08 +0000 (UTC) From: Nico Pache To: Barry Song , David Hildenbrand , linux-cxl@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: ljs@kernel.org, willy@infradead.org, Nico Pache , Zi Yan , Oscar Salvador , Andrew Morton , Matthew Brost , Joshua Hahn , Rakie Kim , Byungchul Park , Gregory Price , Ying Huang , Alistair Popple Subject: [PATCH v2 2/2] mm/migrate: exclude hugetlb folios from MTHP_STAT_NR_ANON accounting Date: Fri, 17 Jul 2026 00:45:00 -0600 Message-ID: <20260717064502.1980173-3-npache@redhat.com> In-Reply-To: <20260717064502.1980173-1-npache@redhat.com> References: <20260717064502.1980173-1-npache@redhat.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="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 __folio_migrate_mapping() increments MTHP_STAT_NR_ANON for the destination folio when `folio_test_anon(folio) && folio_test_large(folio)` is true. However, hugetlb folios satisfy both conditions despite having a completely separate accounting system =E2=80=94 they use hugetlb_add_anon_r= map() which does not touch mTHP stats, and their free path also bypasses the mTHP decrement in __free_pages_prepare(). This causes MTHP_STAT_NR_ANON to be incremented on each hugetlb migration without a corresponding decrement, permanently inflating the nr_anon counter. Add a !folio_test_hugetlb() check to __folio_migrate_mapping() so that only actual mTHP folios are counted. Fixes: 5d65c8d758f2 ("mm: count the number of anonymous THPs per size") Reviewed-by: Zi Yan Co-developed-by: David Hildenbrand Signed-off-by: David Hildenbrand Signed-off-by: Nico Pache Reviewed-by: Baolin Wang --- mm/migrate.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mm/migrate.c b/mm/migrate.c index d9b23909d716..dd15a84b2a52 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -590,7 +590,8 @@ static int __folio_migrate_mapping(struct address_space= *mapping, /* No turning back from here */ newfolio->index =3D folio->index; newfolio->mapping =3D folio->mapping; - if (folio_test_anon(folio) && folio_test_large(folio)) + if (folio_test_anon(folio) && folio_test_large(folio) && + !folio_test_hugetlb(folio)) mod_mthp_stat(folio_order(folio), MTHP_STAT_NR_ANON, 1); if (folio_test_swapbacked(folio)) __folio_set_swapbacked(newfolio); --=20 2.55.0