微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

我的内核模块使用多少内存?

lsmod,/ proc / modules和slabinfo,/ proc / meminfo
不给我内核模块使用多少内存

有没有办法找到这个?

btw,我基本上写了一个小的测试程序,一个设备驱动程序需要ioctl调用来分配1MB,我每秒从我的应用程序发送这个ioctl消息,所以我的驱动器每秒做kmalloc. Iam不能看到“cat / proc / meminfo | grep Slab”的增加

– snip —

int device_ioctl(
         struct file *file,unsigned int ioctl_num,unsigned long ioctl_param)
{
    /* 
     * Switch according to the ioctl called 
     */
    printk ( "<l> inside ioctl %d IOCTL_ALLOC_MSG = %d\n",ioctl_num,IOCTL_ALLOC_MSG );
    switch (ioctl_num) {
    case IOCTL_ALLOC_MSG:
        allocfunc(); // kmalloc 1MB // printk in this function is OK
        break;
    case IOCTL_DEALLOC_MSG:
        deallocfunc();
        break;
    }

    return 0;
}

应用/用户空间

while ( !stop )
        {
            ret_val = ioctl(memfile,IOCTL_ALLOC_MSG);

            if (ret_val < 0) {
                printf("ioctl Failed. Return code: %d,meaning: %s\n",ret_val,strerror(errno));
                return -1;
            }
            sleep ( 10 );

        }

我没有看到slabinfo内存的增长.我知道linux做cache-> slabs-> pages->对象,但在用户界面中必须有一些方法来确定特定内核模块的内存大小.

谢谢,

解决方法

我不确定它是否适合您,但您可以使用’cat / proc / modules’获取模块所占用的内存量,第二列是第一列中模块的大小(以字节为单位)正在使用.

示例输出显示drm模块使用多少内存:

cat / proc / modules | grep ^ drm | awk'{print $1“”$2}“

drm_kms_helper 49394
drm 286028

希望有帮助.

原文地址:https://www.jb51.cc/c/113255.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