标签:atom 源码 rss 防止 通过 UI exp 包含 blog
原链接:http://blog.chinaunix.net/uid-12693781-id-368837.html
/* Variables and functions for calc_load */ static atomic_long_t calc_load_tasks; static unsigned long calc_load_update; unsigned long avenrun[3]; EXPORT_SYMBOL(avenrun); /** * get_avenrun - get the load average array * @loads: pointer to dest load array * @offset: offset to add * @shift: shift count to shift the result left * * These values are estimates at best, so no need for locking. */ void get_avenrun(unsigned long *loads, unsigned long offset, int shift) { loads[0] = (avenrun[0] + offset) << shift; loads[1] = (avenrun[1] + offset) << shift; loads[2] = (avenrun[2] + offset) << shift; } static unsigned long calc_load(unsigned long load, unsigned long exp, unsigned long active) { load *= exp; load += active * (FIXED_1 - exp); return load >> FSHIFT; } /* * calc_load - update the avenrun load estimates 10 ticks after the * CPUs have updated calc_load_tasks. */ void calc_global_load(void) { unsigned long upd = calc_load_update + 10; long active; if (time_before(jiffies, upd)) return; active = atomic_long_read(&calc_load_tasks); active = active > 0 ? active * FIXED_1 : 0; avenrun[0] = calc_load(avenrun[0], EXP_1, active); avenrun[1] = calc_load(avenrun[1], EXP_5, active); avenrun[2] = calc_load(avenrun[2], EXP_15, active); calc_load_update += LOAD_FREQ; } /* * Either called from update_cpu_load() or from a cpu going idle */ static void calc_load_account_active(struct rq *this_rq) { long nr_active, delta; nr_active = this_rq->nr_running; //记录在cpu上运行的进程数 nr_active += (long) this_rq->nr_uninterruptible; //记录不可中断的进程数 if (nr_active != this_rq->calc_load_active) { delta = nr_active - this_rq->calc_load_active; this_rq->calc_load_active = nr_active; atomic_long_add(delta, &calc_load_tasks); } }
#ps aux可以显示进程的运行状态 USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
=================进程STAT状态==================== D 无法中断的休眠状态(通常 IO 的进程) R 正在运行,在可中断队列中; S 处于休眠状态,静止状态; T 停止或被追踪,暂停执行; W 进入内存交换(从内核2.6开始无效); X 死掉的进程; Z 僵尸进程不存在但暂时无法消除; W: 没有足够的记忆体分页可分配 WCHAN 正在等待的进程资源; <:高优先级进程 N: 低优先序进程 L: 有记忆体分页分配并锁在记忆体内 (即时系统或捱A I/O),即,有些页被锁进内存 s 进程的领导者(在它之下有子进程); l 多进程的(使用 CLONE_THREAD, 类似 NPTL pthreads); + 位于后台的进程组;
server1:~$ est 467 connections established
root 2631 0.2 0.0 0 0 ? D Jul20 50:28 [nfsd] root 2632 0.2 0.0 0 0 ? D Jul20 49:24 [nfsd] root 2633 0.2 0.0 0 0 ? S Jul20 49:27 [nfsd] root 2634 0.2 0.0 0 0 ? S Jul20 49:47 [nfsd] root 2635 0.2 0.0 0 0 ? S Jul20 51:12 [nfsd] root 2636 0.2 0.0 0 0 ? S Jul20 49:00 [nfsd] root 2637 0.2 0.0 0 0 ? S Jul20 49:39 [nfsd] root 2638 0.2 0.0 0 0 ? D Jul20 50:24 [nfsd]
server1:~$ top top - 16:13:12 up 14 days, 21:21, 2 users, load average: 180.20, 59.85, 22.61 Tasks: 125 total, 1 running, 124 sleeping, 0 stopped, 0 zombie Cpu : 2.3%us, 1.3%sy, 0.0%ni, 0.0%id, 95.8%wa, 0.0%hi, 0.5%si, 0.0%st Mem: 2076212k total, 2028752k used, 47460k free, 1804k buffers Swap: 2104472k total, 1089140k used, 1015332k free, 244076k cached
标签:atom 源码 rss 防止 通过 UI exp 包含 blog
原文地址:https://www.cnblogs.com/jenkov/p/cpu_load.html