在调试一个功能的时候,发现了两种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分析的更多相关文章

  1. 来聊一聊不low的Linux命令——find、grep、awk、sed

    前几天面试,被一位面试官嫌弃了"你的Linux命令有点low".被嫌弃也挺正常的,因为我的简历写的我自己都有点看不下去:了解Linux常用命令,如ls,tail -f等命令,基本满 ...

  2. 4种用于构建嵌入式linux系统的工具_转

    转自:4种用于构建嵌入式linux系统的工具 Linux 被部署到比 Linus Torvalds 在他的宿舍里开发时所预期的更广泛的设备.令人震惊的支持了各种芯片,使得Linux 可以应用于大大小小 ...

  3. 关于vector的erase删除操作的两种不同方法,在linux与visual studio的实现讨论

    关于vector的erase删除操作的两种不同方法,在linux与visual studio的实现讨论 1.前言: 最近在做某一个题时,用到了vector的删除操作,利用的是erase()函数删除符合 ...

  4. linux系统瓶颈分析(精)

    linux系统瓶颈分析(精) (2013-09-17 14:22:00)   分类: linux服务器瓶颈分析 1.0 性能监控介绍 性能优化就是找到系统处理中的瓶颈以及去除这些的过程,多数管理员相信 ...

  5. linux系统瓶颈分析(精) CPU Memory IO Network

    linux系统瓶颈分析(精) linux系统瓶颈分析(精) (2013-09-17 14:22:00)   分类: linux服务器瓶颈分析 1.0 性能监控介绍性能优化就是找到系统处理中的瓶颈以及去 ...

  6. Linux网络地址转换分析

    Linux网络地址转换分析 地址转换用来改变源/目的端口,是netfilter的一部分,也是通过hook点上注册相应的结构来工作. Nat注册的hook点和conntrack相同,只是优先级不同,数据 ...

  7. linux串口驱动分析

    linux串口驱动分析 硬件资源及描写叙述 s3c2440A 通用异步接收器和发送器(UART)提供了三个独立的异步串行 I/O(SIO)port,每一个port都能够在中断模式或 DMA 模式下操作 ...

  8. Linux input子系统分析

    输入输出是用户和产品交互的手段,因此输入驱动开发在Linux驱动开发中很常见.同时,input子系统的分层架构思想在Linux驱动设计中极具代表性和先进性,因此对Linux input子系统进行深入分 ...

  9. Linux下性能分析工具汇总

    来自:http://os.51cto.com/art/201104/253114.htm 本文讲述的是:CPU性能分析工具.Memory性能分析工具.I/O性能分析工具.Network性能分析工具. ...

随机推荐

  1. 0000 - Spring 中常用注解原理剖析

    1.概述 Spring 框架核心组件之一是 IOC,IOC 则管理 Bean 的创建和 Bean 之间的依赖注入,对于 Bean 的创建可以通过在 XML 里面使用 <bean/> 标签来 ...

  2. UE4如何检测目标在锥形视野内

    转自:http://blog.csdn.net/l346242498/article/details/70237083 做UE4游戏AI方面经常会遇到一个问题,就是何如判定目标在AI单位的视野范围内, ...

  3. linux下的网络通信设置:openssh、PuTTY、tightVNC

    OpenSSH的安装: windows上安装PuTTY:  PuZZY上传文件到linux: 1.在window下的cmd中cd到PuZZY所在的文件夹下 2.使用pscp命令上传文件 3.使用psc ...

  4. servlet和jsp概述

    1.servlet的作用 B/S系统:浏览器/服务器(Servlet的服务模式) Servlet是运行在web服务器或应用服务器上的java程序,它是一个中间层,负责连接来自web浏览器或其它HTTP ...

  5. Call to undefined function think\finfo_open()

    Fileinfo 扩展 - Linux面板- 宝塔面板 上传文件,出现错误 安装的fileinfo扩展

  6. php数组和部分操作函数

    1. 数组定义 数组的定义使用 array()方式定义,可以定义空数组: <?php $number = array(1,3,5,7,9); //定义空数组 $result = array(); ...

  7. Codeforces Round #492 (Div. 2)

    A. /* 从大往小依次除 */ #include<cstdio> #include<algorithm> #include<cstring> #include&l ...

  8. 04-spark streaming

    1.基本概念(了解) ①流(Streaming): 是一种数据传送技术,它把客户机收到的数据变成一个稳定连续的流,源源不断地送出,使用户听到的声音或看到的图象十分平稳, 而且用户在整个文件送完之前就可 ...

  9. Linux之文档与目录结构 (/ 用法, 相对路径,绝对路径)

    Linux之文档与目录结构   Linux文件系统结构 Linux目录结构的组织形式和Windows有很大的不同.首先Linux没有“盘(C盘.D盘.E盘)”的概念.已经建立文件系统的硬盘分区被挂载到 ...

  10. C#打印0到100的素数

    static void Main(string[] args) { //输出1-100的素数 bool res; ; ; i < ; i++) { res = true; ; j < i; ...