RDMA/rxe: Allocate the MR page array with kvzalloc()
Subsystems (3)
PATCH 1/1 RDMA/rxe: Allocate the MR page array with kvzalloc()
A user MR keeps a struct rxe_mr_page, 16 bytes on 64-bit, for every PAGE_SIZE page it covers, in one array allocated with kzalloc() when the MR is registered. Before the array, the pages were kept in an xarray.
With 4 KiB pages, the array of an MR larger than 1 GiB exceeds KMALLOC_MAX_SIZE, so registering it fails with -ENOMEM, and the first attempt warns:
WARNING: mm/slub.c:5459 at ___kmalloc_large_node+0xe9/0x130 Call Trace: __kmalloc_large_node_noprof __kmalloc_noprof __alloc_mr_page_info rxe_mr_init_user rxe_reg_user_mr
Allocate the array with kvzalloc_objs() and free it with kvfree(), so that MRs of any size can be registered again.
Registering an MR over THP-backed memory, median of 3:
size before (ms) after (ms) change
1 GiB 5.3 5.2 -2% 2 GiB -ENOMEM 10.8 n/a 4 GiB -ENOMEM 21.1 n/a 16 GiB -ENOMEM 85.9 n/a
--- drivers/infiniband/sw/rxe/rxe_mr.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/infiniband/sw/rxe/rxe_mr.c +2 -2
@@ -157,7 +157,7 @@ static int rxe_mr_fill_pages_from_sgt(struct rxe_mr *mr, struct sg_table *sgt)static int __alloc_mr_page_info (struct rxe_mr *mr,int num_pages) { - mr->page_info = kzalloc_objs(struct rxe_mr_page, num_pages); + mr->page_info = kvzalloc_objs(struct rxe_mr_page, num_pages);if (!mr->page_info)return -ENOMEM ;
@@ -186,7 +186,7 @@ static void free_mr_page_info(struct rxe_mr *mr)if (!mr->page_info)return ; -kfree (mr->page_info); +kvfree (mr->page_info); mr->page_info =NULL ; }
---
base-commit: e7732ec135b501e87ab060d992b3b5f2ec4396c9
change-id: 20261123-bug-rdma-rxe-large-mr-f752a49d8365
Best regards,
Signature · 1 line
Qiliang Yuan <[email protected]>
[email protected]
AI reviewSashiko has reviewed this patch and found no issues.
Quoted 22 lines
A user MR keeps a struct
rxe_mr_page, 16 bytes on 64-bit, for everyPAGE_SIZEpage it covers, in one array allocated withkzalloc()when the MR is registered. Before the array, the pages were kept in an xarray.With 4 KiB pages, the array of an MR larger than 1 GiB exceeds
KMALLOC_MAX_SIZE, so registering it fails with-ENOMEM, and the first attempt warns:WARNING: mm/slub.c:5459 at ___kmalloc_large_node+0xe9/0x130 Call Trace: __kmalloc_large_node_noprof __kmalloc_noprof __alloc_mr_page_info rxe_mr_init_user rxe_reg_user_mrAllocate the array with
kvzalloc_objs()and free it withkvfree(), so that MRs of any size can be registered again.Registering an MR over THP-backed memory, median of 3:
size before (ms) after (ms) change
Quoted 8 lines
1 GiB 5.3 5.2 -2% 2 GiB -ENOMEM 10.8 n/a 4 GiB -ENOMEM 21.1 n/a 16 GiB -ENOMEM 85.9 n/aFixes 12985e5915a0b ("RDMA/rxe: Fix iova-to-va conversion for MR page sizes != PAGE_SIZE")Signed-off-by Qiliang Yuan <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 19 lines · Qiliang Yuan
A user MR keeps a struct
rxe_mr_page, 16 bytes on 64-bit, for everyPAGE_SIZEpage it covers, in one array allocated withkzalloc()when the MR is registered. Before the array, the pages were kept in an xarray.With 4 KiB pages, the array of an MR larger than 1 GiB exceeds
KMALLOC_MAX_SIZE, so registering it fails with-ENOMEM, and the first attempt warns:WARNING: mm/slub.c:5459 at ___kmalloc_large_node+0xe9/0x130 Call Trace: __kmalloc_large_node_noprof __kmalloc_noprof __alloc_mr_page_info rxe_mr_init_user rxe_reg_user_mrAllocate the array with
kvzalloc_objs()and free it withkvfree(), so that MRs of any size can be registered again.
Quoted 7 lines
Registering an MR over THP-backed memory, median of 3:
size before (ms) after (ms) change
1 GiB 5.3 5.2 -2% 2 GiB -ENOMEM 10.8 n/a 4 GiB -ENOMEM 21.1 n/a 16 GiB -ENOMEM 85.9 n/a
Thanks a lot. kzalloc_objs only allocates contiguous physical memory,
whereas kvzalloc_objs can allocate non-contiguous memory—making
kvzalloc_objs much less likely to fail when allocating large amounts of memory.
Yanjun Zhu
Quoted 36 lines
Fixes 12985e5915a0b ("RDMA/rxe: Fix iova-to-va conversion for MR page sizes != PAGE_SIZE")Signed-off-by Qiliang Yuan <[email protected]>--- drivers/infiniband/sw/rxe/rxe_mr.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/infiniband/sw/rxe/rxe_mr.c +2
-3@@ -157,7 +157,7 @@ static int rxe_mr_fill_pages_from_sgt(struct rxe_mr *mr, struct sg_table *sgt)static int __alloc_mr_page_info (struct rxe_mr *mr,int num_pages) { - mr->page_info = kzalloc_objs(struct rxe_mr_page, num_pages); + mr->page_info = kvzalloc_objs(struct rxe_mr_page, num_pages);if (!mr->page_info)return -ENOMEM ;@@ -186,7 +186,7 @@ static void free_mr_page_info(struct rxe_mr *mr)if (!mr->page_info)return ; -kfree (mr->page_info); +kvfree (mr->page_info); mr->page_info =NULL ; } ---base-commit:
e7732ec135b501e87ab060d992b3b5f2ec4396c9
change-id: 20261123-bug-rdma-rxe-large-mr-f752a49d8365Best regards,
Signature · 2 lines
Best Regards, Yanjun.Zhu
Quoted 22 lines · Qiliang Yuan
A user MR keeps a struct
rxe_mr_page, 16 bytes on 64-bit, for everyPAGE_SIZEpage it covers, in one array allocated withkzalloc()when the MR is registered. Before the array, the pages were kept in an xarray.With 4 KiB pages, the array of an MR larger than 1 GiB exceeds
KMALLOC_MAX_SIZE, so registering it fails with-ENOMEM, and the first attempt warns:WARNING: mm/slub.c:5459 at ___kmalloc_large_node+0xe9/0x130 Call Trace: __kmalloc_large_node_noprof __kmalloc_noprof __alloc_mr_page_info rxe_mr_init_user rxe_reg_user_mrAllocate the array with
kvzalloc_objs()and free it withkvfree(), so that MRs of any size can be registered again.Registering an MR over THP-backed memory, median of 3:
size before (ms) after (ms) change
Quoted 8 lines
1 GiB 5.3 5.2 -2% 2 GiB -ENOMEM 10.8 n/a 4 GiB -ENOMEM 21.1 n/a 16 GiB -ENOMEM 85.9 n/aFixes 12985e5915a0b ("RDMA/rxe: Fix iova-to-va conversion for MR page sizes != PAGE_SIZE")Signed-off-by Qiliang Yuan <[email protected]>
Quoted 32 lines
--- drivers/infiniband/sw/rxe/rxe_mr.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/infiniband/sw/rxe/rxe_mr.c +2
-3@@ -157,7 +157,7 @@ static int rxe_mr_fill_pages_from_sgt(struct rxe_mr *mr, struct sg_table *sgt)static int __alloc_mr_page_info (struct rxe_mr *mr,int num_pages) { - mr->page_info = kzalloc_objs(struct rxe_mr_page, num_pages); + mr->page_info = kvzalloc_objs(struct rxe_mr_page, num_pages);if (!mr->page_info)return -ENOMEM ;@@ -186,7 +186,7 @@ static void free_mr_page_info(struct rxe_mr *mr)if (!mr->page_info)return ; -kfree (mr->page_info); +kvfree (mr->page_info); mr->page_info =NULL ; } ---base-commit:
e7732ec135b501e87ab060d992b3b5f2ec4396c9
change-id: 20261123-bug-rdma-rxe-large-mr-f752a49d8365Best regards,