Kernel Thread

It is often useful for the kernel to perform some operations in the background.The ker- nel accomplishes this via kernel threads—standard processes that exist solely in kernel- space.The significant difference between kernel threads and normal processes is that kernel threads do not have an address space. (Their mm pointer, which points at their address space, is NULL.) They operate only in kernel-space and do not context switch into user-space. Kernel threads, however, are schedulable and preemptable, the same as normal processes.

对kernel 来说在background执行一些操作是很有用的,比如xxx. 内核通过kernel threads 来满足这些需要。

Why:

What:

How:

Data Structure:

Function:

RCU

RCU是Read-copy update的简称。属于内核的一个同步机制。
目的: 提高允许读和更新同时出现的灵活性。
之前的机制及其缺点:锁。传统的加锁机制是确保相互之间的排斥,不论是reader,updater。(读写锁)read-writer允许在没有update的时候同时读。
特点:RCU支持同时出现一个updater 和多个reader. RCU 维护object的多个version并且确保所有之前存在的read-side 临界区完成后再释放object ,从而确保读是连贯的。

文件系统(File System)

什么是文件系统(what are file systems)

A file system is an organization of data and metadata on a storage device.

File System Architecture

0

The system call interface acts a switch, funneling system calls from user space to the appropriate endpoints in kernel space.

The VFS is the primary interface to the underlying file systems. This component exports a set of interfaces and then abstracts them to the individual file systems, which may behave very differently from one another. Two caches exist for file system objects(inodes and dentries). Each provides a pool of recently-used file system objects.

Each individual file system implementation, such as ext2 and so on, exports a common set of interfaces that is used(and expected) by the VFS. The buffer cache requests between the file systems and the

perf

那么 perf 是怎么做到的呢?首先,perf 会通过系统调用 sys_perf_event_open
在内核中注册一个监测“cycles”事件的性能计数器。内核根据 perf 提供的信息在
PMU 上初始化一个硬件性能计数器 ( PMC: Performance Monitoring Counter)。PMC
随着 CPU 周期的增加而自动累加。在 PMC 溢出时, PMU 触发一个 PMI
( Performance Monitoring Interrupt)中断。内核在 PMI 中断的处理函数中保存
PMC 的计数值,触发中断时的指令地址( Register IP: Instruction Pointer),当前
时间戳以及当前进程的 PID, TID, comm 等信息。我们把这些信息统称为一个采
样( sample)。内核会将收集到的 sample 放入用于跟用户空间通信的 Ring Buffer。
用户空间里的 perf 分析程序采用 mmap 机制从 ring buffer 中读入采样,并对其解
析。 perf 根据 pid, comm 等信息可以找到对应的进程。根据 IP 与 ELF 文件中的
符号表可以查到触发 PMI 中断的指令所在的函数。为了能够使 perf 读到函数名,
我们的目标程序必须具备符号表。