virtio-mem: set memalloc_noreclaim only doing memory plug request

alloc_contig_range is called when virtio_mem_unplug_request is made,
which allocates memory in the Movable zone for page migration destination.
Commit a7736b49a7 ("mem-buf: set memalloc_noreclaim for work queues")
introduced PF_MEMALLOC being set which skips memory reclaim.
When we get unplug request with request_size=0, Movable zone could be out
of memory and with memalloc_noreclaim set, system would lead to trigger
the oom-killer.

[   80.253805] virtio_mem soc:virtio_mem_device: plugged size: 0x2c00000
[   80.253828] virtio_mem soc:virtio_mem_device: requested size: 0x0
[   80. 4 callbacks suppressed
[   80.265780] kworker/0:14: page allocation failure: order:0, mode:0x144cca(GFP_HIGHUSER_MOVABLE|__GFP_RETRY_MAYFAIL|__GFP_COMP), nodemask=(null)
[   80.265805] CPU: 0 PID: 265766] warn_alloc:263 Comm: kworker/0:14 Tainted: GOE 6.1.25-android14-7-g3318af4ca06c-debug #1
[   80.265813] Hardware name: Qualcomm Technologies, Inc. Pineapple SVM MTP (DT)
[   80.265819] Workqueue: events_freezable virtio_mem_run_wq
[   80.265839] Call trace:
[   80.265842] dump_backtrace+0xfc/0x14c
[   80.265853] show_stack+0x18/0x24
[   80.265860] dump_stack_lvl+0x64/0x7c
[   80.266423] dump_stack+0x18/0x38
[   80.266429] warn_alloc+0xf0/0x16c
[   80.266438] __alloc_pages_slowpath+0xa34/0xa48
[   80.266444] __alloc_pages+0x12c/0x1c0
[   80.266449] __folio_alloc+0x14/0x20
[   80.266454] alloc_migration_target+0x94/0xa8
[   80.266462] migrate_pages+0x1d8/0xa3c
[   80.266467] __alloc_contig_migrate_range+0x10c/0x22c
[   80.266473] alloc_contig_range+0x104/0x278
[   80.266478] virtio_mem_fake_offline+0x5c/0xc8
[   80.266484] virtio_mem_sbm_unplug_sb_online+0x78/0x170
[   80.266490] virtio_mem_run_wq+0xabc/0x1038
[   80.266495] process_one_work+0x188/0x2ac
[   80.266503] worker_thread+0x230/0x3d4
[   80.266508] kthread+0xec/0x190
[   80.266515] ret_from_fork+0x10/0x20

Hence set memalloc_noreclaim only during virtio_mem_plug_request,
so that for unplug requests, system can reclaim memory for such
allocations to proceed.

Change-Id: Ibeca3484d1fa2aec008c124c80f80aca67e65644
Signed-off-by: Sudarshan Rajagopalan <quic_sudaraja@quicinc.com>
This commit is contained in:
Sudarshan Rajagopalan 2023-07-16 23:16:19 -07:00
parent ddd1c356f6
commit 448bff7281

View file

@ -2431,7 +2431,6 @@ static void virtio_mem_run_wq(struct work_struct *work)
atomic_set(&vm->wq_active, 1);
noreclaim_flag = memalloc_noreclaim_save();
retry:
rc = 0;
@ -2451,7 +2450,9 @@ retry:
if (!rc && vm->requested_size != vm->plugged_size) {
if (vm->requested_size > vm->plugged_size) {
diff = vm->requested_size - vm->plugged_size;
noreclaim_flag = memalloc_noreclaim_save();
rc = virtio_mem_plug_request(vm, diff);
memalloc_noreclaim_restore(noreclaim_flag);
} else {
diff = vm->plugged_size - vm->requested_size;
rc = virtio_mem_unplug_request(vm, diff);
@ -2494,7 +2495,6 @@ retry:
}
atomic_set(&vm->wq_active, 0);
memalloc_noreclaim_restore(noreclaim_flag);
}
static enum hrtimer_restart virtio_mem_timer_expired(struct hrtimer *timer)