一种比较low的linux的hung分析
在调试一个功能的时候,发现了两种hung,以前认为的hung肯定是softlock导致的,后来才发现不一定要有lock这种结构,但是有类似于锁的功能的时候,也可能触发hung,为了避免大家走弯路,故记录之。
unsigned find_get_pages(struct address_space *mapping, pgoff_t start,
unsigned int nr_pages, struct page **pages)
{
struct radix_tree_iter iter;
void **slot;
unsigned ret = 0; if (unlikely(!nr_pages))
return 0; rcu_read_lock();
restart:
radix_tree_for_each_slot(slot, &mapping->page_tree, &iter, start) {
struct page *page;
repeat:
page = radix_tree_deref_slot(slot);
if (unlikely(!page))
continue; if (radix_tree_exception(page)) {
if (radix_tree_deref_retry(page)) {
/*
* Transient condition which can only trigger
* when entry at index 0 moves out of or back
* to root: none yet gotten, safe to restart.
*/
WARN_ON(iter.index);
goto restart;
}
/*
* A shadow entry of a recently evicted page,
* or a swap entry from shmem/tmpfs. Skip
* over it.
*/
continue;
} if (!page_cache_get_speculative(page))--------------------遇到过hung
goto repeat; /* Has the page moved? */
if (unlikely(page != *slot)) {
page_cache_release(page);
goto repeat;
} pages[ret] = page;
if (++ret == nr_pages)
break;
} rcu_read_unlock();
return ret;
}
为什么这里会hung呢,因为repeat之后,又会执行到page_cache_get_speculative 函数,而这个是判断page的计数是否为0,如果不为0,则原子加1,否则就repeat。
那一个page怎么会一直计数为0,而又在radix树中呢,所以接下来又判断,如果这个page被移除了,则说明树中对应的位置有新的page,则重新取page来做计数+1,但是我遇到的情况是,page的计数为0,同时,又没有被radix树移除,导致在 page_cache_get_speculative 函数就repeat 了,当然,这个是由于page的计数管理不当导致的,但是内核表现的情况确是hung 了。
还遇到过一次suse的hung,也是这个函数,当时我写的代码是:
unsigned caq_find_get_pages(struct address_space *mapping, pgoff_t start,pgoff_t end,
unsigned int nr_pages, struct page **pages,pgoff_t *indices)
{
unsigned int i;
unsigned int ret;
unsigned int nr_found, nr_skip;
unsigned int overrange=0; if (unlikely(!nr_pages)||(!pages)||(!indices))
return 0; rcu_read_lock();
restart:
nr_found = radix_tree_gang_lookup_slot(&mapping->page_tree,
(void ***)pages, indices, start, nr_pages);
ret = 0;
nr_skip = 0;
for (i = 0; i < nr_found; i++) {
struct page *page;
repeat:
page = radix_tree_deref_slot((void **)pages[i]);
if (unlikely(!page))
continue; if (radix_tree_exception(page)) {
if (radix_tree_exceptional_entry(page)) {
nr_skip++;
continue;
}
/*
* radix_tree_deref_retry(page):
* can only trigger when entry at index 0 moves out of
* or back to root: none yet gotten, safe to restart.
*/
WARN_ON(start | i);
goto restart;
} //added by caq for not find the count >2
if(atomic_read(&(page->_count))!=1)--------------------我增加的代码
continue; if (!page_cache_get_speculative(page))
goto repeat; /* Has the page moved? */
if (unlikely(page != *((void **)pages[i]))) {
page_cache_release(page);
goto repeat;
}
pages[ret] = page;//在此已经增加了计数了,
ret++;
if(page->index>=end)
{
overrange=1;
break;
}
} /*
* If all entries were removed before we could secure them,
* try again, because callers stop trying once 0 is returned.
*/
if (unlikely(!ret && nr_found > nr_skip && !overrange))
goto restart;
rcu_read_unlock();
return ret;
}
本来是想,不要找那些计数大于1的page,因为我需要拿这些page做一些特殊处理,结果,由于多个用户读同一个page,导致了循环无法退出,出现了hung。
一种比较low的linux的hung分析的更多相关文章
- 来聊一聊不low的Linux命令——find、grep、awk、sed
前几天面试,被一位面试官嫌弃了"你的Linux命令有点low".被嫌弃也挺正常的,因为我的简历写的我自己都有点看不下去:了解Linux常用命令,如ls,tail -f等命令,基本满 ...
- 4种用于构建嵌入式linux系统的工具_转
转自:4种用于构建嵌入式linux系统的工具 Linux 被部署到比 Linus Torvalds 在他的宿舍里开发时所预期的更广泛的设备.令人震惊的支持了各种芯片,使得Linux 可以应用于大大小小 ...
- 关于vector的erase删除操作的两种不同方法,在linux与visual studio的实现讨论
关于vector的erase删除操作的两种不同方法,在linux与visual studio的实现讨论 1.前言: 最近在做某一个题时,用到了vector的删除操作,利用的是erase()函数删除符合 ...
- linux系统瓶颈分析(精)
linux系统瓶颈分析(精) (2013-09-17 14:22:00) 分类: linux服务器瓶颈分析 1.0 性能监控介绍 性能优化就是找到系统处理中的瓶颈以及去除这些的过程,多数管理员相信 ...
- linux系统瓶颈分析(精) CPU Memory IO Network
linux系统瓶颈分析(精) linux系统瓶颈分析(精) (2013-09-17 14:22:00) 分类: linux服务器瓶颈分析 1.0 性能监控介绍性能优化就是找到系统处理中的瓶颈以及去 ...
- Linux网络地址转换分析
Linux网络地址转换分析 地址转换用来改变源/目的端口,是netfilter的一部分,也是通过hook点上注册相应的结构来工作. Nat注册的hook点和conntrack相同,只是优先级不同,数据 ...
- linux串口驱动分析
linux串口驱动分析 硬件资源及描写叙述 s3c2440A 通用异步接收器和发送器(UART)提供了三个独立的异步串行 I/O(SIO)port,每一个port都能够在中断模式或 DMA 模式下操作 ...
- Linux input子系统分析
输入输出是用户和产品交互的手段,因此输入驱动开发在Linux驱动开发中很常见.同时,input子系统的分层架构思想在Linux驱动设计中极具代表性和先进性,因此对Linux input子系统进行深入分 ...
- Linux下性能分析工具汇总
来自:http://os.51cto.com/art/201104/253114.htm 本文讲述的是:CPU性能分析工具.Memory性能分析工具.I/O性能分析工具.Network性能分析工具. ...
随机推荐
- [UE4]虚幻UE4 .uproject文件无关联 右键菜单少了
前一段时间因为一些事,重装系统 然后重新安装UE4跟VS ,突然发现...竟然之前的UE4原先的项目找不到了,然后用UE4打开就提示 “该文件没有与之关联的程序来执行该操作,请先安装一个程序... ...
- [UE4]虚幻4链接独立服务器
如果虚幻4只做客户端的话,应该怎么连接服务器呢? 官方并没有提供蓝图的网络函数,C++里面有. 一.自己实现,提供接口给蓝图使用. 二.第三方插件.插件下载地址:https://github.com/ ...
- VMware同时使用三种网络模式的虚拟机,测试连通性
参考资料: 虚拟机中桥接不自动分配IP与设置静态IP问题: https://blog.csdn.net/u013187057/article/details/80579211 腾讯课堂: https: ...
- [UE4][Canvas]用C++代码绘制血条(HealthBar)
转自:http://aigo.iteye.com/blog/2275110 参考自Epic官方项目StrategyGame 血条效果: StrategyHUD.h StrategyHUD.cpp
- 在线学习和在线凸优化(online learning and online convex optimization)—FTL算法5
最自然的学习规则是使用任何在过去回合中损失最小的向量. 这与Consistent算法的精神相同,它在在线凸优化中通常被称为Follow-The-Leader,最小化累积损失. 对于任何t: 我们谈到了 ...
- linux驱动开发—基于Device tree机制的驱动编写
前言Device Tree是一种用来描述硬件的数据结构,类似板级描述语言,起源于OpenFirmware(OF).在目前广泛使用的Linux kernel 2.6.x版本中,对于不同平台.不同硬件,往 ...
- U3D学习09-物体简单控制及视角观察
一.Character Control非刚体 1.场景初始化,注意调整CC的轴心,不需要碰撞,且删除CC子物体的碰撞.2.移动: 获取X,Z轴变化,定义变量h,v: 定义移动 ...
- RxJava学习;数据转换、线程切换;
Observable(被观察者,发射器)发送数据: just:发送单个的数据: Observable.just("cui","chen","bo&qu ...
- mogoDB工具选择及连接<一>
最近在某微服务项目中需要用到mogoDB 原因是:开源免费.适合互联网公司.大数据量情况下性能比mysql好 咨询过为啥不用oracle,原因你懂得 --费用 好,言归正传: 1.选择工具,使用工具是 ...
- 【Git使用】SourceTree可视化工具的安装和使用攻略
1,下载并安装 sourceTree http://downloads.atlassian.com/software/sourcetree/windows/SourceTreeSetup_1.6.14 ...