From patchwork Wed Apr 5 18:54:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 13202374 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 CB55CC77B62 for ; Wed, 5 Apr 2023 18:54:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2F5286B0071; Wed, 5 Apr 2023 14:54:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2A4566B0074; Wed, 5 Apr 2023 14:54:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 16BFA6B0075; Wed, 5 Apr 2023 14:54:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 06E2E6B0071 for ; Wed, 5 Apr 2023 14:54:33 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id D269C1C6AD5 for ; Wed, 5 Apr 2023 18:54:32 +0000 (UTC) X-FDA: 80648238384.16.791BAE6 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.201]) by imf13.hostedemail.com (Postfix) with ESMTP id 21EE020014 for ; Wed, 5 Apr 2023 18:54:30 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=DvoZtrow; spf=pass (imf13.hostedemail.com: domain of 35cMtZAoKCEwC265Cov0sru22uzs.q20zw18B-00y9oqy.25u@flex--yosryahmed.bounces.google.com designates 209.85.210.201 as permitted sender) smtp.mailfrom=35cMtZAoKCEwC265Cov0sru22uzs.q20zw18B-00y9oqy.25u@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=1680720871; 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=74VbkkX1JNgTJppCDrpyUBhSlzGYrPPYVv0NXjoYgyc=; b=bwW1CnwKNRzvk4Nx1jawz+Px4cCUYUOHeJ+p9uZTniYK9wsNLrPBnSiBvK60j3fPkFYLj8 p3J6JcfT+dSFwQJGbdfhZQTEVAQ93eisK8GJ+WQ+JQHW7tiO6pdL+foAfjcnKlI1dznAh6 Zr24qGUBQxt8AQE904ZwGWZfTc30vAs= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=DvoZtrow; spf=pass (imf13.hostedemail.com: domain of 35cMtZAoKCEwC265Cov0sru22uzs.q20zw18B-00y9oqy.25u@flex--yosryahmed.bounces.google.com designates 209.85.210.201 as permitted sender) smtp.mailfrom=35cMtZAoKCEwC265Cov0sru22uzs.q20zw18B-00y9oqy.25u@flex--yosryahmed.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680720871; a=rsa-sha256; cv=none; b=Zxl85nMHqru+ZkGS0ZSQRiOe49otmfCPQjU3zP8nPzhWQ068/kNSgpCrhz5IZEI3+RHPmS 98EFM8mw3SqNNbfju5UYgHw/pj9Oq2zDz4knBmuCnzhPqGOy33yHCe6zXU7IRPWAE7aYzc 21zhNmItxsdv+tKyOYxRh+Lu23Natoo= Received: by mail-pf1-f201.google.com with SMTP id t16-20020a62d150000000b006261da7aeceso3161636pfl.5 for ; Wed, 05 Apr 2023 11:54:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1680720870; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=74VbkkX1JNgTJppCDrpyUBhSlzGYrPPYVv0NXjoYgyc=; b=DvoZtrowqtchOBo3Knj2bdyh+0reXXG6EgqqogY/mAyo+TSHhWSb9U2cJKuwxd7h2w o2RX0e8+Zwu1WADDOlnnpGNdNztCU7WB8Qje6IiAB/MfTzkr62n9cE3NrDiwNbW0sDjH VkmeCcgNPVtOFmHHi+9HgWbW0Z24Zu6e6XFf+Qci0FBgIegloiaEWYx/NseVj73FQU7q Q51X91yYhlKkYuSLDOnFpKRH7l1zCwbwiEAGW0rXRqhGF9SRBlbwebErhD2Q+IgzmaDJ ZIZh4OMxhCZbxyMwD9Ftdx6AM+OvFYs2mi3lYMsNUVLkpHDU34ZfxGINsWiKNbF9ytdL jp6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680720870; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=74VbkkX1JNgTJppCDrpyUBhSlzGYrPPYVv0NXjoYgyc=; b=r8N/mfYzpfG5xHeoL3N4shSPMHMBTAlU3nC0R4A7BjJMpp4LBZpAquGnCk/tqNcUT5 sHtsk9xrgsnoQ84cSD54NSxQQjCEyN8GYseFupwYHwr3B5i+tbRvQOxdkw1mAT1/pKlM q/JGKwZG1RrzoOjeungVoK9xRvumENWcdvlp67WmXHff1rqNWqNq9Po+2vnhfNl/OBJl T1ZAfw5emDywmWCjLTc7yjm2JJLjDGs3XURcFjr89vC3qx3P1VDYPOmA7yh4l92F6flp YgKxGmXoH+2PVi47EDYAxMAWNeSsq/gCfG38SaCE/q+KsBqFBvpQaUgFyj3iy8SkVnYy LoMQ== X-Gm-Message-State: AAQBX9dDAmo4iY+BS97LfrLUzaFJYtvumemeYKnxEhmf1Xed6I5EY7ve A5xUXW3NJh+434o0mM7QIdrKgPfbk5cWxjwi X-Google-Smtp-Source: AKy350YH2iSQX6gNnTj2zSUoqJgUjpVMBh1a0kuQQW4A3Qs4h6unL0l7+ARu30/SrGo0X9cSZkV5qMEnH3NanZCo X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2327]) (user=yosryahmed job=sendgmr) by 2002:a17:90a:6c65:b0:23f:a26e:daa3 with SMTP id x92-20020a17090a6c6500b0023fa26edaa3mr2624714pjj.9.1680720869909; Wed, 05 Apr 2023 11:54:29 -0700 (PDT) Date: Wed, 5 Apr 2023 18:54:25 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.40.0.348.gf938b09366-goog Message-ID: <20230405185427.1246289-1-yosryahmed@google.com> Subject: [PATCH v5 0/2] Ignore non-LRU-based reclaim in memcg reclaim From: Yosry Ahmed To: Andrew Morton , Alexander Viro , "Darrick J. Wong" , Christoph Lameter , David Rientjes , Joonsoo Kim , Vlastimil Babka , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, "Matthew Wilcox (Oracle)" , Miaohe Lin , David Hildenbrand , Johannes Weiner , Peter Xu , NeilBrown , Shakeel Butt , Michal Hocko , Yu Zhao , Dave Chinner Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-mm@kvack.org, Yosry Ahmed X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 21EE020014 X-Stat-Signature: c7p4twdg1hxf8r337pk59yiypeqtfse3 X-Rspam-User: X-HE-Tag: 1680720870-96517 X-HE-Meta: U2FsdGVkX19UTjd5TYiyD4yAQ1TxBOUqQ6cZX4q9M65Ao6h9Oy5onNgjFldLqNK4izKbaf2WnfRv/gM1puk+27wbDkaKHzTUcJ1pN30PrALuiIZMVf5H13tN/hKGW8gqjlNSmebJfi1KS7VWgd+/nYaHITqLdi4Q0D/OQx5Ks7YpA/ZD3eRX9NzQ0Vld1bHKegslGyTp9To/2VdMdtU3PQMtJnKQ5uCgeSqhFv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BU/4sj58pr2+v3FDyBwyAtiz9xjTwF2SAlKOCFK43aMmohp239WydP0ZJwBtW753zua55Jz4HrBFA6n7wtF2V1oG9t8p0pGZ4xYfJ//BAbCP9RdBjGsLv8sxHr/MQxDzTAUzK+I6YqvwIRuqkLN6OSuRVctJoGx81snoJvQCAlZiQO2h+b1zOvbolxu4xFByRfyJ2tZTtX4nOMhZz4A7OUJj1YYBBjs2aYcEcpWFWmHx8DFVqSvhkp6bS6ThW41l7xjGhCh6w77QYFCSrxcDVQX5neUvLZ1xnmrg1JxkHUhByn7skjq3mduFEChIqTQyfHKT+MuhrPPpPD09XS0Pz/p7HU896dAEkhvAd3GQltnccPuhg5OhGxjV1ilW7PQL1rpLi8GyDpv/ZIp9wztq/CWmznzRpGnPD9f+FnTpdVWsx31DaugxfkmzHHd+1PQafzxxtj+spyrQrgQ3Bq8GrPxc1+aSJQLf7YQnm0H 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: Upon running some proactive reclaim tests using memory.reclaim, we noticed some tests flaking where writing to memory.reclaim would be successful even though we did not reclaim the requested amount fully. Looking further into it, I discovered that *sometimes* we over-report the number of reclaimed pages in memcg reclaim. Reclaimed pages through other means than LRU-based reclaim are tracked through reclaim_state in struct scan_control, which is stashed in current task_struct. These pages are added to the number of reclaimed pages through LRUs. For memcg reclaim, these pages generally cannot be linked to the memcg under reclaim and can cause an overestimated count of reclaimed pages. This short series tries to address that. Patch 1 ignores pages reclaimed outside of LRU reclaim in memcg reclaim. The pages are uncharged anyway, so even if we end up under-reporting reclaimed pages we will still succeed in making progress during charging. Patch 2 is just refactoring, it adds helpers that wrap some operations on current->reclaim_state, and rename reclaim_state->reclaimed_slab to reclaim_state->reclaimed. It also adds a huge comment explaining why we ignore pages reclaimed outside of LRU reclaim in memcg reclaim. The patches are divided as such so that patch 1 can be easily backported without all the refactoring noise. v4 -> v5: - Separate the functional fix into its own patch, and squash all the refactoring into a single second patch for ease of backporting (Andrew Morton). v4: https://lore.kernel.org/lkml/20230404001353.468224-1-yosryahmed@google.com/ Yosry Ahmed (2): mm: vmscan: ignore non-LRU-based reclaim in memcg reclaim mm: vmscan: refactor reclaim_state helpers fs/inode.c | 3 +- fs/xfs/xfs_buf.c | 3 +- include/linux/swap.h | 17 ++++++++++- mm/slab.c | 3 +- mm/slob.c | 6 ++-- mm/slub.c | 5 ++- mm/vmscan.c | 73 +++++++++++++++++++++++++++++++++----------- 7 files changed, 78 insertions(+), 32 deletions(-)