Go Premium for a chance to win a PS4. Enter to Win


Memory managament for an own OS

Posted on 2003-11-13
Medium Priority
Last Modified: 2011-09-20
Who can give me an explanation of how to create a memory management for an own OS? I'm working on it, but there are problems...

I'm allocating page tables for the memory (PAGE_SIZE = 4096) and I can give them the state of "free" and "used". If I allocate memory by using the state "used" I've no security. Everybody else can write to this area, etc...

Who can help me and give an introduction?
Question by:Mathias
  • 5
  • 3
  • 2
LVL 45

Accepted Solution

sunnycoder earned 1200 total points
ID: 9738078
With paging, still have protection. One process cannot access a piece of physical memory unless its page table points to that physical page. So, if the page tables of two processes point to different physical pages, the processes cannot access each other's physical memory.

you may find these helpful


Author Comment

ID: 9738950
I will walk through this links looking If I can use the information. Thanx in advance for quick response :-)
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

LVL 46

Assisted Solution

by:Kent Olsen
Kent Olsen earned 800 total points
ID: 9739647


Start with Sunnycoder's last link.  It seems to be better organized, more concise, and more useful than the others.  I don't think that any of them completely answer your questions, but they should point you in the right direction.

Virtual memory management is quite a trick.  There are a lot of things that you'll need to take into consideration that I didn't see in the links above.  (Great links, though!)

In addition to the items listed in the last link:

physical pg #,
present/absent bit,
protection (read/write/execute),
modified - on a write this is set. Will be useful when the page has to be replaced to find out if it has to be written to disk.
referenced - set each time you read/write to the page. (will be used later)
caching disabled - says do not cache it. Useful for I/O devices that are memory mapped.

You'll also need:

locked bit - this page is locked into memory and cannot be swapped.  (You certainly don't want certain kernel functions to swap out.  Imaging what would happen if the page tables were swapped to disk or if the portion of the kernel that performs swapping back in were on disk.)

age value - as pages are used, they "age".  When pages are swapped, those least recently used should be moved first.

CopyOnWrite bit - if a task changes this page, the page is first copied to another page for exclusive use by this task.  (Bit clears in new page.)  This is how fork() works so efficiently.  It simply allows both tasks to proceed on their way and when one of the tasks modifies a page, the page is copied and the tables modified to indicate that the task is using the new page instead of the old one.

Now on to your question.

Each task will also need its own page table that maps between the task and the system memory.

Imagine two jobs (tasks) that simultaneously execute the command "vi /etc/hosts".  Both tasks have their own memory space, but for all intents and purposes, the tasks look identical.  Certainly the O/S didn't relink vi just because it was being run twice.  So how does a program like vi, with a (pretend) start address of 0xA0000000 run in two separate tasks without the two tasks stepping on each other?  Simple -- each task contains a mapping table that maps the task's virtual address (0xA0000000) to a physical page (0x00002000).  When the tasks references memory, the hardware converts the virtual address to a physical address and performs the reference.  If the reference is invalid, the page is not in memory and a page fault occurs.  The O/S must then determine if the page is valid (and if so, swap it in) or if the address is out of bounds.

By mapping each task's virtual address to physical memory, there is no problem with two tasks trying to improperly write to the same place.

LVL 45

Expert Comment

ID: 9746758
Kent WADR, lock bit and copyonwrite bit (also called dirty bit) are not necessary ... it is possible to devise a memory management system without the two...
lower memory can be defined as kernel memory, unswappable and page table kept there...
dirty bit is a performance enhancement and not a requirement...
Another factor which needs to be worked on to gain good performance is the page replacement algorithm .....
The complexity of any such system would depend on the application desired... If it is an academic project, this would an overkill ;o)

>I'm allocating page tables for the memory (PAGE_SIZE = 4096) and I can give them the state of "free" and "used". If I allocate memory by using
>the state "used" I've no security. Everybody else can write to this area, etc...
as regards to this, I would try to add a bit more to what I and kent have already said ... or rather try to put it differently
any read/write request will go through your memory manager ... The memory manager can easily decide if the page belongs to the requesting process's memory space or not... If access is illegal, you can derive pleasure out of giving seg faults rather than getting them ;o) ...
so there is no threat of someone else writing to another process's memory

Some feedback and background information (what kind of OS, applications etc.) would be helpful.

Author Comment

ID: 9746908
There are useful comments till yet :-)

- OS (PMODE, 32bit, multitasking, ...)
- secure memory management
- GUI-orientated (currently only a shell)

It should be a complex system with POSIX support. To complete this task we need to have at least a working memory management.

Bye, TDS.
LVL 45

Expert Comment

ID: 9746923
Are you clear on the issue of memory management, or are there some doubts/questions ?
LVL 46

Expert Comment

by:Kent Olsen
ID: 9747586

Hi Sunny,

You're right about the copyonwrite bit.  It's a nicety that can always be added later.  (And added pretty easily.)

But I do think that he's better served by incorporating a Locked bit from the start.  That way it's not necessary to rebuild the boot loader every time he builds his kernel.  As his O/S is being loaded, the boot process can simply lock the pages that get used at load time.


GUI-oriented?  You've got a LOT of work ahead before you can even THINK about what graphics to install.  :)  You must walk before you can run!


Author Comment

ID: 10002455
I've splitted the points, because both of these answers are excellent. The answers guided me the right way. Now, I've paging with protection and my os is working more stable. Thanx :-)
LVL 45

Expert Comment

ID: 10004494
thats great ...
good luck

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.
Suggested Courses

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question