免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 10592 | 回复: 14
打印 上一主题 下一主题

solaris 10 kernel 内存占用为什么这么高?请各位大侠帮忙看看! [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-11-05 16:55 |只看该作者 |倒序浏览
mdb -k
(B)0Loading modules: [ unix genunix specfs dtrace ufs sd mpt px ssd fcp fctl md ip hook neti sctp arp nca zfs cpc random crypto fcip logindmux ptm sppp nfs ipc ]
>
>  ::memstat
Page Summary                Pages                MB  %Tot
------------     ----------------  ----------------  ----
Kernel                    4011602             31340   97%
Anon                        48512               379    1%
Exec and libs                2367                18    0%
Page cache                  21384               167    1%
Free (cachelist)            15625               122    0%
Free (freelist)             18116               141    0%

Total                     4117606             32168
Physical                  4096063             32000
>

论坛徽章:
20
申猴
日期:2013-09-12 19:39:05狮子座
日期:2014-07-20 21:19:51寅虎
日期:2014-08-16 18:37:47水瓶座
日期:2014-10-15 18:58:25天蝎座
日期:2015-01-22 18:19:15NBA常规赛纪念章
日期:2015-05-04 22:32:032015亚冠之胡齐斯坦钢铁
日期:2015-06-03 11:28:502015亚冠之吉达阿赫利
日期:2015-09-19 12:41:47午马
日期:2013-09-18 14:36:40戌狗
日期:2013-09-18 14:44:39处女座
日期:2013-09-24 17:46:41CU十二周年纪念徽章
日期:2013-10-24 15:41:34
2 [报告]
发表于 2012-11-06 12:33 |只看该作者
kernel太高深了

论坛徽章:
0
3 [报告]
发表于 2012-11-06 15:12 |只看该作者
楼主使用了zfs文件系统,默认情况下,zfs会使用内存占用当着文件缓存。

发现一台使用了zfs的主机,Kernel 占用了大量的物理内存内存,使得剩余的物理内存只有1G,经过分析后,确认是
zfs的默认设置导致,solaris 10如果不设置zfs:zfs_arc_max 参数,那么zfs就会占用大量物理内存做cashe,知道内存剩下到1G。下面介绍了这个参数的设置:


这篇文章介绍如何降低ZFS占用的kernel内存!
很多Oracle 数据库运行在Solaris 上,作为这类服务器系统的管理员,您是否遇到过以下情况:假设你的系统有16G内存,系统启动后并没有运行什么大型程序,但是当你运行vmstat(或者系统中安装了top)时显示的空闲却内存只有200MB。当你试图启动配置了较大SGA的Oracle数据库时因为无法分配所需的内存而失败。

我想你一定会尖叫,内存都哪去了?

让我们来看一个真实的案例在一台具有16G内存的SUN服务器上运行如下命令:

# echo "::memstat" | mdb -k
Page Summary Pages MB %Tot
------------ ---------------- ---------------- ----
Kernel 1717128 13415 83%
Anon 238964 1866 12%
Exec and libs 23450 183 1%
Page cache 19039 148 1%
Free (cachelist) 19243 150 1%
Free (freelist) 40453 316 2%

Total 2058277 16080
Physical 2054336 16049
内核占用了13GB内存??没错!自从ZFS被引入Solaris 10 ,大家多数使用的是系统默认的ZFS ARC(adaptive replacement cache)设置,正是这一默认设置,导致内核模块中的ZFS ARC占用了大量的内存。

很早以前当我们第一次遇到这一问题时,我们必须在系统启动时使用mdb来设定ARC参数,而不能仅仅通过在/etc/system文件中作一些设定来解决。但是,您不用抱怨太多,因为这一问题现在很容易进行修正。

什么是 ZFS ARC?简单的说,它是被ZFS用告诉缓存的一块内存区域。默认设定下,ZFS ARC最大可以增长到 总内存容量-1G的大小。问题是,当用户空间的应用程序请求分配内存时,ZFS ARC所占用的内存会被相应释放,但实际中内存释放过程往往不够迅速。另外,内存碎片对SHM(Oracle SGA的一部分)来讲是非常严重的问题。

通常,我会保留2GB内存给OS 和其他一些应用程序。如果运行 Oracle 和/或者 Sun App Server,我还会流出SGA和/或 java池。加在一起,我们假设总共需要4G内存不被ZFS占用,如果你的实际内存为8G,那么你需要将ARC 的最大大小设为4G。

如果你不运行Oralce之类的程序,只是在你的机器上运行1个图形桌面或Sunray Server ,需要保留2GB内存不被ZFS占用,并且你总共只有4GB内存,那么就将ARC的最大大小设为2GB。

如何设定ARC的最大大小?当前较新版本的solaris 10系统中您只需编辑/etc/system 文件添加以下设定:

* Restrict ZFS ARC to 8GB
set zfs:zfs_arc_max = 8000000000
我在设定时使用8000000000 ,这实际上< 8GB,但是相对1024x1024x1024的结果来说读起来更方便。

您可以更具实际情况设定ZFS RAC的最大值。保存设定后需要重新启动系统使设定生效。

系统重新启动后,您可以执行kstat -m zfs来验证此设定更改。

# kstat -m zfs
module: zfs instance: 0
name: arcstats class: misc
c 8000000000
c_max 8000000000
c_min 1000000000

论坛徽章:
0
4 [报告]
发表于 2012-11-06 15:13 |只看该作者
How Solaris ZFS Cache Management Differs From UFS and VXFS File Systems [ID 1005367.1]

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

  修改时间 18-OCT-2011     类型 HOWTO     移植的 ID 207481     状态 PUBLISHED   


Applies to:
Solaris SPARC Operating System - Version: 10 3/05 and later   [Release: 10.0 and later ]
All Platforms

Goal
ZFS manages cache differently than other file systems such as: ufs and vxfs. ZFS use of kernel memory as a cache resulted in higher kernel memory allocation as compared to ufs and vxfs file systems. Monitoring a system with tools such as vmstat would report less free memory with ZFS and may lead to unnecessary support calls.
Solution
This is due to how ZFS cache management is different from ufs and vxfs file system.
ZFS does not use the page cache like other file systems such as vxfs and ufs. ZFS's caching is drastically different from these old file systems where cached pages can be moved to the cache list, after being written to the backing store, and thus counted as free memory.
ZFS effects the VM subsystem in terms of memory management. Monitoring of systems with vmstat(1M) and prstat(1M) would report less free memory when ZFS is used heavily ie, copying large file(s) into ZFS file system. Same load running on ufs file system would use less memory since pages that are written to backing store will be moved into a cache list and counted as free memory.

ZFS uses a significantly different caching model than page-based file systems like ufs and vxfs. This is done for both performance and architectural reasons.
This may impact existing application software (like oracle that likes to consume large amount of memory). There is a work being done to improve the interface with the VM subsystem so that it can recover memory from ZFS cache when necessary.

The primary ZFS cache is an Adjustable Replacement Cache (ARC) that is built on top of a number of kmem_cache's: zio_buf_512 thru zio_buf_131072 (+ hdr_cache and buf_cache). These kmem caches are used for holding data blocks (ZFS uses variable block sizes: 512 to128K). The ARC will be at least 64MB and can use maximum of 75% of physical memory. So with Zfs, reported freemem will be lower.

ZFS returns memory in ARC only when there is a memory pressure. It is a different behaviour than pre Solaris 8 (pre priority paging) where reading or writing one large (GBs) file can lead to memory shortage and that leads to paging/swaping of application page. That result in slow application performance and restart. The old problem was due to failure to distinguish between a useful application page and an file system cached page. See knowledge article 1003383.1

ZFS frees up it's cache in a way that does not cause memory shortage. System can operate with lower freemem fine without actually suffer from this. ZFS unlike ufs and vxfs file systems does not throttle writers. Ufs file system, throttles writes when number of dirty pages/vnode reaches 16MB. The objective is to preserve free memory. The downside is slow application write performance that may be unnecessary when plenty of free memory is available. ZFS does not throttled individual application like ufs and vxfs. ZFS only throttles the application when data load over flows the IO subsystem capacity for 5 to 10 second.

However there are occasions when ZFS fails to evict ARC cache quickly and leads to application startup failure due to memory shortage. Also, reaping of memory from ARC can trigger high system utilization at the expense of performance. This issue is addressed in bug:

<Defect 6505658> - target MRU size (arc.p) needs to be adjusted more aggressively

Workaround is to limit the ZFS arc cache by setting:

set zfs:zfs_arc_max

in /etc/system file. For databases, we know in advance, how much memory all databases will consume. Limit ZFS's ARC cache to remaining free memory (and possibly reduce it even more by 2-3x factor) by setting zfs_arc_max tunable to desired value.

This tunable is available in Solaris 10 8/07 (Update 4)  KU 120011-14 installed along with fix for <Defect 6505658>.



Relief/Workaround

For Solaris 10 releases prior to 8/07 (Update 4) or without KU 120011-14 installed a script is provided in the <Defect 6505658>.


ZFS Best Practices Guide:

The ZFS adaptive replacement cache (ARC) tries to use most of a system's
available memory to cache file system data. The default is to use all of
physical memory except 1 Gbyte. As memory pressure increases, the ARC
relinquishes memory.

Consider limiting the maximum ARC memory footprint in the following
situations:

When a known amount of memory is always required by an application. Databases often fall into this category.
On platforms that support dynamic reconfiguration of memory
boards, to prevent ZFS from growing the kernel cage onto all boards.
A system that requires large memory pages might also benefit from
limiting the ZFS cache, which tends to breakdown large pages into base
pages.
Finally, if the system is running another non-ZFS file system, in
addition to ZFS, it is advisable to leave some free memory to host that
other file system's caches.
The trade off is that limiting this memory footprint means that the ARC is unable to cache as much file system data, and this limit could impact performance. In general, limiting the ARC is wasteful if the memory that now goes unused by ZFS is also unused by other system components. Note that non-ZFS file systems typically manage to cache data in what is nevertheless reported as free memory by the system.

论坛徽章:
4
申猴
日期:2013-08-28 13:29:09天秤座
日期:2013-12-31 16:54:51技术图书徽章
日期:2014-03-31 10:00:412015亚冠之北京国安
日期:2015-10-08 16:19:12
5 [报告]
发表于 2012-11-06 16:42 |只看该作者
二楼好强啊,顶。

论坛徽章:
0
6 [报告]
发表于 2012-11-07 22:00 |只看该作者
我是3楼。。。
回复 5# kwtip


   

论坛徽章:
0
7 [报告]
发表于 2012-11-08 08:50 |只看该作者
回复 6# ibmlenovo

你的意思是告诉他你也很强。。。


   

论坛徽章:
0
8 [报告]
发表于 2012-11-08 11:39 |只看该作者
回复 7# wait空白


怎么了?不能太谦虚

   

论坛徽章:
0
9 [报告]
发表于 2012-11-09 09:49 |只看该作者
回复 8# ibmlenovo


对。这种场合,你不能太谦虚。


   

论坛徽章:
7
双子座
日期:2013-09-09 15:55:31CU大牛徽章
日期:2013-09-18 15:22:06CU大牛徽章
日期:2013-09-18 15:22:20CU大牛徽章
日期:2013-09-18 15:22:26CU大牛徽章
日期:2013-09-18 15:22:31CU大牛徽章
日期:2013-09-18 15:22:37CU大牛徽章
日期:2013-09-18 15:22:46
10 [报告]
发表于 2012-11-09 15:03 |只看该作者
ZFS Best Practices Guide不错,google,收藏了~~THX3楼
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP