文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>Squid 开启大内存导致进程内存溢出的解决

Squid 开启大内存导致进程内存溢出的解决

时间:2010-05-26  来源:dafeng1113

FreeBsd 6.2 下 Squid 开启大内存导致进程内存溢出的解决

(2007-05-19 17:24:11)
  分类:Web浪人研究院
 有一台 Freebsd 6.2 的服务器, 跑Squid服务,经常在启动不久之后,就会出现 xcalloc: Unable to allocate 1 blocks of 4108 bytes! 错误信息,大致是指Squid申请内存错误。   在 Squid FAQ 中找到

Messages like "FATAL: xcalloc: Unable to allocate 4096 blocks of 1 bytes!" appear when Squid can't allocate more memory, and on most operating systems (inclusive BSD) there are only two possible reasons:

    * The machine is out of swap
    * The process' maximum data segment size has been reached

The first case is detected using the normal swap monitoring tools available on the platform (pstat on SunOS, perhaps pstat is used on BSD as well).

To tell if it is the second case, first rule out the first case and then monitor the size of the Squid process. If it dies at a certain size with plenty of swap left then the max data segment size is reached without no doubts.

The data segment size can be limited by two factors:

    * Kernel imposed maximum, which no user can go above
    * The size set with ulimit, which the user can control.

When squid starts it sets data and file ulimit's to the hard level. If you manually tune ulimit before starting Squid make sure that you set the hard limit and not only the soft limit (the default operation of ulimit is to only change the soft limit). root is allowed to raise the soft limit above the hard limit.

 

文中指出,导致 Squid在 Freebsd下跑起来内存溢出有两种情况:

1、系统的交换分区 Swap分区不够用。

2、进程申请的最大内存受到限制。

 

该服务器有4G内存,开启了高达8G Swap,明显第一个原因是不对。

 

然后用top 观察Squid运行状态,发现Squid在跑超过512M内存的时候,就自动退出了,而Squid设置的是1280M的内存参数。

 

用 ulimit -a 查看系统参数,发现单进程的内存占用数被限制在了512M

data seg size (kbytes, -d) 524288

 

在后面通过 ulimt -d 2097152 和 ulimit -Hd 进行强制设置并不成功。

 

继续翻阅Google上的资料,在一个台湾网友那里找到了设置的方法。

 

kern.maxdsiz="2G"

添加到

/boot/loader.conf

(中间尝试添加到 /etc/sysctl.conf 重启后不成功)

 

重新启动服务器,再运行 ulimit -a

data seg size           (kbytes, -d) 2097152

 

发现已经被强制改到2G的单线程内存申请最大值了。

 

然后重新运行Squid,观察半个小时,系统运行稳定。

相关阅读 更多 +
排行榜 更多 +
瓢虫少女

瓢虫少女

飞行射击 下载
潜艇鱼雷

潜艇鱼雷

飞行射击 下载
网络掠夺者

网络掠夺者

飞行射击 下载