SlideShare une entreprise Scribd logo
1  sur  15
© 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?

Contenu connexe

Tendances

Linux process management
Linux process managementLinux process management
Linux process managementRaghu nath
 
Linux kernel Architecture and Properties
Linux kernel Architecture and PropertiesLinux kernel Architecture and Properties
Linux kernel Architecture and PropertiesSaadi Rahman
 
Linux scheduling and input and output
Linux scheduling and input and outputLinux scheduling and input and output
Linux scheduling and input and outputSanidhya Chugh
 
Disk and File System Management in Linux
Disk and File System Management in LinuxDisk and File System Management in Linux
Disk and File System Management in LinuxHenry Osborne
 
Block I/O Layer Tracing: blktrace
Block I/O Layer Tracing: blktraceBlock I/O Layer Tracing: blktrace
Block I/O Layer Tracing: blktraceBabak Farrokhi
 
Operating System 2
Operating System 2Operating System 2
Operating System 2tech2click
 
Operating system structures
Operating system structuresOperating system structures
Operating system structuresMohd Arif
 
Basics of boot-loader
Basics of boot-loaderBasics of boot-loader
Basics of boot-loaderiamumr
 
Linux memory-management-kamal
Linux memory-management-kamalLinux memory-management-kamal
Linux memory-management-kamalKamal Maiti
 
Chapter 11 - File System Implementation
Chapter 11 - File System ImplementationChapter 11 - File System Implementation
Chapter 11 - File System ImplementationWayne Jones Jnr
 
Linux architecture
Linux architectureLinux architecture
Linux architecturemcganesh
 

Tendances (20)

Input output in linux
Input output in linuxInput output in linux
Input output in linux
 
Linux File System
Linux File SystemLinux File System
Linux File System
 
Linux process management
Linux process managementLinux process management
Linux process management
 
Linux kernel Architecture and Properties
Linux kernel Architecture and PropertiesLinux kernel Architecture and Properties
Linux kernel Architecture and Properties
 
Linux kernel
Linux kernelLinux kernel
Linux kernel
 
Linux Internals - Interview essentials 4.0
Linux Internals - Interview essentials 4.0Linux Internals - Interview essentials 4.0
Linux Internals - Interview essentials 4.0
 
Linux scheduling and input and output
Linux scheduling and input and outputLinux scheduling and input and output
Linux scheduling and input and output
 
Disk and File System Management in Linux
Disk and File System Management in LinuxDisk and File System Management in Linux
Disk and File System Management in Linux
 
Linux file system
Linux file systemLinux file system
Linux file system
 
Block I/O Layer Tracing: blktrace
Block I/O Layer Tracing: blktraceBlock I/O Layer Tracing: blktrace
Block I/O Layer Tracing: blktrace
 
Operating System 2
Operating System 2Operating System 2
Operating System 2
 
Operating system structures
Operating system structuresOperating system structures
Operating system structures
 
Basics of boot-loader
Basics of boot-loaderBasics of boot-loader
Basics of boot-loader
 
Linux memory-management-kamal
Linux memory-management-kamalLinux memory-management-kamal
Linux memory-management-kamal
 
Chapter 11 - File System Implementation
Chapter 11 - File System ImplementationChapter 11 - File System Implementation
Chapter 11 - File System Implementation
 
linux kernel overview 2013
linux kernel overview 2013linux kernel overview 2013
linux kernel overview 2013
 
Linux scheduler
Linux schedulerLinux scheduler
Linux scheduler
 
Linux architecture
Linux architectureLinux architecture
Linux architecture
 
operating system structure
operating system structureoperating system structure
operating system structure
 
Linux file system
Linux file systemLinux file system
Linux file system
 

Similaire à Linux Memory Management (20)

Linux Kernel Overview
Linux Kernel OverviewLinux Kernel Overview
Linux Kernel Overview
 
File System Modules
File System ModulesFile System Modules
File System Modules
 
Block Drivers
Block DriversBlock Drivers
Block Drivers
 
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
 
Introduction to Linux
Introduction to LinuxIntroduction to Linux
Introduction to Linux
 
Memory Management in Android
Memory Management in AndroidMemory Management in Android
Memory Management in Android
 
File System Modules
File System ModulesFile System Modules
File System Modules
 
Introduction to Linux
Introduction to LinuxIntroduction to Linux
Introduction to Linux
 
Operating Systems
Operating SystemsOperating Systems
Operating Systems
 
Embedded Software Design
Embedded Software DesignEmbedded Software Design
Embedded Software Design
 
Memory Management in Android
Memory Management in AndroidMemory Management in Android
Memory Management in Android
 
Memory Management in Android
Memory Management in AndroidMemory Management in Android
Memory Management in Android
 
Oct2009
Oct2009Oct2009
Oct2009
 
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
 
2337610
23376102337610
2337610
 
Embedded Linux
Embedded LinuxEmbedded Linux
Embedded Linux
 
System Calls
System CallsSystem Calls
System Calls
 
Principles of operating system
Principles of operating systemPrinciples of operating system
Principles of operating system
 
Memory Management in Android
Memory Management in AndroidMemory Management in Android
Memory Management in Android
 
Low-level Accesses
Low-level AccessesLow-level Accesses
Low-level Accesses
 

Plus de Anil Kumar Pugalia (20)

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

Dernier

Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
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
 
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...Martijn de Jong
 
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.pdfUK Journal
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
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
 
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
 
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 RobisonAnna Loughnan Colquhoun
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
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
 
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
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
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
 
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
 
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
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
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 productivityPrincipled Technologies
 

Dernier (20)

Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
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
 
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...
 
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
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
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
 
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
 
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
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
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?
 
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
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
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
 
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
 
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
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
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
 

Linux Memory Management

  • 1. © 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Linux Memory Management
  • 2. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 15© 2010-17 SysPlay Workshops <workshop@sysplay.in> All Rights Reserved. Any Queries?