5

我试图找出为什么free(3)不将内存返回给系统。

我正在分配~11GB,调用malloc_info,释放,malloc_info再次调用。

但我不明白malloc_info输出,特别是保留内存和当前使用的内存之间的区别。

$ uname -a
Linux gunda3 2.6.32-358.18.1.el6.x86_64 #1 SMP Wed Aug 28 17:19:38 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux


 /lib/libc.so.6 
GNU C Library stable release version 2.12, by Roland McGrath et al.
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
Compiled by GNU CC version 4.4.7 20120313 (Red Hat 4.4.7-3).
Compiled on a Linux 2.6.32 system on 2013-08-27.
Available extensions:
    The C stubs add-on version 2.1.2.
    crypt add-on version 2.1 by Michael Glad and others
    GNU Libidn by Simon Josefsson
    Native POSIX Threads Library by Ulrich Drepper et al
    BIND-8.2.3-T5B
    RT using linux kernel aio
libc ABIs: UNIQUE IFUNC
For bug reporting instructions, please see:
<http://www.gnu.org/software/libc/bugs.html>.

-------------------- mallinfo.1 分配 11GB 后 --------------------

<malloc version="1">
<heap nr="0">
<sizes>
<size from="17" to="32" total="544" count="17"/>
<size from="33" to="48" total="816" count="17"/>
<size from="49" to="64" total="64" count="1"/>
<size from="33" to="33" total="10395" count="315"/>
<size from="49" to="49" total="588" count="12"/>
<size from="65" to="65" total="17160" count="264"/>
<size from="81" to="81" total="405" count="5"/>
<size from="97" to="97" total="12125" count="125"/>
<size from="113" to="113" total="339" count="3"/>
<size from="129" to="129" total="258" count="2"/>
<size from="145" to="145" total="145" count="1"/>
<size from="161" to="161" total="483" count="3"/>
<size from="193" to="193" total="579" count="3"/>
<size from="209" to="209" total="418" count="2"/>
<size from="225" to="225" total="15975" count="71"/>
<size from="241" to="241" total="241" count="1"/>
<size from="273" to="273" total="7644" count="28"/>
<size from="321" to="321" total="642" count="2"/>
<size from="337" to="337" total="337" count="1"/>
<size from="385" to="385" total="385" count="1"/>
<size from="449" to="449" total="449" count="1"/>
<size from="465" to="465" total="5580" count="12"/>
<size from="513" to="513" total="1026" count="2"/>
<size from="529" to="529" total="529" count="1"/>
<size from="545" to="545" total="545" count="1"/>
<size from="561" to="561" total="561" count="1"/>
<size from="577" to="577" total="577" count="1"/>
<size from="593" to="593" total="593" count="1"/>
<size from="609" to="609" total="609" count="1"/>
<size from="641" to="641" total="41024" count="64"/>
<size from="689" to="689" total="37895" count="55"/>
<size from="721" to="721" total="721" count="1"/>
<size from="737" to="737" total="5159" count="7"/>
<size from="817" to="817" total="1634" count="2"/>
<size from="833" to="833" total="833" count="1"/>
<size from="849" to="849" total="1698" count="2"/>
<size from="881" to="881" total="881" count="1"/>
<size from="897" to="897" total="897" count="1"/>
<size from="929" to="929" total="1858" count="2"/>
<size from="945" to="945" total="945" count="1"/>
<size from="977" to="977" total="977" count="1"/>
<size from="1009" to="1009" total="1009" count="1"/>
<size from="1025" to="1041" total="3091" count="3"/>
<size from="1217" to="1265" total="220449" count="177"/>
<size from="1281" to="1281" total="2562" count="2"/>
<size from="3953" to="4049" total="299402" count="74"/>
<size from="5457" to="5457" total="5457" count="1"/>
<size from="7985" to="7985" total="7985" count="1"/>
<size from="8193" to="8193" total="294948" count="36"/>
<size from="12177" to="12241" total="36659" count="3"/>
<size from="16129" to="16305" total="32434" count="2"/>
<size from="20369" to="20369" total="20369" count="1"/>
<size from="29377" to="29377" total="58754" count="2"/>
<size from="56689" to="56689" total="56689" count="1"/>
<size from="168081" to="168081" total="168081" count="1"/>
<size from="1024193" to="224731137" total="1186760443" count="651"/>
<unsorted from="177" to="1228360646656" total="4294967473" count="2"/>
</sizes>
<total type="fast" count="35" size="1424"/>
<total type="rest" count="1956" size="5483108915"/>
<system type="current" size="2312204288"/>
<system type="max" size="2312204288"/>
<aspace type="total" size="2312204288"/>
<aspace type="mprotect" size="2312204288"/>
</heap>
<heap nr="1">
<sizes>
<size from="17" to="32" total="96" count="3"/>
<size from="33" to="48" total="144" count="3"/>
<size from="49" to="64" total="128" count="2"/>
<size from="33" to="33" total="66" count="2"/>
<size from="97" to="97" total="194" count="2"/>
<size from="113" to="113" total="113" count="1"/>
<size from="145" to="145" total="145" count="1"/>
<size from="193" to="193" total="386" count="2"/>
<size from="209" to="209" total="209" count="1"/>
<size from="369" to="369" total="369" count="1"/>
<size from="385" to="385" total="385" count="1"/>
<size from="673" to="673" total="1346" count="2"/>
<size from="737" to="737" total="737" count="1"/>
<size from="753" to="753" total="753" count="1"/>
<size from="785" to="785" total="785" count="1"/>
<size from="1345" to="1345" total="1345" count="1"/>
<size from="1633" to="1633" total="1633" count="1"/>
<size from="3169" to="3169" total="3169" count="1"/>
<size from="14017" to="14017" total="14017" count="1"/>
<unsorted from="177" to="1228360646656" total="4294967666" count="3"/>
</sizes>
<total type="fast" count="8" size="368"/>
<total type="rest" count="23" size="4294993318"/>
<system type="current" size="6991872"/>
<system type="max" size="7102464"/>
<aspace type="total" size="6991872"/>
<aspace type="mprotect" size="7102464"/>
</heap>
<heap nr="2">
<sizes>
<size from="49" to="64" total="64" count="1"/>
<unsorted from="177" to="1228360646656" total="4294967843" count="4"/>
</sizes>
<total type="fast" count="1" size="64"/>
<total type="rest" count="4" size="4294967843"/>
<system type="current" size="135168"/>
<system type="max" size="135168"/>
<aspace type="total" size="135168"/>
<aspace type="mprotect" size="135168"/>
</heap>
<heap nr="3">
<sizes>
<size from="49" to="64" total="64" count="1"/>
<unsorted from="177" to="1228360646656" total="4294968020" count="5"/>
</sizes>
<total type="fast" count="1" size="64"/>
<total type="rest" count="5" size="4294968020"/>
<system type="current" size="135168"/>
<system type="max" size="135168"/>
<aspace type="total" size="135168"/>
<aspace type="mprotect" size="135168"/>
</heap>
<heap nr="4">
<sizes>
<size from="49" to="64" total="64" count="1"/>
<unsorted from="177" to="1228360646656" total="4294968197" count="6"/>
</sizes>
<total type="fast" count="1" size="64"/>
<total type="rest" count="6" size="4294968197"/>
<system type="current" size="135168"/>
<system type="max" size="135168"/>
<aspace type="total" size="135168"/>
<aspace type="mprotect" size="135168"/>
</heap>
<heap nr="5">
<sizes>
<size from="49" to="64" total="64" count="1"/>
<unsorted from="177" to="1228360646656" total="4294968374" count="7"/>
</sizes>
<total type="fast" count="1" size="64"/>
<total type="rest" count="7" size="4294968374"/>
<system type="current" size="135168"/>
<system type="max" size="135168"/>
<aspace type="total" size="135168"/>
<aspace type="mprotect" size="135168"/>
</heap>
<heap nr="6">
<sizes>
<size from="17" to="32" total="32" count="1"/>
<size from="6481" to="6481" total="6481" count="1"/>
<size from="126929" to="126929" total="126929" count="1"/>
<size from="1070257" to="7930721" total="14366131" count="3"/>
<unsorted from="49" to="1228360646656" total="4322601393" count="34"/>
</sizes>
<total type="fast" count="1" size="32"/>
<total type="rest" count="39" size="4337100934"/>
<system type="current" size="64720896"/>
<system type="max" size="169734144"/>
<aspace type="total" size="64720896"/>
<aspace type="mprotect" size="66654208"/>
</heap>
<heap nr="7">
<sizes>
<size from="49" to="64" total="64" count="1"/>
<unsorted from="49" to="1228360646656" total="4322601570" count="35"/>
</sizes>
<total type="fast" count="1" size="64"/>
<total type="rest" count="35" size="4322601570"/>
<system type="current" size="135168"/>
<system type="max" size="135168"/>
<aspace type="total" size="135168"/>
<aspace type="mprotect" size="135168"/>
</heap>
<heap nr="8">
<sizes>
<size from="49" to="64" total="64" count="1"/>
<unsorted from="49" to="1228360646656" total="4322601747" count="36"/>
</sizes>
<total type="fast" count="1" size="64"/>
<total type="rest" count="36" size="4322601747"/>
<system type="current" size="135168"/>
<system type="max" size="135168"/>
<aspace type="total" size="135168"/>
<aspace type="mprotect" size="135168"/>
</heap>
<heap nr="9">
<sizes>
<size from="49" to="64" total="64" count="1"/>
<unsorted from="49" to="1228360646656" total="4322601924" count="37"/>
</sizes>
<total type="fast" count="1" size="64"/>
<total type="rest" count="37" size="4322601924"/>
<system type="current" size="135168"/>
<system type="max" size="135168"/>
<aspace type="total" size="135168"/>
<aspace type="mprotect" size="135168"/>
</heap>
<heap nr="10">
<sizes>
<size from="49" to="64" total="64" count="1"/>
<unsorted from="49" to="1228360646656" total="4322602101" count="38"/>
</sizes>
<total type="fast" count="1" size="64"/>
<total type="rest" count="38" size="4322602101"/>
<system type="current" size="135168"/>
<system type="max" size="135168"/>
<aspace type="total" size="135168"/>
<aspace type="mprotect" size="135168"/>
</heap>
<heap nr="11">
<sizes>
<size from="49" to="64" total="64" count="1"/>
<unsorted from="49" to="1228360646656" total="4322602278" count="39"/>
</sizes>
<total type="fast" count="1" size="64"/>
<total type="rest" count="39" size="4322602278"/>
<system type="current" size="135168"/>
<system type="max" size="135168"/>
<aspace type="total" size="135168"/>
<aspace type="mprotect" size="135168"/>
</heap>
<heap nr="12">
<sizes>
<size from="49" to="64" total="64" count="1"/>
<unsorted from="49" to="1228360646656" total="4322602455" count="40"/>
</sizes>
<total type="fast" count="1" size="64"/>
<total type="rest" count="40" size="4322602455"/>
<system type="current" size="135168"/>
<system type="max" size="135168"/>
<aspace type="total" size="135168"/>
<aspace type="mprotect" size="135168"/>
</heap>
<heap nr="13">
<sizes>
<size from="49" to="64" total="64" count="1"/>
<unsorted from="49" to="1228360646656" total="4322602632" count="41"/>
</sizes>
<total type="fast" count="1" size="64"/>
<total type="rest" count="41" size="4322602632"/>
<system type="current" size="135168"/>
<system type="max" size="135168"/>
<aspace type="total" size="135168"/>
<aspace type="mprotect" size="135168"/>
</heap>
<heap nr="14">
<sizes>
<size from="49" to="64" total="64" count="1"/>
<unsorted from="49" to="1228360646656" total="4322602809" count="42"/>
</sizes>
<total type="fast" count="1" size="64"/>
<total type="rest" count="42" size="4322602809"/>
<system type="current" size="135168"/>
<system type="max" size="135168"/>
<aspace type="total" size="135168"/>
<aspace type="mprotect" size="135168"/>
</heap>
<heap nr="15">
<sizes>
<size from="17" to="32" total="32" count="1"/>
<size from="49" to="64" total="64" count="1"/>
<size from="49" to="49" total="2414818" count="49282"/>
<size from="69665" to="69665" total="69665" count="1"/>
<unsorted from="49" to="1228360646656" total="4322602986" count="43"/>
</sizes>
<total type="fast" count="2" size="96"/>
<total type="rest" count="49326" size="4325087469"/>
<system type="current" size="7906492416"/>
<system type="max" size="7908241408"/>
<aspace type="total" size="24018944"/>
<aspace type="mprotect" size="25767936"/>
</heap>
<total type="fast" count="58" size="2688"/>
<total type="rest" count="51674" size="70200980586"/>
<system type="current" size="10292031488"/>
<system type="max" size="10398904320"/>
<aspace type="total" size="2409558016"/>
<aspace type="mprotect" size="2413350912"/>
</malloc>

