Saturday, February 28, 2009

Kernel Services, Part 3

The /boot Partition

The Linux kernel is stored in the partition with the /boot directory. New kernels must also be transferred to this directory. By default, RHEL configures a partition of about 100MB for this directory. This provides enough room for your current kernel plus several additional upgraded kernels.

The /proc Filesystem

The /proc directory is based on a virtual filesystem; in other words, it does not include any files that are stored on the hard drive. But it is a window into what the kernel sees of your computer. It’s a good idea to study the files and directories in /proc, as it can help you diagnose a wide range of problems.

Example 1. A Red Hat Enterprise Linux /proc directory

$ \ls /proc/
1 24 3120 3357 3640 crypto keys swaps
10 2415 3124 3388 3643 devices key-users sys
13871 2438 3147 3409 3655 diskstats kmsg sysrq-trigger
14238 259 3155 3445 3657 dma loadavg sysvipc
15843 262 3187 3446 3667 driver locks tty
17 292 3206 3457 4 execdomains mdstat uptime
18 2921 3222 3458 5 fb meminfo version
18263 2964 3248 3534 6 filesystems misc vmcore
18266 2966 3253 3539 7 fs modules vmstat
18267 2989 326 3543 85 ide mounts xen
18303 2993 3279 3546 86 interrupts net zoneinfo
19031 3 3291 3547 9 iomem partitions
196 3025 3305 3557 buddyinfo ioports schedstat
2 3054 3326 3558 bus irq self
22 3090 3334 3559 cmdline kallsyms slabinfo
233 3109 3345 3638 cpuinfo kcore stat

The numbered items are based on process IDs. For example, the process ID of init is 1. The files in this directory include the memory segments that make up the active process. The contents of each of these files include the active memory for that process.

The other items in the listing are files and directories that correspond to configuration information for components such as DMA channels or whole subsystems such as memory information.

Take a look at some of these files. For example, the /proc/meminfo file provides excellent information as to the state of memory on the local computer, as shown in Example 2. It can help you determine whether RHEL is having trouble detecting all of the memory on your computer.

Example 2. Detected memory information

$ \cat /proc/meminfo
MemTotal: 1048752 kB
MemFree: 46908 kB
Buffers: 160712 kB
Cached: 735564 kB
SwapCached: 0 kB
Active: 438248 kB
Inactive: 494976 kB
HighTotal: 311304 kB
HighFree: 14696 kB
LowTotal: 737448 kB
LowFree: 32212 kB
SwapTotal: 2031608 kB
SwapFree: 2031608 kB
Dirty: 48 kB
Writeback: 0 kB
AnonPages: 36800 kB
Mapped: 21612 kB
Slab: 43268 kB
PageTables: 2076 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
CommitLimit: 2555984 kB
Committed_AS: 113892 kB
VmallocTotal: 114680 kB
VmallocUsed: 4624 kB
VmallocChunk: 109876 kB


It can also help you measure the current memory state of your system. For example, if your system is overloaded, you’ll probably find very little free swap space. The HugePages settings are associated with over 4GB of RAM.

Now you can examine how Linux look at your CPU in the /proc/cpuinfo file, as shown in Example 3. In this particular case, the CPU family information is important; the CPU family value of 6 in this example corresponds to a 686 CPU. If you have a dual-core CPU (and both cores are detected), you will see two entries, even if you have only one physical CPU.

Example 3. Detected CPU information

$ \cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 15
model name : Intel(R) Xeon(R) CPU E5345 @ 2.33GHz
stepping : 11
cpu MHz : 2327.504
cache size : 4096 KB
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 10
wp : yes
flags : fpu tsc msr pae mce cx8 apic mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe nx lm constant_tsc up pni monitor ds_cpl vmx est tm2 cx16 xtpr lahf_lm
bogomips : 5820.56


Many programs are available that simply look at the information stored in /proc and interpret it in a more readable format. The top utility is a perfect example. It reads the process table, queries RAM and swap usage and the level of CPU use, and presents it all on one screen.

IP Forwarding

More importantly, there are kernel variables that can be altered to change the way the kernel behaves while it’s running. Sometimes it’s appropriate to configure a Linux as a router between networks. By default, it does not forward TCP/IP information. You can confirm this with the following command:

# cat /proc/sys/net/ipv4/ip_forward
0

If your computer has two or more network cards, you may want to activate IP forwarding with the following command:

# echo 1 >> /proc/sys/net/ipv4/ip_forward
# cat /proc/sys/net/ipv4/ip_forward
1

Naturally, you will want to make sure the setting is confirmed the next time you boot by activating the net.ipv4.ip_forward directive in the /etc/sysctl.conf file.

0 comments: