1. 首页
  2. IT资讯

GC日志中,Metaspace的这几个参数分得清吗?

“u003Cpu003E在GC日志中,Metaspace这一行的 used ,capacity ,committed ,reserved 具体都代表什么?u003Cbru002Fu003Eu003Cu002Fpu003Eu003Cpreu003EHeapPSYoungGen total 10752K, used 4419K[0xffffffff6ac00000, 0xffffffff6b800000, 0xffffffff6b800000) eden space 9216K, 47% used[0xffffffff6ac00000,0xffffffff6b050d68,0xffffffff6b500000)from space 1536K, 0% used[0xffffffff6b680000,0xffffffff6b680000,0xffffffff6b800000) to space 1536K, 0% used[0xffffffff6b500000,0xffffffff6b500000,0xffffffff6b680000)ParOldGen total 20480K, used 20011K[0xffffffff69800000, 0xffffffff6ac00000, 0xffffffff6ac00000)object space 20480K, 97% used[0xffffffff69800000,0xffffffff6ab8add8,0xffffffff6ac00000)Metaspace used 2425K, capacity 4498K, committed 4864K, reserved 1056768Kclass space used 262K, capacity 386K, committed 512K, reserved 1048576Ku003Cu002Fpreu003Eu003Cpu003E有点懵?u003Cu002Fpu003Eu003Cdiv class=”pgc-img”u003Eu003Cimg src=”http:u002Fu002Fp3.pstatp.comu002Flargeu002Fpgc-imageu002Fd882dff291334a5e8461492ae54ddd9d” img_width=”747″ img_height=”361″ alt=”GC日志中,Metaspace的这几个参数分得清吗?” inline=”0″u003Eu003Cp class=”pgc-img-caption”u003Eu003Cu002Fpu003Eu003Cu002Fdivu003Eu003Cpu003E上网搜了下,找到官方文档,其中有这么一段描述:u003Cu002Fpu003Eu003Cpu003EJava Hotspot VM explicitly manages the space used for metadata. Space is requested from the OS and then divided into chunks. A class loader allocates space for metadata from its chunks (a chunk is bound to a specific class loader). When classes are unloaded for a class loader, its chunks are recycled for reuse or returned to the OS. Metadata uses space allocated by mmap, not by malloc.u003Cu002Fpu003Eu003Cpu003EIn the line beginning with Metaspace, the used value is the amount of space used for loaded classes. The capacity value is the space available for metadata in currently allocated chunks. The committed value is the amount of space available for chunks. The reserved value is the amount of space reserved (but not necessarily committed) for metadata. The line beginning with class space line contains the corresponding values for the metadata for compressed class pointers.u003Cu002Fpu003Eu003Cpu003E英语描述看完,还是懵u003Cu002Fpu003Eu003Cpu003E继续搜,在Stack Overflow找到一张图u003Cu002Fpu003Eu003Cdiv class=”pgc-img”u003Eu003Cimg src=”http:u002Fu002Fp1.pstatp.comu002Flargeu002Fpgc-imageu002F70f4f7b528394b3f8f3f86a31b585fe6″ img_width=”500″ img_height=”425″ alt=”GC日志中,Metaspace的这几个参数分得清吗?” inline=”0″u003Eu003Cp class=”pgc-img-caption”u003Eu003Cu002Fpu003Eu003Cu002Fdivu003Eu003Cul class=”list-paddingleft-2″u003Eu003Cliu003Eused:加载的类的空间量。u003Cu002Fliu003Eu003Cliu003Ecapacity:当前分配块的元数据的空间。u003Cu002Fliu003Eu003Cliu003Ecommitted:空间块的数量。u003Cu002Fliu003Eu003Cliu003Ereserved:元数据的空间保留(但不一定提交)的量。u003Cu002Fliu003Eu003Cu002Fulu003Eu003Cpu003E提交,什么意思?u003Cu002Fpu003Eu003Cpu003E继续摸索了u003Cu002Fpu003Eu003Cpu003EMetaspace由一个或多个虚拟空间组成,虚拟空间的分配单元是Chunk,其中Chunk使用列表进行维护。u003Cu002Fpu003Eu003Cpu003E当使用一个classLoader加载一个类时,过程如下:u003Cu002Fpu003Eu003Cpu003E1、当前classLoader是否有对应的Chunk且有足够的空间。u003Cu002Fpu003Eu003Cpu003E2、查找空闲列表中的有没有空闲的Chunk。u003Cu002Fpu003Eu003Cpu003E3、如果没有,就从当前虚拟空间中分配一个新的Chunk,这个时候会把对应的内存进行Commit,这个动作就是提交。u003Cu002Fpu003Eu003Cpu003E4、如果当前虚拟空间不足,则预留(reserves)一个新的虚拟空间。u003Cu002Fpu003Eu003Cpu003Ereserved是jvm启动时根据参数和操作系统预留的内存大小。u003Cu002Fpu003Eu003Cpu003Ecommitted是指那些被commit的Chunk大小之和;u003Cu002Fpu003Eu003Cpu003Ecapacity是指那些被实际分配的Chunk大小之和;u003Cu002Fpu003Eu003Cpu003E因为有GC的存在,有些Chunk的数据可能会被回收,那么这些Chunk属于committe的一部分,但不属于capacityu003Cu002Fpu003Eu003Cpu003E另外,这些被分配的Chunk,基本很难被100%用完,存在碎片内存的情况,这些Chunk实际被使用的内存之和即used的大小;u003Cu002Fpu003Eu003Cpu003E所以,如何一个服务中被代理的方法特别特别多,就可能存在创建特别特别多的classLoader对象,一个classLoader对象至少需要一个Chunk,这个Chunk可能只放一个class信息,那么就存在特别特别严重的内存碎片,继而就存在一个隐患,可能发生特别频繁的FGC,而且是由Metaspace不足引起的。u003Cu002Fpu003Eu003Cpu003E转载:https:u002Fu002Fmp.weixin.qq.comu002Fsu002FipKLg9I2RoR5YYE5T_veNgu003Cu002Fpu003E”

原文始发于:GC日志中,Metaspace的这几个参数分得清吗?

主题测试文章,只做测试使用。发布者:程序员,转转请注明出处:http://www.cxybcw.com/26348.html

联系我们

13687733322

在线咨询:点击这里给我发消息

邮件:1877088071@qq.com

工作时间:周一至周五,9:30-18:30,节假日休息

QR code