SlideShare a Scribd company logo
© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Linux Memory Management
2© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
What to Expect?
W's of Memory Management?
Memory Partitioning
Memory Organization
Memory Management in Linux
Swapping
3© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Why Memory Management?
Transition from Uni-process → Multi-process
Every process needs its own memory
Memory Division
Program loaded to “any” available memory address
Relocation
Independence / Non-interference between Processes
Protection
Communication between Processes
Sharing
Process Memory with Attributes (like read only for code)
Logical Organization
Executing Programs bigger than available Memory
Physical Organization (Overlaying & Reusing)
4© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
What is Memory Management?
Key task: Division of Memory
Starting from the Division between
OS (Kernel)
Application (User)
Others follow
Relocation, Protection, Sharing
Logical & Physical Organization
May involve movement between primary &
secondary
5© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Memory Partitioning
Two traditional division mechanisms
Segmentation: Unequal sized
Examples: Linear Allocation, Buddy System
Paging: Equal sized
Examples: 4K-Paged Allocation
Examples in Linux
User-space malloc(): Segmentation
Slab sub-system: Paging
6© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Pros & Cons
Memory Fragmentation
External in Segmentation (gets worser)
Internal in Paging
Space Efficiency
Segmentation: More meta but lesser allocation wastage
Paging: Negligible meta but significant allocation wastage
Time Efficiency
Segmentation: Complex search & Storage Algorithm
Paging: Simple Algorithms
7© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Memory Organization
All other needs (Relocation, Protection, Sharing, ...)
Beautifully achieved by the concept of virtualization
That is organizing the memory into
Physical & Virtual Address Spaces
And then using the virtual addressing for all purposes
Both may use either Paging or Segmentation
Best to use similar mechanisms
Linux uses Paging for both with 4KiB/8KiB page size
Virtualization can be achieved
Using special hardware called MMU
Using software MMU
8© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Memory Organization ...
Linux Kernels (>= 2.5.46) support both
Earlier kernels worked only with hardware MMU
uClinux used to be the solution for non-MMU
processors & controllers
Latest Intel, ARM, and most other architectures
have in-built MMU
Older x86, ARM7, and few such doesn't have a
hardware MMU
9© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Memory (RAM)
Working of an MMU
1
1
0
1
Valid Tag Frame Number
TLB (in Cache)
1
Page Table (in RAM)
1
1
1
0
1
0
1
1
0
1
Page Number [31:12] Offset [11:0] Virtual Address
10© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Memory Management in Linux
In Linux, all these combined
User Space & Kernel Space
Memory Page Partitioning
Physical & Virtual Address Spaces
Device Addresses, Mapping & Access
Takes the following form ...
11© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Memory Organization in Linux
An Example assuming 32-bit architecture
4GB Process
VA Space 1
User Space
4GB Process
VA Space N
.
.
.
3GB
Virtual
Address
for User
1GB VA
for Kernel
Kernel Space
(fixed by kernel)
Logical Address
(Non-swappable)
Virtual Address
(Swappable)
0x00000000
0xBFFFFFFF
0xFFFFFFFF
0xC0000000
Upto 3GB
Memory
(RAM)
Addressing
Upto 1GB Dev
Addressing
Physical Address Space
(fixed by architecture)
0x00000000
0xBFFFFFFF
0xC0000000
0xFFFFFFFF
Bus Address (incl.
both h/w memory &
registers)
Physical Address
(incl. only memory)
12© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Linux Memory Manager
Provides Access Control to h/w & memory resources
Provides Dynamic Memory to kernel sub-system
Drivers
File Systems
Stacks
Provides Virtual Memory to Kernel & User space
Kernel & User Processes run in their own virtual address spaces
Providing the various features of a Linux system
System reliability, Security
Communication
Program Execution Support
13© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Swapping
Optimizes primary & secondary memory usage
Primary memory pages swapped out
When running out of memory
Secondary memory pages swapped in
When needed back
Linux maintains Page Cache in Primary Memory for
Code: Reloadable
Data: Unchanged vs Changed
Changed Data: Temporary (Dynamic) vs Persistent (Files)
Linux uses Swap (raw) partition on Secondary Memory
Related commands: mkswap, swapon/off
14© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
What all have we learnt?
W's of Memory Management?
Memory Partitioning
Segmentation & Paging
Memory Organization
Physical & Virtual Addressing
Working of an MMU
Memory Management in Linux
Swapping & Swap Partition
15© 2010-17 SysPlay Workshops <workshop@sysplay.in>
All Rights Reserved.
Any Queries?
Ad

More Related Content

What's hot (20)

Linux OS presentation
Linux OS presentationLinux OS presentation
Linux OS presentation
SahilGothoskar
 
Linux file system
Linux file systemLinux file system
Linux file system
Burhan Abbasi
 
Linux memory
Linux memoryLinux memory
Linux memory
ericrain911
 
Linux Internals - Kernel/Core
Linux Internals - Kernel/CoreLinux Internals - Kernel/Core
Linux Internals - Kernel/Core
Shay Cohen
 
Linux ppt
Linux pptLinux ppt
Linux ppt
lincy21
 
Linux File System
Linux File SystemLinux File System
Linux File System
Anil Kumar Pugalia
 
Linux kernel Architecture and Properties
Linux kernel Architecture and PropertiesLinux kernel Architecture and Properties
Linux kernel Architecture and Properties
Saadi Rahman
 
Operating system structures
Operating system structuresOperating system structures
Operating system structures
Mohd Arif
 
Consistency protocols
Consistency protocolsConsistency protocols
Consistency protocols
ZongYing Lyu
 
Linux command ppt
Linux command pptLinux command ppt
Linux command ppt
kalyanineve
 
Memory management
Memory managementMemory management
Memory management
Rajni Sirohi
 
Ipc in linux
Ipc in linuxIpc in linux
Ipc in linux
Dr. C.V. Suresh Babu
 
Distributed operating system
Distributed operating systemDistributed operating system
Distributed operating system
Prankit Mishra
 
Linux System Monitoring
Linux System Monitoring Linux System Monitoring
Linux System Monitoring
PriyaTeli
 
Linux commands
Linux commandsLinux commands
Linux commands
Mannu Khani
 
Linux scheduler
Linux schedulerLinux scheduler
Linux scheduler
Liran Ben Haim
 
Case study windows
Case study windowsCase study windows
Case study windows
Padam Banthia
 
Unix memory management
Unix memory managementUnix memory management
Unix memory management
Tech_MX
 
Linux
LinuxLinux
Linux
Gouthaman V
 
Storage management
Storage managementStorage management
Storage management
Atul Sharma
 
Linux Internals - Kernel/Core
Linux Internals - Kernel/CoreLinux Internals - Kernel/Core
Linux Internals - Kernel/Core
Shay Cohen
 
Linux ppt
Linux pptLinux ppt
Linux ppt
lincy21
 
Linux kernel Architecture and Properties
Linux kernel Architecture and PropertiesLinux kernel Architecture and Properties
Linux kernel Architecture and Properties
Saadi Rahman
 
Operating system structures
Operating system structuresOperating system structures
Operating system structures
Mohd Arif
 
Consistency protocols
Consistency protocolsConsistency protocols
Consistency protocols
ZongYing Lyu
 
Linux command ppt
Linux command pptLinux command ppt
Linux command ppt
kalyanineve
 
Distributed operating system
Distributed operating systemDistributed operating system
Distributed operating system
Prankit Mishra
 
Linux System Monitoring
Linux System Monitoring Linux System Monitoring
Linux System Monitoring
PriyaTeli
 
Unix memory management
Unix memory managementUnix memory management
Unix memory management
Tech_MX
 
Storage management
Storage managementStorage management
Storage management
Atul Sharma
 

Similar to Linux Memory Management (20)

Linux Kernel Overview
Linux Kernel OverviewLinux Kernel Overview
Linux Kernel Overview
Anil Kumar Pugalia
 
File System Modules
File System ModulesFile System Modules
File System Modules
Anil Kumar Pugalia
 
Block Drivers
Block DriversBlock Drivers
Block Drivers
Anil Kumar Pugalia
 
IT109 Microsoft Windows 7 Operating Systems Unit 01
IT109 Microsoft Windows 7 Operating Systems Unit 01IT109 Microsoft Windows 7 Operating Systems Unit 01
IT109 Microsoft Windows 7 Operating Systems Unit 01
blusmurfydot1
 
Introduction to Linux
Introduction to LinuxIntroduction to Linux
Introduction to Linux
Anil Kumar Pugalia
 
Memory Management in Android
Memory Management in AndroidMemory Management in Android
Memory Management in Android
Opersys inc.
 
File System Modules
File System ModulesFile System Modules
File System Modules
Anil Kumar Pugalia
 
Introduction to Linux
Introduction to LinuxIntroduction to Linux
Introduction to Linux
Anil Kumar Pugalia
 
Operating Systems
Operating SystemsOperating Systems
Operating Systems
We Learn - A Continuous Learning Forum from Welingkar's Distance Learning Program.
 
Embedded Software Design
Embedded Software DesignEmbedded Software Design
Embedded Software Design
Anil Kumar Pugalia
 
Memory Management in Android
Memory Management in AndroidMemory Management in Android
Memory Management in Android
Opersys inc.
 
Memory Management in Android
Memory Management in AndroidMemory Management in Android
Memory Management in Android
Opersys inc.
 
Operating Systems: The Core of Modern Computing – A Comprehensive Exploration...
Operating Systems: The Core of Modern Computing – A Comprehensive Exploration...Operating Systems: The Core of Modern Computing – A Comprehensive Exploration...
Operating Systems: The Core of Modern Computing – A Comprehensive Exploration...
chamod10
 
An Operating System (OS) presentation provides an overview of the fundamental...
An Operating System (OS) presentation provides an overview of the fundamental...An Operating System (OS) presentation provides an overview of the fundamental...
An Operating System (OS) presentation provides an overview of the fundamental...
chamod10
 
Oct2009
Oct2009Oct2009
Oct2009
guest81ab2b4
 
Evolution of the Windows Kernel Architecture, by Dave Probert
Evolution of the Windows Kernel Architecture, by Dave ProbertEvolution of the Windows Kernel Architecture, by Dave Probert
Evolution of the Windows Kernel Architecture, by Dave Probert
yang
 
2337610
23376102337610
2337610
hantfhan
 
Embedded Linux
Embedded LinuxEmbedded Linux
Embedded Linux
Quotient Technology Inc.
 
System Calls
System CallsSystem Calls
System Calls
Anil Kumar Pugalia
 
Principles of operating system
Principles of operating systemPrinciples of operating system
Principles of operating system
Anil Dharmapuri
 
IT109 Microsoft Windows 7 Operating Systems Unit 01
IT109 Microsoft Windows 7 Operating Systems Unit 01IT109 Microsoft Windows 7 Operating Systems Unit 01
IT109 Microsoft Windows 7 Operating Systems Unit 01
blusmurfydot1
 
Memory Management in Android
Memory Management in AndroidMemory Management in Android
Memory Management in Android
Opersys inc.
 
Memory Management in Android
Memory Management in AndroidMemory Management in Android
Memory Management in Android
Opersys inc.
 
Memory Management in Android
Memory Management in AndroidMemory Management in Android
Memory Management in Android
Opersys inc.
 
Operating Systems: The Core of Modern Computing – A Comprehensive Exploration...
Operating Systems: The Core of Modern Computing – A Comprehensive Exploration...Operating Systems: The Core of Modern Computing – A Comprehensive Exploration...
Operating Systems: The Core of Modern Computing – A Comprehensive Exploration...
chamod10
 
An Operating System (OS) presentation provides an overview of the fundamental...
An Operating System (OS) presentation provides an overview of the fundamental...An Operating System (OS) presentation provides an overview of the fundamental...
An Operating System (OS) presentation provides an overview of the fundamental...
chamod10
 
Evolution of the Windows Kernel Architecture, by Dave Probert
Evolution of the Windows Kernel Architecture, by Dave ProbertEvolution of the Windows Kernel Architecture, by Dave Probert
Evolution of the Windows Kernel Architecture, by Dave Probert
yang
 
Principles of operating system
Principles of operating systemPrinciples of operating system
Principles of operating system
Anil Dharmapuri
 
Ad

More from Anil Kumar Pugalia (20)

Kernel Debugging & Profiling
Kernel Debugging & ProfilingKernel Debugging & Profiling
Kernel Debugging & Profiling
Anil Kumar Pugalia
 
Processes
ProcessesProcesses
Processes
Anil Kumar Pugalia
 
System Calls
System CallsSystem Calls
System Calls
Anil Kumar Pugalia
 
Embedded C
Embedded CEmbedded C
Embedded C
Anil Kumar Pugalia
 
Playing with R L C Circuits
Playing with R L C CircuitsPlaying with R L C Circuits
Playing with R L C Circuits
Anil Kumar Pugalia
 
Audio Drivers
Audio DriversAudio Drivers
Audio Drivers
Anil Kumar Pugalia
 
Video Drivers
Video DriversVideo Drivers
Video Drivers
Anil Kumar Pugalia
 
Mobile Hacking using Linux Drivers
Mobile Hacking using Linux DriversMobile Hacking using Linux Drivers
Mobile Hacking using Linux Drivers
Anil Kumar Pugalia
 
Shell Scripting
Shell ScriptingShell Scripting
Shell Scripting
Anil Kumar Pugalia
 
References
ReferencesReferences
References
Anil Kumar Pugalia
 
Functional Programming with LISP
Functional Programming with LISPFunctional Programming with LISP
Functional Programming with LISP
Anil Kumar Pugalia
 
Power of vi
Power of viPower of vi
Power of vi
Anil Kumar Pugalia
 
gcc and friends
gcc and friendsgcc and friends
gcc and friends
Anil Kumar Pugalia
 
"make" system
"make" system"make" system
"make" system
Anil Kumar Pugalia
 
Hardware Design for Software Hackers
Hardware Design for Software HackersHardware Design for Software Hackers
Hardware Design for Software Hackers
Anil Kumar Pugalia
 
RPM Building
RPM BuildingRPM Building
RPM Building
Anil Kumar Pugalia
 
Linux User Space Debugging & Profiling
Linux User Space Debugging & ProfilingLinux User Space Debugging & Profiling
Linux User Space Debugging & Profiling
Anil Kumar Pugalia
 
Linux Network Management
Linux Network ManagementLinux Network Management
Linux Network Management
Anil Kumar Pugalia
 
Timers
TimersTimers
Timers
Anil Kumar Pugalia
 
Threads
ThreadsThreads
Threads
Anil Kumar Pugalia
 
Ad

Recently uploaded (20)

AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
HCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser Environments
panagenda
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
HCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser Environments
panagenda
 

