Re: memory consumed by kernel

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Il 23/09/2010 15.49, Mulyadi Santosa ha scritto:
Hi...

On Thu, Sep 23, 2010 at 16:13, Tayade, Nilesh
<Nilesh.Tayade@xxxxxxxxxxxx>  wrote:
-----Original Message-----
From: kernelnewbies-bounce@xxxxxxxxxxxx [mailto:kernelnewbies-
bounce@xxxxxxxxxxxx] On Behalf Of Arun KS
Sent: Thursday, September 23, 2010 11:30 AM
To: kernelnewbies@xxxxxxxxxxxx
Subject: memory consumed by kernel

Hello There,

cat /proc/meminfo will show the memory statistics of the entire
system.

Is there a way to see the memory consumed by the kernel alone?

I do not have thorough idea. But it seems there is no ready-made tool
(userspace/kernelspace) to know the complete kernel memory.
To debug certain memory related issues - we can refer the /proc/kallsyms
(exact place where each symbol is loaded in memory) and /proc/slabinfo -
the slab allocation for different objects. But considering the total
kernel memory it also includes many other allocations which we do not do
explicitly - like Page tables, or some kind of metadata.

You need to define the limitation of "consumed by the kernel alone".
is it consumed by kernel but later might be used by user space?

In my opinion, you can do it the other way around: sum up all user
mode pages. pay attention with shared memory between threads (this is
the greatest hurdle...so far I know none of tools that succesfully
count them without the help of proper kernel patch..which is likely,
outside mainline kernel tree). Consider it N. Then if you substract
Total RAM with N, you get kernel memory consumption



Hi,
you can compile and load this module and look in /var/log/messages. Every "reserved" range above 1MB is likely to be kernel memory. Generally. under 1MB reserved areas belong to BIOS. That is for x86, and recent kernels. For other architectures is more or less the same, ...apart from BIOS :-P

You can also grep for "Memory" in dmesg to have the whole picture:

Memory: 1024696k/1040320k available (3388k kernel code, 15172k reserved, 1570k data, 384k init, 131016k highmem)

regards
Luca


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

#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/fs.h>
#include <linux/errno.h>
#include <linux/types.h>
#include <linux/mm.h>
#include <linux/kdev_t.h>
#include <asm/page.h>
#include <linux/cdev.h>
#include <linux/device.h>

static int simple_init(void)
{
	int i = 0;
	int temp = 0;
	int reserved;
	struct page * pp;

	while (pfn_valid(i)) {

		pp = pfn_to_page(i);

		reserved = PageReserved(pp);

		if ( ( temp !=  reserved )  || ( i == 0 ) )
			printk("%08x reserved: %s\n", i << PAGE_SHIFT, reserved? "yes": "no");
			
		temp = reserved;
		++i;
	}
	
	return 0;
}

static void simple_cleanup(void)
{
}

module_init(simple_init);
module_exit(simple_cleanup);


--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at http://kernelnewbies.org/FAQ



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux