FreeBSD ZFS
The Zettabyte File System
Data Structures | Defines | Typedefs | Functions | Variables

dmu_zfetch.c File Reference

#include <sys/zfs_context.h>
#include <sys/dnode.h>
#include <sys/dmu_objset.h>
#include <sys/dmu_zfetch.h>
#include <sys/dmu.h>
#include <sys/dbuf.h>
#include <sys/kstat.h>
Include dependency graph for dmu_zfetch.c:

Go to the source code of this file.

Data Structures

struct  zfetch_stats

Defines

#define ZFETCHSTAT_INCR(stat, val)   atomic_add_64(&zfetch_stats.stat.value.ui64, (val));
#define ZFETCHSTAT_BUMP(stat)   ZFETCHSTAT_INCR(stat, 1);

Typedefs

typedef struct zfetch_stats zfetch_stats_t

Functions

 SYSCTL_DECL (_vfs_zfs)
 SYSCTL_INT (_vfs_zfs, OID_AUTO, prefetch_disable, CTLFLAG_RW,&zfs_prefetch_disable, 0,"Disable prefetch")
 SYSCTL_NODE (_vfs_zfs, OID_AUTO, zfetch, CTLFLAG_RW, 0,"ZFS ZFETCH")
 TUNABLE_INT ("vfs.zfs.zfetch.max_streams",&zfetch_max_streams)
 SYSCTL_UINT (_vfs_zfs_zfetch, OID_AUTO, max_streams, CTLFLAG_RW,&zfetch_max_streams, 0,"Max # of streams per zfetch")
 TUNABLE_INT ("vfs.zfs.zfetch.min_sec_reap",&zfetch_min_sec_reap)
 SYSCTL_UINT (_vfs_zfs_zfetch, OID_AUTO, min_sec_reap, CTLFLAG_RDTUN,&zfetch_min_sec_reap, 0,"Min time before stream reclaim")
 TUNABLE_INT ("vfs.zfs.zfetch.block_cap",&zfetch_block_cap)
 SYSCTL_UINT (_vfs_zfs_zfetch, OID_AUTO, block_cap, CTLFLAG_RDTUN,&zfetch_block_cap, 0,"Max number of blocks to fetch at a time")
 TUNABLE_QUAD ("vfs.zfs.zfetch.array_rd_sz",&zfetch_array_rd_sz)
 SYSCTL_UQUAD (_vfs_zfs_zfetch, OID_AUTO, array_rd_sz, CTLFLAG_RDTUN,&zfetch_array_rd_sz, 0,"Number of bytes in a array_read at which we stop prefetching")
static int dmu_zfetch_colinear (zfetch_t *zf, zstream_t *zh)
 Given a zfetch structure and a zstream structure, determine whether the blocks to be read are part of a co-linear pair of existing prefetch streams.
static void dmu_zfetch_dofetch (zfetch_t *zf, zstream_t *zs)
 Given a zstream_t, determine the bounds of the prefetch.
static uint64_t dmu_zfetch_fetch (dnode_t *dn, uint64_t blkid, uint64_t nblks)
 This function computes the actual size, in blocks, that can be prefetched, and fetches it.
static uint64_t dmu_zfetch_fetchsz (dnode_t *dn, uint64_t blkid, uint64_t nblks)
 This function returns the number of blocks that would be prefetched, based upon the supplied dnode, blockid, and nblks.
static int dmu_zfetch_find (zfetch_t *zf, zstream_t *zh, int prefetched)
 Given a zfetch and a zstream structure, see if there is an associated zstream for this block read.
static int dmu_zfetch_stream_insert (zfetch_t *zf, zstream_t *zs)
 Given a zfetch and zstream structure, insert the zstream structure into the AVL tree contained within the zfetch structure.
static zstream_tdmu_zfetch_stream_reclaim (zfetch_t *zf)
 Walk the list of zstreams in the given zfetch, find an old one (by time), and reclaim it for use by the caller.
static void dmu_zfetch_stream_remove (zfetch_t *zf, zstream_t *zs)
 Given a zfetch and zstream structure, remove the zstream structure from its container in the zfetch structure.
static int dmu_zfetch_streams_equal (zstream_t *, zstream_t *)
void zfetch_init (void)
void zfetch_fini (void)
void dmu_zfetch_init (zfetch_t *zf, dnode_t *dno)
 Sets up a zfetch data based on an associated dnode.
