1. 09 Oct, 2008 3 commits
  2. 03 Oct, 2008 1 commit
    • Chris Mason's avatar
      Btrfs: remove last_log_alloc allocator optimization · 30c43e24
      Chris Mason authored
      The tree logging code was trying to separate tree log allocations
      from normal metadata allocations to improve writeback patterns during
      an fsync.
      But, the code was not effective and ended up just mixing tree log
      blocks with regular metadata.  That seems to be working fairly well,
      so the last_log_alloc code can be removed.
      Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
  3. 01 Oct, 2008 1 commit
    • Chris Mason's avatar
      Btrfs: don't read leaf blocks containing only checksums during truncate · 323ac95b
      Chris Mason authored
      Checksum items take up a significant portion of the metadata for large files.
      It is possible to avoid reading them during truncates by checking the keys in
      the higher level nodes.
      If a given leaf is followed by another leaf where the lowest key is a checksum
      item from the same file, we know we can safely delete the leaf without
      reading it.
      For a 32GB file on a 6 drive raid0 array, Btrfs needs 8s to delete
      the file with a cold cache.  It is read bound during the run.
      With this change, Btrfs is able to delete the file in 0.5s
      Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
  4. 29 Sep, 2008 2 commits
    • Chris Mason's avatar
      Btrfs: add and improve comments · d352ac68
      Chris Mason authored
      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: default avatarChris Mason <chris.mason@oracle.com>
    • Chris Mason's avatar
      Btrfs: Wait for IO on the block device inodes of newly added devices · 8c8bee1d
      Chris Mason authored
      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: default avatarChris Mason <chris.mason@oracle.com>
  5. 26 Sep, 2008 4 commits
    • Zheng Yan's avatar
      Btrfs: update space balancing code · 1a40e23b
      Zheng Yan authored
      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: default avatarChris Mason <chris.mason@oracle.com>
    • Zheng Yan's avatar
      Btrfs: extent_map and data=ordered fixes for space balancing · 5b21f2ed
      Zheng Yan authored
      * Add an EXTENT_BOUNDARY state bit to keep the writepage code
      from merging data extents that are in the process of being
      relocated.  This allows us to do accounting for them properly.
      * The balancing code relocates data extents indepdent of the underlying
      inode.  The extent_map code was modified to properly account for
      things moving around (invalidating extent_map caches in the inode).
      * Don't take the drop_mutex in the create_subvol ioctl.  It isn't
      * Fix walking of the ordered extent list to avoid races with sys_unlink
      * Change the lock ordering rules.  Transaction start goes outside
      the drop_mutex.  This allows btrfs_commit_transaction to directly
      drop the relocation trees.
      Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
    • Zheng Yan's avatar
      Btrfs: Add shared reference cache · e4657689
      Zheng Yan authored
      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
      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: default avatarChris Mason <chris.mason@oracle.com>
    • Zheng Yan's avatar
      Btrfs: allocator fixes for space balancing update · e8569813
      Zheng Yan authored
      * Reserved extent accounting:  reserved extents have been
      allocated in the rbtrees that track free space but have not
      been allocated on disk.  They were never properly accounted for
      in the past, making it hard to know how much space was really free.
      * btrfs_find_block_group used to return NULL for block groups that
      had been removed by the space balancing code.  This made it hard
      to account for space during the final stages of a balance run.
      Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
  6. 25 Sep, 2008 29 commits
    • Chris Mason's avatar
      Remove Btrfs compat code for older kernels · 2b1f55b0
      Chris Mason authored
      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: default avatarChris Mason <chris.mason@oracle.com>
    • Zheng Yan's avatar
      Btrfs: Full back reference support · 31840ae1
      Zheng Yan authored
      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: default avatarChris Mason <chris.mason@oracle.com>
    • Josef Bacik's avatar
      Btrfs: free space accounting redo · 0f9dd46c
      Josef Bacik authored
      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: default avatarChris Mason <chris.mason@oracle.com>
    • Chris Mason's avatar
      Btrfs: Record dirty pages tree-log pages in an extent_io tree · d0c803c4
      Chris Mason authored
      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: default avatarChris Mason <chris.mason@oracle.com>
    • Zheng Yan's avatar
      Btrfs: Update find free objectid function for orphan cleanup code · 6527cdbe
      Zheng Yan authored
      Orphan items use BTRFS_ORPHAN_OBJECTID (-5UUL) as key objectid. This
      affects the find free objectid functions, inode objectid can easily
      overflow after orphan file cleanup.
      Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
    • Christoph Hellwig's avatar
      remove unused function btrfs_ilookup · a237d2a2
      Christoph Hellwig authored
      btrfs_ilookup is unused, which is good because a normal filesystem
      should never have to use ilookup anyway.  Remove it.
      Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
      Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
    • Chris Mason's avatar
      Btrfs: Rev the disk format · 91c0827d
      Chris Mason authored
      Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
    • Chris Mason's avatar
      Btrfs: Add a write ahead tree log to optimize synchronous operations · e02119d5
      Chris Mason authored
      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: default avatarChris Mason <chris.mason@oracle.com>
    • Chris Mason's avatar
      Btrfs: Rev the disk format · f3f9931e
      Chris Mason authored
      Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
    • Balaji Rao's avatar
      Introduce btrfs_iget helper · 1a54ef8c
      Balaji Rao authored
      Date: Mon, 21 Jul 2008 02:01:04 +0530
      This patch introduces a btrfs_iget helper to be used in NFS support.
      Signed-off-by: default avatarBalaji Rao <balajirrao@gmail.com>
      Signed-off-by: default avatarDavid Woodhouse <David.Woodhouse@intel.com>
      Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
    • Chris Mason's avatar
      Btrfs: Wait for kernel threads to make progress during async submission · 4854ddd0
      Chris Mason authored
      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: default avatarChris Mason <chris.mason@oracle.com>
    • Chris Mason's avatar
    • Eric Sandeen's avatar
      Btrfs: fix RHEL test for ClearPageFsMisc · 5036f538
      Eric Sandeen authored
      Newer RHEL5 kernels define both ClearPageFSMisc and
      ClearPageChecked, so test for both before redefining.
      Signed-off-by: default avatarEric Sandeen <sandeen@redhat.com>
      Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
    • Yan Zheng's avatar
    • Chris Mason's avatar
    • Sage Weil's avatar
      Btrfs: fix ioctl-initiated transactions vs wait_current_trans() · 9ca9ee09
      Sage Weil authored
      Commit 597:466b27332893 (btrfs_start_transaction: wait for commits in
      progress) breaks the transaction start/stop ioctls by making
      btrfs_start_transaction conditionally wait for the next transaction to
      start.  If an application artificially is holding a transaction open,
      things deadlock.
      This workaround maintains a count of open ioctl-initiated transactions in
      fs_info, and avoids wait_current_trans() if any are currently open (in
      start_transaction() and btrfs_throttle()).  The start transaction ioctl
      uses a new btrfs_start_ioctl_transaction() that _does_ call
      wait_current_trans(), effectively pushing the join/wait decision to the
      outer ioctl-initiated transaction.
      This more or less neuters btrfs_throttle() when ioctl-initiated
      transactions are in use, but that seems like a pretty fundamental
      consequence of wrapping lots of write()'s in a transaction.  Btrfs has no
      way to tell if the application considers a given operation as part of it's
      Obviously, if the transaction start/stop ioctls aren't being used, there
      is no effect on current behavior.
      Signed-off-by: default avatarSage Weil <sage@newdream.net>
       ctree.h       |    1 +
       ioctl.c       |   12 +++++++++++-
       transaction.c |   18 +++++++++++++-----
       transaction.h |    2 ++
       4 files changed, 27 insertions(+), 6 deletions(-)
      Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
    • Chris Mason's avatar
      btrfs_search_slot: reduce lock contention by cowing in two stages · 65b51a00
      Chris Mason authored
      A btree block cow has two parts, the first is to allocate a destination
      block and the second is to copy the old bock over.
      The first part needs locks in the extent allocation tree, and may need to
      do IO.  This changeset splits that into a separate function that can be
      called without any tree locks held.
      btrfs_search_slot is changed to drop its path and start over if it has
      to COW a contended block.  This often means that many writers will
      pre-alloc a new destination for a the same contended block, but they
      cache their prealloc for later use on lower levels in the tree.
      Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
    • Chris Mason's avatar
      Btrfs: Fix streaming read performance with checksumming on · 61b49440
      Chris Mason authored
      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: default avatarChris Mason <chris.mason@oracle.com>
    • Yan's avatar
      Btrfs: implement memory reclaim for leaf reference cache · bcc63abb
      Yan authored
      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: default avatarChris Mason <chris.mason@oracle.com>
    • Yan Zheng's avatar
      Btrfs: Update and fix mount -o nodatacow · f321e491
      Yan Zheng authored
      To check whether a given file extent is referenced by multiple snapshots, the
      checker walks down the fs tree through dead root and checks all tree blocks in
      the path.
      We can easily detect whether a given tree block is directly referenced by other
      snapshot. We can also detect any indirect reference from other snapshot by
      checking reference's generation. The checker can always detect multiple
      references, but can't reliably detect cases of single reference. So btrfs may
      do file data cow even there is only one reference.
      Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
    • Chris Mason's avatar
      Btrfs: Throttle operations if the reference cache gets too large · ab78c84d
      Chris Mason authored
      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
      Overall, this actually makes the FS faster because the cleaner thread will
      be more likely to find things in cache.
      Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
    • Chris Mason's avatar
      Btrfs: Leaf reference cache update · 017e5369
      Chris Mason authored
      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: default avatarChris Mason <chris.mason@oracle.com>
    • Yan Zheng's avatar
      Btrfs: Add a leaf reference cache · 31153d81
      Yan Zheng authored
      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: default avatarChris Mason <chris.mason@oracle.com>
    • Chris Mason's avatar
      Btrfs: Rev the disk format magic · 3a115f52
      Chris Mason authored
      Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
    • Josef Bacik's avatar
    • Josef Bacik's avatar
      Btrfs: Add ACL support · 33268eaf
      Josef Bacik authored
      Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
    • Josef Bacik's avatar
      Btrfs: Remove unused xattr code · 6099afe8
      Josef Bacik authored
      Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
    • Josef Bacik's avatar
      Btrfs: Implement new dir index format · aec7477b
      Josef Bacik authored
      Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
    • Chris Mason's avatar
      Btrfs: Fix the defragmention code and the block relocation code for data=ordered · 3eaa2885
      Chris Mason authored
      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: default avatarChris Mason <chris.mason@oracle.com>