From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-178.mta1.migadu.com (out-178.mta1.migadu.com [95.215.58.178]) (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 77DB3396D0C for ; Thu, 30 Apr 2026 07:12:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777533182; cv=none; b=GC392Kv45tW0P1Kd0J/J3slGGQpl8KvLpKUIWbJVPe0aSrXY9EKqX2S/EbmcGY3cdHKtjuMYCD135aLGTP/9gaaleS73jshoZGCjJK2uPZNmmTfaSuXDLnFM7lCEzJIFtIFMbeELFSVWCm4SeM3f8uKzFzCgBod2BFLxOwWUu2s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777533182; c=relaxed/simple; bh=vVfDr1LupnwdZdCuo3pVGsnmwZLrKpl+auzKS4n2TRw=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=r6LWddpEZ0k7OkxGm4jEHgSrmH6vRVV6q19fsJBu85QMtiPEW9uYXKT/YQBXTB6Q1B3UeowdZU7pJTEXOSMMq8qt3QkMpApKt8+aAKlPJxpFTVO+ZV8dJU459WsKfhNhiJxFMPgnmp+BoBNOPYUDtDAC6OZBmwJWjrBKEgIDjQI= 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=fdBDf2sv; arc=none smtp.client-ip=95.215.58.178 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="fdBDf2sv" Message-ID: <9bbd24c9-35d2-481e-95cc-459696221ad5@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1777533177; 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=Gr6kV2S8/pIIk5nQOyl2HyoYuX7aTD9lGss4TIfvIBo=; b=fdBDf2svHXrLC/3tVDKmwK2VODqqQ/i4sqxbhyouF3IAcbgY4qOaK5KkdytUNT9VICYPEp BgyS5bMsDpGOHW1YAhfbPdkWUFtFj7gTV9rHmKTsphwx0OwKyyk20d35sPdc/KKC3KEhmH IFxifgIGZfqY69y1+ScDw924Mv+PxpA= Date: Thu, 30 Apr 2026 15:12:33 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [PATCH] mm/huge_memory: skip huge_zero_pmd in zap_huge_pmd_folio() Content-Language: en-US To: maobibo@loongson.cn Cc: akpm@linux-foundation.org, david@kernel.org, ljs@kernel.org, ziy@nvidia.com, baolin.wang@linux.alibaba.com, Liam.Howlett@oracle.com, npache@redhat.com, ryan.roberts@arm.com, dev.jain@arm.com, baohua@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20260430070217.39679-1-lance.yang@linux.dev> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Lance Yang In-Reply-To: <20260430070217.39679-1-lance.yang@linux.dev> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT On 2026/4/30 15:02, Lance Yang wrote: > > On Thu, Apr 30, 2026 at 02:34:20PM +0800, Bibo Mao wrote: >> >> >> On 2026/4/30 下午12:28, Lance Yang wrote: >>> >>> On Thu, Apr 30, 2026 at 12:11:20PM +0800, Bibo Mao wrote: >>>> when executing command "make check" with qemu software, there is >>>> error report like this: >>>> BUG: Bad rss-counter state mm:00000000972846bc type:MM_FILEPAGES val:-4096 Comm:bios-tables-tes Pid:27802 >>>> BUG: Bad rss-counter state mm:00000000752180c5 type:MM_FILEPAGES val:-2048 Comm:worker Pid:27815 >>>> BUG: Bad rss-counter state mm:000000009c2f6a61 type:MM_FILEPAGES val:-2048 Comm:qom-test Pid:27825 >>> >>> Good catch! >>> >>>> The problem is that when application exits, rss counter is calculated >>>> with huge_zero_pmd huge page, instead it should be skipped. >>> >>> Looks like the same problem[1] we discussed recently. >>> >>> [1] https://lore.kernel.org/linux-mm/74a75b59-2e13-3985-ee99-d5521f39df2a@google.com/ >>> >>>> Signed-off-by: Bibo Mao >>>> --- >>>> mm/huge_memory.c | 3 +++ >>>> 1 file changed, 3 insertions(+) >>>> >>>> diff --git a/mm/huge_memory.c b/mm/huge_memory.c >>>> index 970e077019b7..3cbea344d4a2 100644 >>>> --- a/mm/huge_memory.c >>>> +++ b/mm/huge_memory.c >>>> @@ -2423,6 +2423,9 @@ static void zap_huge_pmd_folio(struct mm_struct *mm, struct vm_area_struct *vma, >>>> { >>>> const bool is_device_private = folio_is_device_private(folio); >>>> >>>> + if (is_huge_zero_pmd(pmdval)) >>>> + return; >>>> + >>> >>> The huge zero PMD should not be returned by vm_normal_page_pmd() or >>> vm_normal_folio_pmd() as a normal folio. If it reaches >>> zap_huge_pmd_folio(), we already made the wrong normal-vs-special >>> decision ... >>> >>> So I don't think we should special-case it in zap_huge_pmd_folio(). That >>> only avoids this RSS decrement :) >>> >>> Could you please check whether the fix[2] also fixes your QEMU test? >>> >>> [2] https://lore.kernel.org/linux-mm/ea1453a6-14c9-4334-ac7e-2758586393b2@kernel.org/ >> yes, I think it will solve this problem. >> >> Only that I think that there should be tlb flush operation after >> pmdp_huge_get_and_clear_full() even with huge_zero_pmd page, so >> tlb_remove_page_size() should be called. Is that right? > > Calling tlb_remove_page_size() is not necessary there :) > > zap_huge_pmd() already marks the PMD range for TLB invalidation right > after clearing the entry: > > orig_pmd = pmdp_huge_get_and_clear_full(...); > tlb_remove_pmd_tlb_entry(tlb, pmd, addr); > > The later tlb_remove_page_size() is guarded by "is_present && folio", > and is for the normal folio case after normal_or_softleaf_folio_pmd() > return one :) Forgot to add: tlb_remove_page_size() queues the folio for freeing via mmu_gather. The shared huge zero folio only needs PMD TLB invalidation, not the delayed freeing :) > > Please correct me if I missed something :D > > Cheers, Lance