--------------------------------- mallinfo.2 - 释放内存后 ---------- -----

<malloc version="1">
<heap nr="0">
<sizes>
<size from="49" to="64" total="64" count="1"/>
<size from="33" to="33" total="11121" count="337"/>
<size from="49" to="49" total="1323" count="27"/>
<size from="65" to="65" total="17940" count="276"/>
<size from="81" to="81" total="324" count="4"/>
<size from="97" to="97" total="485" count="5"/>
<size from="113" to="113" total="339" count="3"/>
<size from="129" to="129" total="258" count="2"/>
<size from="145" to="145" total="145" count="1"/>
<size from="161" to="161" total="161" count="1"/>
<size from="337" to="337" total="337" count="1"/>
<size from="497" to="497" total="497" count="1"/>
<size from="529" to="529" total="1587" count="3"/>
<size from="721" to="721" total="721" count="1"/>
<size from="1073" to="1073" total="1073" count="1"/>
<size from="1297" to="1297" total="1297" count="1"/>
<size from="1665" to="1665" total="1665" count="1"/>
<size from="1841" to="1841" total="1841" count="1"/>
<size from="1857" to="1857" total="1857" count="1"/>
<size from="2497" to="2497" total="2497" count="1"/>
<size from="3089" to="3089" total="37068" count="12"/>
<size from="3617" to="3617" total="68723" count="19"/>
<size from="6001" to="6001" total="6001" count="1"/>
<size from="7649" to="7649" total="7649" count="1"/>
<size from="8801" to="9073" total="44997" count="5"/>
<size from="10673" to="10673" total="10673" count="1"/>
<size from="12673" to="16001" total="571052" count="44"/>
<size from="17937" to="18465" total="217804" count="12"/>
<size from="20497" to="24353" total="1766880" count="80"/>
<size from="27313" to="28497" total="55810" count="2"/>
<size from="30257" to="31601" total="915085" count="29"/>
<size from="35937" to="36369" total="72306" count="2"/>
<size from="36881" to="40497" total="522845" count="13"/>
<size from="41025" to="61313" total="483387" count="11"/>
<size from="85921" to="85921" total="85921" count="1"/>
<size from="98337" to="98337" total="196674" count="2"/>
<size from="155585" to="163649" total="319234" count="2"/>
<size from="196065" to="253825" total="699763" count="3"/>
<size from="303409" to="488865" total="154161233" count="321"/>
<size from="585665" to="224731137" total="1608964043" count="651"/>
<unsorted from="177" to="1228360646656" total="4294968770" count="3"/>
</sizes>
<total type="fast" count="1" size="64"/>
<total type="rest" count="1883" size="6064221386"/>
<system type="current" size="2312204288"/>
<system type="max" size="2312204288"/>
<aspace type="total" size="2312204288"/>
<aspace type="mprotect" size="2312204288"/>
</heap>
<heap nr="1">
<sizes>
<size from="17" to="32" total="64" count="2"/>
<size from="33" to="48" total="48" count="1"/>
<size from="49" to="64" total="64" count="1"/>
<size from="33" to="33" total="99" count="3"/>
<size from="49" to="49" total="49" count="1"/>
<size from="97" to="97" total="485" count="5"/>
<size from="113" to="113" total="113" count="1"/>
<size from="145" to="145" total="145" count="1"/>
<size from="577" to="577" total="577" count="1"/>
<size from="593" to="593" total="593" count="1"/>
<size from="609" to="609" total="609" count="1"/>
<size from="769" to="769" total="769" count="1"/>
<size from="785" to="785" total="1570" count="2"/>
<size from="1361" to="1361" total="1361" count="1"/>
<size from="1537" to="1537" total="1537" count="1"/>
<size from="1793" to="1793" total="1793" count="1"/>
<size from="2881" to="2881" total="2881" count="1"/>
<size from="3921" to="3921" total="3921" count="1"/>
<size from="13057" to="13057" total="13057" count="1"/>
<size from="24961" to="24961" total="24961" count="1"/>
<size from="61489" to="61489" total="61489" count="1"/>
<unsorted from="177" to="1228360646656" total="4294968963" count="4"/>
</sizes>
<total type="fast" count="4" size="176"/>
<total type="rest" count="29" size="4295084972"/>
<system type="current" size="6836224"/>
<system type="max" size="7102464"/>
<aspace type="total" size="6836224"/>
<aspace type="mprotect" size="7102464"/>
</heap>
<heap nr="2">
<sizes>
<size from="49" to="64" total="64" count="1"/>
<unsorted from="177" to="1228360646656" total="4294969140" count="5"/>
</sizes>
<total type="fast" count="1" size="64"/>
<total type="rest" count="5" size="4294969140"/>
<system type="current" size="135168"/>
<system type="max" size="135168"/>
<aspace type="total" size="135168"/>
<aspace type="mprotect" size="135168"/>
</heap>
<heap nr="3">
<sizes>
<size from="49" to="64" total="64" count="1"/>
<unsorted from="177" to="1228360646656" total="4294969317" count="6"/>
</sizes>
<total type="fast" count="1" size="64"/>
<total type="rest" count="6" size="4294969317"/>
<system type="current" size="135168"/>
<system type="max" size="135168"/>
<aspace type="total" size="135168"/>
<aspace type="mprotect" size="135168"/>
</heap>
<heap nr="4">
<sizes>
<size from="49" to="64" total="64" count="1"/>
<unsorted from="177" to="1228360646656" total="4294969494" count="7"/>
</sizes>
<total type="fast" count="1" size="64"/>
<total type="rest" count="7" size="4294969494"/>
<system type="current" size="135168"/>
<system type="max" size="135168"/>
<aspace type="total" size="135168"/>
<aspace type="mprotect" size="135168"/>
</heap>
<heap nr="5">
<sizes>
<size from="49" to="64" total="64" count="1"/>
<unsorted from="177" to="1228360646656" total="4294969671" count="8"/>
</sizes>
<total type="fast" count="1" size="64"/>
<total type="rest" count="8" size="4294969671"/>
<system type="current" size="135168"/>
<system type="max" size="135168"/>
<aspace type="total" size="135168"/>
<aspace type="mprotect" size="135168"/>
</heap>
<heap nr="6">
<sizes>
<unsorted from="177" to="1228360646656" total="4334883313" count="34"/>
</sizes>
<total type="fast" count="0" size="0"/>
<total type="rest" count="34" size="4334883313"/>
<system type="current" size="62480384"/>
<system type="max" size="169734144"/>
<aspace type="total" size="62480384"/>
<aspace type="mprotect" size="66654208"/>
</heap>
<heap nr="7">
<sizes>
<size from="49" to="64" total="64" count="1"/>
<unsorted from="177" to="1228360646656" total="4334883490" count="35"/>
</sizes>
<total type="fast" count="1" size="64"/>
<total type="rest" count="35" size="4334883490"/>
<system type="current" size="135168"/>
<system type="max" size="135168"/>
<aspace type="total" size="135168"/>
<aspace type="mprotect" size="135168"/>
</heap>
<heap nr="8">
<sizes>
<size from="49" to="64" total="64" count="1"/>
<unsorted from="177" to="1228360646656" total="4334883667" count="36"/>
</sizes>
<total type="fast" count="1" size="64"/>
<total type="rest" count="36" size="4334883667"/>
<system type="current" size="135168"/>
<system type="max" size="135168"/>
<aspace type="total" size="135168"/>
<aspace type="mprotect" size="135168"/>
</heap>
<heap nr="9">
<sizes>
<size from="49" to="64" total="64" count="1"/>
<unsorted from="177" to="1228360646656" total="4334883844" count="37"/>
</sizes>
<total type="fast" count="1" size="64"/>
<total type="rest" count="37" size="4334883844"/>
<system type="current" size="135168"/>
<system type="max" size="135168"/>
<aspace type="total" size="135168"/>
<aspace type="mprotect" size="135168"/>
</heap>
<heap nr="10">
<sizes>
<size from="49" to="64" total="64" count="1"/>
<unsorted from="177" to="1228360646656" total="4334884021" count="38"/>
</sizes>
<total type="fast" count="1" size="64"/>
<total type="rest" count="38" size="4334884021"/>
<system type="current" size="135168"/>
<system type="max" size="135168"/>
<aspace type="total" size="135168"/>
<aspace type="mprotect" size="135168"/>
</heap>
<heap nr="11">
<sizes>
<size from="49" to="64" total="64" count="1"/>
<unsorted from="177" to="1228360646656" total="4334884198" count="39"/>
</sizes>
<total type="fast" count="1" size="64"/>
<total type="rest" count="39" size="4334884198"/>
<system type="current" size="135168"/>
<system type="max" size="135168"/>
<aspace type="total" size="135168"/>
<aspace type="mprotect" size="135168"/>
</heap>
<heap nr="12">
<sizes>
<size from="49" to="64" total="64" count="1"/>
<unsorted from="177" to="1228360646656" total="4334884375" count="40"/>
</sizes>
<total type="fast" count="1" size="64"/>
<total type="rest" count="40" size="4334884375"/>
<system type="current" size="135168"/>
<system type="max" size="135168"/>
<aspace type="total" size="135168"/>
<aspace type="mprotect" size="135168"/>
</heap>
<heap nr="13">
<sizes>
<size from="49" to="64" total="64" count="1"/>
<unsorted from="177" to="1228360646656" total="4334884552" count="41"/>
</sizes>
<total type="fast" count="1" size="64"/>
<total type="rest" count="41" size="4334884552"/>
<system type="current" size="135168"/>
<system type="max" size="135168"/>
<aspace type="total" size="135168"/>
<aspace type="mprotect" size="135168"/>
</heap>
<heap nr="14">
<sizes>
<size from="49" to="64" total="64" count="1"/>
<unsorted from="177" to="1228360646656" total="4334884729" count="42"/>
</sizes>
<total type="fast" count="1" size="64"/>
<total type="rest" count="42" size="4334884729"/>
<system type="current" size="135168"/>
<system type="max" size="135168"/>
<aspace type="total" size="135168"/>
<aspace type="mprotect" size="135168"/>
</heap>
<heap nr="15">
<sizes>
<unsorted from="177" to="1228360646656" total="12229128699" count="220"/>
</sizes>
<total type="fast" count="0" size="0"/>
<total type="rest" count="220" size="12229128699"/>
<system type="current" size="7906492416"/>
<system type="max" size="7908241408"/>
<aspace type="total" size="24018944"/>
<aspace type="mprotect" size="25767936"/>
</heap>
<total type="fast" count="17" size="1008"/>
<total type="rest" count="2500" size="78782268868"/>
<system type="current" size="10289635328"/>
<system type="max" size="10398904320"/>
<aspace type="total" size="2407161856"/>
<aspace type="mprotect" size="2413350912"/>
</malloc>
4

0 回答 0