内核模块的内存使用情况 [英] Memory usage of a kernel module

查看:70
本文介绍了内核模块的内存使用情况的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在尝试估算内核模块(通常是设备驱动程序)消耗的内存量时,我尝试使用 size 实用程序,该实用程序给出了.ko(. bss,.data,.text等).因此,我期望这些值的总和与插入模块后立即由 lsmod 命令给出的输出完全相同.

While trying to estimate the amount of memory consumed by a kernel module (usually device drivers),I tried using the size utility which gave the size of the static memory areas of the .ko ( .bss, .data, .text etc). So I was expecting the sum of these values to be exactly equal to the output given by the lsmod command immediately after inserting the module.

在init()函数中没有执行动态内存分配(kmalloc或vmalloc),以确保不会引起差异.为什么不匹配?

No dynamic memory allocation(kmalloc or vmalloc) is performed in the init() function to ensure that it isn't causing the difference.So why is there a mismatch?

奇怪的是,大多数时候发现不匹配是固定的!!

Curiously the mismatch was found to be a fixed amount most of the time!!

下面列出了命令输出

text    data     bss     dec     hex   filename
172     448    1024016 1024636  fa27c chardev.ko

lsmod

Module  Size    Used by    Tainted: P
chardev 1025040 0 - Live   0xc009d000

推荐答案

您提到在init函数中未进行任何分配,但是这样做考虑了诸如register_chrdev(9)之类的调用,这些调用在内部为设备实例分配了内存?不断变化的评论让我想知道这是否可能是原因.

You mention that no allocation is done in the init function, but does that take into account calls such as register_chrdev(9) which allocate memory internally for the device instance? The comment that it is a constant difference makes me wonder if this might be the cause.

这篇关于内核模块的内存使用情况的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