Linux Memory Management

  • 1. © 2010-17 SysPlay Workshops <[email protected]> All Rights Reserved. Linux Memory Management
  • 2. 2© 2010-17 SysPlay Workshops <[email protected]> All Rights Reserved. What to Expect? W's of Memory Management? Memory Partitioning Memory Organization Memory Management in Linux Swapping
  • 3. 3© 2010-17 SysPlay Workshops <[email protected]> All Rights Reserved. Why Memory Management? Transition from Uni-process → Multi-process Every process needs its own memory Memory Division Program loaded to “any” available memory address Relocation Independence / Non-interference between Processes Protection Communication between Processes Sharing Process Memory with Attributes (like read only for code) Logical Organization Executing Programs bigger than available Memory Physical Organization (Overlaying & Reusing)
  • 4. 4© 2010-17 SysPlay Workshops <[email protected]> All Rights Reserved. What is Memory Management? Key task: Division of Memory Starting from the Division between OS (Kernel) Application (User) Others follow Relocation, Protection, Sharing Logical & Physical Organization May involve movement between primary & secondary
  • 5. 5© 2010-17 SysPlay Workshops <[email protected]> All Rights Reserved. Memory Partitioning Two traditional division mechanisms Segmentation: Unequal sized Examples: Linear Allocation, Buddy System Paging: Equal sized Examples: 4K-Paged Allocation Examples in Linux User-space malloc(): Segmentation Slab sub-system: Paging
  • 6. 6© 2010-17 SysPlay Workshops <[email protected]> All Rights Reserved. Pros & Cons Memory Fragmentation External in Segmentation (gets worser) Internal in Paging Space Efficiency Segmentation: More meta but lesser allocation wastage Paging: Negligible meta but significant allocation wastage Time Efficiency Segmentation: Complex search & Storage Algorithm Paging: Simple Algorithms
  • 7. 7© 2010-17 SysPlay Workshops <[email protected]> All Rights Reserved. Memory Organization All other needs (Relocation, Protection, Sharing, ...) Beautifully achieved by the concept of virtualization That is organizing the memory into Physical & Virtual Address Spaces And then using the virtual addressing for all purposes Both may use either Paging or Segmentation Best to use similar mechanisms Linux uses Paging for both with 4KiB/8KiB page size Virtualization can be achieved Using special hardware called MMU Using software MMU
  • 8. 8© 2010-17 SysPlay Workshops <[email protected]> All Rights Reserved. Memory Organization ... Linux Kernels (>= 2.5.46) support both Earlier kernels worked only with hardware MMU uClinux used to be the solution for non-MMU processors & controllers Latest Intel, ARM, and most other architectures have in-built MMU Older x86, ARM7, and few such doesn't have a hardware MMU
  • 9. 9© 2010-17 SysPlay Workshops <[email protected]> All Rights Reserved. Memory (RAM) Working of an MMU 1 1 0 1 Valid Tag Frame Number TLB (in Cache) 1 Page Table (in RAM) 1 1 1 0 1 0 1 1 0 1 Page Number [31:12] Offset [11:0] Virtual Address
  • 10. 10© 2010-17 SysPlay Workshops <[email protected]> All Rights Reserved. Memory Management in Linux In Linux, all these combined User Space & Kernel Space Memory Page Partitioning Physical & Virtual Address Spaces Device Addresses, Mapping & Access Takes the following form ...
  • 11. 11© 2010-17 SysPlay Workshops <[email protected]> All Rights Reserved. Memory Organization in Linux An Example assuming 32-bit architecture 4GB Process VA Space 1 User Space 4GB Process VA Space N . . . 3GB Virtual Address for User 1GB VA for Kernel Kernel Space (fixed by kernel) Logical Address (Non-swappable) Virtual Address (Swappable) 0x00000000 0xBFFFFFFF 0xFFFFFFFF 0xC0000000 Upto 3GB Memory (RAM) Addressing Upto 1GB Dev Addressing Physical Address Space (fixed by architecture) 0x00000000 0xBFFFFFFF 0xC0000000 0xFFFFFFFF Bus Address (incl. both h/w memory & registers) Physical Address (incl. only memory)
  • 12. 12© 2010-17 SysPlay Workshops <[email protected]> All Rights Reserved. Linux Memory Manager Provides Access Control to h/w & memory resources Provides Dynamic Memory to kernel sub-system Drivers File Systems Stacks Provides Virtual Memory to Kernel & User space Kernel & User Processes run in their own virtual address spaces Providing the various features of a Linux system System reliability, Security Communication Program Execution Support
  • 13. 13© 2010-17 SysPlay Workshops <[email protected]> All Rights Reserved. Swapping Optimizes primary & secondary memory usage Primary memory pages swapped out When running out of memory Secondary memory pages swapped in When needed back Linux maintains Page Cache in Primary Memory for Code: Reloadable Data: Unchanged vs Changed Changed Data: Temporary (Dynamic) vs Persistent (Files) Linux uses Swap (raw) partition on Secondary Memory Related commands: mkswap, swapon/off
  • 14. 14© 2010-17 SysPlay Workshops <[email protected]> All Rights Reserved. What all have we learnt? W's of Memory Management? Memory Partitioning Segmentation & Paging Memory Organization Physical & Virtual Addressing Working of an MMU Memory Management in Linux Swapping & Swap Partition
  • 15. 15© 2010-17 SysPlay Workshops <[email protected]> All Rights Reserved. Any Queries?