Message ID | 20230331070818.2792558-1-yosryahmed@google.com |
---|---|
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp376873vqo; Fri, 31 Mar 2023 00:19:22 -0700 (PDT) X-Google-Smtp-Source: AKy350YhmansewdV9V8QSF3M+lVWNO+WbdUmBG44c50WrInC0lcfTVA6Mi5c1ehrBKAt969mE++9 X-Received: by 2002:a05:6402:5178:b0:4fa:57bf:141a with SMTP id d24-20020a056402517800b004fa57bf141amr28302476ede.32.1680247161934; Fri, 31 Mar 2023 00:19:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680247161; cv=none; d=google.com; s=arc-20160816; b=AJpzAgWI6OQa6IDEDC9Gr+M7VeQa+IE+dph30GCwXKjjBjl7bF0PxRLDNdqEc2+yGt +3TKrPs85hUgNEWaLYjnp8Bj5m0wFNwugN26oaiJZ3osq0BoKh1VTCaAuWOz1a5ZVkOb tv/PGnlwGNPD1nUoQ6bVfMmDi/7WzP8WXrpUH5jZy8mk+QkIIakccbio4lyX0tkC32Z9 wBRsxFhlJMyNDLXd3KXyb6M7UV0bXBuH0qqBl20b5W6NyxYOz0CE9LfYnPRb8fYdTs3l ux/iZuOaNQxS43QfT3Uc1oZtMmIz0AWAiOmb5CokJ7XzE48ezcZlQAfCgUGQ4kqkRvYW YsBQ== 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=AxV13ttd0okhRK37057Bft4LTQPnmiMqtPZxYuE9zT4=; b=q6f4K86th7KcCsPn0bmx8T5eHXpGtdR88dbv5jG4JMBkF3MM3x+sBdqh0Aie5k5DWj 2csFpa4rBKvGIaWmpU4xGsrzZfIKHaXDNqijwtAIWRxZ34Nb8DKDBX0XaT7qTN0SGW26 vf+PSACNxo+rpKpsqcB9QG6oKa3l9zFC7pUOgURTojj5KKNQDU5YLrqb6YQk3IXH554G AdoJ0Tyzs9GuSSFsAzOHF/szzt1fwAqcCucK9FSnw4AknfkanTiE/3HQs52KMyOr4gCW 8SPOlGZlWjWiEO84aCDthrwluKDrikdR1Ynn3KHQQ0yQOTgebHk5NR3pBzCIVYQdGdwY MdIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=YADI96jV; 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 p8-20020aa7d308000000b004fa18c459fcsi1524412edq.263.2023.03.31.00.18.57; Fri, 31 Mar 2023 00:19:21 -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=YADI96jV; 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 S230410AbjCaHIZ (ORCPT <rfc822;jimliu8233@gmail.com> + 99 others); Fri, 31 Mar 2023 03:08:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58444 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230333AbjCaHIX (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 31 Mar 2023 03:08:23 -0400 Received: from mail-pg1-x54a.google.com (mail-pg1-x54a.google.com [IPv6:2607:f8b0:4864:20::54a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F093CA29 for <linux-kernel@vger.kernel.org>; Fri, 31 Mar 2023 00:08:22 -0700 (PDT) Received: by mail-pg1-x54a.google.com with SMTP id q15-20020a63d60f000000b00502e1c551aaso6504676pgg.21 for <linux-kernel@vger.kernel.org>; Fri, 31 Mar 2023 00:08:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1680246501; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=AxV13ttd0okhRK37057Bft4LTQPnmiMqtPZxYuE9zT4=; b=YADI96jVgiYPZRSA/peAggJ1UQ51//UvA/NHqCLbFRbrvy6NrfGn7y68B7SqPbKkWr 0St+ZzCJthd+R7lYoheP1BORTpoCjw4zPzaECkLQxVQTHrMI8B9cjt7DcBGKSw82qoV7 govybumASYXhf60cCUp/IaMa0u8IjM5BtYMB7XLWRbZTN2AHMrwl7r6Pl36MpeIoLENE DQR8j5Vv14GXCDRTUsQx4sKmHq9BSMZeAYA1VDEA82FeD7/GDaQmT73P882/ebuiiwwv zKf3lK298QFggp7XoIt7VpvXlIweYbvefoc6upchYkznH6ammqvuCWagsQRerA20UDUV 19pA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680246501; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=AxV13ttd0okhRK37057Bft4LTQPnmiMqtPZxYuE9zT4=; b=Uy/9U6ItStZMXRERZvc2pnKf+5As6HAcmgS8eJKcdwyWWSApDLDRu+ZktcbMCrCpNy gGiot++tUEnJ6+utUmcmepIW+um9qMa6UFf/YB4jLC2b1veYD1y7yUWNkdgO8AGt6n3k ZjxyRglPkRTHQ9iFQxIewoAnpvHz6FiNoIA316nLzp10/bGHdGuXH1UutFqq5EIzGlQp wFqwdu6B6PJyhtbnEAmS21rtu+UO34Uj3U01U3yo0Ik7DnbNl5sQRfRpt8Geb3FFbdXK +siGF6FxljMkQmbNqBavEIbAn4t1iCZV3xDzDZ6/cY/hXq2nRiR87DWGgC2G4ZA5FpiU wzdg== X-Gm-Message-State: AAQBX9f1VGmLCNgsWigDWfGGdMhRAd2KP2r+TjdO66uypQrLagXcXS+E ZnPE+ez6mF2OaLcd8/uLY/YLbC43m5SPd6es X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2327]) (user=yosryahmed job=sendgmr) by 2002:a17:90a:68cb:b0:23f:d120:4413 with SMTP id q11-20020a17090a68cb00b0023fd1204413mr7943430pjj.1.1680246501490; Fri, 31 Mar 2023 00:08:21 -0700 (PDT) Date: Fri, 31 Mar 2023 07:08:15 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.40.0.348.gf938b09366-goog Message-ID: <20230331070818.2792558-1-yosryahmed@google.com> Subject: [PATCH v3 0/3] Ignore non-LRU-based reclaim in memcg reclaim From: Yosry Ahmed <yosryahmed@google.com> To: Andrew Morton <akpm@linux-foundation.org>, Alexander Viro <viro@zeniv.linux.org.uk>, "Darrick J. Wong" <djwong@kernel.org>, Christoph Lameter <cl@linux.com>, David Rientjes <rientjes@google.com>, Joonsoo Kim <iamjoonsoo.kim@lge.com>, Vlastimil Babka <vbabka@suse.cz>, Roman Gushchin <roman.gushchin@linux.dev>, Hyeonggon Yoo <42.hyeyoo@gmail.com>, "Matthew Wilcox (Oracle)" <willy@infradead.org>, Miaohe Lin <linmiaohe@huawei.com>, David Hildenbrand <david@redhat.com>, Johannes Weiner <hannes@cmpxchg.org>, Peter Xu <peterx@redhat.com>, NeilBrown <neilb@suse.de>, Shakeel Butt <shakeelb@google.com>, Michal Hocko <mhocko@kernel.org>, Yu Zhao <yuzhao@google.com>, Dave Chinner <david@fromorbit.com> Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-mm@kvack.org, Yosry Ahmed <yosryahmed@google.com> 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761866848169620996?= X-GMAIL-MSGID: =?utf-8?q?1761866848169620996?= |
Series |
Ignore non-LRU-based reclaim in memcg reclaim
|
|
Message
Yosry Ahmed
March 31, 2023, 7:08 a.m. UTC
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. Patches 1-2 are just refactoring, they add helpers that wrap some operations on current->reclaim_state, and rename reclaim_state->reclaimed_slab to reclaim_state->reclaimed. Patch 3 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. Do not let the diff stat deceive you, the core of this series is patch 3, which has one line of code change. All the rest is refactoring and one huge comment. v2 -> v3: - Fixed a compilation problem in patch 2 reported by the bot. - Rebased on top of v6.3-rc2. v1 -> v2: - Renamed report_freed_pages() to mm_account_reclaimed_pages(), as suggested by Dave Chinner. There were discussions about leaving updating current->reclaim_state open-coded as it's not worth hiding the current dereferencing to remove one line, but I'd rather have the logic contained with mm/vmscan.c so that the next person that changes this logic doesn't have to change 7 different files. - Renamed add_non_vmscan_reclaimed() to flush_reclaim_state() (Johannes Weiner). - Added more context about how this problem was found in the cover letter (Johannes Weiner). - Added a patch to move set_task_reclaim_state() below the definition of cgroup_reclaim(), and added additional helpers in the same position. This way all the helpers for reclaim_state live together, and there is no need to declare cgroup_reclaim() early or move its definition around to call it from flush_reclaim_state(). This should also fix the build error reported by the bot in !CONFIG_MEMCG. RFC -> v1: - Exported report_freed_pages() in case XFS is built as a module (Matthew Wilcox). - Renamed reclaimed_slab to reclaim in previously missed MGLRU code. - Refactored using reclaim_state to update sc->nr_reclaimed into a helper and added an XL comment explaining why we ignore reclaim_state->reclaimed in memcg reclaim (Johannes Weiner). Yosry Ahmed (3): mm: vmscan: move set_task_reclaim_state() after cgroup_reclaim() mm: vmscan: refactor updating reclaimed pages in reclaim_state mm: vmscan: ignore non-LRU-based reclaim in memcg reclaim fs/inode.c | 3 +- fs/xfs/xfs_buf.c | 3 +- include/linux/swap.h | 5 ++- mm/slab.c | 3 +- mm/slob.c | 6 +-- mm/slub.c | 5 +-- mm/vmscan.c | 88 +++++++++++++++++++++++++++++++++++--------- 7 files changed, 81 insertions(+), 32 deletions(-)