flat assembler
Message board for the users of flat assembler.

Index > OS Construction > Best Memory Model

Goto page 1, 2, 3  Next

Which memory model is the best?
Paged
40%
 40%  [ 6 ]
Paged with Segmentation (segments within pages)
0%
 0%  [ 0 ]
Flat
60%
 60%  [ 9 ]
Total Votes : 15

Author
Thread Post new topic Reply to topic
Adam Kachwalla



Joined: 01 Apr 2006
Posts: 150
Adam Kachwalla
Hello. I am developing my own 64-BIT OS and I am wondering what memory model to use. Here's my goals:

I want my OS to be:

* Light
* Good enough to run large and small programs
* Easy to work with in terms of programming and usability

I have already shortlisted my options to:

Paging
Seems pretty good and easy because programmers will only need to start their programs at "virtual address" 0, and you get all the protection that flat memory model doesn't offer readily.

But is it worth the CPU to do all this?

Paging with segmentation (segments in the pages)
Same as above, but with segmentation implemented within each range of pages (not sure if you know what I mean by that)

Flat
Fast, but I need to add extra protection features and memory management in my Memory Manager module.

Programmers will have to refer to a specific address at runtime (I was always thinking of making an EXE loader that loads relocatable code anyway).

Do you think that it is worth adding the extras, or using one of the Paged memory models.
Post 14 Sep 2008, 07:01
View user's profile Send private message Reply with quote
sinsi



Joined: 10 Aug 2007
Posts: 693
Location: Adelaide
sinsi
Long mode must use paging, so you don't really have a choice.
Post 14 Sep 2008, 08:15
View user's profile Send private message Reply with quote
Adam Kachwalla



Joined: 01 Apr 2006
Posts: 150
Adam Kachwalla
OK, but in long mode am I able to use segmentation on top of paging?

