<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel.git/drivers/md/bcache/btree.c, branch linux-5.6.y</title>
<subtitle>Hosts the 0x221E linux distro kernel.
</subtitle>
<id>https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-5.6.y</id>
<link rel='self' href='https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-5.6.y'/>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/'/>
<updated>2020-03-03T03:01:32Z</updated>
<entry>
<title>Revert "bcache: ignore pending signals when creating gc and allocator thread"</title>
<updated>2020-03-03T03:01:32Z</updated>
<author>
<name>Jens Axboe</name>
</author>
<published>2020-03-03T03:01:32Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=764b53b26c9897b0693c934797e898d6cd883a26'/>
<id>urn:sha1:764b53b26c9897b0693c934797e898d6cd883a26</id>
<content type='text'>
This reverts commit 0b96da639a4874311e9b5156405f69ef9fc3bef8.

We can't just go flushing random signals, under the assumption that the
OOM killer will just do something else. It's not safe from the OOM
perspective, and it could also cause other signals to get randomly lost.

Signed-off-by: Jens Axboe &lt;axboe@kernel.dk&gt;
</content>
</entry>
<entry>
<title>bcache: ignore pending signals when creating gc and allocator thread</title>
<updated>2020-02-13T15:53:49Z</updated>
<author>
<name>Coly Li</name>
</author>
<published>2020-02-13T14:12:05Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=0b96da639a4874311e9b5156405f69ef9fc3bef8'/>
<id>urn:sha1:0b96da639a4874311e9b5156405f69ef9fc3bef8</id>
<content type='text'>
When run a cache set, all the bcache btree node of this cache set will
be checked by bch_btree_check(). If the bcache btree is very large,
iterating all the btree nodes will occupy too much system memory and
the bcache registering process might be selected and killed by system
OOM killer. kthread_run() will fail if current process has pending
signal, therefore the kthread creating in run_cache_set() for gc and
allocator kernel threads are very probably failed for a very large
bcache btree.

Indeed such OOM is safe and the registering process will exit after
the registration done. Therefore this patch flushes pending signals
during the cache set start up, specificly in bch_cache_allocator_start()
and bch_gc_thread_start(), to make sure run_cache_set() won't fail for
large cahced data set.

Signed-off-by: Coly Li &lt;colyli@suse.de&gt;
Signed-off-by: Jens Axboe &lt;axboe@kernel.dk&gt;
</content>
</entry>
<entry>
<title>bcache: reap from tail of c-&gt;btree_cache in bch_mca_scan()</title>
<updated>2020-01-23T18:40:02Z</updated>
<author>
<name>Coly Li</name>
</author>
<published>2020-01-23T17:01:42Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=e3de04469a49ee09c89e80bf821508df458ccee6'/>
<id>urn:sha1:e3de04469a49ee09c89e80bf821508df458ccee6</id>
<content type='text'>
When shrink btree node cache from c-&gt;btree_cache in bch_mca_scan(),
no matter the selected node is reaped or not, it will be rotated from
the head to the tail of c-&gt;btree_cache list. But in bcache journal
code, when flushing the btree nodes with oldest journal entry, btree
nodes are iterated and slected from the tail of c-&gt;btree_cache list in
btree_flush_write(). The list_rotate_left() in bch_mca_scan() will
make btree_flush_write() iterate more nodes in c-&gt;btree_list in reverse
order.

This patch just reaps the selected btree node cache, and not move it
from the head to the tail of c-&gt;btree_cache list. Then bch_mca_scan()
will not mess up c-&gt;btree_cache list to btree_flush_write().

Signed-off-by: Coly Li &lt;colyli@suse.de&gt;
Signed-off-by: Jens Axboe &lt;axboe@kernel.dk&gt;
</content>
</entry>
<entry>
<title>bcache: reap c-&gt;btree_cache_freeable from the tail in bch_mca_scan()</title>
<updated>2020-01-23T18:40:02Z</updated>
<author>
<name>Coly Li</name>
</author>
<published>2020-01-23T17:01:41Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=d5c9c470b01177e4d90cdbf178b8c7f37f5b8795'/>
<id>urn:sha1:d5c9c470b01177e4d90cdbf178b8c7f37f5b8795</id>
<content type='text'>
In order to skip the most recently freed btree node cahce, currently
in bch_mca_scan() the first 3 caches in c-&gt;btree_cache_freeable list
are skipped when shrinking bcache node caches in bch_mca_scan(). The
related code in bch_mca_scan() is,

 737 list_for_each_entry_safe(b, t, &amp;c-&gt;btree_cache_freeable, list) {
 738         if (nr &lt;= 0)
 739                 goto out;
 740
 741         if (++i &gt; 3 &amp;&amp;
 742             !mca_reap(b, 0, false)) {
             		lines free cache memory
 746         }
 747         nr--;
 748 }

The problem is, if virtual memory code calls bch_mca_scan() and
the calculated 'nr' is 1 or 2, then in the above loop, nothing will
be shunk. In such case, if slub/slab manager calls bch_mca_scan()
for many times with small scan number, it does not help to shrink
cache memory and just wasts CPU cycles.

This patch just selects btree node caches from tail of the
c-&gt;btree_cache_freeable list, then the newly freed host cache can
still be allocated by mca_alloc(), and at least 1 node can be shunk.

Signed-off-by: Coly Li &lt;colyli@suse.de&gt;
Signed-off-by: Jens Axboe &lt;axboe@kernel.dk&gt;
</content>
</entry>
<entry>
<title>bcache: remove member accessed from struct btree</title>
<updated>2020-01-23T18:40:02Z</updated>
<author>
<name>Coly Li</name>
</author>
<published>2020-01-23T17:01:40Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=125d98edd11464c8e0ec9eaaba7d682d0f832686'/>
<id>urn:sha1:125d98edd11464c8e0ec9eaaba7d682d0f832686</id>
<content type='text'>
The member 'accessed' of struct btree is used in bch_mca_scan() when
shrinking btree node caches. The original idea is, if b-&gt;accessed is
set, clean it and look at next btree node cache from c-&gt;btree_cache
list, and only shrink the caches whose b-&gt;accessed is cleaned. Then
only cold btree node cache will be shrunk.

But when I/O pressure is high, it is very probably that b-&gt;accessed
of a btree node cache will be set again in bch_btree_node_get()
before bch_mca_scan() selects it again. Then there is no chance for
bch_mca_scan() to shrink enough memory back to slub or slab system.

This patch removes member accessed from struct btree, then once a
btree node ache is selected, it will be immediately shunk. By this
change, bch_mca_scan() may release btree node cahce more efficiently.

Signed-off-by: Coly Li &lt;colyli@suse.de&gt;
Signed-off-by: Jens Axboe &lt;axboe@kernel.dk&gt;
</content>
</entry>
<entry>
<title>Revert "bcache: fix fifo index swapping condition in journal_pin_cmp()"</title>
<updated>2019-11-18T15:35:47Z</updated>
<author>
<name>Jens Axboe</name>
</author>
<published>2019-11-18T15:35:47Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=00b89892c869f34528deca957b10d1468c4e8b38'/>
<id>urn:sha1:00b89892c869f34528deca957b10d1468c4e8b38</id>
<content type='text'>
Coly says:

"Guoju Fang talked to me today, he told me this change was unnecessary
and I was over-thought.

Then I realize fifo_idx() uses a mask to handle the array index overflow
condition, so the index swap in journal_pin_cmp() won't happen. And yes,
Guoju and Kent are correct.

Since you already applied this patch, can you please to remove this
patch from your for-next branch? This single patch does not break
thing, but it is unecessary at this moment."

This reverts commit c0e0954e909c17b43d176ab219fc598964616ae6.

Signed-off-by: Jens Axboe &lt;axboe@kernel.dk&gt;
</content>
</entry>
<entry>
<title>bcache: at least try to shrink 1 node in bch_mca_scan()</title>
<updated>2019-11-13T22:42:50Z</updated>
<author>
<name>Coly Li</name>
</author>
<published>2019-11-13T08:03:24Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=9fcc34b1a6dd4b8e5337e2b6ef45e428897eca6b'/>
<id>urn:sha1:9fcc34b1a6dd4b8e5337e2b6ef45e428897eca6b</id>
<content type='text'>
In bch_mca_scan(), the number of shrinking btree node is calculated
by code like this,
	unsigned long nr = sc-&gt;nr_to_scan;

        nr /= c-&gt;btree_pages;
        nr = min_t(unsigned long, nr, mca_can_free(c));
