On Sun, Oct 30, 2022 at 3:59 AM Marco Elver <elver@xxxxxxxxxx> wrote: > > > +- ``kasan.page_alloc.sample=<sampling frequency>`` makes KASAN tag only > > Frequency is number of samples per frame (unit time, or if used > non-temporally like here, population size). > > [1] https://en.wikipedia.org/wiki/Systematic_sampling > > You're using it as an interval, so I'd just replace uses of frequency > with "interval" appropriately here and elsewhere. Done in v2. > > +static inline bool kasan_sample_page_alloc(void) > > +{ > > + unsigned long *count = this_cpu_ptr(&kasan_page_alloc_count); > > this_cpu_inc_return() > > without it, you need to ensure preemption is disabled around here. > > > + > > + return (*count)++ % kasan_page_alloc_sample == 0; > > Doing '%' is a potentially costly operation if called in a fast-path. > > We can generate better code with (rename 'count' -> 'skip'): > > long skip_next = this_cpu_dec_return(kasan_page_alloc_skip); > > if (skip_next < 0) { > this_cpu_write(kasan_page_alloc_skip, kasan_page_alloc_sample - 1); > return true; > } > > return false; Done in v2. Thank you, Marco!