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: 7772 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp541672vqo; Wed, 5 Apr 2023 12:29:24 -0700 (PDT) X-Google-Smtp-Source: AKy350YPNyQSo1XmvYOuDgx13C1iDR1XiPHcMSdB2xPNRk9odZ/qadIyNYAy/hSVuKvDNg0CYT28 X-Received: by 2002:a17:90b:1b44:b0:23f:a4da:1203 with SMTP id nv4-20020a17090b1b4400b0023fa4da1203mr7967191pjb.19.1680722964387; Wed, 05 Apr 2023 12:29:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680722964; cv=none; d=google.com; s=arc-20160816; b=kvUGVPFHJqW51WWF7aSDF2jBF0IBCBqzOX/Y4ApzTg20k+bxL/ZwL6QD728fGVU4Uz 6CieiFO9fZPzgWMgDAxLKbxIbz064Jgav2GsOsHUFqrjLAGXJmqCCtXb5qXk2uwB/uf1 CZAACwqiiiv4VcebN8V0lp2XaIepQo34o6J5B8mHqguovlX0Sa6jpcvlDmqsglJSHCtX m9YJxtt4u+hZ0Q7hVoeApm4Rhxg7PaBaNXD4jORWw602U5E066FhszCdy5t1zyI6Ej1u q42q8XnLFIB0cnMWhgVpfHgwcyVSeT2I5xDW0PnNISPsbHWmsJLuPjHE9l4js0zB4TrP JBYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:mime-version:date :dkim-signature; bh=74VbkkX1JNgTJppCDrpyUBhSlzGYrPPYVv0NXjoYgyc=; b=x1cpJsXCYhrJBrDrnl2oXDguxWX9JtEXSaI3swhyibCqjhou54DOuX24wF+49lyG36 BPcreQuPOtWSL+0oaoUOMX05aYlAFgspa+QRlmUH3wF5KIpb5VTzsSUrHmfsDj5foKoJ brxuuIZxSa8aMZJj0u3fsCIpiToSqksRWUWW5utevwhb4LH8p1pp6U0l6yHs6M4yc2A7 /sTjto7BZ3BW0Sdt6FnKMxEuFXpav+oiQ1p7Sg/VPNSCB/Vf9JfU/f4edVui2eKxLZq5 e9Ee+s3185qgnZLTAU+uYxlJfL3drNE0gWksgJLvu5m3PeiXrsLS4teyDVoX39tMDj2p MQPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=DvoZtrow; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id lx6-20020a17090b4b0600b00240c065a242si2030147pjb.38.2023.04.05.12.29.11; Wed, 05 Apr 2023 12:29:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=DvoZtrow; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229872AbjDESyd (ORCPT + 99 others); Wed, 5 Apr 2023 14:54:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49172 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232566AbjDESyc (ORCPT ); Wed, 5 Apr 2023 14:54:32 -0400 Received: from mail-pf1-x449.google.com (mail-pf1-x449.google.com [IPv6:2607:f8b0:4864:20::449]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7AECB558E for ; Wed, 5 Apr 2023 11:54:30 -0700 (PDT) Received: by mail-pf1-x449.google.com with SMTP id o4-20020a056a00214400b00627ddde00f4so16497119pfk.4 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=HOa2dtA45/Otd4/dj2kNeY91k2aM67XEbA06gs1PJLrNYl26iV9PCVDzVgLez8/DDz un2fbHecQ0hXazVDzG+kpEBzC37sfwSbwi6f+eZgeph92E+xQFOd9CL9DQmMPq5OR7xm cy70LR6xYEmFSUZ7PUFxbsEH1x1u3moVKBaMNY2l/lMyxP1DfJMoUTA5RXaE8DoAICaa jQWUiBQtXQvwxky7WQ3LvK06bTX5CKXGYTiheb207dMW0zWhUEf4SzuYkTuU9le/0zjD xCmfKviRThQBGjjLNNysV2R2lHNpYSBZrz54gR7VZwsWLDFFtj2wAA+3o4Lv/jvh05ko QgZA== X-Gm-Message-State: AAQBX9cAe1NxCDLRovDNsq2aMHVnuU5oUOI990aAQzPH8KX7Q1+zXgAP N0YIE0sXJFGqP1CTS2oYFXk6cyGv7tYV63Je 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-Spam-Status: No, score=-7.7 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762203411205475085?= X-GMAIL-MSGID: =?utf-8?q?1762365762977667904?= 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(-)