Commit 09eb47a7 authored by Frederic Weisbecker's avatar Frederic Weisbecker

kill-the-bkl/reiserfs: reduce number of contentions in search_by_key()

search_by_key() is a central function in reiserfs which searches
the patch in the fs tree from the root to a node given its key.

It is the function that is most requesting the write lock
because it's a path very often used.

Also we forget to release the lock while reading the next tree node,
making us holding the lock in a wasteful way.

Then we release the lock while reading the current node and its childs,
all-in-one. It should be safe because we have a reference to these
blocks and even if we read a block that will be concurrently changed,
we have an fs_changed check later that will make us retry the path from
the root.

[ Impact: release the write lock while unused in a hot path ]

Cc: Jeff Mahoney <jeffm@suse.com>
Cc: Chris Mason <chris.mason@oracle.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Alexander Beregalov <a.beregalov@gmail.com>
Signed-off-by: default avatarFrederic Weisbecker <fweisbec@gmail.com>
parent b1c839bb
...@@ -529,6 +529,14 @@ static void search_by_key_reada(struct super_block *s, ...@@ -529,6 +529,14 @@ static void search_by_key_reada(struct super_block *s,
for (i = 0; i < num; i++) { for (i = 0; i < num; i++) {
bh[i] = sb_getblk(s, b[i]); bh[i] = sb_getblk(s, b[i]);
} }
/*
* We are going to read some blocks on which we
* have a reference. It's safe, though we might be
* reading blocks concurrently changed if we release
* the lock. But it's still fine because we check later
* if the tree changed
*/
reiserfs_write_unlock(s);
for (j = 0; j < i; j++) { for (j = 0; j < i; j++) {
/* /*
* note, this needs attention if we are getting rid of the BKL * note, this needs attention if we are getting rid of the BKL
...@@ -626,10 +634,12 @@ int search_by_key(struct super_block *sb, const struct cpu_key *key, /* Key to s ...@@ -626,10 +634,12 @@ int search_by_key(struct super_block *sb, const struct cpu_key *key, /* Key to s
if ((bh = last_element->pe_buffer = if ((bh = last_element->pe_buffer =
sb_getblk(sb, block_number))) { sb_getblk(sb, block_number))) {
if (!buffer_uptodate(bh) && reada_count > 1) if (!buffer_uptodate(bh) && reada_count > 1)
/* will unlock the write lock */
search_by_key_reada(sb, reada_bh, search_by_key_reada(sb, reada_bh,
reada_blocks, reada_count); reada_blocks, reada_count);
else
reiserfs_write_unlock(sb);
ll_rw_block(READ, 1, &bh); ll_rw_block(READ, 1, &bh);
reiserfs_write_unlock(sb);
wait_on_buffer(bh); wait_on_buffer(bh);
reiserfs_write_lock(sb); reiserfs_write_lock(sb);
if (!buffer_uptodate(bh)) if (!buffer_uptodate(bh))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment