没有合适的资源?快使用搜索试试~ 我知道了~
首页深入理解Linux内核工作原理
深入理解Linux内核工作原理
需积分: 1 1 下载量 55 浏览量
更新于2024-07-18
收藏 899KB PDF 举报
《Linux内核详解》是一本专门为Linux爱好者编写的书籍,它深入探讨了Linux内核的工作原理和机制,而非纯粹的技术手册。作者David Rusling以其在Linux领域的专业知识,基于当时最新、稳定的Linux 2.4.0版本源码进行讲解,确保读者能够了解实际应用中的内核运作方式。 这本书适合那些希望理解Linux核心结构和功能特性的读者,特别强调Linux作为一个动态目标,其内容反映了业界广泛采用的开源代码。作者大卫·拉斯林将复杂的内核知识以易于理解的方式呈现,让读者不仅知道“怎么做”,更能理解“为什么这样做”。 值得注意的是,Linux内核是一个活跃的项目,本书会随着技术的发展而更新。书中包含了版权和分发声明,明确指出可以自由地在特定条件下复制和重新分发,但必须遵守相关规定。此外,书中还提到了法律声明,指出Linux是Linus Torvalds的商标,并且与Unix和Univention等公司没有关系。 《Linux内核》一书的写作地点设在了英国沃金,它不仅提供了一门技术课程,也体现了开源社区的共享精神。通过阅读这本书,读者不仅能掌握Linux内核的基础知识,还能培养对操作系统底层运作的理解,有助于提升编程和系统管理能力。这是一本值得所有Linux专业人士和爱好者收藏的宝贵参考资料。
资源详情
资源推荐
List of Figures
1.1 Atypical PC motherb oard. . . . . . . . . . . . . . . . . . . . . . . . . 2
3.1 Abstract model of Virtual to Physical address mapping . . . . . . . . 16
3.2 Alpha AXP Page Table Entry . . . . . . . . . . . . . . . . . . . . . . . 20
3.3 Three Level Page Tables . . . . . . . . . . . . . . . . . . . . . . . . . . 22
3.4 The
free area
data structure . . . . . . . . . . . . . . . . . . . . . . . 24
3.5 Areas of Virtual Memory . . . . . . . . . . . . . . . . . . . . . . . . . 26
3.6 The Linux Page Cache . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
4.1 A Process's Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
4.2 A Process's Virtual Memory . . . . . . . . . . . . . . . . . . . . . . . . 44
4.3 Registered Binary Formats . . . . . . . . . . . . . . . . . . . . . . . . 47
4.4 ELF Executable File Format . . . . . . . . . . . . . . . . . . . . . . . 48
5.1 Pipes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
5.2 System V IPC Message Queues . . . . . . . . . . . . . . . . . . . . . . 56
5.3 System V IPC Semaphores . . . . . . . . . . . . . . . . . . . . . . . . 57
5.4 System V IPC Shared Memory . . . . . . . . . . . . . . . . . . . . . . 59
6.1 Example PCI Based System . . . . . . . . . . . . . . . . . . . . . . . . 62
6.2 The PCI Conguration Header . . . . . . . . . . . . . . . . . . . . . . 63
6.3 Type 0 PCI Conguration Cycle . . . . . . . . . . . . . . . . . . . . . 65
6.4 Type 1 PCI Conguration Cycle . . . . . . . . . . . . . . . . . . . . . 65
6.5 Linux Kernel PCI Data Structures . . . . . . . . . . . . . . . . . . . . 67
6.6 Conguring a PCI System: Part 1 . . . . . . . . . . . . . . . . . . . . 69
6.7 Conguring a PCI System: Part 2 . . . . . . . . . . . . . . . . . . . . 70
6.8 Conguring a PCI System: Part 3 . . . . . . . . . . . . . . . . . . . . 71
6.9 Conguring a PCI System: Part 4 . . . . . . . . . . . . . . . . . . . . 71
6.10 PCI Conguration Header: Base Address Registers . . . . . . . . . . . 72
7.1 A Logical Diagram of Interrupt Routing . . . . . . . . . . . . . . . . . 76
7.2 Linux Interrupt Handling Data Structures . . . . . . . . . . . . . . . . 78
8.1 Character Devices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
xv
8.2 Buer Cache Block Device Requests . . . . . . . . . . . . . . . . . . . 87
8.3 Linked list of disks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
8.4 SCSI Data Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
9.1 Physical Layout of the EXT2 File system . . . . . . . . . . . . . . . . 101
9.2 EXT2 Ino de . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
9.3 EXT2 Directory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
9.4 A Logical Diagram of the Virtual File System . . . . . . . . . . . . . . 107
9.5 Registered File Systems . . . . . . . . . . . . . . . . . . . . . . . . . . 110
9.6 A Mounted File System . . . . . . . . . . . . . . . . . . . . . . . . . . 111
9.7 The Buer Cache . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
10.1 TCP/IP Proto col Layers . . . . . . . . . . . . . . . . . . . . . . . . . . 121
10.2 Linux Networking Layers . . . . . . . . . . . . . . . . . . . . . . . . . 123
10.3 Linux BSD Socket Data Structures . . . . . . . . . . . . . . . . . . . . 126
10.4 The So cket Buer (sk bu ) . . . . . . . . . . . . . . . . . . . . . . . . 130
10.5 The Forwarding Information Database . . . . . . . . . . . . . . . . . . 136
11.1 Bottom Half Handling Data Structures . . . . . . . . . . . . . . . . . . 139
11.2 ATask Queue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
11.3 System Timers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
11.4 Wait Queue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
12.1 The List of Kernel Modules . . . . . . . . . . . . . . . . . . . . . . . . 147
Chapter 1
Hardware Basics
An op erating system has to work closely with the hardware system that
acts as its foundations. The op erating system needs certain services that
can only be provided by the hardware. In order to fully understand
the Linux op erating system, you need to understand the basics of the
underlying hardware. This chapter gives a brief introduction to that
hardware: the mo dern PC.
When the \Popular Electronics" magazine for January 1975 was printed with an
illustration of the Altair 8080 on its front cover, a revolution started. The Altair
8080, named after the destination of an early Star Trek episode, could b e assembled
by home electronics enthusiasts for a mere $397. With its Intel 8080 pro cessor and
256 bytes of memory but no screen or keyboard it was punybytoday's standards.
Its inventor, Ed Rob erts, coined the term \p ersonal computer" to describ e his new
invention, but the term PC is now used to refer to almost any computer that you
can pick up without needing help. By this denition, even some of the very p owerful
Alpha AXP systems are PCs.
Enthusiastic hackers saw the Altair's p otential and started to write software and
build hardware for it. To these early pioneers it represented freedom; the freedom
from huge batch processing mainframe systems run and guarded by an elite priest-
hood. Overnight fortunes were made by college drop outs fascinated by this new
phenomenon, a computer that you could have at home on your kitchen table. A lot
of hardware app eared, all dierent to some degree and software hackers were happy
to write software for these new machines. Paradoxically it was IBM who rmly cast
the mould of the modern PC by announcing the IBM PC in 1981 and shipping it to
customers early in 1982. With its Intel 8088 processor, 64K of memory (expandable
to 256K), two oppy disks and an 80 character by 25 lines Colour Graphics Adapter
(CGA) it was not very p owerful by to day's standards but it sold well. It was fol-
lowed, in 1983, by the IBM PC-XT which had the luxury of a 10Mbyte hard drive.
It was not long b efore IBM PC clones were being produced by a host of companies
such as Compaq and the architecture of the PC became a de-facto standard. This
de-facto standard helped a multitude of hardware companies to comp ete together in
a growing market which, happily for consumers, kept prices low. Many of the system
architectural features of these early PCs have carried over into the modern PC. For
example, even the most p owerful Intel Pentium Pro based system starts running in
the Intel 8086's addressing mo de. When Linus Torvalds started writing what was
to become Linux, he picked the most plentiful and reasonably priced hardware, an
1
p
CPU
parallel port
COM1 COM2
power power
ISA Slots
Memory SIMM Slots
PCI Slots
Figure 1.1: Atypical PC motherboard.
Intel 80386 PC.
Looking at a PC from the outside, the most obvious comp onents are a system b ox,
akeyboard, a mouse and a video monitor. On the front of the system b ox are some
buttons, a little display showing some numbers and a oppy drive. Most systems
these days have a CD ROM and if you feel that you have to protect your data, then
there will also b e a tap e drive for backups. These devices are collectively known as
the peripherals.
Although the CPU is in overall control of the system, it is not the only intelligent
device. All of the peripheral controllers, for example the IDE controller, have some
level of intelligence. Inside the PC (Figure 1.1) you will see a motherb oard containing
the CPU or micropro cessor, the memory and a number of slots for the ISA or PCI
peripheral controllers. Some of the controllers, for example the IDE disk controller
may be built directly onto the system b oard.
1.1 The CPU
The CPU, or rather microprocessor, is the heart of any computer system. The micro-
processor calculates, p erforms logical op erations and manages data ows by reading
instructions from memory and then executing them. In the early days of comput-
ing the functional comp onents of the micropro cessor were separate (and physically
large) units. This is when the term
Central Processing Unit
was coined. The modern
microprocessor combines these comp onents onto an integrated circuit etched onto
avery small piece of silicon. The terms
CPU
,
microprocessor
and
processor
are all
used interchangeably in this bo ok.
Microprocessors op erate on binary data; that is data composed of ones and zeros.
These ones and zeros corresp ond to electrical switches b eing either on or o. Just
as 42 is a decimal numb er meaning \4 10s and 2 units", a binary number is a series
of binary digits each one representing a p ower of 2. In this context, a p ower means
the number of times that a numberismultiplied by itself. 10 to the p ower 1 ( 10
1
)
is 10, 10 to the power2(10
2
) is 10x10, 10
3
is 10x10x10 and so on. Binary 0001 is
decimal 1, binary 0010 is decimal 2, binary 0011 is 3, binary 0100 is 4 and so on. So,
42 decimal is 101010 binary or (2+8+32 or 2
1
+2
3
+2
5
). Rather than using binary
to representnumb ers in computer programs, another base, hexadecimal is usually
used. In this base, each digital representsapower of 16. As decimal numbers only
go from 0 to 9 the numbers 10 to 15 are represented as a single digit by the letters
A, B, C, D, E and F. For example, hexadecimal E is decimal 14 and hexadecimal 2A
is decimal 42 (two 16s) + 10). Using the C programming language notation (as I do
throughout this bo ok) hexadecimal numbers are prefaced by\
0x
"; hexadecimal 2A
is written as
0x2A
.
Microprocessors can perform arithmetic operations such as add, multiply and divide
and logical op erations such as \is X greater than Y?".
The processor's execution is governed by an external clo ck. This clo ck, the system
clock, generates regular clo ck pulses to the pro cessor and, at each clo ck pulse, the
processor does some work. For example, a pro cessor could execute an instruction
every clock pulse. A processor's speed is described in terms of the rate of the system
clock ticks. A 100Mhz processor will receive 100,000,000 clo ck ticks every second. It
is misleading to describe the power of a CPU by its clo ck rate as dierent processors
perform dierent amounts of work per clock tick. However, all things b eing equal, a
faster clo ck sp eed means a more powerful pro cessor. The instructions executed by the
processor are very simple; for example \read the contents of memory at location X
into register Y". Registers are the micropro cessor's internal storage, used for storing
data and p erforming operations on it. The op erations p erformed may cause the
processor to stop what it is doing and jump to another instruction somewhere else in
memory. These tiny building blo cks give the mo dern micropro cessor almost limitless
power as it can execute millions or even billions of instructions a second.
The instructions have to be fetched from memory as they are executed. Instructions
may themselves reference data within memory and that data must b e fetched from
memory and saved there when appropriate.
The size, number and type of register within a microprocessor is entirely dependent
on its typ e. An Intel 4086 pro cessor has a dierent register set to an Alpha AXP
processor; for a start, the Intel's are 32 bits wide and the Alpha AXP's are 64 bits
wide. In general, though, any given pro cessor will haveanumber of general purpose
registers and a smaller number of dedicated registers. Most pro cessors have the
following special purp ose, dedicated, registers:
Program Counter (PC)
This register contains the address of the next instruction
to be executed. The contents of the PC are automatically incremented each
time an instruction is fetched,
Stack Pointer (SP)
Processors haveto have access to large amounts of external
read/write random access memory (RAM) which facilitates temporary storage
of data. The stackisaway of easily saving and restoring temp orary values in
external memory. Usually, pro cessors have sp ecial instructions which allowyou
to push values onto the stack and to pop them o again later. The stackworks
剩余207页未读,继续阅读
qiangfamily
- 粉丝: 1
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- AirKiss技术详解:无线传递信息与智能家居连接
- Hibernate主键生成策略详解
- 操作系统实验:位示图法管理磁盘空闲空间
- JSON详解:数据交换的主流格式
- Win7安装Ubuntu双系统详细指南
- FPGA内部结构与工作原理探索
- 信用评分模型解析:WOE、IV与ROC
- 使用LVS+Keepalived构建高可用负载均衡集群
- 微信小程序驱动餐饮与服装业创新转型:便捷管理与低成本优势
- 机器学习入门指南:从基础到进阶
- 解决Win7 IIS配置错误500.22与0x80070032
- SQL-DFS:优化HDFS小文件存储的解决方案
- Hadoop、Hbase、Spark环境部署与主机配置详解
- Kisso:加密会话Cookie实现的单点登录SSO
- OpenCV读取与拼接多幅图像教程
- QT实战:轻松生成与解析JSON数据
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功