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

Konstantin Khorenko khorenko at virtuozzo.com
Thu Sep 30 16:04:01 MSK 2021


The commit is pushed to "branch-rh9-5.14.vz9.1.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after ark-5.14
------>
commit c02a96afdd2c79fdde0750f49c3dd9c2bc0c4a22
Author: Jan Dakinevich <jan.dakinevich at virtuozzo.com>
Date:   Thu Sep 30 16:04:01 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>
    
    (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 fa20b1824fb8..96638690ded8 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;
 	}
 


More information about the Devel mailing list