Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp10419712rwl; Wed, 11 Jan 2023 20:13:18 -0800 (PST) X-Google-Smtp-Source: AMrXdXuvlVUyd8Q3P8a7GnteiAbuIlJlTKIDn2SMvbHRq/SChSFgLC+SIAWiFZcRgc9UAsUGs/uo X-Received: by 2002:a17:906:369b:b0:7e2:c573:d2e9 with SMTP id a27-20020a170906369b00b007e2c573d2e9mr58388313ejc.48.1673496798583; Wed, 11 Jan 2023 20:13:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673496798; cv=none; d=google.com; s=arc-20160816; b=UjRMMZw1/wYo6FgiDZ8dao5xPcLQhhhsU+UU5NFzte/EqbD7h1viRQbwZrvArtGd7R cgtOsH99EOGTxq5XCMm5/3klWyKu85l8Q3UDzN07ebvhyQVu8lBdIAOGX/64raQYjT52 7zXcAvYxWeli+xYpyUHf9xZz+9N+S9JU82Kzuu/adekrb/rEz8dQWh/Mdl1hEGOpnjyM 7D+iYtfAdzZCD2+BrWrlALw495Z5Pm8sNeTs1x79L6AQTk9Gm6Gdi++U1HIXfDEy5TlW hdT1toCBIucg7ffTCqEQVKDEnf09H90nhLfjKM7hKmJ7C6WNjGhDSMAOzR4yE9UOQqpp lxsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=67uOa2879CcHZC9DJ8f6F3eEtAX7+wWoYcrX19koeTA=; b=l/mYEAEGqIAdsXMpYFTivYLVtXgyQgMQfB4S6iaGjOc5VXQtAYnc6Gl6Tl3p0vU5DU h33hk4aVEMOTfsC5VQxgHTBJOxjPkHyvcsCPjQIml6XbM/epQfuseOiTnHMJVZM+BHZx EP1ejx6lXZvqWpP03urUUQMw68RAYvrMybg0iuYqcf09dCjSTIFpq+fcY0mvArW1uCZI LWa+q6IX8VcY40Eu2hZ5f1Uq4ujMCnf0U8At2kZ2r+wifsJeStZ6SM/fjdsQbeSpeI8p xW/YHRS/WowugJ4JP9a+sCbii+RwNTka5/BT5mF5uGxJv3iNkLLFEp5RxKc9+LFlnE/3 JqJw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s10-20020a50ab0a000000b004697dff9638si5627324edc.87.2023.01.11.20.13.06; Wed, 11 Jan 2023 20:13:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230293AbjALD6q (ORCPT + 50 others); Wed, 11 Jan 2023 22:58:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230285AbjALD6d (ORCPT ); Wed, 11 Jan 2023 22:58:33 -0500 Received: from out30-130.freemail.mail.aliyun.com (out30-130.freemail.mail.aliyun.com [115.124.30.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EFDF73C0EE for ; Wed, 11 Jan 2023 19:58:31 -0800 (PST) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R251e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045170;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=7;SR=0;TI=SMTPD_---0VZPF1qd_1673495907; Received: from 30.221.131.229(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VZPF1qd_1673495907) by smtp.aliyun-inc.com; Thu, 12 Jan 2023 11:58:28 +0800 Message-ID: <6acd0aea-2e7b-e30e-214f-81f4c3766ead@linux.alibaba.com> Date: Thu, 12 Jan 2023 11:58:27 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.4.0 Subject: Re: [PATCH v2 1/2] fscache: Use wait_on_bit() to wait for the freeing of relinquished volume Content-Language: en-US To: David Howells , Hou Tao Cc: linux-cachefs@redhat.com, Jeff Layton , linux-erofs@lists.ozlabs.org, linux-kernel@vger.kernel.org, houtao1@huawei.com References: <20221226103309.953112-2-houtao@huaweicloud.com> <20221226103309.953112-1-houtao@huaweicloud.com> <2431838.1673453170@warthog.procyon.org.uk> From: Jingbo Xu In-Reply-To: <2431838.1673453170@warthog.procyon.org.uk> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,NICE_REPLY_A,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY, USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 1/12/23 12:06 AM, David Howells wrote: > Hou Tao wrote: > >> clear_bit(FSCACHE_VOLUME_ACQUIRE_PENDING, &cursor->flags); >> + /* >> + * Paired with barrier in wait_on_bit(). Check >> + * wake_up_bit() and waitqueue_active() for details. >> + */ >> + smp_mb__after_atomic(); >> wake_up_bit(&cursor->flags, FSCACHE_VOLUME_ACQUIRE_PENDING); > > What two values are you applying a partial ordering to? Yeah Hou Tao has explained that a full barrier is needed here to avoid the potential reordering at the waker side. As I was also researching on this these days, I'd like to share my thought on this, hopefully if it could give some insight :) Without the barrier at the waker side, it may suffer from the following race: ``` CPU0 - waker CPU1 - waiter if (waitqueue_active(wq_head)) <-- find no wq_entry in wq_head list wake_up(wq_head); for (;;) { prepare_to_wait(...); # add wq_entry into wq_head list if (@cond) <-- @cond is false break; schedule(); <-- wq_entry still in wq_head list, wait for next wakeup } finish_wait(&wq_head, &wait); @cond = true; ``` in which case the waiter misses the wakeup for one time. -- Thanks, Jingbo