[Devel] [PATCH RH9 21/30] IB/core: Use kvzalloc to allocate ib_device

Andrey Zhadchenko andrey.zhadchenko at virtuozzo.com
Tue Sep 28 21:49:12 MSK 2021


From: Jan Dakinevich <jan.dakinevich at virtuozzo.com>

The allocator ib_alloc_device() is used to allocate both ib_device and
device specific instance. This allocations sometimes quite big and
takes tens KiB, causing high page orders.

Meanwhile, the memory is not intended for DMA and doesn't require to be
physically contiguous.

https://jira.sw.ru/browse/HCI-129
Signed-off-by: Jan Dakinevich <jan.dakinevich at virtuozzo.com>

Rebased to vz8:
 - Change newly added kfree to kvfree in _ib_alloc_device
 - Since there is no kvfree_rcu, introduce new ib_device_reclaim function
and change kfree_rcu to call_rcu(...)

(cherry-picked from vz7 commit 7629b2cc58ee ("IB/core: use kvzalloc to allocate
ib_device"))

Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko at virtuozzo.com>

(cherry picked from vz8 commit 960f8565058ebd525355ffc2c93a31b4238c3be9)
Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko at virtuozzo.com>
---
 drivers/infiniband/core/device.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/infiniband/core/device.c b/drivers/infiniband/core/device.c
index fa20b18..9663869 100644
--- a/drivers/infiniband/core/device.c
+++ b/drivers/infiniband/core/device.c
@@ -485,6 +485,11 @@ static int alloc_name(struct ib_device *ibdev, const char *name)
 	return rc;
 }
 
+static void ib_device_reclaim(struct rcu_head *head)
+{
+	kvfree(container_of(head, struct ib_device, rcu_head));
+}
+
 static void ib_device_release(struct device *device)
 {
 	struct ib_device *dev = container_of(device, struct ib_device, dev);
@@ -507,7 +512,7 @@ static void ib_device_release(struct device *device)
 
 	xa_destroy(&dev->compat_devs);
 	xa_destroy(&dev->client_data);
-	kfree_rcu(dev, rcu_head);
+	call_rcu(&dev->rcu_head, ib_device_reclaim);
 }
 
 static int ib_device_uevent(struct device *device,
@@ -577,12 +582,12 @@ struct ib_device *_ib_alloc_device(size_t size)
 	if (WARN_ON(size < sizeof(struct ib_device)))
 		return NULL;
 
-	device = kzalloc(size, GFP_KERNEL);
+	device = kvzalloc(size, GFP_KERNEL);
 	if (!device)
 		return NULL;
 
 	if (rdma_restrack_init(device)) {
-		kfree(device);
+		kvfree(device);
 		return NULL;
 	}
 
-- 
1.8.3.1



More information about the Devel mailing list