From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7F6E3606A335 for ; Fri, 4 Dec 2026 16:13:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=kUvtYqUx Received: by kanga.kvack.org (Postfix) id 9B2946B05B5; Fri, 4 Dec 2026 11:13:34 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 98A626B05B8; Fri, 4 Dec 2026 11:13:34 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 879076B05BB; Fri, 4 Dec 2026 11:13:34 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 628906B05B5 for ; Fri, 4 Dec 2026 11:13:34 -0500 (EST) Received: from smtpin03.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay10.hostedemail.com (Postfix) with ESMTP id E367DC03F7 for ; Fri, 4 Dec 2026 16:13:33 +0000 (UTC) X-FDA: 85506795906.03.F64E205 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) by imf21.hostedemail.com (Postfix) with ESMTP id 1725B1C000F for ; Fri, 4 Dec 2026 16:13:31 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=gmail.com header.s=20260707 header.b=kUvtYqUx; spf=pass (imf21.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.214.171 as permitted sender) smtp.mailfrom=ryncsn@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796400812; b=VT0kGMJyqcnAjK6rG2Ymut3XqUGxnjrVbf3KtIxdJRBdEhiso4OwZKLUQ8egi+6FNXqEAO N92rQZ9I1xFx3eNSc9uZKCXX08gbHDGctjZwTjtXoKXb34g6w0mgBfmMJ5J2Pk7sohi6sE jtywgdUnqmU7asz3rIk0PUyLzHWvol0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796400812; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=9ua6fwJ47fOKogabvIv9AllBzm/KgF3KZ5fyyeUxj84=; b=xsRYKa0O/8+O2tNfBzog3JT92dJosoKeFnS341RhtEIAcS+TsP0X1JHVF6PtiNE1AyAaPt F7PWDuAjapQHdXj9PWC5n840jSijTsrDfBkoOX5t0D3Qd4fmDaOY7mC+wGVlHgXIuxWf8q agfHBAXQPqmLXB7i8UzkqSDHZs7Q5UI= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=gmail.com header.s=20260707 header.b=kUvtYqUx; spf=pass (imf21.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.214.171 as permitted sender) smtp.mailfrom=ryncsn@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-2f041f88577so7789775ad.1 for ; Fri, 04 Dec 2026 08:13:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796400811; x=1797005611; darn=kvack.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=9ua6fwJ47fOKogabvIv9AllBzm/KgF3KZ5fyyeUxj84=; b=kUvtYqUx0lSk3nhtyumjhUsMPXVSWog+e8B+9K2fBK/iATRvuxYPNp91GYuq1NbSOn wfjH++++Sg7oIhHw8yRHQVeLk1BY6QG7wOt3/oTGWA0788XL8rnoCtvCM7CnYnDGdN9v cKxrNkJ8Gmb8lTQLJDJFMtNbKZxtI7nuHXBCdvOtBKTnoQEsegL9zwmCtI3KsrH9PN8Y 9+M/KetTj+qzQAUYn/Iel6j15CU5tfGKV6qFkuMHD572oRIJ+9cHuyUXfjZWqF9FYnJl EhTNkqbvhXdcMJZzGa3TIck41eo4iQBso09xvTf+lS8Up86AQjqb1ewqdf3EZ6pDxtNN 6vxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796400811; x=1797005611; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=9ua6fwJ47fOKogabvIv9AllBzm/KgF3KZ5fyyeUxj84=; b=2BfPAId0l5PbASScE2PsHuSIBlvdgox/WA6ghB447jWzNa8rwv8ph+ptd5b3GfIIOs zleHNqx1DioJQgMh52C00tTu637NqvI6+89rw15auW4D3fotSSiGXsy42XoxHNfq3zwC T2XiWVpIM7MGgcwhaSISlJNnuAlU3+XCp0QkE/VoCLhdhRfhmPNpP1gi/LYBwb3ZsKVE 8EfNFbWEiOlA4F6B4KZz/ee02z3vgQWeAg4a+q7i7GnWD+Cnd496TMe7brPACsEYYE/G X4/BEQb/9i5BthPK9H1p1clQpUN2QpBDxGZXPl8Ixuq1///FarjIU0dtSpLjt4SeDc00 /zEQ== X-Forwarded-Encrypted: i=1; AL+hErEmbanrfStpJAad/L6pJgYrBX/l+vnEMSYQoo6e4KF741Y6lUvQIWXuzlsT6So39TItcZWG5DdBvw==@kvack.org X-Gm-Message-State: AB4q+uF7vDTe7O01SpRjNVxT0/t6HY+2ZCBz7lzOvr3C/+WDSCPxD4y5 O5Qn8E/3MLFYlrqX/6yW8OO+JingyH2VNzWmywj7XCeRKvGxac1nKrCd X-Gm-Gg: AZFdTZcYV2virXtBxlJZzOsPy0YYJ5/jZPBtaitMq6ahutbdwOlZyXhNHsKVuXPok/9 6jTgJ+jFn8ihBJ45Fj2UCDXBIDKkHmAZ9/F0M0o6+xQ0lwLoSCIv6Q57FYRXWmn36pEnZImzVty xeJxng/lFODsl1UujO+E7kVybNgtlsOPenzB2aLd+IhmNJCA1EaqtRK6uwSFB2zXIdOqe6b3MRo f9VW+3dDiUbXIlo4idZWeT9tujDGHu6z4Zw2R9g6VBT1QooTb1DHwlArnhBMErksVGuuagiLUUx iZ+d/SFlWZqho6INC6TVzAU/n50buZVSfd7wrgrfC8kE9HGSlMyiAIeQDY2pfFx/+c3HNuOfAeH 2Jf/9Kuq70p8I1XnLR+HP1P+Cy9/G2GVKVfR1+Vo6Se9ZeRPlh+OgUyRc2kmuL3g4tVTo4SDRHb xU5eaYJ9YdgUVo3nw/+5fOKjIGaVcFzrfpkV01T5vqiHuoukxRUuaoGT7SEvit5DA7vA++z2kdc T5EVuM8xU3vztjarTaB6g/GG0g2cUYVna2Y7OqxgcWS6NalX/KkMEBSFWj7o8RleDUs7FOsGjLa twZZ9amfwMhAWOSUZ4XBgHD2Dt/D8ley89EE7EUR1M1z+hWcEzlyaCDMAkzyHbnhnQJM X-Received: by 2002:a17:902:ce07:b0:2ed:e22b:77a2 with SMTP id d9443c01a7336-2f1ba225c8cmr21350855ad.55.1796400810664; Fri, 04 Dec 2026 08:13:30 -0800 (PST) Received: from KASONG-MC4 ([115.171.41.91]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2f1b78faa54sm15082075ad.24.2026.12.04.08.13.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 08:13:29 -0800 (PST) Date: Sat, 5 Dec 2026 00:13:07 +0800 From: Kairui Song To: sashiko-reviews@lists.linux.dev Cc: Kairui Song , linux-mm@kvack.org, 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 , "Liam R. Howlett" , Barry Song , Axel Rasmussen , Yuanchu Xie , Wei Xu , Vlastimil Babka , Suren Baghdasaryan , Nhat Pham , Youngjun Park , Zi Yan , Gregory Price , "Matthew Wilcox (Oracle)" , Baolin Wang , Ryan Roberts , Dev Jain , Lance Yang , Hugh Dickins , SJ Park , David Rientjes , Yu Zhao , Vernon Yang , Zicheng Wang , Tal Zussman , Xiang Liu , Ehab Ababneh , Zhao Zhengzhuo , Lian Wang , Joanne Koong , Kunwu Chan , Hui Zhu , Maxim Muzafarov , Tianyi Chen , Aveline Noir , damon@lists.linux.dev, Ridong Chen , tj@kernel.org, mkoutny@suse.com Subject: Re: [PATCH v8 08/19] mm/mglru: make folio lru referenced times count a generic API Message-ID: References: <20261204-mglru-fg-v8-0-64f81c876c15@tencent.com> <20261204-mglru-fg-v8-8-64f81c876c15@tencent.com> X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 1725B1C000F X-Rspam-User: X-Stat-Signature: 446y463mptprfxw58kydc7nuep93edbt X-Spam-Status: No, score=-8.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-HE-Tag: 1796400811-871821 X-HE-Meta: U2FsdGVkX19AuBL4pyoH68WsWo7lMfj4zyiB7Gd8ND+zavyTeilERIwshEisGgfYOqllJs5eHadQnOnXJXjrcNsrXTkJSz6otsKEv31Hhq4xrkoORnXARhPlNVmmHtor8ARlGQoGm6bZNcjXHQGaXWS2HlTqwb75iB20lYLA+YhnaXxJQjEoHpAR63xGnMNqvnS9nMIDo+9PFN7JuHPjFokXjZlgedPf8EL49edhPiDS95w5yWz4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MT0Zo5+HMXH/Hp5OrZmq8mDtwwcMtwObWj8VqhX/vIGEqJ3wIOEYlNV3pIEdU4njY+SCHa28a6H7eNWNwfCUcevZSbsUXf2jGLi+Lw8EwI2n5G+2QRXq+Iz+mvsp+510kUWTOe4PXoTEOuyv2vjkhP4IZ0BuJFBtbTD2pASJ6ACYC3ZvFoPHkfyJifs7n+0hXcRkLrH0RiWZT9XtPyvJTrlqCZLHU6+6W9pJXtWvkXHlzp66WD/9jL+gZl8OUiF143TBSGrudt9pf+B2cPjtsA23STWA2HobfO5yOG61qBL/FARb5ZmJm5Q0NDb/sNgrq4DcjC3zysAz96XdAOe4erKgaKp4IuPd2x0or8bRulSIG8GEiO1vDBXJxF+8XgEXdU0LK4zorGese9C0ep/PIbL4VMJrehxKgDFbAnzBcw306ZmK+3+0Gb8= Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 On Thu, Dec 03, 2026 at 08:17:01PM +0800, sashiko-bot@kernel.org wrote: > Thank you for your contribution! Sashiko AI review found 3 potential > issues to consider: > - [Medium] mm: PG_workingset set before PG_uptodate in > folio_migrate_flags() > - [Medium] mm: /proc/kpageflags KPF_REFERENCED reports MGLRU refs parity > - [Low] mm: unaddressed maintainer request to split MGLRU helpers out of > mm_inline.h > -- > > commit 1ce1bf59d4884a8811452eef49a607c737b4800b > Author: Kairui Song > > mm/mglru: make folio lru referenced times count a generic API > > This commit makes the folio LRU refs helpers available regardless of > CONFIG_LRU_GEN, moves the lru_gen_* helpers under CONFIG_LRU_GEN, and > drops the separate PG_workingset copy from folio_migrate_flags() now that > folio_migrate_lru_refs() copies it. > > > diff --git a/include/linux/mm_inline.h b/include/linux/mm_inline.h > > index 3cdad5765b58d..1749cbddf1258 100644 > > --- a/include/linux/mm_inline.h > > +++ b/include/linux/mm_inline.h > > [ ... ] > > > @@ -228,7 +234,8 @@ static inline void lru_set_refs_flags(unsigned long *flags, unsigned int refs) > > *flags |= BIT(PG_referenced); > > if (refs & BIT(1)) > > *flags |= BIT(PG_workingset); > > - *flags |= ((unsigned long)refs >> 2) << LRU_REFS_PGOFF; > > + if (LRU_REFS_WIDTH) > > + *flags |= ((unsigned long)refs >> 2) << LRU_REFS_PGOFF; > > } > > [Severity: Medium] > As reported by Lian Wang on RFC [1], does this leave /proc/kpageflags > reporting the parity of the MGLRU refs count in KPF_REFERENCED instead of > whether the folio was referenced? > > lru_set_refs_flags() encodes PG_referenced strictly as bit 0 of refs, so > PG_referenced is clear whenever an MGLRU folio has refs equal to 2, 4, or > 6. stable_page_flags() in fs/proc/page.c still copies raw PG_referenced > directly to KPF_REFERENCED, misreporting those referenced folios as > unreferenced to userspace tools such as page-types. Checking whether > lru_get_refs_flags(k) is nonzero under CONFIG_LRU_GEN would preserve > KPF_REFERENCED semantics. /proc/kpageflags just dumps raw PG_* flags, I think I already described this in cover letter, MGLRU's PG_referenced usage is already very broken (smaps, active / inactive readings), we are fixing it, and this is one step of that, not a problem introduced here but a problem being solved. > > +/** > > + * folio_migrate_lru_refs - copy the reference state to a new folio > > + * @new: the destination folio > > + * @old: the source folio > > + * > > + * Transfer the reference state to @new during migration: the MGLRU > > + * refs count, or PG_referenced and PG_workingset (bits 0-1 of the > > + * encoding) for the active/inactive LRU. > > + */ > > +static inline void folio_migrate_lru_refs(struct folio *new, const struct folio *old) > > { > > - return lru_get_gen_flags(READ_ONCE(*const_folio_flags(folio, 0))); > > + folio_set_lru_refs(new, folio_lru_refs(old)); > > } > > [Severity: Low] > As reported by David Hildenbrand (Arm) on v6 [2], this patch and the rest > of the series still keep and expand the MGLRU and LRU-refs helpers in > include/linux/mm_inline.h rather than splitting them out into a dedicated > header as a prerequisite cleanup. > > mm/vmscan.h already has a CONFIG_LRU_GEN section, and all callers of > folio_lru_gen(), lru_set_refs_flags(), lru_get_refs_flags(), > folio_lru_refs(), folio_inc_lru_refs(), and folio_migrate_lru_refs() live > under mm/. Should these helpers move out of include/linux/mm_inline.h > before the later patches modify them, or is there maintainer agreement to > defer the split to a follow-up series? This was already discussed on v6 and multiple people suggested to be done later after FG lands. > > diff --git a/mm/migrate.c b/mm/migrate.c > > index 96b66a272379f..f59dd50b3f229 100644 > > --- a/mm/migrate.c > > +++ b/mm/migrate.c > > @@ -807,8 +807,6 @@ void folio_migrate_flags(struct folio *newfolio, struct folio *folio) > > folio_set_active(newfolio); > > } else if (folio_test_clear_unevictable(folio)) > > folio_set_unevictable(newfolio); > > - if (folio_test_workingset(folio)) > > - folio_set_workingset(newfolio); > > if (folio_test_checked(folio)) > > folio_set_checked(newfolio); > > /* > > [Severity: Medium] > Can moving the PG_workingset copy into folio_migrate_lru_refs() cause > concurrent waiters on newfolio to falsely account migration as workingset > thrashing and PSI memory stall? > > CPU0 (migration) CPU1 (reader / fault) > __migrate_folio() > __folio_migrate_mapping() > xas_store(&xas, newfolio) > local_irq_enable() > folio_migrate_flags() > folio_migrate_lru_refs() > sets PG_workingset > folio_wait_bit_common_timeout() > !uptodate && workingset > psi_memstall_enter() <-- false stall > folio_mark_uptodate(newfolio) > > __folio_migrate_mapping() publishes newfolio into mapping->i_pages with > PG_locked held and PG_uptodate clear, then re-enables interrupts before > folio_migrate_flags() runs with preemption enabled. Previously > PG_workingset was copied after folio_mark_uptodate(newfolio), whereas > folio_migrate_lru_refs() now runs before it. > > A task blocking on PG_locked in folio_wait_bit_common_timeout() during > that window sees !folio_test_uptodate(folio) && folio_test_workingset(folio) > and charges delayacct_thrashing_start() and psi_memstall_enter() until > migration unlocks newfolio. Calling folio_migrate_lru_refs() after > folio_mark_uptodate(newfolio) would preserve the previous ordering. > > The comment above folio_migrate_lru_refs() in folio_migrate_flags() also > still mentions only PG_referenced. It could, though it hardly matters and it's not really wrong to consider it memory pressure I think? Anyway, moving folio_migrate_lru_refs() after folio_mark_uptodate() is trivial. I can change that.