Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp1124126rwl; Wed, 5 Apr 2023 12:08:37 -0700 (PDT) X-Google-Smtp-Source: AKy350YkcuwcgtPlY90MBD0/c0h9Lg9MYhRnubIllCD04ILF1cKvs48/0dDUdqV8z05KCcISNIOZ X-Received: by 2002:a17:90b:17d2:b0:233:d12f:f43a with SMTP id me18-20020a17090b17d200b00233d12ff43amr8070794pjb.1.1680721717508; Wed, 05 Apr 2023 12:08:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680721717; cv=none; d=google.com; s=arc-20160816; b=FkJTpZXDf1SYL7gHYWYlMo8hzcsC5Pd4mixrSq50mR2CboKgRpCOeTLXd8/bEYzJ6t CyjlEctn/aCyShREDwUQoFBFw2/eXHtcVMWaZTNRXWBw5CGf2vxSt07qq0EKXLg/DdQX n+ZtrwRYt8sXW+hwpWXZ+k2QMeGyVhbD/z9zrYnumLogRhMBFN6PD8az3AmoBJU2rmnv XrnrqPvjJEsQ/lfPfo1Ca1mk6ls6yfP5USkfmVgkYA/ygKWXEHJPxW09rypfhAkYao+U KaqWlM7NI2R4FrmssXld1l01Cd0xvu9hCE9tOsfVeuVG7Y060f9M207kqLnVrN6bd6Nz mcKw== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l23-20020a17090add9700b00234001d9d35si1825366pjv.153.2023.04.05.12.08.23; Wed, 05 Apr 2023 12:08:37 -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 S234351AbjDESyd (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 Content-Type: text/plain; charset="UTF-8" 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 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(-) -- 2.40.0.348.gf938b09366-goog