* Extend the backing for a non-VMIO buffer. */
| 4212 | * Extend the backing for a non-VMIO buffer. |
| 4213 | */ |
| 4214 | static void |
| 4215 | vfs_nonvmio_extend(struct buf *bp, int newbsize) |
| 4216 | { |
| 4217 | caddr_t origbuf; |
| 4218 | int origbufsize; |
| 4219 | |
| 4220 | /* |
| 4221 | * We only use malloced memory on the first allocation. |
| 4222 | * and revert to page-allocated memory when the buffer |
| 4223 | * grows. |
| 4224 | * |
| 4225 | * There is a potential smp race here that could lead |
| 4226 | * to bufmallocspace slightly passing the max. It |
| 4227 | * is probably extremely rare and not worth worrying |
| 4228 | * over. |
| 4229 | */ |
| 4230 | if (bp->b_bufsize == 0 && newbsize <= PAGE_SIZE/2 && |
| 4231 | bufmallocspace < maxbufmallocspace) { |
| 4232 | bp->b_data = malloc(newbsize, M_BIOBUF, M_WAITOK); |
| 4233 | bp->b_flags |= B_MALLOC; |
| 4234 | bufmallocadjust(bp, newbsize); |
| 4235 | return; |
| 4236 | } |
| 4237 | |
| 4238 | /* |
| 4239 | * If the buffer is growing on its other-than-first |
| 4240 | * allocation then we revert to the page-allocation |
| 4241 | * scheme. |
| 4242 | */ |
| 4243 | origbuf = NULL; |
| 4244 | origbufsize = 0; |
| 4245 | if (bp->b_flags & B_MALLOC) { |
| 4246 | origbuf = bp->b_data; |
| 4247 | origbufsize = bp->b_bufsize; |
| 4248 | bp->b_data = bp->b_kvabase; |
| 4249 | bufmallocadjust(bp, 0); |
| 4250 | bp->b_flags &= ~B_MALLOC; |
| 4251 | newbsize = round_page(newbsize); |
| 4252 | } |
| 4253 | vm_hold_load_pages(bp, (vm_offset_t) bp->b_data + bp->b_bufsize, |
| 4254 | (vm_offset_t) bp->b_data + newbsize); |
| 4255 | if (origbuf != NULL) { |
| 4256 | bcopy(origbuf, bp->b_data, origbufsize); |
| 4257 | free(origbuf, M_BIOBUF); |
| 4258 | } |
| 4259 | bufspace_adjust(bp, newbsize); |
| 4260 | } |
| 4261 | |
| 4262 | /* |
| 4263 | * This code constitutes the buffer memory from either anonymous system |
no test coverage detected