using segmentation to manage memory in FreeBSD

John Baldwin jhb at FreeBSD.org
Tue Mar 8 08:02:09 PST 2005


On Tuesday 08 March 2005 09:05 am, Ravi Krishna wrote:
> Hi all!
>
> I would like to know if FreeBSD allows one to use segmentation on x86
> to reduce the penalty of context switches. (please read on for
> details)
>
> Virtual memory on x86 can be managed by either segmentation or by paging.
>
> when using paging a context switch from one process to other all the
> TLB mappings stored in TLB cache are flushed, this makes context the
> switch expensive (we will have lots of TLB misses).
> There are situations when individual processes donot have large memory
> requirements . Some processors have TLB tagging, so OS doesnot flush
> all the TLB entries when a context switch happens, only selective ones
> are flushed. Unfortunatly Intex x86 does not have TLB tagging
> available.

Actually, it does.  It's called the PG_G bit and is present if the PGE feature 
is listed in CR4 (which it is for most modern processors, maybe Pentium and 
later?)

> The way to implement something similar on x86 is using segmentation.
> say I have four modules
> A, B, C, D each needing 100MB address.   I can give each of these a
> 100MB segment. Assuming TLB cache is large enough to store TLB
> mappings for all of these four, to context switch (say frm A to B) I
> can just switch the segment, by setting segmentation registers.
> These there will be no TLB flush. When we come back frm B to A again
> we switch the segment. Now again to TLB flush will happen and A will
> be able to use the TLB cache entries for its segment.

Segments just provide a base + offset into the virtual address space that is 
backed by the TLB mappings, so to make this practically useful would be a lot 
more work than would first appear because your segments have to map virtually 
contiguous memory.

> This becomes more attractive for 64 bit systems.

64-bit x86 (that is, amd64 and Intel 64-bit xeons) doesn't even have segments. 

> My question is that is this functionality available on FreeBSD in any way?

Nope.

-- 
John Baldwin <jhb at FreeBSD.org>  <><  http://www.FreeBSD.org/~jhb/
"Power Users Use the Power to Serve"  =  http://www.FreeBSD.org


More information about the freebsd-hackers mailing list