linux ps rss不等于总物理内存,关于进程的物理内存RSS

本文探讨了Linux环境下进程内存RSS的含义,指出其包括私有物理内存和共享内存,并解释了RSS在进程闲置时可能高估内存使用的原因。通过实例分析Oracle进程和SGA配置,强调了简单相加RSS可能不准确,特别是在SGA固定的情况下。
摘要由CSDN通过智能技术生成

通常习惯直接把ps里的RSS看做是进程使用的物理内存。

例如linux下ps的说明如下

rss        RSS      resident set size, the non-swapped physical memory that a task has used

(in kiloBytes). (alias rssize, rsz).

随便在笔记本虚机上看一个oracle进程,居然有30M之巨

[oracle@server2 ~]$ ps aux | head -n 1; ps aux | grep LOCAL=YES| grep -v grep

USER       PID %CPU %MEM    VSZ

RSS TTY      STAT START   TIME COMMAND

oracle    2295  0.0  1.6 856044

30764 ?        Ss   21:23   0:00 oracleorcl (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))

再比如这台惠普,有1823个远程连接。

SQL> !ps -ef| grep LOCAL=NO| wc -l

1823

glance里按RSS排序,直接看最后一页,最少都是200多兆,这么算起来400多G。

User      CPU %    Thrd Disk        Memory       Block

Process Name     PID     Name   (12800%max) Cnt  IOrate      RSS/VSS      On

--------------------------------------------------------------------------------

oraclePRODB2       17050 grid          0.0     1   0.0

226.5mb241.9mb SOCKT

oraclePRODB2        7029 grid          0.0     1   0.0

216.6mb  218.9mb SOCKT

oraclePRODB2       16306 grid          0.0     1   0.0

227.8mb239.3mb SOCKT

oraclePRODB2       17114 grid          0.1     1   0.0

224.3mb243.7mb SOCKT

oraclePRODB2       15957 grid          0.0     1   0.0

226.5mb240.2mb SOCKT

...

...

但是这台机器的

物理内存一个1T,

SGA就固定400G,现在用户进程只用了447G,因此按进程上的RSS简单相加肯定是不准的。

Event         Current   Cumulative   Current Rate   Cum Rate   High Rate

--------------------------------------------------------------------------------

Page Faults       858         4050       343.2      470.9       662.5

Page In             0            0         0.0        0.0       148.9

Page Out            0            0         0.0        0.0         0.0

KB Paged In       0kb          0kb         0.0        0.0         0.0

KB Paged Out      0kb          0kb         0.0        0.0         0.0

Reactivations       0            0         0.0        0.0         0.0

Deactivations       0            0         0.0        0.0         0.0

KB Deactivated    0kb          0kb         0.0        0.0         0.0

VM Reads            0            0         0.0        0.0         0.0

VM Writes           0            0         0.0        0.0         0.0

Total VM : 464.7gb   Sys Mem  : 104.9gb

User Mem: 447.8gb   Phys Mem :  1023gb

Active VM: 261.3gb   Buf Cache:     0mb   Free Mem: 455.8gb   FileCache:  14.5gb

MemFS Blk Cnt:                0   MemFS Swp Cnt:                0

以进程17050为例,glance里显示226.5m。查看pga实际分配了3M

SQL> select round(pga_alloc_mem/1024/1024, 2)||' (MB)' alloc_mb from v$process where spid = 17050;

ALLOC_MB

-----------------

3.09

(MB)

整个PGA一共也就分配了11G

SQL> select round(sum(pga_alloc_mem)/1024/1024/1024, 2)||' (GB)' sum_alloc_mb from v$process;

SUM_ALLOC_MB

---------------------------------------------

11.47

(GB)

于是查看glance里RSS的说明

On HP-UX, for processes that use CPU

time subsequent to midaemon startup,

the resident memory is calculated as

RSS = sum of private region pages

+

(sum of shared region pages /

number of references)

The number of references is a count

of the number of attachments to the

memory region.

Attachments, for

shared regions, may come from

several processes sharing the same

memory, a single process with

multiple attachments, or

combinations of these.

This value is only updated when a

process uses CPU.Thus, under

memory pressure, this value may be

higher than the actual amount of

resident memory for processes which

are idle

because their memory pages

may no longer be resident or the

reference count for shared segments

may have changed.

上面提到有两个原因会造成RSS显示远大于进程实际使用的内存

RSS除了进程私有物理内存之外,还要加上[它所使用的共享内存大小 / 所有正在使用这个共享内存的进程数]。

由于RSS只有在进程使用CPU时才更新,如果进程idle了,就再也不会更新,永远是那么大。

因此每个进程最少200多M,应该就是通过SGA的400000 / 1823 = 219 算出来的。

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/26239116/viewspace-1472417/,如需转载,请注明出处,否则将追究法律责任。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值