mm/damon: have damon_get_folio return folio even for tail pages
Subsystems (2)
PATCH 1/2 mm/damon: have damon_get_folio return folio even for tail pages
This effectively adds support for large folios in damon for paddr, as damon_pa_mkold/young won't get a null folio from this function and won't ignore it, hence access will be checked and reported. This also means that larger folios will be considered for different DAMOS actions like pageout, prioritization and migration. As these DAMOS actions will consider larger folios, iterate through the region at folio_size and not PAGE_SIZE intervals. This should not have an affect on vaddr, as damon_young_pmd_entry considers pmd entries.
--- mm/damon/ops-common.c | 2 +- mm/damon/paddr.c | 24 ++++++++++++++++++------ 2 files changed, 19 insertions(+), 7 deletions(-)
mm/damon/ops-common.c +1 -1
@@ -24,7 +24,7 @@ struct folio *damon_get_folio(unsigned long pfn)struct page *page =pfn_to_online_page (pfn);struct folio *folio; -if (!page ||PageTail (page)) +if (!page)return NULL ; folio =page_folio (page);
mm/damon/paddr.c +18 -6
@@ -266,11 +266,14 @@ static unsigned long damon_pa_pageout(struct damon_region *r, struct damos *s,damos_add_filter (s, filter); } -for (addr = r->ar.start; addr < r->ar.end; addr +=PAGE_SIZE ) { + addr = r->ar.start; +while (addr < r->ar.end) {struct folio *folio =damon_get_folio (PHYS_PFN (addr)); -if (!folio) +if (!folio) { + addr +=PAGE_SIZE ;continue ; + }if (damos_pa_filter_out (s, folio)) goto put_folio;
@@ -286,6 +289,7 @@ static unsigned long damon_pa_pageout(struct damon_region *r, struct damos *s,else list_add (&folio->lru, &folio_list); put_folio: + addr +=folio_size (folio);folio_put (folio); }if (install_young_filter)
@@ -301,11 +305,14 @@ static inline unsigned long damon_pa_mark_accessed_or_deactivate( {unsigned long addr, applied =0 ; -for (addr = r->ar.start; addr < r->ar.end; addr +=PAGE_SIZE ) { + addr = r->ar.start; +while (addr < r->ar.end) {struct folio *folio =damon_get_folio (PHYS_PFN (addr)); -if (!folio) +if (!folio) { + addr +=PAGE_SIZE ;continue ; + }if (damos_pa_filter_out (s, folio)) goto put_folio;
@@ -318,6 +325,7 @@ static inline unsigned long damon_pa_mark_accessed_or_deactivate(folio_deactivate (folio); applied +=folio_nr_pages (folio); put_folio: + addr +=folio_size (folio);folio_put (folio); }return applied *PAGE_SIZE ;
@@ -464,11 +472,14 @@ static unsigned long damon_pa_migrate(struct damon_region *r, struct damos *s,unsigned long addr, applied;LIST_HEAD (folio_list); -for (addr = r->ar.start; addr < r->ar.end; addr +=PAGE_SIZE ) { + addr = r->ar.start; +while (addr < r->ar.end) {struct folio *folio =damon_get_folio (PHYS_PFN (addr)); -if (!folio) +if (!folio) { + addr +=PAGE_SIZE ;continue ; + }if (damos_pa_filter_out (s, folio)) goto put_folio;
@@ -479,6 +490,7 @@ static unsigned long damon_pa_migrate(struct damon_region *r, struct damos *s, goto put_folio;list_add (&folio->lru, &folio_list); put_folio: + addr +=folio_size (folio);folio_put (folio); } applied =damon_pa_migrate_pages (&folio_list, s->target_nid);
Signature · 1 line
2.43.5
PATCH 2/2 mm/damon: introduce DAMOS filter type hugepage
This is to gather statistics to check if hotest memory regions are backed by hugepages. This includes both THPs and hugetlbfs. This filter can help to observe and prove the effectivenes of different schemes for shrinking/collapsing hugepages.
--- include/linux/damon.h | 2 ++ mm/damon/paddr.c | 3 +++ mm/damon/sysfs-schemes.c | 1 + 3 files changed, 6 insertions(+)
include/linux/damon.h +2 -0
@@ -326,6 +326,7 @@ struct damos_stat {* @DAMOS_FILTER_TYPE_ANON: Anonymous pages. * @DAMOS_FILTER_TYPE_MEMCG: Specific memcg's pages. * @DAMOS_FILTER_TYPE_YOUNG: Recently accessed pages. +* @DAMOS_FILTER_TYPE_HUGEPAGE: Page is part of a hugepage. * @DAMOS_FILTER_TYPE_ADDR: Address range. * @DAMOS_FILTER_TYPE_TARGET: Data Access Monitoring target. * @NR_DAMOS_FILTER_TYPES: Number of filter types.
@@ -345,6 +346,7 @@ enum damos_filter_type {DAMOS_FILTER_TYPE_ANON ,DAMOS_FILTER_TYPE_MEMCG ,DAMOS_FILTER_TYPE_YOUNG , +DAMOS_FILTER_TYPE_HUGEPAGE ,DAMOS_FILTER_TYPE_ADDR ,DAMOS_FILTER_TYPE_TARGET , NR_DAMOS_FILTER_TYPES,
mm/damon/paddr.c +3 -0
@@ -222,6 +222,9 @@ static bool damos_pa_filter_match(struct damos_filter *filter,if (matched)damon_folio_mkold (folio);break ; +case DAMOS_FILTER_TYPE_HUGEPAGE : + matched =folio_size (folio) ==HPAGE_PMD_SIZE ; +break ;default :break ; }
mm/damon/sysfs-schemes.c +1 -0
@@ -329,6 +329,7 @@ static const char * const damon_sysfs_scheme_filter_type_strs[] = {"anon" ,"memcg" ,"young" , +"hugepage" ,"addr" , "target", };
Signature · 1 line
2.43.5
Re: [v1 2/2] mm/damon: introduce DAMOS filter type hugepage
Quoted 11 lines · Usama Arif
This is to gather statistics to check if hotest memory regions are backed by hugepages. This includes both THPs and hugetlbfs. This filter can help to observe and prove the effectivenes of different schemes for shrinking/collapsing hugepages.
Signed-off-by Usama Arif <[email protected]>--- include/linux/damon.h | 2 ++ mm/damon/paddr.c | 3 +++ mm/damon/sysfs-schemes.c | 1 + 3 files changed, 6 insertions(+)
The corresponding DAMO PR is at https://github.com/damonitor/damo/pull/19
SeongJae Park
maintainerRe: [v1 2/2] mm/damon: introduce DAMOS filter type hugepage
Quoted 8 lines · On Thu, 16 Jan 2025 15:15:21 +0000 Usama Arif <[email protected]> wrote:
Quoted 5 lines · Usama Arif
This is to gather statistics to check if hotest memory regions are backed by hugepages. This includes both THPs and hugetlbfs. This filter can help to observe and prove the effectivenes of different schemes for shrinking/collapsing hugepages.
Quoted 8 lines
Quoted 6 lines
Signed-off-by Usama Arif <[email protected]>--- include/linux/damon.h | 2 ++ mm/damon/paddr.c | 3 +++ mm/damon/sysfs-schemes.c | 1 + 3 files changed, 6 insertions(+)The corresponding DAMO PR is at https://github.com/damonitor/damo/pull/19
Thank you for taking care of the user-space tool together! I will do review on the PR.
Thanks,
SJ
SeongJae Park
maintainerRe: [v1 2/2] mm/damon: introduce DAMOS filter type hugepage
In reply to Usama ArifQuoted 1 line · On Thu, 16 Jan 2025 14:44:36 +0000 Usama Arif <[email protected]> wrote:
This is to gather statistics to check if hotest memory regions
s/hotest/hottest/?
Quoted 1 line
are backed by hugepages.
This would also be useful for not only hottest memory regions but general memory regions of specific access temperature. I like this.
Quoted 3 lines
This includes both THPs and hugetlbfs.
This filter can help to observe and prove the effectivenes of different schemes for shrinking/collapsing hugepages.
Nice extension of DAMON's page level properties based monitoring!
Quoted 33 lines
Signed-off-by Usama Arif <[email protected]>--- include/linux/damon.h | 2 ++ mm/damon/paddr.c | 3 +++ mm/damon/sysfs-schemes.c | 1 + 3 files changed, 6 insertions(+)include/linux/damon.h +2
-0@@ -326,6 +326,7 @@ struct damos_stat {* @DAMOS_FILTER_TYPE_ANON: Anonymous pages. * @DAMOS_FILTER_TYPE_MEMCG: Specific memcg's pages. * @DAMOS_FILTER_TYPE_YOUNG: Recently accessed pages. +* @DAMOS_FILTER_TYPE_HUGEPAGE: Page is part of a hugepage. * @DAMOS_FILTER_TYPE_ADDR: Address range. * @DAMOS_FILTER_TYPE_TARGET: Data Access Monitoring target. * @NR_DAMOS_FILTER_TYPES: Number of filter types. @@ -345,6 +346,7 @@ enum damos_filter_type {DAMOS_FILTER_TYPE_ANON ,DAMOS_FILTER_TYPE_MEMCG ,DAMOS_FILTER_TYPE_YOUNG , +DAMOS_FILTER_TYPE_HUGEPAGE ,DAMOS_FILTER_TYPE_ADDR ,DAMOS_FILTER_TYPE_TARGET , NR_DAMOS_FILTER_TYPES,mm/damon/paddr.c +0
-0
mm/damon/paddr.c static bool damos_pa_filter_match(struct damos_filter *filter, · line 227
Quoted 6 lines
mm/damon/paddr.c +3
-0@@ -222,6 +222,9 @@ static bool damos_pa_filter_match(struct damos_filter *filter,if (matched)damon_folio_mkold (folio);break ; +case DAMOS_FILTER_TYPE_HUGEPAGE : + matched =folio_size (folio) ==HPAGE_PMD_SIZE ; +break ;
This will make build fails when CONFIG_PGTABLE_HAS_HUGE_LEAVES is not set, like below:
/include/linux/compiler_types.h:542:45: error: call to ‘__compiletime_assert_321’ declared with attribute error: BUILD_BUG failed
542 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ^
[...]
/include/linux/huge_mm.h:111:35: note: in expansion of macro ‘HPAGE_PMD_SHIFT’
111 | #define HPAGE_PMD_SIZE ((1UL) << HPAGE_PMD_SHIFT)
| ^~~~~~~~~~~~~~~
/mm/damon/paddr.c:321:48: note: in expansion of macro ‘HPAGE_PMD_SIZE’
321 | matched = folio_size(folio) == HPAGE_PMD_SIZE;
| ^~~~~~~~~~~~~~
This simple test might help you reproducing it:
https://github.com/damonitor/damon-tests/blob/master/corr/tests/build_i386.sh
What about enclosing the entire case with
#if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_HUGETLB_PAGE) ?
Quoted 8 lines
mm/damon/paddr.c +0
-0default :break ; }mm/damon/sysfs-schemes.c +0
-0
mm/damon/sysfs-schemes.c static const char * const damon_sysfs_scheme_filter_type_strs[] = { · line 335
Quoted 7 lines
mm/damon/sysfs-schemes.c +1
-0@@ -329,6 +329,7 @@ static const char * const damon_sysfs_scheme_filter_type_strs[] = {"anon" ,"memcg" ,"young" , +"hugepage" ,"addr" , "target", };
Other parts look good to me :)
Thanks,
SJ
[...]
Re: [v1 2/2] mm/damon: introduce DAMOS filter type hugepage
Quoted 29 lines · SeongJae Park
mm/damon/paddr.c static bool damos_pa_filter_match(struct damos_filter *filter, · line 227
Quoted 11 lines · On Thu, 16 Jan 2025 14:44:36 +0000 Usama Arif <[email protected]> wrote:
mm/damon/paddr.c +3
-0@@ -222,6 +222,9 @@ static bool damos_pa_filter_match(struct damos_filter *filter,if (matched)damon_folio_mkold (folio);break ; +case DAMOS_FILTER_TYPE_HUGEPAGE : + matched =folio_size (folio) ==HPAGE_PMD_SIZE ; +break ;This will make build fails when
CONFIG_PGTABLE_HAS_HUGE_LEAVESis not set, like below:/include/linux/compiler_types.h:542:45: error: call to ‘__compiletime_assert_321’ declared with attribute error:
BUILD_BUGfailed
542 |_compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ^
[...]
/include/linux/huge_mm.h:111:35: note: in expansion of macro ‘HPAGE_PMD_SHIFT’
111 | #defineHPAGE_PMD_SIZE((1UL) <<HPAGE_PMD_SHIFT)| ^~~~~~~~~~~~~~~/mm/damon/paddr.c:321:48: note: in expansion of macro ‘HPAGE_PMD_SIZE’
321 | matched =folio_size(folio)==HPAGE_PMD_SIZE;
| ^~~~~~~~~~~~~~
Quoted 7 lines
This simple test might help you reproducing it:
https://github.com/damonitor/damon-tests/blob/master/corr/tests/build_i386.shWhat about enclosing the entire case with
#if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_HUGETLB_PAGE) ?
Ah Thanks for pointing this out! Would
#if defined(CONFIG_PGTABLE_HAS_HUGE_LEAVES)
be better?
SeongJae Park
maintainerRe: [v1 2/2] mm/damon: introduce DAMOS filter type hugepage
Quoted 37 lines · On Fri, 17 Jan 2025 11:02:05 +0000 Usama Arif <[email protected]> wrote:
Quoted 34 lines · SeongJae Park
mm/damon/paddr.c static bool damos_pa_filter_match(struct damos_filter *filter, · line 227
Quoted 11 lines · On Thu, 16 Jan 2025 14:44:36 +0000 Usama Arif <[email protected]> wrote:
mm/damon/paddr.c +3
-0@@ -222,6 +222,9 @@ static bool damos_pa_filter_match(struct damos_filter *filter,if (matched)damon_folio_mkold (folio);break ; +case DAMOS_FILTER_TYPE_HUGEPAGE : + matched =folio_size (folio) ==HPAGE_PMD_SIZE ; +break ;This will make build fails when
CONFIG_PGTABLE_HAS_HUGE_LEAVESis not set, like below:/include/linux/compiler_types.h:542:45: error: call to ‘__compiletime_assert_321’ declared with attribute error:
BUILD_BUGfailed
542 |_compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ^
[...]
/include/linux/huge_mm.h:111:35: note: in expansion of macro ‘HPAGE_PMD_SHIFT’
111 | #defineHPAGE_PMD_SIZE((1UL) <<HPAGE_PMD_SHIFT)| ^~~~~~~~~~~~~~~/mm/damon/paddr.c:321:48: note: in expansion of macro ‘HPAGE_PMD_SIZE’
321 | matched =folio_size(folio)==HPAGE_PMD_SIZE;
| ^~~~~~~~~~~~~~This simple test might help you reproducing it:
https://github.com/damonitor/damon-tests/blob/master/corr/tests/build_i386.shWhat about enclosing the entire case with
Quoted 8 lines
Quoted 2 lines
#if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_HUGETLB_PAGE) ?Ah Thanks for pointing this out! Would
#if
defined(CONFIG_PGTABLE_HAS_HUGE_LEAVES)be better?
Yes, that also looks good to me :)
Thanks,
SJ
kernel test robot
build botRe: [v1 2/2] mm/damon: introduce DAMOS filter type hugepage
In reply to Usama Arifkernel test robot noticed the following build errors:
Hi Usama,
kernel test robot noticed the following build errors:
[auto build test ERROR on akpm-mm/mm-everything]
url: https://github.com/intel-lab-lkp/linux/commits/Usama-Arif/mm-damon-introduce-DAMOS-filter-type-hugepage/20250116-224546 base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything patch link: https://lore.kernel.org/r/20250116144436.3947318-2-usamaarif642%40gmail.com patch subject: [v1 2/2] mm/damon: introduce DAMOS filter type hugepage config: i386-randconfig-014-20250118 (https://download.01.org/0day-ci/archive/20250118/[email protected]/config) compiler: clang version 19.1.3 (https://github.com/llvm/llvm-project ab51eccf88f5321e7c60591c5546b254b6afab99) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250118/[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 errors (new ones prefixed by >>):
In file included from mm/damon/paddr.c:12:
In file included from include/linux/pagemap.h:8:
In file included from include/linux/mm.h:2224:
include/linux/vmstat.h:504:43: warning: arithmetic between different enumeration types ('enum zone_stat_item' and 'enum numa_stat_item') [-Wenum-enum-conversion]
504 | return vmstat_text[NR_VM_ZONE_STAT_ITEMS +
| ~~~~~~~~~~~~~~~~~~~~~ ^
505 | item];
| ~~~~
include/linux/vmstat.h:511:43: warning: arithmetic between different enumeration types ('enum zone_stat_item' and 'enum numa_stat_item') [-Wenum-enum-conversion]
511 | return vmstat_text[NR_VM_ZONE_STAT_ITEMS +
| ~~~~~~~~~~~~~~~~~~~~~ ^
512 | NR_VM_NUMA_EVENT_ITEMS +
| ~~~~~~~~~~~~~~~~~~~~~~
include/linux/vmstat.h:524:43: warning: arithmetic between different enumeration types ('enum zone_stat_item' and 'enum numa_stat_item') [-Wenum-enum-conversion]
524 | return vmstat_text[NR_VM_ZONE_STAT_ITEMS +
| ~~~~~~~~~~~~~~~~~~~~~ ^
525 | NR_VM_NUMA_EVENT_ITEMS +
| ~~~~~~~~~~~~~~~~~~~~~~
In file included from mm/damon/paddr.c:17:
include/linux/mm_inline.h:47:41: warning: arithmetic between different enumeration types ('enum node_stat_item' and 'enum lru_list') [-Wenum-enum-conversion]
47 | __mod_lruvec_state(lruvec, NR_LRU_BASE + lru, nr_pages);
| ~~~~~~~~~~~ ^ ~~~
include/linux/mm_inline.h:49:22: warning: arithmetic between different enumeration types ('enum zone_stat_item' and 'enum lru_list') [-Wenum-enum-conversion]
49 | NR_ZONE_LRU_BASE + lru, nr_pages);
| ~~~~~~~~~~~~~~~~ ^ ~~~
5 warnings generated.
>> ld.lld: error: call to __compiletime_assert_374 marked "dontcall-error": BUILD_BUG failedSignature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
kernel test robot
build botRe: [v1 2/2] mm/damon: introduce DAMOS filter type hugepage
In reply to Usama Arifkernel test robot noticed the following build errors:
Hi Usama,
kernel test robot noticed the following build errors:
[auto build test ERROR on akpm-mm/mm-everything]
url: https://github.com/intel-lab-lkp/linux/commits/Usama-Arif/mm-damon-introduce-DAMOS-filter-type-hugepage/20250116-224546 base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything patch link: https://lore.kernel.org/r/20250116144436.3947318-2-usamaarif642%40gmail.com patch subject: [v1 2/2] mm/damon: introduce DAMOS filter type hugepage config: x86_64-randconfig-077-20250118 (https://download.01.org/0day-ci/archive/20250118/[email protected]/config) compiler: clang version 19.1.3 (https://github.com/llvm/llvm-project ab51eccf88f5321e7c60591c5546b254b6afab99) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250118/[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 errors (new ones prefixed by >>):
In file included from mm/damon/paddr.c:17:
include/linux/mm_inline.h:47:41: warning: arithmetic between different enumeration types ('enum node_stat_item' and 'enum lru_list') [-Wenum-enum-conversion]
47 | __mod_lruvec_state(lruvec, NR_LRU_BASE + lru, nr_pages);
| ~~~~~~~~~~~ ^ ~~~
include/linux/mm_inline.h:49:22: warning: arithmetic between different enumeration types ('enum zone_stat_item' and 'enum lru_list') [-Wenum-enum-conversion]
49 | NR_ZONE_LRU_BASE + lru, nr_pages);
| ~~~~~~~~~~~~~~~~ ^ ~~~
>> mm/damon/paddr.c:226:34: error: call to '__compiletime_assert_603' declared with 'error' attribute: BUILD_BUG failed
226 | matched = folio_size(folio) == HPAGE_PMD_SIZE;
| ^
include/linux/huge_mm.h:111:34: note: expanded from macro 'HPAGE_PMD_SIZE'
111 | #define HPAGE_PMD_SIZE ((1UL) << HPAGE_PMD_SHIFT)
| ^
include/linux/huge_mm.h:104:28: note: expanded from macro 'HPAGE_PMD_SHIFT'
104 | #define HPAGE_PMD_SHIFT ({ BUILD_BUG(); 0; })
| ^
include/linux/build_bug.h:59:21: note: expanded from macro 'BUILD_BUG'
59 | #define BUILD_BUG() BUILD_BUG_ON_MSG(1, "BUILD_BUG failed")
| ^
note: (skipping 2 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
include/linux/compiler_types.h:530:2: note: expanded from macro '_compiletime_assert'
530 | __compiletime_assert(condition, msg, prefix, suffix)
| ^
include/linux/compiler_types.h:523:4: note: expanded from macro '__compiletime_assert'
523 | prefix ## suffix(); \
| ^
<scratch space>:50:1: note: expanded from here
50 | __compiletime_assert_603
| ^2 warnings and 1 error generated.
vim +226 mm/damon/paddr.c
200
201 static bool damos_pa_filter_match(struct damos_filter *filter,
202 struct folio *folio)
203 {
204 bool matched = false;
205 struct mem_cgroup *memcg;
206
207 switch (filter->type) {
208 case DAMOS_FILTER_TYPE_ANON:
209 matched = folio_test_anon(folio);
210 break;
211 case DAMOS_FILTER_TYPE_MEMCG:
212 rcu_read_lock();
213 memcg = folio_memcg_check(folio);
214 if (!memcg)
215 matched = false;
216 else
217 matched = filter->memcg_id == mem_cgroup_id(memcg);
218 rcu_read_unlock();
219 break;
220 case DAMOS_FILTER_TYPE_YOUNG:
221 matched = damon_folio_young(folio);
222 if (matched)
223 damon_folio_mkold(folio);
224 break;
225 case DAMOS_FILTER_TYPE_HUGEPAGE:
> 226 matched = folio_size(folio) == HPAGE_PMD_SIZE;
227 break;
228 default:
229 break;
230 }
231
232 return matched == filter->matching;
233 }
234
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Quoted 9 lines · On Thu, 16 Jan 2025 14:44:35 +0000 Usama Arif <[email protected]> wrote:
This effectively adds support for large folios in damon for paddr, as damon_pa_mkold/young won't get a null folio from this function and won't ignore it, hence access will be checked and reported. This also means that larger folios will be considered for different DAMOS actions like pageout, prioritization and migration. As these DAMOS actions will consider larger folios, iterate through the region at
folio_sizeand notPAGE_SIZEintervals. This should not have an affect on vaddr, asdamon_young_pmd_entryconsiders pmd entries.
This patch will improve both accuracy of monitoring results and efficiency of DAMOS for paddr use cases on THP-enabled systems. Thank you Usama!
Quoted 2 lines
Signed-off-by Usama Arif <[email protected]>
Thanks,
SJ
[...]