Skip to content

Commit 5fbc461

Browse files
cmetcalf-tileratorvalds
authored andcommitted
mm: make lru_add_drain_all() selective
make lru_add_drain_all() only selectively interrupt the cpus that have per-cpu free pages that can be drained. This is important in nohz mode where calling mlockall(), for example, otherwise will interrupt every core unnecessarily. This is important on workloads where nohz cores are handling 10 Gb traffic in userspace. Those CPUs do not enter the kernel and place pages into LRU pagevecs and they really, really don't want to be interrupted, or they drop packets on the floor. Signed-off-by: Chris Metcalf <cmetcalf@tilera.com> Reviewed-by: Tejun Heo <tj@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 9cb2dc1 commit 5fbc461

2 files changed

Lines changed: 40 additions & 6 deletions

File tree

‎include/linux/swap.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ extern void activate_page(struct page *);
280280
extern void mark_page_accessed(struct page *);
281281
extern void lru_add_drain(void);
282282
extern void lru_add_drain_cpu(int cpu);
283-
extern int lru_add_drain_all(void);
283+
extern void lru_add_drain_all(void);
284284
extern void rotate_reclaimable_page(struct page *page);
285285
extern void deactivate_page(struct page *page);
286286
extern void swap_setup(void);

‎mm/swap.c‎

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,11 @@ static void activate_page_drain(int cpu)
432432
pagevec_lru_move_fn(pvec, __activate_page, NULL);
433433
}
434434

435+
static bool need_activate_page_drain(int cpu)
436+
{
437+
return pagevec_count(&per_cpu(activate_page_pvecs, cpu)) != 0;
438+
}
439+
435440
void activate_page(struct page *page)
436441
{
437442
if (PageLRU(page) && !PageActive(page) && !PageUnevictable(page)) {
@@ -449,6 +454,11 @@ static inline void activate_page_drain(int cpu)
449454
{
450455
}
451456

457+
static bool need_activate_page_drain(int cpu)
458+
{
459+
return false;
460+
}
461+
452462
void activate_page(struct page *page)
453463
{
454464
struct zone *zone = page_zone(page);
@@ -701,12 +711,36 @@ static void lru_add_drain_per_cpu(struct work_struct *dummy)
701711
lru_add_drain();
702712
}
703713

704-
/*
705-
* Returns 0 for success
706-
*/
707-
int lru_add_drain_all(void)
714+
static DEFINE_PER_CPU(struct work_struct, lru_add_drain_work);
715+
716+
void lru_add_drain_all(void)
708717
{
709-
return schedule_on_each_cpu(lru_add_drain_per_cpu);
718+
static DEFINE_MUTEX(lock);
719+
static struct cpumask has_work;
720+
int cpu;
721+
722+
mutex_lock(&lock);
723+
get_online_cpus();
724+
cpumask_clear(&has_work);
725+
726+
for_each_online_cpu(cpu) {
727+
struct work_struct *work = &per_cpu(lru_add_drain_work, cpu);
728+
729+
if (pagevec_count(&per_cpu(lru_add_pvec, cpu)) ||
730+
pagevec_count(&per_cpu(lru_rotate_pvecs, cpu)) ||
731+
pagevec_count(&per_cpu(lru_deactivate_pvecs, cpu)) ||
732+
need_activate_page_drain(cpu)) {
733+
INIT_WORK(work, lru_add_drain_per_cpu);
734+
schedule_work_on(cpu, work);
735+
cpumask_set_cpu(cpu, &has_work);
736+
}
737+
}
738+
739+
for_each_cpu(cpu, &has_work)
740+
flush_work(&per_cpu(lru_add_drain_work, cpu));
741+
742+
put_online_cpus();
743+
mutex_unlock(&lock);
710744
}
711745

712746
/*

0 commit comments

Comments
 (0)