Re: memory used by kernel?

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

 



On Fri, 08 Oct 2004 13:42:41 +0530, Mandeep Sandhu
<mandeep_sandhu@xxxxxxxxxxx> wrote:

> how much memory does the kernel reserve for it's own use?

The kernel has some data structures that one may consider as being
reserved memory, and it also will use as much physical memory as the
size of the kernel image (minus stuff tagged as __init__ since that
can get freed afterwards).

> is there any commmand by which i find this out?

No. It's not kept as a statistic, but you could look at the output of
free and deduce how much memory was available out of the amount you
have installed:

jcm@perihelion:~$ free
             total       used       free     shared    buffers     cached
Mem:        514968     509768       5200          0       6756      50972
-/+ buffers/cache:     452040      62928
Swap:      1959888         96    1959792

That won't tell you who is using memory however, whether user or kernel.

> If the kernel uses the 1GB/3GB split of memory and i have
> 512 MB of RAM then how much memory has the kernel reserved

That's a fundamental misunderstanding. The kernel (userspace also does
too) runs in protected mode and has a virtual address space, which
means that memory it sees has been "massaged" by the MMU - i.e.
translated, according to a set of page tables which tell the MMU how
to arrange virtual memory. This is done to resolve issues of
fragmentation since both user processes and the kernel can see any
virtually contiguous memory that is required.

The kernel mostly uses virtual memory for its view of the world, and
the 3GB/1GB split comes from the desire to use a single set of page
tables for a process both when in userspace and in kernelspace. This
speeds up the functioning of the kernel, but means however that a
bodge is necessary - the process has the first 3GB to itself, but
memory above that is the kernel addressspace, which is used when in
kernel mode. There could here be a separate set of page tables (there
are but they essentially are already bolted on to the user process')
but that would be extra overhead and work for little gain. Should you
actually need more than 3GB for your process then you can go buy a
64bit machine.

Linux has several different memory allocators, because not everything
can deal with MMU translated memory addresses - for example hardware
which is outside of the CPU core. This is the reason that kmalloc must
be able to allocate contiguous regions of physical memory but ideally
we use vmalloc to get virtually contiguous addresses otherwise.

<plug> I'm writing a series of articles on the kernel for one of the
Linux magazines that I write for - Linux User & Developer -
http://www.linuxuser.co.uk/ - which hopefully will be added to the
wealth of other material available online in the due course of time.
This month features a section which dispells common misunderstandings
acquired from reading the majority of books available on the
subject.</plug>

Jon.

P.S. Standard note to see also Linux Kernel Development and
Understanding the Linux kernel for further details.

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           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