27 Jul, 2011

1 commit

  • This allows us to move duplicated code in
    (atomic_inc_not_zero() for now) to

    Signed-off-by: Arun Sharma
    Reviewed-by: Eric Dumazet
    Cc: Ingo Molnar
    Cc: David Miller
    Cc: Eric Dumazet
    Acked-by: Mike Frysinger
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Arun Sharma
     

27 Jun, 2011

1 commit

  • When iputting the inode, We may leave the delayed nodes if they have some
    delayed items that have not been dealt with. So when the inode is read again,
    we must look up the relative delayed node, and use the information in it to
    initialize the inode. Or we will get inconsonant inode information, it may
    cause that the same directory index number is allocated again, and hit the
    following oops:

    [ 5447.554187] err add delayed dir index item(name: pglog_0.965_0) into the
    insertion tree of the delayed node(root id: 262, inode id: 258, errno: -17)
    [ 5447.569766] ------------[ cut here ]------------
    [ 5447.575361] kernel BUG at fs/btrfs/delayed-inode.c:1301!
    [SNIP]
    [ 5447.790721] Call Trace:
    [ 5447.793191] [] btrfs_insert_dir_item+0x189/0x1bb [btrfs]
    [ 5447.800156] [] btrfs_add_link+0x12b/0x191 [btrfs]
    [ 5447.806517] [] btrfs_add_nondir+0x31/0x58 [btrfs]
    [ 5447.812876] [] btrfs_create+0xf9/0x197 [btrfs]
    [ 5447.818961] [] vfs_create+0x72/0x92
    [ 5447.824090] [] do_last+0x22c/0x40b
    [ 5447.829133] [] path_openat+0xc0/0x2ef
    [ 5447.834438] [] ? __perf_event_task_sched_out+0x24/0x44
    [ 5447.841216] [] ? perf_event_task_sched_out+0x59/0x67
    [ 5447.847846] [] do_filp_open+0x3d/0x87
    [ 5447.853156] [] ? strncpy_from_user+0x43/0x4d
    [ 5447.859072] [] ? getname_flags+0x2e/0x80
    [ 5447.864636] [] ? do_getname+0x14b/0x173
    [ 5447.870112] [] ? audit_getname+0x16/0x26
    [ 5447.875682] [] ? spin_lock+0xe/0x10
    [ 5447.880882] [] do_sys_open+0x69/0xae
    [ 5447.886153] [] sys_open+0x20/0x22
    [ 5447.891114] [] system_call_fastpath+0x16/0x1b

    Fix it by reusing the old delayed node.

    Reported-by: Jim Schutt
    Signed-off-by: Miao Xie
    Tested-by: Jim Schutt
    Signed-off-by: Chris Mason

    Miao Xie
     

18 Jun, 2011

2 commits

  • Snapshot creation has two phases. One is the initial snapshot setup,
    and the second is done during commit, while nobody is allowed to modify
    the root we are snapshotting.

    The delayed metadata insertion code can break that rule, it does a
    delayed inode update on the inode of the parent of the snapshot,
    and delayed directory item insertion.

    This makes sure to run the pending delayed operations before we
    record the snapshot root, which avoids corruptions.

    Signed-off-by: Chris Mason

    Chris Mason
     
  • We have migrated the space for the delayed inode items from
    trans_block_rsv to global_block_rsv, but we forgot to set trans->block_rsv to
    global_block_rsv when we doing delayed inode operations, and the following Oops
    happened:

    [ 9792.654889] ------------[ cut here ]------------
    [ 9792.654898] WARNING: at fs/btrfs/extent-tree.c:5681
    btrfs_alloc_free_block+0xca/0x27c [btrfs]()
    [ 9792.654899] Hardware name: To Be Filled By O.E.M.
    [ 9792.654900] Modules linked in: btrfs zlib_deflate libcrc32c
    ip6t_REJECT nf_conntrack_ipv6 nf_defrag_ipv6 ip6table_filter ip6_tables
    arc4 rt61pci rt2x00pci rt2x00lib snd_hda_codec_hdmi mac80211
    snd_hda_codec_realtek cfg80211 snd_hda_intel edac_core snd_seq rfkill
    pcspkr serio_raw snd_hda_codec eeprom_93cx6 edac_mce_amd sp5100_tco
    i2c_piix4 k10temp snd_hwdep snd_seq_device snd_pcm floppy r8169 xhci_hcd
    mii snd_timer snd soundcore snd_page_alloc ipv6 firewire_ohci pata_acpi
    ata_generic firewire_core pata_via crc_itu_t radeon ttm drm_kms_helper
    drm i2c_algo_bit i2c_core [last unloaded: scsi_wait_scan]
    [ 9792.654919] Pid: 2762, comm: rm Tainted: G W 2.6.39+ #1
    [ 9792.654920] Call Trace:
    [ 9792.654922] [] warn_slowpath_common+0x83/0x9b
    [ 9792.654925] [] warn_slowpath_null+0x1a/0x1c
    [ 9792.654933] [] btrfs_alloc_free_block+0xca/0x27c [btrfs]
    [ 9792.654945] [] ? map_extent_buffer+0x6e/0xa8 [btrfs]
    [ 9792.654953] [] __btrfs_cow_block+0xfc/0x30c [btrfs]
    [ 9792.654963] [] ? btrfs_buffer_uptodate+0x47/0x58 [btrfs]
    [ 9792.654970] [] ? read_block_for_search+0x94/0x368 [btrfs]
    [ 9792.654978] [] btrfs_cow_block+0xfe/0x146 [btrfs]
    [ 9792.654986] [] btrfs_search_slot+0x14d/0x4b6 [btrfs]
    [ 9792.654997] [] ? map_extent_buffer+0x6e/0xa8 [btrfs]
    [ 9792.655022] [] btrfs_lookup_inode+0x2f/0x8f [btrfs]
    [ 9792.655025] [] ? _cond_resched+0xe/0x22
    [ 9792.655027] [] ? mutex_lock+0x29/0x50
    [ 9792.655039] [] btrfs_update_delayed_inode+0x72/0x137 [btrfs]
    [ 9792.655051] [] btrfs_run_delayed_items+0x90/0xdb [btrfs]
    [ 9792.655062] [] btrfs_commit_transaction+0x228/0x654 [btrfs]
    [ 9792.655064] [] ? remove_wait_queue+0x3a/0x3a
    [ 9792.655075] [] btrfs_evict_inode+0x14d/0x202 [btrfs]
    [ 9792.655077] [] evict+0x71/0x111
    [ 9792.655079] [] iput+0x12a/0x132
    [ 9792.655081] [] do_unlinkat+0x106/0x155
    [ 9792.655083] [] ? path_put+0x1f/0x23
    [ 9792.655085] [] ? audit_syscall_entry+0x145/0x171
    [ 9792.655087] [] ? putname+0x34/0x36
    [ 9792.655090] [] sys_unlinkat+0x29/0x2b
    [ 9792.655092] [] system_call_fastpath+0x16/0x1b
    [ 9792.655093] ---[ end trace 02b696eb02b3f768 ]---

    This patch fix it by setting the reservation of the transaction handle to the
    correct one.

    Reported-by: Josef Bacik
    Signed-off-by: Miao Xie
    Signed-off-by: Chris Mason

    Miao Xie
     

21 May, 2011

1 commit

  • Changelog V5 -> V6:
    - Fix oom when the memory load is high, by storing the delayed nodes into the
    root's radix tree, and letting btrfs inodes go.

    Changelog V4 -> V5:
    - Fix the race on adding the delayed node to the inode, which is spotted by
    Chris Mason.
    - Merge Chris Mason's incremental patch into this patch.
    - Fix deadlock between readdir() and memory fault, which is reported by
    Itaru Kitayama.

    Changelog V3 -> V4:
    - Fix nested lock, which is reported by Itaru Kitayama, by updating space cache
    inode in time.

    Changelog V2 -> V3:
    - Fix the race between the delayed worker and the task which does delayed items
    balance, which is reported by Tsutomu Itoh.
    - Modify the patch address David Sterba's comment.
    - Fix the bug of the cpu recursion spinlock, reported by Chris Mason

    Changelog V1 -> V2:
    - break up the global rb-tree, use a list to manage the delayed nodes,
    which is created for every directory and file, and used to manage the
    delayed directory name index items and the delayed inode item.
    - introduce a worker to deal with the delayed nodes.

    Compare with Ext3/4, the performance of file creation and deletion on btrfs
    is very poor. the reason is that btrfs must do a lot of b+ tree insertions,
    such as inode item, directory name item, directory name index and so on.

    If we can do some delayed b+ tree insertion or deletion, we can improve the
    performance, so we made this patch which implemented delayed directory name
    index insertion/deletion and delayed inode update.

    Implementation:
    - introduce a delayed root object into the filesystem, that use two lists to
    manage the delayed nodes which are created for every file/directory.
    One is used to manage all the delayed nodes that have delayed items. And the
    other is used to manage the delayed nodes which is waiting to be dealt with
    by the work thread.
    - Every delayed node has two rb-tree, one is used to manage the directory name
    index which is going to be inserted into b+ tree, and the other is used to
    manage the directory name index which is going to be deleted from b+ tree.
    - introduce a worker to deal with the delayed operation. This worker is used
    to deal with the works of the delayed directory name index items insertion
    and deletion and the delayed inode update.
    When the delayed items is beyond the lower limit, we create works for some
    delayed nodes and insert them into the work queue of the worker, and then
    go back.
    When the delayed items is beyond the upper bound, we create works for all
    the delayed nodes that haven't been dealt with, and insert them into the work
    queue of the worker, and then wait for that the untreated items is below some
    threshold value.
    - When we want to insert a directory name index into b+ tree, we just add the
    information into the delayed inserting rb-tree.
    And then we check the number of the delayed items and do delayed items
    balance. (The balance policy is above.)
    - When we want to delete a directory name index from the b+ tree, we search it
    in the inserting rb-tree at first. If we look it up, just drop it. If not,
    add the key of it into the delayed deleting rb-tree.
    Similar to the delayed inserting rb-tree, we also check the number of the
    delayed items and do delayed items balance.
    (The same to inserting manipulation)
    - When we want to update the metadata of some inode, we cached the data of the
    inode into the delayed node. the worker will flush it into the b+ tree after
    dealing with the delayed insertion and deletion.
    - We will move the delayed node to the tail of the list after we access the
    delayed node, By this way, we can cache more delayed items and merge more
    inode updates.
    - If we want to commit transaction, we will deal with all the delayed node.
    - the delayed node will be freed when we free the btrfs inode.
    - Before we log the inode items, we commit all the directory name index items
    and the delayed inode update.

    I did a quick test by the benchmark tool[1] and found we can improve the
    performance of file creation by ~15%, and file deletion by ~20%.

    Before applying this patch:
    Create files:
    Total files: 50000
    Total time: 1.096108
    Average time: 0.000022
    Delete files:
    Total files: 50000
    Total time: 1.510403
    Average time: 0.000030

    After applying this patch:
    Create files:
    Total files: 50000
    Total time: 0.932899
    Average time: 0.000019
    Delete files:
    Total files: 50000
    Total time: 1.215732
    Average time: 0.000024

    [1] http://marc.info/?l=linux-btrfs&m=128212635122920&q=p3

    Many thanks for Kitayama-san's help!

    Signed-off-by: Miao Xie
    Reviewed-by: David Sterba
    Tested-by: Tsutomu Itoh
    Tested-by: Itaru Kitayama
    Signed-off-by: Chris Mason

    Miao Xie