Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp125550pxb; Fri, 16 Apr 2021 01:07:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw/OuT8CeNym2kMVk5CmtVW3ZguXKKICVslZMCW5m6DLM3UcbJ6E8wmOcSVi36UFmiPoxfU X-Received: by 2002:a17:902:eec5:b029:ea:bffe:2b06 with SMTP id h5-20020a170902eec5b02900eabffe2b06mr8631547plb.8.1618560479020; Fri, 16 Apr 2021 01:07:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618560479; cv=none; d=google.com; s=arc-20160816; b=VLpA698IgS+jb0lTeTkGv+I9EE8I4oxcIbmhCP8bJo7XeKokJjf16Ss1WiScvV5JDb nSfbABM9IRQhNz/CbnT6LOj7YxWr+zGO1OViJBwfGDHxb2KCAJb6HQPta6cmzkqiHKn4 m3yHw+TzY3YlbDQ8fofkyBm19PsEVCjXNDjFNOuBjSnW872qc+IQZBH2iPG5AmR+jIQj 2XrKtsMRof3Boy0AfVYx0wpOhBldQ52jKzzpYj2+eSwGsH756v6z7wuAXwbrTLw5DbBp asYeuqAEbJlUdcAdpVzbVR6RWgmd2OblSSqWyS7eEppFrzz4HwhwvpsvhQOIMqQwt7A/ mZ0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=EudfwbsOz+Rrd2NgP14z/zCUOTCUqsLBWliTNq/re84=; b=ZPYfnv26qMGZ9PLxNHWwNZHTmKtVOf3kp1Cb7LYYOAr+dKiQ5CrySlGqONLyK7ZNRw W2lD9oukJ/y/pX8dwEK+j0mWLeo0pA2S9Cy1xpz9P8ezL/Bpy2YECOeWSdYVAseehxOC G5WS9svoUxHbaXq7qlSL+pjFNpZ47K1oD62AmVXKjqAHG0ad5c0DrSBkOA2Vj0fXgs1B m2g2AAhyXk9EAHrS708WU1W2yYosrNxQA1JrxESOcjFyqXWebQuN83gJhykVajNohOWJ 98QlCM3R8HaBUczdXl1/zg6e7rlS8ANVDReUffn2Ia3YQUZIv0T0Bingj9JOMyGmVlsW w9EA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h12si5880183pgq.171.2021.04.16.01.07.43; Fri, 16 Apr 2021 01:07:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238383AbhDPIBK (ORCPT + 99 others); Fri, 16 Apr 2021 04:01:10 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:16596 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237986AbhDPIBJ (ORCPT ); Fri, 16 Apr 2021 04:01:09 -0400 Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4FM7r060msz17QdP; Fri, 16 Apr 2021 15:58:24 +0800 (CST) Received: from [10.174.176.202] (10.174.176.202) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.498.0; Fri, 16 Apr 2021 16:00:35 +0800 Subject: Re: [RFC PATCH v2 6/7] fs: introduce a usage count into the superblock To: Christoph Hellwig CC: , , , , , References: <20210414134737.2366971-1-yi.zhang@huawei.com> <20210414134737.2366971-7-yi.zhang@huawei.com> <20210415144056.GA2069063@infradead.org> From: Zhang Yi Message-ID: Date: Fri, 16 Apr 2021 16:00:35 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.3.1 MIME-Version: 1.0 In-Reply-To: <20210415144056.GA2069063@infradead.org> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.176.202] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Hi, Christoph On 2021/4/15 22:40, Christoph Hellwig wrote: > On Wed, Apr 14, 2021 at 09:47:36PM +0800, Zhang Yi wrote: >> Commit <87d8fe1ee6b8> ("add releasepage hooks to block devices which can >> be used by file systems") introduce a hook that used by ext4 filesystem >> to release journal buffers, but it doesn't add corresponding concurrency >> protection that ->bdev_try_to_free_page() could be raced by umount >> filesystem concurrently. This patch add a usage count on superblock that >> filesystem can use it to prevent above race and make invoke >> ->bdev_try_to_free_page() safe. > > We already have two refcounts in the superblock: s_active which counts > the active refernce, and s_count which prevents the data structures > from beeing freed. I don't think we need yet another one. > . > Thanks you for your response. I checked the s_count and s_active refcounts, but it seems that we could not use these two refcounts directly. For the s_active. If we get s_active refcount in blkdev_releasepage(), we may put the final refcount when doing umount concurrently and have to do resource recycling, but we got page locked here and lead to deadlock. Maybe we could do async resource recycling through kworker, but I think it's not a good way. For the s_count, it is operated under the global sb_lock now, so get this refcount will serialize page release and affect performance. Besides, It's semantics are different from the 'usage count' by private fileststem, and we have to cooperate with sb->s_umount mutex lock to close the above race. So I introduce another refcount. Am I missing something or any suggestions? Thanks, Yi.