raw_spin_lock_init(&mm->sc_stat.lock);
mm->sc_stat.epoch = epoch;
mm->sc_stat.cpu = -1;
+ mm->sc_stat.next_scan = jiffies;
/*
* The update to mm->sc_stat should not be reordered
static void task_cache_work(struct callback_head *work)
{
+ unsigned long next_scan, now = jiffies;
struct task_struct *p = current;
struct mm_struct *mm = p->mm;
unsigned long m_a_occ = 0;
if (p->flags & PF_EXITING)
return;
+ next_scan = READ_ONCE(mm->sc_stat.next_scan);
+ if (time_before(now, next_scan))
+ return;
+
+ /* only 1 thread is allowed to scan */
+ if (!try_cmpxchg(&mm->sc_stat.next_scan, &next_scan,
+ now + EPOCH_PERIOD))
+ return;
+
if (!zalloc_cpumask_var(&cpus, GFP_KERNEL))
return;