Redian新闻
>
哪位在Linux上用C++碰到过memory fragmentation吗?
avatar
哪位在Linux上用C++碰到过memory fragmentation吗?# Programming - 葵花宝典
l*u
1
碰到一个问题,一个C++写的server,run了一天后,用top看占了1.5G,在它想再分配
一块500M的heap时,就out of memory了。
同样的程序,在另一个server上run了一天后,却只占300M,也没有out of memory的问
题。
本人怀疑是memory fragmentation。因为如果是memory leak的话,不管在哪个server
上都会有memory leak。可能两个server的kernel不一样(虽然都是RHEL3),导致只在一
个server有memory fragmentation?
哪位有这方面经验的能分享一下吗?
avatar
g*g
2
profile it, no better way.

server

【在 l******u 的大作中提到】
: 碰到一个问题,一个C++写的server,run了一天后,用top看占了1.5G,在它想再分配
: 一块500M的heap时,就out of memory了。
: 同样的程序,在另一个server上run了一天后,却只占300M,也没有out of memory的问
: 题。
: 本人怀疑是memory fragmentation。因为如果是memory leak的话,不管在哪个server
: 上都会有memory leak。可能两个server的kernel不一样(虽然都是RHEL3),导致只在一
: 个server有memory fragmentation?
: 哪位有这方面经验的能分享一下吗?

avatar
t*t
3
用valgrind跑跑看, 就是慢了点

server

【在 l******u 的大作中提到】
: 碰到一个问题,一个C++写的server,run了一天后,用top看占了1.5G,在它想再分配
: 一块500M的heap时,就out of memory了。
: 同样的程序,在另一个server上run了一天后,却只占300M,也没有out of memory的问
: 题。
: 本人怀疑是memory fragmentation。因为如果是memory leak的话,不管在哪个server
: 上都会有memory leak。可能两个server的kernel不一样(虽然都是RHEL3),导致只在一
: 个server有memory fragmentation?
: 哪位有这方面经验的能分享一下吗?

avatar
c*m
4
u hv mem leak. mem frag != 1.5G footprint, but == unable to alloc large
chunk.
alloc 500m then other svr u should at least take up >300m. why alloc such
huge size? maybe u should pre-alloc huge mem and self manage, and use
another heap for small allocs and then no frags.
avatar
c*m
5
r u sure its mem usage is 1.5G, not virt size? if 1.5G is virt size then
yes, u more likely hv mem frag.
avatar
t*t
6
actually, glibc default behaviour is to allocate large chunk separately by
mmap.

【在 c**m 的大作中提到】
: u hv mem leak. mem frag != 1.5G footprint, but == unable to alloc large
: chunk.
: alloc 500m then other svr u should at least take up >300m. why alloc such
: huge size? maybe u should pre-alloc huge mem and self manage, and use
: another heap for small allocs and then no frags.

avatar
c*m
7
but if he's frag'ing, then system's i14n may not meet his specific alloc
pattern.
avatar
l*u
8
1.5G is what the columns "SIZE" and "RSS" of the "top" command show.
I need to allocate buffers for incoming socket messages, some of them could
be huge.
The reason I suspect it is memory fragmentation is that the "out of memory"
error:
1) does not always happen on server A, only once every 5-6 days.
2) does not happen on server B at all, even though the cod base and input
are identical.
3) only happens for the largest 1-2 messages. Even after it happened,
small messages still work.
When

【在 c**m 的大作中提到】
: r u sure its mem usage is 1.5G, not virt size? if 1.5G is virt size then
: yes, u more likely hv mem frag.

avatar
c*m
9
I am guessing that when you say "socket messages", you mean your own
application message because buffers for sockets are measured in Ks, not Ms.
So you received huge data through socket and stored them in one chunk of
memory that could be 500M. Without knowing the nature of your application,
my guess is you should process your data and if possible store them to
secondary storage. If your footprint grows to significantly larger than
anticipated my money is on memory leak. I remember that I use

【在 l******u 的大作中提到】
: 1.5G is what the columns "SIZE" and "RSS" of the "top" command show.
: I need to allocate buffers for incoming socket messages, some of them could
: be huge.
: The reason I suspect it is memory fragmentation is that the "out of memory"
: error:
: 1) does not always happen on server A, only once every 5-6 days.
: 2) does not happen on server B at all, even though the cod base and input
: are identical.
: 3) only happens for the largest 1-2 messages. Even after it happened,
: small messages still work.

avatar
l*u
10
The app is to send requests (over the course of 4-5 hours) to a server and
get results back. Some of the results could get big -- I didn't measure
carefully, perhaps not as big as 500M, more likely to be around 100M.
The app isn't particular complex. I've already fixed some major memory
leaks in the app which crashed it every time (the app is > 2 yr old while I'
m 7 months into my tenure here, request/result sizes were getting much
bigger recently) and in testing it runs fine (memory taken at

【在 c**m 的大作中提到】
: I am guessing that when you say "socket messages", you mean your own
: application message because buffers for sockets are measured in Ks, not Ms.
: So you received huge data through socket and stored them in one chunk of
: memory that could be 500M. Without knowing the nature of your application,
: my guess is you should process your data and if possible store them to
: secondary storage. If your footprint grows to significantly larger than
: anticipated my money is on memory leak. I remember that I use

avatar
t*t
11

I'
it
another?
most probably you have memory leak at some place, but it won't be triggered
everytime ---- which still is a memory leak.
problem

【在 l******u 的大作中提到】
: The app is to send requests (over the course of 4-5 hours) to a server and
: get results back. Some of the results could get big -- I didn't measure
: carefully, perhaps not as big as 500M, more likely to be around 100M.
: The app isn't particular complex. I've already fixed some major memory
: leaks in the app which crashed it every time (the app is > 2 yr old while I'
: m 7 months into my tenure here, request/result sizes were getting much
: bigger recently) and in testing it runs fine (memory taken at

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。