How Much to Buffer?
Let's do some maths to determine what should be the buffer size to ensure the best performance.
Now arises the following question: how many updates should LFS buffer before writing to disk? The answer, of course, depends on the disk itself, specifically how high the positioning overhead is in comparison to the transfer rate; see the FFS chapter for a similar analysis.
For example, assume that positioning (i.e., rotation and seek overheads) before each write takes roughly seconds. Assume further that the disk transfer rate is . How much should LFS buffer before writing when running on such a disk?
The way to think about this is that every time you write, you pay a fixed overhead of the positioning cost. Thus, how much do you have to write in order to amortize that cost? The more you write, the better (obviously), and the closer you get to achieving peak bandwidth.
To obtain a concrete answer, let’s assume we are writing out MB. The time to write out this chunk of data () is the positioning time plus the time to transfer (), or:
And thus the effective rate of writing (), which is just the amount of data written divided by the total time to write it, is:
What we’re interested in is getting the effective rate () close to the peak rate. Specifically, we want the effective rate to be some fraction F of the peak rate, where (a typical might be 0.9, or 90% of the peak rate). In mathematical form, this means we want
At this point, we can solve for :
Let’s do an example, with a disk with a positioning time of 10 milliseconds and peak transfer rate of 100 MB/s; assume we want an effective bandwidth of 90% of peak ( = 0.9). In this case, would be:
Try some different values to see how much we need to buffer in order to approach peak bandwidth:
Get hands-on with 1400+ tech skills courses.