Message ID | 20231108171517.2436103-1-shr@devkernel.io |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:aa0b:0:b0:403:3b70:6f57 with SMTP id k11csp1063154vqo; Wed, 8 Nov 2023 09:16:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IFdGqPAs6WB45fvbqNQS+WSu3+ZBx6nP7XChJAaEb+4d9UOeBRpxkBgMhZwScidQV7rO5Es X-Received: by 2002:a05:6a21:3b46:b0:181:7f53:acfa with SMTP id zy6-20020a056a213b4600b001817f53acfamr2658424pzb.28.1699463798080; Wed, 08 Nov 2023 09:16:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699463798; cv=none; d=google.com; s=arc-20160816; b=jCMF9tVJAUv0I0ITwf7CPPgZ+vt32WXMyFmcdba0FVb/qakt6Tkp4oBAcRS2NhbUfc r4OzumfJKH/3BDH8/yGA2qfu4fd9hoLBqAGATzl5S/LsEb2wrMZ4BQNxDoDGzuhk116m TT6tRU7VaTwO3nyimUzUhPfjvpguaW1t5VsHrbT/OFR8IfZEdUbA0oKmOY3F6UzeCXob gSvGXYCXqbxXzsD2lhHdc4gKa5GiJfg7byBgf93oTSzbitd3Mn4gRu59UzCFgiLnvrDY BThk6+FFQ25+x9VEkdA+a38Fve6yfSIYTKYMVPWosxW5CPYUoPIWpNxbVdpk+9GRiTk9 Xjrw== 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=+0qN0utnBZQyxW60GuQ7AxYsH/QYc8VGntT4QVwJcSM=; fh=FDLKXEt+CtWqvPh9j0XALkAoY8xYr0e7aAfOQ5RcFhE=; b=jOejgp74g6J/GaCoU0x8doDf6ZCcFuAUm7jFPuZ3AIgpTKrqXb0IuClonO+tq3vqb4 sTppCU+vFKHly9sTYkOzd+qaIJPA11844+1sfzlqBvxmvfuW/C68ThclLIhVtnIZP6O/ Tiu1a0ZyZViYov+rMhIVlWBGOVWbq+EPbNE3ibtgeNN/mIFn/5VnLjy7iaIsFZZ0vqqK 9r7AyjbOR31TE8jQs5AkmrmwGwm+Wr4axOf/ZD574GM5/ncL6fsnRA+nte+WWUlVWuUx zrlhImPVbQ04HClVIfcM6txc+TENiDedQOJu1NkhnnYKe1WwJICFHJz+Km8KMCf6gg22 d9tQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id u9-20020a655c09000000b005b90b2d9178si4884358pgr.796.2023.11.08.09.16.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Nov 2023 09:16:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id 78211806A42B; Wed, 8 Nov 2023 09:15:43 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232314AbjKHRPj (ORCPT <rfc822;jaysivo@gmail.com> + 32 others); Wed, 8 Nov 2023 12:15:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45170 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229720AbjKHRPh (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 8 Nov 2023 12:15:37 -0500 Received: from 66-220-144-179.mail-mxout.facebook.com (66-220-144-179.mail-mxout.facebook.com [66.220.144.179]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0969F1BFF for <linux-kernel@vger.kernel.org>; Wed, 8 Nov 2023 09:15:34 -0800 (PST) Received: by devbig1114.prn1.facebook.com (Postfix, from userid 425415) id 03FA3EFD51E1; Wed, 8 Nov 2023 09:15:19 -0800 (PST) From: Stefan Roesch <shr@devkernel.io> 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 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 08 Nov 2023 09:15:43 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781930262824479650 X-GMAIL-MSGID: 1782016951734433397 |
Series |
[v3] mm: Fix for negative counter: nr_file_hugepages
|
|
Commit Message
Stefan Roesch
Nov. 8, 2023, 5:15 p.m. UTC
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 <shr@devkernel.io> Co-debugged-by: Johannes Weiner <hannes@cmpxchg.org> Acked-by: Johannes Weiner <hannes@cmpxchg.org> Cc: stable@vger.kernel.org --- mm/huge_memory.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) base-commit: ffc253263a1375a65fa6c9f62a893e9767fbebfa
Comments
On Wed, Nov 08, 2023 at 09:15:17AM -0800, Stefan Roesch wrote: > 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 <shr@devkernel.io> > Co-debugged-by: Johannes Weiner <hannes@cmpxchg.org> > Acked-by: Johannes Weiner <hannes@cmpxchg.org> > Cc: stable@vger.kernel.org Reviewed-by: Matthew Wilcox (Oracle) <willy@infradead.org>
On 08.11.23 18:15, Stefan Roesch wrote: > 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 <shr@devkernel.io> > Co-debugged-by: Johannes Weiner <hannes@cmpxchg.org> > Acked-by: Johannes Weiner <hannes@cmpxchg.org> > Cc: stable@vger.kernel.org > --- > mm/huge_memory.c | 16 +++++++++------- > 1 file changed, 9 insertions(+), 7 deletions(-) > > 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); > + } Reviewed-by: David Hildenbrand <david@redhat.com> Yes, that's the current state: update these counters only for (traditional, IOW PMD-sized) THP. What we'll do with non-pmd-sized THP remains to be discussed (Ryan had some ideas).
On Wed, Nov 8, 2023 at 9:15 AM Stefan Roesch <shr@devkernel.io> wrote: > > 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 <shr@devkernel.io> > Co-debugged-by: Johannes Weiner <hannes@cmpxchg.org> > Acked-by: Johannes Weiner <hannes@cmpxchg.org> > Cc: stable@vger.kernel.org Reviewed-by: Yang Shi <shy828301@gmail.com> > --- > mm/huge_memory.c | 16 +++++++++------- > 1 file changed, 9 insertions(+), 7 deletions(-) > > 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); > + } > } > } > > > base-commit: ffc253263a1375a65fa6c9f62a893e9767fbebfa > -- > 2.39.3 > >
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); + } } }