From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.173 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796400812; b=Mnt6SFd4ZNDaoVhAXoUqjb1e4KS6XtXobAkjuYl+IU9LRtyqpe5gjQt7kHrMcSnXbmVh n8BLL9baBNVSMhZhvDrIchY0ZU7GX6pAYA2oyxGuyXiVINjPANlun/oH5Kt8QTO4kkyyR iQDaqgz1iZv8kxBBE4QLB4H0/tri+Isqg3Tse0MGnV1gMKoIAlwu2thHJkp9NHGMuuR6N EZtS99SHVCh+Aovz5qkG5grkQQlN01+76ZKIjEwHVh6MXBN3OYDovnK2q0hgRy4JiGhn6 R/ZgrbwztfssJ2N4ppYGWIWrqMZhD5ys32M4YUqQSHGcLRcyY6E9ZAc25SoMRr7O2Ig== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796400812; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; bh=9ua6fwJ47fOKogabvIv9AllBzm/KgF3KZ5fyyeUxj84=; b=P0rJq+xYAz+gGGIT4SL5H/GC453UJN+6uhcoCHYu+dMS6fsBoWPj+tfc7j2Hbov4b8I1 527mEPFzZuZ+RpSBNWwPdeVPcFISDVwU18rfTZ/8q6w7QOl4T/xp5gFRnDGlragZhPB9F LvEQue84RDEkOkHw+xhalRrXCsFuyu9iuLWSJTY3HDAVtoNPP+mGAthMldP9QZw4Gxyfy 7MfOC0/xwWD37Ra9W5+PSkx5kG4zyNXnKkdq8EgqFJYDSs9CLq1MlYSjorUIpdcdJd40w FUxZOcJ1RkuVTDtSBqwpLNl16lkqApQJRJnBwtpKYY4rti+AiG9O6smQZnb2GoNAfcQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=max+X5dE; arc=none smtp.remote-ip=209.85.214.173 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8935F606A322 for ; Fri, 4 Dec 2026 16:13:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 8935F606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com 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=max+X5dE Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-2f11330e550so7181535ad.0 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=lists.linux.dev; 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=max+X5dEHMYL4U2Wsn3FYH8L+9d1wmI3Vc3nvfFWrwVLW+uwCjanCMJ4ywGZhtKdl0 JCTq+g60yJQoi4FZyKPU8yZEtBimJCtKGHQ41pFTl70dusWMwNvUelOqUAtAKKMl8GhY 9Ekx1w/xAo387tXL3iLX8FVHDhcbvz7DjeYnS9pe3f6HqVYnV6/o2nvBZlCCkbMIvzyJ b64SQqZb/lI9JnW0ZcEB1NnLkGJdtxddX849oyVOQxtZ0rZBdO6Tb/aVRt6bYDn87VRC 1R5casn/lA6HLK4Lnx7N5jYzdmhRxwi/TDcXk/11bqwWKAXoILiQzPKd2/NmFaN/VSJd cEkg== 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=frPfPsQ/9ijMnggJj1yeJJF20I+qBKuada7N+D+A6Y1lGRBwb3q81Mag9PTAkGJUdp l041Y/z2RkL60tSxpEPLgAZlUR41mEl4Tqvnkk/5Zd3ccNJPfdbFPEtwcJv+nZK2A7MK ViwwNQiNfmTmqDr3k3t06Di5VgmMKiODSXnTdNNEbs4TJ4YvPVQX+c4LeTwtR/tDLKYm 53o4ktyvzer/sZFGT/ut7boMPJ0stnNwMOcZWU1jlO7TIoODpX2rTssgGndkeVJRdLfv lTBKuS+5T1cQutbW65hPMaWon9XuBZpHPp96Veq7c2xSBOprFKoUDHok9UyAKaBwZ6bt jRRA== X-Forwarded-Encrypted: i=1; AL+hErEigUgiJ3yQQ6q/ZSWjdnivTO4udOBHe4UTPwLk70EDbJl3ilvTHo0cwcK6Lewj+uTZPBbMlw==@lists.linux.dev X-Gm-Message-State: AB4q+uEdhXdIRVqcfeZX7Oo3aqgQPavpmX/jdPChLfJIzsgmkncYuqFi qpOTnSGoHvK1YOvojGdltXiDl7QHJIO7w8AssLJVGdlpW4yrMpxwzecr X-Gm-Gg: AZFdTZd+EEM/Ydc+pQqFArNvHooMM+SKJOn6bqP+Dkfz6zv1cunVI7CcidWTItXjBzM LI9g85w+JunIDTOo976bY1ILnU9O/yhexbpfvOA9j0Pg3fpBgkWNCiPINka4Krpf+I8IhusNIET fOYaibgjgyG2p6d72udJeWKRW5oOkxPmRqHc/QVI+z0JA8/lM0Wh8xr+b7kXMZLT8Onwi1mrY3I /BSV4GBZ7PXLJQTFQcgPTV+hdtMtzrtefMUEBVFHh8wUrjTV5x7pCmws9R4GEUpBtUmWLcrDtBw GHrLa66LYzbuJ0TbhTWPo2tjCD8ZE+q6i6HybwIgP6k+4E9gZX8ltBXlOdDw7EYgChitEgasvjW u3MO1dSu6FW1aOMvaof0w8Qr/LUg+bYLiITrsTV702yabhhTqf5x6bdwl6+NbX24WazQ96qQQbb 2lohSNWpDMEEm3jOfXPcKKAKhlbmdKrfIXXvB4S7o8InzdAhKU9jaX9L/MVKk8IJq1q2ShD9yYw z0lzJXGxsFXzahiMmAgtF5YzVniDj2BSRXf9QFk37hfzmDrI/NuprDGTKUoMrsEF5cvRTKOoaDT xRL3UOEocyZFluhJsPn+mdSdoHJPusBZduZgrVtA7OwqWgBQhVkTZ47VMAc+2LLjq8w4 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-Mailing-List: damon@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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.