Skip to contentSkip to conversation

nvme-multipath: use vmalloc for ANA log buffer

PATCH Applied Daniel Wagner 3 participants 5 messages Mar 9, 2022 NVMe

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nvme-multipath: use vmalloc for ANA log buffer

From: Hannes Reinecke <[email protected]>

The ANA log buffer can get really large, as it depends on the controller configuration. So to avoid an out-of-memory issue during scanning use kvmalloc() instead of the kmalloc().

---

As discussed in [1] switch the ana buffer memory type to kvmalloc. I've done some simple testing but also got positive feedback from our partner who observerd order 7 allocation with kmalloc.

This patch is cut against nvme-5.18. Let me know, if it should be again something else.

[1] https://lore.kernel.org/linux-nvme/[email protected]/

 drivers/nvme/host/multipath.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/nvme/host/multipath.c +3 -2
index f8bf6606eb2f..3ddc1ba66f0d 100644
@@ -5,6 +5,7 @@
 
 #include <linux/backing-dev.h>
 #include <linux/moduleparam.h>
+#include <linux/vmalloc.h>
 #include <trace/events/block.h>
 #include "nvme.h"
 
@@ -898,7 +899,7 @@ int nvme_mpath_init_identify(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id)
 	if (ana_log_size > ctrl->ana_log_size) {
 		nvme_mpath_stop(ctrl);
 		nvme_mpath_uninit(ctrl);
-		ctrl->ana_log_buf = kmalloc(ana_log_size, GFP_KERNEL);
+		ctrl->ana_log_buf = kvmalloc(ana_log_size, GFP_KERNEL);
 		if (!ctrl->ana_log_buf)
 			return -ENOMEM;
 	}
@@ -915,7 +916,7 @@ int nvme_mpath_init_identify(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id)
 
 void nvme_mpath_uninit(struct nvme_ctrl *ctrl)
 {
-	kfree(ctrl->ana_log_buf);
+	kvfree(ctrl->ana_log_buf);
 	ctrl->ana_log_buf = NULL;
 	ctrl->ana_log_size = 0;
 }
Signature · 1 line
2.29.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Daniel Wagner

From: Hannes Reinecke <[email protected]>

The ANA log buffer can get really large, as it depends on the controller configuration. So to avoid an out-of-memory issue during scanning use kvmalloc() instead of the kmalloc().

---

We need a blktests for this as earlier code was never exercised to its limits, anyways:-

Looks good.

#2 lore raw
Quoted 2 lines · Chaitanya Kulkarni

We need a blktests for this as earlier code was never exercised to its limits, anyways:-

To test the old code path, you would need to make sure that free memory is fragmented to the point where an order n allocation always fails (n is depending on the ANA log buffer). With the vmalloc in place, I doubt you can really test this allocation problem. Unless you are interested to figure out if it's possible to DOS a machine from the target side out ;)

#3 lore raw
Quoted 11 lines · Daniel Wagner
Quoted 2 lines · Chaitanya Kulkarni

We need a blktests for this as earlier code was never exercised to its limits, anyways:-

To test the old code path, you would need to make sure that free memory is fragmented to the point where an order n allocation always fails (n is depending on the ANA log buffer). With the vmalloc in place, I doubt you can really test this allocation problem. Unless you are interested to figure out if it's possible to DOS a machine from the target side out ;)

true, seems a bit stale now..

-ck