Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp1550557imd; Thu, 1 Nov 2018 18:20:00 -0700 (PDT) X-Google-Smtp-Source: AJdET5fGu6s3Uh7z5kftt1SDxdSh2zL/p0HwksI9o2JJ3cgRCcvcU80LDx+C7IVNhJTCfP5U7uUH X-Received: by 2002:a62:3c6:: with SMTP id 189-v6mr9882220pfd.19.1541121600729; Thu, 01 Nov 2018 18:20:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541121600; cv=none; d=google.com; s=arc-20160816; b=rCKKL2OLLpNRmN6Bf5SqLkXEfEW2mFKmD1ea1EiKkcj9JSIiyoW9j7PlbZY3rTgr6x rCs2XVPUT8DSuDjn6+mDlmFjfppQZYuMphcOS6TyHdKU5/ljsLQ36c2LA6TM8q6hq7X0 FBcS6krWNDtLdp548eNZullx6XOugFrBvZ6mwnXPd8nv1brcG3IbLTzNTwcuXWB4ze50 kmaH5u55BkcYNlW61ejigWHxBVKB7iF6qLKt4yT77ls8tAfj6v8YFBVoeRXPDCwowkk8 V6w2UETKyx+a2oFVjhJ4ANO4E17T/aHWd1b1qpNXfDxN+O8qp5thJR4F4/M8RAxj7p5P AKNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=5UcF913Sf4+lDHIbLTW52lcS7ku+SrLsxCCSsooRGsw=; b=Nir+ybNAf1i+tGQ33iKkIj3TZITbS47OwoX+65OgbFHCyoe9FeRaRvDMCfpbgH0dKl krUVvE7gVAPSMyXtoCjUYnMaNYN6mZZh66BImN2jXxzLyxhT2Wq+XD83SyEXwjYWTXc/ vekm8LJZG57ZmpQE3h1Zz/xuEJIqQaUksw0xzXhWtkeLGF+QbNilpQTxb6pzwg2PVIF5 GAuJUTAUm72NoGzb4N2IEN8vjDQWrrtEzaxZBNcrpCw815pCabOrX2jbAZ0q4PNJLePX dfCpjdE6z7W81rZHb7JACulyYHOcCBa5B4RjeTVh3WtiaZD+dnmHgTyYjhqdviTHyXYI iDBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=oYFQIZrj; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 84-v6si32199019pfq.180.2018.11.01.18.19.45; Thu, 01 Nov 2018 18:20:00 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=oYFQIZrj; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726315AbeKBKXh (ORCPT + 99 others); Fri, 2 Nov 2018 06:23:37 -0400 Received: from mail-oi1-f196.google.com ([209.85.167.196]:40216 "EHLO mail-oi1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725961AbeKBKXh (ORCPT ); Fri, 2 Nov 2018 06:23:37 -0400 Received: by mail-oi1-f196.google.com with SMTP id u130-v6so323745oie.7 for ; Thu, 01 Nov 2018 18:18:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=5UcF913Sf4+lDHIbLTW52lcS7ku+SrLsxCCSsooRGsw=; b=oYFQIZrjGUKX18iySSSE+qtlu1Tf+VZeKNQ0WUY0MxFrzU3xn7mIkhiyiys0oM1Syo 4o1Y1BbmBAMClNC3bFkxRqS24yYgnowKfz7thmga97EIPhA1zdqg53204D/ydXeyA0TG zBU5brM2FVA4fHiPquDkrLAjpDvFxJZI0sDOmvc0RIKmp1+32H3+y8BX6A77OFaI3db1 n7ZBaMIzVjcwe+QL4KraFyl0TYTNLN6wwvRsLUjED/dLKnv9yoaFUDjX4FQDSwrPwZcG NCxYrVjaQ9qv07NBGkvUHNROWnwCXLqOO2K8IqxUuiz8I5xXedK4fIU5lEq9yxfayQMP fKmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=5UcF913Sf4+lDHIbLTW52lcS7ku+SrLsxCCSsooRGsw=; b=BwDhl19FAYz1PP19DEkvVuDUNsoPXn9cRbZVRYKxyLJqKqrot1KHgl3R+/9RzqS08b g6PP2fKSBDVJmTSxdi63wyl59we/GZ51xG2wW2q4ogyil1c8LBdWBKb98mxWvKuCY7Qa X29bP6pGZh34Q5oDVRpYAb8W+e2A9REqcJU8gTCQgWLpAr6sVrdaY/1fTl1/SJp84dl0 KVVmJlpM6+fE2z3zFzCAAPVOPGdJhe9duVY8NnuTUPc193CsofdjYXOuKIjIRg3ZMw9M MHuGdWXmdh2qlx7comy2XA8d76unuIl60m5soxW4wBDizIvK5bYFfSUFUhPj7DZtu0nh TUMg== X-Gm-Message-State: AGRZ1gL2idZa8mAdWmrPr24GH5X+WZ6fJ7nafTFujG5gnus71FKkR3xS vxQCD3uEolWZrWESWnRvKZZJAYpE X-Received: by 2002:aca:742:: with SMTP id 63-v6mr5878081oih.58.1541121497960; Thu, 01 Nov 2018 18:18:17 -0700 (PDT) Received: from JosephdeMacBook-Pro.local ([47.89.83.56]) by smtp.gmail.com with ESMTPSA id l26sm4727665otj.59.2018.11.01.18.18.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Nov 2018 18:18:17 -0700 (PDT) Subject: Re: [Ocfs2-devel] [PATCH V3] ocfs2: fix dead lock caused by ocfs2_defrag_extent To: Changwei Ge , Larry Chen , "mark@fasheh.com" , "jlbec@evilplan.org" Cc: "linux-kernel@vger.kernel.org" , "ocfs2-devel@oss.oracle.com" , Andrew Morton References: <20181101071422.14470-1-lchen@suse.com> <63ADC13FD55D6546B7DECE290D39E37301277DE397@H3CMLB12-EX.srv.huawei-3com.com> <4f96339a-6209-eee1-3792-4720eca35688@gmail.com> <63ADC13FD55D6546B7DECE290D39E37301277DE3FE@H3CMLB12-EX.srv.huawei-3com.com> From: Joseph Qi Message-ID: <011125b5-6343-6f4e-b420-3f152f395980@gmail.com> Date: Fri, 2 Nov 2018 09:18:05 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <63ADC13FD55D6546B7DECE290D39E37301277DE3FE@H3CMLB12-EX.srv.huawei-3com.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 18/11/1 20:34, Changwei Ge wrote: > Hello Joseph, > > On 2018/11/1 20:16, Joseph Qi wrote: >> >> >> On 18/11/1 19:52, Changwei Ge wrote: >>> Hello Joseph, >>> >>> On 2018/11/1 17:01, Joseph Qi wrote: >>>> Hi Larry, >>>> >>>> On 18/11/1 15:14, Larry Chen wrote: >>>>> ocfs2_defrag_extent may fall into deadlock. >>>>> >>>>> ocfs2_ioctl_move_extents >>>>> ocfs2_ioctl_move_extents >>>>> ocfs2_move_extents >>>>> ocfs2_defrag_extent >>>>> ocfs2_lock_allocators_move_extents >>>>> >>>>> ocfs2_reserve_clusters >>>>> inode_lock GLOBAL_BITMAP_SYSTEM_INODE >>>>> >>>>> __ocfs2_flush_truncate_log >>>>> inode_lock GLOBAL_BITMAP_SYSTEM_INODE >>>>> >>>>> As backtrace shows above, ocfs2_reserve_clusters() will call inode_lock >>>>> against the global bitmap if local allocator has not sufficient cluters. >>>>> Once global bitmap could meet the demand, ocfs2_reserve_cluster will >>>>> return success with global bitmap locked. >>>>> >>>>> After ocfs2_reserve_cluster(), if truncate log is full, >>>>> __ocfs2_flush_truncate_log() will definitely fall into deadlock because it >>>>> needs to inode_lock global bitmap, which has already been locked. >>>>> >>>>> To fix this bug, we could remove from ocfs2_lock_allocators_move_extents() >>>>> the code which intends to lock global allocator, and put the removed code >>>>> after __ocfs2_flush_truncate_log(). >>>>> >>>>> ocfs2_lock_allocators_move_extents() is referred by 2 places, one is here, >>>>> the other does not need the data allocator context, which means this patch >>>>> does not affect the caller so far. >>>>> >>>>> Change log: >>>>> 1. Correct the function comment. >>>>> 2. Remove unused argument from ocfs2_lock_meta_allocator_move_extents. >>>>> >>>>> Signed-off-by: Larry Chen >>>>> --- >>>>> fs/ocfs2/move_extents.c | 47 ++++++++++++++++++++++++++--------------------- >>>>> 1 file changed, 26 insertions(+), 21 deletions(-) >>>>> >>> >>>> IMO, here clusters_to_move is only for data_ac, since we change this >>>> function to only handle meta_ac, I'm afraid clusters_to_move related >>>> logic has to been changed correspondingly. >>> >>> I think we can't remove *clusters_to_move* from here as clusters can be reserved latter outsides this function, but we >>> still have to reserve metadata(extents) in advance. >>> So we need that argument. >>> >> I was not saying just remove it. >> IIUC, clusters_to_move is for reserving data clusters (for meta_ac, we > > Um... > *cluster_to_move* is not only used for reserving data clusters. > It is also an effecting input for calculating if existed extents still have enough free records for later > tree operation like attaching clusters to extents. > > Please refer to below code: > 175 unsigned int max_recs_needed = 2 * extents_to_split + clusters_to_move; > IC. It is a bit odd that calculate it here but do the real reserve out. > > >> mostly talk about blocks). Since we have moved data cluster reserve >> logic out of ocfs2_lock_allocators_move_extents() now, then left >> clusters_to_move related logic here is odd. > > Like my preceding elaboration, it is used for telling if we need more extents. > Anyway, I think we must keep *cluster_to_move* here as it used to. :-) > > Thanks, > Changwei > > > > >> >>>>> u32 extents_to_split, >>>>> struct ocfs2_alloc_context **meta_ac, >>>>> - struct ocfs2_alloc_context **data_ac, >>>>> int extra_blocks, >>>>> int *credits) >>>>> { >>>>> @@ -192,13 +188,6 @@ static int ocfs2_lock_allocators_move_extents(struct inode *inode, >>>>> goto out; >>>>> } >>>>> >>>>> - if (data_ac) { >>>>> - ret = ocfs2_reserve_clusters(osb, clusters_to_move, data_ac); >>>>> - if (ret) { >>>>> - mlog_errno(ret); >>>>> - goto out; >>>>> - } >>>>> - } >>>>> >>>>> *credits += ocfs2_calc_extend_credits(osb->sb, et->et_root_el); >>>>> >>>>> @@ -257,10 +246,10 @@ static int ocfs2_defrag_extent(struct ocfs2_move_extents_context *context, >>>>> } >>>>> } >>>>> >>>>> - ret = ocfs2_lock_allocators_move_extents(inode, &context->et, *len, 1, >>>>> - &context->meta_ac, >>>>> - &context->data_ac, >>>>> - extra_blocks, &credits); >>>>> + ret = ocfs2_lock_meta_allocator_move_extents(inode, &context->et, >>>>> + *len, 1, >>>>> + &context->meta_ac, >>>>> + extra_blocks, &credits); >>>>> if (ret) { >>>>> mlog_errno(ret); >>>>> goto out; >>>>> @@ -283,6 +272,21 @@ static int ocfs2_defrag_extent(struct ocfs2_move_extents_context *context, >>>>> } >>>>> } >>>>> >>>>> + /* >>>>> + * Make sure ocfs2_reserve_cluster is called after >>>>> + * __ocfs2_flush_truncate_log, otherwise, dead lock may happen. >>>>> + * >>>>> + * If ocfs2_reserve_cluster is called >>>>> + * before __ocfs2_flush_truncate_log, dead lock on global bitmap >>>>> + * may happen. >>>>> + * >>>>> + */ >>>>> + ret = ocfs2_reserve_clusters(osb, *len, &context->data_ac); >>>>> + if (ret) { >>>>> + mlog_errno(ret); >>>>> + goto out_unlock_mutex; >>>>> + } >>>>> + >>>>> handle = ocfs2_start_trans(osb, credits); >>>>> if (IS_ERR(handle)) { >>>>> ret = PTR_ERR(handle); >>>>> @@ -600,9 +604,10 @@ static int ocfs2_move_extent(struct ocfs2_move_extents_context *context, >>>>> } >>>>> } >>>>> >>>>> - ret = ocfs2_lock_allocators_move_extents(inode, &context->et, len, 1, >>>>> - &context->meta_ac, >>>>> - NULL, extra_blocks, &credits); >>>>> + ret = ocfs2_lock_meta_allocator_move_extents(inode, &context->et, >>>>> + len, 1, >>>>> + &context->meta_ac, >>>>> + extra_blocks, &credits); >>>>> if (ret) { >>>>> mlog_errno(ret); >>>>> goto out; >>>>> >>>> >>>> _______________________________________________ >>>> Ocfs2-devel mailing list >>>> Ocfs2-devel@oss.oracle.com >>>> https://oss.oracle.com/mailman/listinfo/ocfs2-devel >>>> >>