Re: Questions about Minix



J.F. de Smit escreveu:
I believe the original reason to use segmentation was simply to benefit
from the MMU to protect processes from messing up eachother's memory
areas, and nothing more. the "separate I&D" functionality is a new feature
of Minix 3 if I'm correct.

I thought people did not consider segmentation to be performed by the MMU.
Paging is, but segmentation is not.

Going out on a limb for a bit, it might even be possible to support both
models by tinkering a bit with the kernel and writing a second, more
complex process manager. That way, the demanding people can have a paged,
NX-supporting, fancy-featured system while students and starting hobbyists
can have a working system simple enough for them to tinker with.

IMHO paging support is much easy to understand than segmentation support (at
least the allocation part).
Segmentation requires allocating a chunk of contiguous bytes in a best-fit
or a first-fit fashion, while paging only requires some sort of page frame
allocator using a stack or a bitmap (but there's no "first-fit"
nor "best-fit" trick in it).

Of course you still need to allocate chunks of contiguous memory, but only
at a higher level; in user mode and at kernel level if you need dynamic
memory allocation in kernel (I heard from Tanennbaum himself that Minix
does not use dynamic memory in kernel land (because it uses one static
buffer per process to support IPC, and suspends the sending process when
the receiving buffer is full), but I may have misunderstood).

- multiple instances of the same program can share a code segment. This
saves memory, memory transfers and counters fragmentation issues
possibly caused by using large amounts of small segments.

This needs copy-on-write techniques. Unless this "instances" are threads
of the same process.

(...)
immutable. You won't need copy-on-write techniques, because it's
prohibited by the kernel and MMU to write to the .text segment.

Sorry. I read "data segment".
Yes, the code segment can be shared. Now I understand this wouldn't be
possible without spliting the code and data segments.

On the other hand, what you said about the stack and data areas is true:
they share the same segment, and it is fixed. There is no way to prevent
a stack from growing into the heap (only a possibility of detecting it
while context switching)
An expand-down segment descriptor could be used to control stack growth.

True, but this would limit your stack size to some predetermined value,
meaning things go haywire as soon as you run out of stack space, even if
you still have plenty of heap left.

No if you catched the "overflow" using the Stack Fault.
A Stack Fault to be handled in Ring 0 causes a stack switch (unless the
processor is already in ring 0, but that's not the case), so it's safe.
The kernel could then expand the stack segment or kill the process if it
would run into the heap. This could be done because the library has to call
the kernel (sbrk) every time it expands the heap, so the stack fault
handler could know if there was any space left.

By combining heap and stack into one
segment, things will run smoothly until the stack runs into the uppermost
allocated part of the heap. OTOH, the current approach has a race
condition: if the stack runs into the heap, but shrinks back to a legal
size before the kernel gets called due to a trap or interrupt, it is
impossible to tell that the process has destroyed its own heap, leading to
incorrect behaviour.

An expand-down stack segment could avoid this particular problem.

--
João Jerónimo

"Computer are composed of software, hardware, and other stuff terminated
in "ware", like firmware, tupperware, (...)" - by JJ.
.



Relevant Pages

  • Re: Questions about Minix
    ... from the MMU to protect processes from messing up eachother's memory ... Paging is, but segmentation is not. ... in user mode and at kernel level if you need dynamic ... A Stack Fault to be handled in Ring 0 causes a stack switch (unless the ...
    (comp.os.minix)
  • Re: How linear address translate to physical address in kernel space?
    ... the logical address must be pass segment translation. ... In paging process, CR3 register take one important role, it include page ... So in linux kernel, if it ... user task memory address space. ...
    (Linux-Kernel)
  • Re: Questions about Minix
    ... I think I got to that conclusion that .text shared the same memory chunk ... segment to processes from the beginning, and a data segment that did not ... True, but this would limit your stack size to some predetermined value, ... you still have plenty of heap left. ...
    (comp.os.minix)
  • Re: Questions about Minix
    ... allocating each component the memory it needs can be a real pain). ... This real makes stuff very "static", because the stack ... necessary) the segment when the application demands more heap than was ... address in the data segment, because the data segment contains only data ...
    (comp.os.minix)
  • 64-bit c++ application crashing on solaris
    ... We think this could probably be due to sufficient memory not available ... Specifies the default value of the stack size to be used when a kernel ... Illegal stack size, Using N ... Gbytes for 64-bit systems) and if smaller than the minimum or larger ...
    (comp.unix.programmer)