You are not logged in.

#1 2010-11-14 15:36:47

mhertz
Member
From: Denmark
Registered: 2010-06-19
Posts: 668

Howto identify kernel module memory usage?

I'm having about 80mb uncached or so, which I cannot see where's going, and so i'm thinking that it's the foss ati driver which is using it, or maybe some other modules, but lsmod only shows about 1mb as size for the ati modules, but i'm thinking that's wrong.

So does anyone know a way to let me check for memory usage of specific kernel modules? I'm guessing it's somewhere in /proc, but I dunno. I would love if there where some kind of htop but just also for kernel modules additionally.

Edit: Hmm, maybe this should have gone into the kernel subforum, but as I consider this question to be newbie'sh, then that's why I made it here...

Last edited by mhertz (2010-11-14 15:41:29)

Offline

#2 2010-11-14 16:56:53

lagagnon
Member
From: an Island in the Pacific...
Registered: 2009-12-10
Posts: 1,087
Website

Re: Howto identify kernel module memory usage?

Kernel modules are not particularly large, but my nVidia module takes 9.3 MB according to lsmod. I do think lsmod is reporting the correct size. To find out where your 80MB of RAM is going use "ps aux" and check the memory columns for all the processes you have running. You will need to look up what VSZ and RSS actually mean to understand the memory use. Suggest you read this:
http://www.ibm.com/developerworks/linux … emory.html


Philosophy is looking for a black cat in a dark room. Metaphysics is looking for a black cat in a dark room that isn't there. Religion is looking for a black cat in a dark room that isn't there and shouting "I found it!". Science is looking for a black cat in a dark room with a flashlight.

Offline

#3 2010-11-14 18:34:58

ChoK
Member
From: France
Registered: 2008-10-01
Posts: 346

Re: Howto identify kernel module memory usage?

to monitor memory usage :
use htop or top and find the memory hog
then pmap -d `pidof <memory hog>` will give you what libraries are loaded by the memory hog and how much memory they use.

If you have kde, ksysguard gives you the same under "detailed memory information"
If it's X related, xrestop can tell you if there is a pixmap leak.


Ah, good taste! What a dreadful thing! Taste is the enemy of creativeness.
Picasso
Perfection is reached, not when there is no longer anything to add, but when there is no longer anything to take away.
Saint Exupéry

Offline

#4 2010-11-14 19:03:33

csn
Member
Registered: 2009-02-28
Posts: 10

Re: Howto identify kernel module memory usage?

Since a module is just a piece of (runtime loadable) kernel code you cannot easily determine how much memory a particular module uses. You can however get detailed statistics about kernel memory usage by using the slabtop(1) utility, which is part of core/procps, or by viewing /proc/slabinfo directly.
This will show you how much memory is allocated for each of the kernel data structures. Sometimes the name of the data structure will allow you to easily deduce the relevant module name like, for example, in the case of ext4 inode cache, which obviously belongs to the ext4 module. You can test this by doing a `find /' while viewing the output of slabtop. It should make the cache size of the ext4 inode cache go up pretty much instantly.

Also see /proc/meminfo. For example, `grep Slab /proc/meminfo' will tell you how much physical memory SLAB (the linux memory allocator) is using.

Keep in mind that SLAB recycles memory (basically). A Structure that was in use by e.g. ext4 just a moment ago may now be in use by your graphics card driver (provided both modules make use of the same kinds of objects).

