Linux内核中的有关Page的算法
来源:互联网 发布:知牛财经 编辑:程序博客网 时间:2024/05/18 01:38
static inline int get_order(unsigned long size){int order;size = (size-1) >> (PAGE_SHIFT-1);order = -1;do {size >>= 1;order++;} while (size);return order;}
上面这个算法是从内核源代码摘抄下来的,其中PAGE_SHIFT是一个宏,定义的大小为12,这段代码的含义是
返回关联在当前平台的大小的分配级别, 根据 PAGE_SIZE. 这个参数必须是 2 的幂, 并且返回值至少是 0.
明白了这个原理,这个函数还可以改造成以下算法,求一个数是2的多少次幂。
static inline int get_order(unsigned long size){int order;size = (size-1) >> 0;order = -1;do {size >>= 1;order++;} while (size);return order;}于是可以写出下面的一个实例:
#include <stdio.h> #define PAGE_SHIFT 12static inline int get_order(unsigned long size){int order;size = (size-1) >> 0;order = -1;do {size >>= 1;order++;} while (size);return order;}int main(void){int ret = get_order(64);printf("ret:%d\n",ret);}
运行结果:5
0 0
- Linux内核中的有关Page的算法
- Linux内核中的随机数算法
- Linux内核中的调度算法
- 有关linux内核模块的开发
- 有关linux内核模块的开发
- linux 服务器网络有关的内核参数
- 有关Linux内核分析课程的总结
- 内核中的page fault & copy_from_user
- linux内核page结构体的PG_referenced和PG_active标志
- linux内核page结构体的PG_referenced和PG_active标志
- linux内核内核和进程有关的数据结构
- linux内核中的基本数据结构和算法
- Linux内核中的预取算法
- linux内核中的基本数据结构和算法
- Linux 内核的一些算法
- Linux 内核的一些算法
- 有关 Linux 下内核模块的开发方式的记录
- 有关 Linux 下内核模块的开发方式的记录 .
- Push failed Failed with error failed; result=22, HTTP code = 411
- 加载顺序为:context-param -> listener -> filter -> servlet
- ctags+taglist+cscope的安装以及常用快捷键
- 删除图片物理地址
- centos下安装python3.5.2
- Linux内核中的有关Page的算法
- springboot学习(一)认识springboot及创建第一个springboot项目
- 关于日期时间开发
- Spring AOP三种配置详细介绍
- ADO
- 移动手机开发meta注意问题
- HDU-3870-Catch the Theves
- PHP开发小技巧⑧—CURL请求
- Git stash