<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel.git/fs/btrfs/delayed-ref.h, branch linux-4.2.y</title>
<subtitle>Hosts the 0x221E linux distro kernel.
</subtitle>
<id>https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-4.2.y</id>
<link rel='self' href='https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-4.2.y'/>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/'/>
<updated>2015-12-15T05:25:44Z</updated>
<entry>
<title>Btrfs: fix regression running delayed references when using qgroups</title>
<updated>2015-12-15T05:25:44Z</updated>
<author>
<name>Filipe Manana</name>
</author>
<published>2015-10-23T06:52:54Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=dacd97b8c00cfae5f7f743846d4025bbd246ac5e'/>
<id>urn:sha1:dacd97b8c00cfae5f7f743846d4025bbd246ac5e</id>
<content type='text'>
commit b06c4bf5c874a57254b197f53ddf588e7a24a2bf upstream.

In the kernel 4.2 merge window we had a big changes to the implementation
of delayed references and qgroups which made the no_quota field of delayed
references not used anymore. More specifically the no_quota field is not
used anymore as of:

  commit 0ed4792af0e8 ("btrfs: qgroup: Switch to new extent-oriented qgroup mechanism.")

Leaving the no_quota field actually prevents delayed references from
getting merged, which in turn cause the following BUG_ON(), at
fs/btrfs/extent-tree.c, to be hit when qgroups are enabled:

  static int run_delayed_tree_ref(...)
  {
     (...)
     BUG_ON(node-&gt;ref_mod != 1);
     (...)
  }

This happens on a scenario like the following:

  1) Ref1 bytenr X, action = BTRFS_ADD_DELAYED_REF, no_quota = 1, added.

  2) Ref2 bytenr X, action = BTRFS_DROP_DELAYED_REF, no_quota = 0, added.
     It's not merged with Ref1 because Ref1-&gt;no_quota != Ref2-&gt;no_quota.

  3) Ref3 bytenr X, action = BTRFS_ADD_DELAYED_REF, no_quota = 1, added.
     It's not merged with the reference at the tail of the list of refs
     for bytenr X because the reference at the tail, Ref2 is incompatible
     due to Ref2-&gt;no_quota != Ref3-&gt;no_quota.

  4) Ref4 bytenr X, action = BTRFS_DROP_DELAYED_REF, no_quota = 0, added.
     It's not merged with the reference at the tail of the list of refs
     for bytenr X because the reference at the tail, Ref3 is incompatible
     due to Ref3-&gt;no_quota != Ref4-&gt;no_quota.

  5) We run delayed references, trigger merging of delayed references,
     through __btrfs_run_delayed_refs() -&gt; btrfs_merge_delayed_refs().

  6) Ref1 and Ref3 are merged as Ref1-&gt;no_quota = Ref3-&gt;no_quota and
     all other conditions are satisfied too. So Ref1 gets a ref_mod
     value of 2.

  7) Ref2 and Ref4 are merged as Ref2-&gt;no_quota = Ref4-&gt;no_quota and
     all other conditions are satisfied too. So Ref2 gets a ref_mod
     value of 2.

  8) Ref1 and Ref2 aren't merged, because they have different values
     for their no_quota field.

  9) Delayed reference Ref1 is picked for running (select_delayed_ref()
     always prefers references with an action == BTRFS_ADD_DELAYED_REF).
     So run_delayed_tree_ref() is called for Ref1 which triggers the
     BUG_ON because Ref1-&gt;red_mod != 1 (equals 2).

So fix this by removing the no_quota field, as it's not used anymore as
of commit 0ed4792af0e8 ("btrfs: qgroup: Switch to new extent-oriented
qgroup mechanism.").

The use of no_quota was also buggy in at least two places:

1) At delayed-refs.c:btrfs_add_delayed_tree_ref() - we were setting
   no_quota to 0 instead of 1 when the following condition was true:
   is_fstree(ref_root) || !fs_info-&gt;quota_enabled

2) At extent-tree.c:__btrfs_inc_extent_ref() - we were attempting to
   reset a node's no_quota when the condition "!is_fstree(root_objectid)
   || !root-&gt;fs_info-&gt;quota_enabled" was true but we did it only in
   an unused local stack variable, that is, we never reset the no_quota
   value in the node itself.

This fixes the remainder of problems several people have been having when
running delayed references, mostly while a balance is running in parallel,
on a 4.2+ kernel.

Very special thanks to Stéphane Lesimple for helping debugging this issue
and testing this fix on his multi terabyte filesystem (which took more
than one day to balance alone, plus fsck, etc).

