previous contents up next

Unix for Advanced Users

11. Memory Management under Unix

11.4. How the Kernel Organizes Memory

11.4.2. The System and User Areas

When the kernel loads, it uses RAM to keep itself memory resident. Consequently, it has to ensure that user programs do not overwrite/corrupt the kernel data structures (or overwrite/corrupt other users' data structures). It does so by designating part of RAM as kernel or system pages (which hold kernel text and data segments) and user pages (which hold user stacks, data, and text segments). Strong memory protection is implemented in the kernel memory management code to keep the users from corrupting the system area. For example, only the kernel is allowed to switch from the user to the system area. During the normal execution of a Unix process, both system and user areas are used.

A common system call when memory protection is violated is SIGSEGV (you see a "Segmentation violation" message on the screen when this happens. The culprit process is killed and its in-memory portions dumped to a disk file called "core").

1. To see how much time a program is spending in system and user areas, you can use the Unix command time. For example,
    % time sort myfile
    <sort output>
    0.02u 0.02s 0:00.09 0.0%
    
Where the first column on the last line shows the the time the kernel spent executing in the user area, the second the time spent in the system area, and the third the wall clock (elapsed) time.

2. The Unix command dmesg under Linux will show you how the kernel initially allocates the memory:

    % dmesg
    Linux version 2.2.5-15 (root@porky.devel.redhat.com) (gcc version egcs-2.91.66 1
    9990314/Linux (egcs-1.1.2 release)) #1 Mon Apr 19 22:21:09 EDT 1999
    Detected 120285575 Hz processor.
    Console: colour VGA+ 80x25
    Calibrating delay loop... 48.03 BogoMIPS
    Memory: 30412k/32768k available (996k kernel code, 412k reserved, 604k data, 60k
     init)
    VFS: Diskquotas version dquot_6.4.0 initialized
    CPU: Intel Pentium 75 - 200 stepping 05
    Checking 386/387 coupling... OK, FPU using exception 16 error reporting.
    Checking 'hlt' instruction... OK.
    Intel Pentium with F0 0F bug - workaround enabled.
    POSIX conformance testing by UNIFIX
    PCI: BIOS32 entry (0xc00fa000) in high memory, cannot use.
    PCI: Using configuration type 1
    PCI: Probing PCI hardware
    Linux NET4.0 for Linux 2.2
    Based upon Swansea University Computer Society NET3.039
    NET4: Unix domain sockets 1.0 for Linux NET4.0.
    NET4: Linux TCP/IP 1.0 for NET4.0
    IP Protocols: ICMP, UDP, TCP, IGMP
    Initializing RT netlink socket
    Starting kswapd v 1.5 
    Detected PS/2 Mouse Port.
    Serial driver version 4.27 with MANY_PORTS MULTIPORT SHARE_IRQ enabled
    ttyS00 at 0x03f8 (irq = 4) is a 16550A
    ttyS01 at 0x02f8 (irq = 3) is a 16550A
    pty: 256 Unix98 ptys configured
    apm: BIOS version 1.1 Flags 0x0a (Driver version 1.9)
    Real Time Clock Driver v1.09
    RAM disk driver initialized:  16 RAM disks of 4096K size
    Floppy drive(s): fd0 is 1.44M
    .
    .
    .
    

previous contents up next