UGC-NET, GATE, NIELIT (O/A/B Level), KVS/NVS Computer Teacher, PGDCA, BCA, MCA, B-Tech व All India IT Exam विशेष नोट्स: इस अध्याय में हम Slab Allocator and Buddy System Kernel Memory Management (कर्नेल मेमोरी प्रबंधन: स्लैब एलोकेटर और बडी सिस्टम) की संपूर्ण थ्योरी, मुख्य तकनीकी बिंदु, तुलनात्मक तालिका और राष्ट्रीय स्तर की परीक्षाओं के पैटर्न पर आधारित 20 अति-महत्वपूर्ण बहुविकल्पीय प्रश्न (MCQs) विस्तृत हिंदी व अंग्रेजी व्याख्या सहित पढ़ेंगे।
Overview: Kernel memory management relies on the Buddy System to allocate physically contiguous page frames in powers of two while minimizing external fragmentation. The Slab Allocator sits atop the Buddy System, caching frequently used kernel objects like task_struct and inodes to eliminate internal fragmentation and initialization overhead.
अध्याय सार: कर्नेल मेमोरी प्रबंधन बाहरी विखंडन (external fragmentation) को कम करते हुए 2 की घात (powers of two) में भौतिक रूप से सन्निहित पेज फ्रेम आवंटित करने के लिए बडी सिस्टम का उपयोग करता है। स्लैब एलोकेटर बडी सिस्टम के ऊपर काम करता है और task_struct व inodes जैसे कर्नेल ऑब्जेक्ट्स को कैश करके आंतरिक विखंडन को समाप्त करता है।
Slab Allocator and Buddy System Kernel Memory Management: Detailed Notes & Architecture (कर्नेल मेमोरी प्रबंधन: स्लैब एलोकेटर और बडी सिस्टम)
1. Buddy System Allocation Mechanics (बडी सिस्टम आवंटन तंत्र)
[EN] The Buddy System manages free physical page frames by grouping them into 11 free lists of sizes 2^0 (1 page) up to 2^10 (1024 pages). When a request for k pages arrives, it rounds up to the nearest power of two; if that list is empty, a larger block is split into two equal 'buddies'. Upon deallocation, adjacent free buddies of the same size are coalesced back into a larger block.
[HI] बडी सिस्टम मुक्त भौतिक पेज फ्रेम को 2^0 (1 पेज) से 2^10 (1024 पेज) तक की 11 फ्री लिस्ट में समूहित करके प्रबंधित करता है। जब k पेजों का अनुरोध आता है, तो यह निकटतम 2 की घात तक राउंड अप करता है; यदि वह लिस्ट खाली है, तो एक बड़े ब्लॉक को दो समान 'बडीज़' में विभाजित किया जाता है। मुक्त करने पर, समान आकार के आसन्न बडीज़ को वापस बड़े ब्लॉक में मर्ज कर दिया जाता है।
2. Slab Allocator Architecture (स्लैब एलोकेटर आर्किटेक्चर)
[EN] Allocating whole 4 KB pages for small kernel structures (e.g., a 128-byte inode) causes severe internal fragmentation. The Slab Allocator (introduced by Jeff Bonwick in Solaris and adopted in Linux) groups one or more contiguous pages into a 'slab' divided into fixed-size object slots. Caches maintain three lists: full slabs, partial slabs, and empty slabs.
[HI] छोटी कर्नेल संरचनाओं (जैसे 128-बाइट inode) के लिए पूरे 4 KB पेज आवंटित करने से गंभीर आंतरिक विखंडन होता है। स्लैब एलोकेटर एक या अधिक सन्निहित पेजों को 'स्लैब' में समूहित करता है जिसे निश्चित आकार के ऑब्जेक्ट स्लॉट्स में विभाजित किया जाता है। कैश तीन सूचियाँ बनाए रखते हैं: पूर्ण (full), आंशिक (partial), और खाली (empty) स्लैब।
3. SLAB, SLUB, and SLOB Variants in Linux (Linux में SLAB, SLUB और SLOB वेरिएंट)
[EN] Linux historically offered three slab allocators: SLAB (the original complex queue-based design), SLUB (the unqueued default allocator since Linux 2.6.23), and SLOB (a compact K&R-style allocator for embedded systems, removed in Linux 6.4). SLUB simplifies metadata by storing free-object pointers inside the unallocated slots themselves and reduces lock contention on multi-core CPUs.
[HI] Linux में ऐतिहासिक रूप से तीन स्लैब एलोकेटर रहे हैं: SLAB (मूल क्यू-आधारित डिज़ाइन), SLUB (Linux 2.6.23 से डिफ़ॉल्ट अनक्यूड एलोकेटर), और SLOB (एम्बेडेड सिस्टम के लिए कॉम्पैक्ट एलोकेटर, जिसे Linux 6.4 में हटा दिया गया)। SLUB अनआवंटित स्लॉट्स के भीतर ही फ्री-ऑब्जेक्ट पॉइंटर्स स्टोर करके मेटाडेटा को सरल बनाता है।
4. kmalloc vs vmalloc in Kernel Space (कर्नेल स्पेस में kmalloc बनाम vmalloc)
[EN] The kmalloc() function uses the Slab/SLUB allocator to return memory that is both physically and virtually contiguous, making it ideal for DMA buffers and performance-critical kernel code. In contrast, vmalloc() allocates non-contiguous physical pages and maps them into a contiguous virtual address range, which incurs TLB overhead and is used for large buffers like kernel modules.
[HI] kmalloc() फ़ंक्शन स्लैब/SLUB एलोकेटर का उपयोग करके ऐसी मेमोरी लौटाता है जो भौतिक और वर्चुअल दोनों रूप से सन्निहित होती है, जो DMA बफ़र्स के लिए आदर्श है। इसके विपरीत, vmalloc() गैर-सन्निहित भौतिक पेजों को आवंटित करता है और उन्हें सन्निहित वर्चुअल एड्रेस रेंज में मैप करता है, जिसमें TLB ओवरहेड अधिक होता है।
Syntax, Formula & Technical Example (Slab Allocator and Buddy System Kernel Memory Management)
# Inspect Buddy System free page blocks in Linux
cat /proc/buddyinfo
# Inspect Slab/SLUB object caches
sudo cat /proc/slabinfo | head -n 10
# Kernel C API usage
struct kmem_cache *my_cache = kmem_cache_create("my_obj", sizeof(struct my_obj), 0, SLAB_HWCACHE_ALIGN, NULL);
void *obj = kmem_cache_alloc(my_cache, GFP_KERNEL);
kmem_cache_free(my_cache, obj);
Slab Allocator and Buddy System Kernel Memory Management Quick Reference & Comparison Table
| Allocator / API | Contiguity Guarantee | Key Exam Fact |
|---|---|---|
| Buddy System | Physically contiguous (2^n pages) | Coalesces free buddies to prevent external fragmentation |
| SLUB Allocator | Object-level cache over pages | Default Linux slab allocator; minimal metadata |
| kmalloc() | Physically & virtually contiguous | Backed by SLUB; required for DMA transfers |
| vmalloc() | Virtually contiguous only | Maps scattered physical pages; higher TLB overhead |
Slab Allocator and Buddy System Kernel Memory Management Top 20 Bilingual MCQs with Answers
Q1. What is the primary purpose of the Buddy System in an operating system kernel?
(ऑपरेटिंग सिस्टम कर्नेल में बडी सिस्टम का मुख्य उद्देश्य क्या है?)
(A) Manage user-space heap via malloc
(B) Encrypt swap space
(C) Manage physically contiguous page frames in powers of two
(D) Schedule CPU threads
Correct Answer: (C)
[EN] The Buddy System allocates and coalesces physical page frames in power-of-two blocks.
[HI] बडी सिस्टम 2 की घात के ब्लॉकों में भौतिक पेज फ्रेम आवंटित और मर्ज करता है।
Q2. Which type of fragmentation does the Buddy System primarily reduce by coalescing adjacent free blocks?
(आसन्न मुक्त ब्लॉकों को मर्ज करके बडी सिस्टम मुख्य रूप से किस प्रकार के विखंडन को कम करता है?)
(A) Internal fragmentation
(B) External fragmentation
(C) Disk fragmentation
(D) TLB thrashing
Correct Answer: (B)
[EN] Coalescing adjacent buddies restores larger contiguous blocks, reducing external fragmentation.
[HI] आसन्न बडीज़ को मर्ज करने से बड़े सन्निहित ब्लॉक वापस मिलते हैं, जिससे बाहरी विखंडन कम होता है।
Q3. What problem does the Slab Allocator solve that the Buddy System alone cannot?
(स्लैब एलोकेटर किस समस्या को हल करता है जिसे अकेला बडी सिस्टम हल नहीं कर सकता?)
(A) Page fault handling
(B) Context switching latency
(C) Deadlock detection
(D) Internal fragmentation for small kernel objects
Correct Answer: (D)
[EN] Allocating a 4 KB page for a 100-byte object wastes space; Slab divides pages into exact object-sized slots.
[HI] 100-बाइट ऑब्जेक्ट के लिए 4 KB पेज आवंटित करने से स्थान बर्बाद होता है; स्लैब पेजों को सटीक ऑब्जेक्ट-आकार के स्लॉट्स में बांटता है।
Q4. Which slab allocator is the default in modern Linux kernels (since 2.6.23)?
(आधुनिक Linux कर्नेल (2.6.23 से) में कौन सा स्लैब एलोकेटर डिफ़ॉल्ट है?)
(A) SLOB
(B) jemalloc
(C) SLAB
(D) SLUB
Correct Answer: (D)
[EN] SLUB replaced SLAB as the default due to simpler metadata and better multi-core scalability.
[HI] सरल मेटाडेटा और बेहतर मल्टी-कोर स्केलेबिलिटी के कारण SLUB ने SLAB की जगह ली।
Q5. Which Linux file displays the current state of Buddy System free lists per NUMA node and zone?
(कौन सी Linux फ़ाइल प्रति NUMA नोड और ज़ोन बडी सिस्टम फ्री लिस्ट की स्थिति दिखाती है?)
(A) /proc/slabinfo
(B) /proc/meminfo
(C) /proc/buddyinfo
(D) /proc/vmstat
Correct Answer: (C)
[EN] /proc/buddyinfo shows free page counts for orders 0 through 10.
[HI] /proc/buddyinfo ऑर्डर 0 से 10 तक मुक्त पेजों की संख्या दिखाता है।
Q6. Which kernel allocation function guarantees both physical and virtual contiguity?
(कौन सा कर्नेल आवंटन फ़ंक्शन भौतिक और वर्चुअल दोनों सन्निहितता की गारंटी देता है?)
(A) malloc()
(B) brk()
(C) vmalloc()
(D) kmalloc()
Correct Answer: (D)
[EN] kmalloc() returns physically contiguous memory suitable for hardware DMA.
[HI] kmalloc() हार्डवेयर DMA के लिए उपयुक्त भौतिक रूप से सन्निहित मेमोरी लौटाता है।
Q7. In the Slab Allocator, what are the three states of a slab in a cache?
(स्लैब एलोकेटर में, कैश में एक स्लैब की तीन अवस्थाएँ क्या होती हैं?)
(A) Ready, Running, Blocked
(B) Full, Partial, and Empty
(C) Active, Inactive, Zombie
(D) Clean, Dirty, Swapped
Correct Answer: (B)
[EN] Slabs are tracked on full, partial, and empty lists; allocations prefer partial slabs first.
[HI] स्लैब को full, partial और empty सूचियों में ट्रैक किया जाता है।
Q8. Who originally designed the Slab Allocator for the Solaris 2.4 kernel?
(Solaris 2.4 कर्नेल के लिए मूल रूप से स्लैब एलोकेटर किसने डिज़ाइन किया था?)
(A) Andrew Tanenbaum
(B) Jeff Bonwick
(C) Linus Torvalds
(D) Ken Thompson
Correct Answer: (B)
[EN] Jeff Bonwick introduced the slab allocator in 1994 to cache pre-initialized kernel objects.
[HI] जेफ बोनविक ने 1994 में पूर्व-आरंभीकृत कर्नेल ऑब्जेक्ट्स को कैश करने के लिए स्लैब एलोकेटर पेश किया।
Q9. Which slab allocator was designed for tiny embedded systems and removed in Linux 6.4?
(छोटे एम्बेडेड सिस्टम के लिए कौन सा स्लैब एलोकेटर डिज़ाइन किया गया था और Linux 6.4 में हटा दिया गया?)
(A) SLUB
(B) SLOB
(C) CMA
(D) SLAB
Correct Answer: (B)
[EN] SLOB (Simple List Of Blocks) was deprecated and removed in Linux 6.4.
[HI] SLOB (सिंपल लिस्ट ऑफ ब्लॉक्स) को Linux 6.4 में हटा दिया गया।
Q10. What does SLAB_HWCACHE_ALIGN flag do when creating a kmem_cache?
(kmem_cache बनाते समय SLAB_HWCACHE_ALIGN फ्लैग क्या करता है?)
(A) Pins pages in swap
(B) Aligns objects to CPU L1 cache line boundaries
(C) Disables interrupts
(D) Enables hugepages
Correct Answer: (B)
[EN] Cache-line alignment prevents false sharing and improves CPU cache hit rates.
[HI] कैश-लाइन एलाइनमेंट फॉल्स शेयरिंग को रोकता है और CPU कैश हिट दर में सुधार करता है।
Q11. If a process requests 18 pages from a Buddy System, how many pages are actually allocated?
(यदि कोई अनुरोध बडी सिस्टम से 18 पेज मांगता है, तो वास्तव में कितने पेज आवंटित होते हैं?)
(A) 16 pages
(B) 32 pages
(C) 20 pages
(D) 18 pages
Correct Answer: (B)
[EN] The Buddy System rounds up to the next power of two: 2^5 = 32 pages.
[HI] बडी सिस्टम अगले 2 की घात तक राउंड अप करता है: 2^5 = 32 पेज।
Q12. Which command or file is used to inspect kernel slab cache statistics in Linux?
(Linux में कर्नेल स्लैब कैश आंकड़ों का निरीक्षण करने के लिए किस फ़ाइल का उपयोग किया जाता है?)
(A) /proc/slabinfo
(B) /proc/cpuinfo
(C) /proc/buddyinfo
(D) /proc/mounts
Correct Answer: (A)
[EN] /proc/slabinfo lists active objects, total objects, and object size for each cache.
[HI] /proc/slabinfo प्रत्येक कैश के लिए सक्रिय ऑब्जेक्ट्स, कुल ऑब्जेक्ट्स और ऑब्जेक्ट आकार सूचीबद्ध करता है।
Q13. Why is vmalloc() slower than kmalloc() for frequent small allocations?
(लगातार छोटे आवंटनों के लिए vmalloc() kmalloc() से धीमा क्यों है?)
(A) It uses user-space locks
(B) It disables CPU caches
(C) It writes to disk swap
(D) It must build new page table mappings and causes TLB overhead
Correct Answer: (D)
[EN] vmalloc() modifies kernel page tables to map non-contiguous physical pages.
[HI] vmalloc() गैर-सन्निहित भौतिक पेजों को मैप करने के लिए कर्नेल पेज टेबल को संशोधित करता है।
Q14. What is 'object coloring' in the classic SLAB allocator?
(क्लासिक SLAB एलोकेटर में 'ऑब्जेक्ट कलरिंग' क्या है?)
(A) Tagging memory with SELinux labels
(B) Zeroing memory on free
(C) Encrypting kernel pointers
(D) Adding a small offset to slabs so objects map to different CPU cache lines
Correct Answer: (D)
[EN] Slab coloring reduces CPU cache set conflicts across multiple slabs.
[HI] स्लैब कलरिंग कई स्लैब में CPU कैश सेट टकराव को कम करता है।
Q15. Which GFP flag allows kmalloc() to sleep while waiting for memory?
(कौन सा GFP फ्लैग मेमोरी की प्रतीक्षा करते समय kmalloc() को स्लीप करने की अनुमति देता है?)
(A) GFP_ATOMIC
(B) GFP_DMA
(C) GFP_KERNEL
(D) GFP_NOWAIT
Correct Answer: (C)
[EN] GFP_KERNEL may sleep and trigger page reclaim, whereas GFP_ATOMIC cannot sleep (used in interrupts).
[HI] GFP_KERNEL स्लीप कर सकता है, जबकि GFP_ATOMIC स्लीप नहीं कर सकता।
Q16. Two blocks of size 2^k in a Buddy System can be coalesced only if:
(बडी सिस्टम में 2^k आकार के दो ब्लॉक केवल तभी मर्ज हो सकते हैं जब:)
(A) They are both free and are exact address buddies
(B) One is dirty and one is clean
(C) They are in different NUMA nodes
(D) They belong to the same process
Correct Answer: (A)
[EN] Buddies must be adjacent, of equal size, both free, and differ only in bit k of their address.
[HI] बडीज़ को आसन्न, समान आकार का, दोनों मुक्त और पते के केवल बिट k में भिन्न होना चाहिए।
Q17. Within Slab Allocator and Buddy System Kernel Memory Management, which allocator / api directly maps to: "Physically contiguous (2^n pages)"?
(Slab Allocator and Buddy System Kernel Memory Management में कौन सा Allocator / API सीधे "Physically contiguous (2^n pages)" से संबंधित है?)
(A) vmalloc()
(B) SLUB Allocator
(C) kmalloc()
(D) Buddy System
Correct Answer: (D)
[EN] In Slab Allocator and Buddy System Kernel Memory Management, 'Buddy System' handles 'Physically contiguous (2^n pages)' (Coalesces free buddies to prevent external fragmentation).
[HI] Slab Allocator and Buddy System Kernel Memory Management में 'Buddy System' का कार्य/विवरण 'Physically contiguous (2^n pages)' (Coalesces free buddies to prevent external fragmentation) है।
Q18. Which option accurately describes 'SLUB Allocator' in Slab Allocator and Buddy System Kernel Memory Management?
(Slab Allocator and Buddy System Kernel Memory Management के संदर्भ में 'SLUB Allocator' की सही विशेषता कौन सी है?)
(A) Object-level cache over pages
(B) Virtually contiguous only
(C) Physically & virtually contiguous
(D) Physically contiguous (2^n pages)
Correct Answer: (A)
[EN] 'SLUB Allocator' provides 'Object-level cache over pages' — key point: Default Linux slab allocator; minimal metadata.
[HI] 'SLUB Allocator' का मुख्य विवरण 'Object-level cache over pages' है (Default Linux slab allocator; minimal metadata)।
Q19. In Slab Allocator and Buddy System Kernel Memory Management, identify the correct parameter for the specification: "Physically & virtually contiguous".
(Slab Allocator and Buddy System Kernel Memory Management में "Physically & virtually contiguous" विवरण किस विकल्प के लिए सही है?)
(A) kmalloc()
(B) Buddy System
(C) vmalloc()
(D) SLUB Allocator
Correct Answer: (A)
[EN] 'kmalloc()' corresponds to 'Physically & virtually contiguous' (Backed by SLUB; required for DMA transfers).
[HI] 'kmalloc()' का संबंध 'Physically & virtually contiguous' (Backed by SLUB; required for DMA transfers) से है।
Q20. Considering Slab Allocator and Buddy System Kernel Memory Management, what key behavior defines 'vmalloc()'?
(Slab Allocator and Buddy System Kernel Memory Management में 'vmalloc()' की मुख्य भूमिका या मान क्या है?)
(A) Physically & virtually contiguous
(B) Object-level cache over pages
(C) Physically contiguous (2^n pages)
(D) Virtually contiguous only
Correct Answer: (D)
[EN] 'vmalloc()' represents 'Virtually contiguous only' (Maps scattered physical pages; higher TLB overhead).
[HI] 'vmalloc()' का अर्थ/मान 'Virtually contiguous only' है (Maps scattered physical pages; higher TLB overhead)।
Slab Allocator and Buddy System Kernel Memory Management — Exam FAQs
Q1: Why does Linux use both Buddy System and Slab Allocator?
Linux बडी सिस्टम और स्लैब एलोकेटर दोनों का उपयोग क्यों करता है?
[EN] The Buddy System manages coarse-grained page frames (4 KB+), while the Slab Allocator carves those pages into fine-grained kernel objects.
[HI] बडी सिस्टम मोटे तौर पर पेज फ्रेम (4 KB+) प्रबंधित करता है, जबकि स्लैब एलोकेटर उन पेजों को छोटे कर्नेल ऑब्जेक्ट्स में बांटता है।
Q2: Is kmalloc() limited in maximum allocation size?
क्या kmalloc() अधिकतम आवंटन आकार में सीमित है?
[EN] Yes, because it requires physically contiguous pages, kmalloc() is typically limited to 4 MB (order 10).
[HI] हाँ, क्योंकि इसे भौतिक रूप से सन्निहित पेजों की आवश्यकता होती है, kmalloc() आमतौर पर 4 MB (ऑर्डर 10) तक सीमित है।
Q3: What happens when a slab cache runs out of free objects?
जब स्लैब कैश में मुक्त ऑब्जेक्ट समाप्त हो जाते हैं तो क्या होता है?
[EN] The slab allocator requests new page frames from the Buddy System to create a fresh slab.
[HI] स्लैब एलोकेटर एक नया स्लैब बनाने के लिए बडी सिस्टम से नए पेज फ्रेम का अनुरोध करता है।
Post a Comment
Post a Comment