Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Mike Rapoport (Microsoft)" <rppt@kernel.org>
To: Jason Gunthorpe <jgg@ziepe.ca>, Leon Romanovsky <leon@kernel.org>
Cc: Dennis Dalessandro <dennis.dalessandro@cornelisnetworks.com>,
	 Mike Rapoport <rppt@kernel.org>,
	linux-kernel@vger.kernel.org,  linux-mm@kvack.org,
	linux-rdma@vger.kernel.org
Subject: [PATCH 2/5] RDMA/mlx5: replace __get_free_page() with kmalloc()
Date: Tue, 30 Jun 2026 13:52:30 +0300	[thread overview]
Message-ID: <20260630-b4-rdma-v1-2-ab42bcf0de92@kernel.org> (raw)
In-Reply-To: <20260630-b4-rdma-v1-0-ab42bcf0de92@kernel.org>

mlx5_ib_mr_wqe_pfault_handler() allocates a scratch buffer for
parsing work queue entries during page fault handling.

This buffer can be allocated with kmalloc() as there's nothing special
about it to go directly to the page allocator.

kmalloc() provides a better API that does not require ugly casts and
kfree() does not need to know the size of the freed object.

Performance difference between kmalloc() and __get_free_pages() is not
measurable as both allocators take an object/page from a per-CPU list for
fast path allocations.

For the slow path the performance is anyway determined by the amount of
reclaim involved rather than by what allocator is used.

Replace use of __get_free_page() with kmalloc() and free_page() with
kfree().

Link: https://lore.kernel.org/all/635405e4-9423-4a25-a6e7-e03c8ea0bcbe@redhat.com
Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
---
 drivers/infiniband/hw/mlx5/odp.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/infiniband/hw/mlx5/odp.c b/drivers/infiniband/hw/mlx5/odp.c
index 1badec9bf527..90706ff7102a 100644
--- a/drivers/infiniband/hw/mlx5/odp.c
+++ b/drivers/infiniband/hw/mlx5/odp.c
@@ -38,6 +38,7 @@
 #include <linux/hmm-dma.h>
 #include <linux/pci-p2pdma.h>
 
+#include <linux/slab.h>
 #include "mlx5_ib.h"
 #include "cmd.h"
 #include "umr.h"
@@ -1414,7 +1415,7 @@ static void mlx5_ib_mr_wqe_pfault_handler(struct mlx5_ib_dev *dev,
 		goto resolve_page_fault;
 	}
 
-	wqe_start = (void *)__get_free_page(GFP_KERNEL);
+	wqe_start = kmalloc(PAGE_SIZE, GFP_KERNEL);
 	if (!wqe_start) {
 		mlx5_ib_err(dev, "Error allocating memory for IO page fault handling.\n");
 		goto resolve_page_fault;
@@ -1475,7 +1476,7 @@ static void mlx5_ib_mr_wqe_pfault_handler(struct mlx5_ib_dev *dev,
 		    pfault->wqe.wq_num, resume_with_error,
 		    pfault->type);
 	mlx5_core_res_put(res);
-	free_page((unsigned long)wqe_start);
+	kfree(wqe_start);
 }
 
 static void mlx5_ib_mr_rdma_pfault_handler(struct mlx5_ib_dev *dev,

-- 
2.53.0



  parent reply	other threads:[~2026-06-30 10:52 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-30 10:52 [PATCH 0/5] RDMA, IB: replace __get_free_pages() with kmalloc() Mike Rapoport (Microsoft)
2026-06-30 10:52 ` [PATCH 1/5] RDMA/umem: ib_umem_get(): use kmalloc() to allocate page array Mike Rapoport (Microsoft)
2026-06-30 12:31   ` Jason Gunthorpe
2026-06-30 15:00     ` Mike Rapoport
2026-06-30 15:01       ` Mike Rapoport
2026-06-30 15:36         ` Jason Gunthorpe
2026-06-30 10:52 ` Mike Rapoport (Microsoft) [this message]
2026-06-30 10:52 ` [PATCH 3/5] IB/mthca: mthca_reg_user_mr(): use kmalloc() to allocate addresses array Mike Rapoport (Microsoft)
2026-06-30 10:52 ` [PATCH 4/5] IB/mthca: allocate mthca_array memory with kzalloc() Mike Rapoport (Microsoft)
2026-06-30 10:52 ` [PATCH 5/5] IB/rdmavt: use kzalloc() to allocate QPN-map pages Mike Rapoport (Microsoft)

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=20260630-b4-rdma-v1-2-ab42bcf0de92@kernel.org \
    --to=rppt@kernel.org \
    --cc=dennis.dalessandro@cornelisnetworks.com \
    --cc=jgg@ziepe.ca \
    --cc=leon@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-rdma@vger.kernel.org \
    /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