Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
给定一个系统支持一定的 X-KB 页面大小(2 的幂),并且我有一定数量的字节 Y-Bytes(可能或可能不是 X 的倍数)。是否有一个宏可以为我提供相当于 Y-Bytes 的页数的“上限”?
谢谢,vj
不知道有没有这样的宏。但是您可以使用 asm/page.h PAGE_SIZE 和 PAGE_SHIFT 定义轻松编写自己的代码。
NUM_PAGES(y) ((y + PAGE_SIZE - 1) >> PAGE_SHIFT)
或者
NUM_PAGES(y) ((y + PAGE_SIZE - 1) / PAGE_SIZE)