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 D5B09346A10 for ; Thu, 2 Jul 2026 17:25:07 +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=1783013109; cv=none; b=r5lO1hwzVHkMY6rOHi44dN6ubpVvy1rYdeo8bm9IYMcDEpCsF0kkcEj76YC/JNvB2uklW42/NujUbQjsRU8jNKfSkFaiVB3fyaP1G8M75DuCC8iZdM303vCPHn/8iPbj9myopzhgep6073ILX4Wv2WazNV95ASejI5A69P6TFf8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783013109; c=relaxed/simple; bh=wC85SlcB8tKCnNUkljig33zwjFejqec25kpt/3M+9i8=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type; b=dz3hV//mRGKa0lRvod2JBX8wvqOA9qtMZIyhwZ0j0FAuuknSN37ICu29fiheiS6xbmSHfSbvLWow2l69M6kR2Hdb2HNtbbr/nPcyKiESyqmHGjQ2z+pVvckbq9XKLlv70UboCb7cgXH+MynlDP0vRgj0x6eV+E1YfR80CZDOBo4= 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=YnMbjMHJ; 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="YnMbjMHJ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1783013106; 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=h2Ms0gDqn541Zm3m4bDAe3INBlyb1cMJpyBl6JN9E+g=; b=YnMbjMHJ36BAyk0oIG6yc3tT21KSUnDcW9CJVRfFB+wyf9eOzwXyN3COxXnBv8K4r/pute v0YcpUpZAhbNEIZPuDzzc+uj1FAlWMbJ9C1MJEGbaaDwjkNepbq2tM4KIY07fJcGPPhngY vUt7SmJXJ75neUQN7jWLGTuv6neT/Vk= Received: from mx-prod-mc-03.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-197-_Mnzm0EiNzKnCBN8KhOh8Q-1; Thu, 02 Jul 2026 13:25:03 -0400 X-MC-Unique: _Mnzm0EiNzKnCBN8KhOh8Q-1 X-Mimecast-MFC-AGG-ID: _Mnzm0EiNzKnCBN8KhOh8Q_1783013100 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 995D71944B24; Thu, 2 Jul 2026 17:24:59 +0000 (UTC) Received: from p1.redhat.com (unknown [10.22.76.7]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0874E3002D2F; Thu, 2 Jul 2026 17:24:50 +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 , Oscar Salvador , Andrew Morton , Zi Yan , Matthew Brost , Joshua Hahn , Rakie Kim , Byungchul Park , Gregory Price , Ying Huang , Alistair Popple Subject: [PATCH 0/2] mm: fix PMD level mTHP accounting bugs Date: Thu, 2 Jul 2026 11:25:45 -0600 Message-ID: <20260702172548.37075-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: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 While running selftests I noticed the PMD level per-mTHP stats (nr_anon) remained elevated after each run. After further investigation I noticed this accounting error occurs for both the migration.private_anon_htlb_test and the HMM tests. In the HMM case this is due to folio_add_new_anon_rmap() incrementing the mTHP stats, but never containing a corresponding decrement in free_zone_device_folio(). We solve this by making sure to decrement the counter when freeing device memory. In the migration case, we are incrementing this counter without first checking whether this folio is a hugetlb folio, which relies on a separate accounting system. We solve this by adding the proper hugetlb check before incrementing this counter. With these changes in place, the two tests no longer cause elevated PMD level accounting issues. Co-developed-by: David Hildenbrand Signed-off-by: David Hildenbrand Signed-off-by: Nico Pache Nico Pache (2): mm: decrement MTHP_STAT_NR_ANON in free_zone_device_folio() mm/migrate: exclude hugetlb folios from MTHP_STAT_NR_ANON accounting mm/memremap.c | 1 + mm/migrate.c | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) -- 2.54.0