mirror of
https://github.com/linux-msm/laptops-kernel.git
synced 2026-08-13 14:19:53 -07:00
mm: switch deferred split shrinker to list_lru
The deferred split queue handles cgroups in a suboptimal fashion. The
queue is per-NUMA node or per-cgroup, not the intersection. That means on
a cgrouped system, a node-restricted allocation entering reclaim can end
up splitting large pages on other nodes:
alloc/unmap
deferred_split_folio()
list_add_tail(memcg->split_queue)
set_shrinker_bit(memcg, node, deferred_shrinker_id)
for_each_zone_zonelist_nodemask(restricted_nodes)
mem_cgroup_iter()
shrink_slab(node, memcg)
shrink_slab_memcg(node, memcg)
if test_shrinker_bit(memcg, node, deferred_shrinker_id)
deferred_split_scan()
walks memcg->split_queue
The shrinker bit adds an imperfect guard rail. As soon as the cgroup has
a single large page on the node of interest, all large pages owned by that
memcg, including those on other nodes, will be split.
list_lru properly sets up per-node, per-cgroup lists. As a bonus, it
streamlines a lot of the list operations and reclaim walks. It's used
widely by other major shrinkers already. Convert the deferred split queue
as well.
The list_lru per-memcg heads are instantiated on demand when the first
object of interest is allocated for a cgroup, by calling
folio_memcg_alloc_deferred(). Add calls to where splittable pages are
created: anon faults, swapin faults, khugepaged collapse.
These calls create all possible node heads for the cgroup at once, so the
migration code (between nodes) doesn't need any special care.
[akpm@linux-foundation.org: fix build with CONFIG_TRANSPARENT_HUGEPAGE=n]
Link: https://lore.kernel.org/202605281620.lc3rtkBm-lkp@intel.com
[hannes@cmpxchg.org: fix cgroup.memory=nokmem handling]
Link: https://lore.kernel.org/ah9PGv12mqai84ES@cmpxchg.org
Link: https://lore.kernel.org/20260527204757.2544958-10-hannes@cmpxchg.org
Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
Reported-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Tested-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Acked-by: Shakeel Butt <shakeel.butt@linux.dev>
Reviewed-by: Lorenzo Stoakes (Oracle) <ljs@kernel.org>
Acked-by: Usama Arif <usama.arif@linux.dev>
Reviewed-by: Kairui Song <kasong@tencent.com>
Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
Cc: Barry Song <baohua@kernel.org>
Cc: Dave Chinner <david@fromorbit.com>
Cc: David Hildenbrand (Arm) <david@kernel.org>
Cc: Dev Jain <dev.jain@arm.com>
Cc: Lance Yang <lance.yang@linux.dev>
Cc: Liam R. Howlett <liam@infradead.org>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Nico Pache <npache@redhat.com>
Cc: Roman Gushchin <roman.gushchin@linux.dev>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: Vlastimil Babka <vbabka@kernel.org>
Cc: Zi Yan <ziy@nvidia.com>
Cc: kernel test robot <lkp@intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
committed by
Andrew Morton
parent
65180e9663
commit
fafaeceb89
+12
-5
@@ -439,10 +439,10 @@ static inline int split_huge_page(struct page *page)
|
||||
{
|
||||
return split_huge_page_to_list_to_order(page, NULL, 0);
|
||||
}
|
||||
|
||||
int folio_memcg_alloc_deferred(struct folio *folio);
|
||||
|
||||
void deferred_split_folio(struct folio *folio, bool partially_mapped);
|
||||
#ifdef CONFIG_MEMCG
|
||||
void reparent_deferred_split_queue(struct mem_cgroup *memcg);
|
||||
#endif
|
||||
|
||||
void __split_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd,
|
||||
unsigned long address, bool freeze);
|
||||
@@ -679,8 +679,15 @@ static inline int try_folio_split_to_order(struct folio *folio,
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
static inline void deferred_split_folio(struct folio *folio, bool partially_mapped) {}
|
||||
static inline void reparent_deferred_split_queue(struct mem_cgroup *memcg) {}
|
||||
static inline int folio_memcg_alloc_deferred(struct folio *folio)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline void deferred_split_folio(struct folio *folio, bool partially_mapped)
|
||||
{
|
||||
}
|
||||
|
||||
#define split_huge_pmd(__vma, __pmd, __address) \
|
||||
do { } while (0)
|
||||
|
||||
|
||||
@@ -278,10 +278,6 @@ struct mem_cgroup {
|
||||
struct memcg_cgwb_frn cgwb_frn[MEMCG_CGWB_FRN_CNT];
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
|
||||
struct deferred_split deferred_split_queue;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LRU_GEN_WALKS_MMU
|
||||
/* per-memcg mm_struct list */
|
||||
struct lru_gen_mm_list mm_list;
|
||||
|
||||
@@ -1431,14 +1431,6 @@ struct zonelist {
|
||||
*/
|
||||
extern struct page *mem_map;
|
||||
|
||||
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
|
||||
struct deferred_split {
|
||||
spinlock_t split_queue_lock;
|
||||
struct list_head split_queue;
|
||||
unsigned long split_queue_len;
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_MEMORY_FAILURE
|
||||
/*
|
||||
* Per NUMA node memory failure handling statistics.
|
||||
@@ -1564,10 +1556,6 @@ typedef struct pglist_data {
|
||||
unsigned long first_deferred_pfn;
|
||||
#endif /* CONFIG_DEFERRED_STRUCT_PAGE_INIT */
|
||||
|
||||
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
|
||||
struct deferred_split deferred_split_queue;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_NUMA_BALANCING
|
||||
/* start time in ms of current promote rate limit period */
|
||||
unsigned int nbp_rl_start;
|
||||
|
||||
+125
-242
File diff suppressed because it is too large
Load Diff
+1
-1
@@ -852,7 +852,7 @@ static inline bool folio_unqueue_deferred_split(struct folio *folio)
|
||||
/*
|
||||
* At this point, there is no one trying to add the folio to
|
||||
* deferred_list. If folio is not in deferred_list, it's safe
|
||||
* to check without acquiring the split_queue_lock.
|
||||
* to check without acquiring the list_lru lock.
|
||||
*/
|
||||
if (data_race(list_empty(&folio->_deferred_list)))
|
||||
return false;
|
||||
|
||||
@@ -1123,6 +1123,11 @@ static enum scan_result collapse_huge_page(struct mm_struct *mm, unsigned long a
|
||||
if (result != SCAN_SUCCEED)
|
||||
goto out_nolock;
|
||||
|
||||
if (folio_memcg_alloc_deferred(folio)) {
|
||||
result = SCAN_ALLOC_HUGE_PAGE_FAIL;
|
||||
goto out_nolock;
|
||||
}
|
||||
|
||||
mmap_read_lock(mm);
|
||||
result = hugepage_vma_revalidate(mm, address, true, &vma, cc);
|
||||
if (result != SCAN_SUCCEED) {
|
||||
|
||||
+3
-9
@@ -4143,11 +4143,6 @@ static struct mem_cgroup *mem_cgroup_alloc(struct mem_cgroup *parent)
|
||||
for (i = 0; i < MEMCG_CGWB_FRN_CNT; i++)
|
||||
memcg->cgwb_frn[i].done =
|
||||
__WB_COMPLETION_INIT(&memcg_cgwb_frn_waitq);
|
||||
#endif
|
||||
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
|
||||
spin_lock_init(&memcg->deferred_split_queue.split_queue_lock);
|
||||
INIT_LIST_HEAD(&memcg->deferred_split_queue.split_queue);
|
||||
memcg->deferred_split_queue.split_queue_len = 0;
|
||||
#endif
|
||||
lru_gen_init_memcg(memcg);
|
||||
return memcg;
|
||||
@@ -4299,11 +4294,10 @@ static void mem_cgroup_css_offline(struct cgroup_subsys_state *css)
|
||||
zswap_memcg_offline_cleanup(memcg);
|
||||
|
||||
memcg_offline_kmem(memcg);
|
||||
reparent_deferred_split_queue(memcg);
|
||||
/*
|
||||
* The reparenting of objcg must be after the reparenting of the
|
||||
* list_lru and deferred_split_queue above, which ensures that they will
|
||||
* not mistakenly get the parent list_lru and deferred_split_queue.
|
||||
* The reparenting of objcg must be after the reparenting of
|
||||
* the list_lru in memcg_offline_kmem(), which ensures that
|
||||
* they will not mistakenly get the parent list_lru.
|
||||
*/
|
||||
memcg_reparent_objcgs(memcg);
|
||||
reparent_shrinker_deferred(memcg);
|
||||
|
||||
@@ -5222,6 +5222,10 @@ static struct folio *alloc_anon_folio(struct vm_fault *vmf)
|
||||
folio_put(folio);
|
||||
goto next;
|
||||
}
|
||||
if (order > 1 && folio_memcg_alloc_deferred(folio)) {
|
||||
folio_put(folio);
|
||||
goto fallback;
|
||||
}
|
||||
folio_throttle_swaprate(folio, gfp);
|
||||
/*
|
||||
* When a folio is not zeroed during allocation
|
||||
|
||||
@@ -1373,19 +1373,6 @@ static void __init calculate_node_totalpages(struct pglist_data *pgdat,
|
||||
pr_debug("On node %d totalpages: %lu\n", pgdat->node_id, realtotalpages);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
|
||||
static void pgdat_init_split_queue(struct pglist_data *pgdat)
|
||||
{
|
||||
struct deferred_split *ds_queue = &pgdat->deferred_split_queue;
|
||||
|
||||
spin_lock_init(&ds_queue->split_queue_lock);
|
||||
INIT_LIST_HEAD(&ds_queue->split_queue);
|
||||
ds_queue->split_queue_len = 0;
|
||||
}
|
||||
#else
|
||||
static void pgdat_init_split_queue(struct pglist_data *pgdat) {}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_COMPACTION
|
||||
static void pgdat_init_kcompactd(struct pglist_data *pgdat)
|
||||
{
|
||||
@@ -1401,8 +1388,6 @@ static void __meminit pgdat_init_internals(struct pglist_data *pgdat)
|
||||
|
||||
pgdat_resize_init(pgdat);
|
||||
pgdat_kswapd_lock_init(pgdat);
|
||||
|
||||
pgdat_init_split_queue(pgdat);
|
||||
pgdat_init_kcompactd(pgdat);
|
||||
|
||||
init_waitqueue_head(&pgdat->kswapd_wait);
|
||||
|
||||
@@ -465,6 +465,16 @@ static struct folio *__swap_cache_alloc(struct swap_cluster_info *ci,
|
||||
return ERR_PTR(-ENOMEM);
|
||||
}
|
||||
|
||||
if (order > 1 && folio_memcg_alloc_deferred(folio)) {
|
||||
spin_lock(&ci->lock);
|
||||
__swap_cache_do_del_folio(ci, folio, entry, shadow);
|
||||
spin_unlock(&ci->lock);
|
||||
folio_unlock(folio);
|
||||
/* nr_pages refs from swap cache, 1 from allocation */
|
||||
folio_put_refs(folio, nr_pages + 1);
|
||||
return ERR_PTR(-ENOMEM);
|
||||
}
|
||||
|
||||
/* memsw uncharges swap when folio is added to swap cache */
|
||||
memcg1_swapin(folio);
|
||||
if (shadow)
|
||||
|
||||
Reference in New Issue
Block a user