From c583ce0dca78a583994decc5cca17cd4b0001926 Mon Sep 17 00:00:00 2001 From: Yang Rong Date: Tue, 18 Feb 2025 15:33:14 +0800 Subject: [PATCH] anolis: virtio-mem: try to unplug the whole block except vmemmap subblocks ANBZ: #18907 Virtio-mem try to unplug the complete memory block if possible when unplugging. If not possible, it fallbacks to unplug sub-blocks step by step. However, when memmap_on_memory is enabled, it can unplug the whole block except vmemmap sub-blocks in one shot, which can speed up the unplug process. Signed-off-by: Yang Rong Reviewed-by: zhongjiang-ali Reviewed-by: hr567 --- drivers/virtio/virtio_mem.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/drivers/virtio/virtio_mem.c b/drivers/virtio/virtio_mem.c index e0ae99cf39fb..3e553a84a78a 100644 --- a/drivers/virtio/virtio_mem.c +++ b/drivers/virtio/virtio_mem.c @@ -2013,8 +2013,24 @@ static int virtio_mem_sbm_unplug_any_sb_online(struct virtio_mem *vm, return rc; } + sb_id = vm->sbm.sbs_per_mb - 1; + + /* If memmap_on_memory is on, try to unplug the whole block except vmemmap subblocks. */ + if (nr_vmemmap_size && *nb_sb >= vm->sbm.sbs_per_mb - nr_vmemmap_sbs && + virtio_mem_sbm_test_sb_plugged(vm, mb_id, nr_vmemmap_sbs, + vm->sbm.sbs_per_mb - + nr_vmemmap_sbs)) { + rc = virtio_mem_sbm_unplug_sb_online(vm, mb_id, nr_vmemmap_sbs, + vm->sbm.sbs_per_mb - nr_vmemmap_sbs, map); + if (!rc) { + *nb_sb -= vm->sbm.sbs_per_mb - nr_vmemmap_sbs; + sb_id = nr_vmemmap_sbs - 1; + } else if (rc != -EBUSY) + return rc; + } + /* Fallback to single subblocks. */ - for (sb_id = vm->sbm.sbs_per_mb - 1; sb_id >= 0 && *nb_sb; sb_id--) { + for (; sb_id >= 0 && *nb_sb; sb_id--) { /* Find the next candidate subblock */ while (sb_id >= 0 && !virtio_mem_sbm_test_sb_plugged(vm, mb_id, sb_id, 1)) -- Gitee