From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0B68BC433FE for ; Fri, 19 Nov 2021 02:19:49 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4898861B27 for ; Fri, 19 Nov 2021 02:19:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 4898861B27 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.ozlabs.org Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4HwL365jmXz301g for ; Fri, 19 Nov 2021 13:19:46 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.alibaba.com (client-ip=115.124.30.42; helo=out30-42.freemail.mail.aliyun.com; envelope-from=hsiangkao@linux.alibaba.com; receiver=) Received: from out30-42.freemail.mail.aliyun.com (out30-42.freemail.mail.aliyun.com [115.124.30.42]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4HwL315fZfz2xsp for ; Fri, 19 Nov 2021 13:19:36 +1100 (AEDT) X-Alimail-AntiSpam: AC=PASS; BC=-1|-1; BR=01201311R761e4; CH=green; DM=||false|; DS=||; FP=0|-1|-1|-1|0|-1|-1|-1; HT=e01e04357; MF=hsiangkao@linux.alibaba.com; NM=1; PH=DS; RN=7; SR=0; TI=SMTPD_---0UxG4NYB_1637288357; Received: from B-P7TQMD6M-0146(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0UxG4NYB_1637288357) by smtp.aliyun-inc.com(127.0.0.1); Fri, 19 Nov 2021 10:19:19 +0800 Date: Fri, 19 Nov 2021 10:19:16 +0800 From: Gao Xiang To: Huang Jianan Subject: Re: [PATCH] erofs: fix deadlock when shrink erofs slab Message-ID: References: <20211118135844.3559-1-huangjianan@oppo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20211118135844.3559-1-huangjianan@oppo.com> X-BeenThere: linux-erofs@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development of Linux EROFS file system List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: zhangshiming@oppo.com, yh@oppo.com, guanyuwei@oppo.com, guoweichao@oppo.com, linux-erofs@lists.ozlabs.org Errors-To: linux-erofs-bounces+linux-erofs=archiver.kernel.org@lists.ozlabs.org Sender: "Linux-erofs" 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 Reviewed-by: Gao Xiang Thanks, Gao Xiang