[PATCH] ipc/msg: allocate msg_msgseg from kmem buckets

From: Yi Xie

Date: Tue Jun 30 2026 - 02:18:27 EST


struct msg_msg already comes from dedicated kmem buckets, but the
follow-on msg_msgseg chunks for larger payloads still use kmalloc.

Switch the segment allocations to kmem buckets as well. Still free them
with kfree(), same as msg_msg.

Signed-off-by: Yi Xie <xieyi@xxxxxxxxxx>
---
ipc/msgutil.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/ipc/msgutil.c b/ipc/msgutil.c
index e28f0cecb2ec..8aa8ac180317 100644
--- a/ipc/msgutil.c
+++ b/ipc/msgutil.c
@@ -40,6 +40,7 @@ struct msg_msgseg {
#define DATALEN_SEG ((size_t)PAGE_SIZE-sizeof(struct msg_msgseg))

static kmem_buckets *msg_buckets __ro_after_init;
+static kmem_buckets *msgseg_buckets __ro_after_init;

static int __init init_msg_buckets(void)
{
@@ -47,6 +48,10 @@ static int __init init_msg_buckets(void)
sizeof(struct msg_msg),
DATALEN_MSG, NULL);

+ msgseg_buckets = kmem_buckets_create("msg_msgseg", SLAB_ACCOUNT,
+ sizeof(struct msg_msgseg),
+ DATALEN_SEG, NULL);
+
return 0;
}
subsys_initcall(init_msg_buckets);
@@ -73,7 +78,8 @@ static struct msg_msg *alloc_msg(size_t len)
cond_resched();

alen = min(len, DATALEN_SEG);
- seg = kmalloc(sizeof(*seg) + alen, GFP_KERNEL_ACCOUNT);
+ seg = kmem_buckets_alloc(msgseg_buckets,
+ sizeof(*seg) + alen, GFP_KERNEL);
if (seg == NULL)
goto out_err;
*pseg = seg;
--
2.25.1