Summary Files Commits Branches @commit @diff @stats
path: root / src
diff options
context:
space:
mode:
Commit53d6dbf0c1095a03f5935810a3e642a1c1c0b7cd (patch)
Author
 Syndamia <kamen@syndamia.com>
2023-02-26 14:11:48 +0200
Committer
 Syndamia <kamen@syndamia.com>
2023-02-26 14:11:48 +0200
Files9338b9ac10005b9a864975940ea32a95b0d0ca8c /src
syndamia.com-53d6dbf0c1095a03f5935810a3e642a1c1c0b7cd.tar
syndamia.com-53d6dbf0c1095a03f5935810a3e642a1c1c0b7cd.tar.gz
syndamia.com-53d6dbf0c1095a03f5935810a3e642a1c1c0b7cd.zip
Parent47510d932f0dad22422feab8f77c6bab99c1e8f4 (diff)
[talks/lbs] Added slides for memory and process management, restructured kernel slide
2 files changed, 160 insertions, 3 deletions
-rw-r--r--src/talks/linuxgraphy-by-strabo/img/virtual-memory-by-Ehamberg.pngbin0 -> 31668 bytes
-rw-r--r--src/talks/linuxgraphy-by-strabo/index.md163
diff --git a/src/talks/linuxgraphy-by-strabo/img/virtual-memory-by-Ehamberg.png b/src/talks/linuxgraphy-by-strabo/img/virtual-memory-by-Ehamberg.png
new file mode 100644
index 0000000..0f2880c
--- /dev/null
+++ b/src/talks/linuxgraphy-by-strabo/img/virtual-memory-by-Ehamberg.png
Binary files differ
diff --git a/src/talks/linuxgraphy-by-strabo/index.md b/src/talks/linuxgraphy-by-strabo/index.md
index 12b9e6c..fd6d7e3 100644
--- a/src/talks/linuxgraphy-by-strabo/index.md
+++ b/src/talks/linuxgraphy-by-strabo/index.md
@@ -416,19 +416,176 @@ Every user has their own "home" folder (under "/home/USERNAME/", except for root
-&&slide &&font35
+&&slide
## 2.3. Kernel
+&&font18 &&lineb1 &&/font
+
The kernel has the core functionality of the operating system and bridges the gap between programs and hardware.
Some important subsystems include scheduling, file, device, process and memory management.
To preserve the [everything is a file](https://en.wikipedia.org/wiki/Everything_is_a_file) methodology, devices and processes can be handled as files (inside `/dev` and `/proc`).
-They (often, in modern kernels) aren't actual files on a hard drive, but "virtual" files, where operations on them are handled in a different manner than normal by the kernel.
+They (most of the time, in modern kernels) aren't actual files on a hard drive, but "virtual" files, where operations on them are handled in a different manner than normal by the kernel.
+
+&&lineb2
+
+&&font35 Linux is **not** an operating system, it is a kernel!!! &&/font
+
+&&lineb2
+
+Two of the important things a kernel does is manage **processes** and **memory**.
+
+&&/slide
+
+
+
+&&slide &&font35
+
+### 2.3.1 Processes
&&lineb1
-Linux is **not** an operating system, it is a kernel!!!
+A program is some collection of code and other data, stored in a file (or uncompiled code).
+A process is the program in motion, the program itself *alongside* certain system states.
+
+The system states include (but are not limited to):
+
+- the processor state, including the program counter and register values
+- memory map, indicating what regions of memory are allocated (to the process)
+- [file descriptors](https://en.wikipedia.org/wiki/File_descriptor), unique identifiers for files
+
+
+&&/font &&/slide
+
+
+
+&&clide &&font35
+
+On a multitasking (multiprocessing) system, which is any modern desktop system, multiple processes are always running "at once".
+
+In reality, constantly one process is stopped and another is ran, switching between all of them ([context switching](https://en.wikipedia.org/wiki/Context_switch)).
+All "waiting" processes are put in a prioritized queue ([run queue](https://en.wikipedia.org/wiki/Run_queue)).
+
+Stopping is either done by the process itself (more on that later), or by the system when the process has been actively running for too much time.
+
+&&/font &&/clide
+
+
+
+&&clide &&font35
+
+All process information is stored in a data structure, called a *process control block* (or process descriptor).
+Not to be confused with a [printed circuit board](https://en.wikipedia.org/wiki/Printed_circuit_board)!
+A PCB's data can be split into three categories:
+
+1. **Process identification** - the ID of the process itself, of it's parent process, of it's owner (user), etc.
+2. **Process state** - as described, the processor state, etc.
+ On a context switch, values in register are put into the stopped PCB and then are loaded from the running PCB.
+3. **Process control information** - process state, memory map, privileges, etc.
+
+A process can be **forked**, meaning a new process is created, with the same underlying code (but not process states and ...).
+
+&&/font &&/clide
+
+
+
+&&clide &&font35
+
+Typically, there are at least 5 process states:
+
+- **Created**: This is the initial state given to a new process. In this state, the process awaits a "ready" state.
+- **Ready** (Waiting): A process is put in the run queue and awaits being executed ("running" state).
+- **Running**: When the process's program is being currently executed by the CPU. The process can run in either *kernel mode*, having access to the kernel and user addresses, or *user mode*, having access only to it's own code and data.
+- **Blocked**: When a process cannot continue without external change, usually when waiting for an I/O device.
+- **Terminated**: The process has either completed execution or has been killed. The process itself is called a ["zombie process"](https://en.wikipedia.org/wiki/Zombie_process) (until it is removed).
+
+&&/font &&/clide
+
+
+
+&&slide &&font35
+
+### 2.3.2 Memory management
+
+&&lineb2
+
+In ye olde days, you would save a bit of memory for the operating system and give all of the rest to the current process ([monoprogramming](https://en.wiktionary.org/wiki/monoprogramming)), which we wait until completion.
+
+This doesn't allow for context switching (disks are slow) and a blocked state forces the CPU to wait.
+
+Some bad ideas include: depending on the code of all processes to not use the same addresses, use only [relative addresses](https://en.wikipedia.org/wiki/Position-independent_code) (`-fPIC` option in `gcc`) or use a [table](https://en.wikipedia.org//wiki/Relocation_%28computing%29#Relocation_table) that the kernel fills out with addresses.
+
+&&/font &&/slide
+
+
+
+&&slide &&font35
+
+### Virtual memory
+
+&&lineb2
+
+&&fright
+![](./img/virtual-memory-by-Ehamberg.png)
+&&font18 *Image by [Ehamberg](https://commons.wikimedia.org/wiki/File:Virtual_memory.svg)* &&/font
+&&/fright
+
+A process work with some (sequential) addresses, and the OS (with the help of [hardware](https://en.wikipedia.org/wiki/Memory_management_unit)) translates/maps the process' addresses (logical/[virtual addresses](https://en.wikipedia.org/wiki/Virtual_address_space)) to real ones (physical addresses).
+
+We simplify memory management for the program, protects each process' address space and is very flexible.
+
+&&/font &&/slide
+
+
+
+&&slide &&font35
+
+#### Segmentation (without paging)
+
+&&lineb2
+
+Initially, virtual memory was implemented with segmentation, where a process' memory is divided into segments for code, stack, heap, etc.
+Each segment is given a chunk of contiguous memory, which can be resized, and addresses are defined as the base segment (physical) address with an offset.
+
+In the modern day, segmentation isn't used by itself, since resizing segments could require reordering of memory and [external fragmentation](https://en.wikipedia.org/wiki/Fragmentation_%28computing%29#External_fragmentation), where there simply isn't enough contiguous memory, could occur.
+
+
+&&/font &&/slide
+
+
+
+&&slide &&font35
+
+#### Paging
+
+&&lineb3
+
+The virtual and physical memory is divided into fixed-sized chunks of consequtive addresses.
+A virtual memory chunk is called a **page**, while a physical memory chunk is called a (page) **frame**.
+Usually both have the same size of (at least) 4 KiB.
+
+Every process has a [page table](https://en.wikipedia.org/wiki/Page_table), which maps the process' pages to system frames.
+Thus every memory address is translated from it's page location to a frame location.
+
+&&/font &&/slide
+
+
+
+&&slide &&font35
+
+Advantages include:
+
+- elimination of [external fragmentation](https://en.wikipedia.org/wiki/Fragmentation_%28computing%29#External_fragmentation)
+- increased flexibility, allowed sharing of memory between processes (useful for shared libraries)
+- finding free memory is fast and easy, just use the first free pages you see
+- frames can be scattered
+- more efficient swapping, moving of memory from RAM to disk and back
+
+Disadvantages include:
+
+- longer memory access, because of the page table
+- [internal fragmentation](https://en.wikipedia.org/wiki/Fragmentation_%28computing%29#Internal_fragmentation), where one or multiple pages might be partially empty, leaving free space that cannot be used
&&/font &&/slide