SlideShare une entreprise Scribd logo
Go &
The garbage collection
“
Joris Bonnefoy
DevOps @ OVH
@devatoria
2
Introduction
Reminder of basic algorithmic structures
» Objects have a pointer to the next element of the
list
» The last element have a null pointer
Linked list 4
» Objects have pointers to the next and the previous
element of the list
» The first element have a null previous pointer
» The last element have a null next pointer
Doubly linked list 5
» Objects have pointers to the next and the previous element of the
list
» The first element have a previous pointer to the last element of the
list
» The last element have a next pointer to the first element of the list
Circular doubly linked list 6
A simple problem
How to free a dereferenced object?
How to free a dereferenced object? 8
How to free a dereferenced object? 9
How to free a dereferenced object? 10
A solution
The garbage collection
The garbage collection
» John McCarthy - 1959 - Lisp
» Opposite of manual memory management
» Used to free unused allocated memory
» Can handle more types of resources (network
sockets, database handlers, …) using finalization
and region-based allocation
12
The garbage collection
» No dangling pointers
» No memory leaks
» No double free
» Can reduce performances
» Stop-the-world issues
» Can be unpredictable
13
Two types of garbage
collector
Reference counting
How reference counting is implemented?
» Each object has a count of other objects
referencing it
» An object is considered as garbage when its
counter reach 0
16
How reference counting is implemented? 17
How reference counting is implemented? 18
Disadvantages of reference counting
» Sensitive to cycle referencing
19
Disadvantages of reference counting
» Increased space overhead
» Must be atomic
» Not real-time
20
Tracing garbage collection
Concept of tracing garbage collection
» Determine which objects are reachable from a
certain “root” object
» Unreachable objects are considered as garbage
» Can use a lot of algorithms
22
Two ways of reachability
» The object is reachable from a certain root
» Local variables
» Parameters
» Global variables
» The object is reachable via another reachable
object
23
Tracing garbage collection
The naïve mark-and-sweep algorithm
The naïve mark-and-sweep algorithm
» Two stages algorithm
» First, run through the root set tree and mark
reachable objects
» Second, run through the whole memory, sweep
unmarked objects and clear mark of marked
objects
25
The naïve mark-and-sweep algorithm disadvantages
» Must run through the memory twice
» Must freeze the execution of the program to avoid
mutation of the working set
26
Go and the garbage collection
The tri-color marking
The tri-color marking
» Proposed by Dijkstra in 1978
» Tri-color
» Concurrent
» Mark-and-sweep
28
The tri-color marking concept
» Heap is a graph of connected objects
» Uses 3 colored sets
» White: contains objects to collect
» Gray: contains objects reachable from the root
but not yet scanned
» Black: contains reachable and scanned objects
29
The tri-color marking steps
» At the beginning, everyone is in the white set
» Root objects are moved in the gray set
» A root object is scanned
» Its references are colored gray, while the root object itself is
colored black
» Its references are scanned too and moved to the black set
» Once the gray set is empty, the remaining objects in the white set
are freed and sets are recolored
30
The tri-color marking by example 31
The tri-color marking by example 32
The tri-color marking by example 33
The tri-color marking by example 34
The tri-color marking by example 35
The tri-color marking by example 36
The tri-color marking by example 37
The algorithm invariant
“The tri-color marking invariant
No black object may contain a pointer to a
white object
39
How to always satisfy the invariant?
» Stop the world until GC is complete
» Use a write barrier
» Function executed by the mutator to tell the GC that a pointer
has been changed
» Enforce an object to be gray when it is created during the
garbage collector cycle
40
How to always satisfy the invariant? 41
Go back to lower versions of Go
The garbage collector review by Richard Hudson
Go 1.4 and lower
» Stop-the-world from the beginning of the cycle to
the end
» High GC latency
» Not concurrent
43
Go 1.5 (and actual) garbage collector
» Made by Richard Hudson and his team
» Concurrent
» Low latency
» Decrease program performances but increase
throughput
44
Go 1.5 new garbage collector 45
Benchmarking 46
Go 1.6 and further
» Improvements on when to start a GC cycle, used
metrics, etc.
» Predictive
47
What’s new in Go 1.8?
The garbage collector review
Actual garbage collector pain point 49
New type of write barrier
» Hybrid write barrier
» Dijkstra (1978)
» Yuasa (1990)
» New algorithm invariant (weak invariant)
» No need to rescan the whole memory
» Reduces GC cycle
» 100 microseconds for the worst case
» 50 microseconds for 95 percentile
50
“
Any white object pointed to by a black object
is reachable from a grey object via a chain of
white pointers (it is grey-protected).
51
Go 1.8 hybrid write barrier 52
Languages without garbage
collector
Rust
» Based on ownership and borrowing
» Every value has a scope
» Passing or returning a value means transferring its ownership
» When a scope ends, owned values are destroyed
» Everything is checked at compile time
» Everything is allocated on the stack by default
» Using stack frames
» Stack frames are freed on function return
» Can be allocated on the heap using boxes
54
Rust - Ownership 55
Rust - Ownership 56
Rust - Ownership 57
Rust - Borrowing 58
“
Thank you for listening
59
References
» Pusher https://blog.pusher.com/golangs-real-time-gc-in-theory-and-practice/
» Golang new GC proposal
https://github.com/golang/proposal/blob/master/design/17503-eliminate-rescan.md
» Go GC 1.5 blog post https://blog.golang.org/go15gc
» GopherCon 2015 GC Latency talk https://www.youtube.com/watch?v=aiv1JOfMjm0
» Dijkstra 1978 GC paper http://dl.acm.org/citation.cfm?id=359655
» Rust lang https://blog.rust-lang.org/2015/04/10/Fearless-Concurrency.html
60

