~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/mm/damon/ops-common.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0
  2 /*
  3  * Common Primitives for Data Access Monitoring
  4  *
  5  * Author: SeongJae Park <sj@kernel.org>
  6  */
  7 
  8 #include <linux/mmu_notifier.h>
  9 #include <linux/page_idle.h>
 10 #include <linux/pagemap.h>
 11 #include <linux/rmap.h>
 12 
 13 #include "ops-common.h"
 14 
 15 /*
 16  * Get an online page for a pfn if it's in the LRU list.  Otherwise, returns
 17  * NULL.
 18  *
 19  * The body of this function is stolen from the 'page_idle_get_folio()'.  We
 20  * steal rather than reuse it because the code is quite simple.
 21  */
 22 struct folio *damon_get_folio(unsigned long pfn)
 23 {
 24         struct page *page = pfn_to_online_page(pfn);
 25         struct folio *folio;
 26 
 27         if (!page || PageTail(page))
 28                 return NULL;
 29 
 30         folio = page_folio(page);
 31         if (!folio_test_lru(folio) || !folio_try_get(folio))
 32                 return NULL;
 33         if (unlikely(page_folio(page) != folio || !folio_test_lru(folio))) {
 34                 folio_put(folio);
 35                 folio = NULL;
 36         }
 37         return folio;
 38 }
 39 
 40 void damon_ptep_mkold(pte_t *pte, struct vm_area_struct *vma, unsigned long addr)
 41 {
 42         struct folio *folio = damon_get_folio(pte_pfn(ptep_get(pte)));
 43 
 44         if (!folio)
 45                 return;
 46 
 47         if (ptep_clear_young_notify(vma, addr, pte))
 48                 folio_set_young(folio);
 49 
 50         folio_set_idle(folio);
 51         folio_put(folio);
 52 }
 53 
 54 void damon_pmdp_mkold(pmd_t *pmd, struct vm_area_struct *vma, unsigned long addr)
 55 {
 56 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
 57         struct folio *folio = damon_get_folio(pmd_pfn(pmdp_get(pmd)));
 58 
 59         if (!folio)
 60                 return;
 61 
 62         if (pmdp_clear_young_notify(vma, addr, pmd))
 63                 folio_set_young(folio);
 64 
 65         folio_set_idle(folio);
 66         folio_put(folio);
 67 #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
 68 }
 69 
 70 #define DAMON_MAX_SUBSCORE      (100)
 71 #define DAMON_MAX_AGE_IN_LOG    (32)
 72 
 73 int damon_hot_score(struct damon_ctx *c, struct damon_region *r,
 74                         struct damos *s)
 75 {
 76         int freq_subscore;
 77         unsigned int age_in_sec;
 78         int age_in_log, age_subscore;
 79         unsigned int freq_weight = s->quota.weight_nr_accesses;
 80         unsigned int age_weight = s->quota.weight_age;
 81         int hotness;
 82 
 83         freq_subscore = r->nr_accesses * DAMON_MAX_SUBSCORE /
 84                 damon_max_nr_accesses(&c->attrs);
 85 
 86         age_in_sec = (unsigned long)r->age * c->attrs.aggr_interval / 1000000;
 87         for (age_in_log = 0; age_in_log < DAMON_MAX_AGE_IN_LOG && age_in_sec;
 88                         age_in_log++, age_in_sec >>= 1)
 89                 ;
 90 
 91         /* If frequency is 0, higher age means it's colder */
 92         if (freq_subscore == 0)
 93                 age_in_log *= -1;
 94 
 95         /*
 96          * Now age_in_log is in [-DAMON_MAX_AGE_IN_LOG, DAMON_MAX_AGE_IN_LOG].
 97          * Scale it to be in [0, 100] and set it as age subscore.
 98          */
 99         age_in_log += DAMON_MAX_AGE_IN_LOG;
100         age_subscore = age_in_log * DAMON_MAX_SUBSCORE /
101                 DAMON_MAX_AGE_IN_LOG / 2;
102 
103         hotness = (freq_weight * freq_subscore + age_weight * age_subscore);
104         if (freq_weight + age_weight)
105                 hotness /= freq_weight + age_weight;
106         /*
107          * Transform it to fit in [0, DAMOS_MAX_SCORE]
108          */
109         hotness = hotness * DAMOS_MAX_SCORE / DAMON_MAX_SUBSCORE;
110 
111         return hotness;
112 }
113 
114 int damon_cold_score(struct damon_ctx *c, struct damon_region *r,
115                         struct damos *s)
116 {
117         int hotness = damon_hot_score(c, r, s);
118 
119         /* Return coldness of the region */
120         return DAMOS_MAX_SCORE - hotness;
121 }
122 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php