简体   繁体   English

如何从结构页中获取关联数据的物理地址?

[英]How to get the physical address of the associated data from a struct page?

Let's say we've got a struct page from the address space of a page cached file.假设我们从页面缓存文件的地址空间中获得了一个struct page

How could we get the starting physical address of the 4KB data from this struct page ?我们如何从这个struct page中获取 4KB 数据的起始物理地址?

I suppose there should be something like the data pointer inside struct sk_buff , but I didn't find it.我想struct sk_buff中应该有类似data指针的东西,但我没有找到它。


EDIT编辑

Thanks Mat and llya for the answers.感谢 Mat 和 llya 的回答。

After looking at the answers, I think the first problem is to identify whether the struct page is located in ZONE_NORMAL or ZONE_HIGHMEM .看了答案,我觉得第一个问题就是判断struct page是在ZONE_NORMAL还是ZONE_HIGHMEM

During a file I/O, when we don't find the cached page, we will at first allocate a new page using page_cache_alloc_cold() .在文件 I/O 期间,当我们找不到缓存页面时,我们将首先使用page_cache_alloc_cold()分配一个新页面。 page_cache_alloc_cold() will finally calls alloc_pages() which looks like it will use the ZONE_HIGHMEM (which in x86, is the kernel memory area starting at PAGE_OFFSET +896M) for its job. page_cache_alloc_cold()最终会调用alloc_pages() ,看起来它将使用ZONE_HIGHMEM (在 x86 中,是从PAGE_OFFSET +896M 开始的 kernel memory 区域)。

So所以

  • I think Mat's answer is suitable for pages in ZONE_NORMAL我认为 Mat 的答案适合ZONE_NORMAL中的页面
  • Suppose we use kmap() to find the starting physical address of the 4KB data associated with the struct page, is it correct that we should use (unsigned long)(&page)-PAGE_OFFSET to find the physical address where stores the structure itself?假设我们使用kmap()来查找与结构页关联的 4KB 数据的起始物理地址,我们应该使用(unsigned long)(&page)-PAGE_OFFSET来查找存储结构本身的物理地址是否正确?

Please correct.请改正。

You need to map a page into the kernel memory as follows:你需要把 map 一个page变成 kernel memory 如下:

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

This trick is required as there is a HighMemory concept in Linux (see this link for ex.).这个技巧是必需的,因为 Linux 中有一个HighMemory概念(例如,请参见此链接)。

UPD: You can use kmap instead of kmap_atomic in non-atomic contexts. UPD:您可以在非原子上下文中使用kmap而不是kmap_atomic

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM