- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
为什么返回 unsigned long?为什么不是 void* 或 char*?
unsigned long __get_free_pages(unsigned int gfp_mask, unsigned int order)
我猜它会返回一个地址,还是我完全误解了该函数?
最佳答案
你更正了,它返回分配的第一页的第一个字节的内存地址。有趣的是 __get_free_pages()
内部使用的 page_address()
实际上返回 void*
。
这样做的原因可以在 LDD3, chapter 11 (PDF) 中找到:
Although you must be careful when mixing different data types, sometimes there are good reasons to do so. One such situation is for memory addresses, which are special as far as the kernel is concerned. Although, conceptually, addresses are pointers, memory administration is often better accomplished by using an unsigned integer type; the kernel treats physical memory like a huge array, and a memory address is just an index into the array. Furthermore, a pointer is easily dereferenced; when dealing directly with memory addresses, you almost never want to dereference them in this manner. Using an integer type prevents this dereferencing, thus avoiding bugs. Therefore, generic memory addresses in the kernel are usually unsigned long, exploiting the fact that pointers and long integers are always the same size, at least on all the platforms currently supported by Linux.
关于kernel - __get_free_pages 的奇怪返回类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28710083/
为什么返回 unsigned long?为什么不是 void* 或 char*? unsigned long __get_free_pages(unsigned int gfp_mask, unsig
假设调用__get_free_page 以向内核请求ZONE_NORMAL 区域中的空闲页面,因此带有GFP_KERNEL 标志。我们知道返回的地址是一个内核逻辑地址,所以在页表中存在一个“永久”映射
我基本上想知道这两件事 kmalloc 是如何工作的,我的意思是 kmalloc 调用哪个函数来分配内存,是 alloc_pages() 还是 __ger_free_pages()。 为什么为什么不能
我的系统内存充足(一台 24GB 的服务器)。在我的系统中,内核空间被分配了 320MB 和 120MB 用于崩溃内核。剩余的内存用于其他目的。但是,当我使用 __get_free_pages() 分
我是一名优秀的程序员,十分优秀!