Revert "mm: skip CMA pages when they are not available"
Subsystems (3)
PATCH 1/1 Revert "mm: skip CMA pages when they are not available"
This reverts commit 5da226dbfce3a2f44978c2c7cf88166e69a6788b.
lruvec->lru_lock is highly contended and is held when calling isolate_lru_folios. If the lru has a large number of CMA folios consecutively, while the allocation type requested is not MIGRATE_MOVABLE, isolate_lru_folios can hold the lock for a very long time while it skips those. For FIO workload, ~150million order=0 folios were skipped to isolate a few ZONE_DMA folios [1]. This can cause lockups [1] and high memory pressure for extended periods of time [2].
[1] https://lore.kernel.org/all/CAOUHufbkhMZYz20aM_3rHZ3OcK4m2puji2FGpUpn_-DevGk3Kg@mail.gmail.com/
[2] https://lore.kernel.org/all/[email protected]/
--- mm/vmscan.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
mm/vmscan.c +1 -2
@@ -1690,8 +1690,7 @@ static unsigned long isolate_lru_folios(unsigned long nr_to_scan, nr_pages =folio_nr_pages (folio); total_scan += nr_pages; -if (folio_zonenum (folio) > sc->reclaim_idx || -skip_cma (folio, sc)) { +if (folio_zonenum (folio) > sc->reclaim_idx) { nr_skipped[folio_zonenum (folio)] += nr_pages; move_to = &folios_skipped; goto move;
Signature · 1 line
2.43.5
Quoted 24 lines · Usama Arif
This reverts commit
5da226dbfce3a2f44978c2c7cf88166e69a6788b.
lruvec->lru_lockis highly contended and is held when callingisolate_lru_folios. If the lru has a large number of CMA folios consecutively, while the allocation type requested is notMIGRATE_MOVABLE,isolate_lru_folioscan hold the lock for a very long time while it skips those. For FIO workload, ~150million order=0 folios were skipped to isolate a fewZONE_DMAfolios [1]. This can cause lockups [1] and high memory pressure for extended periods of time [2].[1] https://lore.kernel.org/all/CAOUHufbkhMZYz20aM_3rHZ3OcK4m2puji2FGpUpn_-DevGk3Kg@mail.gmail.com/
[2] https://lore.kernel.org/all/[email protected]/Signed-off-by Usama Arif <[email protected]>--- mm/vmscan.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)mm/vmscan.c +0
-0
mm/vmscan.c static unsigned long isolate_lru_folios(unsigned long nr_to_scan, · line 1696
Quoted 9 lines
mm/vmscan.c +1
-2@@ -1690,8 +1690,7 @@ static unsigned long isolate_lru_folios(unsigned long nr_to_scan, nr_pages =folio_nr_pages (folio); total_scan += nr_pages; -if (folio_zonenum (folio) > sc->reclaim_idx || -skip_cma (folio, sc)) { +if (folio_zonenum (folio) > sc->reclaim_idx) { nr_skipped[folio_zonenum (folio)] += nr_pages; move_to = &folios_skipped; goto move;
Actually, I didn't build test this with other config options before sending this patch. skip_cma is only neeeded with MGLRU after this patch, we need to move the definition of the function to be guarded under CONFIG_LRU_GEN, so that we don't get ‘skip_cma’ defined but not used error. Below patch should be good:
From 1aae7f04a5cb203ea2c3ede7973dd9eddbbd7a8b Mon Sep 17 00:00:00 2001
From: Usama Arif <[email protected]>
Date: Wed, 21 Aug 2024 20:26:07 +0100
Subject: [PATCH] Revert "mm: skip CMA pages when they are not available"
This reverts commit 5da226dbfce3a2f44978c2c7cf88166e69a6788b.
lruvec->lru_lock is highly contended and is held when calling isolate_lru_folios. If the lru has a large number of CMA folios consecutively, while the allocation type requested is not MIGRATE_MOVABLE, isolate_lru_folios can hold the lock for a very long time while it skips those. For FIO workload, ~150million order=0 folios were skipped to isolate a few ZONE_DMA folios [1]. This can cause lockups [1] and high memory pressure for extended periods of time [2].
[1] https://lore.kernel.org/all/CAOUHufbkhMZYz20aM_3rHZ3OcK4m2puji2FGpUpn_-DevGk3Kg@mail.gmail.com/
[2] https://lore.kernel.org/all/[email protected]/
--- mm/vmscan.c | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-)
mm/vmscan.c +20 -21
@@ -1625,25 +1625,6 @@ static __always_inline void update_lru_sizes(struct lruvec *lruvec, } -#ifdef CONFIG_CMA -/* -* It is waste of effort to scan and reclaim CMA pages if it is not available -* for current allocation context. Kswapd can not be enrolled as it can not -* distinguish this scenario by using sc->gfp_mask = GFP_KERNEL -*/ -static bool skip_cma (struct folio *folio,struct scan_control *sc) -{ -return !current_is_kswapd () && -gfp_migratetype (sc->gfp_mask) !=MIGRATE_MOVABLE && -folio_migratetype (folio) ==MIGRATE_CMA ; -} -#else -static bool skip_cma (struct folio *folio,struct scan_control *sc) -{ -return false; -} -#endif -/* * Isolating page from the lruvec to fill in @dst list by nr_to_scan times. *
@@ -1690,8 +1671,7 @@ static unsigned long isolate_lru_folios(unsigned long nr_to_scan, nr_pages =folio_nr_pages (folio); total_scan += nr_pages; -if (folio_zonenum (folio) > sc->reclaim_idx || -skip_cma (folio, sc)) { +if (folio_zonenum (folio) > sc->reclaim_idx) { nr_skipped[folio_zonenum (folio)] += nr_pages; move_to = &folios_skipped; goto move;
@@ -4297,6 +4277,25 @@ void lru_gen_soft_reclaim(struct mem_cgroup *memcg, int nid)#endif /* CONFIG_MEMCG */ +#ifdef CONFIG_CMA +/* +* It is waste of effort to scan and reclaim CMA pages if it is not available +* for current allocation context. Kswapd can not be enrolled as it can not +* distinguish this scenario by using sc->gfp_mask = GFP_KERNEL +*/ +static bool skip_cma (struct folio *folio,struct scan_control *sc) +{ +return !current_is_kswapd () && +gfp_migratetype (sc->gfp_mask) !=MIGRATE_MOVABLE && +folio_migratetype (folio) ==MIGRATE_CMA ; +} +#else +static bool skip_cma (struct folio *folio,struct scan_control *sc) +{ +return false; +} +#endif +/****************************************************************************** * the eviction ******************************************************************************/
Signature · 1 line
2.43.5
Quoted 16 lines · Usama Arif
From
1aae7f04a5cb203ea2c3ede7973dd9eddbbd7a8bMon Sep 17 00:00:00 2001
From: Usama Arif <[email protected]>
Date: Wed, 21 Aug 2024 20:26:07 +0100
Subject: [PATCH] Revert "mm: skip CMA pages when they are not available"This reverts commit
5da226dbfce3a2f44978c2c7cf88166e69a6788b.
lruvec->lru_lockis highly contended and is held when callingisolate_lru_folios. If the lru has a large number of CMA folios consecutively, while the allocation type requested is notMIGRATE_MOVABLE,isolate_lru_folioscan hold the lock for a very long time while it skips those. For FIO workload, ~150million order=0 folios were skipped to isolate a fewZONE_DMAfolios [1]. This can cause lockups [1] and high memory pressure for extended periods of time [2].
Quoted 4 lines
[1] https://lore.kernel.org/all/CAOUHufbkhMZYz20aM_3rHZ3OcK4m2puji2FGpUpn_-DevGk3Kg@mail.gmail.com/
[2] https://lore.kernel.org/all/[email protected]/Signed-off-by Usama Arif <[email protected]>
I think this is the right move for now, until there is a robust solution for the original issue.
But hould b7108d66318abf3e060c7839eabcba52e9461568 be reverted along with it? From its changelog:
No observable issue without this patch on MGLRU, but logically it make sense to skip the CMA page reclaim when those pages can't be satisfied for the current allocation context.
Presumably it has the same risk reward profile as it does on conventional reclaim, with long skip runs while holding the lruvec->lock.
Usama Arif
Acked-by Johannes WeinerQuoted 30 lines · Johannes Weiner
Quoted 16 lines · Usama Arif
From
1aae7f04a5cb203ea2c3ede7973dd9eddbbd7a8bMon Sep 17 00:00:00 2001
From: Usama Arif <[email protected]>
Date: Wed, 21 Aug 2024 20:26:07 +0100
Subject: [PATCH] Revert "mm: skip CMA pages when they are not available"This reverts commit
5da226dbfce3a2f44978c2c7cf88166e69a6788b.
lruvec->lru_lockis highly contended and is held when callingisolate_lru_folios. If the lru has a large number of CMA folios consecutively, while the allocation type requested is notMIGRATE_MOVABLE,isolate_lru_folioscan hold the lock for a very long time while it skips those. For FIO workload, ~150million order=0 folios were skipped to isolate a fewZONE_DMAfolios [1]. This can cause lockups [1] and high memory pressure for extended periods of time [2].Quoted 4 lines
[1] https://lore.kernel.org/all/CAOUHufbkhMZYz20aM_3rHZ3OcK4m2puji2FGpUpn_-DevGk3Kg@mail.gmail.com/
[2] https://lore.kernel.org/all/[email protected]/Signed-off-by Usama Arif <[email protected]>Acked-by Johannes Weiner <[email protected]>I think this is the right move for now, until there is a robust solution for the original issue.
But hould
b7108d66318abf3e060c7839eabcba52e9461568be reverted along with it? From its changelog:
Quoted 7 lines
No observable issue without this patch on MGLRU, but logically it make sense to skip the CMA page reclaim when those pages can't be satisfied for the current allocation context.
Presumably it has the same risk reward profile as it does on conventional reclaim, with long skip runs while holding the
lruvec->lock.
Yes makes sense to remove it from there a well, Just doing it in a single commit below:
From 9ad9fb73edf2c04ef932d128fc2729dfd8391c0c Mon Sep 17 00:00:00 2001
From: Usama Arif <[email protected]>
Date: Wed, 21 Aug 2024 20:26:07 +0100
Subject: [PATCH] Revert "mm: skip CMA pages when they are not available"
This reverts commit 5da226dbfce3a2f44978c2c7cf88166e69a6788b and b7108d66318abf3e060c7839eabcba52e9461568.
lruvec->lru_lock is highly contended and is held when calling isolate_lru_folios. If the lru has a large number of CMA folios consecutively, while the allocation type requested is not MIGRATE_MOVABLE, isolate_lru_folios can hold the lock for a very long time while it skips those. For FIO workload, ~150million order=0 folios were skipped to isolate a few ZONE_DMA folios [1]. This can cause lockups [1] and high memory pressure for extended periods of time [2].
Remove skipping CMA for MGLRU as well, as it was introduced in sort_folio for the same resaon as 5da226dbfce3a2f44978c2c7cf88166e69a6788b.
[1] https://lore.kernel.org/all/CAOUHufbkhMZYz20aM_3rHZ3OcK4m2puji2FGpUpn_-DevGk3Kg@mail.gmail.com/
[2] https://lore.kernel.org/all/[email protected]/
--- mm/vmscan.c | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-)
mm/vmscan.c +2 -22
@@ -1604,25 +1604,6 @@ static __always_inline void update_lru_sizes(struct lruvec *lruvec, } -#ifdef CONFIG_CMA -/* -* It is waste of effort to scan and reclaim CMA pages if it is not available -* for current allocation context. Kswapd can not be enrolled as it can not -* distinguish this scenario by using sc->gfp_mask = GFP_KERNEL -*/ -static bool skip_cma (struct folio *folio,struct scan_control *sc) -{ -return !current_is_kswapd () && -gfp_migratetype (sc->gfp_mask) !=MIGRATE_MOVABLE && -folio_migratetype (folio) ==MIGRATE_CMA ; -} -#else -static bool skip_cma (struct folio *folio,struct scan_control *sc) -{ -return false; -} -#endif -/* * Isolating page from the lruvec to fill in @dst list by nr_to_scan times. *
@@ -1669,8 +1650,7 @@ static unsigned long isolate_lru_folios(unsigned long nr_to_scan, nr_pages =folio_nr_pages (folio); total_scan += nr_pages; -if (folio_zonenum (folio) > sc->reclaim_idx || -skip_cma (folio, sc)) { +if (folio_zonenum (folio) > sc->reclaim_idx) { nr_skipped[folio_zonenum (folio)] += nr_pages; move_to = &folios_skipped; goto move;
@@ -4320,7 +4300,7 @@ static bool sort_folio(struct lruvec *lruvec, struct folio *folio, struct scan_c }/* ineligible */ -if (zone > sc->reclaim_idx ||skip_cma (folio, sc)) { +if (zone > sc->reclaim_idx) { gen =folio_inc_gen (lruvec, folio, false);list_move_tail (&folio->lru, &lrugen->folios[gen][type][zone]);return true;
Signature · 1 line
2.43.5
kernel test robot
build botkernel test robot noticed the following build warnings:
Hi Usama,
kernel test robot noticed the following build warnings:
[auto build test WARNING on akpm-mm/mm-everything]
[also build test WARNING on linus/master v6.11-rc4 next-20240822] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Usama-Arif/Revert-mm-skip-CMA-pages-when-they-are-not-available/20240822-033718 base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything patch link: https://lore.kernel.org/r/20240821193506.1525996-1-usamaarif642%40gmail.com patch subject: [PATCH] Revert "mm: skip CMA pages when they are not available" config: openrisc-allnoconfig (https://download.01.org/0day-ci/archive/20240822/[email protected]/config) compiler: or1k-linux-gcc (GCC) 14.1.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240822/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
>> mm/vmscan.c:1641:13: warning: 'skip_cma' defined but not used [-Wunused-function]
1641 | static bool skip_cma(struct folio *folio, struct scan_control *sc)
| ^~~~~~~~
vim +/skip_cma +1641 mm/vmscan.c
b4536f0c829c85 Michal Hocko 2017-01-10 1627
5da226dbfce3a2 Zhaoyang Huang 2023-05-31 1628 #ifdef CONFIG_CMA
5da226dbfce3a2 Zhaoyang Huang 2023-05-31 1629 /*
5da226dbfce3a2 Zhaoyang Huang 2023-05-31 1630 * It is waste of effort to scan and reclaim CMA pages if it is not available
5da226dbfce3a2 Zhaoyang Huang 2023-05-31 1631 * for current allocation context. Kswapd can not be enrolled as it can not
5da226dbfce3a2 Zhaoyang Huang 2023-05-31 1632 * distinguish this scenario by using sc->gfp_mask = GFP_KERNEL
5da226dbfce3a2 Zhaoyang Huang 2023-05-31 1633 */
5da226dbfce3a2 Zhaoyang Huang 2023-05-31 1634 static bool skip_cma(struct folio *folio, struct scan_control *sc)
5da226dbfce3a2 Zhaoyang Huang 2023-05-31 1635 {
5da226dbfce3a2 Zhaoyang Huang 2023-05-31 1636 return !current_is_kswapd() &&
5da226dbfce3a2 Zhaoyang Huang 2023-05-31 1637 gfp_migratetype(sc->gfp_mask) != MIGRATE_MOVABLE &&
97144ce008f918 Vern Hao 2023-08-25 1638 folio_migratetype(folio) == MIGRATE_CMA;
5da226dbfce3a2 Zhaoyang Huang 2023-05-31 1639 }
5da226dbfce3a2 Zhaoyang Huang 2023-05-31 1640 #else
5da226dbfce3a2 Zhaoyang Huang 2023-05-31 @1641 static bool skip_cma(struct folio *folio, struct scan_control *sc)
5da226dbfce3a2 Zhaoyang Huang 2023-05-31 1642 {
5da226dbfce3a2 Zhaoyang Huang 2023-05-31 1643 return false;
5da226dbfce3a2 Zhaoyang Huang 2023-05-31 1644 }
5da226dbfce3a2 Zhaoyang Huang 2023-05-31 1645 #endif5da226dbfce3a2 Zhaoyang Huang 2023-05-31 1646
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki