Kernel

Image showing Fundamental Architecture of Linux

  • 소프트웨어와 하드웨어 사이의 인터페이스 역할을 함
  • 소프트웨어와 하드웨어 사이에서 상호작용을 하며 자원을 가능한한 효율적으로 관리 한다.
    • 커널은 장치 드라이버를 통해서 모든 하드웨어 리소스(Ex. I/O, 메모리, 암호화 등)를 제어하고 이러한 리소스와 관련된 프로세스 간의 충돌을 중재하며, CPU 및 캐시 사용, 파일 시스템 및 네트워크 소켓과 같은 공통 리소스의 활용을 최적화 한다.

The kernel is the heart of the operating system and controls all the important functions of hardware – this is the case for Linux, macOS and Windows, smartphones, servers, and virtualizations like KVM as well as every other type of computer.

Structure of a kernel: 5 Layers

A kernel is always built the same way and consists of several layers:

  • Layer 5: The highest layer is the File system. That’s where processes are assigned to RAM or the hard drive.
    • Communication with Software
  • Layer 4: Device management.
  • Layer 3: Process management (scheduler). Which is responsible for time management and makes multitasking possible.
  • Layer 2: Memory management. Which entails distributing RAM including the virtual main memory.
  • Layer 1: The deepest layer is the interface with hardware (processors, memory, and devices). Which manages network controllers and PCI express controllers.
    • Lowest layer is machine oriented. It can communicate directly with the hardware, processor, and memory.

The four functions of the kernel

  • Memory management: Regulates how much memory is used in different places.
  • Process management: Determines which processes the CPU can use, as well as when and how long they’re used for.
  • Device driver: Intermediates between hardware and processes.
  • System calls and security: Receives service requests from the processes.

The kernel in the operating system

  • Hardware: The foundation of the system, made up of RAM, the processor and input and output devices. The CPU carries out reading and writing operations and calculations for the memory.
  • Kernel: The nucleus of the operating system in contact with the CPU.
  • User processes: All running processes that the kernel manages. The kernel makes communication between processes and servers possible, also known as Inter-Process Communication (IPC).

The kernel modes

  • Kernel Mode: Access to the hardware.
  • User Mode: Areas accessible to users. (Ex. Code, Data, Stack, Heap Area in Process)
    • In User mode, the executing code has no ability to directly access hardware or reference memory.
    • Code running in user mode must delegate to system APIs to access hardware or memory.
    • Due to the protection afforded by this sort of isolation, crashes in user mode are always recoverable.

Switching between User Mode and Kernel Mode

The transition from user mode to kernel mode occurs when the application requests the help of operating system or an interrupt or a system call occurs.

The mode bit is set to 0 in the kernel mode. It is changed from 0 to 1 when switching from kernel mode to user mode.

XNU

XNU is OS kernel used for Mac OS:

Architecture of AIOS: LLM Agent Operating System

Architecture of AIOS: LLM Agent Operating System: