@@ -202,7 +202,47 @@ static unsigned int damon_pa_check_accesses(struct damon_ctx *ctx)
202202 return max_nr_accesses ;
203203}
204204
205- static unsigned long damon_pa_pageout (struct damon_region * r )
205+ static bool __damos_pa_filter_out (struct damos_filter * filter ,
206+ struct page * page )
207+ {
208+ bool matched = false;
209+ struct mem_cgroup * memcg ;
210+
211+ switch (filter -> type ) {
212+ case DAMOS_FILTER_TYPE_ANON :
213+ matched = PageAnon (page );
214+ break ;
215+ case DAMOS_FILTER_TYPE_MEMCG :
216+ rcu_read_lock ();
217+ memcg = page_memcg_check (page );
218+ if (!memcg )
219+ matched = false;
220+ else
221+ matched = filter -> memcg_id == mem_cgroup_id (memcg );
222+ rcu_read_unlock ();
223+ break ;
224+ default :
225+ break ;
226+ }
227+
228+ return matched == filter -> matching ;
229+ }
230+
231+ /*
232+ * damos_pa_filter_out - Return true if the page should be filtered out.
233+ */
234+ static bool damos_pa_filter_out (struct damos * scheme , struct page * page )
235+ {
236+ struct damos_filter * filter ;
237+
238+ damos_for_each_filter (filter , scheme ) {
239+ if (__damos_pa_filter_out (filter , page ))
240+ return true;
241+ }
242+ return false;
243+ }
244+
245+ static unsigned long damon_pa_pageout (struct damon_region * r , struct damos * s )
206246{
207247 unsigned long addr , applied ;
208248 LIST_HEAD (page_list );
@@ -213,6 +253,11 @@ static unsigned long damon_pa_pageout(struct damon_region *r)
213253 if (!page )
214254 continue ;
215255
256+ if (damos_pa_filter_out (s , page )) {
257+ put_page (page );
258+ continue ;
259+ }
260+
216261 ClearPageReferenced (page );
217262 test_and_clear_page_young (page );
218263 if (isolate_lru_page (page )) {
@@ -232,7 +277,7 @@ static unsigned long damon_pa_pageout(struct damon_region *r)
232277}
233278
234279static inline unsigned long damon_pa_mark_accessed_or_deactivate (
235- struct damon_region * r , bool mark_accessed )
280+ struct damon_region * r , struct damos * s , bool mark_accessed )
236281{
237282 unsigned long addr , applied = 0 ;
238283
@@ -241,6 +286,12 @@ static inline unsigned long damon_pa_mark_accessed_or_deactivate(
241286
242287 if (!page )
243288 continue ;
289+
290+ if (damos_pa_filter_out (s , page )) {
291+ put_page (page );
292+ continue ;
293+ }
294+
244295 if (mark_accessed )
245296 mark_page_accessed (page );
246297 else
@@ -251,14 +302,16 @@ static inline unsigned long damon_pa_mark_accessed_or_deactivate(
251302 return applied * PAGE_SIZE ;
252303}
253304
254- static unsigned long damon_pa_mark_accessed (struct damon_region * r )
305+ static unsigned long damon_pa_mark_accessed (struct damon_region * r ,
306+ struct damos * s )
255307{
256- return damon_pa_mark_accessed_or_deactivate (r , true);
308+ return damon_pa_mark_accessed_or_deactivate (r , s , true);
257309}
258310
259- static unsigned long damon_pa_deactivate_pages (struct damon_region * r )
311+ static unsigned long damon_pa_deactivate_pages (struct damon_region * r ,
312+ struct damos * s )
260313{
261- return damon_pa_mark_accessed_or_deactivate (r , false);
314+ return damon_pa_mark_accessed_or_deactivate (r , s , false);
262315}
263316
264317static unsigned long damon_pa_apply_scheme (struct damon_ctx * ctx ,
@@ -267,11 +320,11 @@ static unsigned long damon_pa_apply_scheme(struct damon_ctx *ctx,
267320{
268321 switch (scheme -> action ) {
269322 case DAMOS_PAGEOUT :
270- return damon_pa_pageout (r );
323+ return damon_pa_pageout (r , scheme );
271324 case DAMOS_LRU_PRIO :
272- return damon_pa_mark_accessed (r );
325+ return damon_pa_mark_accessed (r , scheme );
273326 case DAMOS_LRU_DEPRIO :
274- return damon_pa_deactivate_pages (r );
327+ return damon_pa_deactivate_pages (r , scheme );
275328 case DAMOS_STAT :
276329 break ;
277330 default :
0 commit comments