From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8773A444708 for ; Wed, 12 Aug 2026 12:19:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786537147; cv=none; b=esfwIdH0tQV9mnN5X2H0GkPRCTwMh3NloN+RjCQTGD+XwP9ADwvXdwWBX4JL9nVUqb1XMcu/+nWhj17eLB4tKhemWqkCMo9PB7zwoUyIrI4P1nMtgnIx/Gp8TTygOSC8rk04Mz2XllD/DHoVwslmgb1m3kZrY2eAeWLaTEWLKsc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786537147; c=relaxed/simple; bh=FUdDUnzXr+2z6a3eQ4V+h/9C27f/kTZTPh0P8QioeeI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=AwgPHdLWPphCFQXL0L/K13S13a7Mn+QNezSHgiEKq8Q0vjtLoCeL3pxIJf2zU50RZ7Z4G4N3FSvEh/rDJ6SKrlNZE9TJGDtc5gV8Ay4XYvyX7F+RhELXvaEXhHnd/syEn3rNeQefcjbYI+TEqHR1L9X5pGJYPkJpChIBvzawJyY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=njo3WFSy; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="njo3WFSy" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BDE751F000E9; Wed, 12 Aug 2026 12:19:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1786537144; bh=3bXsQJXJBgnmO/j5UVCnEEv0tpGrhoZfdxf5g4cVqXw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=njo3WFSyGDaScgvd6IJHBjqnoSSXc8eHsmqYVtIT+z+kGiY32zHCIHLG1dZdKTzkf WsZF140sZ7HXeZZVQtvkV1HLI/EkPJ83p2zLnENNBOMKYNJoq55pjYH7TDSVkmlZlj Tl0wAonC52TwGwAIy/4hFNR0O554QLM2aGdnQcYe81OocBi8AUfRlATAaXVym5qxFs OgaCK6kKvE4kxmUDINcInx3KnAkZF79yEGzDsgTzFDKJhmUlJkdQShEcuwmFoGe0Bm BM8Ry2v+SmHs/ttJbHE6zToz9DjNEnXqjJ4Ze8a8gAp0gG0om5TAHkDywVs5qapZ3X YKB018bfePxyw== From: "Barry Song (Xiaomi)" To: akpm@linux-foundation.org, linux-mm@kvack.org Cc: axelrasmussen@google.com, chenridong@xiaomi.com, david@kernel.org, hannes@cmpxchg.org, kasong@tencent.com, lianux.mm@gmail.com, linux-kernel@vger.kernel.org, ljs@kernel.org, lyugaofei@xiaomi.com, mhocko@kernel.org, qi.zheng@linux.dev, shakeel.butt@linux.dev, stevensd@chromium.org, wangzicheng@honor.com, weixugc@google.com, yuanchu@google.com, zhangbo56@xiaomi.com, baolin.wang@linux.alibaba.com, baoquan.he@linux.dev, "Barry Song (Xiaomi)" Subject: [RFC PATCH v4 15/16] mm/mglru: dynamically scale aging threshold in lru_gen_imbalanced() Date: Wed, 12 Aug 2026 20:16:57 +0800 Message-Id: <20260812121658.69965-16-baohua@kernel.org> X-Mailer: git-send-email 2.39.3 (Apple Git-146) In-Reply-To: <20260812121658.69965-1-baohua@kernel.org> References: <20260812121658.69965-1-baohua@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Currently, lru_gen_imbalanced() uses a fixed threshold (MAX_NR_GENS) to determine whether the young-to-old folio ratio warrants aging the preferred LRU type. This fixed threshold may not scale well with large memory systems. Borrow the adaptive ratio calculation from inactive_is_low() by scaling the threshold with the square root of the memory size in GB. Suggested-by: Zicheng Wang Signed-off-by: Barry Song (Xiaomi) --- mm/vmscan.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index d6fac5b91ac1..c0350a8b61d1 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -5105,6 +5105,7 @@ static bool lru_gen_imbalanced(struct lruvec *lruvec, unsigned long max_seq, { struct lru_gen_folio *lrugen = &lruvec->lrugen; unsigned long young = 0, old = 0, lag = 0; + unsigned long inactive_ratio, gb; DEFINE_MIN_SEQ(lruvec); /* we still have enough generations to reclaim */ @@ -5127,7 +5128,13 @@ static bool lru_gen_imbalanced(struct lruvec *lruvec, unsigned long max_seq, if (min_seq[!type] + MAX_NR_GENS == max_seq + 1) lag += lruvec_gen_size(lrugen, !type, min_seq[!type]); - return young > old * MAX_NR_GENS && (lag < MAX_LRU_BATCH || + /* + * Borrow the adaptive ratio from inactive_is_low(), and scale + * it by sqrt(MAX_NR_GENS) to make aging less aggressive + */ + gb = (young + old) >> (30 - PAGE_SHIFT); + inactive_ratio = gb ? int_sqrt(10 * gb * MAX_NR_GENS) : MAX_NR_GENS; + return young > old * inactive_ratio && (lag < MAX_LRU_BATCH || (is_extreme_swappiness(swappiness) && sc->priority > 2)); } -- 2.34.1