linux每个memory cgroup的lru链表是什么创建的 - 5.15内核

1.概述

对Linux memory子系统有基本了解的都知道,linux内核通过LRU管理物理内存,不知道是否有思考过如下问题:LRU是全局一套,还是说每个memory cgroup拥有单独的一套LRU链表直接揭晓答案:每个memory cgroup都会单独的LRU链表

2.怎么查到memcg对应的LRU链表

内核5.15可通过mem_cgroup_lruvec获得mem_cgroup对应的lru链表,函数定义在内核include/linux/memcontrol.h:

首先从memcg的nodeinfo中获取一个mem_cgroup_per_node指针 mz,mz中可以取到lruvec,所以关键就是分析memcg->nodeinfo是什么初始化的,答案是:这个memcg 创建的时候就需要初始化nodeinfo,而memcg初始化是在mem_cgroup_alloc函数中,所以接下来重点分析此函数。

3. memcg对应的LRU链表是什么时候初始化的
mem_cgroup_alloc --->alloc_mem_cgroup_per_node_info
 

 可以看到在cgroup创建的时候,调用到mem_cgroup_alloc,进而调用alloc_mem_cgroup_per_node_info,然后memcg->nodeinfo[node] = pn和lruvec_init(&pn->lruvec)初始化了一套LRU链表,然后使用的时候通过mem_cgroup_lruvec取到这里初始化的lruvec,lruvec就包含了inactive file/active file, inactive anon,active anon等各种LRU链表,数据结构如下:

/home/lhl/ga-4.1/repo_code/out/oriole/kernel/src_tmp/linux-5.15/mm/vmscan.c:431:13: error: static declaration of 'cgroup_reclaim' follows non-static declaration static bool cgroup_reclaim(struct scan_control *sc) ^ /home/lhl/ga-4.1/repo_code/out/oriole/kernel/src_tmp/linux-5.15/include/linux/swap.h:423:13: note: previous declaration is here extern bool cgroup_reclaim(struct scan_control *sc); ^ /home/lhl/ga-4.1/repo_code/out/oriole/kernel/src_tmp/linux-5.15/mm/vmscan.c:449:13: error: static declaration of 'writeback_throttling_sane' follows non-static declaration static bool writeback_throttling_sane(struct scan_control *sc) ^ /home/lhl/ga-4.1/repo_code/out/oriole/kernel/src_tmp/linux-5.15/include/linux/swap.h:427:13: note: previous declaration is here extern bool writeback_throttling_sane(struct scan_control *sc); ^ /home/lhl/ga-4.1/repo_code/out/oriole/kernel/src_tmp/linux-5.15/mm/vmscan.c:591:22: error: static declaration of 'lruvec_lru_size' follows non-static declaration static unsigned long lruvec_lru_size(struct lruvec *lruvec, enum lru_list lru, ^ /home/lhl/ga-4.1/repo_code/out/oriole/kernel/src_tmp/linux-5.15/include/linux/mmzone.h:1205:22: note: previous declaration is here extern unsigned long lruvec_lru_size(struct lruvec *lruvec, enum lru_list lru, int zone_idx); ^ /home/lhl/ga-4.1/repo_code/out/oriole/kernel/src_tmp/linux-5.15/mm/vmscan.c:891:22: error: static declaration of 'shrink_slab' follows non-static declaration static unsigned long shrink_slab(gfp_t gfp_mask, int nid, ^ /home/lhl/ga-4.1/repo_code/out/oriole/kernel/src_tmp/linux-5.15/include/linux/swap.h:425:22: note: previous declaration is here extern unsigned long shrink_slab(gfp_t gfp_mask, int nid, struct mem_cgroup *memcg, ^ /home/lhl/ga-4.1/repo_code/out/oriole/kernel/src_tmp/linux-5.15/mm/vmscan.c:2224:12: error: static declaration of 'current_may_throttle' follows non-static declaration static int current_may_throttle(void) ^ /home/lhl/ga-4.1/repo_code/out/oriole/kernel/src_tmp/linux-5.15/include/linux/swap.h:432:12: note: previous declaration is here extern int current_may_throttle(void); ^ /home/lhl/ga-4.1/repo_code/out/oriole/kernel/src_tmp/linux-5.15/mm/vmscan.c:2497:22: error: static declaration of 'shrink_list' follows non-static declaration static unsigned long shrink_list(enum lru_list lru, unsigned long nr_to_scan, ^ /home/lhl/ga-4.1/repo_code/out/oriole/kernel/src_tmp/linux-5.15/include/linux/swap.h:419:22: note: previous declaration is here extern unsigned long shrink_list(enum lru_list lru, unsigned long nr_to_scan, ^ /home/lhl/ga-4.1/repo_code/out/oriole/kernel/src_tmp/linux-5.15/mm/vmscan.c:2539:13: error: static declaration of 'inactive_is_low' follows non-static declaration static bool inactive_is_low(struct lruvec *lruvec, enum lru_list inactive_lru) ^ /home/lhl/ga-4.1/repo_code/out/oriole/kernel/src_tmp/linux-5.15/include/linux/swap.h:422:13: note: previous declaration is here extern bool inactive_is_low(struct lruvec *lruvec, enum lru_list inactive_lru); ^ /home/lhl/ga-4.1/repo_code/out/oriole/kernel/src_tmp/linux-5.15/mm/vmscan.c:4261:12: error: static declaration of 'kswapd' follows non-static declaration static int kswapd(void *p) ^ /home/lhl/ga-4.1/repo_code/out/oriole/kernel/src_tmp/linux-5.15/include/linux/swap.h:37:5: note: previous declaration is here int kswapd (void *p); ^
07-19
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值