SlideShare une entreprise Scribd logo
1  sur  20
Télécharger pour lire hors ligne
Understanding SLAB in Linux Kernel
Haifeng Li

August 23, 2013
Outline

1

2

Implementation

3

Marvell

Introduction

SLUB & SLOB

2 / 20
Kernel Memory Allocated in Early Linux Kernel
In early kernel version, the kernel creates 13 geometrically
distributed lists of free memory areas whose sizes range from
25 to 217 bytes, named as general kernel memory system.

Marvell

3 / 20
Example of kmalloc
¤
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

s t r u c t foo {
s t r u c t mutex f o o l l o c k ;
s t r u c t bar ∗ f o o l b a r l i s t ;
int foo refcnt ;
};
f o o = k m e m a l l o c ( s i z e o f ( s t r u c t f o o ) , KM SLEEP ) ;
m u t e x i n i t (& f o o− o o l o c k ) ;
>f
f o o− o o b a r l i s t = NULL ;
>f
f o o− o o r e f c n t = 0 ;
>f
/∗ u s e f o o ∗/
ASSERT( f o o− o o b a r l i s t == NULL ) ;
>f
ASSERT( f o o− o o r e f c n t == 0 ) ;
>f
m u t e x d e s t r o y (& f o o− o o l o c k ) ;
>f
kmem free ( foo ) ;

The cost of constructing an object can be significantly higher than
cost of allocating memory for it.1
construct+destruct
23.6µs

memory allocation
9.4µs

Wasted space will be at most 1/2, internal fragmentation is still bad.
1
Marvell

Jeff Bonwick,The Slab Allocator:An Object-Caching Kernel Memory Allocator
4 / 20
Some Improvement
¤
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

Marvell

foo cache = kmem cache create ( ” foo cache ” , s i z e o f ( s t r u c t foo ) , 0 ,
foo constructor , foo destructor ) ;
f o o = k m e m c a c h e a l l o c ( f o o c a c h e , KM SLEEP ) ;
/∗ u s e f o o ; ∗/
kmem cache free ( foo cache , foo ) ;
/∗ − − − − − − − − − − − − − − − − − − −
− − − − − − − − − − − − − − − − − − − −∗/
v o i d f o o c o n s t r u c t o r ( v o i d ∗buf , i n t
{
s t r u c t foo ∗foo = buf ;
m u t e x i n i t (& f o o− o o l o c k ) ;
>f
f o o− o o r e f c n t = 0 ;
>f
f o o− o o b a r l i s t = NULL ;
>f
}
v o i d f o o d e s t r u c t o r ( v o i d ∗buf , i n t
{
s t r u c t foo ∗foo = buf ;

size )

size )

ASSERT( f o o− o o b a r l i s t == NULL) ;
>f
ASSERT( f o o− o o r e f c n t == 0 ) ;
>f
m u t e x d e s t r o y (& f o o− o o l o c k ) ;
>f
}

5 / 20
What is SLAB
What is it?
It is a pool based on Buddy subsystem for Kernel. It consists of
many sub-pool, which should be created by hand.
SLAB may like this:

Marvell

6 / 20
Relation of SLAB & Buddy

SLAB API:
1
2
3
4
5
6
7
8

Marvell

/∗ C r e a t e a c a c h e ∗/
s t r u c t kmem cache ∗ k m e m c a c h e c r e a t e ( c o n s t c h a r ∗name , s i z e t s i z e ,
a l i g n , u n s i g n e d l o n g f l a g s , v o i d (∗ c t o r ) ( v o i d ∗) ) ;
/∗ A l l o c a t e an o b j e c t ∗/
v o i d ∗ k m e m c a c h e a l l o c ( s t r u c t kmem cache ∗cache p , g f p t f l a g s )
/∗ D e a l l o c a t e an o b j e c t ∗/
v o i d k m e m c a c h e f r e e ( s t r u c t kmem cache ∗cache p , v o i d ∗ o b j p )
/∗ d e l e t e a c a c h e ∗/
v o i d k m e m c a c h e d e s t r o y ( s t r u c t kmem cache ∗ c a c h e p )

¤
size t

7 / 20
Outline

1

2

Implementation

3

Marvell

Introduction

SLUB & SLOB

8 / 20
Basic Things for Implementation
From implementation aspect, there are 2 levels in this system.

In the first level, how many objects in one slab, and how many
pages one slab will take[struct kmem cache];
In the second level, how to organize objects in slab[struct
slab];

Marvell

9 / 20
Numbers for Slab and Pages
The algorithm of calculating how many pages for one slab
For order= 0 to MAX ORDER:
1
2

3

More than one Object.
Large slab is bad for Subsystem.
IF RAM > 32MB, number is 2; ELSE number is 1;
Internal fragmentation Limition
Left over < pages
8

After the pages of one slab is done, the objects number is also got
easily.

Marvell

10 / 20
How to Organize objects of one slab
Use array to emulate linked list.

Marvell

11 / 20
Optimization(1)–SLAB Color
For servel years ago, L1 cache is small. Cache confliction is
common in slab.

To make the best use of the processor L1 cache, Color is drawn.

Marvell

12 / 20
Optimization(2)
OFF SLAB & IN SLAB [for reducing internal fragment]
If object size > 1 PAGE SIZE, OFF SLAB used.
8
Local array objects limit count & bachount?
Object Size
[128K , ]
[4K , 128K ]
[1K , 4K ]
[ 1 K , 1K ]
4
[0, 1 K ]
4

Count Limit
1
8
24
54
120

batchount
1
4
12
27
60

3 lists’ limit count = nodes*limit + objects number of slab

Marvell

13 / 20
Architecture of SLAB(1)

Marvell

14 / 20
Architecture of SLAB(2)
The common state for SLAB.

Marvell

15 / 20
Allocation
if (an object in the local array)
Take one;
else if (slab in the partial cache list){
Transfer bachcount objects to local array;
Take one;
If slab is full, mount the slab wit full cache list}
else if (slab in the free cache list)
Transfer batchount objects to local array;
Take one;
Mount the slab with partial cache list;
else {
Allocate several pages from buddy for a slab;
Construct the object;
Transfer batchount objects to local array;
Take one;
Mount the slab with partial cache list;
}
Marvell

16 / 20
Free
Algorithm for free an object:
Free an object
if(local array number < limit)
Append an object to local array.
else
Release batchount objects to slab {
if (slab is whole free)
if l3 free objects > limit
Release entire slab to
buddy system
else
Mount the slab to free list
else
Mount the slab to partial list
}
Marvell

17 / 20
Outline

1

2

Implementation

3

Marvell

Introduction

SLUB & SLOB

18 / 20
SLUB
SLUB promises better performance and scalability by dropping
most of the queues and related overhead and simplifying the slab
structure in general, while retaining the current slab allocator
interface. Verified 5 − 10% performance increase2 .
SLUB feature
Drop the slab management out. The management function
is transfered to struct page;
Drop the Full list & Free list out;
On systems with 1k nodes/processors, Several gigabytes just
tied up for storing references to objects for those queues.

Local slab instead of local object array.
When create, if existing slab object size is samilar to creating,
use the existing.
a 50% reduction is claimed
2
Marvell

Corbet,http://lwn.net/Articles/229984/
19 / 20
SLOB
The SLOB allocator intended for tiny systems, especially for
system without MMU.
SLOB feature
0˜256Bytes took one slab list, 256˜1024 took another list,
1024˜4096 took the 3rd list;
If request size > PAGE SIZE, alloc get order (size) pages from
Buddy system directly;
One slob is one page. Scan free object is to be first-fit
algorithm;
Object’s relation is connected by the front 4 Bytes of every
Object;
Doesn’t set local cache for per cpu;

Marvell

20 / 20

Contenu connexe

Tendances

Fast indexes with roaring #gomtl-10
Fast indexes with roaring #gomtl-10 Fast indexes with roaring #gomtl-10
Fast indexes with roaring #gomtl-10 Daniel Lemire
 
Parallel Computing in R
Parallel Computing in RParallel Computing in R
Parallel Computing in Rmickey24
 
Tests unitaires pour PostgreSQL avec pgTap
Tests unitaires pour PostgreSQL avec pgTapTests unitaires pour PostgreSQL avec pgTap
Tests unitaires pour PostgreSQL avec pgTapRodolphe Quiédeville
 
Apache Hadoop for System Administrators
Apache Hadoop for System AdministratorsApache Hadoop for System Administrators
Apache Hadoop for System AdministratorsAllen Wittenauer
 
Annette g09 job file for cyclohexene for niobium
Annette g09 job file for cyclohexene for niobiumAnnette g09 job file for cyclohexene for niobium
Annette g09 job file for cyclohexene for niobiumDr Robert Craig PhD
 
Goroutine stack and local variable allocation in Go
Goroutine stack and local variable allocation in GoGoroutine stack and local variable allocation in Go
Goroutine stack and local variable allocation in GoYu-Shuan Hsieh
 
Introduction to Hadoop - FinistJug
Introduction to Hadoop - FinistJugIntroduction to Hadoop - FinistJug
Introduction to Hadoop - FinistJugDavid Morin
 
robrighter's Node.js presentation for DevChatt
robrighter's Node.js presentation for DevChattrobrighter's Node.js presentation for DevChatt
robrighter's Node.js presentation for DevChattrobrighter
 
Ruby & GCs (QConSP 2014)
Ruby & GCs (QConSP 2014)Ruby & GCs (QConSP 2014)
Ruby & GCs (QConSP 2014)Fabio Akita
 
WebAssembly向け多倍長演算の実装
WebAssembly向け多倍長演算の実装WebAssembly向け多倍長演算の実装
WebAssembly向け多倍長演算の実装MITSUNARI Shigeo
 
37562259 top-consuming-process
37562259 top-consuming-process37562259 top-consuming-process
37562259 top-consuming-processskumner
 
Low Overhead System Tracing with eBPF
Low Overhead System Tracing with eBPFLow Overhead System Tracing with eBPF
Low Overhead System Tracing with eBPFAkshay Kapoor
 
[Globant summer take over] Empowering Big Data with Cassandra
[Globant summer take over] Empowering Big Data with Cassandra[Globant summer take over] Empowering Big Data with Cassandra
[Globant summer take over] Empowering Big Data with CassandraGlobant
 
[OpenInfra Days Korea 2018] (Track 4) - Backend.AI: 오픈소스 머신러닝 인프라 프레임워크
[OpenInfra Days Korea 2018] (Track 4) - Backend.AI: 오픈소스 머신러닝 인프라 프레임워크[OpenInfra Days Korea 2018] (Track 4) - Backend.AI: 오픈소스 머신러닝 인프라 프레임워크
[OpenInfra Days Korea 2018] (Track 4) - Backend.AI: 오픈소스 머신러닝 인프라 프레임워크OpenStack Korea Community
 

Tendances (20)

Fast indexes with roaring #gomtl-10
Fast indexes with roaring #gomtl-10 Fast indexes with roaring #gomtl-10
Fast indexes with roaring #gomtl-10
 
Parallel Computing in R
Parallel Computing in RParallel Computing in R
Parallel Computing in R
 
Tests unitaires pour PostgreSQL avec pgTap
Tests unitaires pour PostgreSQL avec pgTapTests unitaires pour PostgreSQL avec pgTap
Tests unitaires pour PostgreSQL avec pgTap
 
Apache Hadoop for System Administrators
Apache Hadoop for System AdministratorsApache Hadoop for System Administrators
Apache Hadoop for System Administrators
 
OOP in Rust
OOP in RustOOP in Rust
OOP in Rust
 
Dns20
Dns20Dns20
Dns20
 
Jose dossantos.doc
Jose dossantos.docJose dossantos.doc
Jose dossantos.doc
 
Using zone.js
Using zone.jsUsing zone.js
Using zone.js
 
Annette g09 job file for cyclohexene for niobium
Annette g09 job file for cyclohexene for niobiumAnnette g09 job file for cyclohexene for niobium
Annette g09 job file for cyclohexene for niobium
 
Goroutine stack and local variable allocation in Go
Goroutine stack and local variable allocation in GoGoroutine stack and local variable allocation in Go
Goroutine stack and local variable allocation in Go
 
Introduction to Hadoop - FinistJug
Introduction to Hadoop - FinistJugIntroduction to Hadoop - FinistJug
Introduction to Hadoop - FinistJug
 
robrighter's Node.js presentation for DevChatt
robrighter's Node.js presentation for DevChattrobrighter's Node.js presentation for DevChatt
robrighter's Node.js presentation for DevChatt
 
Ruby & GCs (QConSP 2014)
Ruby & GCs (QConSP 2014)Ruby & GCs (QConSP 2014)
Ruby & GCs (QConSP 2014)
 
WebAssembly向け多倍長演算の実装
WebAssembly向け多倍長演算の実装WebAssembly向け多倍長演算の実装
WebAssembly向け多倍長演算の実装
 
37562259 top-consuming-process
37562259 top-consuming-process37562259 top-consuming-process
37562259 top-consuming-process
 
Low Overhead System Tracing with eBPF
Low Overhead System Tracing with eBPFLow Overhead System Tracing with eBPF
Low Overhead System Tracing with eBPF
 
Protostar VM - Heap3
Protostar VM - Heap3Protostar VM - Heap3
Protostar VM - Heap3
 
[Globant summer take over] Empowering Big Data with Cassandra
[Globant summer take over] Empowering Big Data with Cassandra[Globant summer take over] Empowering Big Data with Cassandra
[Globant summer take over] Empowering Big Data with Cassandra
 
[OpenInfra Days Korea 2018] (Track 4) - Backend.AI: 오픈소스 머신러닝 인프라 프레임워크
[OpenInfra Days Korea 2018] (Track 4) - Backend.AI: 오픈소스 머신러닝 인프라 프레임워크[OpenInfra Days Korea 2018] (Track 4) - Backend.AI: 오픈소스 머신러닝 인프라 프레임워크
[OpenInfra Days Korea 2018] (Track 4) - Backend.AI: 오픈소스 머신러닝 인프라 프레임워크
 
Python 5-迴圈-while
Python 5-迴圈-whilePython 5-迴圈-while
Python 5-迴圈-while
 

Similaire à Understanding SLAB in Linux Kernel

TLPI - 7 Memory Allocation
TLPI - 7 Memory AllocationTLPI - 7 Memory Allocation
TLPI - 7 Memory AllocationShu-Yu Fu
 
Kernel Recipes 2014 - What I’m forgetting when designing a new userspace inte...
Kernel Recipes 2014 - What I’m forgetting when designing a new userspace inte...Kernel Recipes 2014 - What I’m forgetting when designing a new userspace inte...
Kernel Recipes 2014 - What I’m forgetting when designing a new userspace inte...Anne Nicolas
 
The n00bs guide to ovs dpdk
The n00bs guide to ovs dpdkThe n00bs guide to ovs dpdk
The n00bs guide to ovs dpdkmarkdgray
 
Katello on TorqueBox
Katello on TorqueBoxKatello on TorqueBox
Katello on TorqueBoxlzap
 
The true story_of_hello_world
The true story_of_hello_worldThe true story_of_hello_world
The true story_of_hello_worldfantasy zheng
 
2 architecture anddatastructures
2 architecture anddatastructures2 architecture anddatastructures
2 architecture anddatastructuresSolin TEM
 
FAQ on Dedupe NetApp
FAQ on Dedupe NetAppFAQ on Dedupe NetApp
FAQ on Dedupe NetAppAshwin Pawar
 
malloc & vmalloc in Linux
malloc & vmalloc in Linuxmalloc & vmalloc in Linux
malloc & vmalloc in LinuxAdrian Huang
 
Verilog Lecture2 thhts
Verilog Lecture2 thhtsVerilog Lecture2 thhts
Verilog Lecture2 thhtsBéo Tú
 
Some analysis of BlueStore and RocksDB
Some analysis of BlueStore and RocksDBSome analysis of BlueStore and RocksDB
Some analysis of BlueStore and RocksDBXiao Yan Li
 
Tutorial de forms 10g
Tutorial de forms 10gTutorial de forms 10g
Tutorial de forms 10gmiguel
 
Software to the slaughter
Software to the slaughterSoftware to the slaughter
Software to the slaughterQuinn Wilton
 
Memory Optimization
Memory OptimizationMemory Optimization
Memory Optimizationguest3eed30
 
Memory Optimization
Memory OptimizationMemory Optimization
Memory OptimizationWei Lin
 
Fortran & Link with Library & Brief Explanation of MKL BLAS
Fortran & Link with Library & Brief Explanation of MKL BLASFortran & Link with Library & Brief Explanation of MKL BLAS
Fortran & Link with Library & Brief Explanation of MKL BLASJongsu "Liam" Kim
 

Similaire à Understanding SLAB in Linux Kernel (20)

Tips of Malloc & Free
Tips of Malloc & FreeTips of Malloc & Free
Tips of Malloc & Free
 
TLPI - 7 Memory Allocation
TLPI - 7 Memory AllocationTLPI - 7 Memory Allocation
TLPI - 7 Memory Allocation
 
Securefile LOBs
Securefile LOBsSecurefile LOBs
Securefile LOBs
 
Kernel Recipes 2014 - What I’m forgetting when designing a new userspace inte...
Kernel Recipes 2014 - What I’m forgetting when designing a new userspace inte...Kernel Recipes 2014 - What I’m forgetting when designing a new userspace inte...
Kernel Recipes 2014 - What I’m forgetting when designing a new userspace inte...
 
The n00bs guide to ovs dpdk
The n00bs guide to ovs dpdkThe n00bs guide to ovs dpdk
The n00bs guide to ovs dpdk
 
Katello on TorqueBox
Katello on TorqueBoxKatello on TorqueBox
Katello on TorqueBox
 
The true story_of_hello_world
The true story_of_hello_worldThe true story_of_hello_world
The true story_of_hello_world
 
2 architecture anddatastructures
2 architecture anddatastructures2 architecture anddatastructures
2 architecture anddatastructures
 
Scope Stack Allocation
Scope Stack AllocationScope Stack Allocation
Scope Stack Allocation
 
FAQ on Dedupe NetApp
FAQ on Dedupe NetAppFAQ on Dedupe NetApp
FAQ on Dedupe NetApp
 
malloc & vmalloc in Linux
malloc & vmalloc in Linuxmalloc & vmalloc in Linux
malloc & vmalloc in Linux
 
Verilog Lecture2 thhts
Verilog Lecture2 thhtsVerilog Lecture2 thhts
Verilog Lecture2 thhts
 
Some analysis of BlueStore and RocksDB
Some analysis of BlueStore and RocksDBSome analysis of BlueStore and RocksDB
Some analysis of BlueStore and RocksDB
 
Basilisk Guide.pdf
Basilisk Guide.pdfBasilisk Guide.pdf
Basilisk Guide.pdf
 
Tutorial de forms 10g
Tutorial de forms 10gTutorial de forms 10g
Tutorial de forms 10g
 
Heap Base Exploitation
Heap Base ExploitationHeap Base Exploitation
Heap Base Exploitation
 
Software to the slaughter
Software to the slaughterSoftware to the slaughter
Software to the slaughter
 
Memory Optimization
Memory OptimizationMemory Optimization
Memory Optimization
 
Memory Optimization
Memory OptimizationMemory Optimization
Memory Optimization
 
Fortran & Link with Library & Brief Explanation of MKL BLAS
Fortran & Link with Library & Brief Explanation of MKL BLASFortran & Link with Library & Brief Explanation of MKL BLAS
Fortran & Link with Library & Brief Explanation of MKL BLAS
 

Dernier

Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 

Dernier (20)

Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 

Understanding SLAB in Linux Kernel

  • 1. Understanding SLAB in Linux Kernel Haifeng Li August 23, 2013
  • 3. Kernel Memory Allocated in Early Linux Kernel In early kernel version, the kernel creates 13 geometrically distributed lists of free memory areas whose sizes range from 25 to 217 bytes, named as general kernel memory system. Marvell 3 / 20
  • 4. Example of kmalloc ¤ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 s t r u c t foo { s t r u c t mutex f o o l l o c k ; s t r u c t bar ∗ f o o l b a r l i s t ; int foo refcnt ; }; f o o = k m e m a l l o c ( s i z e o f ( s t r u c t f o o ) , KM SLEEP ) ; m u t e x i n i t (& f o o− o o l o c k ) ; >f f o o− o o b a r l i s t = NULL ; >f f o o− o o r e f c n t = 0 ; >f /∗ u s e f o o ∗/ ASSERT( f o o− o o b a r l i s t == NULL ) ; >f ASSERT( f o o− o o r e f c n t == 0 ) ; >f m u t e x d e s t r o y (& f o o− o o l o c k ) ; >f kmem free ( foo ) ; The cost of constructing an object can be significantly higher than cost of allocating memory for it.1 construct+destruct 23.6µs memory allocation 9.4µs Wasted space will be at most 1/2, internal fragmentation is still bad. 1 Marvell Jeff Bonwick,The Slab Allocator:An Object-Caching Kernel Memory Allocator 4 / 20
  • 5. Some Improvement ¤ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 Marvell foo cache = kmem cache create ( ” foo cache ” , s i z e o f ( s t r u c t foo ) , 0 , foo constructor , foo destructor ) ; f o o = k m e m c a c h e a l l o c ( f o o c a c h e , KM SLEEP ) ; /∗ u s e f o o ; ∗/ kmem cache free ( foo cache , foo ) ; /∗ − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − − −∗/ v o i d f o o c o n s t r u c t o r ( v o i d ∗buf , i n t { s t r u c t foo ∗foo = buf ; m u t e x i n i t (& f o o− o o l o c k ) ; >f f o o− o o r e f c n t = 0 ; >f f o o− o o b a r l i s t = NULL ; >f } v o i d f o o d e s t r u c t o r ( v o i d ∗buf , i n t { s t r u c t foo ∗foo = buf ; size ) size ) ASSERT( f o o− o o b a r l i s t == NULL) ; >f ASSERT( f o o− o o r e f c n t == 0 ) ; >f m u t e x d e s t r o y (& f o o− o o l o c k ) ; >f } 5 / 20
  • 6. What is SLAB What is it? It is a pool based on Buddy subsystem for Kernel. It consists of many sub-pool, which should be created by hand. SLAB may like this: Marvell 6 / 20
  • 7. Relation of SLAB & Buddy SLAB API: 1 2 3 4 5 6 7 8 Marvell /∗ C r e a t e a c a c h e ∗/ s t r u c t kmem cache ∗ k m e m c a c h e c r e a t e ( c o n s t c h a r ∗name , s i z e t s i z e , a l i g n , u n s i g n e d l o n g f l a g s , v o i d (∗ c t o r ) ( v o i d ∗) ) ; /∗ A l l o c a t e an o b j e c t ∗/ v o i d ∗ k m e m c a c h e a l l o c ( s t r u c t kmem cache ∗cache p , g f p t f l a g s ) /∗ D e a l l o c a t e an o b j e c t ∗/ v o i d k m e m c a c h e f r e e ( s t r u c t kmem cache ∗cache p , v o i d ∗ o b j p ) /∗ d e l e t e a c a c h e ∗/ v o i d k m e m c a c h e d e s t r o y ( s t r u c t kmem cache ∗ c a c h e p ) ¤ size t 7 / 20
  • 9. Basic Things for Implementation From implementation aspect, there are 2 levels in this system. In the first level, how many objects in one slab, and how many pages one slab will take[struct kmem cache]; In the second level, how to organize objects in slab[struct slab]; Marvell 9 / 20
  • 10. Numbers for Slab and Pages The algorithm of calculating how many pages for one slab For order= 0 to MAX ORDER: 1 2 3 More than one Object. Large slab is bad for Subsystem. IF RAM > 32MB, number is 2; ELSE number is 1; Internal fragmentation Limition Left over < pages 8 After the pages of one slab is done, the objects number is also got easily. Marvell 10 / 20
  • 11. How to Organize objects of one slab Use array to emulate linked list. Marvell 11 / 20
  • 12. Optimization(1)–SLAB Color For servel years ago, L1 cache is small. Cache confliction is common in slab. To make the best use of the processor L1 cache, Color is drawn. Marvell 12 / 20
  • 13. Optimization(2) OFF SLAB & IN SLAB [for reducing internal fragment] If object size > 1 PAGE SIZE, OFF SLAB used. 8 Local array objects limit count & bachount? Object Size [128K , ] [4K , 128K ] [1K , 4K ] [ 1 K , 1K ] 4 [0, 1 K ] 4 Count Limit 1 8 24 54 120 batchount 1 4 12 27 60 3 lists’ limit count = nodes*limit + objects number of slab Marvell 13 / 20
  • 15. Architecture of SLAB(2) The common state for SLAB. Marvell 15 / 20
  • 16. Allocation if (an object in the local array) Take one; else if (slab in the partial cache list){ Transfer bachcount objects to local array; Take one; If slab is full, mount the slab wit full cache list} else if (slab in the free cache list) Transfer batchount objects to local array; Take one; Mount the slab with partial cache list; else { Allocate several pages from buddy for a slab; Construct the object; Transfer batchount objects to local array; Take one; Mount the slab with partial cache list; } Marvell 16 / 20
  • 17. Free Algorithm for free an object: Free an object if(local array number < limit) Append an object to local array. else Release batchount objects to slab { if (slab is whole free) if l3 free objects > limit Release entire slab to buddy system else Mount the slab to free list else Mount the slab to partial list } Marvell 17 / 20
  • 19. SLUB SLUB promises better performance and scalability by dropping most of the queues and related overhead and simplifying the slab structure in general, while retaining the current slab allocator interface. Verified 5 − 10% performance increase2 . SLUB feature Drop the slab management out. The management function is transfered to struct page; Drop the Full list & Free list out; On systems with 1k nodes/processors, Several gigabytes just tied up for storing references to objects for those queues. Local slab instead of local object array. When create, if existing slab object size is samilar to creating, use the existing. a 50% reduction is claimed 2 Marvell Corbet,http://lwn.net/Articles/229984/ 19 / 20
  • 20. SLOB The SLOB allocator intended for tiny systems, especially for system without MMU. SLOB feature 0˜256Bytes took one slab list, 256˜1024 took another list, 1024˜4096 took the 3rd list; If request size > PAGE SIZE, alloc get order (size) pages from Buddy system directly; One slob is one page. Scan free object is to be first-fit algorithm; Object’s relation is connected by the front 4 Bytes of every Object; Doesn’t set local cache for per cpu; Marvell 20 / 20