From patchwork Thu Apr 13 10:40:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 13210090 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 5D07DC77B6C for ; Thu, 13 Apr 2023 10:40:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C1D5A900002; Thu, 13 Apr 2023 06:40:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BCD536B0074; Thu, 13 Apr 2023 06:40:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A95BE900002; Thu, 13 Apr 2023 06:40:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 99F756B0072 for ; Thu, 13 Apr 2023 06:40:40 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 53789160357 for ; Thu, 13 Apr 2023 10:40:40 +0000 (UTC) X-FDA: 80676024240.14.1F03F31 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) by imf25.hostedemail.com (Postfix) with ESMTP id 9E8D5A0017 for ; Thu, 13 Apr 2023 10:40:38 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=HVVoobki; spf=pass (imf25.hostedemail.com: domain of 3Jdw3ZAoKCOQeUYXeGNSKJMUUMRK.IUSROTad-SSQbGIQ.UXM@flex--yosryahmed.bounces.google.com designates 209.85.216.74 as permitted sender) smtp.mailfrom=3Jdw3ZAoKCOQeUYXeGNSKJMUUMRK.IUSROTad-SSQbGIQ.UXM@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=1681382438; 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=5nwS1fyBbt8DCsnm68UGE4Io82ni7EltGX1ZDdiySc8=; b=i7bsymWozIlx8FlI6lrXZIHDXbMLJuk96xyBUu74N3CaL+Uz2913X1MvgO9CVVIR0iAAi0 yHNuRNJ69Td//+GmION9hN22v/Aexb8RgfRbilXGp2Co1oMPMp7vMy6xbRKxm9CsR0e+bA U+IsfVghVD9WYZZqmqSOIgZjbFt0GcQ= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=HVVoobki; spf=pass (imf25.hostedemail.com: domain of 3Jdw3ZAoKCOQeUYXeGNSKJMUUMRK.IUSROTad-SSQbGIQ.UXM@flex--yosryahmed.bounces.google.com designates 209.85.216.74 as permitted sender) smtp.mailfrom=3Jdw3ZAoKCOQeUYXeGNSKJMUUMRK.IUSROTad-SSQbGIQ.UXM@flex--yosryahmed.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681382438; a=rsa-sha256; cv=none; b=gfPnwJ/zhu2PFdYdmKKumcwUc/NXMq6lsvjqhsXJWJFUjT8bpYbULP86DeLlmpdpgQzp+F 7qXrtyvy8u3QARRBEEJYE+ZLBw2w7GBlD3Tv77FBfCnb8dVnVfTcDAALvSqgbCEwnTrtgI +yrVkJf07OcHFM0sck1gMaRMhKDKPx0= Received: by mail-pj1-f74.google.com with SMTP id v22-20020a17090ae99600b00246f734ea1fso2289809pjy.4 for ; Thu, 13 Apr 2023 03:40:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1681382437; x=1683974437; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=5nwS1fyBbt8DCsnm68UGE4Io82ni7EltGX1ZDdiySc8=; b=HVVoobkiezjfp6Y+BOD4SNMlrogZ39TsH1UXpB46VIMDpuP6g8jnu4Z1tFvSefqpa7 ibKeL8Y8v8nU89B6vMehbHdbQLqWet8dgNLfmXNet9Ipt1SE7lD//LOA5qZhJsd+TyzB 0NR3cw+wpAzpZDYLnkhBnZTCqUKAdsLrw1zJNZoMYbE0K5EXRK9zgOHKc6hd+xdDV6Wh 7oCtwbLRJC1FzkYCfIDMIgKZJ6uq6+eR3gCZXHpVFEFsNPt0I4yguZUs0ykjuPKeyKJv TkAYIgT/O+m7d5+TGbrU5WfhSrVp7RMxUmdPVOLZgW6fMwK/WQDxq23MCj/rtwo8ySJK trHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681382437; x=1683974437; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=5nwS1fyBbt8DCsnm68UGE4Io82ni7EltGX1ZDdiySc8=; b=KKlwH4tT+2J4KzX3QkSv6cyoqPp1GolaF7yRPGI0OI2AQNYvuVU4pOoYA7lldrGsEc tiSZQqqEMKbw76dPFYlVpN6ZGhHN1HEkd2wCYsn2YyD4ccQSwKiTp0mGKpDIusEN0fDi MrMdEBn7Jg1hhOi2/whFhb9FZbKYeQlQlOLxP+s/FKl6VTnAG69Bdc8YvM5yE1ELpBX5 y4Qs2dMe2jzae30PVUkpLNI7bD7HmsDjP+ZxawOwtrIdhtb0acw4ER80PmoElCExhnyM 2+u3tUgEhkZgShEcxNyJpVHCke0DtRMLbuIrVBfvAU0xOkWanuSZJe1pVguZTlc7l2Lf 6zYw== X-Gm-Message-State: AAQBX9cqgOg/LWM9YAN4Z4k7muL3f6U/5nYLAJgkJtACSheqvWBY4TkS P6YwvL5DekXCY4kLUnVd645J0xPzMVjoIYYd X-Google-Smtp-Source: AKy350Zyd2UqUy2DbXNw2G9qTq8DvjwykWuM+fBRJ4yT4p2uyKCDPpMTL/SCWAMTdDtoYDEHTj4HrbLDBQxJccn5 X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2327]) (user=yosryahmed job=sendgmr) by 2002:a65:5584:0:b0:51b:2e3f:9c41 with SMTP id j4-20020a655584000000b0051b2e3f9c41mr358746pgs.1.1681382437184; Thu, 13 Apr 2023 03:40:37 -0700 (PDT) Date: Thu, 13 Apr 2023 10:40:31 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.40.0.577.gac1e443424-goog Message-ID: <20230413104034.1086717-1-yosryahmed@google.com> Subject: [PATCH v6 0/3] 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 , Tim Chen Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-mm@kvack.org, Yosry Ahmed X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 9E8D5A0017 X-Stat-Signature: ijefcsc8ti5yxbkshjs7qnqy8r4rpdfj X-HE-Tag: 1681382438-601719 X-HE-Meta: U2FsdGVkX1/kwosxEo5YnWIcn4Q4kBJ+lU+Ybqz+vX5f5av5iObZbYnphT2GVJoNEkDdJDGAod0TF/RFVPbuRLpNZga4vZ82mrG2pR8DgwDQbOcWT90AMZpyqMF00xHKyzTxo8SZYozfWtuwnzeIgUpRGJ4hL5IT9GlwK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PSMEEuF1xKOi+tDP63SSTW427JYAzZc+cvNycGLsCdC12dtgEOVFid6WG2YiPMJ25bhEvk8ULr2hdO+5NTDAy0mxOs54neyYX2ncsUySBq8qqngofH7Sb/FBIjEYbR/lJCrpqLGERQ3rutXmUW4oeM0K4zR6iA1rxVUsmnh2vj3iQDfZye9lb4UN/urDVkffIRWBSlO/jyVJLLL9aSojuxbcEgsry00xjwloOvTC/4mX4pKen8U2pNlbW72nbsuhaywmbVAqWlA4UPFIqDKZvypmtjZgVjDUY7cJEYZVWh5njjJXErCI9yctftSTnbm74JYR+tmcBdF8f+exgbUpMUHotskAFoxyzWGOt8mpzt3TAtbm2UyVwg5RsCImDoq0PN42Uywk9xNzmp69ElCnOliPAOvyl4xrdAypKuiHA7yFokP4+LanMM1ttSpQCrADxlmcmlXReAod5l/pI5vIcih+1uUtyuwyOzN13EKK44+QJTzbY+u8kCfCoKuunHQOlAan+ulqMOa5E9fDTO9emg3rPROKz 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 overestimate 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. Patches 2-3 are just refactoring. Patch 2 moves set_reclaim_state() helper next to flush_reclaim_state(). Patch 3 adds a helper that wraps updating current->reclaim_state, and renames reclaim_state->reclaimed_slab to reclaim_state->reclaimed. v5 -> v6: - Re-arranged the patches: - Pulled flush_reclaim_state() helper with the clarifyng comment to the first patch so that the patch is clear on its own (David Hildenbrand). - Separated moving set_reclaim_state() to a separate patch so that we can easily drop it if deemed unnecessary (Questioned by Peter Xu). - Added a fixes tag (David Hildenbrand). - Reworded comment in flush_reclaim_state() (David Hildenbrand and Tim Chen). - Dropped reclaim_state argument to flush_reclaim_state() and use current->reclaim_state directly instead (Peter Xu). v5: https://lore.kernel.org/linux-mm/20230405185427.1246289-1-yosryahmed@google.com/ Yosry Ahmed (3): mm: vmscan: ignore non-LRU-based reclaim in memcg reclaim mm: vmscan: move set_task_reclaim_state() near flush_reclaim_state() mm: vmscan: refactor updating current->reclaim_state 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 | 72 ++++++++++++++++++++++++++++++++------------ 7 files changed, 76 insertions(+), 33 deletions(-)