void dmu_zfetch_rele (zfetch_t *zf)
 Clean-up state associated with a zfetch structure.
void dmu_zfetch (zfetch_t *zf, uint64_t offset, uint64_t size, int prefetched)
 This is the prefetch entry point.

Variables

int zfs_prefetch_disable = 0
uint32_t zfetch_max_streams = 8
 max # of streams per zfetch
uint32_t zfetch_min_sec_reap = 2
 min time before stream reclaim
uint32_t zfetch_block_cap = 256
 max number of blocks to fetch at a time
uint64_t zfetch_array_rd_sz = 1024 * 1024
 number of bytes in a array_read at which we stop prefetching (1Mb)
static zfetch_stats_t zfetch_stats
kstat_t * zfetch_ksp

Define Documentation

#define ZFETCHSTAT_BUMP (   stat)    ZFETCHSTAT_INCR(stat, 1);

Definition at line 115 of file dmu_zfetch.c.

#define ZFETCHSTAT_INCR (   stat,
  val 
)    atomic_add_64(&zfetch_stats.stat.value.ui64, (val));

Definition at line 112 of file dmu_zfetch.c.


Typedef Documentation

typedef struct zfetch_stats zfetch_stats_t

Function Documentation

void dmu_zfetch ( zfetch_t zf,
uint64_t  offset,
uint64_t  size,
int  prefetched 
)

This is the prefetch entry point.

It calls all of the other dmu_zfetch routines to create, delete, find, or operate upon prefetch streams.

Definition at line 675 of file dmu_zfetch.c.

static int dmu_zfetch_colinear ( zfetch_t zf,
zstream_t zh 
) [static]

Given a zfetch structure and a zstream structure, determine whether the blocks to be read are part of a co-linear pair of existing prefetch streams.

If a set is found, coalesce the streams, removing one, and configure the prefetch so it looks for a strided access pattern.

In other words: if we find two sequential access streams that are the same length and distance N appart, and this read is N from the last stream, then we are probably in a strided access pattern. So combine the two sequential streams into a single strided stream.

Returns:
NULL if no co-linear streams are found, 1 otherwise

Definition at line 133 of file dmu_zfetch.c.

static void dmu_zfetch_dofetch ( zfetch_t zf,
zstream_t zs 
) [static]

Given a zstream_t, determine the bounds of the prefetch.

Then call the routine that actually prefetches the individual blocks.

Definition at line 204 of file dmu_zfetch.c.

static uint64_t dmu_zfetch_fetch ( dnode_t dn,
uint64_t  blkid,
uint64_t  nblks 
) [static]

This function computes the actual size, in blocks, that can be prefetched, and fetches it.

Definition at line 307 of file dmu_zfetch.c.

static uint64_t dmu_zfetch_fetchsz ( dnode_t dn,
uint64_t  blkid,
uint64_t  nblks 
) [static]

This function returns the number of blocks that would be prefetched, based upon the supplied dnode, blockid, and nblks.

This is used so that we can update streams in place, and then prefetch with their old value after the fact. This way, we can delay the prefetch, but subsequent accesses to the stream won't result in the same data being prefetched multiple times.

Definition at line 329 of file dmu_zfetch.c.

static int dmu_zfetch_find ( zfetch_t zf,
zstream_t zh,
int  prefetched 
) [static]

Given a zfetch and a zstream structure, see if there is an associated zstream for this block read.

If so, it starts a prefetch for the stream it located and returns true, otherwise it returns false

Definition at line 355 of file dmu_zfetch.c.

void dmu_zfetch_init ( zfetch_t zf,
dnode_t dno 
)

Sets up a zfetch data based on an associated dnode.

This takes a pointer to a zfetch structure and a dnode. It performs the necessary setup for the zfetch structure, grokking data from the associated dnode.

Definition at line 286 of file dmu_zfetch.c.

void dmu_zfetch_rele ( zfetch_t zf)

Clean-up state associated with a zfetch structure.

This frees allocated structure members, empties the zf_stream tree, and generally makes things nice. This doesn't free the zfetch_t itself, that's left to the caller.

Definition at line 552 of file dmu_zfetch.c.

