loader bcache: Track unconsumed readahead
The loader bcache attempts to determine whether readahead is useful, increasing or decreasing its readahead length based on whether a read could be serviced out of the cache. This resulted in two unfortunate behaviours: 1. A series of consecutive 32 kB reads are requested and bcache performs 16 kB readaheads. For each read, bcache determines that, since only the first 16 kB is already in the cache, the readahead was not useful, and keeps the readahead at the minimum (16 kB) level. 2. A series of consecutive 32 kB reads are requested and bcache starts with a 32 kB readahead resulting in a 64 kB being read on the first request. The second 32 kB request can be serviced out of the cache, and bcache responds by doubling its readahead length to 64 kB. The third 32 kB request cannot be serviced out of the cache, and bcache reduces its readahead length back down to 32 kB. The first syndrome converts a series of 32 kB reads into a series of (misaligned) 32 kB reads, while the second syndrome converts a series of 32 kB reads into a series of 64 kB reads; in both cases we do not increase the readahead length to its limit (currently 128 kB) no matter how many consecutive read requests are made. This change avoids this problem by tracking the "unconsumed readahead" length; readahead is deemed to be useful (and the read-ahead length is potentially increased) not only if a request was completely serviced out of the cache, but also if *any* of the request was serviced out of the cache and that length matches the amount of unconsumed readahead. Conversely, we now only reduce the readahead length in cases where there was unconsumed readahead data. In my testing on an EC2 c5.xlarge instance, this change reduces the boot time by roughly 120 ms. Reviewed by: imp, tsoome MFC after: 1 week Sponsored by: https://patreon.com/cperciva Differential Revision: https://reviews.freebsd.org/D32250
This commit is contained in:
parent
b841148bbb
commit
04b9b7c507
@ -67,6 +67,7 @@ struct bcache {
|
||||
size_t bcache_nblks;
|
||||
size_t ra;
|
||||
daddr_t bcache_nextblkno;
|
||||
size_t ralen;
|
||||
};
|
||||
|
||||
static u_int bcache_total_nblks; /* set by bcache_init */
|
||||
@ -250,14 +251,23 @@ read_strategy(void *devdata, int rw, daddr_t blk, size_t size,
|
||||
* increase it when we notice that readahead was useful and decrease
|
||||
* it when we notice that readahead was not useful.
|
||||
*/
|
||||
if (complete) {
|
||||
if (complete || (i == bc->ralen && bc->ralen > 0)) {
|
||||
if (bc->ra < BCACHE_READAHEAD)
|
||||
bc->ra <<= 1; /* increase read ahead */
|
||||
} else {
|
||||
if (nblk - i > BCACHE_MINREADAHEAD && bc->ra > BCACHE_MINREADAHEAD)
|
||||
if (nblk - i > BCACHE_MINREADAHEAD && bc->ralen > 0 &&
|
||||
bc->ra > BCACHE_MINREADAHEAD)
|
||||
bc->ra >>= 1; /* reduce read ahead */
|
||||
}
|
||||
|
||||
/* Adjust our "unconsumed readahead" value. */
|
||||
if (blk == bc->bcache_nextblkno) {
|
||||
if (nblk > bc->ralen)
|
||||
bc->ralen = 0;
|
||||
else
|
||||
bc->ralen -= nblk;
|
||||
}
|
||||
|
||||
if (complete) { /* whole set was in cache, return it */
|
||||
bcopy(bc->bcache_data + (bcache_blksize * BHASH(bc, blk)), buf, size);
|
||||
goto done;
|
||||
@ -314,7 +324,10 @@ read_strategy(void *devdata, int rw, daddr_t blk, size_t size,
|
||||
if (ra != 0 && ra != bc->bcache_nblks) { /* do we have RA space? */
|
||||
ra = MIN(bc->ra, ra - 1);
|
||||
ra = rounddown(ra, 16); /* multiple of 16 blocks */
|
||||
bc->ralen = ra;
|
||||
p_size += ra;
|
||||
} else {
|
||||
bc->ralen = 0;
|
||||
}
|
||||
|
||||
/* invalidate bcache */
|
||||
|
Loading…
Reference in New Issue
Block a user