1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-20 11:11:24 +00:00

Rewrite the vfs_bio_clrbuf(9) to not access the b_data for B_VMIO

buffers directly, use pmap_zero_page_area(9) for each zeroing page
region instead.

Sponsored by:	The FreeBSD Foundation
Tested by:	pho
MFC after:	2 weeks
This commit is contained in:
Konstantin Belousov 2013-03-14 19:48:25 +00:00
parent 397ae429f7
commit a1143a3ba8
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=248276

View File

@ -3712,8 +3712,7 @@ vfs_bio_set_valid(struct buf *bp, int base, int size)
void
vfs_bio_clrbuf(struct buf *bp)
{
int i, j, mask;
caddr_t sa, ea;
int i, j, mask, sa, ea, slide;
if ((bp->b_flags & (B_VMIO | B_MALLOC)) != B_VMIO) {
clrbuf(bp);
@ -3731,30 +3730,33 @@ vfs_bio_clrbuf(struct buf *bp)
if ((bp->b_pages[0]->valid & mask) == mask)
goto unlock;
if ((bp->b_pages[0]->valid & mask) == 0) {
bzero(bp->b_data, bp->b_bufsize);
pmap_zero_page_area(bp->b_pages[0], 0, bp->b_bufsize);
bp->b_pages[0]->valid |= mask;
goto unlock;
}
}
ea = sa = bp->b_data;
for(i = 0; i < bp->b_npages; i++, sa = ea) {
ea = (caddr_t)trunc_page((vm_offset_t)sa + PAGE_SIZE);
ea = (caddr_t)(vm_offset_t)ulmin(
(u_long)(vm_offset_t)ea,
(u_long)(vm_offset_t)bp->b_data + bp->b_bufsize);
sa = bp->b_offset & PAGE_MASK;
slide = 0;
for (i = 0; i < bp->b_npages; i++, sa = 0) {
slide = imin(slide + PAGE_SIZE, bp->b_offset + bp->b_bufsize);
ea = slide & PAGE_MASK;
if (ea == 0)
ea = PAGE_SIZE;
if (bp->b_pages[i] == bogus_page)
continue;
j = ((vm_offset_t)sa & PAGE_MASK) / DEV_BSIZE;
j = sa / DEV_BSIZE;
mask = ((1 << ((ea - sa) / DEV_BSIZE)) - 1) << j;
VM_OBJECT_ASSERT_WLOCKED(bp->b_pages[i]->object);
if ((bp->b_pages[i]->valid & mask) == mask)
continue;
if ((bp->b_pages[i]->valid & mask) == 0)
bzero(sa, ea - sa);
pmap_zero_page_area(bp->b_pages[i], sa, ea - sa);
else {
for (; sa < ea; sa += DEV_BSIZE, j++) {
if ((bp->b_pages[i]->valid & (1 << j)) == 0)
bzero(sa, DEV_BSIZE);
if ((bp->b_pages[i]->valid & (1 << j)) == 0) {
pmap_zero_page_area(bp->b_pages[i],
sa, DEV_BSIZE);
}
}
}
bp->b_pages[i]->valid |= mask;