linux
Note: a reference example of the FreeBSD kernel is already available in great detail elsewhere.
User space
User Space ┌─────────────────┐ │ Applications │ User-level programs run here, user apps & tools │ (User Programs) │ like web browsers, text editors, & media players. ├─────────────────┤ │ Libraries │ Precompiled functions & code that apps use. ├─────────────────┤ │ Utilities │ Command-line user utilities like ls & cat. These │ (Commands) │ tools are used for scripting and automation. └─────────────────┘
Kernel space
Kernel Space ┌─────────────────┐ │ │ The heart of the OS. It manages hardware & offers │ Kernel │ services to apps, like time-sharing CPU bandwidth, │ │ managing memory, and talking to devices. ├─────────────────┤ │ File System │ This module manages files & directories, reading │ Management │ and writing data, and managing metadata (inodes). ├─────────────────┤ │ Process Control │ This module manages processes (running programs). │ and Scheduling │ It ensures fair CPU sharing, based on nice-ing. ├─────────────────┤ │ Memory Mgmt │ This module keeps process data isolated & current. ├─────────────────┤ │ Device Drivers │ Drivers operate devices, usually in standard ways. ├─────────────────┤ │ Networking │ Manages network communication. Includes protocols │ Stack │ for data transmission, handling sockets, managing │ │ connections, and routing data. ├─────────────────┤ │ │ The interface between user space and kernel space. │ System Calls │ Allows user programs to access kernel services, │ │ like file operations or memory allocation. ├─────────────────┤ │ Security │ Security mechanisms include access control, │ Mechanisms │ authentication, and authorization features that │ │ protect the system's resources and data. ├─────────────────┤ │ Interrupt │ The interrupt handler catches hardware interrupts │ Handling │ generated by devices. It manages their arrival │ │ prioritization, & handling. ├─────────────────┤ │ │ Handles strategies to optimize power usage, │ Power Mgmt │ including sleep states, CPU frequency scaling, │ │ and device power management. └─────────────────┘
File system management
File System Management ┌──────────────────────────────┐ │ File System │ Organizes and manages files and directories │ │ on storage devices, providing a structured │ │ way to store, retrieve, and organize data. ├──────────────────────────────┤ │ Directory Structure │ Represents the hierarchy of directories and │ │ subdirectories, enabling efficient navigation │ │ and organization of files. ├──────────────────────────────┤ │ File Operations │ Encompasses operations such as opening, │ │ reading, writing, closing, & deleting files, │ │ ensuring data integrity. ├──────────────────────────────┤ │ Metadata Management │ Manages metadata associated with files, │ (Inodes, Permissions, etc.) │ including information like ownership, │ │ permissions, timestamps, and file size. ├──────────────────────────────┤ │ File System Journaling and │ Maintains a journal or log of changes to the │ Transactional Support │ file system to ensure consistency and │ │ recoverability in case of failures. ├──────────────────────────────┤ │ Disk Space Allocation │ Handles the allocation and management of │ │ physical storage space on storage devices, │ │ preventing fragmentation and optimizing use. ├──────────────────────────────┤ │ Caching and Buffers │ Implements caching mechanisms to improve │ │ file read and write performance, using │ │ buffers to temporarily store data. └──────────────────────────────┘
inodes
Inode Structure ┌───────────────────────────────┐ │ Inode │ Inodes are essential data structures in │ │ Unix-like file systems (such as ext4). │ │ They store metadata about files and │ │ directories, as well as pointers to the │ │ actual data blocks that contain the │ │ file's content. │ ┌───────────────────────────┐ │ │ │ File Metadata │ │ Inodes store information like file │ ├───────────────────────────┤ │ permissions, ownership (user and group), │ │ File Permissions: Owner, │ │ creation/modification/access timestamps, │ │ Group, Timestamps, Size │ │ and the size of the file. │ ├───────────────────────────┤ │ │ │ Block Pointers │ │ Inodes have pointers to data blocks where │ │ (Direct, Indirect, │ │ the actual content of the file is stored. │ │ Double Indirect, etc.) │ │ These pointers can be direct (pointing to │ │ │ │ data blocks directly), indirect (pointing │ │ │ │ to blocks that contain more pointers), │ │ │ │ double indirect (pointing to blocks that │ │ │ │ contain indirect pointers), and so on, │ │ │ │ enabling efficient storage of large files. │ ├───────────────────────────┤ │ │ │ Other Metadata │ │ Inodes can also store extended attributes │ │ (Extended Attributes, │ │ (extra metadata not covered by the │ │ ACLs, etc.) │ │ traditional attributes) and Access Control │ │ │ │ Lists (ACLs) for advanced perms management. │ └───────────────────────────┘ │ └───────────────────────────────┘ │ │ │ ▼ ┌────────────────────┐ │ Data Blocks │ The actual content of a file is stored in data │ (File Content) │ blocks. These blocks are pointed to by the block │ │ pointers in the inode. Data blocks can be of │ │ varying sizes and are organized in a way that │ │ optimizes storage efficiency. └────────────────────┘
Process control and scheduling
Process Control and Scheduling ┌───────────────────┐ │ Process Control │ │ and Management │ Manages processes' creation, termination, │ │ synchronization, and communication. ├───────────────────┤ │ Process States │ Tracks the various states a process can be in, │ │ including Running, Ready, Blocked, etc. ├───────────────────┤ │ CPU Scheduling │ Selects processes for execution, optimizing │ │ CPU utilization, response time, and fairness. ├───────────────────┤ │ Context Switching │ Involves saving and restoring the state of │ │ processes when switching between them. ├───────────────────┤ │ Inter-Process │ Facilitates data sharing and communication │ Communication │ between processes, using mechanisms like │ │ message passing and shared memory. ├───────────────────┤ │ Process Creation │ Handles the creation of new processes, │ and Termination │ including resource allocation and cleanup. └───────────────────┘
Process management
Process Management in Linux ┌───────────────────────────┐ │ User Space │ │ ┌───────────────────────┐ │ │ │ User Programs │ │ │ │ (Applications, │ │ │ │ Utilities, etc.) │ │ │ └───────────────────────┘ │ │ │ │ │ ▼ │ │ ┌───────────────────────┐ │ │ │ System Calls, │ │ │ │ Libraries, etc. │ │ │ └───────────────────────┘ │ │ │ │ │ ▼ │ │ ┌───────────────────────┐ │ │ │ Kernel Space │ │ │ │ ┌───────────────────┐ │ │ │ │ │ Process Scheduler │ │ │ Manages task exec, optimizes CPU utilization. │ │ ├───────────────────┤ │ │ │ │ │ Scheduler Queue │ │ │ Holds tasks awaiting CPU allocation. │ │ ├───────────────────┤ │ │ │ │ │ Time Management │ │ │ Ensures fair and efficient task scheduling. │ │ ├───────────────────┤ │ │ │ │ │ CPU Affinity │ │ │ Binds process to specific CPUs. │ │ ├───────────────────┤ │ │ │ │ │ Preemption & │ │ │ Pauses executing process, switches to another, │ │ │ Context Switching │ │ │ resumes when needed. │ │ ├───────────────────┤ │ │ │ │ │ Priority Inversion│ │ │ Prevents low-priority task blocking │ │ │ Avoidance │ │ │ high-priority task. │ │ ├───────────────────┤ │ │ │ │ │ Load Balancing │ │ │ Distributes tasks for resource optimization. │ │ ├───────────────────┤ │ │ │ │ │ Real-time Sched │ │ │ Enforces timing constraints, ensures critical │ │ │ and Policies │ │ │ task completion. │ │ └───────────────────┘ │ │ │ └───────────────────────┘ │ └───────────────────────────┘