Last Sync: 2022-09-03 19:00:05

This commit is contained in:
tactonbishop 2022-09-03 19:00:05 +01:00
parent ce4291015b
commit b4f2775832
2 changed files with 41 additions and 1 deletions

View file

@ -33,3 +33,7 @@ There are two types of cache memory:
The L1 cache is the fastest since the data has less distance to travel when moving to and from the CPU. This said, the L2 cache is still very fast when compared to the main memory, both because it is SRAM rather than DRAM and because it is closer to the processor than the main memory.
Cache controllers use complex algorithms to determine what should go into the cache to facilitate the best performance, but generally they work on the principle that what has been previously used by the CPU will be requested again soon. If the CPU has just asked for an instruction at memory location 555 it's very likely that it will next ask for the one at 556, and after that the one at 557 and so on. The cache's controller circuits therefore go ahead and fetch these from slow DRAM to fast SRAM.
## Relation between cache and buffers
The terms _cache_ and _buffer_ are often used interchangeably but there is a significant difference. Buffer 'size' refers to the amount of physical memory in RAM that is dedicated to a process where this size is measured in terms of the amount of disk blocks it would take up in the harddrive. Cache is also a measure of memory but it is expressed in terms of [virtual memory](/Operating_Systems/Virtual_memory_and_the_MMU.md): the page size of the memory.

View file

@ -45,7 +45,11 @@ _Here I have pressed `u` to show only the processes associated with my user:_
- The non swapped _physical_ memory the process has used
- `SHR`
- The size of the process's [shared pages](/Operating_Systems/Virtual_memory_and_the_MMU.md#shared-pages)
- `S`
- Status:
- S for sleeping (idle)
- R for running
- D for disk sleep
## Files being used by active processes: `lsof`
`lsof` stands for _list open files_. It lists opened files and the processes using them. Without modifiers it outputs a huge amount of data. The best way to use it is to execute it against a specific PID. For example the below output gives me some useful info about which files VS Code is using:
@ -88,6 +92,38 @@ $ getconf PAGE_SIZE
This will typically be the same for all Linux systems.
### `free` : available physical memory
`free` displays the total amount of free and¬used physical and swap memory in the system, as well as the [buffers and caches](/Hardware/Memory/Role_in_computation.md#relation-between-cache-and-buffers) used by the kernel.
```bash
$ free
total used free shared buff/cache available
Mem: 16099420 5931512 5039344 2046460 5128564 7781904
Swap: 3145724 0 3145724
```
### `vmstat` : virtual memory statistics
Pretty much the same as `free` but in the context of virtual memory. It also distinguishes between buffer and cache.
The default output is a single line with the averages since boot. You can add a delay parameter (in secs) which will then output at that interval, allowing you to see memory usage in realtime, e.g:
```
$ vmstat 5
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
2 0 0 4326768 334228 5050952 0 0 8 19 80 10 4 1 94 0 0
0 0 0 4365520 334260 5054468 0 0 0 125 2140 3434 4 1 94 0 0
1 0 0 4382400 334276 5068940 0 0 0 77 2102 3988 3 1 95 0 0
1 0 0 4434000 334288 5052908 0 0 0 25 2859 4278 6 1 92 0 0
0 0 0 4391576 334304 5086484 0 0 0 110 2899 6480 8 3 90 0 0
```
* `r` stands for the number of runnable processes
* `b` stands for the number of blocked processes: those waiting for I/O to complete before proceeding.
* `si/so`: the amount of memory swapped in (from disk) and swapped out (to disk)
* `bi/ bo`: the amount of blocks received from a device (`bi`), the amoung of blocks sent to a device (`bo`)
### Page faults
There are two kinds of error that can occur with relation to paged memory: