Changeset View
Changeset View
Standalone View
Standalone View
stand/common/bcache.c
Show First 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | |||||
* to boot from, but this has changed with zfs. | * to boot from, but this has changed with zfs. | ||||
*/ | */ | ||||
struct bcache { | struct bcache { | ||||
struct bcachectl *bcache_ctl; | struct bcachectl *bcache_ctl; | ||||
caddr_t bcache_data; | caddr_t bcache_data; | ||||
size_t bcache_nblks; | size_t bcache_nblks; | ||||
size_t ra; | size_t ra; | ||||
daddr_t bcache_nextblkno; | daddr_t bcache_nextblkno; | ||||
size_t ralen; | |||||
}; | }; | ||||
static u_int bcache_total_nblks; /* set by bcache_init */ | static u_int bcache_total_nblks; /* set by bcache_init */ | ||||
static u_int bcache_blksize; /* set by bcache_init */ | static u_int bcache_blksize; /* set by bcache_init */ | ||||
static u_int bcache_numdev; /* set by bcache_add_dev */ | static u_int bcache_numdev; /* set by bcache_add_dev */ | ||||
/* statistics */ | /* statistics */ | ||||
static u_int bcache_units; /* number of devices with cache */ | static u_int bcache_units; /* number of devices with cache */ | ||||
static u_int bcache_unit_nblks; /* nblocks per unit */ | static u_int bcache_unit_nblks; /* nblocks per unit */ | ||||
▲ Show 20 Lines • Show All 161 Lines • ▼ Show 20 Lines | if (BCACHE_LOOKUP(bc, (daddr_t)(blk + i))) { | ||||
bcache_misses += (nblk - i); | bcache_misses += (nblk - i); | ||||
complete = 0; | complete = 0; | ||||
break; | break; | ||||
} else { | } else { | ||||
bcache_hits++; | bcache_hits++; | ||||
} | } | ||||
} | } | ||||
/* | /* | ||||
imp: It would be good to document what 'if approrpiate' means here. The kernel has extensive… | |||||
Done Inline ActionsWill do. cperciva: Will do. | |||||
* Adjust read-ahead size if appropriate. Subject to the requirement | * Adjust read-ahead size if appropriate. Subject to the requirement | ||||
* that bc->ra must stay in between MINREADAHEAD and READAHEAD, we | * that bc->ra must stay in between MINREADAHEAD and READAHEAD, we | ||||
* increase it when we notice that readahead was useful and decrease | * increase it when we notice that readahead was useful and decrease | ||||
* it when we notice that readahead was not useful. | * it when we notice that readahead was not useful. | ||||
*/ | */ | ||||
Not Done Inline ActionsThis line is likely too wide now imp: This line is likely too wide now | |||||
Done Inline ActionsThis file isn't consistently styled, but yes I'll rewrap that bit. cperciva: This file isn't consistently styled, but yes I'll rewrap that bit. | |||||
if (complete) { | if (complete || (i == bc->ralen && bc->ralen > 0)) { | ||||
if (bc->ra < BCACHE_READAHEAD) | if (bc->ra < BCACHE_READAHEAD) | ||||
bc->ra <<= 1; /* increase read ahead */ | bc->ra <<= 1; /* increase read ahead */ | ||||
} else { | } 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 */ | 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 */ | if (complete) { /* whole set was in cache, return it */ | ||||
bcopy(bc->bcache_data + (bcache_blksize * BHASH(bc, blk)), buf, size); | bcopy(bc->bcache_data + (bcache_blksize * BHASH(bc, blk)), buf, size); | ||||
goto done; | goto done; | ||||
} | } | ||||
/* | /* | ||||
* Fill in any misses. From check we have i pointing to first missing | * Fill in any misses. From check we have i pointing to first missing | ||||
* block, read in all remaining blocks + readahead. | * block, read in all remaining blocks + readahead. | ||||
Show All 40 Lines | ra = bc->bcache_nblks - BHASH(bc, p_blk + p_size); | ||||
*/ | */ | ||||
if ((bc->bcache_nextblkno != blk) && ra != 0) { | if ((bc->bcache_nextblkno != blk) && ra != 0) { | ||||
ra = 0; | ra = 0; | ||||
} | } | ||||
if (ra != 0 && ra != bc->bcache_nblks) { /* do we have RA space? */ | if (ra != 0 && ra != bc->bcache_nblks) { /* do we have RA space? */ | ||||
ra = MIN(bc->ra, ra - 1); | ra = MIN(bc->ra, ra - 1); | ||||
ra = rounddown(ra, 16); /* multiple of 16 blocks */ | ra = rounddown(ra, 16); /* multiple of 16 blocks */ | ||||
bc->ralen = ra; | |||||
p_size += ra; | p_size += ra; | ||||
} else { | |||||
bc->ralen = 0; | |||||
} | } | ||||
/* invalidate bcache */ | /* invalidate bcache */ | ||||
for (i = 0; i < p_size; i++) { | for (i = 0; i < p_size; i++) { | ||||
bcache_invalidate(bc, p_blk + i); | bcache_invalidate(bc, p_blk + i); | ||||
} | } | ||||
r_size = 0; | r_size = 0; | ||||
▲ Show 20 Lines • Show All 184 Lines • Show Last 20 Lines |
It would be good to document what 'if approrpiate' means here. The kernel has extensive comments explaining what's going on and that would be useful here.