Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

what is __pa(x)

1 view
Skip to first unread message

Kirk True

unread,
Jan 9, 2004, 10:15:19 AM1/9/04
to
Hi,

> What is __pa(x) function, it said that it translates logical address to
> physical address by x-PAGE_OFFSET, PAGE_OFFSET is normally something
> like 0xc0000000, how can this translate? What is x input?

x is a virtual address. Virtual addresses are the physical addresses
plus PAGE_OFFSET. So to go *back* to a virtual address from a physical
address as the __pa macro does, you simply do the reverse operation and
subtract PAGE_OFFSET.

That's my understanding, anyway. I'm a newbie too and it might not be
that simple.

Kirk

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

Noah Yan

unread,
Jan 9, 2004, 10:15:19 AM1/9/04
to
Dear All,

What is __pa(x) function, it said that it translates logical address to
physical address by x-PAGE_OFFSET, PAGE_OFFSET is normally something

like 0xc0000000, how can this translate? What is x input? Can some
expert have some detail explaining?

Thanks

Raghu R. Arur

unread,
Jan 9, 2004, 10:15:21 AM1/9/04
to

On Mon, 8 Sep 2003, Kirk True wrote:

> Hi,
>
> > What is __pa(x) function, it said that it translates logical address to
> > physical address by x-PAGE_OFFSET, PAGE_OFFSET is normally something
> > like 0xc0000000, how can this translate? What is x input?
>
> x is a virtual address. Virtual addresses are the physical addresses
> plus PAGE_OFFSET. So to go *back* to a virtual address from a physical
> address as the __pa macro does, you simply do the reverse operation and
> subtract PAGE_OFFSET.
>

__pa(x) gives the physical address of the given virtual address - x. this
works only for kernel memory and not for user memory.


Raghu

Noah Yan

unread,
Jan 9, 2004, 10:15:22 AM1/9/04
to
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. What
format is the virtual address (logical address), is it in the format of
SEG:OFFSET, or others? 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? 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?

Thanks very much
Noah Yan

Ed L Cashin

unread,
Jan 9, 2004, 10:15:26 AM1/9/04
to
Noah Yan <yy...@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:
eca...@uga.edu | http://noserose.net/e/pgp/

Noah Yan

unread,
Jan 9, 2004, 10:15:27 AM1/9/04
to
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

Ravi Krishnamurthy

unread,
Jan 9, 2004, 10:15:27 AM1/9/04
to

--- Ed L Cashin <eca...@uga.edu> wrote:

> > 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?
>

> I imagine that if you have, e.g., 768M of RAM, you would
> never use
> kernel virtual addresses greater than ...
>
> 0xc0000000 + (768 * 1024 * 1024) = 0xf0000000

Addresses above this will still be used - for vmalloc.

__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com

Ed L Cashin

unread,
Jan 9, 2004, 10:15:27 AM1/9/04
to
Noah Yan <yy...@mail.uh.edu> writes:

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

It took me a while to understand it, so it helps to make sure I still
understand it. ;)

> 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?

I imagine that if you have, e.g., 768M of RAM, you would never use
kernel virtual addresses greater than ...

0xc0000000 + (768 * 1024 * 1024) = 0xf0000000

Someone please correct me if I'm wrong!

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

--

0 new messages