Linux 上 VMA 的开销
问题: 我如何知道我的进程的 VMA 使用了多少内存(无论是在用户空间还是在内核中)?
我会对我正在做的事情做一个简短的解释,这样你就可以理解我为什么问这个问题。 我在我的 Linux 机器上运行几个进程和一个驱动程序(内核模块)。进程内存被锁定(不可交换),因此我想确保模块和进程消耗的内存不会占用总物理内存的 90%。为了减少 malloc 开销,我使用 mmap。 我真正需要知道的是我的进程真正消耗了多少内存,而不是它们请求了多少内存,据我所知,我只是缺少 VMA 的任何分配开销。
The question:
How can I tell how much memory is in use by the VMA's of my process (either when I'm in userspace or in kernel) ?
I'll give a short explanation on what I'm doing, So you could understand why I'm asking this.
I run on my Linux machine a few processes and one driver (kernel module). The processes memory is locked (not swappable), Therefore I want to make sure that the memory consume by the module along with the processes isn't acceding 90% of my total physical memory. In order to reduce malloc overhead I'm using mmap.
what I really need to know is how much memory my processes are really consuming rather than how much they asked for, and as much as I can tell I'm only missing the VMA's overhead of any allocation.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
挖掘后我找到了答案:
当我在驱动程序中时我可以使用
当前->mm->map_count
了解当前进程的当前 VMA 数量。
将其乘以 sizeof(struct vm_area_struct) 将给出我正在寻找的内容。
从这里开始,会计就非常简单了。
After digging I've found the answer:
While I'm in the driver I can use
current->mm->map_count
To know the current number of VMA's for the current process.
Multiply it by sizeof(struct vm_area_struct) will give me what I was looking for.
From here the accounting is pretty simple.