Received: by 2002:a05:7412:8521:b0:e2:908c:2ebd with SMTP id t33csp2315223rdf; Mon, 6 Nov 2023 10:19:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IGQQJdye8Duj7b8i/4vZZyvjixYS2BXOfceZE5qFQj2Dn+hmsF49JbKwiM5jRn6PQScz6co X-Received: by 2002:a05:6a00:18a6:b0:68b:bf33:2957 with SMTP id x38-20020a056a0018a600b0068bbf332957mr27653111pfh.22.1699294794806; Mon, 06 Nov 2023 10:19:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699294794; cv=none; d=google.com; s=arc-20160816; b=mR14DEJte3iU8w5lVxN5qcK3tE4TnTTmNt1Hrn9x33lS9lVOKO/ZiQDQDtwxmQVU+C z4K62wykhakfQvDQ2xqtVTKX3XPn6kjzLyZ7mJ1gdjZtsoVcMcC+Jx+NOv0ePdy1C9zk slC5t8Nxjb1g7K2YuMuwmeTl1n4BibrCSMBbD3zsTtfiy3dLW4LZKx4dBUgaaXlu/+Jk mKf0nBAUuXYFi5CMPY3PQKK3OCgBBOXRoQpFavHC81p5SOLKKhpGU7h6ayq0CYr/zljx dxDmQpTZ2bEc8/bXY/PfS0flbkkRAMZxz8mb9rMcL6zQXl4EIWROjcegXudCoW9yxPj3 TZWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=tznUvWWUhmVDHsO88N8kkhvGkj2v84Ym28VkJnsQfv0=; fh=uk3jM691Xw6iDKhnZS8+oDfSSJp2iEjT2KAdXFaSvP8=; b=l7ersfIerUnTtM6cyLHc3Il+ElFfc1pYLiqT+JteENqXKH0jrE4oBpJtsXoXcoGV80 sk1Pu1uF4MkwIYJwdwS0Bsp4uwrj6GhoihgEGCnRBzn0z0stIvwBYJhVH77XZQUct3j4 +7eke64wnT9TQ2QhBIpQ4wcbsLkDh5Ev7gymJPxEAQPlaAhHcsL+MtDaYwlOTiPvOpwd PeU4FiVeryKRp5px6+CVD4hpTlcnjhot7M18qkeOGyiec27Lr3eo77eIA25JJOwSDmbH /rfa+GL0bDIueYpUozlGgLzqoS2Hq8GGMbUBROH3QQtlM6L7DmOCnMtPC/s8A0UC0Pqd A5vw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id l196-20020a633ecd000000b0057e21f51ab3si167259pga.665.2023.11.06.10.19.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 10:19:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 82D3C8035137; Mon, 6 Nov 2023 10:19:51 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232339AbjKFSTi (ORCPT + 99 others); Mon, 6 Nov 2023 13:19:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33884 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231911AbjKFSTh (ORCPT ); Mon, 6 Nov 2023 13:19:37 -0500 Received: from 66-220-144-178.mail-mxout.facebook.com (66-220-144-178.mail-mxout.facebook.com [66.220.144.178]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4388DD69 for ; Mon, 6 Nov 2023 10:19:34 -0800 (PST) Received: by devbig1114.prn1.facebook.com (Postfix, from userid 425415) id 9D200EE24BAF; Mon, 6 Nov 2023 10:19:19 -0800 (PST) From: Stefan Roesch To: kernel-team@fb.com Cc: shr@devkernel.io, akpm@linux-foundation.org, hannes@cmpxchg.org, riel@surriel.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v1] mm: Fix for negative counter: nr_file_hugepages Date: Mon, 6 Nov 2023 10:19:18 -0800 Message-Id: <20231106181918.1091043-1-shr@devkernel.io> X-Mailer: git-send-email 2.39.3 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Mon, 06 Nov 2023 10:19:51 -0800 (PST) While qualifiying the 6.4 release, the following warning was detected in messages: vmstat_refresh: nr_file_hugepages -15664 The warning is caused by the incorrect updating of the NR_FILE_THPS counter in the function split_huge_page_to_list. The if case is checking for folio_test_swapbacked, but the else case is missing the check for folio_test_pmd_mappable. The other functions that manipulate the counter like __filemap_add_folio and filemap_unaccount_folio have the corresponding check. I have a test case, which reproduces the problem. It can be found here: https://github.com/sroeschus/testcase/blob/main/vmstat_refresh/madv.c The test case reproduces on an XFS filesystem. Running the same test case on a BTRFS filesystem does not reproduce the problem. AFAIK version 6.1 until 6.6 are affected by this problem. Signed-off-by: Stefan Roesch Co-debugged-by: Johannes Weiner --- mm/huge_memory.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 064fbd90822b4..ea6bee675c4d3 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2740,7 +2740,8 @@ int split_huge_page_to_list(struct page *page, stru= ct list_head *list) if (folio_test_swapbacked(folio)) { __lruvec_stat_mod_folio(folio, NR_SHMEM_THPS, -nr); - } else { + } else if (folio_test_pmd_mappable(folio)) { + __lruvec_stat_mod_folio(folio, NR_FILE_THPS, -nr); filemap_nr_thps_dec(mapping); base-commit: ffc253263a1375a65fa6c9f62a893e9767fbebfa --=20 2.39.3