Solved

Memory managament for an own OS

Posted on 2003-11-13
10
224 Views
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?
0
Comment
Question by:Mathias
  • 5
  • 3
  • 2
10 Comments
 
LVL 45

Accepted Solution

by:
sunnycoder earned 300 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
http://www.ncsa.uiuc.edu/UserInfo/Resources/Hardware/IBMp690/IBM/usr/share/man/info/en_US/a_doc_lib/aixbman/admnconc/admnconc02.htm#ToC
http://www.cs.jhu.edu/~yairamir/cs418/os5/
http://www.cag.lcs.mit.edu/~rinard/osnotes/h8.html
http://www.super-memory.com/sml/colls/osmemory.htm

0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 9738087
0
 
LVL 3

Author Comment

by:Mathias
ID: 9738950
I will walk through this links looking If I can use the information. Thanx in advance for quick response :-)
0
 
LVL 45

Assisted Solution

by:Kdo
Kdo earned 200 total points
ID: 9739647

Hi TDS,

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.


Kent
0
 
LVL 45

Expert Comment

by:sunnycoder
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)

TDS:
>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.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 3

Author Comment

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

Feedback:
- 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.
0
 
LVL 45

Expert Comment

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

Expert Comment

by:Kdo
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.


Hi TDS,

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!

Kent
0
 
LVL 3

Author Comment

by:Mathias
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 :-)
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 10004494
thats great ...
good luck
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now