From mboxrd@z Thu Jan 1 00:00:00 1970 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 9861D292B54 for ; Thu, 11 Jun 2026 15:57:46 +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=1781193467; cv=none; b=KU2y62wgOE2Zuw30ovh0PlCGued83p8olElU461zK39tgUuPUIJ+/USUK+msAhyAX5n9ywa98yHe8epi/rJLV8lE8SVMndPMoJun1/VsxHuhqCmUqC5otPdhIVFtpTWeeIB67seUaYII5XnPU9KrhW79qQdRh4pZpIQGeTI38E8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781193467; c=relaxed/simple; bh=aC/D50n3Vajj/M13O+SFcV+z/+bePeVahMg066WCexE=; h=Message-ID:Date:MIME-Version:From:Subject:To:Cc:Content-Type; b=ERygpKEL+rbOi8rcSQVXKmh5QktMVbBkiyFesB0cFGM0wy27Vh1s8K0QMYPtbDZ1HrL8T7Q7Y0hTiEfF9y8MnsW4t13fl/3kMU7gUf7/N6uJT/2SQ3AB7rUYMB/kVXQq77GYW/UGv++POjb5qWGSV1BeOB9vhtA2ctL3hRUGNXA= 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=bkaPjTca; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=UdZNgvYp; 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="bkaPjTca"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="UdZNgvYp" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1781193465; 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; bh=CaTVBIrexKm22hRMB++bwqNcNQ1H7GPFCEOimwy1d5I=; b=bkaPjTcaz/CuhGg3GJZmEtzdX3Ujn+UGGXbjrXNPaPgwlPbntr0DXoN+7YD4AowZ2t4wWh sfe92c5JMuaL4nglrqMzVu+Ecc+J+0qKu/7hMBA60RsgCfHXjlqr/TPmQWAX0PDzo1szLR pLBEBdUV60zqo0lMguTiBw9gGC3VxRw= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-661-Wf9i16WNN0amja8-hlWYhQ-1; Thu, 11 Jun 2026 11:57:44 -0400 X-MC-Unique: Wf9i16WNN0amja8-hlWYhQ-1 X-Mimecast-MFC-AGG-ID: Wf9i16WNN0amja8-hlWYhQ_1781193463 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-490c840efe6so9665405e9.1 for ; Thu, 11 Jun 2026 08:57:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1781193463; x=1781798263; darn=vger.kernel.org; h=content-transfer-encoding:content-language:cc:to:subject:from :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=CaTVBIrexKm22hRMB++bwqNcNQ1H7GPFCEOimwy1d5I=; b=UdZNgvYpb48vjGl2W8QzPUdxoZynOhpPN0rhVA83/Yk1PWXvRxGN1dHH9B9vdhOQGN 9xa00gdg01PBiGnkozM5ggn4+c0M4YIs6qwoG49mzFog++chlzlY8MwyeBOSZkDsmBMa tsyYBb9CbHK9/fXWo47PpF7mhWf0WxZaA1gMfMao65am0060pTLKQvxMqK2sXmN02wY6 KrLMG64D6wANEd69caTQYSzTK1i7dxX+6favbKHxXpSyn7wtR5BkVWt3x9P3IN6okqfG x8Yfaoc+bUjaEB85BTTrkkdExzGBROhU7ItSb2XgpEgFjPDTMUIRPIYRuFHP/jGCKhqH vs0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781193463; x=1781798263; h=content-transfer-encoding:content-language:cc:to:subject:from :user-agent:mime-version:date:message-id:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=CaTVBIrexKm22hRMB++bwqNcNQ1H7GPFCEOimwy1d5I=; b=CdY9qKZoAvFLpiu2CdpeVKHvgD2aU7k8KBXr2KqcM/lgvw2CXa2yll/xHej97QS1zd XaKtAoKNqYLMIJviVeDEvC4Qb2kY/Y48mhqSKroWENw6s0ghMCVeZZjc2sfpDn2llUpN ottK93244ten5YrZeiLKqlcJ1qt2y4/d5FP7y8pwPggPyz5zh4EGwOelt87CR78P0dOX Z+zpfsY6WEpUNHCNr6n/vafvW8sqgoK+oQMQ8c5uqlPZUXqwnxVYN/1RwbERkgkq6qRo CNj9MpmmaUWd5FMKSMTwID0spG7ujF9rtoKH7ThuxgegRdXzRKpE3jAZyoyXZul90mNk p/TA== X-Forwarded-Encrypted: i=1; AFNElJ8uOgllic/aX0ljn6cMMfl8w/lzQXpbnQhLLSnbH8lnt12vg7t/UsU984xw8Jc/R0c8AqU1vhByOrYwIuM=@vger.kernel.org X-Gm-Message-State: AOJu0YypRQgTQ9wM/SyDaIhJ+L1WgrdXltLH6Ms9+iTa6+dZ+vefUePn 9kfAJuNdYZNg/CgsixAxIJuK6d4XCI5NDO56TVXToMLIpQoAw+EBMzSccDFO2wpkcLLgCPydtkJ 51p+uaMoamKzmWX8MYIdsz4nCacGerhvp2ldvn8jcv0lCbxdyiHAl/2Kf4upWduxPTQ== X-Gm-Gg: Acq92OFqySH5S4i4MmoGcanN2QUHj3KYBSJRWQtNqAABLuVo9L6hv40yi9fN3tTzANv S118yY00LplH9JNW7HVJpET+v9q6SVXmK7Eng3+pSxezLitgmWKd+/uTfv5ZY7wtmH/oAgiu3GT gf8sitZdmbskL1F3Z0EnmbBCLLQ4KPe1IzFzlYXLxKpgwKqv4xUurzzuLcBKEBsdhglrS3njXOo ivrE11JTK91ioRd6rv6kyj6WGcHxunoNf8+IOPIiZKhEDcxxIwxN04SBpHRZnY6mnf0vC9ziAj9 IQ+XL7e5R3SCqwIxSTXtx5ldYWyrV440XTVcVMLW1lNur7YEENip93ysqiX47U30yHyLr0NUwH5 nJxgJRM99qhKPZ/AOj+cZGiFVK4fK7vwgJkO6klBf53qvKkkHnSdJtvfjqcLed0bC0c3t9WeZ3G Y= X-Received: by 2002:a05:600c:3ba7:b0:490:9dc3:3483 with SMTP id 5b1f17b1804b1-490e52cad04mr42831445e9.2.1781193463159; Thu, 11 Jun 2026 08:57:43 -0700 (PDT) X-Received: by 2002:a05:600c:3ba7:b0:490:9dc3:3483 with SMTP id 5b1f17b1804b1-490e52cad04mr42830875e9.2.1781193462659; Thu, 11 Jun 2026 08:57:42 -0700 (PDT) Received: from [172.31.99.182] (91.red-83-48-118.staticip.rima-tde.net. [83.48.118.91]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-490e2c7ead0sm84150385e9.3.2026.06.11.08.57.41 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 11 Jun 2026 08:57:42 -0700 (PDT) Message-ID: Date: Thu, 11 Jun 2026 09:58:55 -0600 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird From: Nico Pache Subject: [Bug Report] Elevated PMD nr_anon after running selftests To: Linux MM , linux-kselftest@vger.kernel.org, LKML , linux-cxl@vger.kernel.org Cc: "David Hildenbrand (Red Hat)" , "Lorenzo Stoakes (Oracle)" , Oscar Salvador , Andrew Morton , Zi Yan , Matthew Brost , Joshua Hahn , Rakie Kim , Byungchul Park , Gregory Price , Ying Huang , Alistair Popple Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Hi, While testing my mTHP code I noticed that mm selftests caused an accounting error in /sys/kernel/mm/transparent_hugepage/hugepages-2048kB/stats/nr_anon At first I thought I might have caused a regression, but when retesting with 7.1-rc5 (without my code), the issue was still present. This issue occurs in two mm selftests: 1) hmm test 2) migration - private_anon_htlb test I spoke to David about this and he suggested the following diff which seems to have solved both issues. David would you like to send a formal patch or patches? Cheers, -- Nico Diff for (1) diff --git a/mm/memremap.c b/mm/memremap.c index 053842d45cb1..683a77dd679d 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); if (folio_test_anon(folio)) { + mod_mthp_stat(folio_order(folio), MTHP_STAT_NR_ANON, -1); for (i = 0; i < nr; i++) __ClearPageAnonExclusive(folio_page(folio, i)); } -- 2.54.0 For (2) he suggested diff --git a/mm/migrate.c b/mm/migrate.c index d9b23909d716..9fd50ea25d2d 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 = folio->index; newfolio->mapping = 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); @@ -623,7 +624,8 @@ static int __folio_migrate_mapping(struct address_space *mapping, */ newfolio->index = folio->index; newfolio->mapping = 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); folio_ref_add(newfolio, nr); /* add cache reference */ if (folio_test_swapbacked(folio)) -- 2.54.0