0

My understanding about kmalloc() is that it uses generic slabs of kernel to allocate memory e.g. kmalloc-8, kmalloc-16, .. kmalloc-8k. But after inserting below module I'm not seeing any change to active_objs parameter of any kmalloc-xxx or kmalloc-rcl-xx slabs.

I tried with different memory size e.g. 128, 4096, 512 but no luck.

#include <linux/init.h>
#include <linux/module.h>
#include <linux/slab.h>

char *data;

static int __init start(void)
{ 
        data = kmalloc(2048, GFP_KERNEL);
        if (!data) {
                printk(KERN_ERR "Failed to allocate memory\n");
                return -ENOMEM;
        }
        printk(KERN_INFO "Module is loaded. (%ld)\n", ksize(data));
        data[0] = 'a';
        return 0;
}

static void __exit end(void)
{
        kfree(data);
        return;
}

module_init(start);
module_exit(end);

MODULE_LICENSE("GPL");

Output: Module is loaded. (2048)

Used vmstat -m and /proc/slabinfo to monitor slabs active objects.

Kernel version: 5.4.0-135-generic

Second issue:

Though I am aware about __GFP_RECLAIM (used in kswapd and direct reclaim).

But struggling to understand difference between kmalloc-rcl-xx slabs and kmalloc-xx slabs.

Is kmalloc-rcl-xx freed memory is reclaimable but kmalloc-xx not?

Which slab will be used if we call kmalloc(size, GFP_KERNEL) and why?

red0ct
  • 4,840
  • 3
  • 17
  • 44
MankPan
  • 79
  • 6

0 Answers0