"Memory model" is both a low-level and a (relatively) high-level concept.
Back in the olden days there was a bit of a "war" raging between processors with a segmented memory model and those with a "paged" or "mapped" memory model. The Burroughs B5000 series machines and the Plessey 250 used a segmented memory model with "capabilities" (or "descriptors"). That is, physical storage was not managed as conceptual fixed-size pages but rather variable-length segments, with each segment corresponding to some logical entity (eg, a procedure or an object). To address between segments "capability registers" were used that could only be loaded in a protected fashion and which contained the physical address of a segment, the length of the segment, and the authorizations (eg, read/write/execute) that the executing program was given to reference the segment.
These systems were happily running when "paged" systems were still struggling to get off the ground.
The original PC was based on the 8086 processor which was designed to support a poor-man's segmented architecture. There were, IIRC, four segment registers that could be selected to be added to a 16-bit general register value to produce a 20-bit address. The theory was that these registers would be managed in software somewhat similar to how the Burroughs and Plessey systems managed them with a bit more hardware support. But before good software could be produced to make use of this feature DOS was kludged onto the 8086, and so the feature was never really used effectively.
As to which is better, well, it doesn't matter anymore, since the segmented model doesn't exist in any "real" (non-experimental) environment. But back in the day the segmented model generally performed better and allowed the OS to be more robust. The major negative factor was that it imposed restrictions on compilers and, to an extent, programmers that were not consistent with the "Wild West" attitudes of many programmers then and now.
The "paged" model
A "paged" model assumes the address space is divided into "pages" of a certain size (though in some cases several different page sizes are supported). Generally the page size is somewhere between 256 bytes and 64k bytes (always a power of 2). It is also assumed that the hardware contains some sort of address translation support so that "logical" addresses (addresses in the program's "address space") can be mapped to "physical" addresses (addresses in RAM).
A paged model may be implemented for two main reasons:
- To allow multiple different threads/processes to have separate address spaces, each starting from "zero" (or some other standard address), and without requiring to OS to pre-allocate the entire possible address space for a thread/process as one contiguous chunk.
- To enable "virtual memory" by allowing individual pages in the logical address space to be "paged out" to disk, to be later reloaded if/when the program attempts to reference them.
There are also minor features of the page translation hardware that may be used, such as setting read/write/execute permissions, allowing some pages to be "shared" between processes/threads, etc.
The "flat" model
Ignoring the Harvard model, which was arguably the very first computer memory model, the flat von Neumann storage model was first model to achieve common use. This is basically that -- a "flat" address space of undistinguished words (not bytes until very late in the game) that began at address zero and continued upward to the "top" of available memory. Some portion of memory at the "bottom" or "top" of memory would be reserved for some sort of "loader", with the rest available to the single executing program. One program at a time ran, with the program able to use all but that small reserved RAM area.
Slowly things changed, to where the small reserved area became larger and held an operating system of sorts, but still only one program at a time. As time progressed still further, various tricks were invented to allow, eg, certain specialized programs to run in a "corner" of memory, permitting spooling programs, etc, to co-exist with the user's programs.
But the push for "multiprogramming" was exerting pressure. Some systems added crude address mapping hardware to enable multiple programs to each have their own address space. Other systems required that programs be "self relocating" so that they could run anywhere in memory vs being "linked" to a specific address.
Early Unix (among others) handled the multiprogramming job by "swapping" programs in and out: A program (loaded at address zero) would run until it "blocked" to do I/O, then it would be "swapped" (in its entirety, including all code and data) to disk and a different program "swapped" in.
But for the most part these techniques slowly evolved (or perhaps devolved) to various forms of page-mapping storage models.
Thanks! If segmented memory model is not related to the different segments (BSS (Block Started by Symbol) segment, Text segment and Data segment) in an object file? I heard those segments in object files quite often (http://en.wikipedia.org/wiki/Object_file#Object_file_formats), so I guess they may not be related to the segments in segmented memory model, although they are all called "segments".
– Tim – 2011-08-07T00:31:29.453