You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/learning-paths/cross-platform/filesystem-cache-hit/intro.md
+11-10Lines changed: 11 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,31 +8,32 @@ layout: learningpathall
8
8
9
9
## Recap of File Systems
10
10
11
-
A file system is the method an operating system uses to store, organize, and manage data on storage devices like hard drives or SSDs. Linux uses a **Virtual File System (VFS)** layer to provide a uniform interface to different file system types (e.g., `ext4`, `xfs`, `btrfs`), allowing programs to interact with them in a consistent way.
11
+
A file system is the method an operating system uses to store, organize, and manage data on storage devices like hard drives or SSDs. Linux uses a virtual file system (VFS) layer to provide a uniform interface to different file system types (e.g., `ext4`, `xfs`, `btrfs`), allowing programs to interact with them in a consistent way.
12
12
13
-
Developers typically interact with the file system through system calls or standard library functions—for example, using `open()`, `read()`, and `write()` in C to access files. For instance, reading a configuration file at `/etc/myapp/config.json` involves navigating the file system hierarchy and accessing the file’s contents through these interfaces. To speed up access to such files, the operating system creates a file system cache, managed by the kernel and residing in main memory (RAM). This cache temporarily stores recently accessed file data to speed up future reads and reduce disk I/O.
13
+
Developers typically interact with the file system through system calls or standard library functions—for example, using `open()`, `read()`, and `write()` in C to access files. For instance, reading a configuration file at `/etc/myapp/config.json` involves navigating the file system hierarchy and accessing the file’s contents through these interfaces. To speed up access to such files, the operating system creates a file system cache, managed by the kernel and resides in main memory (RAM). This cache temporarily stores recently accessed file data and metadata to speed up future reads and reduce disk I/O.
14
14
15
15
16
-
## Observing Memory Usage
16
+
## Recap of Memory Usage
17
17
18
-
The operating system has to manage the memory usage for the entire system.
18
+
The hardware and operating system is responsible for managing the memory usage of the system.
19
19
20
-
The command `free -h` provides a snapshot of memory usage.
20
+
The well-known command `free -wh` provides a snapshot of memory usage. The `cache` column includes the portion of memory used to store the file system cache.
21
21
22
22
```output
23
-
total used free shared buff/cache available
24
-
Mem: 7.6Gi 533Mi7.0Gi948Ki215Mi 7.1Gi
23
+
total used free shared buffers cache available
24
+
Mem: 7.6Gi 1.1Gi5.8Gi960Ki 22Mi 832Mi 6.5Gi
25
25
Swap: 0B 0B 0B
26
26
```
27
27
28
-
The `free`command summarises the memory usage into the following columns.
28
+
The command summarises the memory usage into the following columns.
29
29
30
30
-`total`: Total installed memory
31
31
-`used`: Memory in use (excluding cache/buffers)
32
32
-`free`: Unused memory
33
33
-`shared`: Memory used by tmpfs and shared between processes
34
-
-`buff/cache`: Sum of memory used by kernel buffers and cache
35
-
-`available`: An estimate of memory available to start new apps
34
+
-`buffers`: Memory used by kernel buffers
35
+
-`cache`: Memory used by file system cache
36
+
-`available`: An estimate of memory available (both free memory and memory that can be reclaimed) when a new process starts.
Copy file name to clipboardExpand all lines: content/learning-paths/cross-platform/filesystem-cache-hit/with_hint.md
+6-3Lines changed: 6 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,7 @@ layout: learningpathall
9
9
10
10
## Providing hints with posix_fadvise
11
11
12
-
The `posix_fadvise()` system call gives the Linux kernel hints about expected file access patterns to optimize I/O. The function takes the following arguments.
12
+
The `posix_fadvise()`function is a wrapper around the `fadvise64` linux system call (syscall). This syscall gives the Linux kernel hints about expected file access patterns to optimize I/O, for example preemptively reading ahead for sequential file access. The function takes the following arguments.
13
13
-`fd`: file descriptor of the file,
14
14
-`offset`: where the advice starts (0 = beginning),
15
15
-`len`: how many bytes the advice applies to (0 = to the end),
If you are using `posix_fadvise()` with your own application and you want to observe which system calls are issued. Consider using the system call tracer, `strace` with a command such as `strace -ttT -e trace=<syscall of interest,fadvise64> ./<your workload>` to observe what is causing fewer cache misses.
87
+
{{% /notice %}}
88
+
86
89
### Results
87
90
88
91
Here we observe that on this run with a single line of code we are able to reduce the cache miss rate from ~4.8% to ~3.8%. This can translate to more efficient and performant software, especially if your program is synchronous and has to wait for disk accesses.
89
92
90
93
{{% notice Please Note%}}
91
-
Since this is only a hint to the operating system and it depends on other factors such as memory pressure, memory usage, other processes etc. the behaviour on your system may be different
94
+
Since this is advise to the operating system, the operating may not do anything with this. Real-world impact depends on other factors such as memory pressure, memory usageetc. As such, the behaviour on your own system may be different.
Copy file name to clipboardExpand all lines: content/learning-paths/cross-platform/filesystem-cache-hit/without_hint.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ layout: learningpathall
8
8
9
9
## Setup
10
10
11
-
For this demonstration, I have connected to an Arm-based AWS `c7g.xlarge` instance running Ubuntu 24.04. Results may vary depending on which instance and kernel version you are using. At the time of writing, I was using the `6.8.0-1024-aws`kernel version.
11
+
For this demonstration, connect to an Arm-based AWS `c7g.xlarge` instance running Ubuntu 24.04. Results may vary depending on which instance and kernel version you are using. At the time of writing, kernel version `6.8.0-1024-aws`was used.
12
12
13
13
First, you need to install the linux performance measure tool, `perf`. Please follow the [installation guide](https://learn.arm.com/install-guides/perf/) for your system.
14
14
@@ -33,7 +33,7 @@ L2 cache: 4 MiB (4 instances)
33
33
L3 cache: 32 MiB (1 instance)
34
34
```
35
35
36
-
This information will be useful as we want to ensure our working set size cannot all fit within on-CPU cache.
36
+
This information will be useful to ensure our working set size cannot all fit within on-CPU cache.
37
37
38
38
Next, check the current memory usage of an idle system with the `free -h` command.
0 commit comments