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 - Chernivtsi JS 2019
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Андрей Листочкин (Andrey Listochkin)
June 22, 2019
Programming
1
160
Server Memory - Chernivtsi JS 2019
Андрей Листочкин (Andrey Listochkin)
June 22, 2019
Tweet
Share
More Decks by Андрей Листочкин (Andrey Listochkin)
See All by Андрей Листочкин (Andrey Listochkin)
Everybody Stand Back! I Know Regular Expressions
listochkin
0
210
Command-line scripting with Rust. Wait, what?!
listochkin
0
410
Server Memory - BuildStuff Ukraine 2019
listochkin
0
64
10 Years Later
listochkin
0
390
Managing Managers - DevTalks iHUB
listochkin
0
72
Time, Numbers, Text
listochkin
1
620
Software Licensing: A Minefield Guide
listochkin
0
170
We Make Bots. For Real
listochkin
0
450
Devops for A Busy Developer - XP Days 2016
listochkin
0
190
Other Decks in Programming
See All in Programming
AI時代でも変わらない技術コミュニティの力~10年続く“ゆるい”つながりが生み出す価値
n_takehata
2
590
Railsの気持ちを考えながらコントローラとビューを整頓する/tidying-rails-controllers-and-views-as-rails-think
moro
4
370
PJのドキュメントを全部Git管理にしたら、一番喜んだのはAIだった
nanaism
0
230
Claude Code の Skill で複雑な既存仕様をすっきり整理しよう
yuichirokato
1
240
Raku Raku Notion 20260128
hareyakayuruyaka
0
430
2026/02/04 AIキャラクター人格の実装論 口 調の模倣から、コンテキスト制御による 『思想』と『行動』の創発へ
sr2mg4
0
670
Claude Codeと2つの巻き戻し戦略 / Two Rewind Strategies with Claude Code
fruitriin
0
200
AIとペアプロして処理時間を97%削減した話 #pyconshizu
kashewnuts
1
190
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
180
encoding/json/v2のUnmarshalはこう変わった:内部実装で見る設計改善
kurakura0916
0
230
CSC307 Lecture 13
javiergs
PRO
0
310
RubyとGoでゼロから作る証券システム: 高信頼性が求められるシステムのコードの外側にある設計と運用のリアル
free_world21
0
170
Featured
See All Featured
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.3k
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
1
130
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4k
We Analyzed 250 Million AI Search Results: Here's What I Found
joshbly
1
860
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
110
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
370
Building an army of robots
kneath
306
46k
The Spectacular Lies of Maps
axbom
PRO
1
580
Six Lessons from altMBA
skipperchong
29
4.2k
[RailsConf 2023] Rails as a piece of cake
palkan
59
6.3k
Claude Code のすすめ
schroneko
67
220k
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
1
280
Transcript
None
@listochkin fb.com/tektonna
Not a JavaScript talk
No CSS No frameworks No Node
A bit deeper than most talks on similar subject
None
How programming languages work
Just-in-time compilers Garbage Collection
Memory Management
Server runs our programs
CPU Caches RAM Swap Disk Network
Operating System
None
Pages
4k
Virtual
2 processes [0 … ∞]
Oh, I got a pointer at 4096 What’s at 4095?
Page fault
Allocate page But not really
Once you start writing to it
not 4k?
None
None
malloc
None
malloc me some memory
a pointer
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
scope
if ( … ) { let a = … …
}
None
C++: std::shared_ptr
None
Optimizations
Delayed Counting
Don’t count local references
function (user) { let email = user.email; … … }
Delayed deallocation
Cycle Collector
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”
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
Roots?
Constants Global variables Local variables Closures Thread-locals ...
Mark & Sweep vs Mark-Compact
None
Can you move objects after mark?
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
Mark all memory
None
Incremental Marking
3-colored algorithm by Dijkstra™
None
None
None
None
None
What is a barrier? if statement
else branch is very rare CPU branch predictor
Parallel marking
None
None
Lazy Sweep
Generational
Temporary data
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
1 stw to mark all WBu in RS
None
None
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
request? Minor GCs response is sent? Major GC
Firefox Run GC in background tabs first instead of current
tab
Chrome Animation frame
Walking the memory
Cache locality
GPU
OS Pages pre-forked processes malloc zones GC Pages Remembered Sets
Barriers
None
None