Skip to content

Commit

Permalink
- use VMIO to indicate assignment
Browse files Browse the repository at this point in the history
- remove gratuitous flags
- allocate spa state structure at vdev vnode allocation time
- pass object pointer to copyin / copyout
  • Loading branch information
kmacy committed Dec 24, 2009
1 parent 28a0df2 commit 8aef0fb
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 34 deletions.
6 changes: 3 additions & 3 deletions sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zfs_bio.h
Expand Up @@ -46,8 +46,7 @@ zio_sync_cache(spa_t *spa, blkptr_t *bp, uint64_t txg, void *data,
{
int io_bypass = 0;

if (!zfs_page_cache_disable &&
((vd != NULL) && (vd->vdev_vnode != NULL)) &&
if (!zfs_page_cache_disable && (vd == NULL) &&
((type == ZIO_TYPE_WRITE) || (type == ZIO_TYPE_READ)))
io_bypass = _zio_sync_cache(spa, bp, txg, data, size, type);

Expand All @@ -59,12 +58,13 @@ zio_cache_valid(void *data, uint64_t size, zio_type_t type, vdev_t *vd)
{

if ((vd != NULL) && (type == ZIO_TYPE_READ) &&
(vd->vdev_vnode != NULL) && (size & PAGE_MASK) == 0)
(size & PAGE_MASK) == 0)
_zio_cache_valid(data, size);
}

void *zio_getblk(uint64_t size, int flags);
void zio_relse(void *data, size_t size);
void *zio_spa_state_alloc(spa_t *spa);

#ifdef _KERNEL
void zfs_bio_init(void);
Expand Down
5 changes: 5 additions & 0 deletions sys/cddl/contrib/opensolaris/uts/common/fs/zfs/vdev.c
Expand Up @@ -40,6 +40,10 @@
#include <sys/fs/zfs.h>
#include <sys/arc.h>

#ifdef _KERNEL
#include <sys/zfs_bio.h>
#endif

SYSCTL_DECL(_vfs_zfs);
SYSCTL_NODE(_vfs_zfs, OID_AUTO, vdev, CTLFLAG_RW, 0, "ZFS VDEV");

Expand Down Expand Up @@ -1077,6 +1081,7 @@ vdev_open(vdev_t *vd)
vp->v_type = VREG;
vnode_create_vobject(vp, 512, curthread);
vd->vdev_vnode = vp;
vp->v_data = zio_spa_state_alloc(vd->vdev_spa);
VOP_UNLOCK(vp, 0);
KASSERT(vp->v_object != NULL, ("vnode_create_vobject failed"));

Expand Down
76 changes: 45 additions & 31 deletions sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_bio.c
Expand Up @@ -110,9 +110,7 @@ typedef struct buf * buf_t;

MALLOC_DEFINE(M_ZFS_BIO, "zfs_bio", "zfs buffer cache / vm");

#define B_EVICTED B_00000800
#define B_DATA B_00001000
#define B_ASSIGNED B_00004000

#define ZB_EVICT_ALL 0x1
#define ZB_EVICT_BUFFERED 0x2
Expand Down Expand Up @@ -182,16 +180,16 @@ static buf_hash_table_t buf_hash_table;
static uint64_t
buf_hash(caddr_t va, uint64_t size)
{
uint8_t *vav = (uint8_t *)&va;
uint64_t crc = -1ULL;
uint8_t *vav = (uint8_t *)&va;
int i;

ASSERT(zfs_crc64_table[128] == ZFS_CRC64_POLY);

for (i = i; i < sizeof (caddr_t); i++)
for (i = 0; i < sizeof (caddr_t); i++)
crc = (crc >> 8) ^ zfs_crc64_table[(crc ^ vav[i]) & 0xFF];

crc ^= (size>>9);
crc ^= (size>>4);

return (crc);
}
Expand Down Expand Up @@ -232,6 +230,21 @@ buf_init(void)
mtx_init(&(buf_hash_table.ht_locks[i].ht_lock), buf_lock, NULL, MTX_DEF|MTX_DUPOK);
}

void *
zio_spa_state_alloc(spa_t *spa)
{
struct zio_spa_state *zss;

zss = malloc(sizeof(struct zio_spa_state), M_ZFS_BIO, M_WAITOK|M_ZERO);

zss->zss_spa = spa;
mtx_init(&zss->zss_mtx, "zio_spa_state", NULL, MTX_DEF);
TAILQ_INIT(&zss->zss_blkno_memq);

return (zss);
}


/*
* zio_buf_insert: [ internal use only ]
*
Expand All @@ -244,13 +257,16 @@ INLINE void
zio_buf_va_insert(buf_t bp)
{
caddr_t va = bp->b_data;
uint64_t idx, size = bp->b_bcount;
long idx, size = bp->b_bcount;
struct mtx *lock;
buf_head_t bh;

idx = BUF_HASH_INDEX(va, size);
lock = BUF_HASH_LOCK(idx);
bh = &buf_hash_table.ht_table[idx];

CTR3(KTR_SPARE3, "va_insert(va=%p size=%ld) idx=%ld", va, size, idx);

mtx_lock(lock);
TAILQ_INSERT_HEAD(bh, bp, b_freelist);
mtx_unlock(lock);
Expand Down Expand Up @@ -297,14 +313,17 @@ zio_buf_va_lookup(caddr_t va, uint64_t size)
INLINE buf_t
zio_buf_va_remove(caddr_t va, uint64_t size)
{
uint64_t idx;
long idx;
struct mtx *lock;
buf_head_t bh;
buf_t bp;

idx = BUF_HASH_INDEX(va, size);
lock = BUF_HASH_LOCK(idx);
bh = &buf_hash_table.ht_table[idx];


CTR3(KTR_SPARE3, "va_remove(va=%p size=%ld) idx=%ld", va, (long)size, idx);
mtx_lock(lock);
TAILQ_FOREACH(bp, bh, b_freelist)
if (bp->b_data == va) {
Expand Down Expand Up @@ -489,9 +508,8 @@ zio_buf_blkno_remove(buf_t bp)
}

static __inline void
zio_buf_vm_object_copy(buf_t bp, int direction)
zio_buf_vm_object_copy(vm_object_t object, buf_t bp, int direction)
{
vm_object_t object;
vm_pindex_t start, end;
vm_offset_t offset;
uint64_t byte_offset;
Expand All @@ -501,7 +519,6 @@ zio_buf_vm_object_copy(buf_t bp, int direction)
vm_page_t m;
struct sf_buf *sf;

object = zio_buf_get_vm_object(bp);
byte_offset = stob(bp->b_blkno);
page_offset = byte_offset & PAGE_MASK;
start = OFF_TO_IDX(byte_offset);
Expand Down Expand Up @@ -542,17 +559,17 @@ zio_buf_vm_object_copy(buf_t bp, int direction)
}

static void
zio_buf_vm_object_copyout(buf_t bp)
zio_buf_vm_object_copyout(vm_object_t object, buf_t bp)
{

zio_buf_vm_object_copy(bp, ZB_COPYOUT);
zio_buf_vm_object_copy(object, bp, ZB_COPYOUT);
}

static void
zio_buf_vm_object_copyin(buf_t bp)
zio_buf_vm_object_copyin(vm_object_t object, buf_t bp)
{

zio_buf_vm_object_copy(bp, ZB_COPYIN);
zio_buf_vm_object_copy(object, bp, ZB_COPYIN);
}

static void
Expand Down Expand Up @@ -660,9 +677,7 @@ zio_buf_evict_overlap(vm_object_t object, daddr_t blkno, int size,
TAILQ_REMOVE(&clh, tmpbp, b_freelist);
zio_buf_vm_object_evict(tmpbp);

KASSERT(tmpbp->b_flags & B_EVICTED == 0,
("buffer has already been evicted"));
tmpbp->b_flags |= B_EVICTED;
tmpbp->b_flags &= ~B_VMIO;
state->zss_blkno_root = tmpbp;
/*
* move buffer to the unmanaged tree
Expand Down Expand Up @@ -776,16 +791,18 @@ static buf_t
_zio_getblk_malloc(uint64_t size, int flags)
{
buf_t newbp;
void *data;

if (flags & GB_NODUMP)
data = _zio_data_buf_alloc(size);
else
data = _zio_buf_alloc(size);
newbp = malloc(sizeof(struct buf), M_ZFS_BIO, M_WAITOK|M_ZERO);
newbp->b_data = data;
newbp->b_flags = (B_MALLOC|B_INVAL);
newbp->b_bcount = size;

if (flags & GB_NODUMP) {
newbp->b_flags |= B_DATA;
newbp->b_data = _zio_data_buf_alloc(size);
} else
newbp->b_data = _zio_buf_alloc(size);

return (newbp);
}

static buf_t
Expand Down Expand Up @@ -820,7 +837,7 @@ zio_relse(void *data, size_t size)

bp = zio_buf_va_remove(data, size);

if (bp->b_flags & B_ASSIGNED)
if (bp->b_flags & B_VMIO)
zio_buf_blkno_remove(bp);

if (bp->b_flags & B_MALLOC) {
Expand Down Expand Up @@ -855,9 +872,6 @@ _zio_sync_cache(spa_t *spa, blkptr_t *blkp, uint64_t txg, void *data,

bp = zio_buf_va_lookup(data, size);

KASSERT(bp->b_flags & B_EVICTED == 0,
("doing I/O with cloned or evicted buffer 0x%x", bp->b_flags));

if (bp->b_flags & B_MALLOC) {
zio_buf_evict_overlap(object, blkno, size, state, txg, ZB_EVICT_BUFFERED);

Expand All @@ -866,13 +880,13 @@ _zio_sync_cache(spa_t *spa, blkptr_t *blkp, uint64_t txg, void *data,
* if page resident - copy in
* update zio pipeline
*/
zio_buf_vm_object_copyin(bp);
zio_buf_vm_object_copyin(object, bp);
if (bp->b_flags & B_CACHE) {
/* update zio pipeline */
io_bypass = TRUE;
}
} else {
zio_buf_vm_object_copyout(bp);
zio_buf_vm_object_copyout(object, bp);
}
} else if (bp->b_flags & B_VMIO) {
KASSERT(bp == zio_buf_blkno_lookup(state, blkno),
Expand All @@ -889,7 +903,7 @@ _zio_sync_cache(spa_t *spa, blkptr_t *blkp, uint64_t txg, void *data,
zio_buf_evict_overlap(object, blkno, size, state, NO_TXG,
ZB_EVICT_ALL);
bp->b_blkno = bp->b_lblkno = blkno;
bp->b_flags |= (B_VMIO|B_ASSIGNED);
bp->b_flags |= B_VMIO;
bp->b_birth = txg;
zio_buf_blkno_insert(bp, state);
zio_buf_vm_object_insert(bp, vp, object, zio_op == ZIO_TYPE_WRITE);
Expand All @@ -899,7 +913,7 @@ _zio_sync_cache(spa_t *spa, blkptr_t *blkp, uint64_t txg, void *data,
zio_buf_evict_overlap(object, blkno, size, state, NO_TXG,
ZB_EVICT_BUFFERED);
bp->b_blkno = bp->b_lblkno = blkno;
bp->b_flags |= (B_VMIO|B_ASSIGNED);
bp->b_flags |= B_VMIO;
bp->b_birth = txg;
zio_buf_blkno_insert(bp, state);
VM_OBJECT_LOCK(object);
Expand Down

0 comments on commit 8aef0fb

Please sign in to comment.