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 1EC3C2931D2 for ; Sun, 26 Jul 2026 01:29:52 +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=1785029394; cv=none; b=GRF8Y5/zkhn8TOd1GXsgOycACoLVnu4dqOTpv9WrQ/CH9XI5h9sA+pMO1Vmf1P6AUYlhmTkzrvovmNHXifdAeCMng3KiMmdmVOaqkNscqxWKnRloxtA1kdq6LR32qXSF+r2lP+kQ/q1EwsDwL626a12f8IlhBQYKubUKGA4bVTk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785029394; c=relaxed/simple; bh=TOxmNib5sriH7jrBSl5Hnq4hY0TrtVAi+M7P4h+SdnI=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=Wg0HJ4rmEYH2gOwV2uxaKTmz4ZOmmUi4ywP0ZEv0ggPE45g2v1bVOUVTpqlhYzp8rGJ92fT3VyMvZt4XpI4f85DWn7OrNfrfebzagsS9nSY0ffxd0bO7CsKU1ndAf/sNz7lSXFmZVGOAPdJCu1u7WKZ/IhQv5AoeajcW9wKwHvI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=dHNgdxP2; 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="dHNgdxP2" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 063011F000E9; Sun, 26 Jul 2026 01:29:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1785029392; bh=O9tElxXqoXPZ1eIrYOOiaQHWsLrWbEbHR+ywtN4lvFs=; h=From:To:Cc:Subject:Date; b=dHNgdxP2I0ZswobmOIljQLxhmqG4928d1j9qeY00/7PHWy4bhIWrDfaGF8iTpWCEI gQpC6uqinbbkqeqEv8aciM7NboEQbtBJNgnjxOML7RE1bqFsjCmXgox208txo28dKc VnSaOvHpg4CqhGOIJQBcnql9ck00zS8YiHEoopSEpbXU+lnj9P6SRYcixQ0BhW0UG2 fRTen0JMHFYoFyR1qN9kQks5h57eKHZZwlOAcVUxbfT+uMjYxDaWnvkd2yzfhbq6kW 5k1dqo2UaCZhK0RkMgcaLraTuB1X0jaFasYX0lJv8xokz1XIxrrsBfNafOQyrnSysh yurfYBY4DKfpg== From: "Barry Song (Xiaomi)" To: akpm@linux-foundation.org, linux-mm@kvack.org Cc: hannes@cmpxchg.org, david@kernel.org, mhocko@kernel.org, qi.zheng@linux.dev, shakeel.butt@linux.dev, ljs@kernel.org, kasong@tencent.com, axelrasmussen@google.com, yuanchu@google.com, weixugc@google.com, linux-kernel@vger.kernel.org, lyugaofei@xiaomi.com, stevensd@chromium.org, "Barry Song (Xiaomi)" Subject: [RFC PATCH 0/4] mm: mglru: fix swappiness behavior Date: Sun, 26 Jul 2026 09:29:42 +0800 Message-Id: <20260726012946.18684-1-baohua@kernel.org> X-Mailer: git-send-email 2.39.3 (Apple Git-146) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The active/inactive LRU respects swappiness well. Anonymous page scanning and reclamation increase roughly linearly with swappiness, while file page scanning and reclamation decrease accordingly. For example, when swappiness reaches 200, both pgsteal_file and pgscan_file drop to zero while building the kernel in a 1 GB memcg. In contrast, MGLRU shows almost no change across different swappiness values. pgsteal_file Swappiness LRU MGLRU -------------------------------- 1 10567455 763612 36 990706 480205 71 688170 415848 106 446294 386164 141 286307 359196 176 201733 351686 200 0 330093 pgsteal_anon Swappiness LRU MGLRU -------------------------------- 1 4410548 2726362 36 2465268 2762859 71 2677908 2885124 106 2737227 2841796 141 2984276 3035015 176 3381338 2938302 200 13116359 3113499 pgscan_file Swappiness LRU MGLRU -------------------------------- 1 17997223 923094 36 1325674 539571 71 852345 464222 106 538207 464477 141 357253 412277 176 217536 399446 200 0 375902 pgscan_anon Swappiness LRU MGLRU -------------------------------- 1 31639423 5987136 36 23441521 5753224 71 26067110 6101780 106 25619448 5782919 141 26842088 6234264 176 29200021 5980292 200 62193924 6413125 This patchset respects the type selected by positive_ctrl_err(), which uses swappiness as its gain. It does so by: 1. Avoiding premature fallback to the other type. Only fall back when reclaim is running at high priority. 2. Running aging when the preferred type has few or no reclaimable folios, so more folios of that type become reclaimable. With this patchset, swappiness starts to behave similarly to the active/inactive LRU. pgsteal_file Swappiness LRU MGLRU MGLRU+Patch ------------------------------------------------- 1 10567455 763612 3507619 36 990706 480205 528781 71 688170 415848 478478 106 446294 386164 411632 141 286307 359196 375137 176 201733 351686 298586 200 0 330093 0 pgsteal_anon Swappiness LRU MGLRU MGLRU+Patch ------------------------------------------------- 1 4410548 2726362 2876888 36 2465268 2762859 3022062 71 2677908 2885124 3129555 106 2737227 2841796 2974192 141 2984276 3035015 3092280 176 3381338 2938302 3353395 200 13116359 3113499 14348518 pgscan_file Swappiness LRU MGLRU MGLRU+Patch ------------------------------------------------- 1 17997223 923094 5842416 36 1325674 539571 648111 71 852345 464222 569930 106 538207 464477 480767 141 357253 412277 431911 176 217536 399446 337768 200 0 375902 0 pgscan_anon Swappiness LRU MGLRU MGLRU+Patch ------------------------------------------------- 1 31639423 5987136 4658593 36 23441521 5753224 5444726 71 26067110 6101780 5755804 106 25619448 5782919 5872415 141 26842088 6234264 6144096 176 29200021 5980292 6615500 200 62193924 6413125 22984986 Another possible approach is to decouple anonymous and file-backed aging by maintaining separate max_seq values for each type. This allows anonymous and file-backed memory to age and be reclaimed independently, enabling the swappiness-preferred type to be reclaimed more aggressively while allowing the other type to lag behind. This approach has already been adopted by projects such as CachyOS [1] and Chromium [2]. However, this approach requires substantial changes to MGLRU and fundamentally alters its design by breaking the shared aging timeline between anonymous and file-backed memory. This timeline is the foundation for mechanisms such as the PID controller and the min_ttl_ms thrashing protection. That is why this patchset aims to fix the swappiness behavior without fundamentally changing MGLRU's design, with minimal changes. [1] https://github.com/firelzrd/re-swappiness [2] https://chromium.googlesource.com/chromiumos/third_party/kernel/+log/929932351492d01f0aee37a0ac3be8c7bd88f80d Barry Song (Xiaomi) (3): mm: mglru: only fall back when reclaim is running at high priority mm: mglru: do try_to_inc_min_seq if scanned==0 mm: mglru: run aging if the preferred type has no folios in reclaimable gens lyugaofei (1): mm: mglru: run aging when pages are severely imbalanced across gens mm/vmscan.c | 46 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) -- 2.39.3 (Apple Git-146)