What `lsmod' actually tells you is the code size of the module when it's loaded into memory. This is easy to measure and (usually) should be somewhat proportional to the amount of disk space it consumes. However, this number is totally unrelated to the amount of memory a particular module may allocate at a particular moment during runtime.

Last edited by csn (2010-11-14 19:36:08)

Offline

#5 2010-11-15 08:38:17

mhertz
Member
From: Denmark
Registered: 2010-06-19
Posts: 668

Re: Howto identify kernel module memory usage?

Thanks for your replies, guys!

I'm sorry, I forgot to mention that I do know the "basics" about memory usage, i.e. I know about shared memory/private memory and the kernels cache/buffer and slab allocator etc.

It's after having checked the total memory usage of processes and kernel with tools like ps_mem.py , htop and ps aux + slab of /proc/meminfo(or slabtop) and the about 4mb of kernel memory described in dmesg, that there still is memory unaccounted for when comparing that to free -m's - buffers/cache value.

Then the only thing I could think off was the kernel modules, but slab is just 18mb in all...

The strange thing is that the unaccounted memory came after having switched from arch32 to arch64. It's the exact same setup and computer, progs, drivers etc.

I obviously know that 64bits will use more memory(up to about twice as much), but with the 32bit's arch, then I could see with the aforementioned tools exactly where the memory where spent, but on arch64, then there's a block of memory unaccounted for(to me!), which annoys me...

Hmm, this probably shouldn't be in the newbie subforum afterall, sorry mods... 

Note, I had written a post sometime ago about how to check for the missing memory in the arch64 subforum, but didn't get any answers that could help me. I just wanted to iterate that this subject here isn't a double-post, as I just wanted to know how to measure kernel modules specifically, and as I have gotten the answer from csn(thanks alot mate!), then I guess this subject is finished. Thanks everyone!

Last edited by mhertz (2010-11-15 08:45:51)

Offline

#6 2010-11-16 09:07:07

mhertz
Member
From: Denmark
Registered: 2010-06-19
Posts: 668

Re: Howto identify kernel module memory usage?

@csn

Are you sure that the kernel modules memory usage is included in the total slab memory allocation value? I did allready knew about slab from /proc/meminfo and slabtop, but I had read that it was a kind of kernel cache.

In /proc/meminfo then i just have 18mb reserved for slab, and slabtop shows that this is correct and that ext4_inode_cache is using 15mb of those, and all the others are using very little memory. I could see two entries that related to ati i.e. radeon/0 and readeon/1, but those were strangelly listed as using 0kb memory. Also, even if the ati kernel modules would have names in the slabtop list that I couldn't recognice, then as ext4_inode_cache is using 15mb out of the 18mb of total slab, then the ati modules could at highest use 3mb, and that dosen't sound right either.

Thanks again for your help!

@all

If anyone knows how I can see how much memory, specific kernel modules is using(or just the total of all of them), then I would really appreciate it, thanks.

PS: Just for background info, then here's a quote from a post I made a couple of weeks ago, which lists why i'm interested in knowing how much memory the kernel modules is using:

free -m reports 134MB used without caching, but I cannot see more used than:
ps_mem.py lists under 30MB used(total=private+shared). (and max 50MB if going by htop).
dmesg lists the kernel to use under 5MB.
/proc/meminfo lists slab as using 17MB(half of that reclaimable; I don't know how free -m deals with that).
lsmod shows only 4 big modules(and many small ones) with sizes in the range of highest 900000, which I guess is about 0.9mb.
That is maybe 60MB max and along way up to 134, so I am thinking that it's either some hidden kernel caching/reservation, or that the culprit is the kernel modules i.e.probably the radeon driver,but I don't know how to check that besides the size listed by lsmod, which dosen't show any big values, but the thing is also that I used the same driver on the I686 version and where the memory usage was at total 45MB, then im not sure that it's even that(unless the radeon driver uses many times more memory than the i686 version?).
I wish I knew how to meassure these things in detail...

Last edited by mhertz (2010-11-16 15:22:36)

Offline

#7 2010-11-20 15:56:20

csn
Member
Registered: 2009-02-28
Posts: 10

Re: Howto identify kernel module memory usage?

mhertz wrote:

Are you sure that the kernel modules memory usage is included in the total slab memory allocation value? I did allready knew about slab from /proc/meminfo and slabtop, but I had read that it was a kind of kernel cache.

As far as my understanding goes from reading the docs, slabtop tracks everything while /proc/meminfo only summarizes how much physical memory Slab is currently using. But Slab doesn't distinguish between compiled in modules and runtime loadable modules, either way.

The only way (that I can currently think of) to really measure memory usage of individual modules would be to profile the kernel.

Offline

#8 2013-12-24 02:22:19

firewing1
Member
Registered: 2013-12-17
Posts: 9

Re: Howto identify kernel module memory usage?

Hm, I just ran into the same issue (QEMU 1.7.0 + NoSnoop patches) - I've rebooted the VM a few times and then this time it said out of memory. The 8GB allocated to it was still reserved, shutting down libvirt or rmmod kvm doesn't do anything. Bizzare... I'll see if there's a pattern to triggering it.

Offline

#9 2013-12-24 02:41:00

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 28,162
Website

Re: Howto identify kernel module memory usage?

Please don't necrobump old threads: https://wiki.archlinux.org/index.php/Fo … Bumping.27



Closing


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

Board footer

Powered by FluxBB