Linux内存碎片率的实现方式

最近看到一个patch,当系统free内存碎片率较高时,通过计算当前系统的内存碎片率来启动lmk来杀进程,以达到释放内存的目的。内存碎片率的概念是相对某个size的连续free内存块而言的,其值从0~1000,值越大,说明内存碎片率越高。

内存碎片率的计算函数位于vmstat.c的函数中,具体如下:

int fragmentation_index(struct zone *zone, unsigned int order)
{
	struct contig_page_info info;

	fill_contig_page_info(zone, order, &info);//初始化当前zone下的contig_page_info结构体
	return __fragmentation_index(order, &info);//计算当前zone相对于某个order下的内存碎片率
}

主要涉及到2个函数fill_contig_page_info()和__fragmentation_index():

static void fill_contig_page_info(struct zone *zone,
				unsigned int suitable_order,
				struct contig_page_info *info)
{
	unsigned int order;

	info->free_pages = 0;//当前zone下的free page个数
	info->free_blocks_total = 0;//当前zone下free page block的个数,反映在buddyinfo里面就是每个order值的下的block个数相加
	info->free_blocks_suitable = 0;//相对于suitable_order而言,当前zone
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值