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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Андрей Листочкин (Andrey Listochkin)
November 18, 2019
Programming
68
0
Share
Server Memory - BuildStuff Ukraine 2019
Андрей Листочкин (Andrey Listochkin)
November 18, 2019
More Decks by Андрей Листочкин (Andrey Listochkin)
See All by Андрей Листочкин (Andrey Listochkin)
Everybody Stand Back! I Know Regular Expressions
listochkin
0
220
Command-line scripting with Rust. Wait, what?!
listochkin
0
420
Server Memory - Chernivtsi JS 2019
listochkin
1
160
10 Years Later
listochkin
0
390
Managing Managers - DevTalks iHUB
listochkin
0
81
Time, Numbers, Text
listochkin
1
650
Software Licensing: A Minefield Guide
listochkin
0
180
We Make Bots. For Real
listochkin
0
460
Devops for A Busy Developer - XP Days 2016
listochkin
0
190
Other Decks in Programming
See All in Programming
今さら聞けないCancellationToken
htkym
0
160
Moments When Things Go Wrong
aurimas
3
100
Copilot CLI の継戦能力を高める コンテキスト管理
nozomutu
1
510
These Five Tricks Can Make Your Apps Greener, Cheaper, & Nicer
hollycummins
0
120
いつか誰かが、と思っていた フロントエンド刷新5年間の実践知
kiichisugihara
1
290
プロパティの順序で型推論が壊れる!? TypeScript6.0の修正からContext-Sensitivityの仕組みを追う
bicstone
2
810
~ 秘伝のタレ化した『神スプシ』と戦う ~ 関数型パラダイムで壊れない仕組みへ
h0r15h0
1
120
TSKaigi 2026 TypeScriptバックエンドのオブザーバビリティ戦略 — Datadog × NestJSの実践
taiseiyamamotoan
1
120
AI Agent と正しく分析するための環境作り
yoshyum
2
570
ふにゃっとしない名前の付け方 〜哲学で茹で上げる、コシのあるソフトウェア設計〜
shimomura
0
130
過去のレビュー知見をSkillsで資産化した話
pkshadeck
PRO
1
2.2k
ビジネスモデルから紐解く、AI+型駆動開発
hirokiomote
2
1k
Featured
See All Featured
Large-scale JavaScript Application Architecture
addyosmani
515
110k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
49
9.9k
Joys of Absence: A Defence of Solitary Play
codingconduct
1
370
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
118
110k
Designing for Timeless Needs
cassininazir
1
220
Building the Perfect Custom Keyboard
takai
2
770
Ruling the World: When Life Gets Gamed
codingconduct
0
230
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
300
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.4k
The SEO Collaboration Effect
kristinabergwall1
1
450
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.7k
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!