Commit 8844355d authored by Li Zefan's avatar Li Zefan

btrfs: Fix bugs in zlib workspace

- Fix a race that can result in alloc_workspace > cpus.
- Fix to check num_workspace after wakeup.
Signed-off-by: default avatarLi Zefan <lizf@cn.fujitsu.com>
parent 83a50de9
......@@ -75,16 +75,19 @@ static struct workspace *find_zlib_workspace(void)
return workspace;
}
spin_unlock(&workspace_lock);
if (atomic_read(&alloc_workspace) > cpus) {
DEFINE_WAIT(wait);
spin_unlock(&workspace_lock);
prepare_to_wait(&workspace_wait, &wait, TASK_UNINTERRUPTIBLE);
if (atomic_read(&alloc_workspace) > cpus)
if (atomic_read(&alloc_workspace) > cpus && !num_workspace)
schedule();
finish_wait(&workspace_wait, &wait);
goto again;
}
atomic_inc(&alloc_workspace);
spin_unlock(&workspace_lock);
workspace = kzalloc(sizeof(*workspace), GFP_NOFS);
if (!workspace) {
ret = -ENOMEM;
......
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