1. 09 Oct, 2008 6 commits
  2. 03 Oct, 2008 3 commits
  3. 01 Oct, 2008 4 commits
    • 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>
      323ac95b
    • Josef Bacik's avatar
      Btrfs: fix deadlock between alloc_mutex/chunk_mutex · cf749823
      Josef Bacik authored
      This fixes a deadlock that happens between the alloc_mutex and chunk_mutex.
      Process A comes in, decides to do a do_chunk_alloc, which takes the
      chunk_mutex, and is holding the alloc_mutex because the only way you get to
      do_chunk_alloc is by holding the alloc_mutex.  btrfs_alloc_chunk does its thing
      and goes to insert a new item, which results in a cow of the block.
      
      We get into del_pending_extents from there, where if we need to be rescheduled
      we drop the alloc_mutex and schedule.  At this point process B comes in to do
      an allocation and gets the alloc_mutex, and because process A did not do the
      chunk allocation completely it thinks its a good time to do a chunk allocation
      as well, and hangs on the chunk_mutex.
      
      Process A wakes up and tries to take the alloc_mutex and cannot.  The way to
      fix this is do a mutex_trylock() on chunk_mutex.  If we return 0 we didn't get
      the lock, and if this is just a "hey it may be a good time to allocate a chunk"
      then we just exit.  If we are trying to force an allocation then we reschedule
      and keep trying to acquire the chunk_mutex.  If once we acquire it the space is
      already full then we can just exit, otherwise we can continue with the chunk
      allocation.  Thank you,
      Signed-off-by: default avatarJosef Bacik <jbacik@redhat.com>
      cf749823
    • Jim Meyering's avatar
    • Jim Meyering's avatar
  4. 30 Sep, 2008 2 commits
    • Chris Mason's avatar
      Btrfs: fix multi-device code to use raid policies set by mkfs · 75ccf47d
      Chris Mason authored
      When reading in block groups, a global mask of the available raid policies
      should be adjusted based on the types of block groups found on disk.  This
      global mask is then used to decide which raid policy to use for new
      block groups.
      
      The recent allocator changes dropped the call that updated the global
      mask, making all the block groups allocated at run time single striped
      onto a single drive.
      
      This also fixes the async worker threads to set any thread that uses
      the requeue mechanism as busy.  This allows us to avoid blocking
      on get_request_wait for the async bio submission threads.
      Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
      75ccf47d
    • Josef Bacik's avatar
      Btrfs: fix seekiness due to finding the wrong block group · 45b8c9a8
      Josef Bacik authored
      This patch fixes a problem where we end up seeking too much when *last_ptr is
      valid.  This happens because btrfs_lookup_first_block_group only returns a
      block group that starts on or after the given search start, so if the
      search_start is in the middle of a block group it will return the block group
      after the given search_start, which is suboptimal.
      
      This patch fixes that by doing a btrfs_lookup_block_group, which will return
      the block group that contains the given search start.  If we fail to find a
      block group, we fall back on btrfs_lookup_first_block_group so we can find the
      next block group, not sure if this is absolutely needed, but better safe than
      sorry.
      
      Also if we can't find the block group that we need, or it happens to not be of
      the right type, we need to add empty_cluster since *last_ptr could point to a
      mismatched block group, which means we need to start over with empty_cluster
      added to total needed.  Thank you,
      Signed-off-by: default avatarJosef Bacik <jbacik@redhat.com>
      Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
      45b8c9a8
  5. 29 Sep, 2008 3 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>
      d352ac68
    • Chris Mason's avatar
      Btrfs: drop WARN_ON from btrfs_add_leaf_ref · 9a5e1ea1
      Chris Mason authored
      btrfs_add_leaf_ref was doing checks on the objects it found in the
      rbtree to make sure they were properly linked into the tree.  But, the field
      it was checking can be safely changed outside of the tree spin lock.
      
      The WARN_ON was for debugging the initial implementation and can be
      safely removed.
      Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
      9a5e1ea1
    • 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>
      8c8bee1d
  6. 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>
      1a40e23b
    • 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
      required.
      
      * 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>
      5b21f2ed
    • 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
      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: default avatarChris Mason <chris.mason@oracle.com>
      e4657689
    • 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>
      e8569813
  7. 25 Sep, 2008 18 commits
    • Chris Mason's avatar
      Btrfs: Raise thresholds for metadata writeback · 24ab9cd8
      Chris Mason authored
      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: default avatarChris Mason <chris.mason@oracle.com>
      24ab9cd8
    • Chris Mason's avatar
      Btrfs: fix sleep with spinlock held during unmount · 4434c33c
      Chris Mason authored
      The code to free block groups needs to drop the space info spin lock
      before calling btrfs_remove_free_space_cache (which can schedule).
      
      This is safe because at unmount time, nobody else is going to play
      with the block groups.
      Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
      4434c33c
    • 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>
      2b1f55b0
    • Chris Mason's avatar
      Btrfs: Fix allocation completions in tree log replay · 9b49c9b9
      Chris Mason authored
      After a crash, the tree log code uses btrfs_alloc_logged_extent to
      record allocations of data extents that it finds in the log tree.  These
      come in basically random order, which does not fit how
      btrfs_remove_free_space() expects to be called.
      
      btrfs_remove_free_space was changed to support recording an extent
      allocation in the middle of a region of free space.
      Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
      9b49c9b9
    • Chris Mason's avatar
      Add Btrfs to fs/Kconfig and fs/Makefile · 60582d1e
      Chris Mason authored
      Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
      60582d1e
    • Chris Mason's avatar
      Update Btrfs files for in-kernel usage · b4f6c45d
      Chris Mason authored
      btrfs had magic to put the chagneset id into a printk on module load.
      This removes that from the Makefile and hardcodes the printk to print
      "Btrfs"
      Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
      b4f6c45d
    • Chris Mason's avatar
      Merge Btrfs into fs/btrfs · aef87557
      Chris Mason authored
      aef87557
    • Chris Mason's avatar
      Btrfs: Fix race against disk_i_size updates · 34353029
      Chris Mason authored
      The code to update the on disk i_size happens before the
      ordered_extent record is removed.  So, it is possible for multiple
      ordered_extent completion routines to run at the same time, and to
      find each other in the ordered tree.
      
      The end result is they both decide not to update disk_i_size, leaving
      it too small.  This temporary fix just puts the updates inside
      the extent_mutex.  A real solution would be stronger ordering of
      disk_i_size updates against removing the ordered extent from the tree.
      Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
      34353029
    • 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>
      31840ae1
    • Chris Mason's avatar
      Add check for tree-log roots in btrfs_alloc_reserved_extents · 1c2308f8
      Chris Mason authored
      Tree log blocks are only reserved, and should not ever get fully
      allocated on disk.  This check makes sure they stay out of the
      extent tree.
      Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
      1c2308f8
    • Chris Mason's avatar
      Btrfs: Checksum tree blocks in the background · ce3ed71a
      Chris Mason authored
      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: default avatarChris Mason <chris.mason@oracle.com>
      ce3ed71a
    • 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>
      0f9dd46c
    • Josef Bacik's avatar
      Btrfs: fix cache_block_group error handling · ef8bbdfe
      Josef Bacik authored
      cache block group had a few bugs in the error handling code,
      this makes sure paths get properly released and the correct return value
      goes out.
      Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
      ef8bbdfe
    • Chris Mason's avatar
      Fix leaf overflow check in btrfs_insert_empty_items · f25956cc
      Chris Mason authored
      It was incorrectly adding an extra sizeof(struct btrfs_item) and causing
      false positives (oops)
      Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
      f25956cc
    • Chris Mason's avatar
      Btrfs: Fix mismerge in block header checks · 23a07867
      Chris Mason authored
      I had incorrectly disabled the check for the block number being correct
      in the header block.
      Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
      23a07867
    • Chris Mason's avatar
      Btrfs: Disable the dir fsync optimization to skip logging the dir sometimes · 9623f9a3
      Chris Mason authored
      More testing has turned up a bug, disable this for now.
      Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
      9623f9a3
    • 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>
      d0c803c4
    • Chris Mason's avatar
      Btrfs: Copy into the log tree in big batches · 31ff1cd2
      Chris Mason authored
      This changes the log tree copy code to use btrfs_insert_items and
      to work in larger batches where possible.
      Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
      31ff1cd2