diff mbox series

[for-next,5/5] RDMA/rtrs-srv: Do not use mempool for page allocation

Message ID 20220707142144.459751-6-haris.iqbal@ionos.com (mailing list archive)
State Superseded
Headers show
Series Misc patches for RTRS | expand

Commit Message

Haris Iqbal July 7, 2022, 2:21 p.m. UTC
From: Jack Wang <jinpu.wang@ionos.com>

The mempool is for guaranteed memory allocation during
extreme VM load (see the header of mempool.c of the kernel).
But rtrs-srv allocates pages only when creating new session.
There is no need to use the mempool.

With the removal of mempool, rtrs-server no longer need to reserve
huge mount of memory, this will avoid error like this:
https://www.spinics.net/lists/kernel/msg4404829.html

Signed-off-by: Gioh Kim <gi-oh.kim@ionos.com>
Signed-off-by: Jack Wang <jinpu.wang@ionos.com>
Signed-off-by: Md Haris Iqbal <haris.iqbal@ionos.com>
---
 drivers/infiniband/ulp/rtrs/rtrs-srv.c | 23 ++++++-----------------
 1 file changed, 6 insertions(+), 17 deletions(-)

Comments

Guoqing Jiang July 8, 2022, 7:27 a.m. UTC | #1
On 7/7/22 10:21 PM, Md Haris Iqbal wrote:
> From: Jack Wang <jinpu.wang@ionos.com>
>
> The mempool is for guaranteed memory allocation during
> extreme VM load (see the header of mempool.c of the kernel).
> But rtrs-srv allocates pages only when creating new session.
> There is no need to use the mempool.
>
> With the removal of mempool, rtrs-server no longer need to reserve
> huge mount of memory, this will avoid error like this:
> https://www.spinics.net/lists/kernel/msg4404829.html
>
> Signed-off-by: Gioh Kim <gi-oh.kim@ionos.com>
> Signed-off-by: Jack Wang <jinpu.wang@ionos.com>
> Signed-off-by: Md Haris Iqbal <haris.iqbal@ionos.com>
> ---
>   drivers/infiniband/ulp/rtrs/rtrs-srv.c | 23 ++++++-----------------

Acked-by: Guoqing Jiang <guoqing.jiang@linux.dev>

Thanks,
Guoqing
Jason Gunthorpe July 8, 2022, 1:32 p.m. UTC | #2
On Thu, Jul 07, 2022 at 04:21:44PM +0200, Md Haris Iqbal wrote:
> From: Jack Wang <jinpu.wang@ionos.com>
> 
> The mempool is for guaranteed memory allocation during
> extreme VM load (see the header of mempool.c of the kernel).
> But rtrs-srv allocates pages only when creating new session.
> There is no need to use the mempool.
> 
> With the removal of mempool, rtrs-server no longer need to reserve
> huge mount of memory, this will avoid error like this:
> https://www.spinics.net/lists/kernel/msg4404829.html

Use only lore.kernel.org links please

Jason
Jinpu Wang July 12, 2022, 7:36 a.m. UTC | #3
On Fri, Jul 8, 2022 at 3:32 PM Jason Gunthorpe <jgg@ziepe.ca> wrote:
>
> On Thu, Jul 07, 2022 at 04:21:44PM +0200, Md Haris Iqbal wrote:
> > From: Jack Wang <jinpu.wang@ionos.com>
> >
> > The mempool is for guaranteed memory allocation during
> > extreme VM load (see the header of mempool.c of the kernel).
> > But rtrs-srv allocates pages only when creating new session.
> > There is no need to use the mempool.
> >
> > With the removal of mempool, rtrs-server no longer need to reserve
> > huge mount of memory, this will avoid error like this:
> > https://www.spinics.net/lists/kernel/msg4404829.html
>
> Use only lore.kernel.org links please

Sure, will fix it.
>
> Jason
diff mbox series

Patch

