On Tue, 14 Jul 2026 09:50:59 +0800 Ye Liu <ye.liu@linux.dev> wrote:
> This series collects a few cleanups for mm/page_owner.c that have been
> accumulated while reading through the file. There is no functional
> change -- the goal is to make the code easier to read and maintain.
Thanks, I updated mm.git's mm-unstable branch to this version of the
patchset.
> v6:
> - Patch 3: drop unnecessary 'extern' from __folio_set_owner_migrate_reason()
> declaration in page_owner.h; Adjust the indentation; add Reviewed-by from
> Lorenzo Stoakes.
> - Patch 8: clarify commit message wording; add Reviewed-by from Zi Yan and
> Vlastimil Babka.
> - Patch 9: rename patch to cover both TOCTOU fixes; also replace
> page_memcg_check(page) with extracting objcg from the memcg_data snapshot
> to fix a second TOCTOU issue; add early return for the MEMCG_DATA_OBJEXTS
> (slab) case.
> - Link: https://lore.kernel.org/all/20260701061101.344679-1-ye.liu@linux.dev/
Here's how v6 altered mm.git:
include/linux/hugetlb.h | 4 ++--
include/linux/migrate.h | 6 +++---
include/linux/page_owner.h | 2 +-
mm/page_owner.c | 8 ++++++--
4 files changed, 12 insertions(+), 8 deletions(-)
--- a/include/linux/hugetlb.h~b
+++ a/include/linux/hugetlb.h
@@ -155,7 +155,7 @@ bool folio_isolate_hugetlb(struct folio
int get_hwpoison_hugetlb_folio(struct folio *folio, bool *hugetlb, bool unpoison);
void folio_putback_hugetlb(struct folio *folio);
void move_hugetlb_state(struct folio *old_folio, struct folio *new_folio,
- enum migrate_reason reason);
+ enum migrate_reason reason);
void hugetlb_fix_reserve_counts(struct inode *inode);
extern struct mutex *hugetlb_fault_mutex_table;
u32 hugetlb_fault_mutex_hash(struct address_space *mapping, pgoff_t idx);
@@ -425,7 +425,7 @@ static inline void folio_putback_hugetlb
}
static inline void move_hugetlb_state(struct folio *old_folio,
- struct folio *new_folio, enum migrate_reason reason)
+ struct folio *new_folio, enum migrate_reason reason)
{
}
--- a/include/linux/migrate.h~b
+++ a/include/linux/migrate.h
@@ -57,9 +57,9 @@ void putback_movable_pages(struct list_h
int migrate_folio(struct address_space *mapping, struct folio *dst,
struct folio *src, enum migrate_mode mode);
int migrate_pages(struct list_head *l, new_folio_t new, free_folio_t free,
- unsigned long private, enum migrate_mode mode,
- enum migrate_reason reason,
- unsigned int *ret_succeeded);
+ unsigned long private, enum migrate_mode mode,
+ enum migrate_reason reason,
+ unsigned int *ret_succeeded);
struct folio *alloc_migration_target(struct folio *src, unsigned long private);
bool isolate_movable_ops_page(struct page *page, isolate_mode_t mode);
bool isolate_folio_to_list(struct folio *folio, struct list_head *list);
--- a/include/linux/page_owner.h~b
+++ a/include/linux/page_owner.h
@@ -15,7 +15,7 @@ extern void __set_page_owner(struct page
extern void __split_page_owner(struct page *page, int old_order,
int new_order);
extern void __folio_copy_owner(struct folio *newfolio, struct folio *old);
-extern void __folio_set_owner_migrate_reason(struct folio *folio, enum migrate_reason reason);
+void __folio_set_owner_migrate_reason(struct folio *folio, enum migrate_reason reason);
extern void __dump_page_owner(const struct page *page);
extern void pagetypeinfo_showmixedcount_print(struct seq_file *m,
pg_data_t *pgdat, struct zone *zone);
--- a/mm/page_owner.c~b
+++ a/mm/page_owner.c
@@ -540,6 +540,7 @@ static inline int print_page_owner_memcg
struct page *page)
{
unsigned long memcg_data;
+ struct obj_cgroup *objcg;
struct mem_cgroup *memcg;
bool online;
char name[80];
@@ -549,11 +550,14 @@ static inline int print_page_owner_memcg
if (!memcg_data || PageTail(page))
goto out_unlock;
- if (memcg_data & MEMCG_DATA_OBJEXTS)
+ if (memcg_data & MEMCG_DATA_OBJEXTS) {
ret += scnprintf(kbuf + ret, count - ret,
"Slab cache page\n");
+ goto out_unlock;
+ }
- memcg = page_memcg_check(page);
+ objcg = (void *)(memcg_data & ~OBJEXTS_FLAGS_MASK);
+ memcg = objcg ? obj_cgroup_memcg(objcg) : NULL;
if (!memcg)
goto out_unlock;
_