DAMOS finds memory that is eligible to apply the action, using DAMOS core filters and target access pattern. If the total amount of the eligible memory is larger than DAMOS quota, DAMOS selects memory to apply the action based on their relative hotness and the action type. For migrate_hot action, hotter regions are selected. For migrate_cold action, colder regions are selected. The hotness is calculated using the age and the access frequency. The frequency is counted by the traditional access monitoring and saved in damon_region->nr_accesses. When DAMON is configured with data attribute probes and probe weights, it runs in attributes-only monitoring mode. In the mode, the traditional access monitoring is skipped and therefore the access frequency counter is not updated. If the mode is enabled at runtime, the counter would have a stale value for the remaining aggregation interval. Though the counter will eventually be reset after the aggregation interval. Assuming the counter values are zero for the above mentioned reason, the prioritization logic will show all regions as having zero access frequency. For actions that prefer hot regions such as migrate_hot, regions of shorter age will be prioritized. For actions that prefer cold regions such as migrate_cold and pageout, regions of longer age will be prioritized. No real access frequency or the attributes monitoring results are considered. It is only chaotic and useless. It could be even more chaotic if the counters have stale values. In the attribute-only mode, probe hits weighted sum plays the role that is similar to that of the traditional access frequency. The adaptive region adjustment logic uses it in the attributes only mode. Do the same for the DAMOS quota region prioritization purpose hotness calculation. Replace the access frequency with the probe hits weighted sum for the hotness calculation in the mode. Signed-off-by: SJ Park --- mm/damon/ops-common.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/mm/damon/ops-common.c b/mm/damon/ops-common.c index 38720794c9fc..adbdba6dc6da 100644 --- a/mm/damon/ops-common.c +++ b/mm/damon/ops-common.c @@ -165,6 +165,25 @@ void damon_hugetlb_mkold(pte_t *pte, struct mm_struct *mm, #define DAMON_MAX_SUBSCORE (100) #define DAMON_MAX_AGE_IN_LOG (32) +static int damon_freq_subscore(struct damon_ctx *c, + struct damon_region *r) +{ + unsigned int num, denom, samples_per_aggr; + struct damon_probe *p; + + samples_per_aggr = damon_nr_samples_per_aggr(&c->attrs); + if (damon_has_probe_weights(c)) { + num = damon_probe_hits_wsum(r, false, true, c); + denom = 0; + damon_for_each_probe(p, c) + denom += samples_per_aggr * p->weight; + } else { + num = damon_nr_accesses_mvsum(r, c); + denom = samples_per_aggr; + } + return mult_frac(num, DAMON_MAX_SUBSCORE, denom); +} + int damon_hot_score(struct damon_ctx *c, struct damon_region *r, struct damos *s) { @@ -175,9 +194,7 @@ int damon_hot_score(struct damon_ctx *c, struct damon_region *r, unsigned int age_weight = s->quota.weight_age; int hotness; - freq_subscore = mult_frac(damon_nr_accesses_mvsum(r, c), - DAMON_MAX_SUBSCORE, - damon_nr_samples_per_aggr(&c->attrs)); + freq_subscore = damon_freq_subscore(c, r); age_in_sec = div_u64((u64)r->age * c->attrs.aggr_interval, USEC_PER_SEC); -- 2.47.3