Skip to content

Commit becacb0

Browse files
Matthew Wilcoxakpm00
authored andcommitted
mm: memcg: add folio_memcg_check()
Patch series "mm: convert page_idle/damon to use folios", v4. This patch (of 8): Convert page_memcg_check() into folio_memcg_check() and add a page_memcg_check() wrapper. The behaviour of page_memcg_check() is unchanged; tail pages always had a NULL ->memcg_data. Link: https://lkml.kernel.org/r/[email protected] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Matthew Wilcox (Oracle) <[email protected]> Signed-off-by: Kefeng Wang <[email protected]> Cc: David Hildenbrand <[email protected]> Cc: SeongJae Park <[email protected]> Cc: Vishal Moola (Oracle) <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 071acb3 commit becacb0

File tree

2 files changed

+29
-17
lines changed

2 files changed

+29
-17
lines changed

include/linux/memcontrol.h

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -466,34 +466,34 @@ static inline struct mem_cgroup *folio_memcg_rcu(struct folio *folio)
466466
}
467467

468468
/*
469-
* page_memcg_check - get the memory cgroup associated with a page
470-
* @page: a pointer to the page struct
469+
* folio_memcg_check - Get the memory cgroup associated with a folio.
470+
* @folio: Pointer to the folio.
471471
*
472-
* Returns a pointer to the memory cgroup associated with the page,
473-
* or NULL. This function unlike page_memcg() can take any page
474-
* as an argument. It has to be used in cases when it's not known if a page
472+
* Returns a pointer to the memory cgroup associated with the folio,
473+
* or NULL. This function unlike folio_memcg() can take any folio
474+
* as an argument. It has to be used in cases when it's not known if a folio
475475
* has an associated memory cgroup pointer or an object cgroups vector or
476476
* an object cgroup.
477477
*
478-
* For a non-kmem page any of the following ensures page and memcg binding
478+
* For a non-kmem folio any of the following ensures folio and memcg binding
479479
* stability:
480480
*
481-
* - the page lock
481+
* - the folio lock
482482
* - LRU isolation
483-
* - lock_page_memcg()
483+
* - lock_folio_memcg()
484484
* - exclusive reference
485485
* - mem_cgroup_trylock_pages()
486486
*
487-
* For a kmem page a caller should hold an rcu read lock to protect memcg
488-
* associated with a kmem page from being released.
487+
* For a kmem folio a caller should hold an rcu read lock to protect memcg
488+
* associated with a kmem folio from being released.
489489
*/
490-
static inline struct mem_cgroup *page_memcg_check(struct page *page)
490+
static inline struct mem_cgroup *folio_memcg_check(struct folio *folio)
491491
{
492492
/*
493-
* Because page->memcg_data might be changed asynchronously
494-
* for slab pages, READ_ONCE() should be used here.
493+
* Because folio->memcg_data might be changed asynchronously
494+
* for slabs, READ_ONCE() should be used here.
495495
*/
496-
unsigned long memcg_data = READ_ONCE(page->memcg_data);
496+
unsigned long memcg_data = READ_ONCE(folio->memcg_data);
497497

498498
if (memcg_data & MEMCG_DATA_OBJCGS)
499499
return NULL;
@@ -508,6 +508,13 @@ static inline struct mem_cgroup *page_memcg_check(struct page *page)
508508
return (struct mem_cgroup *)(memcg_data & ~MEMCG_DATA_FLAGS_MASK);
509509
}
510510

511+
static inline struct mem_cgroup *page_memcg_check(struct page *page)
512+
{
513+
if (PageTail(page))
514+
return NULL;
515+
return folio_memcg_check((struct folio *)page);
516+
}
517+
511518
static inline struct mem_cgroup *get_mem_cgroup_from_objcg(struct obj_cgroup *objcg)
512519
{
513520
struct mem_cgroup *memcg;
@@ -1170,6 +1177,11 @@ static inline struct mem_cgroup *folio_memcg_rcu(struct folio *folio)
11701177
return NULL;
11711178
}
11721179

1180+
static inline struct mem_cgroup *folio_memcg_check(struct folio *folio)
1181+
{
1182+
return NULL;
1183+
}
1184+
11731185
static inline struct mem_cgroup *page_memcg_check(struct page *page)
11741186
{
11751187
return NULL;

mm/memcontrol.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2952,13 +2952,13 @@ struct mem_cgroup *mem_cgroup_from_obj_folio(struct folio *folio, void *p)
29522952
}
29532953

29542954
/*
2955-
* page_memcg_check() is used here, because in theory we can encounter
2955+
* folio_memcg_check() is used here, because in theory we can encounter
29562956
* a folio where the slab flag has been cleared already, but
29572957
* slab->memcg_data has not been freed yet
2958-
* page_memcg_check(page) will guarantee that a proper memory
2958+
* folio_memcg_check() will guarantee that a proper memory
29592959
* cgroup pointer or NULL will be returned.
29602960
*/
2961-
return page_memcg_check(folio_page(folio, 0));
2961+
return folio_memcg_check(folio);
29622962
}
29632963

29642964
/*

0 commit comments

Comments
 (0)