Siksha Sarovar

Siksha Sarovar (sikshasarovar.com) is a free educational web application that helps students in India learn programming and prepare for academic and competitive exams. The platform offers structured coding courses (C, C++, Python, Java, HTML, CSS, PHP, Power BI, AI, Machine Learning, Data Science), complete university curriculum notes for BCA/MCA students with previous year question papers, Class 10 and Class 12 CBSE/HBSE school notes, and dedicated preparation material for SSC, UPSC, Banking, Railway and other government exams. Browsing the site is completely free and requires no account. Users may optionally sign in with Google solely to save their learning progress, quiz scores and personal preferences across devices.

Privacy Policy | Terms of Service | Contact Siksha Sarovar | About Siksha Sarovar

v4.0.9 · PWA
Siksha Sarovar logo
Siksha Sarovar
Your Learning Universe

Siksha Sarovar is a free e-learning platform for coding courses, BCA university notes and competitive exam preparation. Optional Google sign-in saves your learning progress across devices.

Initializing knowledge base…
Compiling modules 0%

Memory Management Basics

Lesson 18 of 31 in the free Operating System & Linux Programming notes on Siksha Sarovar, written by Rohit Jangra.

Why Manage Memory?

Programs reference data by addresses. Physical RAM is finite, shared, and slow compared to CPU. The OS must:

  1. Keep track of which memory is in use and by whom.
  2. Decide which processes get loaded when memory frees up.
  3. Translate program-generated addresses into hardware addresses.

Logical vs Physical Address Space

  • Logical (virtual) address — generated by the CPU; what the program sees.
  • Physical address — what the memory unit sees.
  • The Memory Management Unit (MMU) performs run-time mapping logical → physical.

A trivial MMU adds a relocation register to every logical address. More elaborate MMUs do paging and segmentation.

Address Binding

Addresses can be bound to physical locations at three times:

  1. Compile time — absolute code; must reload if start address changes.
  2. Load time — relocatable code; addresses fixed at load.
  3. Execution time — bindings done at run time, supports swapping/paging. Modern systems use this.

Static vs Dynamic Loading

  • Static loading — entire program loaded before execution.
  • Dynamic loading — routines loaded on first call (saves memory for rarely used code).

Static vs Dynamic Linking

  • Static — libraries copied into executable at link time.
  • Dynamic.so/.dll shared libraries linked at run time. Saves disk and RAM, allows updates without relinking.

Swapping

When RAM is full, the OS may swap entire processes to disk and bring them back later. Swap area is typically a dedicated disk partition (/dev/sda2) or file.

Swapping is heavy — modern OSes prefer page-level paging (next lessons). Swapping is still used for hibernation and memory pressure.

Memory Allocation Strategies

For a single contiguous region, when a process requests n bytes the OS scans the free-hole list and uses one of:

  • First Fit — first hole large enough.
  • Best Fit — smallest hole that fits. Minimizes wasted space, slower scan.
  • Worst Fit — largest hole. Counter-intuitive but leaves a usable remainder.

Fragmentation

  • External fragmentation — total free memory exists but no contiguous chunk is large enough.
  • Internal fragmentation — allocated block larger than requested; the slack is wasted.

Compaction shuffles allocated regions to merge holes — only possible with run-time binding; expensive.

Summary

  • Logical/physical separation enables relocation and protection.
  • Swapping moves entire processes; modern systems mostly page.
  • Allocation strategies trade off speed, fragmentation, and search overhead.