概述
MGLRU作为全新的LRU算法尤其独特之处,但是传统LRU算法中涉及的很多问题,MGLRU算法依然也要面对,比如本文即将讨论的在回收内存的时候,到底应该是回收anon 还是 file page,前面我们有一篇文章专门介绍了传统lru算法的策略和实现方式,可以作为参考和对比,看看两种回收方式的差异点:Linux 回收内存到底怎么计算anon/file回收比例,只是swappiness这么简单?-优快云博客
由于当下时间点mglru全网分析的基本为0,这种问题只能去研究mglru的源码,接下来我们直接通过源码分析其实现方式:
源码实现
vmscan.c:
shrink_lruvec
--->lru_gen_shrink_lruvec
--->evict_folios
--->isolate_folios
--->get_type_to_scan
static int get_type_to_scan(struct lruvec *lruvec, int swappiness, int *tier_idx)
{
int type, tier;
struct ctrl_pos sp, pv;
int gain[ANON_AND_FILE] = { swappiness, 200 - swappiness };
/*
* Compare the first tier of anon with that of file to determine which
* type to scan. Also need to compare other tiers of the selected type
* with t

本文探讨MGLRU算法在内存回收时如何决定回收anon还是file页面。MGLRU仅在最老一代区分anon和file,回收选择基于swappiness和workingset计算的refault概率,采用PID控制算法。详细分析了源码中的get_type_to_scan函数及其背后的统计机制。
最低0.47元/天 解锁文章
785

被折叠的 条评论
为什么被折叠?



