Linux-Kernel-2.4-Internals.pdf

(251 KB) Pobierz
Linux Kernel 2.4 Internals
Linux Kernel 2.4 Internals
Linux Kernel 2.4 Internals
Table of Contents
Linux Kernel 2.4 Internals. ................................................................................................................................1
Tigran Aivazian tigran@veritas.com. ......................................................................................................1
1. Booting.. ...............................................................................................................................................1
2. Process and Interrupt Managemen. .....................................................................................................1
3. Virtual Filesystem (VFS). ....................................................................................................................2
4. Linux Page Cache. ...............................................................................................................................2
5. IPC mechanisms ..................................................................................................................................2
1. Booting.. ...............................................................................................................................................2
1.1 Building the Linux Kernel Image. .....................................................................................................2
1.2 Booting: Overview. ............................................................................................................................3
1.3 Booting: BIOS POST.. .......................................................................................................................4
1.4 Booting: bootsector and setup. ...........................................................................................................4
1.5 Using LILO as a bootloader. ..............................................................................................................7
1.6 High level initialisation. .....................................................................................................................7
1.7 SMP Bootup on x86. ..........................................................................................................................9
1.8 Freeing initialisation data and code. ..................................................................................................9
1.9 Processing kernel command line. ....................................................................................................10
2. Process and Interrupt Managemen. ...................................................................................................11
2.1 Task Structure and Process Table. ...................................................................................................11
2.2 Creation and termination of tasks and kernel threads. .....................................................................15
2.3 Linux Scheduler. ..............................................................................................................................17
2.4 Linux linked list implementation. ....................................................................................................19
2.5 Wait Queues. ....................................................................................................................................21
2.6 Kernel Timers. .................................................................................................................................23
2.7 Bottom Halves. ................................................................................................................................23
2.8 Task Queues. ....................................................................................................................................24
2.9 Tasklets. ...........................................................................................................................................25
2.10 Softirqs. ..........................................................................................................................................25
2.11 How System Calls Are Implemented on i386 Architecture?. ........................................................25
2.12 Atomic Operations. ........................................................................................................................26
2.13 Spinlocks, Read−write Spinlocks and Big−Reader Spinlocks. .....................................................27
2.14 Semaphores and read/write Semaphores .......................................................................................29
2.15 Kernel Support for Loading Modules. ...........................................................................................30
3. Virtual Filesystem (VFS). ..................................................................................................................33
3.1 Inode Caches and Interaction with Dcache. .....................................................................................33
3.2 Filesystem Registration/Unregistration ...........................................................................................36
3.3 File Descriptor Managemen. ...........................................................................................................38
3.4 File Structure Managemen. .............................................................................................................39
3.5 Superblock and Mountpoint Managemen. ......................................................................................42
3.6 Example Virtual Filesystem: pipefs. ................................................................................................45
3.7 Example Disk Filesystem: BFS. ......................................................................................................47
3.8 Execution Domains and Binary Formats. ........................................................................................48
4. Linux Page Cache. .............................................................................................................................50
5. IPC mechanisms ................................................................................................................................52
5.1 Semaphores. ....................................................................................................................................52
Semaphore System Call Interfaces. ................................................................................................53
sys_semget(). ..................................................................................................................................53
sys_semctl(). ...................................................................................................................................53
i
43165760.001.png
Linux Kernel 2.4 Internals
Table of Contents
sys_semop(). ............................................................................................................................53
Non−blocking Semaphore Operations. ..........................................................................................53
Failing Semaphore Operations. ......................................................................................................54
Blocking Semaphore Operations. ...................................................................................................54
Semaphore Specific Support Structures. ........................................................................................55
struct sem_array. ............................................................................................................................55
struct sem. .......................................................................................................................................55
struct seminfo. ................................................................................................................................55
struct semid64_ds. ..........................................................................................................................55
struct sem_queue. ...........................................................................................................................56
struct sembuf. .................................................................................................................................56
struct sem_undo. .............................................................................................................................56
Semaphore Support Functions. .......................................................................................................56
newary(. .........................................................................................................................................57
freeary(). .........................................................................................................................................57
semctl_down(). ...............................................................................................................................57
IPC_RMID. ....................................................................................................................................57
IPC_SET. ........................................................................................................................................57
semctl_nolock(). .............................................................................................................................58
IPC_INFO and SEM_INFO. ..........................................................................................................58
SEM_STAT. ...................................................................................................................................58
semctl_main(). ................................................................................................................................58
GETALL. .......................................................................................................................................58
SETALL. ........................................................................................................................................58
IPC_STAT. .....................................................................................................................................59
GETVAL. .......................................................................................................................................59
GETPID. .........................................................................................................................................59
GETNCNT. ....................................................................................................................................59
GETZCNT. .....................................................................................................................................59
SETVAL. ........................................................................................................................................59
count_semncnt(). ............................................................................................................................59
count_semzcnt(). ............................................................................................................................59
update_queue(). ..............................................................................................................................59
try_atomic_semop(. .......................................................................................................................60
sem_revalidate(). ............................................................................................................................60
freeundos(. .....................................................................................................................................60
alloc_undo(. ...................................................................................................................................61
sem_exit(). ......................................................................................................................................61
5.2 Message queues. .............................................................................................................................61
Message System Call Interfaces. ....................................................................................................61
sys_msgget(). ..................................................................................................................................61
sys_msgctl(.. ..................................................................................................................................62
IPC_INFO ( or MSG_INFO). ........................................................................................................62
IPC_STAT ( or MSG_STAT). .......................................................................................................62
IPC_SET. ........................................................................................................................................62
IPC_RMID. ....................................................................................................................................62
sys_msgsnd(). .................................................................................................................................62
ii
43165760.002.png
Linux Kernel 2.4 Internals
Table of Contents
sys_msgrcv(). ...........................................................................................................................63
Message Specific Structures. ..........................................................................................................64
struct msg_queue. ...........................................................................................................................64
struct msg_msg. ..............................................................................................................................65
struct msg_msgseg. ........................................................................................................................65
struct msg_sender. ..........................................................................................................................65
struct msg_receive. ........................................................................................................................65
struct msqid64_ds. ..........................................................................................................................65
struct msqid_ds. ..............................................................................................................................66
msg_setbu.. ....................................................................................................................................66
Message Support Functions.. ..........................................................................................................66
newque(). ........................................................................................................................................66
freeque(). ........................................................................................................................................67
ss_wakeup(). ...................................................................................................................................67
ss_add(). .........................................................................................................................................67
ss_del(). ..........................................................................................................................................67
expunge_all(). .................................................................................................................................67
load_msg(). .....................................................................................................................................67
store_msg(). ....................................................................................................................................68
free_msg(). .....................................................................................................................................68
convert_mode(). .............................................................................................................................68
testmsg(). ........................................................................................................................................68
pipelined_send(). ............................................................................................................................68
copy_msqid_to_user(). ...................................................................................................................69
copy_msqid_from_user(). ..............................................................................................................69
5.3 Shared Memory. ..............................................................................................................................69
Shared Memory System Call Interfaces. ........................................................................................69
sys_shmget(). ..................................................................................................................................69
sys_shmctl(.. ..................................................................................................................................69
IPC_INFO. .....................................................................................................................................69
SHM_INFO. ...................................................................................................................................69
SHM_STAT, IPC_STAT. ..............................................................................................................70
SHM_LOCK, SHM_UNLOCK. ....................................................................................................70
IPC_RMID. ....................................................................................................................................70
IPC_SET. ........................................................................................................................................70
sys_shmat(). ....................................................................................................................................70
sys_shmdt(). ...................................................................................................................................71
Shared Memory Support Structures. ..............................................................................................71
struct shminfo64. ............................................................................................................................71
struct shm_info. ..............................................................................................................................72
struct shmid_kernel. .......................................................................................................................72
struct shmid64_ds. ..........................................................................................................................72
struct shmem_inode_info. ..............................................................................................................72
Shared Memory Support Functions.. ..............................................................................................73
newseg(). ........................................................................................................................................73
shm_get_stat(). ...............................................................................................................................73
shmem_lock(). ................................................................................................................................73
iii
43165760.003.png
Linux Kernel 2.4 Internals
Table of Contents
shm_destroy(). .........................................................................................................................74
shm_inc(). .......................................................................................................................................74
shm_close(). ...................................................................................................................................74
shmem_file_setup(). .......................................................................................................................74
5.4 Linux IPC Primitives. .....................................................................................................................74
ipc_alloc(). ......................................................................................................................................74
ipc_addid(.. ....................................................................................................................................75
ipc_rmid(). ......................................................................................................................................75
ipc_buildid(). ..................................................................................................................................75
ipc_checkid(). .................................................................................................................................75
grow_ary(). .....................................................................................................................................75
ipc_findkey(). .................................................................................................................................75
ipcperms(). ......................................................................................................................................76
ipc_lock(. .......................................................................................................................................76
ipc_unlock(. ...................................................................................................................................76
ipc_lockall(. ...................................................................................................................................76
ipc_unlockall(. ...............................................................................................................................76
ipc_get(.. ........................................................................................................................................76
ipc_parse_version(). .......................................................................................................................76
struct kern_ipc_perm. .....................................................................................................................76
struct ipc_ids.. .................................................................................................................................77
struct ipc_id. ...................................................................................................................................77
iv
43165760.004.png
Zgłoś jeśli naruszono regulamin