4.2.41 · D3 · HinglishOperating Systems

Worked examplesContainers — namespaces, cgroups, difference from VMs

3,157 words14 min read↑ Read in English

4.2.41 · D3 · Coding › Operating Systems › Containers — namespaces, cgroups, difference from VMs

Yeh page Containers — namespaces, cgroups, difference from VMs ka drill floor hai. Hum parent se do ideas lete hain — namespaces (ek process kya DEKH sakta hai) aur cgroups (ek process kya USE kar sakta hai) — aur unhe har us case se guzarte hain jo ek real machine ya exam throw kar sakti hai.

Shuru karne se pehle, ek reminder taaki kuch bhi use hone se pehle build ho jaye:


Scenario matrix

Containers ke baare mein har sawaal inhi cells mein se ek mein aata hai. Neeche diye worked examples mein se har ek us cell ke saath tagged hai jo woh cover karta hai, aur saath mein yeh sab hit karte hain.

# Case class Tricky part Example
A CPU quota < period (fraction of a core) share below 1 Ex 1
B CPU quota = period (exactly one core) boundary value Ex 2
C CPU quota > period (multiple cores) share above 1 Ex 3
D Degenerate quota = max (unlimited) division by "infinity" Ex 4
E Memory limit + OOM decision byte arithmetic, over/under Ex 5
F PID namespace numbering "PID 1" ka surprise Ex 6
G User namespace UID mapping root-inside ≠ root-outside Ex 7
H Container vs VM word problem kaunsa, aur kyun Ex 8
I Exam twist: cgroup without namespace isolation vs limits confusion Ex 9

CPU share: cases A, B, C, D

Agla figure ek CPU ki timeline hai. Time left se right chalti hai; har period ek box hai; har box ka shaded part woh quota hai jo group ko run karne ki allowed hai. Dekho ki fraction chaaron cases mein kaise badlta hai — woh fraction hi answer hai. (Case C ko zyada se zyada ek core chahiye, isliye usse ek se zyada aise timelines chahiye — hum usse Ex 3 mein words mein handle karte hain.)

Figure — Containers — namespaces, cgroups, difference from VMs

Memory: case E


Namespaces: cases F and G

Agla figure do process tables side by side dikhata hai: host ka table (bahut saare PIDs) aur container ka private PID-namespace table (1 se renumbered). Red arrow follow karo — yeh wahi running process hai jo do alag ID badges pehne hai.

Figure — Containers — namespaces, cgroups, difference from VMs

Container vs VM: cases H and I


Recall Poore matrix par self-test

cpu.max = "50000 200000" kitne cores deta hai? ::: cores memory.max = 134217728 kitne MiB hai? ::: MiB Naya PID namespace: pehle process ko kaunsa PID milta hai? ::: 1 User-ns container-0 ko base 100000 par map karta hai → host UID? ::: 100000 (unprivileged, root nahi) Us mapping ke allow hone ke liye /etc/subuid mein kya hona chahiye? ::: user ke liye ek delegated range, jaise alice:100000:65536 Cgroup alone, koi namespace nahi: kya woh host processes hide kar sakta hai? ::: Nahi — sirf namespaces view isolate karte hain memory.current RSS ke saath kya charge karta hai? ::: reclaimable page cache (isliye charged memory > RSS)


Parent topic par wapas jao · prerequisite: Processes and the clone/fork syscall · related: Scheduling — CFS and CPU shares, Networking — virtual interfaces and bridges, Filesystems — mount and chroot.