LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices

Reply
 
Search this Thread
Old 08-15-2008, 05:26 AM   #1
valpa
LQ Newbie
 
Registered: Jun 2007
Posts: 24

Rep: Reputation: 15
access paging table memory using another page table via MMU?


Hi,


The user process want to access the PHY memory via virtual address, the MMU will translate VA(virtual address) to PA(physical address) by using process's page table.

This page table must itself locate in PHY memory. Thus, when kernel need to handle the process page table, it must use another page table for MMU to access the process page table memory. So, what is the another page table used?
 
Old 08-15-2008, 09:42 AM   #2
johnsfine
Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,125

Rep: Reputation: 1119Reputation: 1119Reputation: 1119Reputation: 1119Reputation: 1119Reputation: 1119Reputation: 1119Reputation: 1119Reputation: 1119
Read the info available from this link
http://linux-mm.org/

I was rather disappointed with it myself. It is more a random collection of odd fractions of the information. It has neither a good overview nor a consistent level of detail.

But it does have useful information. And I don't know a better source. And you seem to need some of that information.

I've been annoyed in other threads where experts have referred people to that page for specific advanced MM info you can't get there. But, until some better page is posted that one should be considered required reading before you start asking MM questions.

Quote:
Originally Posted by valpa View Post
Thus, when kernel need to handle the process page table, it must use another page table for MMU to access the process page table memory.
True.

Quote:
So, what is the another page table used?
Maybe I'm misunderstanding the question.

You'd need to really dig in the code to find out exactly which page of the kernel's page table contains the entry that maps any given page of a given process's page table. Is that really what you want to know?

Remember there is a 1 to 512 ratio (for 64-bit or PAE) between page table space and the space mapped by those page tables. So the overhead of remapping the pages tables for kernel access isn't very great.

Long ago, when I wrote my own 32-bit kernel for 486's, I double used the user level page directory as part of the kernel page table to minimize the space and time cost of that mapping. In a 486, the page directory had a format consistent enough with a page table that it worked very well to use the same physical page as both the user's page directory and the page table page used by the kernel to map the user's full page table.
I'm not sure whether all the new interesting features in page tables and page directories would create a problem for that double use trick. But I am pretty sure Linux and Windows never used that double use trick, even back when the newest available hardware presented no disadvantages for that trick.
 
Old 08-19-2008, 12:31 AM   #3
valpa
LQ Newbie
 
Registered: Jun 2007
Posts: 24

Original Poster
Rep: Reputation: 15
Quote:
You'd need to really dig in the code to find out exactly which page of the kernel's page table contains the entry that maps any given page of a given process's page table. Is that really what you want to know?
I think at the very begining of booting linux, there is only one page table established in arch/i386/kernel/head.S. Then all child/grandchild page tables for later processes are copy & write from the very first page table. Right??

In another word, Does a process's page table has the entry which map's to the page table physical memory location?

Last edited by valpa; 08-19-2008 at 02:38 AM.
 
Old 08-19-2008, 09:04 AM   #4
johnsfine
Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,125

Rep: Reputation: 1119Reputation: 1119Reputation: 1119Reputation: 1119Reputation: 1119Reputation: 1119Reputation: 1119Reputation: 1119Reputation: 1119
Quote:
Originally Posted by valpa View Post
Does a process's page table has the entry which map's to the page table physical memory location?
IIUC, the usual (not all build variants) Linux memory management puts all page tables into the kernel virtual address space and puts the entire kernel virtual address space into every process's virtual address space.

So from a hardware definition of page tables, that does mean a process's page table maps itself.

A page table typically takes many pages, so you seem to be misunderstanding something where you said "the entry".

Did you read things at that site I suggested? I think that would have answered your question.
 
Old 08-22-2008, 12:39 AM   #5
valpa
LQ Newbie
 
Registered: Jun 2007
Posts: 24

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by johnsfine View Post
IIUC, the usual (not all build variants) Linux memory management puts all page tables into the kernel virtual address space and puts the entire kernel virtual address space into every process's virtual address space.

So from a hardware definition of page tables, that does mean a process's page table maps itself.

A page table typically takes many pages, so you seem to be misunderstanding something where you said "the entry".

Did you read things at that site I suggested? I think that would have answered your question.

Thanks, I should read the reference through, and ask based on reference part.
Thanks for suggestion.
 
Old 08-22-2008, 12:30 PM   #6
sundialsvcs
Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 5,425

Rep: Reputation: 1159Reputation: 1159Reputation: 1159Reputation: 1159Reputation: 1159Reputation: 1159Reputation: 1159Reputation: 1159Reputation: 1159
The currently-active page and segment tables are located using control registers in the CPU hardware, which only privileged programs can reference.

When Linux switches from one task to another, it reloads these registers with the appropriate pointer-values for this particular task.

Reloading the control-registers also causes the TLB (translation lookaside buffer) to be flushed.

When this has been done, all subsequent virtual-address translation that takes place on this CPU will use the new segment/page tables.

If it is necessary to modify the page or segment table entries for a task, the appropriate TLB entries must be invalidated, thus forcing the modified entries to be picked-up and used. The Linux memory manager also handles this.

Page and segment tables must be located in real-memory; it cannot be virtual (for what are, if you think about it, perfectly-obvious reasons...). But page-tables, at least, can be "absent." A page-fault can occur either because the page-table says the page is not there, or because the segment-table says the page-table is not there.

Last edited by sundialsvcs; 08-22-2008 at 12:33 PM.
 
Old 08-22-2008, 11:31 PM   #7
valpa
LQ Newbie
 
Registered: Jun 2007
Posts: 24

Original Poster
Rep: Reputation: 15
Quote:
When Linux switches from one task to another, it reloads these registers with the appropriate pointer-values for this particular task.
Ok, it reloads the registers... I think there must be some codes (instructions) to accomplish the reloads and switches. These codes must be locate in the memory. And CPU fetch these codes via page table too. What kind of page table it use when task switch and reload the register. Is it the current process's page table??
 
Old 08-23-2008, 06:16 PM   #8
johnsfine
Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,125

Rep: Reputation: 1119Reputation: 1119Reputation: 1119Reputation: 1119Reputation: 1119Reputation: 1119Reputation: 1119Reputation: 1119Reputation: 1119
Quote:
Originally Posted by johnsfine View Post
and puts the entire kernel virtual address space into every process's virtual address space.
Quote:
Originally Posted by valpa View Post
What kind of page table it use when task switch and reload the register. Is it the current process's page table??
If you understand the basic concepts, my quote above answered your question before you asked it.

The 32-bit x86 hardware architecture includes some very complicated mechanisms for doing things like interrupt service and task switching, using kernel code that is not in the address space of the tasks interrupted and switched. But Linux and Windows don't use that stuff.

The kernel code is mapped into every process's page table so it is available at the same address before, during and after a task switch.

The 64-bit hardware architecture eliminates a lot of those complicated features that Windows and Linux weren't using, so a 64-bit OS pretty much has no choice but to handle those things roughly the way Windows and Linux do.
 
Old 08-26-2008, 04:26 PM   #9
sundialsvcs
Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 5,425

Rep: Reputation: 1159Reputation: 1159Reputation: 1159Reputation: 1159Reputation: 1159Reputation: 1159Reputation: 1159Reputation: 1159Reputation: 1159
Quote:
Originally Posted by valpa View Post
Ok, it reloads the registers... I think there must be some codes (instructions) to accomplish the reloads and switches. These codes must be locate in the memory. And CPU fetch these codes via page table too. What kind of page table it use when task switch and reload the register. Is it the current process's page table??
This is one of the reasons why Linux maps the virtual-address space out the way that it does: every process's address-space map includes not only the process's private storage, but also stuff that is in-common to every process. "Linux itself," for example, is mapped there, even though processes might well have no access to it.

You're correct to observe that the addresses in the control-registers must be real addresses, not virtual ones. Quite obviously, "the address of the current page-table" cannot be a virtual address...

In this way, the CPU can take an interrupt, handle it, and do a certain amount of subsequent processing no matter what address-space is currently mapped by the hardware. The idea is that it might even be able to take the interrupt, do what has to be done, and return right back to the currently-running process without having to do a VM-switch.

Modern CPU architectures are heavily "pipelined." The CPU might have five or six (or more) different instructions at various stages of execution at the very same time. Fundamental events, like switching from one address-space to another, force that pipeline to be flushed, and this is something that the operating system doesn't want to do very often.
 
  


Reply

Tags
management, page


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Page table walk manually WebBeing Programming 0 08-05-2008 07:50 PM
Does each process get its own page table pages? rtaheri Linux - General 1 07-10-2008 08:27 PM
three- level page table in linux 2.6 mehrotraamit-2 Linux - Newbie 1 11-15-2005 11:19 AM
How to import MS ACCESS Table including OLE filed into the MySQL Table ? myunicom Linux - General 1 11-28-2003 12:30 PM
html page layouts with a table acid_kewpie Programming 5 06-20-2003 06:24 AM


All times are GMT -5. The time now is 02:03 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration