views:

30

answers:

2
+1  Q: 

Pure segmentation

I'm a bit confused about pure segmentation due to in my head always existed the idea of virtual memory.

But as I understand pure segmentation is also imagining a virtual address space, divided in segments that are ALL loaded in RAM.

The difference with virtual memory with segmentation, is that possibly there's some segment that it's not in RAM.

Is this correct?

I ADD A QUESTION: Is there a practical difference between segmentation combined with paging, and a two-level paging?, it's the same except for the "limit" protection of the segment method. Or there's another difference?

A: 

No, it's not correct. For example, on x86, segmentation uses "far" pointers that consist of two parts: the segment selector (loaded into a segment register, e.g., DS) and an offset into the segment. Segment offsets always begin at 0. The CPU uses the segment selector to find the segment descriptor which contains the segment's LINEAR base address, length and access rights. All accesses are length-checked; if you try to access memory outside of the segment limit or with invalid access (e.g., writing to a read-only segment), the CPU will generate a general protection fault.

Since segment addresses are always zero-based and the segment base is implicit in the segment selector, the OS can move segments around and defragment memory without affecting the programs using that data. (Contrast this with the "flat" memory model where if you move some data, you also have to update all pointers pointing to it.)

Now, when paging is disabled, the LINEAR segment base address is its physical memory address. When paging is enabled, all accesses to segment data are translated by the MMU as usual.

zvrba
And yes, there is a difference between segmentation and two-level paging. Two- or (multi-)level paging is a technique to reduce the memory used by page tables.
zvrba
In an only segmentated memory system, MMU cannot be used?. I mean, using a cache like TLB to avoid slow RAM to check the base and limit of each segment. As far as I know, the TLB works fine for paging, having (in a simple form): page-frame, page-frame, etc. In the case of segmentation, I'd need: segment-limit-frame, segment-limit-frame...
makakko
No, MMU has no function in an only-segmented system. Segment descriptors are usually cached by the CPU in another way.
zvrba
Thanks for your help and patience.
makakko
A: 

If you're serious about understanding memory management at this level, an excellent explanation can be found by reading Operating System Concepts by Silberschatz, Galvin, and Gagne. You should be able to find an inexpensive, older edition.

Karmastan