SlideShare uma empresa Scribd logo
1 de 20
Baixar para ler offline
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

Mais conteúdo relacionado

Mais procurados

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
 

Mais procurados (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
 

Semelhante a 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
 

Semelhante a 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
 

Último

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
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
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
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
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdfChristopherTHyatt
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 

Último (20)

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
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
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 

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