$filterdir/nbdkit-spinning-filter.so
The filter.
Use "nbdkit --dump-config" to find the location of $filterdir.
Add seek delays to simulate a spinning hard disk
nbdkit --filter=spinning
PLUGIN
[heads=N]
[{separate-heads=true | false}]
[max-seek-time=N]
[half-seek-time=N]
[min-seek-time=N]
"nbdkit-spinning-filter" is a filter for nbdkit(1) which adds seek delays to simulate a spinning hard disk with a mechanical arm and head. You can use this to test the NBD rotational property.
In the default configuration this filter simulates a disk with one head. Accesses which are close to the current position of this head have a very small delay. Accesses which are far away suffer increasingly larger delays as the simulated head seeks to that position on the disk. Each access moves the simulated position of the head.
For example to turn nbdkit-memory-plugin(1) (a RAM disk) into something which behaves more like a spinning disk:
nbdkit --filter=spinning memory 1G
You can control the number of heads and whether they can move independently or not. Setting "heads=4" and "separate-heads=false" simulates a disk with a single mechanical arm, two platters and four heads. From the point of view of logical blocks this looks like the following, where the heads move in tandem over 4 equally spaced sections of the disk:
arm│ head┌────────────┬──────┴─────┬────────────┐ ↙⇓ ⇓ ⇓ ⇓┌─────────────────────────────────────────────────┐└─────────────────────────────────────────────────┘
In this mode, requests are serialized waiting for the arm to move even if the requests are for different heads (as happens on a real disk).
Using "separate-heads=true" simulates heads which move on independent arms (but each head is still confined to its quarter of the disk):
range of movement for 4ᵗʰ arm/head┌──────┴─────┐⇓ ⇓ ⇓ ⇓┌─────────────────────────────────────────────────┐└─────────────────────────────────────────────────┘
In this mode, requests may operate in parallel if they are handled by different heads.
The rotational property is a boolean flag in the NBD protocol which hints to the client whether the plugin behaves like a spinning disk (if rotational is true) or like a solid state disk or RAM (if rotational is false).
This filter always advertises the rotational property, because it behaves like a spinning disk.
Well-behaved NBD clients should observe this property and adjust their behaviour, for instance by scheduling disk accesses to reduce seeking.
You can place nbdkit-rotational-filter(1) in front of this filter if you want to simulate what happens with a spinning disk which does not advertise the property correctly:
nbdkit --filter=rotational --filter=spinning PLUGIN rotational=false
Use nbdinfo(1) to examine the rotational property of an NBD server.
By default, seeks to adjacent tracks take 10 milliseconds, seeking from the first sector to the last sector of the disk takes ½ second, and seeking half way across the disk takes 0.2 seconds (so the curve of seek times is mildly quadratic). Note these seek times are at least an order of magnitude larger than a typical hard disk, in order to exaggerate the effect for testing purposes.
You can adjust the time taken to seek across the whole disk ("max-seek-time"), across half of the disk ("half-seek-time"), and from one track to an adjacent track ("min-seek-time") in order to change this curve. For example, setting "half-seek-time=500ms max-seek-time=1000ms" will make seek times twice as slow as the default and approximately linear with distance.
heads=NSet the number of simulated heads to "N" (default is 1).
separate-heads=trueseparate-heads=falseSimulate separate, independently moving heads (true), or heads connected together on a single arm (false). See the description above. The default is "false".
min-seek-time=Nhalf-seek-time=Nmax-seek-time=NAdjust the time taken to seek to an adjacent track, seek across half of the disk, and seek across the whole disk. All numbers are in seconds. The defaults are "min-seek-time=10ms", "half-seek-time=200ms" and "max-seek-time=500ms".
See nbdkit_parse_delay(3) for the precise format of these parameters.
$filterdir/nbdkit-spinning-filter.so
The filter.
Use "nbdkit --dump-config" to find the location of $filterdir.
"nbdkit-spinning-filter" first appeared in nbdkit 1.40.