I
itsolution
Hi folks,
Could you shed some light on this issue?
my program is running on Freebsd as a daemon. When user sends a
request, it forks itself and lets its child process handles the
request.
And its main role is just to read a big xml file and save each object
into its embedded DB(such as gdbm).
Each object data can be up to several K bytes. So, whenever reading
each object from XML file, I call malloc() for making
containers(with its unit 1K) which will contain the data.
After reading each object , I immediately save data in containers
into the internal DB via DB API. And then, I free those containers.
So, there should be no memory explosion issue.
But, I always see malloc() failure as it reads(and saves into DB)
some number(like around one or 2 thousands ) of object. It's
weird. I always free the memory chunk returned by malloc once each
object is read/saved.
I attached the output of tracking memory usage (using vmstat) until
the malloc failure is encountered.
Any idea on why malloc(for 1K chunk) eventually fails despite it has
enough VM at that moment??
Only 20MB difference in free VM between (when a child myxmlreader
starts) and (when it dies due to malloc failure). So, still enough
VM remains.
(A new request comes in and a child process starts reading a big xml
file)
root 5471 18.6 0.4 75556 7888 d0 D 2:30AM 0:07.66 ./
myxmlreader
root 5468 0.0 0.2 71036 3280 d0 I 2:30AM 0:00.06 ./
myxmlreader
root@% vmstat
procs memory page disk faults cpu
r b w avm fre flt re pi po fr sr ad0 in sy cs us sy
id
1 1 0 718380 1415840 2 0 0 0 2 0 0 1277 10288 668 14
86 0
root@% vmstat
procs memory page disk faults cpu
r b w avm fre flt re pi po fr sr ad0 in sy cs us sy
id
2 1 0 719108 1414164 2 0 0 0 2 0 0 1277 10293 668 14
86 0
root@% vmstat
procs memory page disk faults cpu
r b w avm fre flt re pi po fr sr ad0 in sy cs us sy
id
3 0 0 720632 1412600 2 0 0 0 2 0 0 1277 10299 668 14
86 0
root@% vmstat
procs memory page disk faults cpu
r b w avm fre flt re pi po fr sr ad0 in sy cs us sy
id
3 0 0 722328 1410924 2 0 0 0 2 0 0 1277 10307 668 14
86 0
root@% vmstat
procs memory page disk faults cpu
r b w avm fre flt re pi po fr sr ad0 in sy cs us sy
id
3 0 0 725316 1406360 2 0 0 0 2 0 0 1277 10317 668 14
86 0
root@% vmstat
procs memory page disk faults cpu
r b w avm fre flt re pi po fr sr ad0 in sy cs us sy
id
2 0 0 727044 1404392 2 0 0 0 2 0 0 1277 10324 668 14
86 0
root@% vmstat
procs memory page disk faults cpu
r b w avm fre flt re pi po fr sr ad0 in sy cs us sy
id
2 0 0 730300 1401128 2 0 0 0 2 0 0 1277 10336 668 14
86 0
root@% vmstat
procs memory page disk faults cpu
r b w avm fre flt re pi po fr sr ad0 in sy cs us sy
id
3 0 0 732288 1399156 2 0 0 0 2 0 0 1277 10346 668 14
86 0
root@% vmstat
procs memory page disk faults cpu
r b w avm fre flt re pi po fr sr ad0 in sy cs us sy
id
2 1 0 734096 1397312 2 0 0 0 2 0 0 1277 10357 668 14
86 0
root@% vmstat
procs memory page disk faults cpu
r b w avm fre flt re pi po fr sr ad0 in sy cs us sy
id
2 1 0 712780 1352132 2 0 0 0 2 0 0 1277 10365 668 14
86 0
(At this moment, the child process has processed reading/saving one
thousand and several hundreds of xml object and finally malloc has
failed , the child process has died)
root@% ps -aux | grep myxmlreader
root 5468 0.0 0.2 71036 3192 d0 S 2:30AM 0:00.06 ./
myxmlreader
Could you shed some light on this issue?
my program is running on Freebsd as a daemon. When user sends a
request, it forks itself and lets its child process handles the
request.
And its main role is just to read a big xml file and save each object
into its embedded DB(such as gdbm).
Each object data can be up to several K bytes. So, whenever reading
each object from XML file, I call malloc() for making
containers(with its unit 1K) which will contain the data.
After reading each object , I immediately save data in containers
into the internal DB via DB API. And then, I free those containers.
So, there should be no memory explosion issue.
But, I always see malloc() failure as it reads(and saves into DB)
some number(like around one or 2 thousands ) of object. It's
weird. I always free the memory chunk returned by malloc once each
object is read/saved.
I attached the output of tracking memory usage (using vmstat) until
the malloc failure is encountered.
Any idea on why malloc(for 1K chunk) eventually fails despite it has
enough VM at that moment??
Only 20MB difference in free VM between (when a child myxmlreader
starts) and (when it dies due to malloc failure). So, still enough
VM remains.
(A new request comes in and a child process starts reading a big xml
file)
root 5471 18.6 0.4 75556 7888 d0 D 2:30AM 0:07.66 ./
myxmlreader
root 5468 0.0 0.2 71036 3280 d0 I 2:30AM 0:00.06 ./
myxmlreader
root@% vmstat
procs memory page disk faults cpu
r b w avm fre flt re pi po fr sr ad0 in sy cs us sy
id
1 1 0 718380 1415840 2 0 0 0 2 0 0 1277 10288 668 14
86 0
root@% vmstat
procs memory page disk faults cpu
r b w avm fre flt re pi po fr sr ad0 in sy cs us sy
id
2 1 0 719108 1414164 2 0 0 0 2 0 0 1277 10293 668 14
86 0
root@% vmstat
procs memory page disk faults cpu
r b w avm fre flt re pi po fr sr ad0 in sy cs us sy
id
3 0 0 720632 1412600 2 0 0 0 2 0 0 1277 10299 668 14
86 0
root@% vmstat
procs memory page disk faults cpu
r b w avm fre flt re pi po fr sr ad0 in sy cs us sy
id
3 0 0 722328 1410924 2 0 0 0 2 0 0 1277 10307 668 14
86 0
root@% vmstat
procs memory page disk faults cpu
r b w avm fre flt re pi po fr sr ad0 in sy cs us sy
id
3 0 0 725316 1406360 2 0 0 0 2 0 0 1277 10317 668 14
86 0
root@% vmstat
procs memory page disk faults cpu
r b w avm fre flt re pi po fr sr ad0 in sy cs us sy
id
2 0 0 727044 1404392 2 0 0 0 2 0 0 1277 10324 668 14
86 0
root@% vmstat
procs memory page disk faults cpu
r b w avm fre flt re pi po fr sr ad0 in sy cs us sy
id
2 0 0 730300 1401128 2 0 0 0 2 0 0 1277 10336 668 14
86 0
root@% vmstat
procs memory page disk faults cpu
r b w avm fre flt re pi po fr sr ad0 in sy cs us sy
id
3 0 0 732288 1399156 2 0 0 0 2 0 0 1277 10346 668 14
86 0
root@% vmstat
procs memory page disk faults cpu
r b w avm fre flt re pi po fr sr ad0 in sy cs us sy
id
2 1 0 734096 1397312 2 0 0 0 2 0 0 1277 10357 668 14
86 0
root@% vmstat
procs memory page disk faults cpu
r b w avm fre flt re pi po fr sr ad0 in sy cs us sy
id
2 1 0 712780 1352132 2 0 0 0 2 0 0 1277 10365 668 14
86 0
(At this moment, the child process has processed reading/saving one
thousand and several hundreds of xml object and finally malloc has
failed , the child process has died)
root@% ps -aux | grep myxmlreader
root 5468 0.0 0.2 71036 3192 d0 S 2:30AM 0:00.06 ./
myxmlreader