Lines Matching refs:bc
83 #define BHASH(bc, blkno) ((blkno) & ((bc)->bcache_nblks - 1)) argument
84 #define BCACHE_LOOKUP(bc, blkno) \ argument
85 ((bc)->bcache_ctl[BHASH((bc), (blkno))].bc_blkno != (blkno))
90 static void bcache_invalidate(struct bcache *bc, daddr_t blkno);
91 static void bcache_insert(struct bcache *bc, daddr_t blkno);
92 static void bcache_free_instance(struct bcache *bc);
123 struct bcache *bc = malloc(sizeof (struct bcache)); in bcache_allocate() local
129 if (bc == NULL) { in bcache_allocate()
131 return (bc); in bcache_allocate()
141 bc->bcache_nblks = bcache_total_nblks >> i; in bcache_allocate()
142 bcache_unit_nblks = bc->bcache_nblks; in bcache_allocate()
143 bc->bcache_data = malloc(bc->bcache_nblks * bcache_blksize); in bcache_allocate()
144 if (bc->bcache_data == NULL) { in bcache_allocate()
146 bc->bcache_nblks = 32; in bcache_allocate()
147 bc->bcache_data = malloc(bc->bcache_nblks * bcache_blksize + in bcache_allocate()
151 bc->bcache_ctl = malloc(bc->bcache_nblks * sizeof(struct bcachectl)); in bcache_allocate()
153 if ((bc->bcache_data == NULL) || (bc->bcache_ctl == NULL)) { in bcache_allocate()
154 bcache_free_instance(bc); in bcache_allocate()
160 for (i = 0; i < bc->bcache_nblks; i++) { in bcache_allocate()
161 bc->bcache_ctl[i].bc_count = -1; in bcache_allocate()
162 bc->bcache_ctl[i].bc_blkno = -1; in bcache_allocate()
165 bc->ra = BCACHE_READAHEAD; /* optimistic read ahead */ in bcache_allocate()
166 bc->bcache_nextblkno = -1; in bcache_allocate()
167 return (bc); in bcache_allocate()
173 struct bcache *bc = cache; in bcache_free() local
175 if (bc == NULL) in bcache_free()
178 bcache_free_instance(bc); in bcache_free()
191 struct bcache *bc = dd->dv_cache; in write_strategy() local
198 bcache_invalidate(bc, blk + i); in write_strategy()
215 struct bcache *bc = dd->dv_cache; in read_strategy() local
221 if (bc == NULL) { in read_strategy()
237 if (BCACHE_LOOKUP(bc, (daddr_t)(blk + i))) { in read_strategy()
252 if (complete || (i == bc->ralen && bc->ralen > 0)) { in read_strategy()
253 if (bc->ra < BCACHE_READAHEAD) in read_strategy()
254 bc->ra <<= 1; /* increase read ahead */ in read_strategy()
256 if (nblk - i > BCACHE_MINREADAHEAD && bc->ralen > 0 && in read_strategy()
257 bc->ra > BCACHE_MINREADAHEAD) in read_strategy()
258 bc->ra >>= 1; /* reduce read ahead */ in read_strategy()
262 if (blk == bc->bcache_nextblkno) { in read_strategy()
263 if (nblk > bc->ralen) in read_strategy()
264 bc->ralen = 0; in read_strategy()
266 bc->ralen -= nblk; in read_strategy()
270 bcopy(bc->bcache_data + (bcache_blksize * BHASH(bc, blk)), buf, size); in read_strategy()
280 p_buf = bc->bcache_data + (bcache_blksize * BHASH(bc, p_blk)); in read_strategy()
281 r_size = bc->bcache_nblks - BHASH(bc, p_blk); /* remaining blocks */ in read_strategy()
312 ra = bc->bcache_nblks - BHASH(bc, p_blk + p_size); in read_strategy()
318 if ((bc->bcache_nextblkno != blk) && ra != 0) { in read_strategy()
322 if (ra != 0 && ra != bc->bcache_nblks) { /* do we have RA space? */ in read_strategy()
323 ra = MIN(bc->ra, ra - 1); in read_strategy()
327 bc->ralen = ra; in read_strategy()
330 bc->ralen = 0; in read_strategy()
335 bcache_invalidate(bc, p_blk + i); in read_strategy()
353 bcache_insert(bc, p_blk + i); in read_strategy()
365 if (BCACHE_LOOKUP(bc, (daddr_t)(blk + i))) in read_strategy()
373 bcopy(bc->bcache_data + (bcache_blksize * BHASH(bc, blk)), buf, size); in read_strategy()
381 bc->bcache_nextblkno = blk + (size / DEV_BSIZE); in read_strategy()
395 struct bcache *bc = dd->dv_cache; in bcache_strategy() local
402 if (bc != NULL) in bcache_strategy()
403 bcache_nblks = bc->bcache_nblks; in bcache_strategy()
406 if (bc == NULL || in bcache_strategy()
423 cblk = bcache_nblks - BHASH(bc, blk); /* # of blocks left */ in bcache_strategy()
462 bcache_free_instance(struct bcache *bc) in bcache_free_instance() argument
464 if (bc != NULL) { in bcache_free_instance()
465 free(bc->bcache_ctl); in bcache_free_instance()
466 free(bc->bcache_data); in bcache_free_instance()
467 free(bc); in bcache_free_instance()
475 bcache_insert(struct bcache *bc, daddr_t blkno) in bcache_insert() argument
479 cand = BHASH(bc, blkno); in bcache_insert()
482 bc->bcache_ctl[cand].bc_blkno = blkno; in bcache_insert()
483 bc->bcache_ctl[cand].bc_count = bcache_bcount++; in bcache_insert()
490 bcache_invalidate(struct bcache *bc, daddr_t blkno) in bcache_invalidate() argument
494 i = BHASH(bc, blkno); in bcache_invalidate()
495 if (bc->bcache_ctl[i].bc_blkno == blkno) { in bcache_invalidate()
496 bc->bcache_ctl[i].bc_count = -1; in bcache_invalidate()
497 bc->bcache_ctl[i].bc_blkno = -1; in bcache_invalidate()