Hang on... how does 64-bit Windows use flat memory model then?
Post 14 Sep 2008, 08:20
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
No, you can't use segmentation in 64bit mode (only for FS and GS). I suggest you to take Intel or AMD manual and give it a good read.
Post 14 Sep 2008, 08:58
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17279
Location: In your JS exploiting you and your system
revolution
If all else fails RTFM. And if that also fails check out my website to find out how long mode works (and doesn't work).

But seriously, what is wrong with paging? Why do so many people seem to think it is the spawn of Satan? It is just a simple translation mechanism, and it makes a lot of OS related things so much easier to do.
Post 14 Sep 2008, 09:13
View user's profile Send private message Visit poster's website Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u
You could use paging, but map it 1 to 1, which would be like not having paging.
Post 14 Sep 2008, 13:40
View user's profile Send private message Reply with quote
Adam Kachwalla



Joined: 01 Apr 2006
Posts: 150
Adam Kachwalla
Dex4u wrote:

You could use paging, but map it 1 to 1, which would be like not having paging.

I'm not against paging, infact I think paging might make OS-DEV easier. But will it be more CPU intensive than using flat model?
revolution wrote:
But seriously, what is wrong with paging? Why do so many people seem to think it is the spawn of Satan? It is just a simple translation mechanism, and it makes a lot of OS related things so much easier to do.

That's what I'm trying to find out. If there is a catch to using paging, is it really worth using or will it make my OS slower than a rock? If I use flat model, am I saving CPU time at the expense of making my OS bigger than Vista?
Post 15 Sep 2008, 01:11
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17279
Location: In your JS exploiting you and your system
revolution
Adam Kachwalla wrote:
I'm not against paging, infact I think paging might make OS-DEV easier. But will it be more CPU intensive than using flat model?
No.
Adam Kachwalla wrote:
revolution wrote:
But seriously, what is wrong with paging? Why do so many people seem to think it is the spawn of Satan? It is just a simple translation mechanism, and it makes a lot of OS related things so much easier to do.

That's what I'm trying to find out. If there is a catch to using paging, is it really worth using or will it make my OS slower than a rock? If I use flat model, am I saving CPU time at the expense of making my OS bigger than Vista?
Paging will add a small amount of overhead when you use large areas of memory in a random order. But that type of memory usage is very untypical. I doubt you will notice any speed difference at all. Try it. Code up a small utility and time it running with and without paging. I would be surprised if you can see any difference in speed.

What has given you the idea that paging is slow?


Last edited by revolution on 15 Sep 2008, 02:05; edited 1 time in total
Post 15 Sep 2008, 02:03
View user's profile Send private message Visit poster's website Reply with quote
neville



Joined: 13 Jul 2008
Posts: 507
Location: New Zealand
neville
revolution wrote:

But seriously, what is wrong with paging? Why do so many people seem to think it is the spawn of Satan? It is just a simple translation mechanism, and it makes a lot of OS related things so much easier to do.

Hi from across the ditch, Adam.

I guess I might be one of the "spawn of Satan" believers referred to by revolution. Wink

This would probably be due to the discussion when I introduced my own 32-bit memory operating system FAMOS see http://board.flatassembler.net/topic.php?t=8945

FAMOS is presently in Flat Real Mode, which serves very well to demonstrate the concept of a memory OS.

Your compatriate Sinsi points out that 64-bit long mode MUST be paged, but I'm still hoping to find a way to effectively implement flat memory in my 64-bit version of FAMOS. I'm not totally opposed to paging, but I am opposed to Virtual Memory in "modern" operating systems. VM is now an antiquated idea IMHO. Trouble is, paging often seems to lead to VM (but shouldn't have to).

Paging itself must also increase both CPU and code overhead IMHO, so any OS which implements paging is likely to be both slower and larger. So I'll stick my neck out again and vote for flat in your poll. Yeah! Smile

_________________
FAMOS - the first memory operating system
Post 15 Sep 2008, 02:04
View user's profile Send private message Visit poster's website Reply with quote
Adam Kachwalla



Joined: 01 Apr 2006
Posts: 150
Adam Kachwalla
Note that security and protection are also an important factor in this OS I'm deving. So that also would determine which memory model to use

revolution wrote:
What has given you the idea that paging is slow?

I just heard from other people and read from other websites that it is slow. I want to confirm this (because that would be disappointing as its VM features and security features look quite impressive compared with Flat Memory Model


Last edited by Adam Kachwalla on 15 Sep 2008, 02:13; edited 1 time in total
Post 15 Sep 2008, 02:10
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17279
Location: In your JS exploiting you and your system
revolution
What is wrong with VM? I find it useful in my 512MB laptop. For 99% of the time I don't need more than 250MB and everything runs smoothly, but when I run some app that want 600MB of memory then I am happy for the OS to pretend it has more RAM and use the HDD. Sure the app will run slower but that does not bother me, it is cheaper and easier than having to go and find some RAM at the computer store. If I needed 600MB 99% of the time then I would buy the extra RAM, but until that time comes VM will serve my purposes just fine.
Post 15 Sep 2008, 02:10
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17279
Location: In your JS exploiting you and your system
revolution
Adam Kachwalla wrote:
Note that security and protection are also an important factor in this OS I'm deving. So that also would determine which memory model to use
You should have mentioned that earlier because now your choice is simple, definitely use paging. That way you can expose only the memory areas that each app is supposed to see.
Post 15 Sep 2008, 02:13
View user's profile Send private message Visit poster's website Reply with quote
Adam Kachwalla



Joined: 01 Apr 2006
Posts: 150
Adam Kachwalla
revolution wrote:
What is wrong with VM?
Nothing. Nothing at all.


Last edited by Adam Kachwalla on 07 Mar 2013, 03:02; edited 1 time in total
Post 15 Sep 2008, 02:14
View user's profile Send private message Reply with quote
Adam Kachwalla



Joined: 01 Apr 2006
Posts: 150
Adam Kachwalla
revolution wrote:
Adam Kachwalla wrote:
Note that security and protection are also an important factor in this OS I'm deving. So that also would determine which memory model to use
You should have mentioned that earlier because now your choice is simple, definitely use paging. That way you can expose only the memory areas that each app is supposed to see.


So does each application see an address range from 0x0000000000000000-0x################, or from 0x################-0x################? ie. can applications reference 0x0000000000000000 in the paging model and get the first page allocated to it, or do they have to refer to the actual location in memory/real page number?

Also I want both speed and security, and if paging is only slightly and unnoticeably slower than flat memory model (a fly hitting a car; the car will slow down by a millionth of a kilometer-per-hour) than it is worth using!

Can it handle a lot of memory requests in a given time? I have stuff in my OS that manipulate memory all the time
Post 15 Sep 2008, 02:18
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17279
Location: In your JS exploiting you and your system
revolution
Adam Kachwalla: Read about paging in the Intel/AMD manuals. Rather than me try to explain the whole mechanism here it would be best to get such detailed info directly from the source.

In brief: Apps don't know the physical address of the memory they use. Apps always use virtual adddresses.
Post 15 Sep 2008, 02:25
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17279
Location: In your JS exploiting you and your system
revolution
Adam Kachwalla wrote:
Also I want both speed and security, and if paging is only slightly and unnoticeably slower than flat memory model (a fly hitting a car; the car will slow down by a millionth of a kilometer-per-hour) than it is worth using!
Yes, that might be a good analogy. Very slight overhead.
Adam Kachwalla wrote:
Can it handle a lot of memory requests in a given time? I have stuff in my OS that manipulate memory all the time
Yes of course, the mechanism can handle requests as fast as your code can make the requests.
Post 15 Sep 2008, 02:26
View user's profile Send private message Visit poster's website Reply with quote
Adam Kachwalla



Joined: 01 Apr 2006
Posts: 150
Adam Kachwalla
revolution wrote:
Adam Kachwalla: Read about paging in the Intel/AMD manuals. Rather than me try to explain the whole mechanism here it would be best to get such detailed info directly from the source.

All I needed here was to know whether or not to use paged memory model, and you've put a strong case. I think I'll go with paged memory module. Thanks for your help

BTW I have a few questions:

1. What is the enormous "Virtual Memory" range 0x0000000000000000-0xFFFFFFFFFFFFFFFF for? NOBODY will ever have 16 exabytes of memory in a million years!
2. Why does Windows NT use flat memory model instead of paged when, by what you're saying paged is more reliable? Is it just a stupid mistake MS made (or rather MS+IBM, because OS/2 uses it as well!)? Or was it for compatibility with MS-DOS? Note that I'm not trying to be a "flat-memory-model advocate", I'm simply asking a question.
Post 15 Sep 2008, 02:33
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17279
Location: In your JS exploiting you and your system
revolution
Adam Kachwalla wrote:
1. What is the enormous "Virtual Memory" range 0x0000000000000000-0xFFFFFFFFFFFFFFFF for? NOBODY will ever have 16 exabytes of memory in a million years!
Better to have more than needed than to run out. But 2^64 bytes might be possible before 1MY.
Adam Kachwalla wrote:
2. Why does Windows NT use flat memory model instead of paged when, by what you're saying paged is more reliable? Is it just a stupid mistake MS made (or rather MS+IBM, because OS/2 uses it as well!)? Or was it for compatibility with MS-DOS? Note that I'm not trying to be a "flat-memory-model advocate", I'm simply asking a question.
NT uses paging.
Post 15 Sep 2008, 02:39
View user's profile Send private message Visit poster's website Reply with quote
neville



Joined: 13 Jul 2008
Posts: 507
Location: New Zealand
neville
Adam Kachwalla wrote:
NOBODY will ever have 16 exabytes of memory in a million years!

Less than 30 years ago, somebody thought that no computer would ever (i.e. not even in a million years) need more than 1 megabyte of memory space, RAM and ROM. So they disabled the 20th address line to try to make sure of it at the hardware level!

You might have missed my post (about 9 up) where I put in a plug for Flat memory, but I agree that paged memory is better for OS security. But Virtual Memory as well adds a lot of complexity to memory management, and IMHO the advantages are outweighed by the disadvantages. (see the link in my post above).

_________________
FAMOS - the first memory operating system
Post 15 Sep 2008, 04:05
View user's profile Send private message Visit poster's website Reply with quote
tom tobias



Joined: 09 Sep 2003
Posts: 1320
Location: usa
tom tobias
revolution, discussing his view of PAGING, wrote:
...
Very slight overhead....
Time too, is in the eye of the beholder.

Paging
1. definition: Operating System requirement (not option) to copy portions of task FROM hard disk TO system memory, AND then, to return unused portions of the task BACK to the hard disk again.
2. Philosophy: this is (yet another) example of wasteful, and utterly stupid activity (not evil) which is derived from the ERA of EXPENSIVE system memory. At that time, 1960's, no one could imagine a computer with 2 GB memory. How many tasks require that much memory? Apart from Astronomers and Mathematicians, who else is using 2 GB of memory, whether on a hard disk, (paged into memory) or sitting entirely in memory, for a single task?
3. Alternative: Load the whole task into main memory, one time. No further requirement to "page", hence, no overhead at all. Yes, it will take longer to COMMENCE the task, compared with a paged model.

Adam started the thread asking about flat versus paging (itself a step child of segmentation philosophy). This debate really goes back to Intel versus Motorola, from thirty years ago, and I remain firmly in the anti-Intel camp.
For your own OS, in my opinion, STICK to the SIMPLEST, which is FLAT, without concern for "protection", instead, make your OS simple, (or as Adam suggested: "light", which, in some circles, could be interpreted improperly, as implying insufficient hops), so that, upon infection, one simply reformats the OS partition, and reinstalls the OS, a matter of ten seconds from a well designed program operating from the DVD.
Forget paging.
Forget "protection".
THINK memory!
Smile
Post 15 Sep 2008, 11:04
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2, 3  Next

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.