SlideShare a Scribd company logo
2
• Intel 8086
• Intel 80286
• Intel 80386
• Memory Management Unit
• Meltdown
• Malloc
• IOMMU
O V E R V I E W
3
4
Memory BUS
20 address lines (wires)
2^20 = 1MB addressable RAM
5
1 MB
of
RAM
0x0
0x10.0000
int main()
{
int *a = malloc();
...
}
Memory BUS
6
• No isolation between applications, as each application was accessing the physical
memory directly
Directly accessing
the RAM
7
8
Memory
access
Memory
access
• First attempt to use Virtual Memory through a Memory Management Unit
• A Protected Mode was just added, using different memory Segments for each
application
• Not widely adopted because of problems in backwards compatibility with 8086
9
10
MMU access
Physical
access
• Different from 80286: introduction of Paging support in the MMU
11
MMU access
Physical
access
Hey, I got 4 GB of RAM!
I’m all yours.
1 MB
of
RAM
4 GB
of
RAM
32-bit Address Bus,
accessing max. 4GB
of RAM
True Virtualization:
hiding the hardware,
overcommitting
12
Virtual
Memory
access
1 MB
of
RAM4 GB
of
RAM
Physical
Memory
access
int main()
{
int *a = malloc();
...
}
0x0
0x10.0000
0x0
0x1.0000.0000
13
14
RAM
1 MB
Page 0
Page 1
.
.
.
.
.
.
.
.
Page 256
• The memory is split into pages:
• By default 4KB pages
• 64 KB
• 2 MB (Huge Pages)
• 1GB (Huge Pages)
Using the default 4KB
pages, the RAM will be
split in 256 pages
15
RAM
Virtual Memory
CPU
0 GB
4 GB
0 MB
1 MB
16
RAM
1
4
2
3
CPU
MMU
Process A
Virtual Memory
1
2
3
4
• One advantage is that the application
sees a contiguous portion of memory
(e.g. Process A, pages 3 and 4)
for (int *i = 0x1000; i < 0x3000; i++)
*i = 0;
0x1000
0x3000
17
CPU RAM
Process A
Virtual Memory
1
2
3
4
Process B
Virtual Memory
1
2
3
1
3
2
4
1
2
3
MMU
18
RAM
1
Process A Page Table
4
Process A Page Table
2
3
Process A Page Directory
32 bit Virtual Address
4KB
(max.
1024
entries)
Page Directory
4KB
(max.
1024
entries)
Page Table
CPU
The first 10 bits point to an
offset within the PD
10 bits means 1024 values
The PD entry will point to a
Page Table
Process A Page Table
The last 12 bits point to the
offset inside the Process’
page
The CPU makes a
read/write to a 32-bit
address
The next 10 bits will point to
an offset within the
Page Table Entry
19
32 bit Virtual Address
Page Directory Page Table
CPU
Notice the 2 additional
memory accesses.
First
When cloning of a
process happens (a
new thread), it is
enough to copy the
entries in the PD to the
new PD
RAM
1
Process A Page Table
4
Process A Page Table
2
3
Process A Page Directory
Process A Page Table
The third one actually
gets the desired data.
Second
The bottom entries
point to lower Virtual
Memory (0GB +)
The upper entries
point to higher Virtual
Memory (4GB)
20
32 bit Virtual Address
Page Global Directory
(PGD)
Page Middle Directory
(PMD)
RAM
1
Process A Page Table
4
Process A Page Table
2
3
Process A Page Directory
Process A Page Table
In the Linux kernel, we
have the following
terms:
PGD, PMD, PTE Page Table Entry
PTE
21
32 bit Virtual Address
Page Global Directory
(PGD)
Page Middle Directory
(PMD)
PGD
RAM
1
Process A Page Table
4
Process A Page Table
2
3
Process A Page Directory
Process A Page Table
How the kernel stores
information about a
process
Page Table Entry
PTE
task_struct
Each process has a
pointer to a PGD
22
The CR3 keeps the physical
memory address, so that the
MMU can use it directly
Tricky question:
Why sometimes the CR3
value is higher than the
RAM size?
The CR3 (Control Register 3)
stores the PGD pointer
23
RAM
1
3
2
4
1
2
3
• Each process has its own set of page
tables (also stored in RAM)
CPU MMU
Process A
Virtual Memory
1
2
3
4
CR3
Process A - PGD
24
RAM
Process B
Virtual Memory
1
2
3
1
3
2
4
1
2
3
CPU MMU
Process B - PGD
Process A - PGD
CR3
Process B
25
/proc/meminfo
Total physical
memory (1GB)
The amount of RAM
consumed to keep
the page tables of all
processes
26
27
28
Process A
Virtual Memory
1
2
3
4
Process B
Virtual Memory
1
2
3
1
2
3
1
2
3
The user address space
of a process should be
in the 0GB-3GB range
The kernel’s pages,
mapped in each
user-space process
29
1024
entries
Process A
Virtual Memory
1
2
3
4
Process B
Virtual Memory
1
2
3
1
2
3
1
2
3
RAM
1
3
2
4
1
2
3
Process B - PGD
Process A - PGD
KERNEL - PGD
MMU
A single Page Table
for the Kernel
Page Global Directory
256
entries
768
entries
30
The Kernel’s Page
Table mostly use Huge
Pages
31
32
Process A
Virtual Memory
1
2
3
4
1
2
3
int main()
{
int *a = 0xC000.0000;
printf(“%dn”, *a);
}
The MMU makes the
translation and detects that
the Pages have the System
bit set, but the Instruction
Pointer is in user-space
MMU
The program will receive
SIGSEGV but can handle the
signal and can continue its
execution
The MMU sends an
Exception to the CPU
and the program
receives SIGSEGV
CPU
The MMU already
forwarded the data
to the CPU’s cache
CPU cache
Using a side-channel
attack on the cache, the
application can read the
kernel memory data
A pointer to
somewhere in the
kernel address
space
33
Process A
Virtual Memory
1
2
3
4
1
2
3
User Program connect()
System Call User Space
Kernel Space
Kernel
During the System Call, the
CR3 does not change, as
the Page Table already
contains the mapping
required by the kernel to
execute its code and
access its data.
34
User Program connect()
System Call User Space
Kernel Space
Kernel
Process A
Virtual Memory
(in kernel-space)
1
2
3
4
1
2
3
Process A
Virtual Memory
(in user-space)
1
2
3
4
1
2
3
A very very small kernel
region is still mapped at
each fork() in the new
process Page Table
(VDSO, vSyscall)
After Meltdown, at each
System Call, Interrupt or
Exception, the CR3 register
is changed to point to the
kernel’s Page Table
The cost for this protection?
A new page to store
Process A’s kernel’s PGD
But the memory
consumption is not the
problem.
Flushing the TLB cache
when changing the CR3
takes a big penalty.
After Meltdown, the kernel
manages two sets of PGD
for each process
35
36
vma_struct task_struct
vma_struct
vma_struct
vma_struct
vma_struct
The Linux kernel
object to represent a
process
The Linux kernel
object to represent a
virtual memory area
(start, end)
37
vma_struct task_struct
vma_struct
vma_struct
vma_struct
vma_struct
A mmap() call will
allocate a new VMA
and link it in the list
MMAP() call here
vma_struct
PGD
The first page of the
Virtual Address space is
intentionally left
unmapped, to catch
NULL pointers
SegFault
Minor fault, the
PGD/PMD/PTE will be
updated.
When cloning a new
process, the list is
iterated and copied to
the new process (except
for the Stack vma_struct)
38
• Malloc() will request the kernel to increase the
Heap area region, using mmap() or brk() system
calls
• After a malloc() call, the Page Tables are not yet
updated
• Only after the first read/write operation, the Page
Tables are updated and a physical page is
assigned (Minor Page Faults)
• If the page was swapped to disk, the kernel can
bring it back in RAM (Major Page Faults)
• If a read/write request with an address in
between the Stack and the Heap will result in a
Segmentation Fault (caught by the MMU
because the Page Tables do not contain the
requested page)
39
The /proc/PID/maps
prints info about each
VMA region
132KB virtual size
12KB physical size
RSS = Resident Set Size
40
• It doesn’t fail (or rarely fails)
• As with any virtualization technique, the Virtual
Memory overcommits
• When running low on physical memory (RAM),
the application will most likely SIGSEGV or the
OOM (Out of Memory) killer starts stopping
processes
Best setting not to
overcommit memory
Make your process less
likely to be picked by the
OOM killer
41
How much VM is each
process using (in KB)
How much RAM is
actually used (in KB)
How many Page Table
Entries are used for each
process
42
43
• Similar to how processes
are isolated between
each other by the MMU,
in the same way multiple
Devices can be isolated
• Page table walks must
be performed when the
Devices read/writes to a
Virtual Memory address
• Example: SR-IOV lets
Virtual Machines see a
dedicated Network Card
44
Questions?

More Related Content

What's hot

Linux memorymanagement
Linux memorymanagementLinux memorymanagement
Linux memorymanagement
pradeepelinux
 
ppt
pptppt
Memory organization
Memory organizationMemory organization
Memory organization
Dhaval Bagal
 
Linux memory
Linux memoryLinux memory
Linux memory
ericrain911
 
Memory Mapping Cache
Memory Mapping CacheMemory Mapping Cache
Memory Mapping Cache
Sajith Harshana
 
Ui disk & terminal drivers
Ui disk & terminal driversUi disk & terminal drivers
Ui disk & terminal drivers
Sarang Ananda Rao
 
Pdf micro
Pdf microPdf micro
Pdf micro
edwardkiwalabye1
 
Linux Memory Management with CMA (Contiguous Memory Allocator)
Linux Memory Management with CMA (Contiguous Memory Allocator)Linux Memory Management with CMA (Contiguous Memory Allocator)
Linux Memory Management with CMA (Contiguous Memory Allocator)
Pankaj Suryawanshi
 
Memory Management
Memory ManagementMemory Management
Memory Management
Rekha Karangiya
 
Topic 1 Data Representation
Topic 1 Data RepresentationTopic 1 Data Representation
Topic 1 Data Representation
Naruin
 
Hcs Topic 2 Computer Structure V2
Hcs Topic 2  Computer Structure V2Hcs Topic 2  Computer Structure V2
Hcs Topic 2 Computer Structure V2
ekul
 
Hcs Topic 2 Computer Structure V2
Hcs Topic 2  Computer Structure V2Hcs Topic 2  Computer Structure V2
Hcs Topic 2 Computer Structure V2
Naruin
 
Unix Memory Management - Operating Systems
Unix Memory Management - Operating SystemsUnix Memory Management - Operating Systems
Unix Memory Management - Operating Systems
Drishti Bhalla
 
Memory management in Linux kernel
Memory management in Linux kernelMemory management in Linux kernel
Memory management in Linux kernel
Vadim Nikitin
 
Computer System Architecture
Computer System ArchitectureComputer System Architecture
Computer System Architecture
Brenda Debra
 
Memory organization
Memory organizationMemory organization
Memory organization
ishapadhy
 
parallel processing
parallel processingparallel processing
parallel processing
Sufiyana Mujawar
 
Memory Organization | Computer Fundamental and Organization
Memory Organization | Computer Fundamental and OrganizationMemory Organization | Computer Fundamental and Organization
Memory Organization | Computer Fundamental and Organization
Smit Luvani
 
Computer System Architecture Lecture Note 8.2 Cache Memory
Computer System Architecture Lecture Note 8.2 Cache MemoryComputer System Architecture Lecture Note 8.2 Cache Memory
Computer System Architecture Lecture Note 8.2 Cache Memory
Budditha Hettige
 

What's hot (19)

Linux memorymanagement
Linux memorymanagementLinux memorymanagement
Linux memorymanagement
 
ppt
pptppt
ppt
 
Memory organization
Memory organizationMemory organization
Memory organization
 
Linux memory
Linux memoryLinux memory
Linux memory
 
Memory Mapping Cache
Memory Mapping CacheMemory Mapping Cache
Memory Mapping Cache
 
Ui disk & terminal drivers
Ui disk & terminal driversUi disk & terminal drivers
Ui disk & terminal drivers
 
Pdf micro
Pdf microPdf micro
Pdf micro
 
Linux Memory Management with CMA (Contiguous Memory Allocator)
Linux Memory Management with CMA (Contiguous Memory Allocator)Linux Memory Management with CMA (Contiguous Memory Allocator)
Linux Memory Management with CMA (Contiguous Memory Allocator)
 
Memory Management
Memory ManagementMemory Management
Memory Management
 
Topic 1 Data Representation
Topic 1 Data RepresentationTopic 1 Data Representation
Topic 1 Data Representation
 
Hcs Topic 2 Computer Structure V2
Hcs Topic 2  Computer Structure V2Hcs Topic 2  Computer Structure V2
Hcs Topic 2 Computer Structure V2
 
Hcs Topic 2 Computer Structure V2
Hcs Topic 2  Computer Structure V2Hcs Topic 2  Computer Structure V2
Hcs Topic 2 Computer Structure V2
 
Unix Memory Management - Operating Systems
Unix Memory Management - Operating SystemsUnix Memory Management - Operating Systems
Unix Memory Management - Operating Systems
 
Memory management in Linux kernel
Memory management in Linux kernelMemory management in Linux kernel
Memory management in Linux kernel
 
Computer System Architecture
Computer System ArchitectureComputer System Architecture
Computer System Architecture
 
Memory organization
Memory organizationMemory organization
Memory organization
 
parallel processing
parallel processingparallel processing
parallel processing
 
Memory Organization | Computer Fundamental and Organization
Memory Organization | Computer Fundamental and OrganizationMemory Organization | Computer Fundamental and Organization
Memory Organization | Computer Fundamental and Organization
 
Computer System Architecture Lecture Note 8.2 Cache Memory
Computer System Architecture Lecture Note 8.2 Cache MemoryComputer System Architecture Lecture Note 8.2 Cache Memory
Computer System Architecture Lecture Note 8.2 Cache Memory
 

Similar to Understanding the virtual memory - Ixia Connect #2

Module 4 advanced microprocessors
Module 4 advanced microprocessorsModule 4 advanced microprocessors
Module 4 advanced microprocessors
Deepak John
 
The 8086 Micro Processor Architecture By Dr. RidhaJemal
The 8086 Micro Processor Architecture By Dr. RidhaJemalThe 8086 Micro Processor Architecture By Dr. RidhaJemal
The 8086 Micro Processor Architecture By Dr. RidhaJemal
Anas Sa
 
Defense_Presentation
Defense_PresentationDefense_Presentation
Defense_Presentation
Debjyoti Majumder
 
Chp1 68000 microprocessor copy
Chp1 68000 microprocessor   copyChp1 68000 microprocessor   copy
Chp1 68000 microprocessor copy
mkazree
 
Microprocessor Unit -1 SE computer-II.pptx
Microprocessor  Unit -1 SE computer-II.pptxMicroprocessor  Unit -1 SE computer-II.pptx
Microprocessor Unit -1 SE computer-II.pptx
akshathsingh2003
 
Coa presentation3
Coa presentation3Coa presentation3
Coa presentation3
rickypatel151
 
memeoryorganization PPT for organization of memories
memeoryorganization PPT for organization of memoriesmemeoryorganization PPT for organization of memories
memeoryorganization PPT for organization of memories
GauravDaware2
 
Main Memory Management in Operating System
Main Memory Management in Operating SystemMain Memory Management in Operating System
Main Memory Management in Operating System
Rashmi Bhat
 
C++ Advanced Memory Management With Allocators
C++ Advanced Memory Management With AllocatorsC++ Advanced Memory Management With Allocators
C++ Advanced Memory Management With Allocators
GlobalLogic Ukraine
 
Exascale Capabl
Exascale CapablExascale Capabl
Exascale Capabl
Sagar Dolas
 
bit, Byte, Kilobyte
bit, Byte, Kilobyte bit, Byte, Kilobyte
bit, Byte, Kilobyte
Poliano123
 
COA Lecture 01(Introduction).pptx
COA Lecture 01(Introduction).pptxCOA Lecture 01(Introduction).pptx
COA Lecture 01(Introduction).pptx
syed rafi
 
U I - 4. 80386 Real mode.pptx
U I - 4. 80386 Real mode.pptxU I - 4. 80386 Real mode.pptx
U I - 4. 80386 Real mode.pptx
SangeetaShekhawatTri
 
Virtual Memory In Contemporary Microprocessors And 64-Bit Microprocessors Arc...
Virtual Memory In Contemporary Microprocessors And 64-Bit Microprocessors Arc...Virtual Memory In Contemporary Microprocessors And 64-Bit Microprocessors Arc...
Virtual Memory In Contemporary Microprocessors And 64-Bit Microprocessors Arc...
Anurag Deb
 
Components of System Unit
Components of System UnitComponents of System Unit
Components of System Unit
Afaq Siddiqui
 
ADVANCED MICROPROCESSORS featuers, block diagram and register organization.ppt
ADVANCED MICROPROCESSORS featuers, block diagram and register organization.pptADVANCED MICROPROCESSORS featuers, block diagram and register organization.ppt
ADVANCED MICROPROCESSORS featuers, block diagram and register organization.ppt
NaganarasaiahGoud
 
Data Manipulation
Data ManipulationData Manipulation
Data Manipulation
Asfi Bhai
 
Gpu computing workshop
Gpu computing workshopGpu computing workshop
Gpu computing workshop
datastack
 
Making a Process (Virtualizing Memory)
Making a Process (Virtualizing Memory)Making a Process (Virtualizing Memory)
Making a Process (Virtualizing Memory)
David Evans
 
Component of system unit.ppt
Component of system unit.pptComponent of system unit.ppt
Component of system unit.ppt
AhsanRamzan7
 

Similar to Understanding the virtual memory - Ixia Connect #2 (20)

Module 4 advanced microprocessors
Module 4 advanced microprocessorsModule 4 advanced microprocessors
Module 4 advanced microprocessors
 
The 8086 Micro Processor Architecture By Dr. RidhaJemal
The 8086 Micro Processor Architecture By Dr. RidhaJemalThe 8086 Micro Processor Architecture By Dr. RidhaJemal
The 8086 Micro Processor Architecture By Dr. RidhaJemal
 
Defense_Presentation
Defense_PresentationDefense_Presentation
Defense_Presentation
 
Chp1 68000 microprocessor copy
Chp1 68000 microprocessor   copyChp1 68000 microprocessor   copy
Chp1 68000 microprocessor copy
 
Microprocessor Unit -1 SE computer-II.pptx
Microprocessor  Unit -1 SE computer-II.pptxMicroprocessor  Unit -1 SE computer-II.pptx
Microprocessor Unit -1 SE computer-II.pptx
 
Coa presentation3
Coa presentation3Coa presentation3
Coa presentation3
 
memeoryorganization PPT for organization of memories
memeoryorganization PPT for organization of memoriesmemeoryorganization PPT for organization of memories
memeoryorganization PPT for organization of memories
 
Main Memory Management in Operating System
Main Memory Management in Operating SystemMain Memory Management in Operating System
Main Memory Management in Operating System
 
C++ Advanced Memory Management With Allocators
C++ Advanced Memory Management With AllocatorsC++ Advanced Memory Management With Allocators
C++ Advanced Memory Management With Allocators
 
Exascale Capabl
Exascale CapablExascale Capabl
Exascale Capabl
 
bit, Byte, Kilobyte
bit, Byte, Kilobyte bit, Byte, Kilobyte
bit, Byte, Kilobyte
 
COA Lecture 01(Introduction).pptx
COA Lecture 01(Introduction).pptxCOA Lecture 01(Introduction).pptx
COA Lecture 01(Introduction).pptx
 
U I - 4. 80386 Real mode.pptx
U I - 4. 80386 Real mode.pptxU I - 4. 80386 Real mode.pptx
U I - 4. 80386 Real mode.pptx
 
Virtual Memory In Contemporary Microprocessors And 64-Bit Microprocessors Arc...
Virtual Memory In Contemporary Microprocessors And 64-Bit Microprocessors Arc...Virtual Memory In Contemporary Microprocessors And 64-Bit Microprocessors Arc...
Virtual Memory In Contemporary Microprocessors And 64-Bit Microprocessors Arc...
 
Components of System Unit
Components of System UnitComponents of System Unit
Components of System Unit
 
ADVANCED MICROPROCESSORS featuers, block diagram and register organization.ppt
ADVANCED MICROPROCESSORS featuers, block diagram and register organization.pptADVANCED MICROPROCESSORS featuers, block diagram and register organization.ppt
ADVANCED MICROPROCESSORS featuers, block diagram and register organization.ppt
 
Data Manipulation
Data ManipulationData Manipulation
Data Manipulation
 
Gpu computing workshop
Gpu computing workshopGpu computing workshop
Gpu computing workshop
 
Making a Process (Virtualizing Memory)
Making a Process (Virtualizing Memory)Making a Process (Virtualizing Memory)
Making a Process (Virtualizing Memory)
 
Component of system unit.ppt
Component of system unit.pptComponent of system unit.ppt
Component of system unit.ppt
 

Recently uploaded

Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
Aftab Hussain
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
Sven Peters
 
How to write a program in any programming language
How to write a program in any programming languageHow to write a program in any programming language
How to write a program in any programming language
Rakesh Kumar R
 
E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
Hornet Dynamics
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CDKuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
rodomar2
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
Google
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
Alina Yurenko
 
E-commerce Application Development Company.pdf
E-commerce Application Development Company.pdfE-commerce Application Development Company.pdf
E-commerce Application Development Company.pdf
Hornet Dynamics
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Crescat
 
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
kalichargn70th171
 
Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
Remote DBA Services
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
Boni García
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
Łukasz Chruściel
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
Octavian Nadolu
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
TheSMSPoint
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
lorraineandreiamcidl
 

Recently uploaded (20)

Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
 
How to write a program in any programming language
How to write a program in any programming languageHow to write a program in any programming language
How to write a program in any programming language
 
E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CDKuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
 
E-commerce Application Development Company.pdf
E-commerce Application Development Company.pdfE-commerce Application Development Company.pdf
E-commerce Application Development Company.pdf
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
 
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
 
Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
 

