• C

Memory managament for an own OS

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?
LVL 3
MathiasIT SpecialistAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sunnycoderCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MathiasIT SpecialistAuthor Commented:
I will walk through this links looking If I can use the information. Thanx in advance for quick response :-)
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Kent OlsenData Warehouse Architect / DBACommented:

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
sunnycoderCommented:
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
MathiasIT SpecialistAuthor Commented:
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
sunnycoderCommented:
Are you clear on the issue of memory management, or are there some doubts/questions ?
0
Kent OlsenData Warehouse Architect / DBACommented:

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
MathiasIT SpecialistAuthor Commented:
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
sunnycoderCommented:
thats great ...
good luck
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.