Also, this fixes deadlock issue when using the clone ioctl with qgroups
enabled, as reported by Elias Probst in the mailing list. The deadlock
happens because after calling btrfs_insert_empty_item we have our path
holding a write lock on a leaf of the fs/subvol tree and then before
releasing the path we called check_ref() which did backref walking, when
qgroups are enabled, and tried to read lock the same leaf. The trace for
this case is the following:

  INFO: task systemd-nspawn:6095 blocked for more than 120 seconds.
  (...)
  Call Trace:
    [&lt;ffffffff86999201&gt;] schedule+0x74/0x83
    [&lt;ffffffff863ef64c&gt;] btrfs_tree_read_lock+0xc0/0xea
    [&lt;ffffffff86137ed7&gt;] ? wait_woken+0x74/0x74
    [&lt;ffffffff8639f0a7&gt;] btrfs_search_old_slot+0x51a/0x810
    [&lt;ffffffff863a129b&gt;] btrfs_next_old_leaf+0xdf/0x3ce
    [&lt;ffffffff86413a00&gt;] ? ulist_add_merge+0x1b/0x127
    [&lt;ffffffff86411688&gt;] __resolve_indirect_refs+0x62a/0x667
    [&lt;ffffffff863ef546&gt;] ? btrfs_clear_lock_blocking_rw+0x78/0xbe
    [&lt;ffffffff864122d3&gt;] find_parent_nodes+0xaf3/0xfc6
    [&lt;ffffffff86412838&gt;] __btrfs_find_all_roots+0x92/0xf0
    [&lt;ffffffff864128f2&gt;] btrfs_find_all_roots+0x45/0x65
    [&lt;ffffffff8639a75b&gt;] ? btrfs_get_tree_mod_seq+0x2b/0x88
    [&lt;ffffffff863e852e&gt;] check_ref+0x64/0xc4
    [&lt;ffffffff863e9e01&gt;] btrfs_clone+0x66e/0xb5d
    [&lt;ffffffff863ea77f&gt;] btrfs_ioctl_clone+0x48f/0x5bb
    [&lt;ffffffff86048a68&gt;] ? native_sched_clock+0x28/0x77
    [&lt;ffffffff863ed9b0&gt;] btrfs_ioctl+0xabc/0x25cb
  (...)

The problem goes away by eleminating check_ref(), which no longer is
needed as its purpose was to get a value for the no_quota field of
a delayed reference (this patch removes the no_quota field as mentioned
earlier).

Reported-by: Stéphane Lesimple &lt;stephane_btrfs@lesimple.fr&gt;
Tested-by: Stéphane Lesimple &lt;stephane_btrfs@lesimple.fr&gt;
Reported-by: Elias Probst &lt;mail@eliasprobst.eu&gt;
Reported-by: Peter Becker &lt;floyd.net@gmail.com&gt;
Reported-by: Malte Schröder &lt;malte@tnxip.de&gt;
Reported-by: Derek Dongray &lt;derek@valedon.co.uk&gt;
Reported-by: Erkki Seppala &lt;flux-btrfs@inside.org&gt;
Cc: stable@vger.kernel.org  # 4.2+
Signed-off-by: Filipe Manana &lt;fdmanana@suse.com&gt;
Reviewed-by: Qu Wenruo &lt;quwenruo@cn.fujitsu.com&gt;
</content>
</entry>
<entry>
<title>btrfs: qgroup: Add the ability to skip given qgroup for old/new_roots.</title>
<updated>2015-06-10T16:26:23Z</updated>
<author>
<name>Qu Wenruo</name>
</author>
<published>2015-04-20T01:53:50Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=9086db86e0b09c39abead4d747119695553e3978'/>
<id>urn:sha1:9086db86e0b09c39abead4d747119695553e3978</id>
<content type='text'>
This is used by later qgroup fix patches for snapshot.

As current snapshot accounting is done by btrfs_qgroup_inherit(), but
new extent oriented quota mechanism will account extent from
btrfs_copy_root() and other snapshot things, causing wrong result.

So add this ability to handle snapshot accounting.

