SlideShare une entreprise Scribd logo
1  sur  22
Memory
+ Memory Management
Linux Kernel Memory Management
( https://www.kernel.org/doc/Documentation/vm/ )
Linux uses Virtual Memory to manage the
address space of the entire OS
VM extends the size of the physical memory
All OS processes 'live' in the VM and can
occasionally be relocated due to the kernel
demand
+ Memory Management
Linux Kernel Memory Management
Memory Manager Unit (MMU) is an
implementation of a hardware object
( in the CPU ) which manages the VM
Translation Lookaside Buffer (TLB) is a table
maintained by the CPU which holds recently
used main-to-virtual 'translations’
( diigo.com/085lsy )
+ Linux Kernel
CODE
DATA
STACK
CACHE
TLBVirtual MemoryVirtual Memory
P
PP P
P
H H
Kernel
+ Memory Management
Linux Kernel Memory Management
Managing virtual memory is the 'heaviest' task of
the Linux Kernel
It makes most of the OS advanced features
possible
Either dig deep, or run auto-pilot
( Tuned and Ktune diigo.com/085ltv )
+ Memory Management
Linux Kernel Memory Management
Linux Kernel uses VM to provide a much larger
memory than the amount of physical memory
When a memory page needs to be written and
there isnt a free page on physical memory Linux
uses swapping to ‘make room’ for that page
Linux Kernel uses LRU (Least Recently Used)
algorithm to calculate which page is to be
‘swapped out’
+ Memory Management
Random Access Memory
RAM is being used by the Kernel for
– Storing the Kernel Code and Data
– Handle Kernel's buffers and descriptors
requests
– Handle Processes generic memory areas
and file mapping requests
– *Cache buffered devices I/O
+ Memory Management
Random Access Memory
Dividing the limited amount of RAM between all
of these tasks is crucial if one is to achieve
proper performance from the system
Memory fragmentation can also be a set back in
terms of performance and needs to be dealt with
by the Kernel
+ Memory Management
Kernel Memory Allocator
KMA is a kernel subsystem which handles
memory allocation requests from all portions of
the OS
Linux Kernel uses SLAB allocator with the
'buddy' algorithm
– Allocate pages according to request type
– Reuses kernel functions (e.g: exec)
metadata pages
+ Memory Management
Process Virtual Address Space
The address space of each process contains all
of the memory addresses which are accessible
to that process, including:
 execute code
 un/initialized program data
 shared libraries
 heap
+ Memory Management
Process Virtual Address Space
The Linux Kernel uses advanced strategies in
order to improve performance on these tasks
– Demand Paging: Allows a program to
start execution before all of it's pages are
actually loaded
– Copy-on-Write: Fork child processes with
a read-only reference to the parent
process address space
+ Memory Management
Cache (Page Cache)
Most of the available RAM on the system is used
as a buffered I/O cache.
This is done in order to improve performance
when working with 'slow' devices
Write cache ('dirty' buffers) is being periodically
'sync'ed to the original device
+ Memory Management
Cache (Page Cache)
Linux Kernel caches pages which contains
 Data being processed from a file system
 Data being processed directly from a block device
 Both files and directories data
 File structure, inodes, etc’
 User mode process data which was swapped out
+ Memory Management
Cache (Page Cache)
To disable the page cache for a certain
operation, the relevant system call, should be
called with the flag O_DIRECT
Use the command ‘readahead’ to load a file list
into the Page Cache for later processing
+ Memory Management
Huge Pages
Linux uses 'page' as the smallest portion of RAM
being mapped
When mapping a huge size of sequential pages,
there is a noticeable overhead for managing
these pages
Huge pages address this problem by eliminating
the limitation of small (default: 4k) page size
+ Memory Management
Kernel Threads
Some of the Kernel tasks related to VM
management are being done using kernel
threads
 Keventd (aka events)
 Kswapd
 Pdflush
 Kblockd
 Kjournald
+ Memory Management
Kernel Tune able Parameters
Most of the mechanisms described throughout
this course can be tuned using the 'sysctl' or
'/proc' interfaces
In order to keep track of the tune able
parameters default values, inner-relations and
current effect, make sure to consult the kernel
Documentation tree
(/usr/share/doc/kernel-*/Documentation)
+ Memory Management
Kernel Tune able Parameters
 'drop_caches': invokes a cache 'sync' and
free up cached memory
 'vfs_cache_pressure': tune the amount of
resources put into reclaiming inodes and
dentries cache
'dirty_background_ratio': when will pdflush start writing out 'dirty' data
+ Memory Management
Kernel Tune able Parameters
 'dirty_writeback_centisecs': pdflush
interval
 'dirty_expire_centisecs': page's maximum
'age' before pdflush writes it out to disk
+ Memory Management
Kernel Tune able Parameters
 'page-cluster': number of pages written to
SWAP during swap in (logarithmic)
 'nr_hugepages': number of allocated huge
pages (works with 'hugetlb_shm_group')
+ Memory Management
Linux Kernel Memory Management
Use the following commands to review memory
information
 'top'
 'vmstat’
 ‘sar’
 'free’
 ‘cat /proc/meminfo’
+ Memory Management
Linux Kernel Memory Management
Exercise
Try Using the following script to overview page
cache usage #!/bin/bash
trap 'pkill "$*"' INT# **
]] -z $1 ]] && exit 2
B=$(free | awk '/^Mem/ {print $7{'(
echo Before: $B >&2
$*
A=$(free | awk '/^Mem/ {print $7{'(
echo Before: $B After: $A >&2
echo "--------------" >&2
echo Total: $(( $A - $B )) >&2

Contenu connexe

Tendances

Linux Memory Management
Linux Memory ManagementLinux Memory Management
Linux Memory Management
Ni Zo-Ma
 

Tendances (20)

Linux Memory Management
Linux Memory ManagementLinux Memory Management
Linux Memory Management
 
BPF - in-kernel virtual machine
BPF - in-kernel virtual machineBPF - in-kernel virtual machine
BPF - in-kernel virtual machine
 
Advanced Namespaces and cgroups
Advanced Namespaces and cgroupsAdvanced Namespaces and cgroups
Advanced Namespaces and cgroups
 
Slab Allocator in Linux Kernel
Slab Allocator in Linux KernelSlab Allocator in Linux Kernel
Slab Allocator in Linux Kernel
 
The Linux Kernel Implementation of Pipes and FIFOs
The Linux Kernel Implementation of Pipes and FIFOsThe Linux Kernel Implementation of Pipes and FIFOs
The Linux Kernel Implementation of Pipes and FIFOs
 
Understanding of linux kernel memory model
Understanding of linux kernel memory modelUnderstanding of linux kernel memory model
Understanding of linux kernel memory model
 
Linux Crash Dump Capture and Analysis
Linux Crash Dump Capture and AnalysisLinux Crash Dump Capture and Analysis
Linux Crash Dump Capture and Analysis
 
Page cache in Linux kernel
Page cache in Linux kernelPage cache in Linux kernel
Page cache in Linux kernel
 
Linux kernel debugging
Linux kernel debuggingLinux kernel debugging
Linux kernel debugging
 
Linux kernel debugging
Linux kernel debuggingLinux kernel debugging
Linux kernel debugging
 
semaphore & mutex.pdf
semaphore & mutex.pdfsemaphore & mutex.pdf
semaphore & mutex.pdf
 
Linux Kernel Booting Process (2) - For NLKB
Linux Kernel Booting Process (2) - For NLKBLinux Kernel Booting Process (2) - For NLKB
Linux Kernel Booting Process (2) - For NLKB
 
Reverse Mapping (rmap) in Linux Kernel
Reverse Mapping (rmap) in Linux KernelReverse Mapping (rmap) in Linux Kernel
Reverse Mapping (rmap) in Linux Kernel
 
Linux File System
Linux File SystemLinux File System
Linux File System
 
The TCP/IP Stack in the Linux Kernel
The TCP/IP Stack in the Linux KernelThe TCP/IP Stack in the Linux Kernel
The TCP/IP Stack in the Linux Kernel
 
Linux Network Stack
Linux Network StackLinux Network Stack
Linux Network Stack
 
Linux kernel
Linux kernelLinux kernel
Linux kernel
 
Linux Initialization Process (2)
Linux Initialization Process (2)Linux Initialization Process (2)
Linux Initialization Process (2)
 
Vmlinux: anatomy of bzimage and how x86 64 processor is booted
Vmlinux: anatomy of bzimage and how x86 64 processor is bootedVmlinux: anatomy of bzimage and how x86 64 processor is booted
Vmlinux: anatomy of bzimage and how x86 64 processor is booted
 
Linux Linux Traffic Control
Linux Linux Traffic ControlLinux Linux Traffic Control
Linux Linux Traffic Control
 

En vedette

01 linux history overview
01 linux history overview01 linux history overview
01 linux history overview
Shay Cohen
 

En vedette (20)

Linux Performance Tunning introduction
Linux Performance Tunning introductionLinux Performance Tunning introduction
Linux Performance Tunning introduction
 
Infra / Cont delivery - 3rd party automation
Infra / Cont delivery - 3rd party automationInfra / Cont delivery - 3rd party automation
Infra / Cont delivery - 3rd party automation
 
Linux Performance Tunning Kernel
Linux Performance Tunning KernelLinux Performance Tunning Kernel
Linux Performance Tunning Kernel
 
chroot and SELinux
chroot and SELinuxchroot and SELinux
chroot and SELinux
 
01 linux history overview
01 linux history overview01 linux history overview
01 linux history overview
 
09 string processing_with_regex copy
09 string processing_with_regex copy09 string processing_with_regex copy
09 string processing_with_regex copy
 
06 users groups_and_permissions
06 users groups_and_permissions06 users groups_and_permissions
06 users groups_and_permissions
 
07 vi text_editor
07 vi text_editor07 vi text_editor
07 vi text_editor
 
05 standard io_and_pipes
05 standard io_and_pipes05 standard io_and_pipes
05 standard io_and_pipes
 
10 finding files
10 finding files10 finding files
10 finding files
 
12 linux archiving tools
12 linux archiving tools12 linux archiving tools
12 linux archiving tools
 
03 browsing the filesystem
03 browsing the filesystem03 browsing the filesystem
03 browsing the filesystem
 
02 linux desktop usage
02 linux desktop usage02 linux desktop usage
02 linux desktop usage
 
Linux Internals - Kernel/Core
Linux Internals - Kernel/CoreLinux Internals - Kernel/Core
Linux Internals - Kernel/Core
 
04 using and_configuring_bash
04 using and_configuring_bash04 using and_configuring_bash
04 using and_configuring_bash
 
13 process management
13 process management13 process management
13 process management
 
11 linux filesystem copy
11 linux filesystem copy11 linux filesystem copy
11 linux filesystem copy
 
14 network tools
14 network tools14 network tools
14 network tools
 
08 text processing_tools
08 text processing_tools08 text processing_tools
08 text processing_tools
 
Introduction to SELinux Part-I
Introduction to SELinux Part-IIntroduction to SELinux Part-I
Introduction to SELinux Part-I
 

Similaire à Linux Performance Tunning Memory

Vmwareperformancetroubleshooting 100224104321-phpapp02
Vmwareperformancetroubleshooting 100224104321-phpapp02Vmwareperformancetroubleshooting 100224104321-phpapp02
Vmwareperformancetroubleshooting 100224104321-phpapp02
Suresh Kumar
 

Similaire à Linux Performance Tunning Memory (20)

Nachos 2
Nachos 2Nachos 2
Nachos 2
 
Visual comparison of Unix-like systems & Virtualisation
Visual comparison of Unix-like systems & VirtualisationVisual comparison of Unix-like systems & Virtualisation
Visual comparison of Unix-like systems & Virtualisation
 
I/O System and Case study
I/O System and Case studyI/O System and Case study
I/O System and Case study
 
Os
OsOs
Os
 
Linux introduction
Linux introductionLinux introduction
Linux introduction
 
I/O System and Case Study
I/O System and Case StudyI/O System and Case Study
I/O System and Case Study
 
Refining Linux
Refining LinuxRefining Linux
Refining Linux
 
Operating system ppt
Operating system pptOperating system ppt
Operating system ppt
 
Operating system ppt
Operating system pptOperating system ppt
Operating system ppt
 
Operating system ppt
Operating system pptOperating system ppt
Operating system ppt
 
Operating system ppt
Operating system pptOperating system ppt
Operating system ppt
 
Io sy.stemppt
Io sy.stempptIo sy.stemppt
Io sy.stemppt
 
virtual memory - Computer operating system
virtual memory - Computer operating systemvirtual memory - Computer operating system
virtual memory - Computer operating system
 
SO-Memoria.pdf
SO-Memoria.pdfSO-Memoria.pdf
SO-Memoria.pdf
 
SO-Memoria.pdf
SO-Memoria.pdfSO-Memoria.pdf
SO-Memoria.pdf
 
Operation System
Operation SystemOperation System
Operation System
 
Memory management in Linux
Memory management in LinuxMemory management in Linux
Memory management in Linux
 
Operation System
Operation SystemOperation System
Operation System
 
Vmwareperformancetroubleshooting 100224104321-phpapp02 (1)
Vmwareperformancetroubleshooting 100224104321-phpapp02 (1)Vmwareperformancetroubleshooting 100224104321-phpapp02 (1)
Vmwareperformancetroubleshooting 100224104321-phpapp02 (1)
 
Vmwareperformancetroubleshooting 100224104321-phpapp02
Vmwareperformancetroubleshooting 100224104321-phpapp02Vmwareperformancetroubleshooting 100224104321-phpapp02
Vmwareperformancetroubleshooting 100224104321-phpapp02
 

Dernier

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Dernier (20)

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
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
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
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
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
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
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
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 

Linux Performance Tunning Memory

  • 2. + Memory Management Linux Kernel Memory Management ( https://www.kernel.org/doc/Documentation/vm/ ) Linux uses Virtual Memory to manage the address space of the entire OS VM extends the size of the physical memory All OS processes 'live' in the VM and can occasionally be relocated due to the kernel demand
  • 3. + Memory Management Linux Kernel Memory Management Memory Manager Unit (MMU) is an implementation of a hardware object ( in the CPU ) which manages the VM Translation Lookaside Buffer (TLB) is a table maintained by the CPU which holds recently used main-to-virtual 'translations’ ( diigo.com/085lsy )
  • 4. + Linux Kernel CODE DATA STACK CACHE TLBVirtual MemoryVirtual Memory P PP P P H H Kernel
  • 5. + Memory Management Linux Kernel Memory Management Managing virtual memory is the 'heaviest' task of the Linux Kernel It makes most of the OS advanced features possible Either dig deep, or run auto-pilot ( Tuned and Ktune diigo.com/085ltv )
  • 6. + Memory Management Linux Kernel Memory Management Linux Kernel uses VM to provide a much larger memory than the amount of physical memory When a memory page needs to be written and there isnt a free page on physical memory Linux uses swapping to ‘make room’ for that page Linux Kernel uses LRU (Least Recently Used) algorithm to calculate which page is to be ‘swapped out’
  • 7. + Memory Management Random Access Memory RAM is being used by the Kernel for – Storing the Kernel Code and Data – Handle Kernel's buffers and descriptors requests – Handle Processes generic memory areas and file mapping requests – *Cache buffered devices I/O
  • 8. + Memory Management Random Access Memory Dividing the limited amount of RAM between all of these tasks is crucial if one is to achieve proper performance from the system Memory fragmentation can also be a set back in terms of performance and needs to be dealt with by the Kernel
  • 9. + Memory Management Kernel Memory Allocator KMA is a kernel subsystem which handles memory allocation requests from all portions of the OS Linux Kernel uses SLAB allocator with the 'buddy' algorithm – Allocate pages according to request type – Reuses kernel functions (e.g: exec) metadata pages
  • 10. + Memory Management Process Virtual Address Space The address space of each process contains all of the memory addresses which are accessible to that process, including:  execute code  un/initialized program data  shared libraries  heap
  • 11. + Memory Management Process Virtual Address Space The Linux Kernel uses advanced strategies in order to improve performance on these tasks – Demand Paging: Allows a program to start execution before all of it's pages are actually loaded – Copy-on-Write: Fork child processes with a read-only reference to the parent process address space
  • 12. + Memory Management Cache (Page Cache) Most of the available RAM on the system is used as a buffered I/O cache. This is done in order to improve performance when working with 'slow' devices Write cache ('dirty' buffers) is being periodically 'sync'ed to the original device
  • 13. + Memory Management Cache (Page Cache) Linux Kernel caches pages which contains  Data being processed from a file system  Data being processed directly from a block device  Both files and directories data  File structure, inodes, etc’  User mode process data which was swapped out
  • 14. + Memory Management Cache (Page Cache) To disable the page cache for a certain operation, the relevant system call, should be called with the flag O_DIRECT Use the command ‘readahead’ to load a file list into the Page Cache for later processing
  • 15. + Memory Management Huge Pages Linux uses 'page' as the smallest portion of RAM being mapped When mapping a huge size of sequential pages, there is a noticeable overhead for managing these pages Huge pages address this problem by eliminating the limitation of small (default: 4k) page size
  • 16. + Memory Management Kernel Threads Some of the Kernel tasks related to VM management are being done using kernel threads  Keventd (aka events)  Kswapd  Pdflush  Kblockd  Kjournald
  • 17. + Memory Management Kernel Tune able Parameters Most of the mechanisms described throughout this course can be tuned using the 'sysctl' or '/proc' interfaces In order to keep track of the tune able parameters default values, inner-relations and current effect, make sure to consult the kernel Documentation tree (/usr/share/doc/kernel-*/Documentation)
  • 18. + Memory Management Kernel Tune able Parameters  'drop_caches': invokes a cache 'sync' and free up cached memory  'vfs_cache_pressure': tune the amount of resources put into reclaiming inodes and dentries cache 'dirty_background_ratio': when will pdflush start writing out 'dirty' data
  • 19. + Memory Management Kernel Tune able Parameters  'dirty_writeback_centisecs': pdflush interval  'dirty_expire_centisecs': page's maximum 'age' before pdflush writes it out to disk
  • 20. + Memory Management Kernel Tune able Parameters  'page-cluster': number of pages written to SWAP during swap in (logarithmic)  'nr_hugepages': number of allocated huge pages (works with 'hugetlb_shm_group')
  • 21. + Memory Management Linux Kernel Memory Management Use the following commands to review memory information  'top'  'vmstat’  ‘sar’  'free’  ‘cat /proc/meminfo’
  • 22. + Memory Management Linux Kernel Memory Management Exercise Try Using the following script to overview page cache usage #!/bin/bash trap 'pkill "$*"' INT# ** ]] -z $1 ]] && exit 2 B=$(free | awk '/^Mem/ {print $7{'( echo Before: $B >&2 $* A=$(free | awk '/^Mem/ {print $7{'( echo Before: $B After: $A >&2 echo "--------------" >&2 echo Total: $(( $A - $B )) >&2

Notes de l'éditeur

  1. COW - Where do we know this from ? *Kernel RAM management issues, are partially like well-known common storage management issues