diff --git a/drivers/infiniband/ulp/rtrs/rtrs-srv.c b/drivers/infiniband/ulp/rtrs/rtrs-srv.c
index 8278d3600a36..34c03bde5064 100644
--- a/drivers/infiniband/ulp/rtrs/rtrs-srv.c
+++ b/drivers/infiniband/ulp/rtrs/rtrs-srv.c
@@ -11,7 +11,6 @@ 
 #define pr_fmt(fmt) KBUILD_MODNAME " L" __stringify(__LINE__) ": " fmt
 
 #include <linux/module.h>
-#include <linux/mempool.h>
 
 #include "rtrs-srv.h"
 #include "rtrs-log.h"
@@ -26,11 +25,7 @@  MODULE_LICENSE("GPL");
 #define DEFAULT_SESS_QUEUE_DEPTH 512
 #define MAX_HDR_SIZE PAGE_SIZE
 
-/* We guarantee to serve 10 paths at least */
-#define CHUNK_POOL_SZ 10
-
 static struct rtrs_rdma_dev_pd dev_pd;
-static mempool_t *chunk_pool;
 struct class *rtrs_dev_class;
 static struct rtrs_srv_ib_ctx ib_ctx;
 
@@ -1358,7 +1353,7 @@  static void free_srv(struct rtrs_srv_sess *srv)
 
 	WARN_ON(refcount_read(&srv->refcount));
 	for (i = 0; i < srv->queue_depth; i++)
-		mempool_free(srv->chunks[i], chunk_pool);
+		__free_pages(srv->chunks[i], get_order(max_chunk_size));
 	kfree(srv->chunks);
 	mutex_destroy(&srv->paths_mutex);
 	mutex_destroy(&srv->paths_ev_mutex);
@@ -1411,7 +1406,8 @@  static struct rtrs_srv_sess *get_or_create_srv(struct rtrs_srv_ctx *ctx,
 		goto err_free_srv;
 
 	for (i = 0; i < srv->queue_depth; i++) {
-		srv->chunks[i] = mempool_alloc(chunk_pool, GFP_KERNEL);
+		srv->chunks[i] = alloc_pages(GFP_KERNEL,
+					     get_order(max_chunk_size));
 		if (!srv->chunks[i])
 			goto err_free_chunks;
 	}
@@ -1424,7 +1420,7 @@  static struct rtrs_srv_sess *get_or_create_srv(struct rtrs_srv_ctx *ctx,
 
 err_free_chunks:
 	while (i--)
-		mempool_free(srv->chunks[i], chunk_pool);
+		__free_pages(srv->chunks[i], get_order(max_chunk_size));
 	kfree(srv->chunks);
 
 err_free_srv:
@@ -2273,14 +2269,10 @@  static int __init rtrs_server_init(void)
 		       err);
 		return err;
 	}
-	chunk_pool = mempool_create_page_pool(sess_queue_depth * CHUNK_POOL_SZ,
-					      get_order(max_chunk_size));
-	if (!chunk_pool)
-		return -ENOMEM;
 	rtrs_dev_class = class_create(THIS_MODULE, "rtrs-server");
 	if (IS_ERR(rtrs_dev_class)) {
 		err = PTR_ERR(rtrs_dev_class);
-		goto out_chunk_pool;
+		goto out_err;
 	}
 	rtrs_wq = alloc_workqueue("rtrs_server_wq", 0, 0);
 	if (!rtrs_wq) {
@@ -2292,9 +2284,7 @@  static int __init rtrs_server_init(void)
 
 out_dev_class:
 	class_destroy(rtrs_dev_class);
-out_chunk_pool:
-	mempool_destroy(chunk_pool);
-
+out_err:
 	return err;
 }
 
@@ -2302,7 +2292,6 @@  static void __exit rtrs_server_exit(void)
 {
 	destroy_workqueue(rtrs_wq);
 	class_destroy(rtrs_dev_class);
-	mempool_destroy(chunk_pool);
 	rtrs_rdma_dev_pd_deinit(&dev_pd);
 }