Linux Kernel Structure Learning

Source: Internet
Author: User
Linux Kernel Structure Learning-general Linux technology-Linux programming and kernel information. For more information, see the following section. The Linux kernel consists of five subsystems: process scheduling, memory management, virtual file system, network interface, and inter-process communication.

1. Process Scheduling (SCHED): controls the process's access to the CPU.

2. Memory Management (MM): allows multiple processes to securely share the primary memory area.

3. Virtual File System (VFS): hides the details of various hardware and provides unified interfaces for all devices. VFS provides dozens of different file systems. Virtual File systems can be divided into logical file systems and device drivers. A device driver is a device driver module written for each hardware controller.

4. Network Interface (NET): provides access to various network standards and support for various network hardware. Network Interfaces can be divided into network protocols and network drivers. The network protocol Section is responsible for implementing each possible network transmission protocol. Network Device Drivers communicate with hardware devices. Each possible hardware device has the same device driver.

5. inter-process communication (IPC): supports various inter-process communication mechanisms

System Data Structure
In Linux kernel sight, some data structures are frequently used, which are task_struct.

The Linux kernel uses a data structure (task_struct) to represent a process and the data structure pointer of the process is directed to a task array. The size of this array is determined by NR_TASKS (512 by default), indicating the maximum number of processes that can run simultaneously in Linux.

Mm_struct
The virtual memory of each process is represented by an mm_struct struct that actually contains information about the currently executed image and contains a set of pointers pointing to the vm_area_struct structure, the vw_area_struct Structure describes a region of the virtual memory.

Inode
Files and directories in the Virtual File System are represented by the corresponding inode. The content of each VFS index node is provided by the file system-specific routine. The VFS index node exists only in the kernel memory and is actually saved in the cache of the VFS index node.

Reading source code
Linux kernel source code structure

The linux kernel source code is located in the/usr/src/linux directory.


The/include subdirectory contains most of the contained files required for kernel code creation. This module uses other modules to reconstruct the kernel.

The/init subdirectory contains the kernel initialization code, which is the starting point of kernel work.

The/arch sub-directory contains all kernel code with specific hardware structures. For example, i386 and alpha

The/drivers subdirectory contains all the device drivers in the kernel, such as Block devices and SCSI devices.

The/fs subdirectory contains the code of all file systems. For example, ext2 or vfat.

The/net subdirectory contains the connection code of the kernel.

The/mm sub-directory contains all the memory management code.

The/ipc subdirectory contains the inter-process communication code.

The/kernel subdirectory contains the main kernel code.

The following is a clue to read the source code:

System startup and initialization:

In intelbased systems, when loadlin.exe or LILO loads the kernel into the memory and passes control to the kernel, the kernel starts to start. For more information, see arch/i386/kernel/head. S and head. S to set the specific structure and jump to the main () Routine of init/main. c.

Memory Management:

The memory management code is mainly in/mm, but the code of the specific structure is in archkernel, And the scheduler is in kernel/sched. c. The fork code is in the kernel/fork. c. The kernel routine handler is in include/linux/interrupt. h. The data structure of task_struct is in inlucde/linux/sched. h.

PCI:

The PCI pseudo driver is in drivers/pci. c, which is defined in inclulde/linux/pci. h. Each structure has some specific pci bios code. Intel is in arch/alpha/kernel/bios32.c.

Inter-process communication:

All SystemVIPC object permissions are included in the ipc_perm data structure, which can be found in include/linux/ipc. h. SystemV messages are implemented in ipc/msg. c. The shared content is implemented in ipc/shm. c. Semaphores are implemented in ipc/sem. c and pipelines in/ipc/pipe. c.

Interrupt handling:

The Interrupt Processing code of the kernel is exclusive to almost all microprocessors. The interrupt handling code is defined in arch/i386/kernel/irq. c In include/asm-i386/irq. h.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.