1. 30 9月, 2008 1 次提交
    • C
      Btrfs: add and improve comments · d352ac68
      Chris Mason 提交于
      This improves the comments at the top of many functions.  It didn't
      dive into the guts of functions because I was trying to
      avoid merging problems with the new allocator and back reference work.
      
      extent-tree.c and volumes.c were both skipped, and there is definitely
      more work todo in cleaning and commenting the code.
      Signed-off-by: NChris Mason <chris.mason@oracle.com>
      d352ac68
  2. 29 9月, 2008 1 次提交
    • C
      Btrfs: Wait for IO on the block device inodes of newly added devices · 8c8bee1d
      Chris Mason 提交于
      btrfs-vol -a /dev/xxx will zero the first and last two MB of the device.
      The kernel code needs to wait for this IO to finish before it adds
      the device.
      
      btrfs metadata IO does not happen through the block device inode.  A
      separate address space is used, allowing the zero filled buffer heads in
      the block device inode to be written to disk after FS metadata starts
      going down to the disk via the btrfs metadata inode.
      
      The end result is zero filled metadata blocks after adding new devices
      into the filesystem.
      
      The fix is a simple filemap_write_and_wait on the block device inode
      before actually inserting it into the pool of available devices.
      Signed-off-by: NChris Mason <chris.mason@oracle.com>
      8c8bee1d
  3. 26 9月, 2008 4 次提交
    • Z
      Btrfs: update space balancing code · 1a40e23b
      Zheng Yan 提交于
      This patch updates the space balancing code to utilize the new
      backref format.  Before, btrfs-vol -b would break any COW links
      on data blocks or metadata.  This was slow and caused the amount
      of space used to explode if a large number of snapshots were present.
      
      The new code can keeps the sharing of all data extents and
      most of the tree blocks.
      
      To maintain the sharing of data extents, the space balance code uses
      a seperate inode hold data extent pointers, then updates the references
      to point to the new location.
      
      To maintain the sharing of tree blocks, the space balance code uses
      reloc trees to relocate tree blocks in reference counted roots.
      There is one reloc tree for each subvol, and all reloc trees share
      same root key objectid. Reloc trees are snapshots of the latest
      committed roots of subvols (root->commit_root).
      
      To relocate a tree block referenced by a subvol, there are two steps.
      COW the block through subvol's reloc tree, then update block pointer in
      the subvol to point to the new block. Since all reloc trees share
      same root key objectid, doing special handing for tree blocks
      owned by them is easy. Once a tree block has been COWed in one
      reloc tree, we can use the resulting new block directly when the
      same block is required to COW again through other reloc trees.
      In this way, relocated tree blocks are shared between reloc trees,
      so they are also shared between subvols.
      Signed-off-by: NChris Mason <chris.mason@oracle.com>
      1a40e23b
    • Z
      Btrfs: Add shared reference cache · e4657689
      Zheng Yan 提交于
      Btrfs has a cache of reference counts in leaves, allowing it to
      avoid reading tree leaves while deleting snapshots.  To reduce
      contention with multiple subvolumes, this cache is private to each
      subvolume.
      
      This patch adds shared reference cache support. The new space
      balancing code plays with multiple subvols at the same time, So
      the old per-subvol reference cache is not well suited.
      Signed-off-by: NChris Mason <chris.mason@oracle.com>
      e4657689
    • C
      Btrfs: Raise thresholds for metadata writeback · 24ab9cd8
      Chris Mason 提交于
      Btrfs metadata writeback is fairly expensive.  Once a tree block is written
      it must be cowed before it can be changed again.  The btree writepages
      code has a threshold based on a count of dirty btree bytes which is
      updated as IO is sent out.
      
      This changes btree_writepages to skip the writeout if there are less
      than 32MB of dirty bytes from the btrees, improving performance
      across many workloads.
      Signed-off-by: NChris Mason <chris.mason@oracle.com>
      24ab9cd8
    • C
      Remove Btrfs compat code for older kernels · 2b1f55b0
      Chris Mason 提交于
      Btrfs had compatibility code for kernels back to 2.6.18.  These have
      been removed, and will be maintained in a separate backport
      git tree from now on.
      Signed-off-by: NChris Mason <chris.mason@oracle.com>
      2b1f55b0
  4. 25 9月, 2008 34 次提交
    • Z
      Btrfs: Full back reference support · 31840ae1
      Zheng Yan 提交于
      This patch makes the back reference system to explicit record the
      location of parent node for all types of extents. The location of
      parent node is placed into the offset field of backref key. Every
      time a tree block is balanced, the back references for the affected
      lower level extents are updated.
      Signed-off-by: NChris Mason <chris.mason@oracle.com>
      31840ae1
    • C
      Btrfs: Checksum tree blocks in the background · ce3ed71a
      Chris Mason 提交于
      Tree blocks were using async bio submission, but the sum was still
      being done directly during writepage.  This moves the checksumming
      into the worker thread.
      Signed-off-by: NChris Mason <chris.mason@oracle.com>
      ce3ed71a
    • J
      Btrfs: free space accounting redo · 0f9dd46c
      Josef Bacik 提交于
      1) replace the per fs_info extent_io_tree that tracked free space with two
      rb-trees per block group to track free space areas via offset and size.  The
      reason to do this is because most allocations come with a hint byte where to
      start, so we can usually find a chunk of free space at that hint byte to satisfy
      the allocation and get good space packing.  If we cannot find free space at or
      after the given offset we fall back on looking for a chunk of the given size as
      close to that given offset as possible.  When we fall back on the size search we
      also try to find a slot as close to the size we want as possible, to avoid
      breaking small chunks off of huge areas if possible.
      
      2) remove the extent_io_tree that tracked the block group cache from fs_info and
      replaced it with an rb-tree thats tracks block group cache via offset.  also
      added a per space_info list that tracks the block group cache for the particular
      space so we can lookup related block groups easily.
      
      3) cleaned up the allocation code to make it a little easier to read and a
      little less complicated.  Basically there are 3 steps, first look from our
      provided hint.  If we couldn't find from that given hint, start back at our
      original search start and look for space from there.  If that fails try to
      allocate space if we can and start looking again.  If not we're screwed and need
      to start over again.
      
      4) small fixes.  there were some issues in volumes.c where we wouldn't allocate
      the rest of the disk.  fixed cow_file_range to actually pass the alloc_hint,
      which has helped a good bit in making the fs_mark test I run have semi-normal
      results as we run out of space.  Generally with data allocations we don't track
      where we last allocated from, so everytime we did a data allocation we'd search
      through every block group that we have looking for free space.  Now searching a
      block group with no free space isn't terribly time consuming, it was causing a
      slight degradation as we got more data block groups.  The alloc_hint has fixed
      this slight degredation and made things semi-normal.
      
      There is still one nagging problem I'm working on where we will get ENOSPC when
      there is definitely plenty of space.  This only happens with metadata
      allocations, and only when we are almost full.  So you generally hit the 85%
      mark first, but sometimes you'll hit the BUG before you hit the 85% wall.  I'm
      still tracking it down, but until then this seems to be pretty stable and make a
      significant performance gain.
      Signed-off-by: NChris Mason <chris.mason@oracle.com>
      0f9dd46c
    • C
      Btrfs: Fix mismerge in block header checks · 23a07867
      Chris Mason 提交于
      I had incorrectly disabled the check for the block number being correct
      in the header block.
      Signed-off-by: NChris Mason <chris.mason@oracle.com>
      23a07867
    • C
      Btrfs: Record dirty pages tree-log pages in an extent_io tree · d0c803c4
      Chris Mason 提交于
      This is the same way the transaction code makes sure that all the
      other tree blocks are safely on disk.  There's an extent_io tree
      for each root, and any blocks allocated to the tree logs are
      recorded in that tree.
      
      At tree-log sync, the extent_io tree is walked to flush down the
      dirty pages and wait for them.
      
      The main benefit is less time spent walking the tree log and skipping
      clean pages, and getting sequential IO down to the drive.
      Signed-off-by: NChris Mason <chris.mason@oracle.com>
      d0c803c4
    • C
      Btrfs: Optimize tree log block allocations · d00aff00
      Chris Mason 提交于
      Since tree log blocks get freed every transaction, they never really
      need to be written to disk.  This skips the step where we update
      metadata to record they were allocated.
      Signed-off-by: NChris Mason <chris.mason@oracle.com>
      d00aff00
    • C
      3a5f1d45
    • C
    • C
      Btrfs: Tree logging fixes · 4bef0848
      Chris Mason 提交于
      * Pin down data blocks to prevent them from being reallocated like so:
      
      trans 1: allocate file extent
      trans 2: free file extent
      trans 3: free file extent during old snapshot deletion
      trans 3: allocate file extent to new file
      trans 3: fsync new file
      
      Before the tree logging code, this was legal because the fsync
      would commit the transation that did the final data extent free
      and the transaction that allocated the extent to the new file
      at the same time.
      
      With the tree logging code, the tree log subtransaction can commit
      before the transaction that freed the extent.  If we crash,
      we're left with two different files using the extent.
      
      * Don't wait in start_transaction if log replay is going on.  This
      avoids deadlocks from iput while we're cleaning up link counts in the
      replay code.
      
      * Don't deadlock in replay_one_name by trying to read an inode off
      the disk while holding paths for the directory
      
      * Hold the buffer lock while we mark a buffer as written.  This
      closes a race where someone is changing a buffer while we write it.
      They are supposed to mark it dirty again after they change it, but
      this violates the cow rules.
      Signed-off-by: NChris Mason <chris.mason@oracle.com>
      4bef0848
    • C
      Btrfs: Add a write ahead tree log to optimize synchronous operations · e02119d5
      Chris Mason 提交于
      File syncs and directory syncs are optimized by copying their
      items into a special (copy-on-write) log tree.  There is one log tree per
      subvolume and the btrfs super block points to a tree of log tree roots.
      
      After a crash, items are copied out of the log tree and back into the
      subvolume.  See tree-log.c for all the details.
      Signed-off-by: NChris Mason <chris.mason@oracle.com>
      e02119d5
    • C
      a1b32a59
    • C
      Btrfs: Throttle for async bio submits higher up the chain · 9473f16c
      Chris Mason 提交于
      The current code waits for the count of async bio submits to get below
      a given threshold if it is too high right after adding the latest bio
      to the work queue.  This isn't optimal because the caller may have
      sequential adjacent bios pending they are waiting to send down the pipe.
      
      This changeset requires the caller to wait on the async bio count,
      and changes the async checksumming submits to wait for async bios any
      time they self throttle.
      
      The end result is much higher sequential throughput.
      Signed-off-by: NChris Mason <chris.mason@oracle.com>
      9473f16c
    • C
      Btrfs: Wait for async bio submissions to make some progress at queue time · b64a2851
      Chris Mason 提交于
      Before, the btrfs bdi congestion function was used to test for too many
      async bios.  This keeps that check to throttle pdflush, but also
      adds a check while queuing bios.
      Signed-off-by: NChris Mason <chris.mason@oracle.com>
      b64a2851
    • C
      Btrfs: Lower contention on the csum mutex · 53863232
      Chris Mason 提交于
      This takes the csum mutex deeper in the call chain and releases it
      more often.
      Signed-off-by: NChris Mason <chris.mason@oracle.com>
      53863232
    • C
      Btrfs: Wait for kernel threads to make progress during async submission · 4854ddd0
      Chris Mason 提交于
      Before this change, btrfs would use a bdi congestion function to make
      sure there weren't too many pending async checksum work items.
      
      This change makes the process creating async work items wait instead,
      leading to fewer congestion returns from the bdi.  This improves
      pdflush background_writeout scanning.
      Signed-off-by: NChris Mason <chris.mason@oracle.com>
      4854ddd0
    • C
      5443be45
    • C
      Btrfs: Transaction commit: don't use filemap_fdatawait · 777e6bd7
      Chris Mason 提交于
      After writing out all the remaining btree blocks in the transaction,
      the commit code would use filemap_fdatawait to make sure it was all
      on disk.  This means it would wait for blocks written by other procs
      as well.
      
      The new code walks the list of blocks for this transaction again
      and waits only for those required by this transaction.
      Signed-off-by: NChris Mason <chris.mason@oracle.com>
      777e6bd7
    • C
    • C
    • C
    • C
    • C
      Btrfs: More throttle tuning · 2dd3e67b
      Chris Mason 提交于
      * Make walk_down_tree wake up throttled tasks more often
      * Make walk_down_tree call cond_resched during long loops
      * As the size of the ref cache grows, wait longer in throttle
      * Get rid of the reada code in walk_down_tree, the leaves don't get
        read anymore, thanks to the ref cache.
      Signed-off-by: NChris Mason <chris.mason@oracle.com>
      2dd3e67b
    • C
      Btrfs: Fix streaming read performance with checksumming on · 61b49440
      Chris Mason 提交于
      Large streaming reads make for large bios, which means each entry on the
      list async work queues represents a large amount of data.  IO
      congestion throttling on the device was kicking in before the async
      worker threads decided a single thread was busy and needed some help.
      
      The end result was that a streaming read would result in a single CPU
      running at 100% instead of balancing the work off to other CPUs.
      
      This patch also changes the pre-IO checksum lookup done by reads to
      work on a per-bio basis instead of a per-page.  This results in many
      extra btree lookups on large streaming reads.  Doing the checksum lookup
      right before bio submit allows us to reuse searches while processing
      adjacent offsets.
      Signed-off-by: NChris Mason <chris.mason@oracle.com>
      61b49440
    • Y
      Btrfs: implement memory reclaim for leaf reference cache · bcc63abb
      Yan 提交于
      The memory reclaiming issue happens when snapshot exists. In that
      case, some cache entries may not be used during old snapshot dropping,
      so they will remain in the cache until umount.
      
      The patch adds a field to struct btrfs_leaf_ref to record create time. Besides,
      the patch makes all dead roots of a given snapshot linked together in order of
      create time. After a old snapshot was completely dropped, we check the dead
      root list and remove all cache entries created before the oldest dead root in
      the list.
      Signed-off-by: NChris Mason <chris.mason@oracle.com>
      bcc63abb
    • C
      Btrfs: Fix verify_parent_transid · 33958dc6
      Chris Mason 提交于
      It was incorrectly clearing the up to date flag on the buffer even
      when the buffer properly verified.
      Signed-off-by: NChris Mason <chris.mason@oracle.com>
      33958dc6
    • C
      Btrfs: Throttle operations if the reference cache gets too large · ab78c84d
      Chris Mason 提交于
      A large reference cache is directly related to a lot of work pending
      for the cleaner thread.  This throttles back new operations based on
      the size of the reference cache so the cleaner thread will be able to keep
      up.
      
      Overall, this actually makes the FS faster because the cleaner thread will
      be more likely to find things in cache.
      Signed-off-by: NChris Mason <chris.mason@oracle.com>
      ab78c84d
    • C
      Btrfs: Leaf reference cache update · 017e5369
      Chris Mason 提交于
      This changes the reference cache to make a single cache per root
      instead of one cache per transaction, and to key by the byte number
      of the disk block instead of the keys inside.
      
      This makes it much less likely to have cache misses if a snapshot
      or something has an extra reference on a higher node or a leaf while
      the first transaction that added the leaf into the cache is dropping.
      
      Some throttling is added to functions that free blocks heavily so they
      wait for old transactions to drop.
      Signed-off-by: NChris Mason <chris.mason@oracle.com>
      017e5369
    • Y
      Btrfs: Add a leaf reference cache · 31153d81
      Yan Zheng 提交于
      Much of the IO done while dropping snapshots is done looking up
      leaves in the filesystem trees to see if they point to any extents and
      to drop the references on any extents found.
      
      This creates a cache so that IO isn't required.
      Signed-off-by: NChris Mason <chris.mason@oracle.com>
      31153d81
    • J
    • C
      Btrfs: Fix the defragmention code and the block relocation code for data=ordered · 3eaa2885
      Chris Mason 提交于
      Before setting an extent to delalloc, the code needs to wait for
      pending ordered extents.
      
      Also, the relocation code needs to wait for ordered IO before scanning
      the block group again.  This is because the extents are not removed
      until the IO for the new extents is finished
      Signed-off-by: NChris Mason <chris.mason@oracle.com>
      3eaa2885
    • C
      Btrfs: Search data ordered extents first for checksums on read · 89642229
      Chris Mason 提交于
      Checksum items are not inserted into the tree until all of the io from a
      given extent is complete.  This means one dirty page from an extent may
      be written, freed, and then read again before the entire extent is on disk
      and the checksum item is inserted.
      
      The checksums themselves are stored in the ordered extent so they can
      be inserted in bulk when IO is complete.  On read, if a checksum item isn't
      found, the ordered extents were being searched for a checksum record.
      
      This all worked most of the time, but the checksum insertion code tries
      to reduce the number of tree operations by pre-inserting checksum items
      based on i_size and a few other factors.  This means the read code might
      find a checksum item that hasn't yet really been filled in.
      
      This commit changes things to check the ordered extents first and only
      dive into the btree if nothing was found.  This removes the need for
      extra locking and is more reliable.
      Signed-off-by: NChris Mason <chris.mason@oracle.com>
      89642229
    • C
      Btrfs: Index extent buffers in an rbtree · 6af118ce
      Chris Mason 提交于
      Before, extent buffers were a temporary object, meant to map a number of pages
      at once and collect operations on them.
      
      But, a few extra fields have crept in, and they are also the best place to
      store a per-tree block lock field as well.  This commit puts the extent
      buffers into an rbtree, and ensures a single extent buffer for each
      tree block.
      Signed-off-by: NChris Mason <chris.mason@oracle.com>
      6af118ce
    • C
      btrfs_start_transaction: wait for commits in progress to finish · f9295749
      Chris Mason 提交于
      btrfs_commit_transaction has to loop waiting for any writers in the
      transaction to finish before it can proceed.  btrfs_start_transaction
      should be polite and not join a transaction that is in the process
      of being finished off.
      
      There are a few places that can't wait, basically the ones doing IO that
      might be needed to finish the transaction.  For them, btrfs_join_transaction
      is added.
      Signed-off-by: NChris Mason <chris.mason@oracle.com>
      f9295749
    • C
      Btrfs: Use async helpers to deal with pages that have been improperly dirtied · 247e743c
      Chris Mason 提交于
      Higher layers sometimes call set_page_dirty without asking the filesystem
      to help.  This causes many problems for the data=ordered and cow code.
      This commit detects pages that haven't been properly setup for IO and
      kicks off an async helper to deal with them.
      Signed-off-by: NChris Mason <chris.mason@oracle.com>
      247e743c