RE: what is __pa(x)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



What a detailed explanation, It makes me much clear on this. Thanks very
much.

Still some questions on 32bit 3G/1G mode, the 1G RAM does not mean the
machine must have physical 1G memory, it does matter if the machine has
less or more than 1G physical RAM, right?

Thanks 
Noah Yan


-----Original Message-----
From: Ed L Cashin [mailto:ecashin@uga.edu] 
Sent: Tuesday, September 09, 2003 10:57 AM
To: yyan3@UH.EDU
Cc: 'Kernel Newbies'
Subject: Re: what is __pa(x)

Noah Yan <yyan4@mail.uh.edu> writes:

> That give me some hints that this works only for kernel memory and
> not for user memory. But I am still confused. And
> 0x00000000-oxc000000 is for user and kernel while
> oxc0000000-oxffffffff is only for kernel. 

Yes, those are virtual addresses.  I'm only talking about the
old-fashioned 32-bit, 3G/1G-split model of Linux VM on i386.  I find
it easier to understand that first and then learn about the other
models.

Many of the complexities of the other models come about because of the
difficulties in using 32 bits to access more than 2^32 units of
memory.  It's good to have a grasp of what linux did before we had
that much RAM.  Anyway, understanding the traditional model helps to
make it possible to understand the more complex VM hacks people are
doing these days.

> What format is the virtual
> address (logical address), is it in the format of SEG:OFFSET, or
> others? 

On i386, the segment specifier is kept in registers, so the address in
a pointer is only the 32-bit offset within the segment.  When I think
about a virtual address, I usually ignore the segment specifier, since
that's in a register and isn't part of a pointer's value.

> I am still unclear about the layout difference between kernel memory
> and user memory. Is kernel memory just flat address mode? How big of
> it, 4G?

For the traditional i386 32-bit, 3G/1G split model, you have 4G of
virtual addresses that a 32-bit pointer can specify.  To make things
simple, the kernel's virtual addresses correspond to physical
addresses like shown below.

    	   
 0x100000000 +-------+ 	\
             |       |	 \
             |kernel |	  \
             |VM     |	   \
             |addrs  |	    \
             |       |	     \-
             |       |	       \
 0x0c0000000 +-------+ 	\       \
             |       |	 \       \
             |user   |	  \	  \
             |VM     |	   \	   \
             |addrs  |	    \	    \
             |       |	     \	     \
             |       |	      \	      \
 0x080000000 +-------+	       \       \
             |       |	        \       \
             |user   |	         \       \-
             |VM     |	          \-       \
             |addrs  |	            \       \
             |       |	             \	     \
             |       |	              \	      \
 0x040000000 +-------+	               \       \+-------+ 
             |       |	                \     	|       |
             |user   |	                 \    	|1G     |
             |VM     | 	                  \   	|RAM    |
             |addrs  | 	                   \  	|       |
             |       | 	                    \ 	|       |
             |       | 	                     \	|       |
           0 +-------+		              \	+-------+


In the 3G of user virtual addresses, you don't have that linear
correspondance between virtual and physical addresses.  If you were to
draw lines in the above picture from the user region to the RAM, the
lines would be criss crossing in an unorderly way.  Note that a frame
in RAM may have many virtual addresses pointing to it.  A frame used
in userland has at least the mapping inside the kernel and the mapping
in userland.

> What I am thinking is that 4G is application address space, and
> first 3G is for both kernel and user and the left 1G is only
> reserved for kernel. And these two parts are divided by
> PAGE_OFFSET. So how can x-PAGE_OFFSET get physical address?

That isn't quite right.  As you can see from the picture, subtracting
0xc0000000 from a kernelspace virtual address results in the physical
address.  That is because the kernel uses virtual addresses in the
range 0xc0000000 to 0x100000000 that correspond to a gigabyte of page
frames.  Virtual addresses below 0xc0000000 are userspace addresses.

-- 
--Ed L Cashin            |   PGP public key:
  ecashin@uga.edu        |   http://noserose.net/e/pgp/

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux