TimeLinux1

Friday, April 22, 2011

Linux: A closer look - 4 - Memory Management

... continued ...

-every linux process has an address space in memory logically consisting of three segments: text, data and stack.
-contents of the three segments:
          . text segment    - machine instructions from programs executable code produced by a compiler/assembler; constant size.
          . data segment   - variables, strings, arrays and other runtime data. size changes (unlike text seg above).
          . stack segment  - shell variables, the command text etc. usually virtual address map.
-text segment can be shared between processes, data and stack are not.
-depending on the process needs and variables, the address space size allocated by linux varies from process to process.
-but it is in powers of 2 and expressed in pages.  eg: 2tothe4 pages or 16 pages.
-the size of the page is OS dependant. eg its common to have page size as 512 bytes, 1 KB, 2 KB etc.
-if initially allocated address space is not enough, a process can dynamically allocate more memory in Linux.
-the available address space for a machine is dependant on cpu bitsize.
-eg a 32 bit cpu will be able to handle an address space 2tothepower32 bits in size.
-eg a 64 bit cpu will be able to handle an address space 2tothepower64 bits in size.
-the Posix standard doesnt define memory management system calls. It lays its burden on the C library function called 'malloc'.
-in Linux, there are memory management system calls like - 'mmap' and 'munmap'
-note that the address space for a process is comprised of physical memory (text, data) and virtual memory components (stack).
-if a process is sitting idle and memory is short to handle all the needs, it can be moved from physical memory to virtual memory on disk.
-in earlier Unix systems the entire process used to be moved (called swapping).
-in Linux, instead of moving the entire process, parts of a process are moved (this is for efficiency).
-this is done by the page daemon (process 2, that we discussed in our previous blog)
-note that process 0 is and idle process sometimes called swapper, proc 1 is init and proc 2 is page daemon.
-the page daemon runs infrequently -- sleeps, wakes up and sleeps again. it is usually listed as 'kswapd' in ps.

... continued ...

No comments:

Post a Comment