Signed-off-by: Qu Wenruo &lt;quwenruo@cn.fujitsu.com&gt;
Signed-off-by: Chris Mason &lt;clm@fb.com&gt;
</content>
</entry>
<entry>
<title>btrfs: qgroup: Record possible quota-related extent for qgroup.</title>
<updated>2015-06-10T16:25:32Z</updated>
<author>
<name>Qu Wenruo</name>
</author>
<published>2015-04-16T06:34:17Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=3368d001ba5df44930d986e82b1b497d4da285ba'/>
<id>urn:sha1:3368d001ba5df44930d986e82b1b497d4da285ba</id>
<content type='text'>
Add hook in add_delayed_ref_head() to record quota-related extent record
into delayed_ref_root-&gt;dirty_extent_record rb-tree for later qgroup
accounting.

Signed-off-by: Qu Wenruo &lt;quwenruo@cn.fujitsu.com&gt;
Signed-off-by: Chris Mason &lt;clm@fb.com&gt;
</content>
</entry>
<entry>
<title>btrfs: delayed-ref: Use list to replace the ref_root in ref_head.</title>
<updated>2015-06-10T16:25:03Z</updated>
<author>
<name>Qu Wenruo</name>
</author>
<published>2015-03-30T09:03:00Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=c6fc24549960f26910cd0c6e4b5f48f2f306b11d'/>
<id>urn:sha1:c6fc24549960f26910cd0c6e4b5f48f2f306b11d</id>
<content type='text'>
This patch replace the rbtree used in ref_head to list.
This has the following advantage:
1) Easier merge logic.
With the new list implement, we only need to care merging the tail
ref_node with the new ref_node.
And this can be done quite easy at insert time, no need to do a
indicated merge at run_delayed_refs().

Signed-off-by: Qu Wenruo &lt;quwenruo@cn.fujitsu.com&gt;
Signed-off-by: Chris Mason &lt;clm@fb.com&gt;
</content>
</entry>
<entry>
<title>Btrfs: account for crcs in delayed ref processing</title>
<updated>2015-04-10T21:04:47Z</updated>
<author>
<name>Josef Bacik</name>
</author>
<published>2015-02-03T15:50:16Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=1262133b8d6f10f5ca7621cd4cf65ddf6254126a'/>
<id>urn:sha1:1262133b8d6f10f5ca7621cd4cf65ddf6254126a</id>
<content type='text'>
As we delete large extents, we end up doing huge amounts of COW in order
to delete the corresponding crcs.  This adds accounting so that we keep
track of that space and flushing of delayed refs so that we don't build
up too much delayed crc work.

This helps limit the delayed work that must be done at commit time and
tries to avoid ENOSPC aborts because the crcs eat all the global
reserves.

Signed-off-by: Chris Mason &lt;clm@fb.com&gt;
</content>
</entry>
<entry>
<title>Btrfs: rework qgroup accounting</title>
<updated>2014-06-10T00:20:48Z</updated>
<author>
<name>Josef Bacik</name>
</author>
<published>2014-05-14T00:30:47Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=fcebe4562dec83b3f8d3088d77584727b09130b2'/>
<id>urn:sha1:fcebe4562dec83b3f8d3088d77584727b09130b2</id>
<content type='text'>
Currently qgroups account for space by intercepting delayed ref updates to fs
trees.  It does this by adding sequence numbers to delayed ref updates so that
it can figure out how the tree looked before the update so we can adjust the
counters properly.  The problem with this is that it does not allow delayed refs
to be merged, so if you say are defragging an extent with 5k snapshots pointing
to it we will thrash the delayed ref lock because we need to go back and
manually merge these things together.  Instead we want to process quota changes
when we know they are going to happen, like when we first allocate an extent, we
free a reference for an extent, we add new references etc.  This patch
accomplishes this by only adding qgroup operations for real ref changes.  We
only modify the sequence number when we need to lookup roots for bytenrs, this
reduces the amount of churn on the sequence number and allows us to merge
delayed refs as we add them most of the time.  This patch encompasses a bunch of
architectural changes

1) qgroup ref operations: instead of tracking qgroup operations through the
delayed refs we simply add new ref operations whenever we notice that we need to
when we've modified the refs themselves.

2) tree mod seq:  we no longer have this separation of major/minor counters.
this makes the sequence number stuff much more sane and we can remove some
locking that was needed to protect the counter.

3) delayed ref seq: we now read the tree mod seq number and use that as our
sequence.  This means each new delayed ref doesn't have it's own unique sequence
number, rather whenever we go to lookup backrefs we inc the sequence number so
we can make sure to keep any new operations from screwing up our world view at
that given point.  This allows us to merge delayed refs during runtime.

With all of these changes the delayed ref stuff is a little saner and the qgroup
accounting stuff no longer goes negative in some cases like it was before.
Thanks,

