Skip to content

Commit fa23a33

Browse files
Matthew Wilcox (Oracle)akpm00
authored andcommitted
mm: separate folio_split_memcg_refs() from split_page_memcg()
Patch series "Minor memcg cleanups & prep for memdescs", v2. Separate the handling of accounted folios and GFP_ACCOUNT pages for easier to understand code. For more detail, see https://lore.kernel.org/linux-mm/[email protected]/ This patch (of 5): Folios always use memcg_data to refer to the mem_cgroup while pages allocated with GFP_ACCOUNT have a pointer to the obj_cgroup. Since the caller already knows what it has, split the function into two and then we don't need to check. Move the assignment of split folio memcg_data to the point where we set up the other parts of the new folio. That leaves folio_split_memcg_refs() just handling the memcg accounting. Link: https://lkml.kernel.org/r/[email protected] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Matthew Wilcox (Oracle) <[email protected]> Acked-by: Johannes Weiner <[email protected]> Acked-by: Shakeel Butt <[email protected]> Acked-by: Zi Yan <[email protected]> Acked-by: Roman Gushchin <[email protected]> Cc: David Hildenbrand <[email protected]> Cc: Matthew Wilcow (Oracle) <[email protected]> Cc: Michal Hocko <[email protected]> Cc: Muchun Song <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent cb44821 commit fa23a33

File tree

3 files changed

+24
-16
lines changed

3 files changed

+24
-16
lines changed

include/linux/memcontrol.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,6 +1039,8 @@ static inline void memcg_memory_event_mm(struct mm_struct *mm,
10391039
}
10401040

10411041
void split_page_memcg(struct page *head, int old_order, int new_order);
1042+
void folio_split_memcg_refs(struct folio *folio, unsigned old_order,
1043+
unsigned new_order);
10421044

10431045
static inline u64 cgroup_id_from_mm(struct mm_struct *mm)
10441046
{
@@ -1463,6 +1465,11 @@ static inline void split_page_memcg(struct page *head, int old_order, int new_or
14631465
{
14641466
}
14651467

1468+
static inline void folio_split_memcg_refs(struct folio *folio,
1469+
unsigned old_order, unsigned new_order)
1470+
{
1471+
}
1472+
14661473
static inline u64 cgroup_id_from_mm(struct mm_struct *mm)
14671474
{
14681475
return 0;

mm/huge_memory.c

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3394,6 +3394,9 @@ static void __split_folio_to_order(struct folio *folio, int old_order,
33943394
folio_set_young(new_folio);
33953395
if (folio_test_idle(folio))
33963396
folio_set_idle(new_folio);
3397+
#ifdef CONFIG_MEMCG
3398+
new_folio->memcg_data = folio->memcg_data;
3399+
#endif
33973400

33983401
folio_xchg_last_cpupid(new_folio, folio_last_cpupid(folio));
33993402
}
@@ -3525,18 +3528,7 @@ static int __split_unmapped_folio(struct folio *folio, int new_order,
35253528
}
35263529
}
35273530

3528-
/*
3529-
* Reset any memcg data overlay in the tail pages.
3530-
* folio_nr_pages() is unreliable until prep_compound_page()
3531-
* was called again.
3532-
*/
3533-
#ifdef NR_PAGES_IN_LARGE_FOLIO
3534-
folio->_nr_pages = 0;
3535-
#endif
3536-
3537-
3538-
/* complete memcg works before add pages to LRU */
3539-
split_page_memcg(&folio->page, old_order, split_order);
3531+
folio_split_memcg_refs(folio, old_order, split_order);
35403532
split_page_owner(&folio->page, old_order, split_order);
35413533
pgalloc_tag_split(folio, old_order, split_order);
35423534

mm/memcontrol.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3081,10 +3081,19 @@ void split_page_memcg(struct page *head, int old_order, int new_order)
30813081
for (i = new_nr; i < old_nr; i += new_nr)
30823082
folio_page(folio, i)->memcg_data = folio->memcg_data;
30833083

3084-
if (folio_memcg_kmem(folio))
3085-
obj_cgroup_get_many(__folio_objcg(folio), old_nr / new_nr - 1);
3086-
else
3087-
css_get_many(&folio_memcg(folio)->css, old_nr / new_nr - 1);
3084+
obj_cgroup_get_many(__folio_objcg(folio), old_nr / new_nr - 1);
3085+
}
3086+
3087+
void folio_split_memcg_refs(struct folio *folio, unsigned old_order,
3088+
unsigned new_order)
3089+
{
3090+
unsigned new_refs;
3091+
3092+
if (mem_cgroup_disabled() || !folio_memcg_charged(folio))
3093+
return;
3094+
3095+
new_refs = (1 << (old_order - new_order)) - 1;
3096+
css_get_many(&__folio_memcg(folio)->css, new_refs);
30883097
}
30893098

30903099
unsigned long mem_cgroup_usage(struct mem_cgroup *memcg, bool swap)

0 commit comments

Comments
 (0)