From patchwork Wed Jun 21 02:30: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: 13286577 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 6CD79EB64D8 for ; Wed, 21 Jun 2023 02:31:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D4EDD8D0002; Tue, 20 Jun 2023 22:30:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CD9B48D0001; Tue, 20 Jun 2023 22:30:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B51B88D0002; Tue, 20 Jun 2023 22:30:59 -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 A47D88D0001 for ; Tue, 20 Jun 2023 22:30:59 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 7C73EC0674 for ; Wed, 21 Jun 2023 02:30:59 +0000 (UTC) X-FDA: 80925177438.19.B3AB185 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) by imf09.hostedemail.com (Postfix) with ESMTP id C8F0214000B for ; Wed, 21 Jun 2023 02:30:57 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=rmtJdI5G; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf09.hostedemail.com: domain of 34GCSZAoKCBcLBFELx49103BB381.zB985AHK-997Ixz7.BE3@flex--yosryahmed.bounces.google.com designates 209.85.216.73 as permitted sender) smtp.mailfrom=34GCSZAoKCBcLBFELx49103BB381.zB985AHK-997Ixz7.BE3@flex--yosryahmed.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687314657; a=rsa-sha256; cv=none; b=EtfNo3LcCSShkYysJHOjAmtJzIEXEV+ah3R38SYplYipbLnOwFVYgEci3Ae1stKJn8074L 5qLzxcZTsKYROUyCVKcG2LaJDuVAgZ5ZlXU8XCXPMVgtHAPdNZovJRSqZ/b7X+iDx3BcJn voN/AH7MmMtoGjXp0MreGPzoxXWNEA0= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=rmtJdI5G; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf09.hostedemail.com: domain of 34GCSZAoKCBcLBFELx49103BB381.zB985AHK-997Ixz7.BE3@flex--yosryahmed.bounces.google.com designates 209.85.216.73 as permitted sender) smtp.mailfrom=34GCSZAoKCBcLBFELx49103BB381.zB985AHK-997Ixz7.BE3@flex--yosryahmed.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1687314657; 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=zMvVDCIqwutYRW7BL6wWIoprb3WJoHOr+n8+HE8xmyM=; b=i4wlJkFZ1bbnnR2Z4goSwi6RPB2Ocj61Yzwa2P2OrzOq+jBJcvLLFgzXCHotih/ubv6rgb ybYychOyB3KdhjKMjLC2agbL2KtTJrzN/2Jwnqr5X4DkgCqmsfmToPspWn8THSecylW7p6 FnagRX7YHiLWahS5NlSgyxH4LhJjFn0= Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-25eac66428dso2290025a91.2 for ; Tue, 20 Jun 2023 19:30:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1687314656; x=1689906656; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=zMvVDCIqwutYRW7BL6wWIoprb3WJoHOr+n8+HE8xmyM=; b=rmtJdI5G1/6wEp0nVhAgxso+a3Mm7glgZlr7ICu1hFJ9UoSvLcjsh3iroBWHa+roOa AlXXj0ZNZ4hSg/+DDCeZOJVVN2p7j+QQybGU9VsOYiep+h1HWn88LZQitJlFD4XqaV2c Id+3mXdrhiILKsof5gCOVh6cJIaFI9CVt7E8nxPUB8QfNhtwY8SlyJKpf6YXzxx2X/sC LphIp6fDHG1B1niycXyy0t/qCTXgGgCkYmuLNeONUblJoGNRa541t5sR+YcFNYs1Cax4 S4EQ9LBP0i8YH17eUqtGY9s2I8q3AgmHKcG+FUBveB69EbKNh8UKtWihNq7wWxRTJ3Ew q/JQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687314656; x=1689906656; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=zMvVDCIqwutYRW7BL6wWIoprb3WJoHOr+n8+HE8xmyM=; b=VWfC8pQMl4gZ4TW9rNiRXPOSoRR/9J6PDV72SydDLIMhXQAbfP32F/niQOQkgCXT4M 0QzhXl2mr6/H4mM6zkmA37nvh0WlvdFbxI61i0vb1XV4aqFKywCMB3EKw8WT7jO1fJU8 mDA+7Wws5CzYkeiGUdwikTlkL7fcDF/o8RWjtDkGa8Jf0EpAsHREJcxoZJiXtYktqVWM 66LZsyojKVXduOEMox3dTBnTrH30eH0Ha1LzrE5TH77X+lxiiH7G2mx7K5XaqsS385Bg 79BPEY2Ut6gMDi3EvTT3f5u67z8pH7TCHQ3EW4WuBiawmiyw2pihK6J4VbGn/mo5y+H1 UiOw== X-Gm-Message-State: AC+VfDyQG37fBtRiC8rgn0b3pBnNbhNLudJlLk9DkdKQ4SctTwEgqhYG w9xe715K//TuRhk+bOmh50ZoiLmLk35lFpip X-Google-Smtp-Source: ACHHUZ4wvD8NisRGZkbCm16bHHzOVT6pr5ElJPtaQQsrB+7eK5uc4EwB8Wn4MiiBKHnFztWWKZDJEm0QnPReByj0 X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2327]) (user=yosryahmed job=sendgmr) by 2002:a17:90b:78b:b0:25f:612:b17e with SMTP id l11-20020a17090b078b00b0025f0612b17emr1096620pjz.7.1687314656443; Tue, 20 Jun 2023 19:30:56 -0700 (PDT) Date: Wed, 21 Jun 2023 02:30:53 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.41.0.162.gfafddb0af9-goog Message-ID: <20230621023053.432374-1-yosryahmed@google.com> Subject: [PATCH 1/2] mm: memcg: rename and document global_reclaim() From: Yosry Ahmed To: Andrew Morton Cc: Yu Zhao , Johannes Weiner , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Yosry Ahmed X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: C8F0214000B X-Stat-Signature: 76hez56rtes8z4nabxrcmjh9grqzjz9b X-HE-Tag: 1687314657-434157 X-HE-Meta: U2FsdGVkX1/LD67mAcwKNIZfasWOUxzhayYAo66akOQMLLnQOe2z+ONLS7myfSyLmOZy9YLcD6SNGZNa6qsBBJelV00CgoGNrjADZKSaO3fcIeNGrvfU3TV83F+86CyhwN1910yoiHEts8+9OTkigfFUKF9MCkg0FP5B+wqe5vooOby6bTz6Tn+IFrWSRvq1QR59i8MppJoJqjP3bysYihA9zsYI8S6B2PVw42zj9p8rhCmIQpgRCpBJGKiCsztN/hQFFvK8H9clSguCw2LpVqXwkMoZJB1YHc6k0ELuT9P2zAVdwmGrDXmtIH//dsPBOnqmQAWYilJgdCA50aXlt9+6DOSF3e+ZpO+oogij1C6pCZqdSeRxtlh0F07MuN4s5s4dnsQXgGnVnMIqj6bcebfgAVaT1pCK6EFoX6VpLUTYTPl0i07c4FTYSCsxop/28Pu2H40M0WLfWXrBckSR8x/x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a1ea2aDEw3quv6Qe6sW1YrWGWFf3N2WshHeMbJNnmtSNoskzn9ulcjjziBOEElEBGz5SsSk+8xULnbs3biJf5oCC1dgvMp+cWpj+bZbkdxHh/3mvC5Wppm+I1fktm++riWYEggwFAGtl6vA322i4aVrDS3G/VVveJpBgXOgET4mnOflyLKYYYk/o8iXa1+M1IUFR5OawxsHQwSKUEQC07zpvaAr6Qorh/QZ6BHjSpL2aVaKwMHWuizpqO8= 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: Evidently, global_reclaim() can be a confusing name. Especially that it used to exist before with a subtly different definition (removed by commit b5ead35e7e1d ("mm: vmscan: naming fixes: global_reclaim() and sane_reclaim()"). It can be interpreted as non-cgroup reclaim, even though it returns true for cgroup reclaim on the root memcg (through memory.reclaim). Rename it to root_reclaim() in an attempt to make it less ambiguous, and add documentation to it as well as cgroup_reclaim. Reported-by: Johannes Weiner Closes: https://lore.kernel.org/lkml/20230405200150.GA35884@cmpxchg.org/ Signed-off-by: Yosry Ahmed Acked-by: Yu Zhao --- mm/vmscan.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index e305c11ec8fc..0dbbf718c53e 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -445,12 +445,17 @@ void reparent_shrinker_deferred(struct mem_cgroup *memcg) mutex_unlock(&shrinker_mutex); } +/* Returns true for reclaim through cgroup limits or cgroup interfaces. */ static bool cgroup_reclaim(struct scan_control *sc) { return sc->target_mem_cgroup; } -static bool global_reclaim(struct scan_control *sc) +/* + * Returns true for reclaim on the root cgroup. This is true for direct + * allocator reclaim and reclaim through cgroup interfaces on the root cgroup. + */ +static bool root_reclaim(struct scan_control *sc) { return !sc->target_mem_cgroup || mem_cgroup_is_root(sc->target_mem_cgroup); } @@ -505,7 +510,7 @@ static bool cgroup_reclaim(struct scan_control *sc) return false; } -static bool global_reclaim(struct scan_control *sc) +static bool root_reclaim(struct scan_control *sc) { return true; } @@ -562,7 +567,7 @@ static void flush_reclaim_state(struct scan_control *sc) * memcg reclaim, to make reporting more accurate and reduce * underestimation, but it's probably not worth the complexity for now. */ - if (current->reclaim_state && global_reclaim(sc)) { + if (current->reclaim_state && root_reclaim(sc)) { sc->nr_reclaimed += current->reclaim_state->reclaimed; current->reclaim_state->reclaimed = 0; } @@ -5339,7 +5344,7 @@ static long get_nr_to_scan(struct lruvec *lruvec, struct scan_control *sc, bool static unsigned long get_nr_to_reclaim(struct scan_control *sc) { /* don't abort memcg reclaim to ensure fairness */ - if (!global_reclaim(sc)) + if (!root_reclaim(sc)) return -1; return max(sc->nr_to_reclaim, compact_gap(sc->order)); @@ -5491,7 +5496,7 @@ static void lru_gen_shrink_lruvec(struct lruvec *lruvec, struct scan_control *sc { struct blk_plug plug; - VM_WARN_ON_ONCE(global_reclaim(sc)); + VM_WARN_ON_ONCE(root_reclaim(sc)); VM_WARN_ON_ONCE(!sc->may_writepage || !sc->may_unmap); lru_add_drain(); @@ -5552,7 +5557,7 @@ static void lru_gen_shrink_node(struct pglist_data *pgdat, struct scan_control * struct blk_plug plug; unsigned long reclaimed = sc->nr_reclaimed; - VM_WARN_ON_ONCE(!global_reclaim(sc)); + VM_WARN_ON_ONCE(!root_reclaim(sc)); /* * Unmapped clean folios are already prioritized. Scanning for more of @@ -6274,7 +6279,7 @@ static void shrink_lruvec(struct lruvec *lruvec, struct scan_control *sc) bool proportional_reclaim; struct blk_plug plug; - if (lru_gen_enabled() && !global_reclaim(sc)) { + if (lru_gen_enabled() && !root_reclaim(sc)) { lru_gen_shrink_lruvec(lruvec, sc); return; } @@ -6515,7 +6520,7 @@ static void shrink_node(pg_data_t *pgdat, struct scan_control *sc) struct lruvec *target_lruvec; bool reclaimable = false; - if (lru_gen_enabled() && global_reclaim(sc)) { + if (lru_gen_enabled() && root_reclaim(sc)) { lru_gen_shrink_node(pgdat, sc); return; }