How to get the physical address of the associated data from the structure page?

Say we have a struct page from the address space of the cached page file.

How can we get the starting physical address of the 4KB data from this struct page ?

I assume that inside the struct sk_buff should be something like a data pointer, but I did not find it.


EDIT

Thanks to Mat and llya for the answers.

After looking at the answers, I think the first problem is to determine if the struct page in ZONE_NORMAL or ZONE_HIGHMEM .

During file I / O, when we do not find the cached page, we will first select a new page using page_cache_alloc_cold() . page_cache_alloc_cold() will finally call alloc_pages() , which seems to use ZONE_HIGHMEM (which, in x86, is the kernel memory area starting at PAGE_OFFSET + 896M) for its work.

So,

  • I think Mat answer is suitable for pages in ZONE_NORMAL
  • Suppose we use kmap() to find the source physical address of the 4 KB data associated with the page structure, should we use (unsigned long)(&page)-PAGE_OFFSET to find the physical address where the structure itself is stored?

Please correct.

+7
source share
1 answer

You need to map page to kernel memory as follows:

 void * mapping = kmap_atomic(page, KM_USER0); // work with mapping... kunmap_atomic(mapping, KM_USER0); 

This trick is required since Linux has the concept of HighMemory (see this link for an example.)

UPD: you can use kmap instead of kmap_atomic in non- kmap_atomic contexts.

+1
source

All Articles