• SeongJae Park's avatar
    mm/damon/core: use number of passed access sampling as a timer · 4472edf6
    SeongJae Park authored
    DAMON sleeps for sampling interval after each sampling, and check if the
    aggregation interval and the ops update interval have passed using
    ktime_get_coarse_ts64() and baseline timestamps for the intervals.  That
    design is for making the operations occur at deterministic timing
    regardless of the time that spend for each work.  However, it turned out
    it is not that useful, and incur not-that-intuitive results.
    
    After all, timer functions, and especially sleep functions that DAMON uses
    to wait for specific timing, are not necessarily strictly accurate.  It is
    legal design, so no problem.  However, depending on such inaccuracies, the
    nr_accesses can be larger than aggregation interval divided by sampling
    interval.  For example, with the default setting (5 ms sampling interval
    and 100 ms aggregation interval) we frequently show regions having
    nr_accesses larger than 20.  Also, if the execution of a DAMOS scheme
    takes a long time, next aggregation could happen before enough number of
    samples are collected.  This is not what usual users would intuitively
    expect.
    
    Since access check sampling is the smallest unit work of DAMON, using the
    number of passed sampling intervals as the DAMON-internal timer can easily
    avoid these problems.  That is, convert aggregation and ops update
    intervals to numbers of sampling intervals that need to be passed before
    those operations be executed, count the number of passed sampling
    intervals, and invoke the operations as soon as the specific amount of
    sampling intervals passed.  Make the change.
    
    Note that this could make a behavioral change to settings that using
    intervals that not aligned by the sampling interval.  For example, if the
    sampling interval is 5 ms and the aggregation interval is 12 ms, DAMON
    effectively uses 15 ms as its aggregation interval, because it checks
    whether the aggregation interval after sleeping the sampling interval. 
    This change will make DAMON to effectively use 10 ms as aggregation
    interval, since it uses 'aggregation interval / sampling interval *
    sampling interval' as the effective aggregation interval, and we don't use
    floating point types.  Usual users would have used aligned intervals, so
    this behavioral change is not expected to make any meaningful impact, so
    just make this change.
    
    Link: https://lkml.kernel.org/r/20230914021523.60649-1-sj@kernel.orgSigned-off-by: default avatarSeongJae Park <sj@kernel.org>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    4472edf6
core.c 38.8 KB