如何以编程方式获取Linux内核页面大小 [英] How to get linux kernel page size programmatically

查看:236
本文介绍了如何以编程方式获取Linux内核页面大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为IA64开发Linux模块.我当前的问题是驱动程序使用PAGE_SIZE和PAGE_SHIFT宏进行dma页面分配.我遇到的问题是,编译驱动程序的计算机不是运行该驱动程序所需的计算机.因此,如果编译器上的PAGE_SIZE为2 ^ 14K,而目标机器为2 ^ 16K,则驱动程序将失败.

I am working on a Linux module for IA64. My current problem is that the driver uses the PAGE_SIZE and PAGE_SHIFT macros for dma page allocation. The problem I am having is that the machine compiling the driver is not the ones that needed to run the driver. So, if the PAGE_SIZE on the compiling machine is 2^14K and the destination machine is 2^16K then the driver fails.

我不想将这个问题变成关于在不是运行模块的机器上编译模块的最佳实践"问题.我了解有关的问题.我发现人们通常使用getpagesize()或sysconf(_SC_PAGE_SIZE).这两个选项不在ia64内核标头中,因此我无法使用它们.还有其他方法可以获取运行时PAGE_SIZE吗?

I don't want to turn this question into a 'best practice' issue about compiling modules on machines which are not the ones running the modules. I understand the issues about that. What I found is that people mostly uses getpagesize() or sysconf(_SC_PAGE_SIZE). These two options are out of the ia64 kernel headers so I can't use them. Is there another way that I could get the runtime PAGE_SIZE?

我正在查看的选项:

  • 正在/proc中读取某些文件?
  • 系统调用?
  • 其他可以让我通过推断来计算PAGE_SIZE的函数(例如ORDER,getpageshift等)吗?
  • 其他?

推荐答案

这是我最终要做的:

  • 重新处理当前模块,以获取一个名为page_shift的新模块参数,并使用该参数来计算PAGE_SIZE (PAGE_SIZE = 1 << PAGE_SHIFT)
  • 创建了一个模块加载程序包装程序,该程序使用来自libc的getconf API获取当前系统PAGE_SHIFT.该包装器获取当前系统页面移位并将其作为模块参数传递.
  • Re-work my current module to take a new module parameter called page_shift and used that to calculate the PAGE_SIZE (PAGE_SIZE = 1 << PAGE_SHIFT)
  • Created a module loader wrapper which gets the current system PAGE_SHIFT using getconf API from libc. This wrapper gets the current system page shift and pass it as a module parameter.

现在,该模块已加载到具有不同PAGE_SIZE的不同体系结构上,没有任何问题.

Right now the module is being loaded on different architectures with different PAGE_SIZE without any problems.

这篇关于如何以编程方式获取Linux内核页面大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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