Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Server Memory - BuildStuff Ukraine 2019
Search
Андрей Листочкин (Andrey Listochkin)
November 18, 2019
Programming
0
44
Server Memory - BuildStuff Ukraine 2019
Андрей Листочкин (Andrey Listochkin)
November 18, 2019
Tweet
Share
More Decks by Андрей Листочкин (Andrey Listochkin)
See All by Андрей Листочкин (Andrey Listochkin)
Everybody Stand Back! I Know Regular Expressions
listochkin
0
180
Command-line scripting with Rust. Wait, what?!
listochkin
0
360
Server Memory - Chernivtsi JS 2019
listochkin
1
150
10 Years Later
listochkin
0
370
Managing Managers - DevTalks iHUB
listochkin
0
58
Time, Numbers, Text
listochkin
1
590
Software Licensing: A Minefield Guide
listochkin
0
150
We Make Bots. For Real
listochkin
0
420
Devops for A Busy Developer - XP Days 2016
listochkin
0
180
Other Decks in Programming
See All in Programming
オホーツクでコミュニティを立ち上げた理由―地方出身プログラマの挑戦 / TechRAMEN 2025 Conference
lemonade_37
2
480
ワープロって実は計算機で
pepepper
2
1.4k
kiroでゲームを作ってみた
iriikeita
0
180
tool ディレクティブを導入してみた感想
sgash708
1
150
The State of Fluid (2025)
s2b
0
180
AIに安心して任せるためにTypeScriptで一意な型を作ろう
arfes0e2b3c
0
380
管你要 trace 什麼、bpftrace 用下去就對了 — COSCUP 2025
shunghsiyu
0
430
AI OCR API on Lambdaを Datadogで可視化してみた
nealle
0
120
Understanding Ruby Grammar Through Conflicts
yui_knk
1
120
あまり知られていない MCP 仕様たち / MCP specifications that aren’t widely known
ktr_0731
0
280
物語を動かす行動"量" #エンジニアニメ
konifar
14
5.3k
レガシープロジェクトで最大限AIの恩恵を受けられるようClaude Codeを利用する
tk1351
2
330
Featured
See All Featured
ReactJS: Keep Simple. Everything can be a component!
pedronauck
667
120k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
183
54k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
48
9.6k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
131
19k
Optimizing for Happiness
mojombo
379
70k
Large-scale JavaScript Application Architecture
addyosmani
512
110k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
61k
Making the Leap to Tech Lead
cromwellryan
134
9.5k
Fashionably flexible responsive web design (full day workshop)
malarkey
407
66k
How to Think Like a Performance Engineer
csswizardry
25
1.8k
Fireside Chat
paigeccino
39
3.6k
The Straight Up "How To Draw Better" Workshop
denniskardys
236
140k
Transcript
None
@listochkin + fb.com/tektonna
Memory Management
A bit deeper than most talks on similar subject
None
CPU Caches RAM Swap Disk Network
Operating System
None
Pages 4k
Virtual
3 processes [0 … ∞] [0 … ∞] [0 …
∞]
Allocate page But not really
None
malloc calloc realloc
None
pointer = malloc(size)
free(pointer)
malloc malloc malloc free malloc free free
Forget to free Free the wrong pointer Read from unallocated
memory
Can we do better?
Reference Counting
None
const players = [ … ] players.forEach(p => makeMove(p))
a = … doX(a) yield a
if ( … ) { let a = … …
}
C++: std::shared_ptr
None
Optimizations
Delayed Counting
Don’t count local references
function (user) { let email = user.email; … … }
Delayed deallocation
Reference Cycles
None
None
Compile time ref-counting
Several types of pointers
Ownership
Forbids cycles by forbidding several owning references at the same
time
None
None
None
Perl 1987 - today Python 1991 - 2001 PHP 1994
- 2009
Multiprocess deploys
fork
Copy on Write
Worker Accepts requests As memory use raises: Stop accepting requests
Complete in-flight requests Terminate
Master Keep track on workers Start new workers Signal them
to terminate when memory pressure is high
“Pre-fork”
Load the framework Load app code Run full GC ----
Start forking process to accept requests
None
None
“Processes” Supervision Trees
Tracing GC
1959 60 years ago
Start at Root references Follow all references Build a live
objects tree Delete all objects not part of the tree
Ruby Java JavaScript Lua Go Default Choice
Roots?
Constants Global variables Local variables Closures Thread-locals ...
Mark & Sweep vs Mark-Compact
None
Team Sweep: Go Ruby* Lua Embedded JS engines Erlang
Pros: Pointers don’t change Native extensions Easier to implement
Team Compact: Java JavaScript Ruby* Haskell
Pros: Less memory fragmentation over time Cons: Harder Takes longer
to do a GC
Incremental Marking
3-colored algorithm by Dijkstra™
None
None
None
None
None
What is a barrier? if statement
CPU branch predictor
Parallel marking
None
Lazy Sweep
Generational
Temporary data data.filter( … ).map( … ) log(`… ${data}`) JSON.stringify(result)
Major vs Minor GC
Pointers from Old objects to new objects
Remembered Set
Major GC Scan roots only Bigger object graph
Minor GC Scan roots + RS Small object graph
None
Modern GCs are hybrid
None
None
C-extensions
Can’t move objects if their references are passed to an
extension
Can’t add WB
RGen GC
2 types of objects WB-protected WB-unprotected
WBu are never OldGen
OldGen -> WBu WBu to Remembered Set
Mark WBus on every minor GC
Adding compaction for WBp
None
V8
Minor GC Parallel
Major Parallel marking Parallel / Concurrent Compact || Sweep
None
When to trigger GC?
Out-of-Bounds GC
Firefox Run GC in background tabs first instead of current
tab
Chrome Animation frame
OS Pages pre-forked processes malloc zones GC Regions Remembered Sets
Barriers
None
None
Practical Advice
Memory Leaks Multiprocess Deploys
Throughput ⇔ Latency
Throughput Batch jobs Queues
Latency Requests Messaging
Keep different types of workloads in different processes
More memory Swap with SSDs
Experiment and measure
@listochkin Hire Me!