static int dmu_zfetch_stream_insert ( zfetch_t zf,
zstream_t zs 
) [static]

Given a zfetch and zstream structure, insert the zstream structure into the AVL tree contained within the zfetch structure.

Peform the appropriate book-keeping. It is possible that another thread has inserted a stream which matches one that we are about to insert, so we must be sure to check for this case. If one is found, return failure, and let the caller cleanup the duplicates.

Definition at line 581 of file dmu_zfetch.c.

static zstream_t * dmu_zfetch_stream_reclaim ( zfetch_t zf) [static]

Walk the list of zstreams in the given zfetch, find an old one (by time), and reclaim it for use by the caller.

Definition at line 607 of file dmu_zfetch.c.

static void dmu_zfetch_stream_remove ( zfetch_t zf,
zstream_t zs 
) [static]

Given a zfetch and zstream structure, remove the zstream structure from its container in the zfetch structure.

Perform the appropriate book-keeping.

Definition at line 638 of file dmu_zfetch.c.

static int dmu_zfetch_streams_equal ( zstream_t zs1,
zstream_t zs2 
) [static]

Definition at line 647 of file dmu_zfetch.c.

SYSCTL_DECL ( _vfs_zfs  )
SYSCTL_INT ( _vfs_zfs  ,
OID_AUTO  ,
prefetch_disable  ,
CTLFLAG_RW  ,
zfs_prefetch_disable,
,
"Disable prefetch"   
)
SYSCTL_NODE ( _vfs_zfs  ,
OID_AUTO  ,
zfetch  ,
CTLFLAG_RW  ,
,
"ZFS ZFETCH"   
)
SYSCTL_UINT ( _vfs_zfs_zfetch  ,
OID_AUTO  ,
block_cap  ,
CTLFLAG_RDTUN  ,
zfetch_block_cap,
,
"Max number of blocks to fetch at a time"   
)
SYSCTL_UINT ( _vfs_zfs_zfetch  ,
OID_AUTO  ,
max_streams  ,
CTLFLAG_RW  ,
zfetch_max_streams,
,
"Max # of streams per zfetch  
)
SYSCTL_UINT ( _vfs_zfs_zfetch  ,
OID_AUTO  ,
min_sec_reap  ,
CTLFLAG_RDTUN  ,
zfetch_min_sec_reap,
,
"Min time before stream reclaim"   
)
SYSCTL_UQUAD ( _vfs_zfs_zfetch  ,
OID_AUTO  ,
array_rd_sz  ,
CTLFLAG_RDTUN  ,
zfetch_array_rd_sz,
,
"Number of bytes in a array_read at which we stop prefetching"   
)
TUNABLE_INT ( "vfs.zfs.zfetch.min_sec_reap"  ,
zfetch_min_sec_reap 
)
TUNABLE_INT ( "vfs.zfs.zfetch.max_streams"  ,
zfetch_max_streams 
)
TUNABLE_INT ( "vfs.zfs.zfetch.block_cap"  ,
zfetch_block_cap 
)
TUNABLE_QUAD ( "vfs.zfs.zfetch.array_rd_sz"  ,
zfetch_array_rd_sz 
)
void zfetch_fini ( void  )

Definition at line 270 of file dmu_zfetch.c.

void zfetch_init ( void  )

Definition at line 256 of file dmu_zfetch.c.


Variable Documentation

kstat_t* zfetch_ksp

Definition at line 117 of file dmu_zfetch.c.

Initial value:
 {
        { "hits",                       KSTAT_DATA_UINT64 },
        { "misses",                     KSTAT_DATA_UINT64 },
        { "colinear_hits",              KSTAT_DATA_UINT64 },
        { "colinear_misses",            KSTAT_DATA_UINT64 },
        { "stride_hits",                KSTAT_DATA_UINT64 },
        { "stride_misses",              KSTAT_DATA_UINT64 },
        { "reclaim_successes",          KSTAT_DATA_UINT64 },
        { "reclaim_failures",           KSTAT_DATA_UINT64 },
        { "streams_resets",             KSTAT_DATA_UINT64 },
        { "streams_noresets",           KSTAT_DATA_UINT64 },
        { "bogus_streams",              KSTAT_DATA_UINT64 },
}

Definition at line 98 of file dmu_zfetch.c.

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines