From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 9865A572682; Thu, 15 Oct 2026 18:15:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1792088156; cv=none; b=Cg1LUAooXAkRiKChgsOg6zwqY8enaLI9bFTvquJC07fOlcsWxw5scyUkN2h6CXfCwqcvaWWlBFOB2SVm3a074JakJgMDA0Ch6Fnw6jFvL4cQyg6CzsaoUYkQYA/bIbdXkNXqW6nSYyTfPpRtNhng3/pOPwwKBhp9v5licvz8rXw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1792088156; c=relaxed/simple; bh=9vYadqVkh4WrhDMsH1jX5lN/XH9JwLR+fwEjQqvXr+8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=tnkL1029knAPoPnZlJzmEXTXGJ18dV7fCIydBk1BC4yIFnjNhkStF+Y8dNMN/+YUbhA+HLdbHJRJQRXr7Zqj8dHloLJyZiSpS4NrVc8ccYum2tKn4yKaW7+ahlnBaHapyuUv+4aF9FLT/93Fyq4p9SJGhK0ofrxZJOibOthGJXk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=M/VSqVM9; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="M/VSqVM9" Received: by smtp.kernel.org (Postfix) with ESMTPS id 76DCAC2BD05; Thu, 15 Oct 2026 18:15:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1792088156; bh=9vYadqVkh4WrhDMsH1jX5lN/XH9JwLR+fwEjQqvXr+8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=M/VSqVM9jJUGAMm2rmzaGRTlfA1KecX+avNavtRyTAfdlsSBYSzUgFtLcsq4XD3aS wU3RIHerSYc+iW5yiW8PxYF4E+++seprkzUMoLXA8hCUq7GBle9n5VW6wY24yxhG+q gteyIE0lOqQYcw6X87lY46GlqqfRSA3DT74VvWOpjCksfA6vqR4uHuEyx4soGNYKZ4 JNkUdGDRr+mFbPMImkog47DofQrw9N2LmqNU43+r5RpvKJp6331Xgq8kX5EgKDqqsj W0V3LUjXEeSDEWXPtMem3RwzrwPbPJ3xaPggetVITO0wHJn9957FMFd20Gz9q96B2M LTvlP1bXbY35g== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 63007CC6B38; Thu, 15 Oct 2026 18:15:56 +0000 (UTC) From: Kairui Song via B4 Relay Date: Fri, 16 Oct 2026 02:16:06 +0800 Subject: [PATCH v4 17/17] Documentation/mm: multi-gen LRU: update for frequency guided promotion Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261016-mglru-fg-v4-17-2106750c0bfa@tencent.com> References: <20261016-mglru-fg-v4-0-2106750c0bfa@tencent.com> In-Reply-To: <20261016-mglru-fg-v4-0-2106750c0bfa@tencent.com> To: linux-mm@kvack.org, "Liam R. Howlett" , SJ Park Cc: Andrew Morton , Johannes Weiner , Muchun Song , Qi Zheng , Ying Huang , Chris Li , Baoquan He , Nico Pache , Usama Arif , Michal Hocko , Roman Gushchin , Shakeel Butt , David Hildenbrand , Lorenzo Stoakes , Barry Song , Axel Rasmussen , Yuanchu Xie , Wei Xu , Vlastimil Babka , Suren Baghdasaryan , Kemeng Shi , Nhat Pham , Youngjun Park , Zi Yan , Gregory Price , "Matthew Wilcox (Oracle)" , Baolin Wang , Ryan Roberts , Dev Jain , Lance Yang , Hugh Dickins , David Rientjes , Yu Zhao , Vernon Yang , Zicheng Wang , Chen Ridong , Tal Zussman , Kairui Song , Xiang Liu , Ehab Ababneh , zhaozhengzhuo , Lian Wang , Kunwu Chan , linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, damon@lists.linux.dev, Kairui Song X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1792088152; l=5953; i=kasong@tencent.com; s=kasong-sign-tencent; h=from:subject:message-id; bh=H9ePyPxQfKEyJG8pjQryA22Bu9URRS7jnmN2RCV298Y=; b=Vb9KmjNNstGoNvaMOwNk7ofyjEq/gP8OVY3K9CwFsX4iWIUxqEgFFz0bvwWvH+Y2p0iByDKlP wZqWyoquQutCr8DLLctzG4RU7bhi8F6VKDcrlaEAi+LHGq3mAiOnAnb X-Developer-Key: i=kasong@tencent.com; a=ed25519; pk=kCdoBuwrYph+KrkJnrr7Sm1pwwhGDdZKcKrqiK8Y1mI= X-Endpoint-Received: by B4 Relay for kasong@tencent.com/kasong-sign-tencent with auth_id=562 X-Original-From: Kairui Song Reply-To: kasong@tencent.com From: Kairui Song The design doc still describes the old tier and promotion model: - Tiers are no longer order_base_2() of the file descriptor accesses. A folio's tier is derived from its referenced count, which counts accesses from both page tables and file descriptors. - A young PTE no longer always promotes a folio to the newest generation. The first access only moves a folio one generation forward if it is at the tail of its LRU, i.e., in one of the two oldest generations of its type, a second access promotes it, and executable file folios are promoted on their first access. - The eviction no longer uses the first tier as the only baseline. The type is selected by comparing all tiers of each type, and a tier is protected by comparing it against the tiers below it. Update the aging and eviction sections accordingly. Assisted-by: LLM Signed-off-by: Kairui Song --- Documentation/mm/multigen_lru.rst | 57 ++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 24 deletions(-) diff --git a/Documentation/mm/multigen_lru.rst b/Documentation/mm/multigen_lru.rst index 52ed5092022f..ec8744c1f42c 100644 --- a/Documentation/mm/multigen_lru.rst +++ b/Documentation/mm/multigen_lru.rst @@ -95,16 +95,19 @@ at most ``MAX_NR_GENS`` generations. The gen counter stores a value within ``[1, MAX_NR_GENS]`` while a page is on one of ``lrugen->folios[]``; otherwise it stores zero. -Each generation is divided into multiple tiers. A page accessed ``N`` -times through file descriptors is in tier ``order_base_2(N)``. Unlike -generations, tiers do not have dedicated ``lrugen->folios[]``. In -contrast to moving across generations, which requires the LRU lock, -moving across tiers only involves atomic operations on -``folio->flags`` and therefore has a negligible cost. A feedback loop -modeled after the PID controller monitors refaults over all the tiers -from anon and file types and decides which tiers from which types to -evict or protect. The desired effect is to balance refault percentages -between anon and file types proportional to the swappiness level. +Each generation is divided into multiple tiers. A page's tier is +derived from its referenced count, which counts the accesses collected +from both channels above and is capped at ``LRU_REFS_MAX``: pages +accessed at most once are in the lowest tier, and the tiers above hold +pages accessed at least twice. Unlike generations, tiers do not have +dedicated ``lrugen->folios[]``. In contrast to moving across +generations, which requires the LRU lock, updating the referenced +count only involves atomic operations on ``folio->flags`` and +therefore has a negligible cost. A feedback loop modeled after the PID +controller monitors refaults over all the tiers from anon and file +types and decides which tiers from which types to evict or protect. +The desired effect is to balance refault percentages between anon and +file types proportional to the swappiness level. There are two conceptually independent procedures: the aging and the eviction. They form a closed-loop system, i.e., the page reclaim. @@ -122,25 +125,31 @@ and calls ``walk_page_range()`` with each ``mm_struct`` on this list to scan PTEs, and after each iteration, it increments ``max_seq``. For the latter, when the eviction walks the rmap and finds a young PTE, the aging scans the adjacent PTEs. For both, on finding a young PTE, -the aging clears the accessed bit and updates the gen counter of the -page mapped by this PTE to ``(max_seq%MAX_NR_GENS)+1``. +the aging clears the accessed bit and bumps the referenced count of +the page mapped by this PTE. A second access promotes the page by +updating its gen counter to ``(max_seq%MAX_NR_GENS)+1``; the first +access only moves a page one generation forward if it is at the tail +of its LRU, i.e., in one of the two oldest generations of its type, +so that the next time it becomes the oldest one, its accessed bit +reflects whether it has been used again. Executable file pages are +promoted on their first access, since reclaiming them causes typical +I/O thrashing. Eviction -------- The eviction consumes old generations. Given an ``lruvec``, it increments ``min_seq`` when ``lrugen->folios[]`` indexed by -``min_seq%MAX_NR_GENS`` becomes empty. To select a type and a tier to -evict from, it first compares ``min_seq[]`` to select the older type. -If both types are equally old, it selects the one whose first tier has -a lower refault percentage. The first tier contains single-use -unmapped clean pages, which are the best bet. The eviction sorts a -page according to its gen counter if the aging has found this page -accessed through page tables and updated its gen counter. It also -moves a page to the next generation, i.e., ``min_seq+1``, if this page -was accessed multiple times through file descriptors and the feedback -loop has detected outlying refaults from the tier this page is in. To -this end, the feedback loop uses the first tier as the baseline, for -the reason stated earlier. +``min_seq%MAX_NR_GENS`` becomes empty. To select a type to evict from, +it first compares ``min_seq[]`` to select the older type. If both +types are equally old, it compares the refault percentages of all the +tiers of each type proportional to the swappiness level. To select a +tier to protect, it compares the refault percentage of each tier +against that of the tiers below it. The lowest tier contains pages +accessed at most once, which are the best bet. The eviction sorts a +page according to its gen counter if the aging or an access has +updated its gen counter. It also moves a page to the next generation, +i.e., ``min_seq+1``, if the feedback loop has detected outlying +refaults from the tier this page is in. Working set protection ---------------------- -- 2.56.0