linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jan Dakinevich <jan.dakinevich@virtuozzo.com>
To: Doug Ledford <dledford@redhat.com>,
	Jason Gunthorpe <jgg@ziepe.ca>,
	Yishai Hadas <yishaih@mellanox.com>,
	Leon Romanovsky <leon@kernel.org>,
	Parav Pandit <parav@mellanox.com>,
	Mark Bloch <markb@mellanox.com>,
	Daniel Jurgens <danielj@mellanox.com>,
	Kees Cook <keescook@chromium.org>,
	Kamal Heib <kamalheib1@gmail.com>,
	Bart Van Assche <bvanassche@acm.org>,
	linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Denis Lunev <den@virtuozzo.com>,
	Konstantin Khorenko <khorenko@virtuozzo.com>,
	Jan Dakinevich <jan.dakinevich@virtuozzo.com>
Subject: [PATCH 1/4] IB/core: introduce ->release() callback
Date: Tue, 18 Sep 2018 16:03:43 +0300	[thread overview]
Message-ID: <1537275826-27247-2-git-send-email-jan.dakinevich@virtuozzo.com> (raw)
In-Reply-To: <1537275826-27247-1-git-send-email-jan.dakinevich@virtuozzo.com>

IB infrastructure shares common device instance constructor with
reference counting, and it uses kzalloc() to allocate memory
for device specific instance with incapsulated ib_device field as one
contigous memory block.

The issue is that the device specific instances tend to be too large
and require high page order memory allocation. Unfortunately, kzalloc()
in ib_alloc_device() can not be replaced with kvzalloc() since it would
require a lot of review in all IB driver to prove correctness of the
replacement.

The driver can allocate some heavy partes of their instance for itself
and keep pointers for them in own instance. For this it is important
that the alocated parts have the same life time as ib_device, thus
their deallocation should be based on the same reference counting.

Let suppose:

struct foo_ib_device {
	struct ib_device device;

	void *part;

	...
};

To properly free memory from .foo_ib_part the driver should provide
function for ->release() callback:

void foo_ib_release(struct ib_device *device)
{
	struct foo_ib_device *foo = container_of(device,  struct foo_ib_device,
						 device);

	kvfree(foo->part);
}

...and initialiaze this callback immediately after foo_ib_device
instance allocation.

	struct foo_ib_device *foo;

	foo = ib_alloc_device(sizeof(struct foo_ib_device));

	foo->device.release = foo_ib_release;

	/* allocate parts */
	foo->part = kvmalloc(65536, GFP_KERNEL);

Signed-off-by: Jan Dakinevich <jan.dakinevich@virtuozzo.com>
---
 drivers/infiniband/core/device.c | 2 ++
 include/rdma/ib_verbs.h          | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/drivers/infiniband/core/device.c b/drivers/infiniband/core/device.c
index db3b627..a8c8b0d 100644
--- a/drivers/infiniband/core/device.c
+++ b/drivers/infiniband/core/device.c
@@ -215,6 +215,8 @@ static void ib_device_release(struct device *device)
 		ib_cache_release_one(dev);
 		kfree(dev->port_immutable);
 	}
+	if (dev->release)
+		dev->release(dev);
 	kfree(dev);
 }
 
diff --git a/include/rdma/ib_verbs.h b/include/rdma/ib_verbs.h
index e950c2a..fb582bb 100644
--- a/include/rdma/ib_verbs.h
+++ b/include/rdma/ib_verbs.h
@@ -2271,6 +2271,8 @@ struct ib_device {
 
 	struct iw_cm_verbs	     *iwcm;
 
+	void			   (*release)(struct ib_device *device);
+
 	/**
 	 * alloc_hw_stats - Allocate a struct rdma_hw_stats and fill in the
 	 *   driver initialized data.  The struct is kfree()'ed by the sysfs
-- 
2.1.4


  reply	other threads:[~2018-09-18 13:04 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-18 13:03 [PATCH 0/4] IB: decrease large contigous allocation Jan Dakinevich
2018-09-18 13:03 ` Jan Dakinevich [this message]
2018-09-18 14:44   ` [PATCH 1/4] IB/core: introduce ->release() callback Jason Gunthorpe
2018-09-18 13:03 ` [PATCH 2/4] IB/mlx4: move iboe field aside from mlx4_ib_dev Jan Dakinevich
2018-09-18 13:03 ` [PATCH 3/4] IB/mlx4: move pkeys " Jan Dakinevich
2018-09-18 13:03 ` [PATCH 4/4] IB/mlx4: move sriov " Jan Dakinevich
2018-09-18 14:46 ` [PATCH 0/4] IB: decrease large contigous allocation Jason Gunthorpe
2018-09-18 21:23   ` Leon Romanovsky
2018-09-26 15:43     ` Jan Dakinevich
2018-09-26 17:00       ` Leon Romanovsky
2018-09-26 15:48   ` Jan Dakinevich
2018-09-26 17:06     ` Jason Gunthorpe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1537275826-27247-2-git-send-email-jan.dakinevich@virtuozzo.com \
    --to=jan.dakinevich@virtuozzo.com \
    --cc=bvanassche@acm.org \
    --cc=danielj@mellanox.com \
    --cc=den@virtuozzo.com \
    --cc=dledford@redhat.com \
    --cc=jgg@ziepe.ca \
    --cc=kamalheib1@gmail.com \
    --cc=keescook@chromium.org \
    --cc=khorenko@virtuozzo.com \
    --cc=leon@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=markb@mellanox.com \
    --cc=parav@mellanox.com \
    --cc=yishaih@mellanox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).