[PATCH] erofs: fix deadlock when shrink erofs slab

Gao Xiang hsiangkao at linux.alibaba.com
Fri Nov 19 13:19:16 AEDT 2021


On Thu, Nov 18, 2021 at 09:58:44PM +0800, Huang Jianan wrote:
> We observed the following deadlock in the stress test under low
> memory scenario:
> 
> Thread A                               Thread B
> - erofs_shrink_scan
>  - erofs_try_to_release_workgroup
>   - erofs_workgroup_try_to_freeze -- A
>                                        - z_erofs_do_read_page
>                                         - z_erofs_collection_begin
>                                          - z_erofs_register_collection
>                                           - erofs_insert_workgroup
>                                            - xa_lock(&sbi->managed_pslots) -- B
>                                            - erofs_workgroup_get
>                                             - erofs_wait_on_workgroup_freezed -- A
>   - xa_erase
>    - xa_lock(&sbi->managed_pslots) -- B
> 
> To fix this, it need to hold the xa lock before freeze the workgroup
> beacuse we will operate xarry. So let's hold the lock before access
  ^ because               ^ xarray

> each workgroup, just like when we using the radix tree before.
> 
> Fixes: 64094a04414f ("erofs: convert workstn to XArray")
> Signed-off-by: Huang Jianan <huangjianan at oppo.com>

Reviewed-by: Gao Xiang <hsiangkao at linux.alibaba.com>

Thanks,
Gao Xiang



More information about the Linux-erofs mailing list