2.10 Optimization management
Which are the CPU cache that you use for instructions that are very frequently used?
L1, L2 is replicated, L3 is not. If I have 4 cores, how many cache do I have? 4+4+4+1=13
How do you call when two processes share loaded on the RAM? sharing
virtual memory is a mixture of? RAM and secondary memory
calculate size of VM and SWAP
1/2 RAM <= SWAP area <= 2 RAM
3/2 RAM <= VM <= 3 RAM
sysdm cpl
how do you call the flag that turns to 1 when the process is creating problems?
location of types of memory
β Optimize the computer
- File Management: FAT32
- RAM management: Segment, Paging
- Process management: FIFO, SJF
- IRQ/DRG: DMA, Polling, PIO
- ππ» All this make the computer overloaded
- ππ» We need to optimize the computer
β Priority of computer components
- CPU
- Main Memory RAM
- Secondary Memory (HDD, SSD)
- Peripherals
- ππ» We should optimize the computer components following this order
1οΈβ£ Lets help the CPU
π€ Problem that CPU suffers
- 1οΈβ£ speed problem, being slow β‘οΈ bottleneck problem
- 2οΈβ£ temperature problem π better refrigeration problem, better ventilation
π Solve the bottleneck problem
- Use CPU cache
CPU cacheis inside CPU- The
CPU cacheis divided into 4 potions
π‘ CPU cache is stable
- in general,
CPU cacheis not deleted CPU cacheis stable(not deleted after session finishes)- unless we manually clean them
4 types of CPU cache
- L1D: Level 1 Data cache
- For data that CPU uses very very often
- π
power of 2, as in computer everything is in binary, it is stored in cache for frequent access - π
1s and0s
- π
- βπ» one L1D per core
- it needs to be close to the CPU, as it is used very often to the nueman machine
π size: comparatively small, we just want them for super frequent things
- L1I: Level 1 Instructions cache
- for instructions that we use very very often
- π standard mathametical instructions, like
sum,minus,mul,div,move(move data to another space),sqrt(square root)
- π standard mathametical instructions, like
- βπ» one L1I per core
π size: comparatively small, we just want them for super frequent things
- L2: Level 2 Cache
- Both instructions and data mixed together that we use quite often
- π mathametical operations that are not so frequent:
log,cos function...
- π mathametical operations that are not so frequent:
- π size: bigger than level 1, need to save both instructions and data
- πΊοΈ location: located further away from the neuman machine, compared to level 1
βπ» one L2 per core
- shared L3: Level 3 Cache
- Both instructions and data we use sometimes
- π
loops, like for, while
- π
- π³ size: bigger, very big
- πΊοΈ location: far from neuman machine
- βπ» Shared level 3: Not one per core, shared among all the cores
- Level 3 cache uses front side bus
1
2
3
4
5
6
7
8
β If I have 8 cores, how many CPU caches do I have?
- L1D: 8
- L1I: 8
- L2: 8
- L3 : one shared L3 per core
ππ» in total 25 CPU cache memory
π‘ ISA
- Instructions Set Architecture
- set of instructions that the CPU needs to exectute
- the instructions that come by default when I buy my computer
- factory settings of my CPU
the instructions that the neuman machines do by default
CPU cachehelpsISA, as some ofISAinstructions are stored in theCPU cache
1
2
3
4
5
6
7
8
9
β If I reset my computer to factory settings, pure nueman machine, am I deleting the CPU cache memory?
ππ» yes, we are deleting
βCPU cache helps which of the following?
1. IPC to the kernel
2. ISA
3. IRQ
4. DRQ
ππ» ISA
2οΈβ£ Lets help the RAM
π€ Problem that RAM suffers
- 1οΈβ£ problem of space: even smaller bc of
process table, pages table, vectors table, service routinesand above all, processes!
π Sharing
- there are some common portions that several proecesses share
- π
menu bar in word, excel, ppt are more or less the same - If some processes have some elements in common,
- then put the same elements just one time on the RAM
and share it among the processes
- ππ» the shared elements would be less secure
- as it can be accessed by several processes
- sharing can be deactivated
π Virtual Memory
βοΈ Some processes are ok to be slow and is not used so frequently
- can be slow
- is not used all the time
- we do not need the process to be there all the time in the RAM
βοΈ Page File and SWAP area
- we can leave the process in a specific part of the Harddisk(secondary memory)
- called in Page File
windows/mac/androidand SWAP area inlinux - ππ» in
page file/SWAP areawe store the pages of the process that - we donβt use very often
- and we do not need so fast
- like having an extra storage
- ππ» makes the RAM feel bigger than it seems
ππ» Feels like virtually, I have more RAM
- its called swap, bc when you need it,
- it seems the process is inside the RAM
But actually, the process is inside the hardddisk
- So in harddisk, it is generally for closed program
- but in SWAP part of harddisk, there are opened process
βοΈ Format for Page File and SWAP area
- This area is in the secondary memory
- β οΈ the format is different from starndard( NOT
FAT32,exFAT,NTFS,ext 2, 3, 4β) - the format of
Page FileandSWAP areais called swap - as
Page FileandSWAP areais for helping the RAM,swap formatis similar to the RAM
βοΈ Virtual Memory
- VIrtual Memory = my RAM β SWAP in Harddisk
VM π° MM β SWAP area(SM)
βοΈ Calculate the VM
- If RAM is small β¬οΈ SWAP must be big β¬οΈ
- If
RAM < 4GB, SWAP must be two times the RAMSWAP = RAM * 2 - If
RAM = 4GB, SWAP must be same as the RAMSWAP = RAM - If
RAM > 4GB, SWAP must be half of the RAMSWAP = RAM / 2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
β 3GB of RAM, my SWAP should be?
ππ» 6GB
β Then how much is my VM?
ππ» 9GB
------
β 4GB of RAM, my SWAP should be?
ππ» 4GB
β Then how much is my VM?
ππ» 8GB
------
β 16GB of RAM, my SWAP should be?
ππ» 8GB
β Then how much is my VM?
ππ» 24GB
β οΈ Error we can get if we do not follow the VM caculation rule
- If we follow these rules, we will never have a problem with the virtual memory
- However, if we do not follow these rules, we might get a problem
- βοΈ When you have a VM error, the error starts by
0x000000 - cannot read instruction on
0x000000 if you see this error, you have a virtual memory problem
- this error occurs bc many OS take SWAP smaller than needed
- many OS prefer more pure HD than more SWAP
- π deactivate the automatic VM supply(administraciΓ³n automatica memoria virtual)
- π and supply VM manually
βοΈ Perfect limits for VM
SWAPshould always be between half and double the size of theRAMhalf of RAM< size of swap <double of RAM- if my RAM is big, if my SWAP small, SWAP is
half of RAMmy VM would beRAM + RAM/2 = 1.5RAM - if my RAM is small, if my SWAP big, SWAP is
twice the RAMmy VM would beRAM + RAM*2 = 3 RAM - Thus, the VM size should always be
RAM * 1.5< size of VM <RAM * 3- ππ» This size of VM would avoid the problem of VM
0xerror
1
2
3
4
β I have 8GB of RAM. Study the minimum and maximum limits of VM so I do not get the VM error.
ππ» 8 * 1.5 < VM size < 8 * 3
ππ» thus, 12GB < VM size < 24GB
ππ» as long as I guarantee that my computer makes VM from 12 to 24GB, I will never get the 0x error.
1/2 RAM <= SWAP area <= 2 RAM
3/2 RAM <= VM <= 3 RAM
- these formulas guarantee that we will not have the
0x000000error - if I keep this formula, I will protect my computer from having the
0x000000error
βοΈ Command to solve the VM error
1
sysdm cpl
- system setting commands start with
sys all the commands that start with
sysare for setting the system- all the commands that contain/end with
dmis for device management - all the commands that end with
cplare commands that are reachable through the control panel
βοΈ How to run the commmand
- β οΈ This process very very hidden,
- need to open three windows!
- bc of security purposes
- in order to run this command, press
windows keyandR
- then type the command
sysdm cpl - a new window appears
- go to advanced options
- Performance area
- Configuration button
- new window appears
- Advanced options
- Change button
- new window appears
- virtual memory
- Untick the automatic administration
- Choose custom size
- custom size needs to include the limits for the
virtual memory - So adopt the
virtual memory formula - If we use this formaula, we protect the system from VM errros
- initial size will be
1.5 * RAM, but in MB - maximum size will be
3* RAM, but in MB - we only manually choose the size when we get the
0x000000error
- We should do this when we really have a problem, at the moment we have a problem
- So do not manually change the size when you do not have an error
- If we do it even if we do not have an error, we are stealing capacity of the HD when we do not need it, so why do it?
- After writing the size manually, click on
accept β‘οΈ accept β‘οΈ accept three times, and close all three windows - Restart the computer
- Now you will not see the 0x000000` error!
βοΈ How do you find the size of the RAM?
- Open task manager(administrador de tareas)
- shortcut:
Ctrl+Alt+Supr - or
Ctrl+Shift+Esc
- Task Manager
- Performance
- Memory
- You can find the size of the RAM in the top right corner
1
2
3
4
5
6
7
If my RAM is 8GB,
inicial size will be 8 * 1.5 = 12 GB
change to MB: 12 * 1024 = 12288 MB
maximum size will be 8 * 3 = 24GB
change to MB: 24 * 1024 = 24576 MB
3οΈβ£ Lets help the Secondary Memory
π Harddisk Buffer
- harddisk buffer is in the
Harddisk buffer: temporal storage for making profit of a data transaction
- the portion that you need now β‘οΈ goes to the RAM
- the portion that you do not need now, but you took following the proximity principle β‘οΈ goes to the buffer
π‘ Proximity principle
- when you open a program, most probably you will need more than that
- ππ» open more, also the ones next to the pointed program
- π if you opened ejercicio 1, you will also open 2, 3,4β¦
- the extra can be stored in the
harddisk bufferto have it closer to you.
π Web cache, Broswer cache
- when we download elements from the web and we visit web pages
- most probably, we will use the element/web page later
- store the elements in the broswer cache
- web cache is a folder in the harddisk
- when we empty the cache, we are emptying the web cache
βοΈ Two things you save in the web cache?
- web cache saves the 1οΈβ£ history of web pages
- and components you have 2οΈβ£ downloaded from the web pages
βοΈ Where is broswer cache?
- Harddisk
βοΈ How many web cache?
- one folder per user
- one folder per browswer
- also the same for cookies, one folder per browser, one folder per user
- π cookies: my preferences/ web cache: my history, downloads
1
2
β If I have two users, and three web browsers, how many web cache do I have?
ππ» 6 web caches
1
2
3
4
5
β When you delete the history in your browser, what are you deleting?
ππ» you are just deleting the list of visited web pages,
but not downloads, components history
ππ» so you are not fully deleting, you can still see downloads history
4οΈβ£ Lets help the Peripherals
π€ Problem that RAM suffers
- π’ normally peripherals are slower than the other computer compoenents
- so we need to help peripheral speed
π Peripherals buffer
- specific folder
- in which the peripherals stores the pending documents
- and takes them at its own speed
π like the printer queue
- If the peripheral uses the
peripheral buffer - we say it is using
Buffering
π Spooling
- If the buffer is shared by several computers on the network
- one printer is shared by several computers
- we call it spooling
- same as buffer, but with several computers connected to one peripheral
β How can I protect my system?
- Due to optimization techniques, all the computer components are interconnected
- so one problem in one component can affect the whole computer
- π If I have a problem in SWAP, will affect HD and also the RAM
βοΈ Stamp a process
- when a process creates a problem in one component
- the process is stamped
- Stamp a process: set a flag
NX: Non Executeto 1 NXmeansplease, do not execute the proecss!- so when the process reaches another component,
if
NX = 1, the entrance will be blocked! forbidden- Then the process that is stamped
NXwill be swapped out - and if it is a malware
- (the anti virus will tell you)
- 3 layer protection(me, my parent, my children)
- antivirus will expel the process and its 3 generations from the RAM
βοΈ Where is the NX flag?
- the flag is stored inside the process table, in the OSRAM
- ππ» way a protecting the system
β Type of memories
βοΈ ROM: memory you can only read, you cannot modify
- these days, the only element that is
ROMisBIOS - find the battery, and the
BIOS/ROMwill be next to the battery
βοΈ SM/EM: HDD, SSD
- files when they are closed, stored
βοΈ RAM, MM
- opened processes
- Random: bc processes will be placed randomly, incontinguously, not ordered
βοΈ VM:
- combination of memory both in HD(SWAP) and RAM
- Can you point to the VM physically? ππ» NO, VM is a concept
βοΈ CPU Cache:
- inside the CPU
βοΈ Web Cache:
- in the harddisk, it is a folder
βοΈ Disk Buffer:
- in the harddisk
βοΈ Buffering and Spooling:
- in the peripherals
βοΈ Disk Cache:
- A portion of the RAM helping the HD
for frequently opened/closed applcations
- Sometimes, you have free space in the RAM
πRAM is always faster than the π’HD
- If we have an application that we
open(RAM)andclose(HD)several times, - if there is free space in the RAM,
- it makes sence to just keep it in the RAM
- even when you close it
- beacuase
1. as RAM is fastand2. we have free space on the RAM - ππ» So the RAM is helping the HD
- We call that disk cache
π Disk cache and Virtual Memory
- Disk cache: RAM helping HD
- Virtual Memory: HD helping RAM










