Blog
Mert Özen's blog posts on software development, backend, frontend, and DevOps.
Scheduling: Which Thread Runs When? Context Switches, Priorities and Linux EEVDF
The scheduler runs more threads than there are cores in short slices and makes a context switch at every handoff; since 6.6 Linux does this with EEVDF, sharing fairly by nice weights. We count context switches through /proc, measure their cost, and show that nice 10 gets a tenth of the CPU, that Process.PriorityClass affects only the main thread on Linux, and that a --cpus=0.5 container is throttled in 30 of 31 periods.
Process Memory in Practice: mmap, Copy-on-Write, Shared Memory and Container Memory Limits
A process gets memory from the OS with mmap and VirtualAlloc; file-backed pages are shared between processes, copied on write, and in a container the .NET GC caps its heap at 75% of the cgroup limit. We measure a managed allocation in a 256 MB container ending in a catchable OutOfMemoryException at 189 MB instead of OOMKilled, a shared file being counted twice across two processes' RSS, and DATAS cutting Server GC's memory from 593 MB to 167 MB.
I/O Models and IPC: Blocking, Non-Blocking, epoll/kqueue/IOCP, Pipes and Signals
No thread waits during await: on Linux .NET registers sockets with epoll and a single .NET Sockets thread watches them all, while IOCP does the same job on Windows. We show with strace that 1000 idle connections hold 14 OS threads with async and 1014 with blocking, try Unix domain sockets and named pipes, and measure why a container started through a shell never receives SIGTERM and dies with 137 after 10 seconds.
Containers from the OS Perspective: Namespaces, cgroup v2 and "A Container Is Just a Process"
A container is an ordinary process whose view is limited by namespaces and whose consumption is limited by cgroups; it shares the host's kernel. We show that dotnet, PID 1 in the container, is process 300861 on the host, that the user namespace is shared, that .NET reads CPU and memory limits from the cgroup, and that creating threads past pids.max crashes with "Out of memory." while memory is free.