mm/damon/paddr: move probe filter handling to ops-common

Probe filter matching logic for anon and memcg type filters in DAMON's
physical address space operation set (paddr) can be reused by virtual
address space operation set (vaddr) in future.  Prepare the future by
moving the code to ops-common.c

Link: https://lore.kernel.org/20260909140408.104699-3-sj@kernel.org
Signed-off-by: SJ Park <sj@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Cc: Gutierrez Asier <gutierrez.asier@huawei-partners.com>
This commit is contained in:
SJ Park 2026-09-09 07:04:04 -07:00 committed by Andrew Morton
parent df8060e665
commit ed1ddfa3e8
3 changed files with 35 additions and 22 deletions

View File

@ -531,3 +531,35 @@ bool damos_ops_has_filter(struct damos *s)
return true;
return false;
}
bool damon_ops_filter_match(struct damon_filter *filter, struct folio *folio)
{
bool matched = false;
struct mem_cgroup *memcg;
switch (filter->type) {
case DAMON_FILTER_TYPE_ANON:
if (!folio) {
matched = false;
break;
}
matched = folio_test_anon(folio);
break;
case DAMON_FILTER_TYPE_MEMCG:
if (!folio) {
matched = false;
break;
}
rcu_read_lock();
memcg = folio_memcg_check(folio);
if (!memcg)
matched = false;
else
matched = filter->memcg_id == mem_cgroup_id(memcg);
rcu_read_unlock();
break;
default:
break;
}
return matched == filter->matching;
}

View File

@ -31,3 +31,5 @@ bool damos_folio_filter_match(struct damos_filter *filter, struct folio *folio);
unsigned long damon_migrate_pages(struct list_head *folio_list, int target_nid);
bool damos_ops_has_filter(struct damos *s);
bool damon_ops_filter_match(struct damon_filter *filter, struct folio *folio);

View File

@ -143,29 +143,8 @@ static bool damon_pa_filter_match(struct damon_filter *filter,
struct folio *folio)
{
bool matched = false;
struct mem_cgroup *memcg;
switch (filter->type) {
case DAMON_FILTER_TYPE_ANON:
if (!folio) {
matched = false;
break;
}
matched = folio_test_anon(folio);
break;
case DAMON_FILTER_TYPE_MEMCG:
if (!folio) {
matched = false;
break;
}
rcu_read_lock();
memcg = folio_memcg_check(folio);
if (!memcg)
matched = false;
else
matched = filter->memcg_id == mem_cgroup_id(memcg);
rcu_read_unlock();
break;
case DAMON_FILTER_TYPE_PGIDLE_UNSET:
if (!folio)
matched = false;
@ -173,7 +152,7 @@ static bool damon_pa_filter_match(struct damon_filter *filter,
matched = damon_folio_young(folio);
break;
default:
break;
return damon_ops_filter_match(filter, folio);
}
return matched == filter->matching;
}