Contenu connexe

Tendances

PréSentation Du Guide Version Extensive Rev3
PréSentation Du Guide Version Extensive Rev3PréSentation Du Guide Version Extensive Rev3
PréSentation Du Guide Version Extensive Rev3rabbath
 
Secure container: Kata container and gVisor
Secure container: Kata container and gVisorSecure container: Kata container and gVisor
Secure container: Kata container and gVisor
Ching-Hsuan Yen
 
Docker swarm introduction
Docker swarm introductionDocker swarm introduction
Docker swarm introduction
Evan Lin
 
Formation Professional Scrum Master I
Formation Professional Scrum Master IFormation Professional Scrum Master I
Formation Professional Scrum Master I
Guillaume LAURIE
 
Docker Birthday #3 - Intro to Docker Slides
Docker Birthday #3 - Intro to Docker SlidesDocker Birthday #3 - Intro to Docker Slides
Docker Birthday #3 - Intro to Docker Slides
Docker, Inc.
 
GitOps: Git come unica fonte di verità per applicazioni e infrastruttura
GitOps: Git come unica fonte di verità per applicazioni e infrastrutturaGitOps: Git come unica fonte di verità per applicazioni e infrastruttura
GitOps: Git come unica fonte di verità per applicazioni e infrastruttura
sparkfabrik
 
Introduction to Docker Compose
Introduction to Docker ComposeIntroduction to Docker Compose
Introduction to Docker Compose
Ajeet Singh Raina
 
Introduction à docker.io
Introduction à docker.ioIntroduction à docker.io
Introduction à docker.io
Nicolas Hennion
 
Cfgmgmtcamp 2023 — eBPF Superpowers
Cfgmgmtcamp 2023 — eBPF SuperpowersCfgmgmtcamp 2023 — eBPF Superpowers
Cfgmgmtcamp 2023 — eBPF Superpowers
Raphaël PINSON
 
01. Kubernetes-PPT.pptx
01. Kubernetes-PPT.pptx01. Kubernetes-PPT.pptx
01. Kubernetes-PPT.pptx
TamalBanerjee16
 
Loic sarton questions de l'examen management environnemental
Loic sarton   questions de l'examen management environnementalLoic sarton   questions de l'examen management environnemental
Loic sarton questions de l'examen management environnemental
Loic Sarton
 
OpenStack Osloを使おう - cliff編
OpenStack Osloを使おう - cliff編OpenStack Osloを使おう - cliff編
OpenStack Osloを使おう - cliff編
Hideki Saito
 
Microservices with Docker, Kubernetes, and Jenkins
Microservices with Docker, Kubernetes, and JenkinsMicroservices with Docker, Kubernetes, and Jenkins
Microservices with Docker, Kubernetes, and Jenkins
Red Hat Developers
 
Prioriser ses fonctionnalités avec le modèle de KANO
Prioriser ses fonctionnalités avec le modèle de KANOPrioriser ses fonctionnalités avec le modèle de KANO
Prioriser ses fonctionnalités avec le modèle de KANO
Thiga
 
Kubernetes - A Comprehensive Overview
Kubernetes - A Comprehensive OverviewKubernetes - A Comprehensive Overview
Kubernetes - A Comprehensive Overview
Bob Killen
 
Presentation-DEVOPS-par-GDG
Presentation-DEVOPS-par-GDGPresentation-DEVOPS-par-GDG
Presentation-DEVOPS-par-GDG
TinarivosoaAbaniaina
 
A la découverte de kubernetes
A la découverte de kubernetesA la découverte de kubernetes
A la découverte de kubernetes
Julien Maitrehenry
 
Hands-On Introduction to Kubernetes at LISA17
Hands-On Introduction to Kubernetes at LISA17Hands-On Introduction to Kubernetes at LISA17
Hands-On Introduction to Kubernetes at LISA17
Ryan Jarvinen
 

Tendances (20)

PréSentation Du Guide Version Extensive Rev3
PréSentation Du Guide Version Extensive Rev3PréSentation Du Guide Version Extensive Rev3
PréSentation Du Guide Version Extensive Rev3
 
Secure container: Kata container and gVisor
Secure container: Kata container and gVisorSecure container: Kata container and gVisor
Secure container: Kata container and gVisor
 
Docker swarm introduction
Docker swarm introductionDocker swarm introduction
Docker swarm introduction
 
Formation Professional Scrum Master I
Formation Professional Scrum Master IFormation Professional Scrum Master I
Formation Professional Scrum Master I
 
Docker Birthday #3 - Intro to Docker Slides
Docker Birthday #3 - Intro to Docker SlidesDocker Birthday #3 - Intro to Docker Slides
Docker Birthday #3 - Intro to Docker Slides
 
GitOps: Git come unica fonte di verità per applicazioni e infrastruttura
GitOps: Git come unica fonte di verità per applicazioni e infrastrutturaGitOps: Git come unica fonte di verità per applicazioni e infrastruttura
GitOps: Git come unica fonte di verità per applicazioni e infrastruttura
 
Introduction to Docker Compose
Introduction to Docker ComposeIntroduction to Docker Compose
Introduction to Docker Compose
 
Introduction à docker.io
Introduction à docker.ioIntroduction à docker.io
Introduction à docker.io
 
Cfgmgmtcamp 2023 — eBPF Superpowers
Cfgmgmtcamp 2023 — eBPF SuperpowersCfgmgmtcamp 2023 — eBPF Superpowers
Cfgmgmtcamp 2023 — eBPF Superpowers
 
01. Kubernetes-PPT.pptx
01. Kubernetes-PPT.pptx01. Kubernetes-PPT.pptx
01. Kubernetes-PPT.pptx
 
Loic sarton questions de l'examen management environnemental
Loic sarton   questions de l'examen management environnementalLoic sarton   questions de l'examen management environnemental
Loic sarton questions de l'examen management environnemental
 
OpenStack Osloを使おう - cliff編
OpenStack Osloを使おう - cliff編OpenStack Osloを使おう - cliff編
OpenStack Osloを使おう - cliff編
 
Microservices with Docker, Kubernetes, and Jenkins
Microservices with Docker, Kubernetes, and JenkinsMicroservices with Docker, Kubernetes, and Jenkins
Microservices with Docker, Kubernetes, and Jenkins
 
Charte de projet
Charte de projetCharte de projet
Charte de projet
 
Prioriser ses fonctionnalités avec le modèle de KANO
Prioriser ses fonctionnalités avec le modèle de KANOPrioriser ses fonctionnalités avec le modèle de KANO
Prioriser ses fonctionnalités avec le modèle de KANO
 
Kubernetes - A Comprehensive Overview
Kubernetes - A Comprehensive OverviewKubernetes - A Comprehensive Overview
Kubernetes - A Comprehensive Overview
 
Presentation-DEVOPS-par-GDG
Presentation-DEVOPS-par-GDGPresentation-DEVOPS-par-GDG
Presentation-DEVOPS-par-GDG
 
A la découverte de kubernetes
A la découverte de kubernetesA la découverte de kubernetes
A la découverte de kubernetes
 
Hands-On Introduction to Kubernetes at LISA17
Hands-On Introduction to Kubernetes at LISA17Hands-On Introduction to Kubernetes at LISA17
Hands-On Introduction to Kubernetes at LISA17
 
Was ist Docker?
Was ist Docker?Was ist Docker?
Was ist Docker?
 

Similaire à Go and the garbage collection

JDK8 Functional API
JDK8 Functional APIJDK8 Functional API
JDK8 Functional API
Justin Lin
 
.NET UY Meetup 7 - CLR Memory by Fabian Alves
.NET UY Meetup 7 - CLR Memory by Fabian Alves.NET UY Meetup 7 - CLR Memory by Fabian Alves
.NET UY Meetup 7 - CLR Memory by Fabian Alves
.NET UY Meetup
 
Understanding low latency jvm gcs
Understanding low latency jvm gcsUnderstanding low latency jvm gcs
Understanding low latency jvm gcs
Jean-Philippe BEMPEL
 
A survey on Heap Exploitation
A survey on Heap Exploitation A survey on Heap Exploitation
A survey on Heap Exploitation
Alireza Karimi
 
Probabilistic data structure
Probabilistic data structureProbabilistic data structure
Probabilistic data structure
Thinh Dang
 
CrashLocator: Locating Crashing Faults Based on Crash Stacks (ISSTA 2014)
CrashLocator: Locating Crashing Faults Based on Crash Stacks (ISSTA 2014)CrashLocator: Locating Crashing Faults Based on Crash Stacks (ISSTA 2014)
CrashLocator: Locating Crashing Faults Based on Crash Stacks (ISSTA 2014)
Sung Kim
 
Yin Yangs of Software Development
Yin Yangs of Software DevelopmentYin Yangs of Software Development
Yin Yangs of Software Development
Naveenkumar Muguda
 
Introduction to Big Data
Introduction to Big DataIntroduction to Big Data
Introduction to Big Data
Albert Bifet
 
Hoard_2022AIM1001.pptx.pdf
Hoard_2022AIM1001.pptx.pdfHoard_2022AIM1001.pptx.pdf
Hoard_2022AIM1001.pptx.pdf
AshutoshKumar437302
 
Reactive Streams: Handling Data-Flow the Reactive Way
Reactive Streams: Handling Data-Flow the Reactive WayReactive Streams: Handling Data-Flow the Reactive Way
Reactive Streams: Handling Data-Flow the Reactive Way
Roland Kuhn
 
Ants coony optimiztion problem in Advance analysis of algorithms
Ants coony optimiztion problem in Advance analysis of algorithmsAnts coony optimiztion problem in Advance analysis of algorithms
Ants coony optimiztion problem in Advance analysis of algorithms
ALIZAIB KHAN
 
CMSC 202 - Lec20 - Containers and Iterators(2).pptx
CMSC 202 - Lec20 - Containers and Iterators(2).pptxCMSC 202 - Lec20 - Containers and Iterators(2).pptx
CMSC 202 - Lec20 - Containers and Iterators(2).pptx
deathlyfire321
 
Fast Single-pass K-means Clusterting at Oxford
Fast Single-pass K-means Clusterting at Oxford Fast Single-pass K-means Clusterting at Oxford
Fast Single-pass K-means Clusterting at Oxford
MapR Technologies
 
C# basics
C# basicsC# basics
C# basics
Luigi Berrettini
 
Quantum Computing
Quantum ComputingQuantum Computing
Quantum Computing
Stephen Habegger
 
Big Graph Analytics Systems (Sigmod16 Tutorial)
Big Graph Analytics Systems (Sigmod16 Tutorial)Big Graph Analytics Systems (Sigmod16 Tutorial)
Big Graph Analytics Systems (Sigmod16 Tutorial)
Yuanyuan Tian
 
Garbage Collection
Garbage CollectionGarbage Collection
Garbage Collection
Eelco Visser
 
Aco 03-04-2013
Aco 03-04-2013Aco 03-04-2013
Aco 03-04-2013
Ahmad Khan
 
Sean Kandel - Data profiling: Assessing the overall content and quality of a ...
Sean Kandel - Data profiling: Assessing the overall content and quality of a ...Sean Kandel - Data profiling: Assessing the overall content and quality of a ...
Sean Kandel - Data profiling: Assessing the overall content and quality of a ...
huguk
 
Lecture_3.pptx
Lecture_3.pptxLecture_3.pptx
Lecture_3.pptx
GayathriSanthosh11
 

Similaire à Go and the garbage collection (20)

JDK8 Functional API
JDK8 Functional APIJDK8 Functional API
JDK8 Functional API
 
.NET UY Meetup 7 - CLR Memory by Fabian Alves
.NET UY Meetup 7 - CLR Memory by Fabian Alves.NET UY Meetup 7 - CLR Memory by Fabian Alves
.NET UY Meetup 7 - CLR Memory by Fabian Alves
 
Understanding low latency jvm gcs
Understanding low latency jvm gcsUnderstanding low latency jvm gcs
Understanding low latency jvm gcs
 
A survey on Heap Exploitation
A survey on Heap Exploitation A survey on Heap Exploitation
A survey on Heap Exploitation
 
Probabilistic data structure
Probabilistic data structureProbabilistic data structure
Probabilistic data structure
 
CrashLocator: Locating Crashing Faults Based on Crash Stacks (ISSTA 2014)
CrashLocator: Locating Crashing Faults Based on Crash Stacks (ISSTA 2014)CrashLocator: Locating Crashing Faults Based on Crash Stacks (ISSTA 2014)
CrashLocator: Locating Crashing Faults Based on Crash Stacks (ISSTA 2014)
 
Yin Yangs of Software Development
Yin Yangs of Software DevelopmentYin Yangs of Software Development
Yin Yangs of Software Development
 
Introduction to Big Data
Introduction to Big DataIntroduction to Big Data
Introduction to Big Data
 
Hoard_2022AIM1001.pptx.pdf
Hoard_2022AIM1001.pptx.pdfHoard_2022AIM1001.pptx.pdf
Hoard_2022AIM1001.pptx.pdf
 
Reactive Streams: Handling Data-Flow the Reactive Way
Reactive Streams: Handling Data-Flow the Reactive WayReactive Streams: Handling Data-Flow the Reactive Way
Reactive Streams: Handling Data-Flow the Reactive Way
 
Ants coony optimiztion problem in Advance analysis of algorithms
Ants coony optimiztion problem in Advance analysis of algorithmsAnts coony optimiztion problem in Advance analysis of algorithms
Ants coony optimiztion problem in Advance analysis of algorithms
 
CMSC 202 - Lec20 - Containers and Iterators(2).pptx
CMSC 202 - Lec20 - Containers and Iterators(2).pptxCMSC 202 - Lec20 - Containers and Iterators(2).pptx
CMSC 202 - Lec20 - Containers and Iterators(2).pptx
 
Fast Single-pass K-means Clusterting at Oxford
Fast Single-pass K-means Clusterting at Oxford Fast Single-pass K-means Clusterting at Oxford
Fast Single-pass K-means Clusterting at Oxford
 
C# basics
C# basicsC# basics
C# basics
 
Quantum Computing
Quantum ComputingQuantum Computing
Quantum Computing
 
Big Graph Analytics Systems (Sigmod16 Tutorial)
Big Graph Analytics Systems (Sigmod16 Tutorial)Big Graph Analytics Systems (Sigmod16 Tutorial)
Big Graph Analytics Systems (Sigmod16 Tutorial)
 
Garbage Collection
Garbage CollectionGarbage Collection
Garbage Collection
 
Aco 03-04-2013
Aco 03-04-2013Aco 03-04-2013
Aco 03-04-2013
 
Sean Kandel - Data profiling: Assessing the overall content and quality of a ...
Sean Kandel - Data profiling: Assessing the overall content and quality of a ...Sean Kandel - Data profiling: Assessing the overall content and quality of a ...
Sean Kandel - Data profiling: Assessing the overall content and quality of a ...
 
Lecture_3.pptx
Lecture_3.pptxLecture_3.pptx
Lecture_3.pptx
 

Dernier

Trusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process MiningTrusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process Mining
LucaBarbaro3
 
dbms calicut university B. sc Cs 4th sem.pdf
dbms  calicut university B. sc Cs 4th sem.pdfdbms  calicut university B. sc Cs 4th sem.pdf
dbms calicut university B. sc Cs 4th sem.pdf
Shinana2
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
Jason Packer
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
Brandon Minnick, MBA
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Tosin Akinosho
 
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
alexjohnson7307
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
Tatiana Kojar
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
Chart Kalyan
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
Zilliz
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
kumardaparthi1024
 
Finale of the Year: Apply for Next One!
Finale of the Year: Apply for Next One!Finale of the Year: Apply for Next One!
Finale of the Year: Apply for Next One!
GDSC PJATK
 
Operating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptxOperating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptx
Pravash Chandra Das
 
UI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentationUI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentation
Wouter Lemaire
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
Ivanti
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
saastr
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
Azure API Management to expose backend services securely
Azure API Management to expose backend services securelyAzure API Management to expose backend services securely
Azure API Management to expose backend services securely
Dinusha Kumarasiri
 
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Tatiana Kojar
 

Dernier (20)

Trusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process MiningTrusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process Mining
 
dbms calicut university B. sc Cs 4th sem.pdf
dbms  calicut university B. sc Cs 4th sem.pdfdbms  calicut university B. sc Cs 4th sem.pdf
dbms calicut university B. sc Cs 4th sem.pdf
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
 
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
 
Finale of the Year: Apply for Next One!
Finale of the Year: Apply for Next One!Finale of the Year: Apply for Next One!
Finale of the Year: Apply for Next One!
 
Operating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptxOperating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptx
 
UI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentationUI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentation
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
Azure API Management to expose backend services securely
Azure API Management to expose backend services securelyAzure API Management to expose backend services securely
Azure API Management to expose backend services securely
 
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
 

Go and the garbage collection

  • 1. Go & The garbage collection
  • 2. “ Joris Bonnefoy DevOps @ OVH @devatoria 2
  • 3. Introduction Reminder of basic algorithmic structures
  • 4. » Objects have a pointer to the next element of the list » The last element have a null pointer Linked list 4
  • 5. » Objects have pointers to the next and the previous element of the list » The first element have a null previous pointer » The last element have a null next pointer Doubly linked list 5
  • 6. » Objects have pointers to the next and the previous element of the list » The first element have a previous pointer to the last element of the list » The last element have a next pointer to the first element of the list Circular doubly linked list 6
  • 7. A simple problem How to free a dereferenced object?
  • 8. How to free a dereferenced object? 8
  • 9. How to free a dereferenced object? 9
  • 10. How to free a dereferenced object? 10
  • 12. The garbage collection » John McCarthy - 1959 - Lisp » Opposite of manual memory management » Used to free unused allocated memory » Can handle more types of resources (network sockets, database handlers, …) using finalization and region-based allocation 12
  • 13. The garbage collection » No dangling pointers » No memory leaks » No double free » Can reduce performances » Stop-the-world issues » Can be unpredictable 13
  • 14. Two types of garbage collector
  • 16. How reference counting is implemented? » Each object has a count of other objects referencing it » An object is considered as garbage when its counter reach 0 16
  • 17. How reference counting is implemented? 17
  • 18. How reference counting is implemented? 18
  • 19. Disadvantages of reference counting » Sensitive to cycle referencing 19
  • 20. Disadvantages of reference counting » Increased space overhead » Must be atomic » Not real-time 20
  • 22. Concept of tracing garbage collection » Determine which objects are reachable from a certain “root” object » Unreachable objects are considered as garbage » Can use a lot of algorithms 22
  • 23. Two ways of reachability » The object is reachable from a certain root » Local variables » Parameters » Global variables » The object is reachable via another reachable object 23
  • 24. Tracing garbage collection The naïve mark-and-sweep algorithm
  • 25. The naïve mark-and-sweep algorithm » Two stages algorithm » First, run through the root set tree and mark reachable objects » Second, run through the whole memory, sweep unmarked objects and clear mark of marked objects 25
  • 26. The naïve mark-and-sweep algorithm disadvantages » Must run through the memory twice » Must freeze the execution of the program to avoid mutation of the working set 26
  • 27. Go and the garbage collection The tri-color marking
  • 28. The tri-color marking » Proposed by Dijkstra in 1978 » Tri-color » Concurrent » Mark-and-sweep 28
  • 29. The tri-color marking concept » Heap is a graph of connected objects » Uses 3 colored sets » White: contains objects to collect » Gray: contains objects reachable from the root but not yet scanned » Black: contains reachable and scanned objects 29
  • 30. The tri-color marking steps » At the beginning, everyone is in the white set » Root objects are moved in the gray set » A root object is scanned » Its references are colored gray, while the root object itself is colored black » Its references are scanned too and moved to the black set » Once the gray set is empty, the remaining objects in the white set are freed and sets are recolored 30
  • 31. The tri-color marking by example 31
  • 32. The tri-color marking by example 32
  • 33. The tri-color marking by example 33
  • 34. The tri-color marking by example 34
  • 35. The tri-color marking by example 35
  • 36. The tri-color marking by example 36
  • 37. The tri-color marking by example 37
  • 39. “The tri-color marking invariant No black object may contain a pointer to a white object 39
  • 40. How to always satisfy the invariant? » Stop the world until GC is complete » Use a write barrier » Function executed by the mutator to tell the GC that a pointer has been changed » Enforce an object to be gray when it is created during the garbage collector cycle 40
  • 41. How to always satisfy the invariant? 41
  • 42. Go back to lower versions of Go The garbage collector review by Richard Hudson
  • 43. Go 1.4 and lower » Stop-the-world from the beginning of the cycle to the end » High GC latency » Not concurrent 43
  • 44. Go 1.5 (and actual) garbage collector » Made by Richard Hudson and his team » Concurrent » Low latency » Decrease program performances but increase throughput 44
  • 45. Go 1.5 new garbage collector 45
  • 47. Go 1.6 and further » Improvements on when to start a GC cycle, used metrics, etc. » Predictive 47
  • 48. What’s new in Go 1.8? The garbage collector review
  • 49. Actual garbage collector pain point 49
  • 50. New type of write barrier » Hybrid write barrier » Dijkstra (1978) » Yuasa (1990) » New algorithm invariant (weak invariant) » No need to rescan the whole memory » Reduces GC cycle » 100 microseconds for the worst case » 50 microseconds for 95 percentile 50
  • 51. “ Any white object pointed to by a black object is reachable from a grey object via a chain of white pointers (it is grey-protected). 51
  • 52. Go 1.8 hybrid write barrier 52
  • 54. Rust » Based on ownership and borrowing » Every value has a scope » Passing or returning a value means transferring its ownership » When a scope ends, owned values are destroyed » Everything is checked at compile time » Everything is allocated on the stack by default » Using stack frames » Stack frames are freed on function return » Can be allocated on the heap using boxes 54
  • 59. “ Thank you for listening 59
  • 60. References » Pusher https://blog.pusher.com/golangs-real-time-gc-in-theory-and-practice/ » Golang new GC proposal https://github.com/golang/proposal/blob/master/design/17503-eliminate-rescan.md » Go GC 1.5 blog post https://blog.golang.org/go15gc » GopherCon 2015 GC Latency talk https://www.youtube.com/watch?v=aiv1JOfMjm0 » Dijkstra 1978 GC paper http://dl.acm.org/citation.cfm?id=359655 » Rust lang https://blog.rust-lang.org/2015/04/10/Fearless-Concurrency.html 60