Operating Systems, Page Frame Allocation

Hello everyone, In today’s article I’m going to talk about how to set up Page Frame Allocation in your Operating System. In the last week we talked bout how to set up paging and this will be like an extension of it.

Page Frame Allocation

An important aspect of operating systems, virtual memory is implemented using demand paging. Demand paging necessitates the development of a page-replacement algorithm and a frame allocation algorithm. Frame allocation algorithms are used if you have multiple processes where it helps decide how many frames to allocate to each process. There are two things to keep in mind when Allocation page frames they are that you cannot allocate more than the total number of available frames and that at least a minimum number of frames should be allocated to each process.

My Experience

First, before we do anything with page frames we will need a way to figure out how much memory is available to our OS. This is not hard since GRUB provides tool to do this. Remember the multi boot structure we used to run our user programs we can use the same thing here. GRUB collects information about memory like what parts of it is reserved, what parts are I/O mapped, what parts are read-only etc. You just have to read these from the multiboot structure and you will be good to go. But we have to make sure the parts of the memory used by the kernel is not set as free since GRUB doesn’t mark this part of the memory as reserved we have to do this step ourselves, This can be done by using Export lables at the start and the beginning of the linker script.

The new can directly read them from assembly and push them to the stack so they are available from C.

Now to creating the page frame allocator, First the page frame allocator needs to keep track of which pages frames are free and which aren’t. There are several ways to do this like bitmaps, linked lists, trees or the Buddy System. Since bitmaps are easy to implant, we will use them here. In bitmaps one bit is used for each page frame and one (or more) page frames are dedicated to store the bitmap.

Then we need to map the page frame into the virtual memory by updating the Page Table used by the kernel.

Until now we were only able to fork with fixed data sizes but with the page frame we can implement a malloc function to use in the kernel.

We must also make sure to map the page frames returned by the page frame allocator to virtual addresses.

Finally if everythig has gone well the OS will display the message Page Frame Allocation Complete.


Helin E, Renberg A. (2015). The little book about OS development: https://littleosbook.github.io/

Os Dev Wiki https://wiki.osdev.org/Main_Page

linux-insides https://0xax.gitbooks.io/linux-insides/content/

GNU GRUB Multiboot Manual http://www.gnu.org/software/grub/manual/multiboot/

JamesM’s kernel development tutorials http://www.jamesmolloy.co.uk/tutorial_html/6.-Paging.html

Thank you for reading and I will be back next week with another article.




Software Engineering Undergraduate of University of Kelaniya, Sri Lanka.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Facade Design pattern for Beginners

Bitwise case conversion

Learnings with API Latency Measurement & Lambda Cold start.

SRE Leaders Panel: Managing Systems Complexity

What programming taught me about life

The most popular Python scientific libraries

The Exorde Platform

Simulating Life, Cells, and randomness

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Mahela Dissanayake

Mahela Dissanayake

Software Engineering Undergraduate of University of Kelaniya, Sri Lanka.

More from Medium

What is Josephus Problem and how to solve it without any in-built function?

What You Need To Get About Git Before Gitting…GETTING Started

Advent Of Code 2021 — Dive! — Puzzle 2

Architecting Scalable Game Netcode with AWS and Linode for Unity3d