[Devel] [PATCH RHEL8 COMMIT] IB/core: Use kvzalloc to allocate ib_device

Konstantin Khorenko khorenko at virtuozzo.com
Tue May 25 12:16:41 MSK 2021


The commit is pushed to "branch-rh8-4.18.0-240.1.1.vz8.5.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh8-4.18.0-240.1.1.vz8.5.33
------>
commit 4a8863cf16f624039d6ad7f95dfd0cd7f18235f1
Author: Jan Dakinevich <jan.dakinevich at virtuozzo.com>
Date:   Tue May 25 12:16:41 2021 +0300

    IB/core: Use kvzalloc to allocate ib_device
    
    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>
---
 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 b0f75799836b..d649c5c4b27e 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);
@@ -505,7 +510,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,
@@ -574,12 +579,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;
 	}
 


More information about the Devel mailing list