From patchwork Wed Feb 14 06:05:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kinsey Ho X-Patchwork-Id: 200816 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp1014948dyb; Tue, 13 Feb 2024 22:07:41 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVqDR2dVEJGAe5h4UAGehpO3bf8X0d/aBzkWuH6HCAx2z9MD+bNzYlzc/Y4S0Z4rI4wpsk8Zwh/dovbb5XhlSpP1t4k4Q== X-Google-Smtp-Source: AGHT+IFM+SK2BFaCP/++PFrHV6rD/QcjeYmfEPfKwyLueAb50YTy9D5PQdtzoF4g1PA7lqR53aSQ X-Received: by 2002:a17:903:41c5:b0:1db:3076:21e3 with SMTP id u5-20020a17090341c500b001db307621e3mr1754147ple.56.1707890860917; Tue, 13 Feb 2024 22:07:40 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707890860; cv=pass; d=google.com; s=arc-20160816; b=FV6czLH6Kn18YY/oVuIgkHL5pY8lddYFWhCPr6w5anjSGG0vOdGHoeyv4VK5onu9ll uqYcPI5k+I3RGf+lud1H72piEB12wT9gr6Q6DCujvqOdqBWA6itagA+mhz5Cu4B/3g+Y 4pLB98WYLxFrgS6/x8X/tNgNAhixo2S+cFpBRsCkB53+CIxQ1y4jnBX05kQSo4ge1epb G7/yvw3L5NYJhpVmzU5AKkIEGMo2LMzt2sDnMAQ046Cb51cjWboDb9CvSmRBKfMe62TM +CyFfs50QBt3FUZY1cFasNoXXQ9ORTcpl4vR+CQDLQ2hN26Pp/2fK7bTa+N5mRndWx2P R7Dw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=oan+94DZASviMy6e/v6AGJHUkNS1XGpMmnaov86Qm34=; fh=0uSBxL8/6kIhGrBc0gG4QHguPOxD09PnVa4rpE7CvAU=; b=fu/2UoMVs9bnUp3BPTrXT8r3wYXcGW9XiRFuoyUvB6EJGF1bYNskqodyVrgpPpgOf8 RctLqLKbWhxp+eQoDii/Rlays8c7yC70DBHQAclHr/GbwkvwsqgMOA3wiQVTGKX4Zbpi rqeuX8kgNLpKCsQyk5DV+Iw9pmebIP2hvmlZEkCQ4rg/56ik0MxgnZC+YhFHNmB21JzG jQDD4UXCLoLQjULhGzIWq6B5p1T3zswEzcGJYtVmQ5GJmn5NKBaSmn8YFWGy3suAyBZ6 q8ATXG6oABRgIJUdTeYAGm+DDdoHi3w4C+Bc81yNO4HC8o+BRPQOWlhZxQvJhfY0NXcy bn4Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=KnlYhY3Q; arc=pass (i=1 spf=pass spfdomain=flex--kinseyho.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-64768-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64768-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=2; AJvYcCULyNBTXhx1dCGy+L9IgaHAfoit8kwpumM7yy8qveFE+OcQDvqn60C01UQg2OrJZdogBKpWjZf3erjDbIvcwh/hEG6UiA== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id w4-20020a170902d3c400b001db5079b71csi1138264plb.598.2024.02.13.22.07.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 22:07:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-64768-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=KnlYhY3Q; arc=pass (i=1 spf=pass spfdomain=flex--kinseyho.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-64768-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64768-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 72A0D28E1CF for ; Wed, 14 Feb 2024 06:06:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7F838125CF; Wed, 14 Feb 2024 06:06:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="KnlYhY3Q" Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3BAE3111BE for ; Wed, 14 Feb 2024 06:06:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707890763; cv=none; b=QWoReFhF6HxtyXWduIwTEYKOw/e6FUti8zfEVHEWqGl5z/jZBiqQ5ptbBiZmUhntRHumWe/j8pY9fsh93k9genng/PfgVyw2HDYzpXvHw+p8/nDzC68PeIMEntV8SgCkamUNZ1VpcKsO/7Lq6kI/FFSWesXV0FOsuFBGfuzm6tg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707890763; c=relaxed/simple; bh=T/QGXqkR1FvOAuC5zznScAzCN6HFAcM6dUi3a9AX+sw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=TP0aqG/aKi3LlPcOo3UhZMIEth/k+I8VCUOZElHWjfAC+3NNhUBvBI9xLNGmjgfEGlXgv2lRSdGgpGt6wT833W52eZBB98YA/CRva/cLJ7vJ1A3AwkWCeyVtJnmqXYvRoyFT/wpFUdl+8F5aeObl9p0aEzb+uO5jlfJnX4rdBRc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--kinseyho.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=KnlYhY3Q; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--kinseyho.bounces.google.com Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dc3645a6790so9467916276.0 for ; Tue, 13 Feb 2024 22:06:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1707890761; x=1708495561; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=oan+94DZASviMy6e/v6AGJHUkNS1XGpMmnaov86Qm34=; b=KnlYhY3QcWeDvbOKhL5WnPWBsWV4a1i7L6Tjo4XmvoRndsskAZf39tTyPeH5mPyld8 kRVU3z2ep1UTdv75VhPCpF6XmXC2puL94HcV5Bc5VULB3W70tjOW0uIF4zjgWcFA7GA8 oX7vpYtW/Ix02MIqRdJwEdQ2hz/S8geSp0hStnNjCglnazEiItuiahkZqweuhbkAsR4L FGelscy0th2vaDlTKhN2WsJdUc+Ba8R4O8M2t5cTUpZqPD1Gz6JKXoG0kehPhP5624Jq CG87dOOmxPCVRI6owehaXr91E9VABYun0xs1AnERSWBTlqWXeRPPd565e9RCQ96Hr3w+ qtag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707890761; x=1708495561; 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=oan+94DZASviMy6e/v6AGJHUkNS1XGpMmnaov86Qm34=; b=FxOdf8GdQTiP33+VzyF4I54cqnCN1H6TPS/RtZXhvhssS7RnUxUsrtsD3yEiMhb3+s X64j8XXJkeZ5aZWYBU6ncov8VPv8nnjqM+zz6fAep+jvAea/no3QzzGDB2EfkRyWGcJH Jh88AYl/TD3ke3clWCj5uJnoPNP/JE4fEFyvx8DWeall+2Q4D0VAlRZM5/dXGP9qYUuL n6cjpQGshKRRIZ5Jo937/C3FKydVAkwX+mJme+98Z1J0HrqlTjwapf6dTshruNkZK8Yp yuZpCP6EjefFSMxXgFzil2lYbcVBV7PX++wegciYg8TvW42UURPGQ9GjVSyPTmZknq90 hi5g== X-Forwarded-Encrypted: i=1; AJvYcCUl93Yyo2PPdGJZspcO6uFjfpyV9SGD71NReKUyxLXKR66jT+f4e6TY3t5aGTvo4yOCzReDLxwQbXhyfjTE4U4tPX9Vh66CgoZqepx6 X-Gm-Message-State: AOJu0Yw6/XSmE3SzE4o7iYiNoFfpRiIW1SN+LvlofHDJLhLjiLV+i/pK lmZJvyr0FkMHf60x6+0zZWzjy0kuBBwR+9Djti7QZDzvXvYuAVZuroRp8sknUypBK1kk4N3CFIE Rt3NXAJgJSw== X-Received: from kinseyct.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:46b]) (user=kinseyho job=sendgmr) by 2002:a25:698d:0:b0:dca:33b8:38d7 with SMTP id e135-20020a25698d000000b00dca33b838d7mr320126ybc.11.1707890761264; Tue, 13 Feb 2024 22:06:01 -0800 (PST) Date: Wed, 14 Feb 2024 06:05:35 +0000 In-Reply-To: <20240214060538.3524462-1-kinseyho@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240214060538.3524462-1-kinseyho@google.com> X-Mailer: git-send-email 2.43.0.687.g38aa6559b0-goog Message-ID: <20240214060538.3524462-3-kinseyho@google.com> Subject: [PATCH mm-unstable v1 2/5] mm/mglru: improve should_run_aging() From: Kinsey Ho To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Yu Zhao , Donet Tom , "Aneesh Kumar K . V" , Kinsey Ho X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790853367374984942 X-GMAIL-MSGID: 1790853367374984942 scan_control *sc does not need to be passed into should_run_aging(), as it provides only the reclaim priority. This can be moved to get_nr_to_scan(). Refactor should_run_aging() and get_nr_to_scan() to improve code readability. No functional changes. Signed-off-by: Kinsey Ho --- mm/vmscan.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 9d15648561ec..87de39e7410b 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -4602,14 +4602,13 @@ static int evict_folios(struct lruvec *lruvec, struct scan_control *sc, int swap } static bool should_run_aging(struct lruvec *lruvec, unsigned long max_seq, - struct scan_control *sc, bool can_swap, unsigned long *nr_to_scan) + bool can_swap, unsigned long *nr_to_scan) { int gen, type, zone; unsigned long old = 0; unsigned long young = 0; unsigned long total = 0; struct lru_gen_folio *lrugen = &lruvec->lrugen; - struct mem_cgroup *memcg = lruvec_memcg(lruvec); DEFINE_MIN_SEQ(lruvec); /* whether this lruvec is completely out of cold folios */ @@ -4637,13 +4636,7 @@ static bool should_run_aging(struct lruvec *lruvec, unsigned long max_seq, } } - /* try to scrape all its memory if this memcg was deleted */ - if (!mem_cgroup_online(memcg)) { - *nr_to_scan = total; - return false; - } - - *nr_to_scan = total >> sc->priority; + *nr_to_scan = total; /* * The aging tries to be lazy to reduce the overhead, while the eviction @@ -4675,6 +4668,7 @@ static bool should_run_aging(struct lruvec *lruvec, unsigned long max_seq, */ static long get_nr_to_scan(struct lruvec *lruvec, struct scan_control *sc, bool can_swap) { + bool success; unsigned long nr_to_scan; struct mem_cgroup *memcg = lruvec_memcg(lruvec); DEFINE_MAX_SEQ(lruvec); @@ -4682,14 +4676,17 @@ static long get_nr_to_scan(struct lruvec *lruvec, struct scan_control *sc, bool if (mem_cgroup_below_min(sc->target_mem_cgroup, memcg)) return -1; - if (!should_run_aging(lruvec, max_seq, sc, can_swap, &nr_to_scan)) - return nr_to_scan; + success = should_run_aging(lruvec, max_seq, can_swap, &nr_to_scan); - /* skip the aging path at the default priority */ - if (sc->priority == DEF_PRIORITY) + /* try to scrape all its memory if this memcg was deleted */ + if (nr_to_scan && !mem_cgroup_online(memcg)) return nr_to_scan; - /* skip this lruvec as it's low on cold folios */ + /* try to get away with not aging at the default priority */ + if (!success || sc->priority == DEF_PRIORITY) + return nr_to_scan >> sc->priority; + + /* stop scanning this lruvec as it's low on cold folios */ return try_to_inc_max_seq(lruvec, max_seq, can_swap, false) ? -1 : 0; }