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 <[email protected]>
Reviewed-by: Gao Xiang <[email protected]>
Thanks,
Gao Xiang