mm/damon/core: tunning nr_subregions at the kdamond_split_regions()
Subsystems (2)
PATCH 2/2 mm/damon/core: tunning nr_subregions at the kdamond_split_regions()
Currently, DAMON is designed to allow the number of nr_subregions to be set from minimum of 10 to maximum of 1000. kdamond_split_regions() splits the region by setting nr_subregions to 2 or 3. This splits the region too narrowly, resulting in an overly wide address sampling range and increased access determination failures.
Below are the test results for a case where address access determination succeeded only in the first half of the address region, while failure occurred in the latter half, when the address region was set to the [1G, 4G] range.
When there are few nr_regions: (8)
|--------|--------|---------|-------|-------|-------|-------|
0 1 2 3 4 5 6 7 target, nr_regions, addr region [1G, (sample_addr), 4G] nr age
--------------------- ----------------------------------- --- ---
TRACE [ 1] t=0, nr=8, [1073741824,(1073742349),1075138560] 20 0 TRACE [ 2] t=0, nr=8, [1075138560,(1075142341),1233899520] 0 0 TRACE [ 3] t=0, nr=8, [1233899520,(1360224040),1515687936] 0 0 TRACE [ 4] t=0, nr=8, [1515687936,(1872615549),2246262784] 0 0 TRACE [ 5] t=0, nr=8, [2246262784,(2294436960),2536173568] 0 0 TRACE [ 6] t=0, nr=8, [2536173568,(2577497080),2748776448] 0 0 TRACE [ 7] t=0, nr=8, [2748776448,(2818332252),3328598016] 0 0 TRACE [ 8] t=0, nr=8, [3328598016,(3553053181),4294967296] 0 0
When determining nr_subregions in kdamond_split_regions(), the number of nr_subregions is not fixed at 2 or 3, but can be adjusted based on the number of nr_regions and the sample_interval.
If the number of nr_regions is small, the number of nr_subregions is increased, and conversely, if the number of nr_regions is large, the number of nr_subregions is decreased. (Reducing access failures)
As the sample_interval increases, the number of nr_subregions is increased. As the sample_interval decreases, the number of nr_subregions is also reduced. (Reducing system load)
Below is a test result showing that increasing nr_subregions increases the access determination success rate when the address range is set to [1G, 4G].
When there are many nr_regions: (16)
|----|---|----|---|----|----|---|---|---|---|---|---|---|---|
0 1 2 3 4 5 6 7 8 9 15 target, nr_regions, addr region [1G, (sample_addr), 4G] nr age
--------------------- ----------------------------------- --- ---
TRACE [ 1] t=0, nr=16, [1073741824,(1073742496),1074819072] 20 4 TRACE [ 2] t=0, nr=16, [1074819072,(1086087568),1396940800] 0 2 TRACE [ 3] t=0, nr=16, [1396940800,(1408406119),1709060096] 0 0 TRACE [ 4] t=0, nr=16, [1709060096,(1718634828),2029752320] 0 0 TRACE [ 5] t=0, nr=16, [2029752320,(2033076942),2147844096] 0 0 TRACE [ 6] t=0, nr=16, [2147844096,(2147870592),2148532224] 20 5 TRACE [ 7] t=0, nr=16, [2148532224,(2163851851),2466242560] 0 0 TRACE [ 8] t=0, nr=16, [2466242560,(2466983182),2786467840] 0 1 TRACE [ 9] t=0, nr=16, [2786467840,(2794755756),3105136640] 0 0 TRACE [10] t=0, nr=16, [3105136640,(3108065434),3221405696] 0 0 TRACE [11] t=0, nr=16, [3221405696,(3221424712),3222261760] 20 4 TRACE [12] t=0, nr=16, [3222261760,(3222269016),3222290432] 13 0 TRACE [13] t=0, nr=16, [3222290432,(3234589365),3542605824] 0 0 TRACE [14] t=0, nr=16, [3542605824,(3551138058),3859030016] 0 0 TRACE [15] t=0, nr=16, [3859030016,(3866123754),4178018304] 0 1 TRACE [16] t=0, nr=16, [4178018304,(4179564176),4294967296] 0 0
--- mm/damon/core.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-)
mm/damon/core.c +17 -11
@@ -2423,24 +2423,30 @@ static void kdamond_split_regions(struct damon_ctx *ctx) {struct damon_target *t;unsigned int nr_regions =0 ; -static unsigned int last_nr_regions; -int nr_subregions =2 ; +const unsigned int nr_min = ctx->attrs.min_nr_regions;/* 10 */ +const unsigned int nr_max = ctx->attrs.max_nr_regions;/* 1000 */ +const unsigned long si_min = ctx->attrs.intervals_goal.min_sample_us; +unsigned long si = ctx->attrs.sample_interval; +int nr_subregions;damon_for_each_target (t, ctx) nr_regions +=damon_nr_regions (t); -if (nr_regions > ctx->attrs.max_nr_regions /2 ) -return ; - -/* Maybe the middle of the region has different access frequency */ -if (last_nr_regions == nr_regions && - nr_regions < ctx->attrs.max_nr_regions /3 ) - nr_subregions =3 ; + nr_subregions = (nr_regions > nr_min) ? + ((si > si_min *100 ) ? nr_max /10 : nr_max /20 ) + : nr_max; +/* +* nr_subregions is maximized within the range not exceeding nr_max. +* Increasing nr_subregions minimizes missed address detection. +*/ +while (nr_subregions * nr_regions > nr_max) { + nr_subregions -=4 ; +if (nr_subregions <2 ) +return ; + }damon_for_each_target (t, ctx)damon_split_regions_of (t, nr_subregions, ctx->min_sz_region); - - last_nr_regions = nr_regions; }/*
--
2.43.0