Received: by 2002:a05:7412:7c14:b0:fa:6e18:a558 with SMTP id ii20csp194529rdb; Mon, 22 Jan 2024 00:37:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IHsOLeODSMorwOJ48eUYGjUZpUoB2PKiB7fT3GrjbTLcwETBkeEpcHywmf31YjZi5zLTEbq X-Received: by 2002:a50:9519:0:b0:558:72d1:b8ed with SMTP id u25-20020a509519000000b0055872d1b8edmr1327929eda.45.1705912660203; Mon, 22 Jan 2024 00:37:40 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705912660; cv=pass; d=google.com; s=arc-20160816; b=DEMsnkBkIzkk+Jdi33zlHsKcagSqK4H9mCcshyXKq1/yu/MRB79+iGaEo6QnkxlHkA T8yh4wRgxMY7ZT2ycA+SvT8eUNQcqfTFoHDupmnRS6ANoDHXrLoq1xE9fQMWo4fL2BcZ enPynZ9x9X6jaAJJalZfOc8jOwsf56+H0nFN5++BESYK0o5fTmw018n18cFT5/DkVJBA ax9AlMPDBUotbcA7+kgNVogU4Sc9taOjcQfOlaxlzGvfv/wl+yL3YoU/rvsFct0pi6H0 JEe7yrJBHPDSTdJMb7Ae8EGfvqn7U1jeVNWtr9JKU11Ey5Fgf20HJuE4VfXs8mROOF+a 26Yw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=Hw8AFYEmPdsZJn4Cv4H2yLbjk+0ueNo/x9k47CvSyfg=; fh=LjOQMBMhP1Y13Qw7w50qGHmWz8pprPOu2Waoa4Vg17A=; b=RVGdG/Z0qTQJ12L98LnQcalWD2lE2SjwjOtfvQhvpYxO6wxxwsPFujHxbMOLAfgC/l 5qem6CkeCg+jWBQEQZBYXjA5e6rLYbY8bSiVVGjhu6EXBDsQg8Wx9ARp7RBXNzk83Qfw T/o2tbfYJZ2/W0e70Z4mqMWllykYq+LrIWcLXCTA+U2QZ9gOIOWeGYZHaoWAnwfSbEYH kCwTuoNzA+lHq+9q3te9npcSTH74gpqBb248BugPDCI1R2HztdS4/9uJ742QKwAHB9dt ++WGv5LCk95amL2mIJfpZeLjSX+pyNPXvbj6EtSHl+TMjIdCuy+ebDYXqf1LxEEPjdgm q6kA== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=linux.alibaba.com dmarc=pass fromdomain=linux.alibaba.com); spf=pass (google.com: domain of linux-kernel+bounces-32531-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-32531-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id x3-20020a50d603000000b0055c0cd8db38si1648563edi.629.2024.01.22.00.37.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 00:37:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-32531-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=linux.alibaba.com dmarc=pass fromdomain=linux.alibaba.com); spf=pass (google.com: domain of linux-kernel+bounces-32531-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-32531-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id C7D511F22D31 for ; Mon, 22 Jan 2024 08:37:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 74683288DB; Mon, 22 Jan 2024 08:37:31 +0000 (UTC) Received: from out30-97.freemail.mail.aliyun.com (out30-97.freemail.mail.aliyun.com [115.124.30.97]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 771EE17C80 for ; Mon, 22 Jan 2024 08:37:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.97 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705912650; cv=none; b=pFZX6+Yn5VEvJo8BNPRsLuPBEj6r+E5vrD2ziyQSbhB0w4JVNzZqr0O4Y5hhujXzCWRGZP/n8HsiPNGrciv+5w2Ka54mbn3k0lwYextAG2Wnra2Not6EFOI2IZYIM9Y/HPRtmgrBhKmetRIlppt2Fv5DtOUYdAmYsoQH5tZzXko= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705912650; c=relaxed/simple; bh=GoV0jX5OP7TlSbxGOU/2lArwPKWg3tqVoToqOIxHjvs=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=CxnTFdSuYywcVuEYoJiRK88wnLvdChTok7OYH2+ZwXBvR0vf6m6RRe5+1JQNJut3JpKJhXGGhUW8MpwiHTg0BwQUcdORIK47TxqQiCJOOyMeTg03/jV567MboUadTUEPySXtcp9zbD/VfddmPvXCbgcmgypmEnJEZKcX21CsfEk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; arc=none smtp.client-ip=115.124.30.97 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R391e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046059;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0W.5LQ0x_1705912643; Received: from 30.221.145.129(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0W.5LQ0x_1705912643) by smtp.aliyun-inc.com; Mon, 22 Jan 2024 16:37:24 +0800 Message-ID: <99302340-731d-435f-ab9e-7a31fe86c95e@linux.alibaba.com> Date: Mon, 22 Jan 2024 16:37:23 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] erofs: make iov_iter describe target buffer when read from fscache Content-Language: en-US To: Gao Xiang , xiang@kernel.org, chao@kernel.org, linux-erofs@lists.ozlabs.org Cc: huyue2@coolpad.com, linux-kernel@vger.kernel.org References: <20240122071253.119004-1-jefflexu@linux.alibaba.com> From: Jingbo Xu In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Hi, Xiang, On 1/22/24 3:42 PM, Gao Xiang wrote: > Hi Jingbo, > > On 2024/1/22 15:12, Jingbo Xu wrote: >> So far the fscache mode supports uncompressed data only, and the data >> read from fscache is put directly into the target page cache.  As the >> support for compressed data in fscache mode is going to be introduced, >> refactor the interface of reading fscache so that the following >> compressed part could make the raw data read from fscache be directed to >> the target buffer it wants, decompress the raw data, and finally fill >> the page cache with the decompressed data. >> >> As the first step, a new structure, i.e. erofs_fscache_io (cio), is > > I'd suggest just using io instead of cio here. > > .. i.e. erofs_fscache_io (io) ... Thanks for the review, I will update the patch regarding all these comments. > >> introduced to describe a generic read request from the fscache, while >> the caller can specify the target buffer it wants in the iov_iter >> structure (cio->iter).  Besides, the caller can also specify its > > .. structure (io->iter) ... > >> completion callback and private data through cio, which will be called >> to make further handling, e.g. unlocking the page cache for uncompressed >> data or decompressing the read raw data, when the read request from the >> fscache completes.  Now erofs_fscache_read_io_async() serves as a >> generic interface for reading raw data from fscache for both compressed >> and uncompressed data. >> >> The erofs_fscache_request structure is kept to describe a request to >> fill the page cache in the specified range. >> >> Signed-off-by: Jingbo Xu >> --- >>   fs/erofs/fscache.c | 219 ++++++++++++++++++++++++--------------------- >>   1 file changed, 118 insertions(+), 101 deletions(-) >> >> diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c >> index bc12030393b2..10709f20bef5 100644 >> --- a/fs/erofs/fscache.c >> +++ b/fs/erofs/fscache.c >> @@ -13,8 +13,6 @@ static LIST_HEAD(erofs_domain_cookies_list); >>   static struct vfsmount *erofs_pseudo_mnt; >>     struct erofs_fscache_request { >> -    struct erofs_fscache_request *primary; >> -    struct netfs_cache_resources cache_resources; >>       struct address_space    *mapping;    /* The mapping being >> accessed */ >>       loff_t            start;        /* Start position */ >>       size_t            len;        /* Length of the request */ >> @@ -23,42 +21,13 @@ struct erofs_fscache_request { >>       refcount_t        ref; >>   }; >>   -static struct erofs_fscache_request *erofs_fscache_req_alloc(struct >> address_space *mapping, >> -                         loff_t start, size_t len) >> -{ >> -    struct erofs_fscache_request *req; >> - >> -    req = kzalloc(sizeof(struct erofs_fscache_request), GFP_KERNEL); >> -    if (!req) >> -        return ERR_PTR(-ENOMEM); >> - >> -    req->mapping = mapping; >> -    req->start   = start; >> -    req->len     = len; >> -    refcount_set(&req->ref, 1); >> - >> -    return req; >> -} >> - >> -static struct erofs_fscache_request *erofs_fscache_req_chain(struct >> erofs_fscache_request *primary, >> -                         size_t len) >> -{ >> -    struct erofs_fscache_request *req; >> - >> -    /* use primary request for the first submission */ >> -    if (!primary->submitted) { >> -        refcount_inc(&primary->ref); >> -        return primary; >> -    } >> - >> -    req = erofs_fscache_req_alloc(primary->mapping, >> -            primary->start + primary->submitted, len); >> -    if (!IS_ERR(req)) { >> -        req->primary = primary; >> -        refcount_inc(&primary->ref); >> -    } >> -    return req; >> -} >> +struct erofs_fscache_io { >> +    struct netfs_cache_resources cache_resources; > >     struct netfs_cache_resources cres; > >> +    struct iov_iter        iter; >> +    netfs_io_terminated_t    end_io; >> +    void            *private; >> +    refcount_t        ref; >> +}; >>     static void erofs_fscache_req_complete(struct >> erofs_fscache_request *req) >>   { >> @@ -83,82 +52,116 @@ static void erofs_fscache_req_complete(struct >> erofs_fscache_request *req) >>   static void erofs_fscache_req_put(struct erofs_fscache_request *req) >>   { >>       if (refcount_dec_and_test(&req->ref)) { >> -        if (req->cache_resources.ops) >> -            >> req->cache_resources.ops->end_operation(&req->cache_resources); >> -        if (!req->primary) >> -            erofs_fscache_req_complete(req); >> -        else >> -            erofs_fscache_req_put(req->primary); >> +        erofs_fscache_req_complete(req); >>           kfree(req); >>       } >>   } >>   -static void erofs_fscache_subreq_complete(void *priv, >> +static struct erofs_fscache_request *erofs_fscache_req_alloc(struct >> address_space *mapping, >> +                        loff_t start, size_t len) >> +{ >> +    struct erofs_fscache_request *req; >> + >> +    req = kzalloc(sizeof(*req), GFP_KERNEL); >> +    if (req) { >> +        req->mapping = mapping; >> +        req->start = start; >> +        req->len = len; >> +        refcount_set(&req->ref, 1); >> +    } >> +    return req; > > The following part may be better? to save an indentation: > >     req = kzalloc(sizeof(*req), GFP_KERNEL); >     if (!req) >         return NULL; >     req->mapping = mapping; >     req->start = start; >     req->len = len; >     refcount_set(&req->ref, 1); >     return req; > >> +} >> + >> +static bool erofs_fscache_io_put(struct erofs_fscache_io *cio) >> +{ >> +    if (refcount_dec_and_test(&cio->ref)) { >> +        if (cio->cache_resources.ops) >> +            >> cio->cache_resources.ops->end_operation(&cio->cache_resources); >> +        kfree(cio); >> +        return true; >> +    } >> +    return false; > > >     if (!refcount_dec_and_test(&io->ref)) >         return false; >     if (io->cres.ops) >         io->cres.ops->end_operation(&io->cres); >     kfree(io); >     return true; > >> +} >> + >> +static void erofs_fscache_req_io_put(struct erofs_fscache_io *cio) > > cio -> io > >> +{ >> +    struct erofs_fscache_request *req = cio->private; >> + >> +    if (erofs_fscache_io_put(cio)) >> +        erofs_fscache_req_put(req); >> +} >> + >> +static void erofs_fscache_req_end_io(void *priv, >>           ssize_t transferred_or_error, bool was_async) >>   { >> -    struct erofs_fscache_request *req = priv; >> +    struct erofs_fscache_io *cio = priv; >> +    struct erofs_fscache_request *req = cio->private; >> + >> +    if (IS_ERR(transferred_or_error)) >> +        req->error = transferred_or_error; >> +    erofs_fscache_req_io_put(cio); >> +} >> + >> +static struct erofs_fscache_io *erofs_fscache_req_io_alloc(struct >> erofs_fscache_request *req) >> +{ >> +    struct erofs_fscache_io *cio; >>   -    if (IS_ERR_VALUE(transferred_or_error)) { >> -        if (req->primary) >> -            req->primary->error = transferred_or_error; >> -        else >> -            req->error = transferred_or_error; >> +    cio = kzalloc(sizeof(*cio), GFP_KERNEL); >> +    if (cio) { >> +        cio->end_io = erofs_fscache_req_end_io; >> +        cio->private = req; >> +        refcount_inc(&req->ref); >> +        refcount_set(&cio->ref, 1); >>       } >> -    erofs_fscache_req_put(req); >> +    return cio; > > >     io = kzalloc(sizeof(*io), GFP_KERNEL); >     if (!io) >         return NULL; >     io->end_io = erofs_fscache_req_end_io; >     io->private = req; >     refcount_inc(&req->ref); >     refcount_set(&io->ref, 1); >     return io; > > Thanks, > Gao Xiang -- Thanks, Jingbo