You are on a budget phone with 3 GB of RAM. bKash is open, Facebook is open, a video is playing, and the camera has just started. Every one of these programs was written as if memory were a private room that begins at address 0. Two of them even keep a variable at exactly the same address. And yet they never overwrite each other, a buggy app cannot scribble over bKash, and the moment you close the video its memory goes to the camera. Who keeps the rooms apart? Who decides which room goes to whom? And what happens when there is plenty of free memory in total, but never in one piece?
That is the work of the memory manager inside the operating system, and this chapter is about the classic way it does the job. We start with the simplest hardware trick, one register that moves a program anywhere it likes. Then we place whole processes in memory, see how the free space crumbles into useless gaps, and finally meet paging, the idea that removes the problem at its root. Paging is also where the exam sums live: page numbers, offsets, table sizes, wasted bytes.
By the end of the chapter you will be able to translate an address with a base and a limit register, say when an address becomes real (compile, load or run time), and explain swapping and overlays. You will place processes with first, best, worst and next fit, count what is wasted, and run a buddy-system allocation by hand. And you will split any address into page number and offset, push it through a page table, and do every sum the papers set on paging: bits, entries, table size, the half-empty last page, the best page size.
We go in eight parts, from easy to hard: the two kinds of address; when an address is fixed, and how programs are loaded and linked; swapping and overlays; contiguous allocation and the four fits; fragmentation, compaction and the buddy system; paging itself; the sums; and finally protection and sharing.