2

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?

Shai
  • 111,146
  • 38
  • 238
  • 371
makakko
  • 357
  • 5
  • 11
  • Your terminology is a bit off. "Virtual memory" describes any system that can alter addresses before accessing RAM. *Segmentation* is one form of virtual memory. *Paging* is another form that is more commonly used. Maybe you are confusing "virtual memory" with "paging?" – Karmastan Jul 16 '10 at 06:04
  • I'm confused about paging, and pure pagin. Or segmentation and pure segmentation. What is pure? – makakko Jul 16 '10 at 06:18

2 Answers2

2

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
  • 24,186
  • 3
  • 55
  • 65
  • 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 Jul 16 '10 at 06:35
  • 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 Jul 16 '10 at 06:53
  • No, MMU has no function in an only-segmented system. Segment descriptors are usually cached by the CPU in another way. – zvrba Jul 16 '10 at 10:46
0

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
  • 5,618
  • 18
  • 24