|
| 1 | +--- |
| 2 | +title: Linux NFS read-ahead best practices for Azure NetApp Files - Session slots and slot table entries | Microsoft Docs |
| 3 | +description: Describes filesystem cache and Linux NFS read-ahead best practices for Azure NetApp Files. |
| 4 | +services: azure-netapp-files |
| 5 | +documentationcenter: '' |
| 6 | +author: b-juche |
| 7 | +manager: '' |
| 8 | +editor: '' |
| 9 | + |
| 10 | +ms.assetid: |
| 11 | +ms.service: azure-netapp-files |
| 12 | +ms.workload: storage |
| 13 | +ms.tgt_pltfrm: na |
| 14 | +ms.devlang: na |
| 15 | +ms.topic: conceptual |
| 16 | +ms.date: 07/02/2021 |
| 17 | +ms.author: b-juche |
| 18 | +--- |
| 19 | +# Linux NFS read-ahead best practices for Azure NetApp Files |
| 20 | + |
| 21 | +This article helps you understand filesystem cache best practices for Azure NetApp Files. |
| 22 | + |
| 23 | +NFS read-ahead predictively requests blocks from a file in advance of I/O requests by the application. It is designed to improve client sequential read throughput. Until recently, all modern Linux distributions set the read-ahead value to be equivalent of 15 times the mounted filesystems `rsize`. |
| 24 | + |
| 25 | +The following table shows the default read-ahead values for each given `rsize` mount option. |
| 26 | + |
| 27 | +| Mounted filesystem `rsize` | Blocks read-ahead | |
| 28 | +|-|-| |
| 29 | +| 64 KiB | 960 KiB | |
| 30 | +| 256 KiB | 3,840 KiB | |
| 31 | +| 1024 KiB | 15,360 KiB | |
| 32 | + |
| 33 | +RHEL 8.3 and Ubuntu 18.04 introduced changes that might negatively impact client sequential read performance. Unlike earlier releases, these distributions set read-ahead to a default of 128 KiB regardless of the `rsize` mount option used. Upgrading from releases with the larger read-ahead value to those with the 128-KiB default experienced decreases in sequential read performance. However, read-ahead values may be tuned upward both dynamically and persistently. For example, testing with SAS GRID found the 15,360-KiB read value optimal compared to 3,840 KiB, 960 KiB, and 128 KiB. Not enough tests have been run beyond 15,360 KiB to determine positive or negative impact. |
| 34 | + |
| 35 | +The following table shows the default read-ahead values for each currently available distribution. |
| 36 | + |
| 37 | +| Distribution | Release | Blocks read-ahead | |
| 38 | +|-|-|-| |
| 39 | +| RHEL | 8.3 | 128 KiB | |
| 40 | +| RHEL | 7.X, 8.0, 8.1, 8.2 | 15 X `rsize` | |
| 41 | +| SLES | 12.X – at least 15SP2 | 15 X `rsize` | |
| 42 | +| Ubuntu | 18.04 – at least 20.04 | 128 KiB | |
| 43 | +| Ubuntu | 16.04 | 15 X `rsize` | |
| 44 | +| Debian | Up to at least 10 | 15 x `rsize` | |
| 45 | + |
| 46 | + |
| 47 | +## How to work with per-NFS filesystem read-ahead |
| 48 | + |
| 49 | +NFS read-ahead is defined at the mount point for an NFS filesystem. The default setting can be viewed and set both dynamically and persistently. For convenience, the following bash script written by Red Hat has been provided for viewing or dynamically setting read-ahead for amounted NFS filesystem. |
| 50 | + |
| 51 | +Read-ahead can be defined either dynamically per NFS mount using the following script or persistently using `udev` rules as shown in this section. To display or set read-ahead for a mounted NFS filesystem, you can save the following script as a bash file, modify the file’s permissions to make it an executable (`chmod 544 readahead.sh`), and run as shown. |
| 52 | + |
| 53 | +## How to show or set read-ahead values |
| 54 | + |
| 55 | +To show the current read-ahead value (the returned value is in KiB), run the following command: |
| 56 | + |
| 57 | +`$ ./readahead.sh show <mount-point>` |
| 58 | + |
| 59 | +To set a new value for read-ahead, run the following command: |
| 60 | + |
| 61 | +`$ ./readahead.sh show <mount-point> [read-ahead-kb]` |
| 62 | + |
| 63 | +### Example |
| 64 | + |
| 65 | +``` |
| 66 | +#!/bin/bash |
| 67 | +# set | show readahead for a specific mount point |
| 68 | +# Useful for things like NFS and if you do not know / care about the backing device |
| 69 | +# |
| 70 | +# To the extent possible under law, Red Hat, Inc. has dedicated all copyright |
| 71 | +# to this software to the public domain worldwide, pursuant to the |
| 72 | +# CC0 Public Domain Dedication. This software is distributed without any warranty. |
| 73 | +# See <http://creativecommons.org/publicdomain/zero/1.0/>. |
| 74 | +# |
| 75 | +
|
| 76 | +E_BADARGS=22 |
| 77 | +function myusage() { |
| 78 | +echo "Usage: `basename $0` set|show <mount-point> [read-ahead-kb]" |
| 79 | +} |
| 80 | +
|
| 81 | +if [ $# -gt 3 -o $# -lt 2 ]; then |
| 82 | + myusage |
| 83 | + exit $E_BADARGS |
| 84 | +fi |
| 85 | +
|
| 86 | +MNT=${2%/} |
| 87 | +BDEV=$(grep $MNT /proc/self/mountinfo | awk '{ print $3 }') |
| 88 | +
|
| 89 | +if [ $# -eq 3 -a $1 == "set" ]; then |
| 90 | + echo $3 > /sys/class/bdi/$BDEV/read_ahead_kb |
| 91 | +elif [ $# -eq 2 -a $1 == "show" ]; then |
| 92 | + echo "$MNT $BDEV /sys/class/bdi/$BDEV/read_ahead_kb = "$(cat /sys/class/bdi/$BDEV/read_ahead_kb) |
| 93 | +else |
| 94 | + myusage |
| 95 | + exit $E_BADARGS |
| 96 | +fi |
| 97 | +``` |
| 98 | + |
| 99 | +## How to persistently set read-ahead for NFS mounts |
| 100 | + |
| 101 | +To persistently set read-ahead for NFS mounts, `udev` rules can be written as follows: |
| 102 | + |
| 103 | +1. Create and test `/etc/udev/rules.d/99-nfs.rules`: |
| 104 | + |
| 105 | + `SUBSYSTEM=="bdi", ACTION=="add", PROGRAM="/bin/awk -v bdi=$kernel 'BEGIN{ret=1} {if ($4 == bdi) {ret=0}} END{exit ret}' /proc/fs/nfsfs/volumes", ATTR{read_ahead_kb}="15380"` |
| 106 | + |
| 107 | +2. Apply the `udev` rule: |
| 108 | + |
| 109 | + `$udevadm control --reload` |
| 110 | + |
| 111 | +## Next steps |
| 112 | + |
| 113 | +* [Linux direct I/O best practices for Azure NetApp Files](performance-linux-direct-io.md) |
| 114 | +* [Linux filesystem cache best practices for Azure NetApp Files](performance-linux-filesystem-cache.md) |
| 115 | +* [Linux NFS mount options best practices for Azure NetApp Files](performance-linux-mount-options.md) |
| 116 | +* [Linux concurrency best practices](performance-linux-concurrency-session-slots.md) |
| 117 | +* [Azure virtual machine SKUs best practices](performance-virtual-machine-sku.md) |
| 118 | +* [Performance benchmarks for Linux](performance-benchmarks-linux.md) |
0 commit comments