Re: General questions about virtual memory

2008-07-30 Thread Max Laier
Hi,

On Wednesday 30 July 2008 13:59:53 FreeBSD Hackers wrote:
 Examples of some specific questions that I have include:

 WRT translation of virtual addresses to physical addresses, where does the
 hardware stop and the software begin?  Explanation: who determines the
 format of the page tables (CPU or OS)?  Who populates and maintains the
 page tables?  Where does the translation lookaside buffer reside?  Who
 maintains the TLB?

it depends ... different architectures use different models.  In i386 most of 
the above is done by hardware aided by software (i.e. the software has to 
flush the hardware TLB when it knows that the entries are no longer up to date 
...)

 Also WRT page tables, how does the OS and the MMU adjust for different
 sizes of physical RAM?  Wouldn't the page tables for a system with 512 MB
 of RAM will be fewer than the page tables for a system with 2 GB of RAM? 
 How does the CPU know how many page table entries there are?

This suggest that you don't understand virtual memory at all.  Go back to the 
start of the chapter and re-read.  The page directories and page tables 
describe a *virtual* address space.  For a given architecture the *virtual* 
address space has a fixed size (4GB for i386), so the page table structure is 
always the same size (though it might be sparsely populated).  Inside the page 
table you store *physical* addresses, the size of which is defined by the 
hardware.  Also note that the physical addresses of your RAM might not 
necessarily start at zero and go for XX MB ... you need additional bookkeeping 
to track that (see core map, free lists, ...).  The size of the PTE is defined 
by hardware and doesn't change at runtime.

 I have a few more questions, but for starters this is the kind of
 information I'm seeking.  I'm just not getting a clear enough picture from
 the textbook I'm reading now.  (It makes me wish I was still in college so
 I could dump my questions on my college professor. :)

 If anyone is willing to help me understand this, I would greatly appreciate
 it.  I would also value your input if there are other resources (people,
 mailing lists, books, web pages, etc.) that you want to recommend instead
 of taking some time to help teach me.

google, wikipedia, the FreeBSD articles, ... all there at your fingertips.

-- 
/\  Best regards,  | [EMAIL PROTECTED]
\ /  Max Laier  | ICQ #67774661
 X   http://pf4freebsd.love2party.net/  | [EMAIL PROTECTED]
/ \  ASCII Ribbon Campaign  | Against HTML Mail and News
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: General questions about virtual memory

2008-07-30 Thread FreeBSD Hackers

 This suggest that you don't understand virtual memory at all.  Go back to
 the
 start of the chapter and re-read.  The page directories and page tables
 describe a *virtual* address space.  For a given architecture the *virtual*
 address space has a fixed size (4GB for i386), so the page table structure
 is
 always the same size (though it might be sparsely populated).  Inside the
 page


Ack!  As soon as I read this I realized the mistake I had made in my
thinking.  This was a dumb question, and I knew better than to ask.  Somehow
I had confused myself.

- 8 -

If a read request is made to a virtual address who's data has been swapped
out, the CPU traps to the OS to fix the problem.  Assuming there are no free
page frames for the new data, a page frame is selected and evicted to make
room for the new page.  Whatever page was chosen belongs to a process
somewhere in the system.  When that page frame gets swapped, the PTE
pointing to that page frame must be updated to indicate that that data is no
longer in RAM.  How does the OS find that PTE?  Does it search through every
entry of every page table for every process in the system until it finds it?

Kevin
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: General questions about virtual memory

2008-07-30 Thread Erik Trulsson
On Wed, Jul 30, 2008 at 07:59:53AM -0400, FreeBSD Hackers wrote:
 Hi, all.  I apologize for not posting a question specific to FreeBSD (I'll
 study about that later), but I'm looking for some help understanding a few
 things and I don't know where else to turn.  Using FreeBSD to give me
 concrete examples of how certain things work is okay, since I do use FreeBSD
 and I intend to read and study books covering the design and implementation
 of FreeBSD.
 
 I recently picked up one of my old college textbooks, Modern Operating
 Systems (Tanenbaum, an older edition, but I'm not sure which one since the
 book is at home and I am not) with a strong desire to read it cover-to-cover
 and get a solid foundation of the concepts described therein.  The chapter
 on virtual memory has left me with some questions, and if anyone would be
 willing to help me understand (either on or off list) a few things that
 aren't clear, I would very much appreciate it.

You could try picking up one of Tanenbaum's other books: Structured
Computer Organization, which among other things cover virtual memory from
a hardware perspective. (At least my copy does. It is the third edition,
which is not the latest.)


 
 Examples of some specific questions that I have include:
 
 WRT translation of virtual addresses to physical addresses, where does the
 hardware stop and the software begin?  Explanation: who determines the
 format of the page tables (CPU or OS)?  Who populates and maintains the page
 tables?  Where does the translation lookaside buffer reside?  Who maintains
 the TLB?

