Skip to content

Commit

Permalink
mm: introduce dedicated WQ_MEM_RECLAIM workqueue to do lru_add_drain_all
Browse files Browse the repository at this point in the history
This patch is based on https://patchwork.ozlabs.org/patch/574623/.

Tejun submitted commit 23d11a5 ("workqueue: skip flush dependency
checks for legacy workqueues") for the legacy create*_workqueue()
interface.

But some workq created by alloc_workqueue still reports warning on
memory reclaim, e.g nvme_workq with flag WQ_MEM_RECLAIM set:

    workqueue: WQ_MEM_RECLAIM nvme:nvme_reset_work is flushing !WQ_MEM_RECLAIM events:lru_add_drain_per_cpu
    ------------[ cut here ]------------
    WARNING: CPU: 0 PID: 6 at SoC/linux/kernel/workqueue.c:2448 check_flush_dependency+0xb4/0x10c
    ...
    check_flush_dependency+0xb4/0x10c
    flush_work+0x54/0x140
    lru_add_drain_all+0x138/0x188
    migrate_prep+0xc/0x18
    alloc_contig_range+0xf4/0x350
    cma_alloc+0xec/0x1e4
    dma_alloc_from_contiguous+0x38/0x40
    __dma_alloc+0x74/0x25c
    nvme_alloc_queue+0xcc/0x36c
    nvme_reset_work+0x5c4/0xda8
    process_one_work+0x128/0x2ec
    worker_thread+0x58/0x434
    kthread+0xd4/0xe8
    ret_from_fork+0x10/0x50

That's because lru_add_drain_all() will schedule the drain work on
system_wq, whose flag is set to 0, !WQ_MEM_RECLAIM.

Introduce a dedicated WQ_MEM_RECLAIM workqueue to do
lru_add_drain_all(), aiding in getting memory freed.

Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Wang Sheng-Hui <[email protected]>
Acked-by: Tejun Heo <[email protected]>
Cc: Keith Busch <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Thierry Reding <[email protected]>
Cc: Ingo Molnar <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
shhuiw authored and torvalds committed Jun 9, 2016
1 parent ba62baf commit f3a932b
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion mm/swap.c
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,24 @@ static void lru_add_drain_per_cpu(struct work_struct *dummy)

static DEFINE_PER_CPU(struct work_struct, lru_add_drain_work);

/*
* lru_add_drain_wq is used to do lru_add_drain_all() from a WQ_MEM_RECLAIM
* workqueue, aiding in getting memory freed.
*/
static struct workqueue_struct *lru_add_drain_wq;

static int __init lru_init(void)
{
lru_add_drain_wq = alloc_workqueue("lru-add-drain", WQ_MEM_RECLAIM, 0);

if (WARN(!lru_add_drain_wq,
"Failed to create workqueue lru_add_drain_wq"))
return -ENOMEM;

return 0;
}
early_initcall(lru_init);

void lru_add_drain_all(void)
{
static DEFINE_MUTEX(lock);
Expand All @@ -686,7 +704,7 @@ void lru_add_drain_all(void)
pagevec_count(&per_cpu(lru_deactivate_pvecs, cpu)) ||
need_activate_page_drain(cpu)) {
INIT_WORK(work, lru_add_drain_per_cpu);
schedule_work_on(cpu, work);
queue_work_on(cpu, lru_add_drain_wq, work);
cpumask_set_cpu(cpu, &has_work);
}
}
Expand Down

0 comments on commit f3a932b

Please sign in to comment.