From patchwork Wed Nov 8 17:15:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 13450332 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0DABBC4332F for ; Wed, 8 Nov 2023 17:15:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8028080024; Wed, 8 Nov 2023 12:15:36 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7B22F80023; Wed, 8 Nov 2023 12:15:36 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6A13880024; Wed, 8 Nov 2023 12:15:36 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 5B22180023 for ; Wed, 8 Nov 2023 12:15:36 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 1A9BBC0AB6 for ; Wed, 8 Nov 2023 17:15:36 +0000 (UTC) X-FDA: 81435438672.09.264C0DD Received: from 66-220-144-178.mail-mxout.facebook.com (66-220-144-178.mail-mxout.facebook.com [66.220.144.178]) by imf12.hostedemail.com (Postfix) with ESMTP id 5F3EE4000E for ; Wed, 8 Nov 2023 17:15:34 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=none; spf=neutral (imf12.hostedemail.com: 66.220.144.178 is neither permitted nor denied by domain of shr@devkernel.io) smtp.mailfrom=shr@devkernel.io; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1699463734; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references; bh=+0qN0utnBZQyxW60GuQ7AxYsH/QYc8VGntT4QVwJcSM=; b=BfRs0Yyi+mwDn7jx0RVr2ytni9dV2rhhDDDx1ax1DJb+ECFSJMjoPznjMig6pul+KaMuTz FyjljUVwIZsnfp6PiJCueSpJnWqVHWiPfUF5dfTr/BJWiDCgHayYbUi1mjK29/UvkeSR3r xghBIasifkmfMwhszbM+KXavG0bosI0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1699463734; a=rsa-sha256; cv=none; b=5Bpb/2+/DNAWPpacdgPMlXxIp37/1i3A9boORxqZnukPU7kw6STQsvepujdkNcDmO3OUR4 EH221m4sVYV979DKYRyKbR2dk7FGB7BWn2eJBlK7dospqt2FOMwNuGxtT0l4Paonbut6Jx vYewGNzmkpU8NGVFZsK/7HQPNDbkf+4= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=none; spf=neutral (imf12.hostedemail.com: 66.220.144.178 is neither permitted nor denied by domain of shr@devkernel.io) smtp.mailfrom=shr@devkernel.io; dmarc=none Received: by devbig1114.prn1.facebook.com (Postfix, from userid 425415) id 03FA3EFD51E1; Wed, 8 Nov 2023 09:15: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, stable@vger.kernel.org, willy@infradead.org Subject: [PATCH v3] mm: Fix for negative counter: nr_file_hugepages Date: Wed, 8 Nov 2023 09:15:17 -0800 Message-Id: <20231108171517.2436103-1-shr@devkernel.io> X-Mailer: git-send-email 2.39.3 MIME-Version: 1.0 X-Rspamd-Queue-Id: 5F3EE4000E X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: sparag8q7ktd4i7ectk35amts9yokhfs X-HE-Tag: 1699463734-259472 X-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k1nn967AwJ/wlLYUXAroho4azK/QA6Tn9hOhtOXN6+HXUEJn0ZTwZkYEZDnLUNQ3rxAsrQ5RcTvpFopZUY2P8J/k1eKrVJXDmRGnliSMZrK7KePB6LjYmZXI7EsovuCC2tB0s/0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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 Acked-by: Johannes Weiner Cc: stable@vger.kernel.org Reviewed-by: Matthew Wilcox (Oracle) Reviewed-by: David Hildenbrand Reviewed-by: Yang Shi --- mm/huge_memory.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) base-commit: ffc253263a1375a65fa6c9f62a893e9767fbebfa diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 064fbd90822b4..874000f97bfc1 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2737,13 +2737,15 @@ int split_huge_page_to_list(struct page *page, struct list_head *list) int nr = folio_nr_pages(folio); xas_split(&xas, folio, folio_order(folio)); - if (folio_test_swapbacked(folio)) { - __lruvec_stat_mod_folio(folio, NR_SHMEM_THPS, - -nr); - } else { - __lruvec_stat_mod_folio(folio, NR_FILE_THPS, - -nr); - filemap_nr_thps_dec(mapping); + if (folio_test_pmd_mappable(folio)) { + if (folio_test_swapbacked(folio)) { + __lruvec_stat_mod_folio(folio, + NR_SHMEM_THPS, -nr); + } else { + __lruvec_stat_mod_folio(folio, + NR_FILE_THPS, -nr); + filemap_nr_thps_dec(mapping); + } } }