It can vary a bit between different architectures, but in general the format
of the page tables is determined by the CPU.  The TLB is located inside the
CPU (so it can be accessed quickly, it is after all just a specialized
cache.)  The page tables are normally populated and maintained by the OS,
the CPU just reads them.  The TLB is typically maintained in hardware, but
there are systems where it has to be updated by the OS.


 
 Also WRT page tables, how does the OS and the MMU adjust for different sizes
 of physical RAM?  Wouldn't the page tables for a system with 512 MB of RAM
 will be fewer than the page tables for a system with 2 GB of RAM?  How does
 the CPU know how many page table entries there are?

The page tables are typically used for mapping between virtual and physical
addresses (and also for access rights to the mapped memory).  This means
that the size of the page table depends primarily on the size of the virtual
memory which is not dependent on the actual RAM installed.

The page tables are typically a tree-like structure, where the top level is
a fairly small (typically one page) fixed-size array which contains pointers
to the next level of the page table.  In that level there are either yet
another array of entries each of which is either a pointer to another level,
or a page descriptor.  You walk down the tree until you either find a
descriptor for the page you are looking for or an entry saying that pages
further down that branch has not been allocated.

How many levels there are is system dependent.  IIRC the i386 only uses a
two-level format (three levels when using PAE), while the Motorola 68030
could have as many as seven levels.


 
 I have a few more questions, but for starters this is the kind of
 information I'm seeking.  I'm just not getting a clear enough picture from
 the textbook I'm reading now.  (It makes me wish I was still in college so I
 could dump my questions on my college professor. :)
 
 If anyone is willing to help me understand this, I would greatly appreciate
 it.  I would also value your input if there are other resources (people,
 mailing lists, books, web pages, etc.) that you want to recommend instead of
 taking some time to help teach me.


You could try picking up one of Tanenbaum's other books: Structured
Computer Organization, which among other things cover virtual memory from
a hardware perspective, including examples for how the page tables are
organized for a couple of example architectures.


-- 
Insert your favourite quote here.
Erik Trulsson
[EMAIL PROTECTED]
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: General questions about virtual memory

2008-07-30 Thread Max Laier
On Wednesday 30 July 2008 18:07:51 FreeBSD Hackers wrote:
  This suggest that you don't understand virtual memory at all.  Go back to
  the
  start of the chapter and re-read.  The page directories and page tables
  describe a *virtual* address space.  For a given architecture the
  *virtual* address space has a fixed size (4GB for i386), so the page
  table structure is
  always the same size (though it might be sparsely populated).  Inside the
  page

 Ack!  As soon as I read this I realized the mistake I had made in my
 thinking.  This was a dumb question, and I knew better than to ask. 
 Somehow I had confused myself.

 - 8 -

 If a read request is made to a virtual address who's data has been swapped
 out, the CPU traps to the OS to fix the problem.  Assuming there are no
 free page frames for the new data, a page frame is selected and evicted to
 make room for the new page.  Whatever page was chosen belongs to a process
 somewhere in the system.  When that page frame gets swapped, the PTE
 pointing to that page frame must be updated to indicate that that data is
 no longer in RAM.  How does the OS find that PTE?  Does it search through
 every entry of every page table for every process in the system until it
 finds it?

You should have quoted (and I suppose read) my entire message:
.. you need additional bookkeeping 
  to track that (see core map, free lists, ...)

Wikipedia really does a good job explaining all this.

-- 
/\  Best regards,  | [EMAIL PROTECTED]
\ /  Max Laier  | ICQ #67774661
 X   http://pf4freebsd.love2party.net/  | [EMAIL PROTECTED]
/ \  ASCII Ribbon Campaign  | Against HTML Mail and News
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: General questions about virtual memory

2008-07-30 Thread Nate Eldredge

On Wed, 30 Jul 2008, FreeBSD Hackers wrote:


If anyone is willing to help me understand this, I would greatly appreciate
it.  I would also value your input if there are other resources (people,
mailing lists, books, web pages, etc.) that you want to recommend instead of
taking some time to help teach me.


As a slightly less orthodox suggestion, I learned a lot of this from the 
practice side rather than the theory side, and it seems like maybe 
this is where some of your questions lie.  In addition to a textbook, you 
might find it useful to get a copy of the manual for your favorite CPU, 
which will explain, at the level of assembly language, how all these 
features work.  (They are usually available free on the manufacturer's 
website, though you may have to hunt around a bit or register for a 
developer program or something.)  You can read it in conjunction with the 
FreeBSD kernel source to see an actual example.  I found this approach 
very instructive.


--

Nate Eldredge
[EMAIL PROTECTED]
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]