variable sc-&gt;nr_to_scan is number of objects (here is bcache B+tree
nodes' number) to shrink, and pointer variable sc is sent from memory
management code as parametr of a callback.

If sc-&gt;nr_to_scan is smaller than c-&gt;btree_pages, after the above
calculation, variable 'nr' will be 0 and nothing will be shrunk. It is
frequeently observed that only 1 or 2 is set to sc-&gt;nr_to_scan and make
nr to be zero. Then bch_mca_scan() will do nothing more then acquiring
and releasing mutex c-&gt;bucket_lock.

This patch checkes whether nr is 0 after the above calculation, if 0
is the result then set 1 to variable 'n'. Then at least bch_mca_scan()
will try to shrink a single B+tree node.

Signed-off-by: Coly Li &lt;colyli@suse.de&gt;
Signed-off-by: Jens Axboe &lt;axboe@kernel.dk&gt;
</content>
</entry>
<entry>
<title>bcache: add code comments in bch_btree_leaf_dirty()</title>
<updated>2019-11-13T22:42:50Z</updated>
<author>
<name>Coly Li</name>
</author>
<published>2019-11-13T08:03:22Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=5dccefd3ea0b33cf3e5a45cbccc7e0bf22791655'/>
<id>urn:sha1:5dccefd3ea0b33cf3e5a45cbccc7e0bf22791655</id>
<content type='text'>
This patch adds code comments in bch_btree_leaf_dirty() to explain
why w-&gt;journal should always reference the eldest journal pin of
all the writing bkeys in the btree node. To make the bcache journal
code to be easier to be understood.

Signed-off-by: Coly Li &lt;colyli@suse.de&gt;
Signed-off-by: Jens Axboe &lt;axboe@kernel.dk&gt;
</content>
</entry>
<entry>
<title>bcache: fix a lost wake-up problem caused by mca_cannibalize_lock</title>
<updated>2019-11-13T22:42:50Z</updated>
<author>
<name>Guoju Fang</name>
</author>
<published>2019-11-13T08:03:16Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=34cf78bf34d48dddddfeeadb44f9841d7864997a'/>
<id>urn:sha1:34cf78bf34d48dddddfeeadb44f9841d7864997a</id>
<content type='text'>
This patch fix a lost wake-up problem caused by the race between
mca_cannibalize_lock and bch_cannibalize_unlock.

Consider two processes, A and B. Process A is executing
mca_cannibalize_lock, while process B takes c-&gt;btree_cache_alloc_lock
and is executing bch_cannibalize_unlock. The problem happens that after
process A executes cmpxchg and will execute prepare_to_wait. In this
timeslice process B executes wake_up, but after that process A executes
prepare_to_wait and set the state to TASK_INTERRUPTIBLE. Then process A
goes to sleep but no one will wake up it. This problem may cause bcache
device to dead.

Signed-off-by: Guoju Fang &lt;fangguoju@gmail.com&gt;
Signed-off-by: Coly Li &lt;colyli@suse.de&gt;
Signed-off-by: Jens Axboe &lt;axboe@kernel.dk&gt;
</content>
</entry>
<entry>
<title>bcache: fix fifo index swapping condition in journal_pin_cmp()</title>
<updated>2019-11-13T22:42:49Z</updated>
<author>
<name>Coly Li</name>
</author>
<published>2019-11-13T08:03:15Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=c0e0954e909c17b43d176ab219fc598964616ae6'/>
<id>urn:sha1:c0e0954e909c17b43d176ab219fc598964616ae6</id>
<content type='text'>
Fifo structure journal.pin is implemented by a cycle buffer, if the back
index reaches highest location of the cycle buffer, it will be swapped
to 0. Once the swapping happens, it means a smaller fifo index might be
associated to a newer journal entry. So the btree node with oldest
journal entry won't be selected in bch_btree_leaf_dirty() to reference
the dirty B+tree leaf node. This problem may cause bcache journal won't
protect unflushed oldest B+tree dirty leaf node in power failure, and
this B+tree leaf node is possible to beinconsistent after reboot from
power failure.

This patch fixes the fifo index comparing logic in journal_pin_cmp(),
to avoid potential corrupted B+tree leaf node when the back index of
journal pin is swapped.

Signed-off-by: Coly Li &lt;colyli@suse.de&gt;
Signed-off-by: Jens Axboe &lt;axboe@kernel.dk&gt;
</content>
</entry>
</feed>
