mem
mem-regions
stack
- stack frames
- stack overflow errors
heap
- look up the data in heap using pointers
- out of memory errors
- Manual memory management VS
GC(js,go,java)
jvm
-
stack
- thread stack:
-Xss - local stack
- thread stack:
-
heap
- YG: eden + s0 + s1, YGC(minor gc: eden 空间不足)
- OG: OGC(major gc)
- GC:
-
mem native
- mataspace:(old PG),
class definitions,static,final - direct memory
- mataspace:(old PG),
jvm params
-Xms(heap Initial)
-Xmx(heap Max)
-Xss(Thread stack initial)
-XX:MetaspaceSize
-XX:MaxMetaspaceSize
-XX:+UseSerialGC | +UseParallelGC | +UseG1GC | +UseZGC => 自己选
gc
使用
daemon thread(分析可用的场景)
- gc 使用的算法
- marking(标记): GC roots(Stack pointers)
- Sweeping(清除):
- Compacting(压缩):
- GC 算法选择标准
- Throughput:执行gc时间, =>吞吐量=application/(gc + application)
- Pause-time:STW(stop-the-world,主要发生在marking阶段)时间, => 适合web应用
- Footprint:Size of the heap used
- gc collector 回收器
-XX:+UseSerialGC-XX:+UseParallelGC-XX:+UseG1GC: low pause times and high throughput-XX:+UseZGC: low latency, no stw
- gc 过程
- minor gc:
eden 空间不足出发YGC - major gc
System.gc(), Runtime.getRunTime().gc()- OG 空间不足
- mataspace 空间不足
- YGC不管用,minor gc 执行完空间依然不足
- minor gc:
v8
又叫
Resident Set
- V8 is written in C++ and can be embedded in any C++ application(兼容C++)
- JavaScript is
single-threaded V8also uses asingle process per JavaScript context(单进程,单线程) - if you use service
workersit will spawn a new V8 process per worker.(不是多线程) - en.wikipedia.org/wiki/Mmap mmap
gc
-
stack
-
heap
- New Space:(YG = s0 + s1),Minor GC
- Old Space:(OG),Major GC(Mark-Sweep & Mark-Compact)
- Old pointer space:object里面有pointer
- Old data space: object里面只有数据
- Large object space:
- Code-space:
- Cell space, property cell space, and map space:
Cells, PropertyCells,Maps=>Map经常用
-
class, funcction 定义都在heap里面,类似PG,新生成的对象使用YG + OG(使用stack pointer(gc-root)管理)
-
Global stack frame => 全局栈,OS管理, 不会OOM,但heap会发生OOM
# New Space = two semi-space, using Scavenger(Minor GC)
--min_semi_space_size(Initial)
--max_semi_space_size(Max)
# Old Space: using Major GC(Mark-Sweep & Mark-Compact)
--initial_old_space_size(Initial)
--max_old_space_size(Max)
# stack
--stack_size
- tagged pointers 标记指针
- Minor GC (Scavenger) => YG,
- Major GC(Mark-Sweep-Compact)=> OG
- marking: gc-root + DFS(深度loop)
mem-leak
callback and promise in mem
- felixgerschau.com/javascript-…
- felixgerschau.com/javascript-…
- deepu.tech/memory-mana…
- felixgerschau.com/javascript-…
go-vm
https://www.ardanlabs.com/blog/2018/08/scheduling-in-go-part2.html- P/M/G (Go scheduler机制)
- logical processor : 逻辑cpu
- Resident Set
- stack( =>G,每个goroutine)
- mheap(page in 8K-32K, =>P,对应processor)
- arena(mcentral):64M
- mcache(mspan: span/nospan)
- escape analysis 逃逸分析