From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794342103; b=QuV84mnOs+ScdErU8K6oCPrCplSa3Vpe5VbdGR0i5hRN5zQ3LwXodRdyyTUFMpb6lqF2 D0LQ7bqjH2VOE3Y0oNYWZdoLLi7TKHH5Pmhtao0XkWU9+FSO3EPY+tCH4wt1+SyVhw9+r vUubs0Bh1DXBGJ8Hhu/GX05mdQ/nQ9p0jTEv0Vi+iMFiKKki8cpi/MDwzvammVCF7YQ3o b4KaOPQCPexRJxS5qlRzY1+VfRFrGQhVtGJW8rsRJKl4p+wnivzXmRwkmNB4maxA+ruE7 +MWMezWXXEkVbjgxdJOtC4ITm49JbHez8/Qsdw/B/BWq2SNCt4VttykRtqAFSJG24GQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794342103; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-Id:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=Mj38FmKYhvqiRaBM262V/Sxj/aA72yBpxP9txaZ0CNM=; b=yEk1M3qAO8lgSVed6C9Wp45wENpkCXHAxEvmkJ9eWhu3Q9SEUXc94adwQGf0G/Xz9gx3 V7ObqXLRY8n8Wd+kiQNP4KmU95Dc1FvRUhbmX/CdhRgPHdlgHjjFqUk3SIPQuX1YcOpeS +U6MbfZhIc3UgIRNYbEe8gSAc815F8gLfDIFxKcmsNo6Q/TQnlGy9ob6Yzit03nPHLi15 5rMaLnn/05LD6Hw9rAw7ipKsyE0bDI1V3ilUen0kbYhERbBM+UGdfS0W4pg6x48mUIxjT +aR3BuFE1Npae5QYK5y7FXYK97kpkHWIDl16rCWHKDq5FF2oBP1U1fJVLPv8uAIk1Dw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=bbrug8Xl; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C4CDE606A32A for ; Tue, 10 Nov 2026 20:21:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=bbrug8Xl Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8CD871F0089F; Tue, 10 Nov 2026 20:21:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794342102; bh=Mj38FmKYhvqiRaBM262V/Sxj/aA72yBpxP9txaZ0CNM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=bbrug8Xlpt4l/RuemKutlMDaV4lVQoYOYwHxPJAfFCtKTNR+7sZDRH78wm8x2QRfF fTlMidfAt9Ru6P/It5lcSjGVfZZ0rE5/Y/adp8qvAtpFcNaYS01vHyalxU34rIKlHF zHRsRE/BqJKpaCFEMJAlUk36Im4YSqxnZIqWHX6jhgDyGscBnipb9ZAgB2DxigiE8b Q1DIKGDVQ1+FanO0tF7JyaxWN2W9Xc753KVpp+6vpU+QC1rZ8rPDguma1zU/tBy6Da 96bzBjJThDxQp3rQlIUjjFPJzCQM+V0MYF8oyGjauz5zcMjGGjn3U6QTmbcDLi/z6b 1YooYkBpK+d7Q== From: "Barry Song (Xiaomi)" To: akpm@linux-foundation.org, linux-mm@kvack.org Cc: axelrasmussen@google.com, baolin.wang@linux.alibaba.com, baoquan.he@linux.dev, hannes@cmpxchg.org, hui.zhu@linux.dev, kasong@tencent.com, kunwu.chan@gmail.com, liam@infradead.org, lianux.mm@gmail.com, linux-kernel@vger.kernel.org, liuxiang.277@bytedance.com, lyugaofei@xiaomi.com, mhocko@kernel.org, mhocko@suse.com, qi.zheng@linux.dev, ridong.chen@linux.dev, rppt@kernel.org, ryncsn@gmail.com, shakeel.butt@linux.dev, surenb@google.com, wangzicheng@honor.com, weixugc@google.com, yuanchu@google.com, zhangbo56@xiaomi.com, zhuhui@kylinos.cn, sidchintamaneni@gmail.com, Barry Song Subject: [PATCH v6 13/15] mm/mglru: Avoid prolonged anon reclaim with swappiness=200 Date: Wed, 11 Nov 2026 04:20:23 +0800 Message-Id: <20261110202025.25736-14-baohua@kernel.org> X-Mailer: git-send-email 2.39.3 (Apple Git-146) In-Reply-To: <20261110202025.25736-1-baohua@kernel.org> References: <20261110202025.25736-1-baohua@kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: lyugaofei It has been observed that swappiness=200 can significantly slow down reclaim on some machines, with some workloads running 3x slower under MGLRU than under CLRU. This is because swappiness=200 currently results in file_factor=0. Give file reclaim a small factor at lower priorities, for example, when sc->priority < DEF_PRIORITY / 2. Signed-off-by: lyugaofei Co-developed-by: Barry Song (Xiaomi) Signed-off-by: Barry Song (Xiaomi) --- mm/vmscan.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 34faabe617ae..5d6fc5d4d761 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -4888,8 +4888,8 @@ static int get_tier_idx(struct lruvec *lruvec, int type) * We don't calculate the scan cost, MGLRU uses lazy promotion, which will * cancel the scan budget natually. */ -static void lru_gen_balance_scan(struct lruvec *lruvec, int swappiness, - unsigned long total_scan, unsigned long nr[]) +static void lru_gen_balance_scan(struct lruvec *lruvec, struct scan_control *sc, + int swappiness, unsigned long total_scan, unsigned long nr[]) { struct lru_gen_folio *lrugen = &lruvec->lrugen; u64 refault_rate[ANON_AND_FILE], anon_factor, file_factor; @@ -4946,7 +4946,12 @@ static void lru_gen_balance_scan(struct lruvec *lruvec, int swappiness, file_weight = nr[LRU_GEN_FILE] + nr[LRU_GEN_ANON] / size_bias; anon_factor = (u64)swappiness * refault_rate[LRU_GEN_FILE] * anon_weight; - file_factor = (u64)(MAX_SWAPPINESS - swappiness) * refault_rate[LRU_GEN_ANON] * file_weight; + if (swappiness == MAX_SWAPPINESS) + file_factor = sc->priority < DEF_PRIORITY / 2 ? + refault_rate[LRU_GEN_ANON] * file_weight : 0; + else + file_factor = (u64)(MAX_SWAPPINESS - swappiness) * + refault_rate[LRU_GEN_ANON] * file_weight; /* Cross-multiply the ratio above. */ anon_scan = mul_u64_u64_div_u64(total_scan, anon_factor, anon_factor + file_factor); @@ -5137,7 +5142,7 @@ static void lru_gen_prepare_scan(struct lruvec *lruvec, struct scan_control *sc, total = apply_proportional_protection(memcg, sc, total); total >>= sc->priority; - lru_gen_balance_scan(lruvec, swappiness, total, nr_to_scan); + lru_gen_balance_scan(lruvec, sc, swappiness, total, nr_to_scan); } static bool should_abort_scan(struct lruvec *lruvec, struct scan_control *sc) @@ -5880,7 +5885,7 @@ static int run_eviction(struct lruvec *lruvec, unsigned long seq, struct scan_co return 0; lruvec_evictable_size(lruvec, swappiness, nr_to_scan); - lru_gen_balance_scan(lruvec, swappiness, + lru_gen_balance_scan(lruvec, sc, swappiness, nr_to_reclaim - sc->nr_reclaimed, nr_to_scan); if (!evict_folio_lists(nr_to_scan, lruvec, sc, swappiness, MAX_LRU_BATCH)) -- 2.34.1