SlideShare uma empresa Scribd logo
1 de 41
Plan for Today
Recap: Virtualizing Memory
Segmentation Faults
Page Faults: Challenge winner!
Processes, Threads, Tasks
1
PS2 is Due Sunday
Exam 1 is out after
class Tuesday (Feb
11) due 11:59pm
Thursday (Feb 13) –
open resources,
most questions will
be taken from notes
PS2 Demos
Everyone should be signed up
If you can’t find a time that works for
your team, let me know by tomorrow
At the scheduled start time and place:
Your full team should be present
One of you should have:
– Your code ready to show in your
favorite editor
– Your gash ready to run
2
PS2 autograder and
submission will be posted by
Friday (if I forget, but no one
reminds me, there won’t be
an extension like for PS1!)
If your team is not ready to go
at your scheduled time (no
grace period!), your demo is
cancelled and you need to
schedule a new one with me.
386 Checkup
3
Dir Page Offset
CR3
Page
Directory
Page Table
Physical
Memory
20 bits addr / 12 bits flags
Page + Offset
12 bits
(4K pages)
10 bits
(1K tables)
10 bits
(1K entries)
32-bit linear address
How big is the page table on my MacBook Pro?
1024 entries
× 4 bytes/entry
= 4096 bytes = 1 page
222 < 4.3M
Intel 386
4
386 introduced in 1985:
1 MB $500
Original Macintosh (Jan 1984)
$2495
128KB RAM
(later in 1984: 512K version)
Windows 1.0 (Nov 1985)
required 192 KB of RAM
386 Design Checkup
5
CR3
Page
Directory
Page Table
Physical
Memory
20 bits addr / 12 bits flags
Page + Offset
386 Design Fail!
6
CR3
Page
Directory
Page Table
Physical
Memory
20 bits addr / 12 bits flags
Page + Offset
264 addressable locations
/ 212 locations/page
= 252 pages
Page table would require 254 bytes $17B (eBay annual revenues) worth of RAM!
Solution?
7
Page Table
Physical
Memory
20 bits addr / 12 bits flags
Page + Offset
Page + Offset
base basebasebase
Multi-Level (Hierarchical) Page Tables
8
Unused L1 Page Offset
12 bits16 bits 9 bits
64 (-16)-bit x86 linear address
L2 Page L3 Page
9 bits 9 bits
L4 Page
9 bits
CR3
L1 Page
Table
+ L1 Index
L2 Page
Table
+ L2 Index
L3 Page
Table
+ L3 Index
L4 Page
Table
+ L4 Index
Physical
Memory
Page + Offset
Do we still need segmentation?
9
LogicalAddress
Segmentation
Unit
LinearAddress
Paging
Unit
PhysicalAddress
Memory
Page + Offset
base basebasebase
10
Unused L1 Page Offset
12 bits16 bits 9 bits
L2 Page L3 Page
9 bits 9 bits
L4 Page
9 bits
CR3
L1 Page
Table
+ L1 Index
L2 Page
Table
+ L2 Index
L3 Page
Table
+ L3 Index
L4 Page
Table
+ L4 Index
Physical
Memory
Page + Offset
Where are all the L2, L3, and L4 page tables?
Page + Offset
base basebasebase
11
Unused L1 Page Offset
12 bits16 bits 9 bits
L2 Page L3 Page
9 bits 9 bits
L4 Page
9 bits
CR3
L1 Page
Table
+ L1 Index
L2 Page
Table
+ L2 Index
L3 Page
Table
+ L3 Index
L4 Page
Table
+ L4 Index
Physical
Memory
Page + Offset
Why is each page 512 entries instead of 1024?
Page + Offset
base basebasebase
12
Unused L1 Page Offset
12 bits16 bits 9 bits
L2 Page L3 Page
9 bits 9 bits
L4 Page
9 bits
CR3
L1 Page
Table
+ L1 Index
L2 Page
Table
+ L2 Index
L3 Page
Table
+ L3 Index
L4 Page
Table
+ L4 Index
Physical
Memory
Page + Offset
Why is the page size still 4K? (x86 can support 2MB pages)
Page + Offset
base basebasebase
13
Unused L1 Page Offset
12 bits16 bits 9 bits
L2 Page L3 Page
9 bits 9 bits
L4 Page
9 bits
CR3
L1 Page
Table
+ L1 Index
L2 Page
Table
+ L2 Index
L3 Page
Table
+ L3 Index
L4 Page
Table
+ L4 Index
Physical
Memory
Page + Offset
What would you do instead if you cared about saving energy
more than saving silicon?
All x86 all the time?
14
15
16
Dave: “Don’t buy bitcoins!”
17
ARMv8-A 64-bit processor
(ISA licensed by ARM, designed by
Apple, manufactured by Samsung)
18
19
Is 256TB enough?
Is 256TB enough?
20
“This design gives us a 256TB
address space, which should be
enough for a while. If memory
prices continue to fall so that
the cost of memory halves every
year (a bit faster than it has
been doing historically),
handheld computers will come
with 256TB in about 20 years.
By then, I expect ARMv9 to be
released.”
David Chisnall, A Look at the 64-
Bit ARMv8 Architecture
21
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv) {
char *s = (char *) malloc (1);
int i = 0;
while (1) {
printf("%d: %lx / %dn", i, s + i, i[s]);
i += 1;
}
}
What will this program do?
22
int main(int argc, char **argv) {
char *s = (char *) malloc (1);
int i = 0;
while (1) {
printf("%d: %lx / %dn", i, s + i, i[s]);
i += 1;
}
} gash> gcc -Wall segfault.c
segfault.c: In function ‘main’:
segfault.c:8: warning: format ‘%lx’ expects type ‘long unsigned
int’, but argument 3 has type ‘char *’
segfault.c:8: warning: format ‘%lx’ expects type ‘long unsigned
int’, but argument 3 has type ‘char *’
What causes a segmentation fault?
23
What causes a segmentation fault?
24
Page + Offset
base basebasebase
12 bits16 bits 9 bits 9 bits 9 bits 9 bits
CR3
L1 Page
Table
+ L1 Index
L2 Page
Table
+ L2 Index
L3 Page
Table
+ L3 Index
L4 Page
Table
+ L4 Index
Physical
Memory
Page + Offset
Unused L1 Page OffsetL2 Page L3 Page L4 Page
25
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv) {
char *s = (char *) malloc (1);
int i = 0;
while (1) {
printf("%d: %lx / %dn",
i, s + i, i[s]);
i += 1;
}
}
> ./a.out
0: 7ff7004039a0 / 0
1: 7ff7004039a1 / 0
2: 7ff7004039a2 / 0
…
95: 7ff7004039ff / 0
…
1033819: 7ff7004ffffb / 0
1033820: 7ff7004ffffc / 0
1033821: 7ff7004ffffd / 0
1033822: 7ff7004ffffe / 0
1033823: 7ff7004fffff / 0
Segmentation fault: 11
What causes a page fault?
26
Page + Offset
base basebasebase
12 bits16 bits 9 bits 9 bits 9 bits 9 bits
CR3
L1 Page
Table
+ L1 Index
L2 Page
Table
+ L2 Index
L3 Page
Table
+ L3 Index
L4 Page
Table
+ L4 Index
Physical
Memory
Page + Offset
Unused L1 Page OffsetL2 Page L3 Page L4 Page
What causes a page fault?
27
base
Page
Table
+ L1 Index
Challenge from Last Class
28
Challenge: Write a program that
takes N as an input and produces
(nearly) exactly N page faults. A
good solution is worth a USS
Hopper patch (even cooler than a
Rust sticker!) or an exemption from
Exam 1 or Exam 2.
Winner:
Michael Recachinas
Faults Summary
Segmentation Fault:
Process attempts to access memory that is not in its memory
space (or write to memory that is read-only)
Should never happen
Page Fault:
Process attempts to access memory that is not currently
available.
Happens hundreds of times before your code even
starts running!
29
Processes,
Threads, and Tasks
30
Process
Originally: abstraction
for owning the whole
machine
31
Thread
(Illusion or reality of)
independent sequence
of instructions
Whatdoyouneed:
32
Own program counter
Own stack, registers
Own memory space
Own program counter
Own stack, registers
Shares memory space
Process
Originally: abstraction
for owning the whole
machine
Thread
(Illusion or reality of)
independent sequence
of instructions
Whatdoyouneed:
Tasks
in Rust
33
Tasks
Thread
Own PC
Own stack, registers
Safely shared immutable memory
Safely independent own memory
34
fn spawn(f: proc ())
spawn( proc() {
println(“Get to work!”);
});
Task = Thread – unsafe memory sharing
or
Task = Process + safe memory sharing – cost of OS process
35
How can we take
advantage of more cores
to find Collatz results
faster?
fn collatz_steps(n: int) -> int {
if n == 1 {
0
} else {
1 + collatz_steps(if n % 2 == 0 { n / 2 } else { 3 * n + 1 })
}
}
fn find_collatz(k: int) -> int {
// Returns the minimum value, n, with Collatz steps >= k.
let mut n = 1;
while collatz_steps(n) < k { n += 1; }
n
}
36
fn find_collatz(k: int) -> int {
let mut n = 1;
loop {
let val = n;
spawn(proc() {
if collatz_steps(val) > k {
println!("Result: {}", val);
}
});
n += 1;
}
}
Channels
37
let (port, chan) : (Port<T>, Chan<T>) = Chan::new();
chan.send(T); T = port.recv();
Asynchronous Synchronous
38
fn find_collatz(k: int) -> int {
let mut n = 1;
let (port, chan) : (Port<int>, Chan<int>) = Chan::new();
spawn(proc() {
loop {
let val = n;
spawn(proc() {
if collatz_steps(val) > k { chan.send(val); }
});
n += 1;
}
let n = port.recv();
n
}
Not going to work…
39
fn find_collatz(k: int) -> int {
let mut n = 1;
let max_tasks = 7; // keep all my cores busy
let mut found_result = false;
let mut result = -1; // need to initialize
while !found_result {
let mut ports = ~[];
for i in range(0, max_tasks) {
let val = n + i;
let (port, chan) : (Port<int>, Chan<int>) = Chan::new();
ports.push(port);
spawn(proc() {
let steps = collatz_steps(val);
println!("Result for {}: {}", val, steps);
chan.send(steps);
});
}
for i in range(0, max_tasks) {
let port = ports.pop();
let steps = port.recv();
if steps > k {
found_result = true;
result = n + i;
}
}
n += max_tasks;
}
assert!(result != -1);
result
}
Charge
40
PS2 is Due Sunday
Exam 1 is out after class Tuesday
(Feb 11) due 11:59pm Thursday
(Feb 13) – open resources, most
questions will be taken from notes
Everyone should have
scheduled PS2 demo!
or…Challenge: make a good
multi-tasking find_collatz (at
least 6x speedup)

Mais conteúdo relacionado

Mais procurados

SSL Failing, Sharing, and Scheduling
SSL Failing, Sharing, and SchedulingSSL Failing, Sharing, and Scheduling
SSL Failing, Sharing, and SchedulingDavid Evans
 
Kernel Recipes 2019 - GNU poke, an extensible editor for structured binary data
Kernel Recipes 2019 - GNU poke, an extensible editor for structured binary dataKernel Recipes 2019 - GNU poke, an extensible editor for structured binary data
Kernel Recipes 2019 - GNU poke, an extensible editor for structured binary dataAnne Nicolas
 
Virtual Memory (Making a Process)
Virtual Memory (Making a Process)Virtual Memory (Making a Process)
Virtual Memory (Making a Process)David Evans
 
Crossing into Kernel Space
Crossing into Kernel SpaceCrossing into Kernel Space
Crossing into Kernel SpaceDavid Evans
 
Putting a Fork in Fork (Linux Process and Memory Management)
Putting a Fork in Fork (Linux Process and Memory Management)Putting a Fork in Fork (Linux Process and Memory Management)
Putting a Fork in Fork (Linux Process and Memory Management)David Evans
 
Making a Process
Making a ProcessMaking a Process
Making a ProcessDavid Evans
 
Smarter Scheduling
Smarter SchedulingSmarter Scheduling
Smarter SchedulingDavid Evans
 
Spectre(v1%2 fv2%2fv4) v.s. meltdown(v3)
Spectre(v1%2 fv2%2fv4) v.s. meltdown(v3)Spectre(v1%2 fv2%2fv4) v.s. meltdown(v3)
Spectre(v1%2 fv2%2fv4) v.s. meltdown(v3)Gavin Guo
 
Code gpu with cuda - CUDA introduction
Code gpu with cuda - CUDA introductionCode gpu with cuda - CUDA introduction
Code gpu with cuda - CUDA introductionMarina Kolpakova
 
Alternative cryptocurrencies
Alternative cryptocurrencies Alternative cryptocurrencies
Alternative cryptocurrencies vpnmentor
 
Next Generation Indexes For Big Data Engineering (ODSC East 2018)
Next Generation Indexes For Big Data Engineering (ODSC East 2018)Next Generation Indexes For Big Data Engineering (ODSC East 2018)
Next Generation Indexes For Big Data Engineering (ODSC East 2018)Daniel Lemire
 
Code GPU with CUDA - Identifying performance limiters
Code GPU with CUDA - Identifying performance limitersCode GPU with CUDA - Identifying performance limiters
Code GPU with CUDA - Identifying performance limitersMarina Kolpakova
 
Multi-Tasking Map (MapReduce, Tasks in Rust)
Multi-Tasking Map (MapReduce, Tasks in Rust)Multi-Tasking Map (MapReduce, Tasks in Rust)
Multi-Tasking Map (MapReduce, Tasks in Rust)David Evans
 
pa-pe-pi-po-pure Python Text Processing
pa-pe-pi-po-pure Python Text Processingpa-pe-pi-po-pure Python Text Processing
pa-pe-pi-po-pure Python Text ProcessingRodrigo Senra
 

Mais procurados (20)

SSL Failing, Sharing, and Scheduling
SSL Failing, Sharing, and SchedulingSSL Failing, Sharing, and Scheduling
SSL Failing, Sharing, and Scheduling
 
System Calls
System CallsSystem Calls
System Calls
 
Kernel Recipes 2019 - GNU poke, an extensible editor for structured binary data
Kernel Recipes 2019 - GNU poke, an extensible editor for structured binary dataKernel Recipes 2019 - GNU poke, an extensible editor for structured binary data
Kernel Recipes 2019 - GNU poke, an extensible editor for structured binary data
 
Virtual Memory (Making a Process)
Virtual Memory (Making a Process)Virtual Memory (Making a Process)
Virtual Memory (Making a Process)
 
Crossing into Kernel Space
Crossing into Kernel SpaceCrossing into Kernel Space
Crossing into Kernel Space
 
Putting a Fork in Fork (Linux Process and Memory Management)
Putting a Fork in Fork (Linux Process and Memory Management)Putting a Fork in Fork (Linux Process and Memory Management)
Putting a Fork in Fork (Linux Process and Memory Management)
 
Making a Process
Making a ProcessMaking a Process
Making a Process
 
Scheduling
SchedulingScheduling
Scheduling
 
Smarter Scheduling
Smarter SchedulingSmarter Scheduling
Smarter Scheduling
 
Spectre(v1%2 fv2%2fv4) v.s. meltdown(v3)
Spectre(v1%2 fv2%2fv4) v.s. meltdown(v3)Spectre(v1%2 fv2%2fv4) v.s. meltdown(v3)
Spectre(v1%2 fv2%2fv4) v.s. meltdown(v3)
 
Code gpu with cuda - CUDA introduction
Code gpu with cuda - CUDA introductionCode gpu with cuda - CUDA introduction
Code gpu with cuda - CUDA introduction
 
Alternative cryptocurrencies
Alternative cryptocurrencies Alternative cryptocurrencies
Alternative cryptocurrencies
 
Programar para GPUs
Programar para GPUsProgramar para GPUs
Programar para GPUs
 
Next Generation Indexes For Big Data Engineering (ODSC East 2018)
Next Generation Indexes For Big Data Engineering (ODSC East 2018)Next Generation Indexes For Big Data Engineering (ODSC East 2018)
Next Generation Indexes For Big Data Engineering (ODSC East 2018)
 
Computer Science Homework Help
Computer Science Homework HelpComputer Science Homework Help
Computer Science Homework Help
 
Code GPU with CUDA - Identifying performance limiters
Code GPU with CUDA - Identifying performance limitersCode GPU with CUDA - Identifying performance limiters
Code GPU with CUDA - Identifying performance limiters
 
Meltdown & spectre
Meltdown & spectreMeltdown & spectre
Meltdown & spectre
 
Multi-Tasking Map (MapReduce, Tasks in Rust)
Multi-Tasking Map (MapReduce, Tasks in Rust)Multi-Tasking Map (MapReduce, Tasks in Rust)
Multi-Tasking Map (MapReduce, Tasks in Rust)
 
pa-pe-pi-po-pure Python Text Processing
pa-pe-pi-po-pure Python Text Processingpa-pe-pi-po-pure Python Text Processing
pa-pe-pi-po-pure Python Text Processing
 
Operating System Assignment Help
Operating System Assignment HelpOperating System Assignment Help
Operating System Assignment Help
 

Semelhante a Segmentation Faults, Page Faults, Processes, Threads, and Tasks

Everyday I'm Shuffling - Tips for Writing Better Spark Programs, Strata San J...
Everyday I'm Shuffling - Tips for Writing Better Spark Programs, Strata San J...Everyday I'm Shuffling - Tips for Writing Better Spark Programs, Strata San J...
Everyday I'm Shuffling - Tips for Writing Better Spark Programs, Strata San J...Databricks
 
Don't Call It a Comeback: Attribute Grammars for Big Data Visualization
Don't Call It a Comeback: Attribute Grammars for Big Data VisualizationDon't Call It a Comeback: Attribute Grammars for Big Data Visualization
Don't Call It a Comeback: Attribute Grammars for Big Data VisualizationLeo Meyerovich
 
Class 16: Making Loops
Class 16: Making LoopsClass 16: Making Loops
Class 16: Making LoopsDavid Evans
 
2 Years of Real World FP at REA
2 Years of Real World FP at REA2 Years of Real World FP at REA
2 Years of Real World FP at REAkenbot
 
Address/Thread/Memory Sanitizer
Address/Thread/Memory SanitizerAddress/Thread/Memory Sanitizer
Address/Thread/Memory SanitizerPlatonov Sergey
 
NVIDIA HPC ソフトウエア斜め読み
NVIDIA HPC ソフトウエア斜め読みNVIDIA HPC ソフトウエア斜め読み
NVIDIA HPC ソフトウエア斜め読みNVIDIA Japan
 
lecture16-recap-questions-and-answers.pdf
lecture16-recap-questions-and-answers.pdflecture16-recap-questions-and-answers.pdf
lecture16-recap-questions-and-answers.pdfAyushKumar93531
 
LECTURE2 td 2 sue les theories de graphes
LECTURE2 td 2 sue les theories de graphesLECTURE2 td 2 sue les theories de graphes
LECTURE2 td 2 sue les theories de graphesAhmedMahjoub15
 
EMBEDDED SYSTEMS 4&5
EMBEDDED SYSTEMS 4&5EMBEDDED SYSTEMS 4&5
EMBEDDED SYSTEMS 4&5PRADEEP
 
23_Advanced_Processors controller system
23_Advanced_Processors controller system23_Advanced_Processors controller system
23_Advanced_Processors controller systemstellan7
 
Lec18 Intro to Computer Engineering by Hsien-Hsin Sean Lee Georgia Tech -- In...
Lec18 Intro to Computer Engineering by Hsien-Hsin Sean Lee Georgia Tech -- In...Lec18 Intro to Computer Engineering by Hsien-Hsin Sean Lee Georgia Tech -- In...
Lec18 Intro to Computer Engineering by Hsien-Hsin Sean Lee Georgia Tech -- In...Hsien-Hsin Sean Lee, Ph.D.
 
Apache Flink internals
Apache Flink internalsApache Flink internals
Apache Flink internalsKostas Tzoumas
 
Memory Optimization
Memory OptimizationMemory Optimization
Memory Optimizationguest3eed30
 
Memory Optimization
Memory OptimizationMemory Optimization
Memory OptimizationWei Lin
 
Swug July 2010 - windows debugging by sainath
Swug July 2010 - windows debugging by sainathSwug July 2010 - windows debugging by sainath
Swug July 2010 - windows debugging by sainathDennis Chung
 
Efficient Data Storage for Analytics with Apache Parquet 2.0
Efficient Data Storage for Analytics with Apache Parquet 2.0Efficient Data Storage for Analytics with Apache Parquet 2.0
Efficient Data Storage for Analytics with Apache Parquet 2.0Cloudera, Inc.
 

Semelhante a Segmentation Faults, Page Faults, Processes, Threads, and Tasks (20)

Everyday I'm Shuffling - Tips for Writing Better Spark Programs, Strata San J...
Everyday I'm Shuffling - Tips for Writing Better Spark Programs, Strata San J...Everyday I'm Shuffling - Tips for Writing Better Spark Programs, Strata San J...
Everyday I'm Shuffling - Tips for Writing Better Spark Programs, Strata San J...
 
Don't Call It a Comeback: Attribute Grammars for Big Data Visualization
Don't Call It a Comeback: Attribute Grammars for Big Data VisualizationDon't Call It a Comeback: Attribute Grammars for Big Data Visualization
Don't Call It a Comeback: Attribute Grammars for Big Data Visualization
 
Class 16: Making Loops
Class 16: Making LoopsClass 16: Making Loops
Class 16: Making Loops
 
2 Years of Real World FP at REA
2 Years of Real World FP at REA2 Years of Real World FP at REA
2 Years of Real World FP at REA
 
Address/Thread/Memory Sanitizer
Address/Thread/Memory SanitizerAddress/Thread/Memory Sanitizer
Address/Thread/Memory Sanitizer
 
NVIDIA HPC ソフトウエア斜め読み
NVIDIA HPC ソフトウエア斜め読みNVIDIA HPC ソフトウエア斜め読み
NVIDIA HPC ソフトウエア斜め読み
 
lecture16-recap-questions-and-answers.pdf
lecture16-recap-questions-and-answers.pdflecture16-recap-questions-and-answers.pdf
lecture16-recap-questions-and-answers.pdf
 
Ardx experimenters-guide-web
Ardx experimenters-guide-webArdx experimenters-guide-web
Ardx experimenters-guide-web
 
LECTURE2 td 2 sue les theories de graphes
LECTURE2 td 2 sue les theories de graphesLECTURE2 td 2 sue les theories de graphes
LECTURE2 td 2 sue les theories de graphes
 
EMBEDDED SYSTEMS 4&5
EMBEDDED SYSTEMS 4&5EMBEDDED SYSTEMS 4&5
EMBEDDED SYSTEMS 4&5
 
23_Advanced_Processors controller system
23_Advanced_Processors controller system23_Advanced_Processors controller system
23_Advanced_Processors controller system
 
Lec18 Intro to Computer Engineering by Hsien-Hsin Sean Lee Georgia Tech -- In...
Lec18 Intro to Computer Engineering by Hsien-Hsin Sean Lee Georgia Tech -- In...Lec18 Intro to Computer Engineering by Hsien-Hsin Sean Lee Georgia Tech -- In...
Lec18 Intro to Computer Engineering by Hsien-Hsin Sean Lee Georgia Tech -- In...
 
Apache Flink internals
Apache Flink internalsApache Flink internals
Apache Flink internals
 
Memory Optimization
Memory OptimizationMemory Optimization
Memory Optimization
 
Memory Optimization
Memory OptimizationMemory Optimization
Memory Optimization
 
Nicpaper2009
Nicpaper2009Nicpaper2009
Nicpaper2009
 
Flink internals web
Flink internals web Flink internals web
Flink internals web
 
Swug July 2010 - windows debugging by sainath
Swug July 2010 - windows debugging by sainathSwug July 2010 - windows debugging by sainath
Swug July 2010 - windows debugging by sainath
 
ISA.pptx
ISA.pptxISA.pptx
ISA.pptx
 
Efficient Data Storage for Analytics with Apache Parquet 2.0
Efficient Data Storage for Analytics with Apache Parquet 2.0Efficient Data Storage for Analytics with Apache Parquet 2.0
Efficient Data Storage for Analytics with Apache Parquet 2.0
 

Mais de David Evans

Cryptocurrency Jeopardy!
Cryptocurrency Jeopardy!Cryptocurrency Jeopardy!
Cryptocurrency Jeopardy!David Evans
 
Trick or Treat?: Bitcoin for Non-Believers, Cryptocurrencies for Cypherpunks
Trick or Treat?: Bitcoin for Non-Believers, Cryptocurrencies for CypherpunksTrick or Treat?: Bitcoin for Non-Believers, Cryptocurrencies for Cypherpunks
Trick or Treat?: Bitcoin for Non-Believers, Cryptocurrencies for CypherpunksDavid Evans
 
Hidden Services, Zero Knowledge
Hidden Services, Zero KnowledgeHidden Services, Zero Knowledge
Hidden Services, Zero KnowledgeDavid Evans
 
Anonymity in Bitcoin
Anonymity in BitcoinAnonymity in Bitcoin
Anonymity in BitcoinDavid Evans
 
Midterm Confirmations
Midterm ConfirmationsMidterm Confirmations
Midterm ConfirmationsDavid Evans
 
Scripting Transactions
Scripting TransactionsScripting Transactions
Scripting TransactionsDavid Evans
 
How to Live in Paradise
How to Live in ParadiseHow to Live in Paradise
How to Live in ParadiseDavid Evans
 
Mining Economics
Mining EconomicsMining Economics
Mining EconomicsDavid Evans
 
Becoming More Paranoid
Becoming More ParanoidBecoming More Paranoid
Becoming More ParanoidDavid Evans
 
Asymmetric Key Signatures
Asymmetric Key SignaturesAsymmetric Key Signatures
Asymmetric Key SignaturesDavid Evans
 
Introduction to Cryptography
Introduction to CryptographyIntroduction to Cryptography
Introduction to CryptographyDavid Evans
 
Class 1: What is Money?
Class 1: What is Money?Class 1: What is Money?
Class 1: What is Money?David Evans
 
Multi-Party Computation for the Masses
Multi-Party Computation for the MassesMulti-Party Computation for the Masses
Multi-Party Computation for the MassesDavid Evans
 
Proof of Reserve
Proof of ReserveProof of Reserve
Proof of ReserveDavid Evans
 
Blooming Sidechains!
Blooming Sidechains!Blooming Sidechains!
Blooming Sidechains!David Evans
 
Useful Proofs of Work, Permacoin
Useful Proofs of Work, PermacoinUseful Proofs of Work, Permacoin
Useful Proofs of Work, PermacoinDavid Evans
 

Mais de David Evans (20)

Cryptocurrency Jeopardy!
Cryptocurrency Jeopardy!Cryptocurrency Jeopardy!
Cryptocurrency Jeopardy!
 
Trick or Treat?: Bitcoin for Non-Believers, Cryptocurrencies for Cypherpunks
Trick or Treat?: Bitcoin for Non-Believers, Cryptocurrencies for CypherpunksTrick or Treat?: Bitcoin for Non-Believers, Cryptocurrencies for Cypherpunks
Trick or Treat?: Bitcoin for Non-Believers, Cryptocurrencies for Cypherpunks
 
Hidden Services, Zero Knowledge
Hidden Services, Zero KnowledgeHidden Services, Zero Knowledge
Hidden Services, Zero Knowledge
 
Anonymity in Bitcoin
Anonymity in BitcoinAnonymity in Bitcoin
Anonymity in Bitcoin
 
Midterm Confirmations
Midterm ConfirmationsMidterm Confirmations
Midterm Confirmations
 
Scripting Transactions
Scripting TransactionsScripting Transactions
Scripting Transactions
 
How to Live in Paradise
How to Live in ParadiseHow to Live in Paradise
How to Live in Paradise
 
Bitcoin Script
Bitcoin ScriptBitcoin Script
Bitcoin Script
 
Mining Economics
Mining EconomicsMining Economics
Mining Economics
 
Mining
MiningMining
Mining
 
The Blockchain
The BlockchainThe Blockchain
The Blockchain
 
Becoming More Paranoid
Becoming More ParanoidBecoming More Paranoid
Becoming More Paranoid
 
Asymmetric Key Signatures
Asymmetric Key SignaturesAsymmetric Key Signatures
Asymmetric Key Signatures
 
Introduction to Cryptography
Introduction to CryptographyIntroduction to Cryptography
Introduction to Cryptography
 
Class 1: What is Money?
Class 1: What is Money?Class 1: What is Money?
Class 1: What is Money?
 
Multi-Party Computation for the Masses
Multi-Party Computation for the MassesMulti-Party Computation for the Masses
Multi-Party Computation for the Masses
 
Proof of Reserve
Proof of ReserveProof of Reserve
Proof of Reserve
 
Silk Road
Silk RoadSilk Road
Silk Road
 
Blooming Sidechains!
Blooming Sidechains!Blooming Sidechains!
Blooming Sidechains!
 
Useful Proofs of Work, Permacoin
Useful Proofs of Work, PermacoinUseful Proofs of Work, Permacoin
Useful Proofs of Work, Permacoin
 

Último

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
 
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
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
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
 
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
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
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
 
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
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 

Último (20)

Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
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...
 
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
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
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...
 
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
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 

Segmentation Faults, Page Faults, Processes, Threads, and Tasks

  • 1.
  • 2. Plan for Today Recap: Virtualizing Memory Segmentation Faults Page Faults: Challenge winner! Processes, Threads, Tasks 1 PS2 is Due Sunday Exam 1 is out after class Tuesday (Feb 11) due 11:59pm Thursday (Feb 13) – open resources, most questions will be taken from notes
  • 3. PS2 Demos Everyone should be signed up If you can’t find a time that works for your team, let me know by tomorrow At the scheduled start time and place: Your full team should be present One of you should have: – Your code ready to show in your favorite editor – Your gash ready to run 2 PS2 autograder and submission will be posted by Friday (if I forget, but no one reminds me, there won’t be an extension like for PS1!) If your team is not ready to go at your scheduled time (no grace period!), your demo is cancelled and you need to schedule a new one with me.
  • 4. 386 Checkup 3 Dir Page Offset CR3 Page Directory Page Table Physical Memory 20 bits addr / 12 bits flags Page + Offset 12 bits (4K pages) 10 bits (1K tables) 10 bits (1K entries) 32-bit linear address How big is the page table on my MacBook Pro? 1024 entries × 4 bytes/entry = 4096 bytes = 1 page 222 < 4.3M
  • 5. Intel 386 4 386 introduced in 1985: 1 MB $500 Original Macintosh (Jan 1984) $2495 128KB RAM (later in 1984: 512K version) Windows 1.0 (Nov 1985) required 192 KB of RAM
  • 6. 386 Design Checkup 5 CR3 Page Directory Page Table Physical Memory 20 bits addr / 12 bits flags Page + Offset
  • 7. 386 Design Fail! 6 CR3 Page Directory Page Table Physical Memory 20 bits addr / 12 bits flags Page + Offset 264 addressable locations / 212 locations/page = 252 pages Page table would require 254 bytes $17B (eBay annual revenues) worth of RAM!
  • 8. Solution? 7 Page Table Physical Memory 20 bits addr / 12 bits flags Page + Offset
  • 9. Page + Offset base basebasebase Multi-Level (Hierarchical) Page Tables 8 Unused L1 Page Offset 12 bits16 bits 9 bits 64 (-16)-bit x86 linear address L2 Page L3 Page 9 bits 9 bits L4 Page 9 bits CR3 L1 Page Table + L1 Index L2 Page Table + L2 Index L3 Page Table + L3 Index L4 Page Table + L4 Index Physical Memory Page + Offset
  • 10. Do we still need segmentation? 9 LogicalAddress Segmentation Unit LinearAddress Paging Unit PhysicalAddress Memory
  • 11. Page + Offset base basebasebase 10 Unused L1 Page Offset 12 bits16 bits 9 bits L2 Page L3 Page 9 bits 9 bits L4 Page 9 bits CR3 L1 Page Table + L1 Index L2 Page Table + L2 Index L3 Page Table + L3 Index L4 Page Table + L4 Index Physical Memory Page + Offset Where are all the L2, L3, and L4 page tables?
  • 12. Page + Offset base basebasebase 11 Unused L1 Page Offset 12 bits16 bits 9 bits L2 Page L3 Page 9 bits 9 bits L4 Page 9 bits CR3 L1 Page Table + L1 Index L2 Page Table + L2 Index L3 Page Table + L3 Index L4 Page Table + L4 Index Physical Memory Page + Offset Why is each page 512 entries instead of 1024?
  • 13. Page + Offset base basebasebase 12 Unused L1 Page Offset 12 bits16 bits 9 bits L2 Page L3 Page 9 bits 9 bits L4 Page 9 bits CR3 L1 Page Table + L1 Index L2 Page Table + L2 Index L3 Page Table + L3 Index L4 Page Table + L4 Index Physical Memory Page + Offset Why is the page size still 4K? (x86 can support 2MB pages)
  • 14. Page + Offset base basebasebase 13 Unused L1 Page Offset 12 bits16 bits 9 bits L2 Page L3 Page 9 bits 9 bits L4 Page 9 bits CR3 L1 Page Table + L1 Index L2 Page Table + L2 Index L3 Page Table + L3 Index L4 Page Table + L4 Index Physical Memory Page + Offset What would you do instead if you cared about saving energy more than saving silicon?
  • 15. All x86 all the time? 14
  • 16. 15
  • 17. 16 Dave: “Don’t buy bitcoins!”
  • 18. 17 ARMv8-A 64-bit processor (ISA licensed by ARM, designed by Apple, manufactured by Samsung)
  • 19. 18
  • 21. Is 256TB enough? 20 “This design gives us a 256TB address space, which should be enough for a while. If memory prices continue to fall so that the cost of memory halves every year (a bit faster than it has been doing historically), handheld computers will come with 256TB in about 20 years. By then, I expect ARMv9 to be released.” David Chisnall, A Look at the 64- Bit ARMv8 Architecture
  • 22. 21 #include <stdio.h> #include <stdlib.h> int main(int argc, char **argv) { char *s = (char *) malloc (1); int i = 0; while (1) { printf("%d: %lx / %dn", i, s + i, i[s]); i += 1; } } What will this program do?
  • 23. 22 int main(int argc, char **argv) { char *s = (char *) malloc (1); int i = 0; while (1) { printf("%d: %lx / %dn", i, s + i, i[s]); i += 1; } } gash> gcc -Wall segfault.c segfault.c: In function ‘main’: segfault.c:8: warning: format ‘%lx’ expects type ‘long unsigned int’, but argument 3 has type ‘char *’ segfault.c:8: warning: format ‘%lx’ expects type ‘long unsigned int’, but argument 3 has type ‘char *’
  • 24. What causes a segmentation fault? 23
  • 25. What causes a segmentation fault? 24 Page + Offset base basebasebase 12 bits16 bits 9 bits 9 bits 9 bits 9 bits CR3 L1 Page Table + L1 Index L2 Page Table + L2 Index L3 Page Table + L3 Index L4 Page Table + L4 Index Physical Memory Page + Offset Unused L1 Page OffsetL2 Page L3 Page L4 Page
  • 26. 25 #include <stdio.h> #include <stdlib.h> int main(int argc, char **argv) { char *s = (char *) malloc (1); int i = 0; while (1) { printf("%d: %lx / %dn", i, s + i, i[s]); i += 1; } } > ./a.out 0: 7ff7004039a0 / 0 1: 7ff7004039a1 / 0 2: 7ff7004039a2 / 0 … 95: 7ff7004039ff / 0 … 1033819: 7ff7004ffffb / 0 1033820: 7ff7004ffffc / 0 1033821: 7ff7004ffffd / 0 1033822: 7ff7004ffffe / 0 1033823: 7ff7004fffff / 0 Segmentation fault: 11
  • 27. What causes a page fault? 26 Page + Offset base basebasebase 12 bits16 bits 9 bits 9 bits 9 bits 9 bits CR3 L1 Page Table + L1 Index L2 Page Table + L2 Index L3 Page Table + L3 Index L4 Page Table + L4 Index Physical Memory Page + Offset Unused L1 Page OffsetL2 Page L3 Page L4 Page
  • 28. What causes a page fault? 27 base Page Table + L1 Index
  • 29. Challenge from Last Class 28 Challenge: Write a program that takes N as an input and produces (nearly) exactly N page faults. A good solution is worth a USS Hopper patch (even cooler than a Rust sticker!) or an exemption from Exam 1 or Exam 2. Winner: Michael Recachinas
  • 30. Faults Summary Segmentation Fault: Process attempts to access memory that is not in its memory space (or write to memory that is read-only) Should never happen Page Fault: Process attempts to access memory that is not currently available. Happens hundreds of times before your code even starts running! 29
  • 32. Process Originally: abstraction for owning the whole machine 31 Thread (Illusion or reality of) independent sequence of instructions Whatdoyouneed:
  • 33. 32 Own program counter Own stack, registers Own memory space Own program counter Own stack, registers Shares memory space Process Originally: abstraction for owning the whole machine Thread (Illusion or reality of) independent sequence of instructions Whatdoyouneed:
  • 35. Tasks Thread Own PC Own stack, registers Safely shared immutable memory Safely independent own memory 34 fn spawn(f: proc ()) spawn( proc() { println(“Get to work!”); }); Task = Thread – unsafe memory sharing or Task = Process + safe memory sharing – cost of OS process
  • 36. 35 How can we take advantage of more cores to find Collatz results faster? fn collatz_steps(n: int) -> int { if n == 1 { 0 } else { 1 + collatz_steps(if n % 2 == 0 { n / 2 } else { 3 * n + 1 }) } } fn find_collatz(k: int) -> int { // Returns the minimum value, n, with Collatz steps >= k. let mut n = 1; while collatz_steps(n) < k { n += 1; } n }
  • 37. 36 fn find_collatz(k: int) -> int { let mut n = 1; loop { let val = n; spawn(proc() { if collatz_steps(val) > k { println!("Result: {}", val); } }); n += 1; } }
  • 38. Channels 37 let (port, chan) : (Port<T>, Chan<T>) = Chan::new(); chan.send(T); T = port.recv(); Asynchronous Synchronous
  • 39. 38 fn find_collatz(k: int) -> int { let mut n = 1; let (port, chan) : (Port<int>, Chan<int>) = Chan::new(); spawn(proc() { loop { let val = n; spawn(proc() { if collatz_steps(val) > k { chan.send(val); } }); n += 1; } let n = port.recv(); n } Not going to work…
  • 40. 39 fn find_collatz(k: int) -> int { let mut n = 1; let max_tasks = 7; // keep all my cores busy let mut found_result = false; let mut result = -1; // need to initialize while !found_result { let mut ports = ~[]; for i in range(0, max_tasks) { let val = n + i; let (port, chan) : (Port<int>, Chan<int>) = Chan::new(); ports.push(port); spawn(proc() { let steps = collatz_steps(val); println!("Result for {}: {}", val, steps); chan.send(steps); }); } for i in range(0, max_tasks) { let port = ports.pop(); let steps = port.recv(); if steps > k { found_result = true; result = n + i; } } n += max_tasks; } assert!(result != -1); result }
  • 41. Charge 40 PS2 is Due Sunday Exam 1 is out after class Tuesday (Feb 11) due 11:59pm Thursday (Feb 13) – open resources, most questions will be taken from notes Everyone should have scheduled PS2 demo! or…Challenge: make a good multi-tasking find_collatz (at least 6x speedup)