Signed-off-by: Josef Bacik &lt;jbacik@fb.com&gt;
Signed-off-by: Chris Mason &lt;clm@fb.com&gt;
</content>
</entry>
<entry>
<title>Btrfs: attach delayed ref updates to delayed ref heads</title>
<updated>2014-01-28T21:20:25Z</updated>
<author>
<name>Josef Bacik</name>
</author>
<published>2014-01-23T14:21:38Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=d7df2c796d7eedd72a334dc89c65e1fec8171431'/>
<id>urn:sha1:d7df2c796d7eedd72a334dc89c65e1fec8171431</id>
<content type='text'>
Currently we have two rb-trees, one for delayed ref heads and one for all of the
delayed refs, including the delayed ref heads.  When we process the delayed refs
we have to hold onto the delayed ref lock for all of the selecting and merging
and such, which results in quite a bit of lock contention.  This was solved by
having a waitqueue and only one flusher at a time, however this hurts if we get
a lot of delayed refs queued up.

So instead just have an rb tree for the delayed ref heads, and then attach the
delayed ref updates to an rb tree that is per delayed ref head.  Then we only
need to take the delayed ref lock when adding new delayed refs and when
selecting a delayed ref head to process, all the rest of the time we deal with a
per delayed ref head lock which will be much less contentious.

The locking rules for this get a little more complicated since we have to lock
up to 3 things to properly process delayed refs, but I will address that problem
later.  For now this passes all of xfstests and my overnight stress tests.
Thanks,

Signed-off-by: Josef Bacik &lt;jbacik@fb.com&gt;
Signed-off-by: Chris Mason &lt;clm@fb.com&gt;
</content>
</entry>
<entry>
<title>Btrfs: introduce a head ref rbtree</title>
<updated>2014-01-28T21:19:22Z</updated>
<author>
<name>Liu Bo</name>
</author>
<published>2013-10-14T04:59:45Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=c46effa601f869f3d20a7386a745d9c002838eb8'/>
<id>urn:sha1:c46effa601f869f3d20a7386a745d9c002838eb8</id>
<content type='text'>
The way how we process delayed refs is
1) get a bunch of head refs,
2) pick up one head ref,
3) go one node back for any delayed ref updates.

The head ref is also linked in the same rbtree as the delayed ref is,
so in 1) stage, we have to walk one by one including not only head refs, but
delayed refs.

When we have a great number of delayed refs pending to process,
this'll cost time a lot.

Here we introduce a head ref specific rbtree, it only has head refs, so troubles
go away.

Signed-off-by: Liu Bo &lt;bo.li.liu@oracle.com&gt;
Signed-off-by: Josef Bacik &lt;jbacik@fusionio.com&gt;
Signed-off-by: Chris Mason &lt;clm@fb.com&gt;
</content>
</entry>
<entry>
<title>Btrfs: handle running extent ops with skinny metadata</title>
<updated>2013-05-18T01:40:15Z</updated>
<author>
<name>Josef Bacik</name>
</author>
<published>2013-05-09T17:49:30Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=b1c79e0947e0c190f865e2eb7b84a0fea0021cec'/>
<id>urn:sha1:b1c79e0947e0c190f865e2eb7b84a0fea0021cec</id>
<content type='text'>
Chris hit a bug where we weren't finding extent records when running extent ops.
This is because we use the delayed_ref_head when running the extent op, which
means we can't use the -&gt;type checks to see if we are metadata.  We also lose
the level of the metadata we are working on.  So to fix this we can just check
the -&gt;is_data section of the extent_op, and we can store the level of the buffer
we were modifying in the extent_op.  Thanks,

Signed-off-by: Josef Bacik &lt;jbacik@fusionio.com&gt;
</content>
</entry>
<entry>
<title>Merge branch 'raid56-experimental' into for-linus-3.9</title>
<updated>2013-02-20T19:06:05Z</updated>
<author>
<name>Chris Mason</name>
</author>
<published>2013-02-20T19:06:05Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=e942f883bc6651d50be139477baf6fb0eed3d5bb'/>
<id>urn:sha1:e942f883bc6651d50be139477baf6fb0eed3d5bb</id>
<content type='text'>
Signed-off-by: Chris Mason &lt;chris.mason@fusionio.com&gt;

Conflicts:
	fs/btrfs/ctree.h
	fs/btrfs/extent-tree.c
	fs/btrfs/inode.c
	fs/btrfs/volumes.c
</content>
</entry>
</feed>
