From patchwork Tue Apr 4 00:13:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 78796 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2670141vqo; Mon, 3 Apr 2023 17:24:27 -0700 (PDT) X-Google-Smtp-Source: AKy350Y54sygDxZIDU1mJX88HQTd8lbeskyrozsGlbdWa3E2mA7awpy3fQ+ctjPv3DbJv+kNaCMX X-Received: by 2002:a17:90b:1b4a:b0:241:b90:4a1c with SMTP id nv10-20020a17090b1b4a00b002410b904a1cmr617612pjb.44.1680567867348; Mon, 03 Apr 2023 17:24:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680567867; cv=none; d=google.com; s=arc-20160816; b=bhv9f9lKhS2Bo+t5GmybvZHRMOtGkQhsquQ1kiAbe0EV8w86vJXhCePW/Q7TfBUftf eGQ2tnX0Gl+CqfsGDWrGTLvLBkZm8mi5Wr39p8R/3MWWZUNyeL28WzrjE6EogBjO8qRT daNZZYuzSlk98JQquU1mR+iK+dmyaz9BkMALv3XJX0VjG6JeW8LdSEiGGmait6KwQVXG 0xAPk3SLgf1I5QxcfJovie8ZBgkeTvqyKYJEnTki957yR8BBXC49V0XAHyIrS688Rbxk IQZunvGntyFfCPBcpA0fehonfN4CqIkk9ZeugqsQVOUgyoGsEyCyl8ePqS7ZfKghD4C8 6Zvw== 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:references :mime-version:in-reply-to:date:dkim-signature; bh=/hxuqZFO5U+CmKAu0Izd1qiRBhW4afUnD0WyfUo4Gcw=; b=aBAle02kfPnrR1kuy7p4z/UN5MTEGZvwdgWje/SvgJrHV+RCOvCOy7BP/x5oC9gdv7 p3tkNkaF0WjB3bJIsECFXdozrC4LFPGBDtmCEAa60bUQlLLnWSbaLb2p/dENSD43oeKq Iniis/QYTLOu1VAc/CWeJpSM/bhaNbEliUcAROgRL/df/mHD2Wz3l58jGBAu6aFgtAZF VyeWE8X9+bMAVi/lWkO+/CDnx2Fkjd3B6KanpugstnVVz2n2t3eSMWaAtHvduHvawUcI 1QFSc2IQSI1+ze5SqKaVm62utBbfsk1elvFW/L8ksH+cSyHKO3HTWEf289Svr/afZUJQ O8zg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=ERBMFlpw; 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 mj24-20020a17090b369800b002336940f887si8724540pjb.61.2023.04.03.17.24.14; Mon, 03 Apr 2023 17:24:27 -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=ERBMFlpw; 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 S231750AbjDDAOF (ORCPT + 99 others); Mon, 3 Apr 2023 20:14:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231248AbjDDAN7 (ORCPT ); Mon, 3 Apr 2023 20:13:59 -0400 Received: from mail-pl1-x64a.google.com (mail-pl1-x64a.google.com [IPv6:2607:f8b0:4864:20::64a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A7CD3C14 for ; Mon, 3 Apr 2023 17:13:58 -0700 (PDT) Received: by mail-pl1-x64a.google.com with SMTP id x4-20020a170902ec8400b001a1a5f6f272so18251142plg.1 for ; Mon, 03 Apr 2023 17:13:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1680567238; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=/hxuqZFO5U+CmKAu0Izd1qiRBhW4afUnD0WyfUo4Gcw=; b=ERBMFlpwQ+/e/a/Z3AL8E+p3U9MNbkZrsz1HL/MZqvfsps00VtVZYbkySPDVq2/6aR LHVdBQe3ElTtHckYtN+0h+FDNuiI47HZzvKorWDJwFV06A2ZOZ9rTLgMNb03YVp2wZvD PgyPdh7s9QF5a+LrPpjkbUaqX5VHdnehZzbSO8EQsnkGFGX9ApbhWI2WH3GTZIdOCnMl aWLwqKHsahq90y7bzc7mLyA1MCyJjLXiPgYUQBEdJC8xf/8EamW1fLH2Ww2pGZUCTg1p jUEPpHXUbx3wFMtNPW+KmYfxXVLvMYfkOtlZrUyDZokuwj17Ht/6/tV/rlF0tPwOfpWA Gsag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680567238; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=/hxuqZFO5U+CmKAu0Izd1qiRBhW4afUnD0WyfUo4Gcw=; b=FB6O2ZPhwCGI5J6hY4vz8wxbUloouw3UWQ6Vadf+tFJ4KMyq8oONGuA1CfOZc8KAdQ eAbNCokXZtgzY4zVrUjWqahVxV1eK45rE/vpRYCyqh0p9lyMsGisa6LHX8gYin6848gi NvKvSgBm6AIFK85VXtRoUSTsNPXitPO5kT+d07H1HT6quEzIEFJsCNNHTK9DJKS6/PI2 CVD1jcFcQLdYMRuZR4RNqHWSDpbRQ99ChTiT1hZLsnWUuQPL4w73IT8q2oNqd1l4S+M6 +cBCuUNJtsy++vfQOuUrMyLtoS53fPC4Ysq2a1ZM0ix8EkweAxgEWaP6sfX8L2skWqu1 IOeQ== X-Gm-Message-State: AAQBX9fDjzxePFXfcKFZtI40oyhCsX5XWk388fVcXFq+GHu9pJe0RW8Q bp/KK2jNBDcznLj1Ovrn/WjKtXK3a4DzT3bb X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2327]) (user=yosryahmed job=sendgmr) by 2002:a05:6a00:23cd:b0:625:5949:6dc0 with SMTP id g13-20020a056a0023cd00b0062559496dc0mr232232pfc.4.1680567238017; Mon, 03 Apr 2023 17:13:58 -0700 (PDT) Date: Tue, 4 Apr 2023 00:13:51 +0000 In-Reply-To: <20230404001353.468224-1-yosryahmed@google.com> Mime-Version: 1.0 References: <20230404001353.468224-1-yosryahmed@google.com> X-Mailer: git-send-email 2.40.0.348.gf938b09366-goog Message-ID: <20230404001353.468224-2-yosryahmed@google.com> Subject: [PATCH v4 1/3] mm: vmscan: move set_task_reclaim_state() after global_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?1762203131692001621?= X-GMAIL-MSGID: =?utf-8?q?1762203131692001621?= set_task_reclaim_state() is currently defined in mm/vmscan.c above an #ifdef CONFIG_MEMCG block where global_reclaim() is defined. We are about to add some more helpers that operate on reclaim_state, and will need to use global_reclaim(). Move set_task_reclaim_state() after the #ifdef CONFIG_MEMCG block containing the definition of global_reclaim() to keep helpers operating on reclaim_state together. Signed-off-by: Yosry Ahmed --- mm/vmscan.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 9c1c5e8b24b8f..fef7d1c0f82b2 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -188,18 +188,6 @@ struct scan_control { */ int vm_swappiness = 60; -static void set_task_reclaim_state(struct task_struct *task, - struct reclaim_state *rs) -{ - /* Check for an overwrite */ - WARN_ON_ONCE(rs && task->reclaim_state); - - /* Check for the nulling of an already-nulled member */ - WARN_ON_ONCE(!rs && !task->reclaim_state); - - task->reclaim_state = rs; -} - LIST_HEAD(shrinker_list); DECLARE_RWSEM(shrinker_rwsem); @@ -511,6 +499,18 @@ static bool writeback_throttling_sane(struct scan_control *sc) } #endif +static void set_task_reclaim_state(struct task_struct *task, + struct reclaim_state *rs) +{ + /* Check for an overwrite */ + WARN_ON_ONCE(rs && task->reclaim_state); + + /* Check for the nulling of an already-nulled member */ + WARN_ON_ONCE(!rs && !task->reclaim_state); + + task->reclaim_state = rs; +} + static long xchg_nr_deferred(struct shrinker *shrinker, struct shrink_control *sc) { From patchwork Tue Apr 4 00:13:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 78798 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2672100vqo; Mon, 3 Apr 2023 17:29:30 -0700 (PDT) X-Google-Smtp-Source: AKy350Z96pNZLYIbHsv4/bj6EeA0z435FKTaq/KssRbK29tpFUFCs1m8squ5gp5/TMHjouwbjeSC X-Received: by 2002:a05:6a20:8c2a:b0:dd:df53:434e with SMTP id j42-20020a056a208c2a00b000dddf53434emr370215pzh.51.1680568170305; Mon, 03 Apr 2023 17:29:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680568170; cv=none; d=google.com; s=arc-20160816; b=gyFduwrVuI6gQYTIYyK8bD0WBLa7cD1nGdwXzbtQ2MqYhWr8BY2UrX6lBDUpuzrMMI 57gNnQTclpxyHt3VRlSP5Vb2jVSAxr5RO/3SB1qp/ekW69YmqM6Kyid3UTY90WcSFUsg bYyDxzX+YIukhZLrhIh65Rk4S998l4/zT2UbWb6iFEQXiTybXadko1u+mBZUZnpJw3qx ercn/rlzhapIZS6Crtq4qJNa00lVBf+MSSKVOff8kHarbmEVteqc5efDVAVUGi8eGjWG +qE+JrU5XP+9T84EATtpdy5pQdQCjRWaPsrGoXAp5v9BASr96/hVSl7gnn08ueKbepVH B7zw== 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:references :mime-version:in-reply-to:date:dkim-signature; bh=KttjkMRwWn+raVJD4pdmRR27zCHPUdxyxHHqMjZ4zso=; b=ZD06C375eokz8MQQexJAG/ty22mEbw5nYEq+gmVe7+iaNWif9orAzMhiKRqOaN7Lc8 M5JQD+srv4SS6u+NMWIEYmVsPizzrh5GhU20l1oPys30l3BjcDdUvghTQEfVCG5P/ALt jo+GSmSx2SAme5WV8RHBTi63k+Q6mnbaFOGJBtinbiyFWZHEOKFNpgp71a+lKAwLI9C0 7XzU0jJRe8X5WAPv9jME2giH7VjMQCPynzVS4cazA4DG9w3naIXJRLZL089nGkpRsaz2 nFHtAUEBzC5eq1DiQhdnFJKq7UL3/p7uv612dlLAt0ltypXyhzAX0tGgQaZbL96A04iF jh9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=LtYxh8Yf; 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 t127-20020a625f85000000b00627e9b0d5d7si9252065pfb.354.2023.04.03.17.29.18; Mon, 03 Apr 2023 17:29:30 -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=LtYxh8Yf; 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 S231804AbjDDAOK (ORCPT + 99 others); Mon, 3 Apr 2023 20:14:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41262 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231701AbjDDAOC (ORCPT ); Mon, 3 Apr 2023 20:14:02 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 887BFAB for ; Mon, 3 Apr 2023 17:14:00 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-54161af1984so304658217b3.3 for ; Mon, 03 Apr 2023 17:14:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1680567240; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=KttjkMRwWn+raVJD4pdmRR27zCHPUdxyxHHqMjZ4zso=; b=LtYxh8YfdBOctNDOeOLcBvNxi7r6sZaIjGKGM0dSm4YAneG6TwPyrn6ciNpFpw7o05 agIDp8r5g1zsrBgbrkIAj0istxDrIlFVjEGnPtfdwxO+fsBcrB9rTcH6hnSDhjeSGcI9 DNWZ+jLmPaIMNrbRgwWvkKyl3KncBlpUe/ySEPbtedlDu2Al/e4kMdIq0CbOxcu1yZTM p4hiQCl8bRdPl3Qg3dXxTrvvyXCgzXh5Si+jrlA5hVfiT0NfHjRVSIoyov4AHA/OntzE adXxHHHwpx/tQEJ5noRB+DDraQeehxLQoOxrCnjR60/cYEdTl8ijh1e5DVzefIts+Ack bxFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680567240; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=KttjkMRwWn+raVJD4pdmRR27zCHPUdxyxHHqMjZ4zso=; b=xA3x6FoaNdy1Ep/HsjUQBZTBZNS0bJUVR2K8WDZm0YM9w97ta1fgVpv5/FZQJ/CdG2 zz7EMnuZ7Am6V7dxwubNU6MjJdeUzbZcwGEdOaoLKxKoMthYxvMXXDqkRutP+xFD9eoG sd67uN+j8955zM4f953xp19uk00q0uzdLfo1fSYr4AXTe7uQP56ptTk38zS/UpB//Qbd cME3Xj6gRsFO+cMzGW9hWdAnCHOOEoOAS+f/lrXvdWHoVKBJMGZmIDmLscQjqUkEnMC8 Kd0bR7aS/6ba5LbAgeWg9a5nLHpckeazQS7xs3RMzVULmEqlkMfkW3gh5d2d/dpvim6q 9V/g== X-Gm-Message-State: AAQBX9fEPst7636G4tX4Ig9UL3Wl2iP9XyL+OpR+KwxpLLbFKBk+Xo9x SiYILOCz1SyBVIltsJ4FziPK8oUnlbfx9+IU X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2327]) (user=yosryahmed job=sendgmr) by 2002:a25:d950:0:b0:b7d:87f:ce3e with SMTP id q77-20020a25d950000000b00b7d087fce3emr663961ybg.6.1680567239851; Mon, 03 Apr 2023 17:13:59 -0700 (PDT) Date: Tue, 4 Apr 2023 00:13:52 +0000 In-Reply-To: <20230404001353.468224-1-yosryahmed@google.com> Mime-Version: 1.0 References: <20230404001353.468224-1-yosryahmed@google.com> X-Mailer: git-send-email 2.40.0.348.gf938b09366-goog Message-ID: <20230404001353.468224-3-yosryahmed@google.com> Subject: [PATCH v4 2/3] mm: vmscan: refactor updating reclaimed pages in reclaim_state 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?1762203449576557776?= X-GMAIL-MSGID: =?utf-8?q?1762203449576557776?= During reclaim, we keep track of pages reclaimed from other means than LRU-based reclaim through scan_control->reclaim_state->reclaimed_slab, which we stash a pointer to in current task_struct. However, we keep track of more than just reclaimed slab pages through this. We also use it for clean file pages dropped through pruned inodes, and xfs buffer pages freed. Rename reclaimed_slab to reclaimed, and add a helper function that wraps updating it through current, so that future changes to this logic are contained within mm/vmscan.c. Signed-off-by: Yosry Ahmed --- 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 | 21 +++++++++++++++------ 7 files changed, 38 insertions(+), 20 deletions(-) diff --git a/fs/inode.c b/fs/inode.c index 4558dc2f13557..e60fcc41faf17 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -864,8 +864,7 @@ static enum lru_status inode_lru_isolate(struct list_head *item, __count_vm_events(KSWAPD_INODESTEAL, reap); else __count_vm_events(PGINODESTEAL, reap); - if (current->reclaim_state) - current->reclaim_state->reclaimed_slab += reap; + mm_account_reclaimed_pages(reap); } iput(inode); spin_lock(lru_lock); diff --git a/fs/xfs/xfs_buf.c b/fs/xfs/xfs_buf.c index 54c774af6e1c6..15d1e5a7c2d34 100644 --- a/fs/xfs/xfs_buf.c +++ b/fs/xfs/xfs_buf.c @@ -286,8 +286,7 @@ xfs_buf_free_pages( if (bp->b_pages[i]) __free_page(bp->b_pages[i]); } - if (current->reclaim_state) - current->reclaim_state->reclaimed_slab += bp->b_page_count; + mm_account_reclaimed_pages(bp->b_page_count); if (bp->b_pages != bp->b_page_array) kmem_free(bp->b_pages); diff --git a/include/linux/swap.h b/include/linux/swap.h index 209a425739a9f..e131ac155fb95 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -153,13 +153,28 @@ union swap_header { * memory reclaim */ struct reclaim_state { - unsigned long reclaimed_slab; + /* pages reclaimed outside of LRU-based reclaim */ + unsigned long reclaimed; #ifdef CONFIG_LRU_GEN /* per-thread mm walk data */ struct lru_gen_mm_walk *mm_walk; #endif }; +/* + * mm_account_reclaimed_pages(): account reclaimed pages outside of LRU-based + * reclaim + * @pages: number of pages reclaimed + * + * If the current process is undergoing a reclaim operation, increment the + * number of reclaimed pages by @pages. + */ +static inline void mm_account_reclaimed_pages(unsigned long pages) +{ + if (current->reclaim_state) + current->reclaim_state->reclaimed += pages; +} + #ifdef __KERNEL__ struct address_space; diff --git a/mm/slab.c b/mm/slab.c index dabc2a671fc6f..64bf1de817b24 100644 --- a/mm/slab.c +++ b/mm/slab.c @@ -1392,8 +1392,7 @@ static void kmem_freepages(struct kmem_cache *cachep, struct slab *slab) smp_wmb(); __folio_clear_slab(folio); - if (current->reclaim_state) - current->reclaim_state->reclaimed_slab += 1 << order; + mm_account_reclaimed_pages(1 << order); unaccount_slab(slab, order, cachep); __free_pages(&folio->page, order); } diff --git a/mm/slob.c b/mm/slob.c index fe567fcfa3a39..79cc8680c973c 100644 --- a/mm/slob.c +++ b/mm/slob.c @@ -61,7 +61,7 @@ #include #include -#include /* struct reclaim_state */ +#include /* mm_account_reclaimed_pages() */ #include #include #include @@ -211,9 +211,7 @@ static void slob_free_pages(void *b, int order) { struct page *sp = virt_to_page(b); - if (current->reclaim_state) - current->reclaim_state->reclaimed_slab += 1 << order; - + mm_account_reclaimed_pages(1 << order); mod_node_page_state(page_pgdat(sp), NR_SLAB_UNRECLAIMABLE_B, -(PAGE_SIZE << order)); __free_pages(sp, order); diff --git a/mm/slub.c b/mm/slub.c index 39327e98fce34..7aa30eef82350 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -11,7 +11,7 @@ */ #include -#include /* struct reclaim_state */ +#include /* mm_account_reclaimed_pages() */ #include #include #include @@ -2063,8 +2063,7 @@ static void __free_slab(struct kmem_cache *s, struct slab *slab) /* Make the mapping reset visible before clearing the flag */ smp_wmb(); __folio_clear_slab(folio); - if (current->reclaim_state) - current->reclaim_state->reclaimed_slab += pages; + mm_account_reclaimed_pages(pages); unaccount_slab(slab, order, s); __free_pages(&folio->page, order); } diff --git a/mm/vmscan.c b/mm/vmscan.c index fef7d1c0f82b2..8f0e7c4e91ae3 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -511,6 +511,19 @@ static void set_task_reclaim_state(struct task_struct *task, task->reclaim_state = rs; } +/* + * flush_reclaim_state(): add pages reclaimed outside of LRU-based reclaim to + * scan_control->nr_reclaimed. + */ +static void flush_reclaim_state(struct scan_control *sc, + struct reclaim_state *rs) +{ + if (rs) { + sc->nr_reclaimed += rs->reclaimed; + rs->reclaimed = 0; + } +} + static long xchg_nr_deferred(struct shrinker *shrinker, struct shrink_control *sc) { @@ -5346,8 +5359,7 @@ static int shrink_one(struct lruvec *lruvec, struct scan_control *sc) vmpressure(sc->gfp_mask, memcg, false, sc->nr_scanned - scanned, sc->nr_reclaimed - reclaimed); - sc->nr_reclaimed += current->reclaim_state->reclaimed_slab; - current->reclaim_state->reclaimed_slab = 0; + flush_reclaim_state(sc, current->reclaim_state); return success ? MEMCG_LRU_YOUNG : 0; } @@ -6472,10 +6484,7 @@ static void shrink_node(pg_data_t *pgdat, struct scan_control *sc) shrink_node_memcgs(pgdat, sc); - if (reclaim_state) { - sc->nr_reclaimed += reclaim_state->reclaimed_slab; - reclaim_state->reclaimed_slab = 0; - } + flush_reclaim_state(sc, reclaim_state); /* Record the subtree's reclaim efficiency */ if (!sc->proactive) From patchwork Tue Apr 4 00:13:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 78797 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2671813vqo; Mon, 3 Apr 2023 17:28:47 -0700 (PDT) X-Google-Smtp-Source: AKy350ZUCNPEzc7EwXpEPD75keeVSW4Xz2qHHUx9yFe7vmhEd4Hy38Mo5ZOYtWZkix9Ggt0PdxAF X-Received: by 2002:a17:903:41d1:b0:1a1:7b8d:6719 with SMTP id u17-20020a17090341d100b001a17b8d6719mr773338ple.27.1680568127346; Mon, 03 Apr 2023 17:28:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680568127; cv=none; d=google.com; s=arc-20160816; b=ZY/C14LmcGcDJFNe0K5ocH+2wobqfVzpFdSKajlrysIcoRGh+tlPxOQOUicFBx2USG 4NBLXNKLz3z+Lf/3C1GK4pX2Gt4lICpA6zfa37ktfY1AYZMNB/VRZebYC8vTdeGLPi3V orBKLtMWhL9GCCoDQopAHZErGv3CKWsWbc1kAzgu0RtUoLmCalHJcHs7JDQiH7jyw1e7 sg1+nksn6oJ9HD8ZP0ZIE694OTR2cawXPTo4cSRMTsuIIM8Tls7bNSRmw/2S3j+DG6uu /ZA1Acsuql4rf1LDGOkaGlB8ElIUzMDGihf4hOfsAizNjx7Ce4FphiDb/6a7j9vvuFBj tGLg== 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:references :mime-version:in-reply-to:date:dkim-signature; bh=QYyKpmgAe3S55Nk5FWRs2dH0UIocesat7xjNxdFTU4k=; b=r2wFnTVeD3WqGYiL5CBBlQh4axioS/MsrT5CXn9HAn4817pW7f6IS44OD3ixeN9hJe LpZKfRT5kW7iAZiNpxikmVBRTCSMm1l1yOQsw/5BHo0W/uPLCO7UXi3bkRifAnEDZvyr Uv9qnQg1Kvun0sJFk3oTJ7xYaJZIYEfCPdGsuQabW4bco+XEkD9AraM2KULClywC4P+L 8mYPBJl8LJw77jdasxiaxOvAg6X8zoyK10DcNygZtNfl6kYlpDgBx3xedxe3kMlSKLM0 /mfBW3IazHo3mpe2gkDKtBcTx1r/h4+HnHAt9LG/j4gPII2wVSorRi/s2/VIgjmtb73G X6wA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=W5WukSX7; 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 c3-20020a170902aa4300b001a1d6a9c6besi8727249plr.386.2023.04.03.17.28.34; Mon, 03 Apr 2023 17:28:47 -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=W5WukSX7; 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 S231969AbjDDAOW (ORCPT + 99 others); Mon, 3 Apr 2023 20:14:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41810 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231845AbjDDAOM (ORCPT ); Mon, 3 Apr 2023 20:14:12 -0400 Received: from mail-pj1-x104a.google.com (mail-pj1-x104a.google.com [IPv6:2607:f8b0:4864:20::104a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4FDC94497 for ; Mon, 3 Apr 2023 17:14:02 -0700 (PDT) Received: by mail-pj1-x104a.google.com with SMTP id q30-20020a17090a17a100b0023d376ac2c5so8023274pja.5 for ; Mon, 03 Apr 2023 17:14:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1680567242; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=QYyKpmgAe3S55Nk5FWRs2dH0UIocesat7xjNxdFTU4k=; b=W5WukSX7xVU0/vv5ALD+tup9Pddeb9Iipi9kb8kJt/jBn+TQTiZoJyEWgKO/OQ61Jh 2tDeM9kRzvnDYGPtmMlhz5iVehjZJg/jQ63YFUQ7WbbPKq0AY2cM2cHrwogahpd+PgEG XwtqC+dGnvs0z0/3t8FCcMDB2O7fMVf3H3E2qFVcjwb9hPLZO3zgEa2XrTMXRi9MFCHf WEtCE6c9sD8f7AqxvmgV8c+yt8qmrF2I9lAqEvjVuhsI1HciUBrepOGZet31fNCDDW8P oX+wUwY7aO9vBuigwgimgUP/rKThFLYxYAVKIiGShyp9evKm8iqS6ChI4jTiXqDaT7MQ ct3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680567242; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=QYyKpmgAe3S55Nk5FWRs2dH0UIocesat7xjNxdFTU4k=; b=11CMZadpfZHeeuZe8uO1MMsaXQCYwQFGOBZFUb9/IrRlgNmaORSuMZsrUXC9fg5ckI I7JinSrAjAmrFcXtY+ITJ6USSzwTylRCvvfbSZAestPZRhBcAZiSLQNLZHvLESfP6wja MGsDXvg3sdyscHeS2OveMqyQ/6r/tAJqcj9PShcmMGcql7lRIjSZJxV4InMBYaSnnzuf Z/MiIlMg0ULoCB8Pc8ugPtDMiaCYmHlqHO4zgJb6JDIXzrwXZBCKhL87jd8Ovama2ab2 aD4wLgz9OZ4eFzL5TmCj6kFR3n3Re13vpN/PWh6VEHs+e5uOOQvdftnlA2X3aBjM4o1+ YaQQ== X-Gm-Message-State: AAQBX9ce0ni5e2JKrqb04s3HVOSDVBxjPTZsFknWKdoR49GfX0hY9Rzo 9iTmPyEeCU5a/KLDFfmyhcIIZFiviEi75OAt X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2327]) (user=yosryahmed job=sendgmr) by 2002:a05:6a00:2e14:b0:627:e6d5:ba2d with SMTP id fc20-20020a056a002e1400b00627e6d5ba2dmr223605pfb.6.1680567241767; Mon, 03 Apr 2023 17:14:01 -0700 (PDT) Date: Tue, 4 Apr 2023 00:13:53 +0000 In-Reply-To: <20230404001353.468224-1-yosryahmed@google.com> Mime-Version: 1.0 References: <20230404001353.468224-1-yosryahmed@google.com> X-Mailer: git-send-email 2.40.0.348.gf938b09366-goog Message-ID: <20230404001353.468224-4-yosryahmed@google.com> Subject: [PATCH v4 3/3] mm: vmscan: 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?1762203404807036307?= X-GMAIL-MSGID: =?utf-8?q?1762203404807036307?= We keep track of different types of reclaimed pages through reclaim_state->reclaimed, and we add them to the reported number of reclaimed pages. For non-memcg reclaim, this makes sense. For memcg reclaim, we have no clue if those pages are charged to the memcg under reclaim. Slab pages are shared by different memcgs, so a freed slab page may have only been partially charged to the memcg under reclaim. The same goes for clean file pages from pruned inodes (on highmem systems) or xfs buffer pages, there is no simple way to currently link them to the memcg under reclaim. Stop reporting those freed pages as reclaimed pages during memcg reclaim. This should make the return value of writing to memory.reclaim, and may help reduce unnecessary reclaim retries during memcg charging. Writing to memory.reclaim on the root memcg is considered as cgroup_reclaim(), but for this case we want to include any freed pages, so use the global_reclaim() check instead. Generally, this should make the return value of try_to_free_mem_cgroup_pages() more accurate. In some limited cases (e.g. freed a slab page that was mostly charged to the memcg under reclaim), the return value of try_to_free_mem_cgroup_pages() can be underestimated, but this should be fine. The freed pages will be uncharged anyway, and we can charge the memcg the next time around as we usually do memcg reclaim in a retry loop. Signed-off-by: Yosry Ahmed --- mm/vmscan.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 8f0e7c4e91ae3..049e39202e6ce 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -518,7 +518,35 @@ static void set_task_reclaim_state(struct task_struct *task, static void flush_reclaim_state(struct scan_control *sc, struct reclaim_state *rs) { - if (rs) { + /* + * Currently, reclaim_state->reclaimed includes three types of pages + * freed outside of vmscan: + * (1) Slab pages. + * (2) Clean file pages from pruned inodes. + * (3) XFS freed buffer pages. + * + * For all of these cases, we have no way of finding out whether these + * pages were related to the memcg under reclaim. For example, a freed + * slab page could have had only a single object charged to the memcg + * under reclaim. Also, populated inodes are not on shrinker LRUs + * anymore except on highmem systems. + * + * Instead of over-reporting the reclaimed pages in a memcg reclaim, + * only count such pages in global reclaim. This prevents unnecessary + * retries during memcg charging and false positive from proactive + * reclaim (memory.reclaim). + * + * For uncommon cases were the freed pages were actually significantly + * charged to the memcg under reclaim, and we end up under-reporting, it + * should be fine. The freed pages will be uncharged anyway, even if + * they are not reported properly, and we will be able to make forward + * progress in charging (which is usually in a retry loop). + * + * We can go one step further, and report the uncharged objcg pages in + * memcg reclaim, to make reporting more accurate and reduce + * under-reporting, but it's probably not worth the complexity for now. + */ + if (rs && global_reclaim(sc)) { sc->nr_reclaimed += rs->reclaimed; rs->reclaimed = 0; }