๐๐ฒ๐ง๐๐ฆ๐ข๐ ๐๐๐ฆ๐จ๐ซ๐ฒ ๐๐ฅ๐ฅ๐จ๐๐๐ญ๐ข๐จ๐ง ๐๐ก๐ฎ๐ง๐ค ๐๐ญ๐ซ๐ฎ๐๐ญ๐ฎ๐ซ๐โฃ
Memory allocators like ๐ฆ๐๐ฅ๐ฅ๐จ๐ organize heap memory into discrete chunks that can exist in either allocated or free states.
Each chunk contains essential metadata along with the actual payload space requested by the application. โฃ
The chunk structure begins with ๐ฉ๐ซ๐๐ฏ_๐ฌ๐ข๐ณ๐ field storing the size of the previous chunk, followed by a size field that records the current chunk's total size along with status flags.
The ๐๐๐ flags indicate whether the chunk is ๐๐ฅ๐ฅ๐จ๐๐๐ญ๐๐, ๐๐ฆ๐๐ฉ'๐, or if the Previous chunk is in use, providing critical state information for efficient memory management.โฃ โฃ
In-use chunks maintain a streamlined structure where malloc returns a pointer to the payload area immediately following the metadata header.
The ๐ฆ๐๐ก๐ฎ๐ง๐ค๐ฉ๐ญ๐ซ points to the chunk's beginning, while the returned pointer gives applications direct access to their allocated memory space.
The ๐ฉ๐ซ๐๐ฏ_๐ฌ๐ข๐ณ๐ field in allocated chunks doesn't contribute to size calculations since adjacent chunk information becomes irrelevant once memory is actively used by an application.โฃ
Free chunks require additional bookkeeping to support efficient allocation algorithms and coalescing operations.
Beyond the standard prev_size and size fields, free chunks include forward and ๐๐๐๐ค๐ฐ๐๐ซ๐ ๐ฉ๐จ๐ข๐ง๐ญ๐๐ซ๐ฌ (๐๐ฐ๐ ๐๐ง๐ ๐๐๐ค) that link them into doubly-linked free lists.
โฃLarge free chunks also contain ๐๐_๐ง๐๐ฑ๐ญ๐ฌ๐ข๐ณ๐ and ๐๐ค_๐ง๐๐ฑ๐ญ๐ฌ๐ข๐ณ๐ pointers, creating a secondary linked structure that helps the allocator quickly locate appropriately sized blocks without traversing entire free lists.โฃ โฃ
The minimum chunk size equals ๐*๐ฌ๐ข๐ณ๐๐จ๐(๐ฏ๐จ๐ข๐*) to ensure sufficient space for the metadata overhead required during free operations.
When chunks are freed, the allocator needs room for the forward and backward pointers that weren't necessary during allocation. โฃ
This size constraint applies regardless of the requested allocation size, meaning even tiny malloc requests receive chunks large enough to hold future free list pointers.
Platform-specific alignment requirements may increase this minimum size further to maintain proper memory alignment for optimal processor performance.โฃ
Chunks exist as contiguous blocks in heap memory, allowing traversal from any starting chunk by adding its size value to locate the next adjacent chunk.
This layout enables efficient coalescing of adjacent free chunks and supports debugging tools that need to walk through heap structures.
However, detecting the final chunk in a heap segment requires additional boundary checking since the size-based traversal mechanism alone cannot distinguish between valid chunks and unallocated heap space at the segment's end.
โข โข โข
Missing some Tweet in this thread? You can try to
force a refresh
The fundamental architecture of the GNU/Linux operating system
These programs are what you see and use daily, running in whatโs called user space. Itโs a neat separation, keeping things organized and secure by isolating them from the deeper system stuff.
Just below that sits the GNU C Library, or glibc, which acts like a bridge. This layer provides the essential functions and tools that user applications rely on to talk to the system.
Whether itโs handling input/output or managing memory, glibc makes sure everything runs smoothly by offering a standardized set of commands.
Itโs a critical piece, connecting the apps you use to the underlying machinery without you even noticing.
Moving down, we hit the System Call Interface, a kind of gateway between user space and kernel space.
Unlocking Secrets: How Diffie-Hellman Keeps Your Data Safe
This way of key exchange is a clever way for two people, or systems, to create a secret key they can both use, even if theyโre communicating over an open channel like the internet.
Letโs say you and a website want to share a secret. You each start by picking a random number, called a private key. These private keys are super important, and you keep them hidden, never sharing them with anyone.
Using your private key and a known number (a constant that everyone agrees on), you each create a public key. This public key isnโt secretโyou send it to each other without worrying about who might see it.
Now, hereโs where it gets interesting. You take your private key and combine it with the websiteโs public key. The website does the same, mixing its private key with your public key.
What comprises the state of a running program (a process or task)?
The state of a running program, often referred to as a process or task, is a comprehensive snapshot that encapsulates all necessary information to resume its execution exactly where it left off.
This state includes the values stored in the CPU registers (such as EAX, EBX, ECX, EDX, ESI, EDI, EBP, ESP, EIP, and the segment registers like CS, DS, SS, ES, FS, GS), which are critical for maintaining the context of the program's execution.
These registers hold various pieces of information like the program counter (EIP), stack pointer (ESP), and general-purpose data. Additionally, the state also involves the operating system's data structures, which manage process control blocks, memory maps, and other metadata necessary for process management.
Virtual to Physical: The CPU's Address Translation Journey
The CPU generates a logical address to refer to data in memory, which is not the actual physical location
๐งตRead the whole thread for better understanding ๐
Also I have attached the article link for further reading.
- The Memory Management Unit (MMU) translates the logical address into a physical address in RAM
- The Translation Look-aside Buffer (TLB) stores recent translations for faster access
- If the translation is in the TLB, the MMU quickly translates the logical address; if not, it looks up the page table in memory
- The CPU then accesses the correct memory location in physical RAM, which is divided into pages for efficient memory management and protection
Understanding Linux's Approach to Interrupt Stacks: Hardware and Software
In Linux, when a hardware device creates an interrupt, the CPU halts its current task and moves to an interrupt service routine (ISR). This process is essential for timely handling of hardware events, regardless of other ongoing tasks.
๐งตRead the whole thread๐
Interrupt handlers use two stack types. The kernel stack is used in user or kernel mode for function calls and variables. During a user mode interrupt, the CPU switches to kernel mode, saving the user context with the process's kernel stack for the ISR. If an interrupt occurs in kernel mode, it uses the same process's kernel stack.
Linux uses special IRQ stacks for security and efficiency. The hardware IRQ stack is per-CPU to prevent overflow and corruption. It is smaller than the regular kernel stack but fit for ISRs. The software IRQ stack manages less urgent tasks after primary interrupt handling, enabling parallel processing across multiple cores.