<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Pages on Sanketh's Blog</title><link>https://sankethbk.github.io/blog/tags/pages/</link><description>Recent content in Pages on Sanketh's Blog</description><generator>Hugo -- 0.163.1</generator><language>en-us</language><lastBuildDate>Tue, 19 May 2026 00:00:00 +0000</lastBuildDate><atom:link href="https://sankethbk.github.io/blog/tags/pages/index.xml" rel="self" type="application/rss+xml"/><item><title>Memory Maangement in Kernel</title><link>https://sankethbk.github.io/blog/posts/operating-systems/linux/2026-05-19-kernel-memory-management-1/</link><pubDate>Tue, 19 May 2026 00:00:00 +0000</pubDate><guid>https://sankethbk.github.io/blog/posts/operating-systems/linux/2026-05-19-kernel-memory-management-1/</guid><description>&lt;h1 id="memory-management-in-kernel"&gt;Memory Management in Kernel&lt;/h1&gt;
&lt;h2 id="why-kernel-space-memory-management-is-harder"&gt;Why Kernel Space Memory Management is Harder?&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Userspace&lt;/strong&gt; can fail safely and wait patiently. &lt;strong&gt;Kernel-space&lt;/strong&gt; cannot, making its allocation fundamentally harder.&lt;/p&gt;
&lt;h3 id="key-differences-in-kernel-memory-allocation"&gt;Key Differences in Kernel Memory Allocation&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Sleeping is often banned:&lt;/strong&gt; Userspace can block while waiting for memory. Kernel contexts (interrupts, spinlocks) cannot, requiring instant success or failure flags like &lt;code&gt;GFP_ATOMIC&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Failure is catastrophic:&lt;/strong&gt; App failures just kill the app; kernel allocation failures crash the entire system. The kernel must rely on emergency reserves, reclaim, and the OOM killer to survive.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Dangerous recursion:&lt;/strong&gt; The kernel manages memory using memory. A reclaim operation can trigger filesystem actions that need more memory, causing deadlocks (prevented by flags like &lt;code&gt;GFP_NOFS&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Strict physical constraints:&lt;/strong&gt; Userspace only worries about virtual memory. The kernel must manage physical pages, DMA limits, and NUMA locality.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Physical fragmentation matters:&lt;/strong&gt; The kernel frequently requires physically contiguous pages, making fragmentation a critical, system-halting roadblock.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Interrupt context is brutal:&lt;/strong&gt; Interrupt handlers need immediate memory without sleeping or waiting on locks, relying heavily on per-CPU caches and lockless structures.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;High deadlock risk:&lt;/strong&gt; Allocators interact with reclaim, writebacks, and system locks. &lt;code&gt;GFP&lt;/code&gt; flags are essential to dictate exactly what an allocator is safely allowed to do.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Predictable latency is required:&lt;/strong&gt; Kernel subsystems (networking, real-time workloads) cannot tolerate unpredictable allocation pauses, necessitating highly optimized allocators like SLAB/SLUB.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;The Mental Shift&lt;/strong&gt;&lt;/p&gt;</description></item></channel></rss>