如何从结构页面获取相关数据的物理地址? [英] How to get the physical address of the associated data from a struct page?

查看:306
本文介绍了如何从结构页面获取相关数据的物理地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

比方说,我们已经有了一个结构页从页面缓存的文件的地址空间。

Let's say we've got a struct page from the address space of a page cached file.

我们怎样才能从这个结构页 4KB的数据的起始物理地址?

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

我想应该是这样的数据结构的sk_buff 的指针,但我没有找到它

I suppose there should be something like the data pointer inside struct sk_buff, but I didn't find it.

修改

由于垫子和llya的答案。

Thanks Mat and llya for the answers.

在看答案后,我想第一个问题是确定是否结构页位于 ZONE_NORMAL ZONE_HIGHMEM

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.

在一个文件I / O,当我们没有找到缓存的页面,我们将首先使用分配一个新的页面 page_cache_alloc_cold() page_cache_alloc_cold()将最后调用 alloc_pages()它看起来像它会使用 ZONE_HIGHMEM (这在86,是开始于 PAGE_OFFSET + 896M内核内存区)为它的工作。

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(). 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.

所以


  • 我想垫的答案是适合 ZONE_NORMAL

  • 假设我们使用 KMAP()找到与结构页面相关的4KB数据的起始物理地址,它是正确的,我们应该使用(无符号长)(安培;页)-PAGE_OFFSET 来找到在哪里存储结构本身
  • 的物理地址?
  • I think Mat's answer is suitable for pages in 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?

请纠正。

推荐答案

您需要一个映射到内核内存如下:

You need to map a page into the kernel memory as follows:

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

是必需的这招,因为在Linux上 HighMemory 的概念(见的链接前)。

This trick is required as there is a HighMemory concept in Linux (see this link for ex.).

UPD:您可以使用 KMAP 而不是 kmap_atomic 在非原子上下文

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

这篇关于如何从结构页面获取相关数据的物理地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