From patchwork Mon May 6 19:29:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 13655926 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 21219C25B4F for ; Mon, 6 May 2024 19:29:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AD6846B009B; Mon, 6 May 2024 15:29:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A864C6B009D; Mon, 6 May 2024 15:29:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 974F16B009F; Mon, 6 May 2024 15:29:29 -0400 (EDT) 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 78C856B009B for ; Mon, 6 May 2024 15:29:29 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 3930D1C0167 for ; Mon, 6 May 2024 19:29:29 +0000 (UTC) X-FDA: 82088960058.17.6C4A538 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) by imf20.hostedemail.com (Postfix) with ESMTP id 8133D1C000D for ; Mon, 6 May 2024 19:29:27 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=4ZfIo+9m; spf=pass (imf20.hostedemail.com: domain of 3li85ZgoKCBMH7BAHt05xwz77z4x.v75416DG-553Etv3.7Az@flex--yosryahmed.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3li85ZgoKCBMH7BAHt05xwz77z4x.v75416DG-553Etv3.7Az@flex--yosryahmed.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1715023767; 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-type:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=vMsFvGn5E9drw/PQULeDN2NnDOV6ZTK3bSrrukYn3gE=; b=c1bXrF/ca/Rt72tZkjKL5lq/Jwxh8TQjX3fnFXy+TX44CrmegP0aIl+YicLaKxsjuG64E6 PxjIZU6QD6d1q5IHFKj9+MFtOh3xahBWTUokMi59E621omXP73lX4/jRcQiA4OCZC9KvyA QZiEPrtqKK2II0SBAl8rsU97esUA7dI= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=4ZfIo+9m; spf=pass (imf20.hostedemail.com: domain of 3li85ZgoKCBMH7BAHt05xwz77z4x.v75416DG-553Etv3.7Az@flex--yosryahmed.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3li85ZgoKCBMH7BAHt05xwz77z4x.v75416DG-553Etv3.7Az@flex--yosryahmed.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1715023767; a=rsa-sha256; cv=none; b=PMg2SsONLtVo4StgxGGZutzypC/v8/8mBjDcQ3uEJHjIel21qhwrQmzD/0lxozEreFrf/2 QFLEpLJPHADi6kFsAsG6mG0oIxC52Orom2/Q4TlNz8Jnu6Toz3/TdajWiVNNwjdrO4P+Go EGykKI8IocjOJ6FDnFgzSoUbmq40jxQ= Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-61b028ae5easo43160117b3.3 for ; Mon, 06 May 2024 12:29:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1715023766; x=1715628566; darn=kvack.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=vMsFvGn5E9drw/PQULeDN2NnDOV6ZTK3bSrrukYn3gE=; b=4ZfIo+9mMs6n9xaIxTmrdHZEmdayy4XPBOUa8k6mtWKHqd8Rz22w2xC8ynA8KE1On7 n3ala8rWplE2DPXT2HlAHV9Am0xNvmoow7GUj4JW/vBI2T7F0E79zMFU6pQr5GpIE1t6 XI4XyF9QHFRkzlxlTB0hNgF16BcxvwpJ5ipFyVhSjJA0qDya47+I68uAUmvJDGUrrN9K gMEGbSGKLcX6jfV2eR5ovCOWjKkpiTCW0kMwsLrOQIktiQOLOAOoSQywQc93cMoC26/u xOCKXcIXjt6PVfQjYXb2Ckn+lDEhKBqh+OmbgUgaEqV2YoIwaXQzbu+9q39uXLd84puO uemw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715023766; x=1715628566; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=vMsFvGn5E9drw/PQULeDN2NnDOV6ZTK3bSrrukYn3gE=; b=ThvnaSa/mBf3v0LCDlGvohLHYTrF8PZLmKyD4VSwQnAfH8jjTaZI+IXhj6JcTIXMqn iaZIe1jL4BoOzmSXwW+hXHduQWoAdTtCs3KkIBDMrnwBbdBRRlxbeZNbhKCPpNKu5cB1 RJTcHZBjquTiVeph02/eGhG9yysyo4FWF9oscmso5sBLwT83/eIo8zcKMD8Xy6NsM6+J pOBbcY6YZWM00U71k9bb7WmgI2W2kcoi5nHYW3O3vdBLLLDTBoKxAjjze69pM8zwc10+ 8O7ObEcruPLZR7NCwa8Img6COl0HdEEjXA4JdL08kZIfheT485MV1qS92YIP8d/w3Ltn PZGA== X-Forwarded-Encrypted: i=1; AJvYcCUxZday/Ri9obGFCUPnjS3IYTtOnZzXfLhtdZ1fJ16xZGcjVrSufhgmLn2VeqiXhnq+nazZhaJTjTVfUcgmHDwXBsg= X-Gm-Message-State: AOJu0YzG7V4aVERZdGCFJzq+Qvol6Hc2yczWo4YBl9DmmXeusiRb6X4K q5peK5YQG70lg9sV4n97PEHping4awhDRhU8mtIlMYb0fE/SEOsaHPgwipmN3R8BjbfvhyAJhBv HhDXGgOMyoj+X7pi8VA== X-Google-Smtp-Source: AGHT+IENOCELgpMw5VEmqAi5bqOPnEO/Pk6007gBdU/F+qmzq+7vIo3uBQyfw0E3lDsJXlJtZTiPMqjyGbUwAkXi X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:29b4]) (user=yosryahmed job=sendgmr) by 2002:a81:4f05:0:b0:61b:e75b:4806 with SMTP id d5-20020a814f05000000b0061be75b4806mr3003407ywb.1.1715023766466; Mon, 06 May 2024 12:29:26 -0700 (PDT) Date: Mon, 6 May 2024 19:29:24 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.45.0.rc1.225.g2a3ae87e7f-goog Message-ID: <20240506192924.271999-1-yosryahmed@google.com> Subject: [PATCH v2] mm: do not update memcg stats for NR_{FILE/SHMEM}_PMDMAPPED From: Yosry Ahmed To: Andrew Morton Cc: Shakeel Butt , Johannes Weiner , Michal Hocko , Roman Gushchin , Muchun Song , David Hildenbrand , linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, Yosry Ahmed , syzbot+9319a4268a640e26b72b@syzkaller.appspotmail.com X-Rspam-User: X-Rspamd-Queue-Id: 8133D1C000D X-Rspamd-Server: rspam06 X-Stat-Signature: 31f6fmwj6nqfez1pkg9rho9fep77k5m5 X-HE-Tag: 1715023767-391943 X-HE-Meta: U2FsdGVkX1+Jly/lP49wBbvIo29dqGJO1RueOhYLupouJGdJlt++VUTdrywvaUY47IupsuuEcQ3T4ChSk4ad27iDQAE6ccXc+IpAFyBcdUtFTyh/jAiJqc2OkRKOe1BvXu5oDUdr0qJQ4VlqTQHEOtzD2Uwrl9/Uieu6FsgqWSywK5NUVweYaBFFwY/IJh/hSKGDTzl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Mgk9sIz5i2PdMNjWYdbbSt2aEAkTJNkt7s3Ozrz0vK5KkHyvGUeUN/Is/CQyJln8MKfYr0H+jBobE+quzq+jH1qeIVFqF9aiZr2xvVGGnblPdAtjgl8CMi6+55giqVCpwnF+WlgAOysrRX0PVIjxrYLFyLLkMzxvplcOK+U4Htz6Bedu2/S3QSFn5kWfmmJXeIt59rMSUQIkciWmpZDYqbsFgjqfxZnBkNGI6KI/B4jFIWRtTmsoD26R4CFAwFl9c4llBiq4NGqfjZpb6w1U/KxtIJjRVN7dmMJnm4QkCsgXbruXzKA8w35LCW1vE2b2321d2h1cy9WOlYstdFROqr/TxEz8fC4FK9xej93vjGnfLtHwP/W0R6ynD/fjDv9EGHCVVELEdvpPso7YMnYyONUN7yiPSex0Fk7Py6e/OucuRTbEkkIBOFQW2EChV56DBO36gRMOX2cAyBWacPD94LgjSs1CBNHnpdg77P0MSqGJULWLponghqaRMCFEBJDGc1RnUW4hvVI/PGuUEDDbEEbZql8i67rguX2B04jR2eC0brXtjM6/CfUmW8t4ZTAT+2A+7Jxk/VMdSvj349Z7aDEh5b+U4IujpwCA5oqtKq4gGAyHL8Y9ozQg== 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: Previously, all NR_VM_EVENT_ITEMS stats were maintained per-memcg, although some of those fields are not exposed anywhere. Commit 14e0f6c957e39 ("memcg: reduce memory for the lruvec and memcg stats") changed this such that we only maintain the stats we actually expose per-memcg via a translation table. Additionally, commit 514462bbe927b ("memcg: warn for unexpected events and stats") added a warning if a per-memcg stat update is attempted for a stat that is not in the translation table. The warning started firing for the NR_{FILE/SHMEM}_PMDMAPPED stat updates in the rmap code. These stats are not maintained per-memcg, and hence are not in the translation table. Do not use __lruvec_stat_mod_folio() when updating NR_FILE_PMDMAPPED and NR_SHMEM_PMDMAPPED. Use __mod_node_page_state() instead, which updates the global per-node stats only. Reported-by: syzbot+9319a4268a640e26b72b@syzkaller.appspotmail.com Closes: https://lore.kernel.org/lkml/0000000000001b9d500617c8b23c@google.com Fixes: 514462bbe927 ("memcg: warn for unexpected events and stats") Acked-by: Shakeel Butt Signed-off-by: Yosry Ahmed Acked-by: David Hildenbrand Reviewed-by: Roman Gushchin --- mm/rmap.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/mm/rmap.c b/mm/rmap.c index 12be4241474ab..ed7f820369864 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1435,13 +1435,14 @@ static __always_inline void __folio_add_file_rmap(struct folio *folio, struct page *page, int nr_pages, struct vm_area_struct *vma, enum rmap_level level) { + pg_data_t *pgdat = folio_pgdat(folio); int nr, nr_pmdmapped = 0; VM_WARN_ON_FOLIO(folio_test_anon(folio), folio); nr = __folio_add_rmap(folio, page, nr_pages, level, &nr_pmdmapped); if (nr_pmdmapped) - __lruvec_stat_mod_folio(folio, folio_test_swapbacked(folio) ? + __mod_node_page_state(pgdat, folio_test_swapbacked(folio) ? NR_SHMEM_PMDMAPPED : NR_FILE_PMDMAPPED, nr_pmdmapped); if (nr) __lruvec_stat_mod_folio(folio, NR_FILE_MAPPED, nr); @@ -1493,6 +1494,7 @@ static __always_inline void __folio_remove_rmap(struct folio *folio, enum rmap_level level) { atomic_t *mapped = &folio->_nr_pages_mapped; + pg_data_t *pgdat = folio_pgdat(folio); int last, nr = 0, nr_pmdmapped = 0; bool partially_mapped = false; enum node_stat_item idx; @@ -1540,13 +1542,14 @@ static __always_inline void __folio_remove_rmap(struct folio *folio, } if (nr_pmdmapped) { + /* NR_{FILE/SHMEM}_PMDMAPPED are not maintained per-memcg */ if (folio_test_anon(folio)) - idx = NR_ANON_THPS; - else if (folio_test_swapbacked(folio)) - idx = NR_SHMEM_PMDMAPPED; + __lruvec_stat_mod_folio(folio, NR_ANON_THPS, -nr_pmdmapped); else - idx = NR_FILE_PMDMAPPED; - __lruvec_stat_mod_folio(folio, idx, -nr_pmdmapped); + __mod_node_page_state(pgdat, + folio_test_swapbacked(folio) ? + NR_SHMEM_PMDMAPPED : NR_FILE_PMDMAPPED, + -nr_pmdmapped); } if (nr) { idx = folio_test_anon(folio) ? NR_ANON_MAPPED : NR_FILE_MAPPED;