Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp3660085pxp; Wed, 23 Mar 2022 03:17:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzJtni9bhUMosnINdBC/eVdw8hxNaCkxqhzThAgBVej/sNNRNnbAcNdebiSft1PGU9dnG1u X-Received: by 2002:aa7:dc4e:0:b0:419:407b:6bff with SMTP id g14-20020aa7dc4e000000b00419407b6bffmr15959564edu.158.1648030639129; Wed, 23 Mar 2022 03:17:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648030639; cv=none; d=google.com; s=arc-20160816; b=01Ck2n3+Cv9Rsc5zHXM6ETFkfnxnLLIVai61WQQmKfwVLrQ3dM0in4N3isz1okDqH6 cL4OZGJ+YEEi/jP+btFH9u1HwuDbeCBbXoEr2kIj8ZAdDjQ5WD9p37bY9C3ceFjOJoPI oNskMeg7SI1CIFbhWQZJ+l90H7190u+yV73P1Ip70MQbALah2Y5d9sTZEeMdr0M2tLkx cgJ5OEFwlyXaxRmsqn7B3phZ78oOXY5fRRqaqFw45+iUbiu9EkeXSiJbaEzUGOk1S9xG 7QMaXeMZYf1W8nQGVrtg7b1frGYEyoGEUHqwpgTfwxtsRC0oMYs9CltqNqTsss/E8a/T 2KsA== 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=B0AXgNiCt67VhDGEcOPZvzCk+ySt9uLWR9atp1lMzNA=; b=b5rxVrvIYukrQrqwbwi0ckrqGTYsorWlT0Yv/46DU2v618KYClnB2aFDSRunTES53F UEj1jzEQ9erEtLDYkWqXG/w0D1Mdp+ElTrpHWnxQAKwex2+/ohnsOf+H82cT2XNY/B2A R/ndpen/w8/x6RJgUSaggA1hWcmfQRiJ5KwY2hy0AUKGhbKzMYmgiSZNmJVVSGa/rYia 7PK1j/wupkEJzDrr3DSV/hj7Nly94OV/1d/U9SzhT4TDBUEVibc7jbHn/vCKMcF/FKR9 mp7DrdsAUAKZsE6IZCcNOr+Qvrh3uDimd7hwjN3TDMI8CUhkW+dpdNds89p5j/dVFhlV lyhQ== 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 la6-20020a170907780600b006df76385e39si11852704ejc.729.2022.03.23.03.16.50; Wed, 23 Mar 2022 03:17:18 -0700 (PDT) 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 S241843AbiCWFeg (ORCPT + 99 others); Wed, 23 Mar 2022 01:34:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231261AbiCWFed (ORCPT ); Wed, 23 Mar 2022 01:34:33 -0400 Received: from out30-56.freemail.mail.aliyun.com (out30-56.freemail.mail.aliyun.com [115.124.30.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 09104F7F; Tue, 22 Mar 2022 22:33:01 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R151e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04395;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=16;SR=0;TI=SMTPD_---0V7zuNYS_1648013577; Received: from 30.225.24.115(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0V7zuNYS_1648013577) by smtp.aliyun-inc.com(127.0.0.1); Wed, 23 Mar 2022 13:32:58 +0800 Message-ID: <8f93abf9-2c3e-51cd-9afa-ee2b68e61a4b@linux.alibaba.com> Date: Wed, 23 Mar 2022 13:32:57 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.6.1 Subject: Re: [PATCH v5 03/22] cachefiles: introduce on-demand read mode Content-Language: en-US To: Matthew Wilcox , David Howells Cc: linux-cachefs@redhat.com, xiang@kernel.org, chao@kernel.org, linux-erofs@lists.ozlabs.org, torvalds@linux-foundation.org, gregkh@linuxfoundation.org, linux-fsdevel@vger.kernel.org, joseph.qi@linux.alibaba.com, bo.liu@linux.alibaba.com, tao.peng@linux.alibaba.com, gerry@linux.alibaba.com, eguan@linux.alibaba.com, linux-kernel@vger.kernel.org, luodaowen.backend@bytedance.com References: <20220316131723.111553-1-jefflexu@linux.alibaba.com> <20220316131723.111553-4-jefflexu@linux.alibaba.com> <6bc551d2-15fc-5d17-c99b-8db588c6b671@linux.alibaba.com> <1035025.1647876652@warthog.procyon.org.uk> From: JeffleXu In-Reply-To: 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_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,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 3/23/22 1:04 AM, Matthew Wilcox wrote: > On Mon, Mar 21, 2022 at 03:30:52PM +0000, David Howells wrote: >> Matthew Wilcox wrote: >> >>> Absolutely; just use xa_lock() to protect both setting & testing the >>> flag. >> >> How should Jeffle deal with xarray dropping the lock internally in order to do >> an allocation and then taking it again (actually in patch 5)? > > There are a number of ways to handle this. I'll outline two; others > are surely possible. Thanks. > > option 1: > > add side: > > xa_lock(); > if (!DEAD) > xa_store(GFP_KERNEL); > if (DEAD) > xa_erase(); > xa_unlock(); > > destroy side: > > xa_lock(); > set DEAD; > xa_for_each() > xa_erase(); > xa_unlock(); > > That has the problem (?) that it might be temporarily possible to see > a newly-added entry in a DEAD array. I think this problem doesn't matter in our scenario. > > If that is a problem, you can use xa_reserve() on the add side, followed > by overwriting it or removing it, depending on the state of the DEAD flag. Right. Then even the normal path (when memory allocation succeeds) needs to call xa_reserve() once. > > If you really want to, you can decompose the add side so that you always > check the DEAD flag before doing the store, ie: > > do { > xas_lock(); > if (DEAD) > xas_set_error(-EINVAL); > else > xas_store(); > xas_unlock(); > } while (xas_nomem(GFP_KERNEL)); This way is more cleaner from the locking semantics, with the cost of code duplication. However, after decomposing the __xa_alloc(), we can also reuse the xas when setting CACHEFILES_REQ_NEW mark. ``` + xa_lock(xa); + ret = __xa_alloc(xa, &id, req, xa_limit_32b, GFP_KERNEL); + if (!ret) + __xa_set_mark(xa, id, CACHEFILES_REQ_NEW); + xa_unlock(xa); ``` So far personally I prefer the decomposing way in our scenario. -- Thanks, Jeffle