Understanding the virtual memory - Ixia Connect #2

  • 1.
  • 2. 2 • Intel 8086 • Intel 80286 • Intel 80386 • Memory Management Unit • Meltdown • Malloc • IOMMU O V E R V I E W
  • 3. 3
  • 4. 4 Memory BUS 20 address lines (wires) 2^20 = 1MB addressable RAM
  • 5. 5 1 MB of RAM 0x0 0x10.0000 int main() { int *a = malloc(); ... } Memory BUS
  • 6. 6 • No isolation between applications, as each application was accessing the physical memory directly Directly accessing the RAM
  • 7. 7
  • 8. 8 Memory access Memory access • First attempt to use Virtual Memory through a Memory Management Unit • A Protected Mode was just added, using different memory Segments for each application • Not widely adopted because of problems in backwards compatibility with 8086
  • 9. 9
  • 10. 10 MMU access Physical access • Different from 80286: introduction of Paging support in the MMU
  • 11. 11 MMU access Physical access Hey, I got 4 GB of RAM! I’m all yours. 1 MB of RAM 4 GB of RAM 32-bit Address Bus, accessing max. 4GB of RAM True Virtualization: hiding the hardware, overcommitting
  • 12. 12 Virtual Memory access 1 MB of RAM4 GB of RAM Physical Memory access int main() { int *a = malloc(); ... } 0x0 0x10.0000 0x0 0x1.0000.0000
  • 13. 13
  • 14. 14 RAM 1 MB Page 0 Page 1 . . . . . . . . Page 256 • The memory is split into pages: • By default 4KB pages • 64 KB • 2 MB (Huge Pages) • 1GB (Huge Pages) Using the default 4KB pages, the RAM will be split in 256 pages
  • 16. 16 RAM 1 4 2 3 CPU MMU Process A Virtual Memory 1 2 3 4 • One advantage is that the application sees a contiguous portion of memory (e.g. Process A, pages 3 and 4) for (int *i = 0x1000; i < 0x3000; i++) *i = 0; 0x1000 0x3000
  • 17. 17 CPU RAM Process A Virtual Memory 1 2 3 4 Process B Virtual Memory 1 2 3 1 3 2 4 1 2 3 MMU
  • 18. 18 RAM 1 Process A Page Table 4 Process A Page Table 2 3 Process A Page Directory 32 bit Virtual Address 4KB (max. 1024 entries) Page Directory 4KB (max. 1024 entries) Page Table CPU The first 10 bits point to an offset within the PD 10 bits means 1024 values The PD entry will point to a Page Table Process A Page Table The last 12 bits point to the offset inside the Process’ page The CPU makes a read/write to a 32-bit address The next 10 bits will point to an offset within the Page Table Entry
  • 19. 19 32 bit Virtual Address Page Directory Page Table CPU Notice the 2 additional memory accesses. First When cloning of a process happens (a new thread), it is enough to copy the entries in the PD to the new PD RAM 1 Process A Page Table 4 Process A Page Table 2 3 Process A Page Directory Process A Page Table The third one actually gets the desired data. Second The bottom entries point to lower Virtual Memory (0GB +) The upper entries point to higher Virtual Memory (4GB)
  • 20. 20 32 bit Virtual Address Page Global Directory (PGD) Page Middle Directory (PMD) RAM 1 Process A Page Table 4 Process A Page Table 2 3 Process A Page Directory Process A Page Table In the Linux kernel, we have the following terms: PGD, PMD, PTE Page Table Entry PTE
  • 21. 21 32 bit Virtual Address Page Global Directory (PGD) Page Middle Directory (PMD) PGD RAM 1 Process A Page Table 4 Process A Page Table 2 3 Process A Page Directory Process A Page Table How the kernel stores information about a process Page Table Entry PTE task_struct Each process has a pointer to a PGD
  • 22. 22 The CR3 keeps the physical memory address, so that the MMU can use it directly Tricky question: Why sometimes the CR3 value is higher than the RAM size? The CR3 (Control Register 3) stores the PGD pointer
  • 23. 23 RAM 1 3 2 4 1 2 3 • Each process has its own set of page tables (also stored in RAM) CPU MMU Process A Virtual Memory 1 2 3 4 CR3 Process A - PGD
  • 24. 24 RAM Process B Virtual Memory 1 2 3 1 3 2 4 1 2 3 CPU MMU Process B - PGD Process A - PGD CR3 Process B
  • 25. 25 /proc/meminfo Total physical memory (1GB) The amount of RAM consumed to keep the page tables of all processes
  • 26. 26
  • 27. 27
  • 28. 28 Process A Virtual Memory 1 2 3 4 Process B Virtual Memory 1 2 3 1 2 3 1 2 3 The user address space of a process should be in the 0GB-3GB range The kernel’s pages, mapped in each user-space process
  • 29. 29 1024 entries Process A Virtual Memory 1 2 3 4 Process B Virtual Memory 1 2 3 1 2 3 1 2 3 RAM 1 3 2 4 1 2 3 Process B - PGD Process A - PGD KERNEL - PGD MMU A single Page Table for the Kernel Page Global Directory 256 entries 768 entries
  • 30. 30 The Kernel’s Page Table mostly use Huge Pages
  • 31. 31
  • 32. 32 Process A Virtual Memory 1 2 3 4 1 2 3 int main() { int *a = 0xC000.0000; printf(“%dn”, *a); } The MMU makes the translation and detects that the Pages have the System bit set, but the Instruction Pointer is in user-space MMU The program will receive SIGSEGV but can handle the signal and can continue its execution The MMU sends an Exception to the CPU and the program receives SIGSEGV CPU The MMU already forwarded the data to the CPU’s cache CPU cache Using a side-channel attack on the cache, the application can read the kernel memory data A pointer to somewhere in the kernel address space
  • 33. 33 Process A Virtual Memory 1 2 3 4 1 2 3 User Program connect() System Call User Space Kernel Space Kernel During the System Call, the CR3 does not change, as the Page Table already contains the mapping required by the kernel to execute its code and access its data.
  • 34. 34 User Program connect() System Call User Space Kernel Space Kernel Process A Virtual Memory (in kernel-space) 1 2 3 4 1 2 3 Process A Virtual Memory (in user-space) 1 2 3 4 1 2 3 A very very small kernel region is still mapped at each fork() in the new process Page Table (VDSO, vSyscall) After Meltdown, at each System Call, Interrupt or Exception, the CR3 register is changed to point to the kernel’s Page Table The cost for this protection? A new page to store Process A’s kernel’s PGD But the memory consumption is not the problem. Flushing the TLB cache when changing the CR3 takes a big penalty. After Meltdown, the kernel manages two sets of PGD for each process
  • 35. 35
  • 36. 36 vma_struct task_struct vma_struct vma_struct vma_struct vma_struct The Linux kernel object to represent a process The Linux kernel object to represent a virtual memory area (start, end)
  • 37. 37 vma_struct task_struct vma_struct vma_struct vma_struct vma_struct A mmap() call will allocate a new VMA and link it in the list MMAP() call here vma_struct PGD The first page of the Virtual Address space is intentionally left unmapped, to catch NULL pointers SegFault Minor fault, the PGD/PMD/PTE will be updated. When cloning a new process, the list is iterated and copied to the new process (except for the Stack vma_struct)
  • 38. 38 • Malloc() will request the kernel to increase the Heap area region, using mmap() or brk() system calls • After a malloc() call, the Page Tables are not yet updated • Only after the first read/write operation, the Page Tables are updated and a physical page is assigned (Minor Page Faults) • If the page was swapped to disk, the kernel can bring it back in RAM (Major Page Faults) • If a read/write request with an address in between the Stack and the Heap will result in a Segmentation Fault (caught by the MMU because the Page Tables do not contain the requested page)
  • 39. 39 The /proc/PID/maps prints info about each VMA region 132KB virtual size 12KB physical size RSS = Resident Set Size
  • 40. 40 • It doesn’t fail (or rarely fails) • As with any virtualization technique, the Virtual Memory overcommits • When running low on physical memory (RAM), the application will most likely SIGSEGV or the OOM (Out of Memory) killer starts stopping processes Best setting not to overcommit memory Make your process less likely to be picked by the OOM killer
  • 41. 41 How much VM is each process using (in KB) How much RAM is actually used (in KB) How many Page Table Entries are used for each process
  • 42. 42
  • 43. 43 • Similar to how processes are isolated between each other by the MMU, in the same way multiple Devices can be isolated • Page table walks must be performed when the Devices read/writes to a Virtual Memory address • Example: SR-IOV lets Virtual Machines see a dedicated Network Card