Print this page
3741 zfs needs better comments
Submitted by:   Will Andrews <willa@spectralogic.com>
Submitted by:   Justin Gibbs <justing@spectralogic.com>
Submitted by:   Alan Somers <alans@spectralogic.com>
Reviewed by:    Matthew Ahrens <mahrens@delphix.com>

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/fs/zfs/dmu_zfetch.c
          +++ new/usr/src/uts/common/fs/zfs/dmu_zfetch.c
↓ open down ↓ 40 lines elided ↑ open up ↑
  41   41  /* max # of streams per zfetch */
  42   42  uint32_t        zfetch_max_streams = 8;
  43   43  /* min time before stream reclaim */
  44   44  uint32_t        zfetch_min_sec_reap = 2;
  45   45  /* max number of blocks to fetch at a time */
  46   46  uint32_t        zfetch_block_cap = 256;
  47   47  /* number of bytes in a array_read at which we stop prefetching (1Mb) */
  48   48  uint64_t        zfetch_array_rd_sz = 1024 * 1024;
  49   49  
  50   50  /* forward decls for static routines */
  51      -static int              dmu_zfetch_colinear(zfetch_t *, zstream_t *);
       51 +static boolean_t        dmu_zfetch_colinear(zfetch_t *, zstream_t *);
  52   52  static void             dmu_zfetch_dofetch(zfetch_t *, zstream_t *);
  53   53  static uint64_t         dmu_zfetch_fetch(dnode_t *, uint64_t, uint64_t);
  54   54  static uint64_t         dmu_zfetch_fetchsz(dnode_t *, uint64_t, uint64_t);
  55      -static int              dmu_zfetch_find(zfetch_t *, zstream_t *, int);
       55 +static boolean_t        dmu_zfetch_find(zfetch_t *, zstream_t *, int);
  56   56  static int              dmu_zfetch_stream_insert(zfetch_t *, zstream_t *);
  57   57  static zstream_t        *dmu_zfetch_stream_reclaim(zfetch_t *);
  58   58  static void             dmu_zfetch_stream_remove(zfetch_t *, zstream_t *);
  59   59  static int              dmu_zfetch_streams_equal(zstream_t *, zstream_t *);
  60   60  
  61   61  typedef struct zfetch_stats {
  62   62          kstat_named_t zfetchstat_hits;
  63   63          kstat_named_t zfetchstat_misses;
  64   64          kstat_named_t zfetchstat_colinear_hits;
  65   65          kstat_named_t zfetchstat_colinear_misses;
↓ open down ↓ 31 lines elided ↑ open up ↑
  97   97   * Given a zfetch structure and a zstream structure, determine whether the
  98   98   * blocks to be read are part of a co-linear pair of existing prefetch
  99   99   * streams.  If a set is found, coalesce the streams, removing one, and
 100  100   * configure the prefetch so it looks for a strided access pattern.
 101  101   *
 102  102   * In other words: if we find two sequential access streams that are
 103  103   * the same length and distance N appart, and this read is N from the
 104  104   * last stream, then we are probably in a strided access pattern.  So
 105  105   * combine the two sequential streams into a single strided stream.
 106  106   *
 107      - * If no co-linear streams are found, return NULL.
      107 + * Returns whether co-linear streams were found.
 108  108   */
 109      -static int
      109 +static boolean_t
 110  110  dmu_zfetch_colinear(zfetch_t *zf, zstream_t *zh)
 111  111  {
 112  112          zstream_t       *z_walk;
 113  113          zstream_t       *z_comp;
 114  114  
 115  115          if (! rw_tryenter(&zf->zf_rwlock, RW_WRITER))
 116  116                  return (0);
 117  117  
 118  118          if (zh == NULL) {
 119  119                  rw_exit(&zf->zf_rwlock);
↓ open down ↓ 199 lines elided ↑ open up ↑
 319  319  
 320  320  
 321  321          return (fetchsz);
 322  322  }
 323  323  
 324  324  /*
 325  325   * given a zfetch and a zstream structure, see if there is an associated zstream
 326  326   * for this block read.  If so, it starts a prefetch for the stream it
 327  327   * located and returns true, otherwise it returns false
 328  328   */
 329      -static int
      329 +static boolean_t
 330  330  dmu_zfetch_find(zfetch_t *zf, zstream_t *zh, int prefetched)
 331  331  {
 332  332          zstream_t       *zs;
 333  333          int64_t         diff;
 334  334          int             reset = !prefetched;
 335  335          int             rc = 0;
 336  336  
 337  337          if (zh == NULL)
 338  338                  return (0);
 339  339  
↓ open down ↓ 292 lines elided ↑ open up ↑
 632  632  
 633  633  /*
 634  634   * This is the prefetch entry point.  It calls all of the other dmu_zfetch
 635  635   * routines to create, delete, find, or operate upon prefetch streams.
 636  636   */
 637  637  void
 638  638  dmu_zfetch(zfetch_t *zf, uint64_t offset, uint64_t size, int prefetched)
 639  639  {
 640  640          zstream_t       zst;
 641  641          zstream_t       *newstream;
 642      -        int             fetched;
      642 +        boolean_t       fetched;
 643  643          int             inserted;
 644  644          unsigned int    blkshft;
 645  645          uint64_t        blksz;
 646  646  
 647  647          if (zfs_prefetch_disable)
 648  648                  return;
 649  649  
 650  650          /* files that aren't ln2 blocksz are only one block -- nothing to do */
 651  651          if (!zf->zf_dnode->dn_datablkshift)
 652  652                  return;
↓ open down ↓ 5 lines elided ↑ open up ↑
 658  658          bzero(&zst, sizeof (zstream_t));
 659  659          zst.zst_offset = offset >> blkshft;
 660  660          zst.zst_len = (P2ROUNDUP(offset + size, blksz) -
 661  661              P2ALIGN(offset, blksz)) >> blkshft;
 662  662  
 663  663          fetched = dmu_zfetch_find(zf, &zst, prefetched);
 664  664          if (fetched) {
 665  665                  ZFETCHSTAT_BUMP(zfetchstat_hits);
 666  666          } else {
 667  667                  ZFETCHSTAT_BUMP(zfetchstat_misses);
 668      -                if (fetched = dmu_zfetch_colinear(zf, &zst)) {
      668 +                fetched = dmu_zfetch_colinear(zf, &zst);
      669 +                if (fetched) {
 669  670                          ZFETCHSTAT_BUMP(zfetchstat_colinear_hits);
 670  671                  } else {
 671  672                          ZFETCHSTAT_BUMP(zfetchstat_colinear_misses);
 672  673                  }
 673  674          }
 674  675  
 675  676          if (!fetched) {
 676  677                  newstream = dmu_zfetch_stream_reclaim(zf);
 677  678  
 678  679                  /*
↓ open down ↓ 46 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX