Memory Management Simulator: First Fit, Best Fit, Worst Fit and Paging

The OS must place processes in main memory. Contiguous allocation chooses a hole (First, Best or Worst fit) and can suffer fragmentation; paging splits memory into fixed frames and translates logical addresses with a page table.

About this simulator

The operating system must decide where in main memory each process goes. Contiguous allocation chooses a free hole by first fit, best fit or worst fit and can leave unusable gaps (external fragmentation). Paging avoids that by splitting memory into fixed-size frames and translating logical addresses through a page table. Both techniques are simulated here with your own numbers.

How it works

  1. First fit takes the first hole that is big enough; Best fit the smallest big-enough hole; Worst fit the largest hole.
  2. Holes left too small to use cause external fragmentation.
  3. In paging, a logical address =page number×page size+offset= \text{page number} \times \text{page size} + \text{offset}; the page table maps the page to a frame.

Formulas used

  • Page number=⌊address/page size⌋\text{Page number} = \lfloor \text{address} / \text{page size} \rfloor
  • Offset=address mod page size\text{Offset} = \text{address} \bmod \text{page size}
  • Physical=frame×page size+offset\text{Physical} = \text{frame} \times \text{page size} + \text{offset}

Worked example

Holes of 100, 500, 200, 300 and 600 KB receive processes of 212, 417, 112 and 426 KB. First fit places 212 in the 500 KB hole, 417 in 600 KB, 112 in the leftover 288 KB, but 426 KB fails. Best fit places all four. For paging with 100-byte pages, logical address 250 is page 2, offset 50; if page 2 is in frame 7 the physical address is 7 × 100 + 50 = 750.

Enter these numbers in the simulator above to see every step.

When to use it

  • Comparing placement strategies on the same request sequence.
  • Converting logical addresses to physical addresses for exam problems.
  • Seeing external fragmentation: plenty of free memory in total but no hole big enough.

Frequently asked questions

Which is better: first fit, best fit or worst fit?

First fit is usually fastest; best fit leaves the smallest leftover holes but can create many tiny ones; worst fit leaves larger leftovers. Which places the most processes depends on the request sequence — try all three above.

How do you convert a logical address to a physical address in paging?

Page number=⌊address/page size⌋\text{Page number} = \lfloor \text{address} / \text{page size} \rfloor and offset=address mod page size\text{offset} = \text{address} \bmod \text{page size}. Look up the frame in the page table; physical address=frame×page size+offset\text{physical address} = \text{frame} \times \text{page size} + \text{offset}.

What is external fragmentation?

Free memory that is split into pieces too small to satisfy a request even though the total free space is large enough.