查看jvm进程id
[yeqiang@localhost ~]$ jps
8353 Launcher
13301 Jps
8581 Main
7528 RemoteMavenServer
8363 App
4301 Main
查看操作系统内存占用
[yeqiang@localhost ~]$ ps aux | egrep "MEM|8363"
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
yeqiang 8363 2.3 2.8 4121404 473348 pts/0 Sl 10:10 1:41 /usr/local/jdk1.8.0_161/bin/java -Xmx400m -javaagent:/home/yeqiang/program/idea-IC-171.4694.70/lib/idea_rt.jar=43137:/home/yeqiang/program/idea-IC-171.4694.70/bin -Dfile.encoding=UTF-8
内存使用状态快速求和方法
[yeqiang@localhost ~]$ jstat -gc 8363| grep -v S0C | awk '{s=$3+$4+$6+$8+$10+$12} END {print s}'
203272
堆内存(S0U+S1U+EU+OU)+元数据内存(MU)+已编译class占用内存(CSSU)
共203272KB 大约200MB
jstat 查看堆,元数据,编译class内存占用情况:
[yeqiang@localhost ~]$ jstat -gc 8363
S0C S1C S0U S1U EC EU OC OU MC MU CCSC CCSU YGC YGCT FGC FGCT GCT
35328.0 36352.0 0.0 1504.0 63488.0 56313.1 273408.0 39001.0 121176.0 118360.5 10840.0 10150.4 31 0.327 8 0.520 0.848
[yeqiang@localhost ~]$ man jstat
-gc option
Garbage-collected heap statistics.
S0C: Current survivor space 0 capacity (kB).
S1C: Current survivor space 1 capacity (kB).
S0U: Survivor space 0 utilization (kB).
S1U: Survivor space 1 utilization (kB).
EC: Current eden space capacity (kB).
EU: Eden space utilization (kB).
OC: Current old space capacity (kB).
OU: Old space utilization (kB).
MC: Metaspace capacity (kB).
MU: Metacspace utilization (kB).
CCSC: Compressed class space capacity (kB).
CCSU: Compressed class space used (kB).
YGC: Number of young generation garbage collection events.
YGCT: Young generation garbage collection time.
FGC: Number of full GC events.
FGCT: Full garbage collection time.
GCT: Total garbage collection time.
jvm 内存相关内存参数
-Xmnsize
Sets the initial and maximum size (in bytes) of the heap for the young generation (nursery). Append the letter k or K to indicate kilobytes, m or M to indicate megabytes, g or G to indicate
gigabytes.
The young generation region of the heap is used for new objects. GC is performed in this region more often than in other regions. If the size for the young generation is too small, then a lot of
minor garbage collections will be performed. If the size is too large, then only full garbage collections will be performed, which can take a long time to complete. Oracle recommends that you
keep the size for the young generation between a half and a quarter of the overall heap size.
-Xmssize
Sets the initial size (in bytes) of the heap. This value must be a
multiple of 1024 and greater than 1 MB. Append the letter k or K to
indicate kilobytes, m or M to indicate megabytes, g or G to
indicate gigabytes.
-Xmxsize
Specifies the maximum size (in bytes) of the memory allocation pool
in bytes. This value must be a multiple of 1024 and greater than 2
MB. Append the letter k or K to indicate kilobytes, m or M to
indicate megabytes, g or G to indicate gigabytes. The default value
is chosen at runtime based on system configuration. For server
deployments, -Xms and -Xmx are often set to the same value. See the
section "Ergonomics" in Java SE HotSpot Virtual Machine Garbage
Collection Tuning Guide at
http://docs.oracle.com/javase/8/docs/technotes/guides/vm/gctuning/index.html.
-XX:+PrintGC
Enables printing of messages at every GC. By default, this option is disabled.
-XX:+PrintGCDetails
Enables printing of detailed messages at every GC. By default, this option is disabled.
-XX:NativeMemoryTracking=mode
Specifies the mode for tracking JVM native memory usage. Possible mode arguments for this option include the following:
off
Do not track JVM native memory usage. This is the default behavior if you do not specify the -XX:NativeMemoryTracking option.
summary
Only track memory usage by JVM subsystems, such as Java heap, class, code, and thread.
detail
In addition to tracking memory usage by JVM subsystems, track memory usage by individual CallSite, individual virtual memory region and its committed regions.
-XX:NativeMemoryTracking=detail -XX:+PrintGC -XX:+PrintGCDetails -Xmn100m -Xms200m -Xmx200m
jcmd
[yeqiang@localhost webapp2]$ jcmd 17108 VM.native_memory
17108:
Native Memory Tracking:
Total: reserved=2589996KB, committed=1291028KB
- Java Heap (reserved=204800KB, committed=204800KB)
(mmap: reserved=204800KB, committed=204800KB)
- Class (reserved=1062080KB, committed=10176KB)
(classes #532)
(malloc=5312KB #1296)
(mmap: reserved=1056768KB, committed=4864KB)
- Thread (reserved=1048963KB, committed=1048963KB)
(thread #1017)
(stack: reserved=1044408KB, committed=1044408KB)
(malloc=3363KB #5086)
(arena=1192KB #2033)
- Code (reserved=249712KB, committed=2648KB)
(malloc=112KB #451)
(mmap: reserved=249600KB, committed=2536KB)
- GC (reserved=13191KB, committed=13191KB)
(malloc=5771KB #119)
(mmap: reserved=7420KB, committed=7420KB)
- Compiler (reserved=133KB, committed=133KB)
(malloc=2KB #29)
(arena=131KB #3)
- Internal (reserved=8809KB, committed=8809KB)
(malloc=8777KB #13536)
(mmap: reserved=32KB, committed=32KB)
- Symbol (reserved=1512KB, committed=1512KB)
(malloc=961KB #178)
(arena=552KB #1)
- Native Memory Tracking (reserved=590KB, committed=590KB)
(malloc=194KB #2585)
(tracking overhead=396KB)
- Arena Chunk (reserved=206KB, committed=206KB)
(malloc=206KB)