Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp898526pxp; Wed, 16 Mar 2022 20:34:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzTe2W8sm4ZYg7lu2V7id4HpYz2b+GkQjxeYLvzmHPiX7bA4xTkbJHpp0csU4RR1Xh7bAmh X-Received: by 2002:a65:5583:0:b0:380:d91a:8270 with SMTP id j3-20020a655583000000b00380d91a8270mr2112650pgs.620.1647488096572; Wed, 16 Mar 2022 20:34:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647488096; cv=none; d=google.com; s=arc-20160816; b=Syps1yYhfZDkksvM5fG8v3nxONxpzIyko6UsEfPioeICtC1W+PWG6U7dj4draHoZvP HxMwegdhdZBuHKZi377zH5+XMBRpHZ9aDgS2Imf5VlR99W0SZsrxh/fYiadJopvt34D2 8sYowkRyoQb+iDqQ5QlcRytNwH0xEL+ly1pmSt9acHoR8TTYRH4g0ZRGZPUwPqdmM/vO k05YyV+VPqTSIEIPLL6AVpV8PQuSOgXfum7FgD7AHFjmnku08TYQp3tk6nGkN0X2OECR IQYSiqbjYznnOA8Dc9dHf3txaX8N+tGlFYlPkKckcwZoCW5B/egYMoONVA9eG6Xsod7A qFJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=e2Qm+c+TwVmF6Esola2828tt2xzAotAtCM3cr/gYuKM=; b=ymimNrHYVuFQzmJTXJDK3ULRTLHa3BJibAcxd6q6moXZ7mw8d0bLHNfk2lm8381OZN qI5o3JwDFDZP8zACKYqOdpryziLh44eU72X3H8BYQ7sNpWJZVWnes9zRJyVkuiP7BHor tIy02UAnoq/GUVSmS7dKlu2x1rT9Sfq50mygkVXR+SmScEA+2n/S5DBaR2gEOA+1h1p0 nqFtpUPs6XkCVz7jL5//aixIJryg4z+RINPxjd+d+mUyIrstXqlLOOxVgyxjeUvHsTBa a5yrrB7tzPQ1tGNzFNJyGiPrcyqnAC59oVHfD7McLxbrYZNyPKOkYeJXGd0WO3E3whhg d50w== 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:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id d21-20020a056a00199500b004f7ac1c2db6si3702605pfl.348.2022.03.16.20.34.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Mar 2022 20:34:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 664E749C89; Wed, 16 Mar 2022 20:30:33 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356302AbiCPNTg (ORCPT + 99 others); Wed, 16 Mar 2022 09:19:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356235AbiCPNTB (ORCPT ); Wed, 16 Mar 2022 09:19:01 -0400 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 EC5A2184; Wed, 16 Mar 2022 06:17:46 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R491e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04423;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=16;SR=0;TI=SMTPD_---0V7NEPqi_1647436663; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0V7NEPqi_1647436663) by smtp.aliyun-inc.com(127.0.0.1); Wed, 16 Mar 2022 21:17:43 +0800 From: Jeffle Xu To: dhowells@redhat.com, linux-cachefs@redhat.com, xiang@kernel.org, chao@kernel.org, linux-erofs@lists.ozlabs.org Cc: torvalds@linux-foundation.org, gregkh@linuxfoundation.org, willy@infradead.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 Subject: [PATCH v5 13/22] erofs: add anonymous inode managing page cache of blob file Date: Wed, 16 Mar 2022 21:17:14 +0800 Message-Id: <20220316131723.111553-14-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220316131723.111553-1-jefflexu@linux.alibaba.com> References: <20220316131723.111553-1-jefflexu@linux.alibaba.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY autolearn=no 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 Introduce one anonymous inode for managing page cache of corresponding blob file. Then erofs could read directly from the address space of the anonymous inode when cache hit. Signed-off-by: Jeffle Xu --- fs/erofs/fscache.c | 45 ++++++++++++++++++++++++++++++++++++++++++--- fs/erofs/internal.h | 3 ++- 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c index 28ec7c69744a..684ac6f940bc 100644 --- a/fs/erofs/fscache.c +++ b/fs/erofs/fscache.c @@ -6,6 +6,9 @@ static struct fscache_volume *volume; +static const struct address_space_operations erofs_fscache_blob_aops = { +}; + static int erofs_fscache_init_cookie(struct erofs_fscache_context *ctx, char *path) { @@ -32,8 +35,34 @@ void erofs_fscache_cleanup_cookie(struct erofs_fscache_context *ctx) ctx->cookie = NULL; } +static int erofs_fscache_get_inode(struct erofs_fscache_context *ctx, + struct super_block *sb) +{ + struct inode *const inode = new_inode(sb); + + if (!inode) + return -ENOMEM; + + set_nlink(inode, 1); + inode->i_size = OFFSET_MAX; + + inode->i_mapping->a_ops = &erofs_fscache_blob_aops; + mapping_set_gfp_mask(inode->i_mapping, + GFP_NOFS | __GFP_HIGHMEM | __GFP_MOVABLE); + ctx->inode = inode; + return 0; +} + +static inline +void erofs_fscache_put_inode(struct erofs_fscache_context *ctx) +{ + iput(ctx->inode); + ctx->inode = NULL; +} + static int erofs_fscache_init_ctx(struct erofs_fscache_context *ctx, - struct super_block *sb, char *path) + struct super_block *sb, char *path, + bool need_inode) { int ret; @@ -43,6 +72,15 @@ static int erofs_fscache_init_ctx(struct erofs_fscache_context *ctx, return ret; } + if (need_inode) { + ret = erofs_fscache_get_inode(ctx, sb); + if (ret) { + erofs_err(sb, "failed to get anonymous inode"); + erofs_fscache_cleanup_cookie(ctx); + return ret; + } + } + return 0; } @@ -50,10 +88,11 @@ static inline void erofs_fscache_cleanup_ctx(struct erofs_fscache_context *ctx) { erofs_fscache_cleanup_cookie(ctx); + erofs_fscache_put_inode(ctx); } struct erofs_fscache_context *erofs_fscache_get_ctx(struct super_block *sb, - char *path) + char *path, bool need_inode) { struct erofs_fscache_context *ctx; int ret; @@ -62,7 +101,7 @@ struct erofs_fscache_context *erofs_fscache_get_ctx(struct super_block *sb, if (!ctx) return ERR_PTR(-ENOMEM); - ret = erofs_fscache_init_ctx(ctx, sb, path); + ret = erofs_fscache_init_ctx(ctx, sb, path, need_inode); if (ret) { kfree(ctx); return ERR_PTR(ret); diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h index 123a8dfc179b..32aaa5ee5e14 100644 --- a/fs/erofs/internal.h +++ b/fs/erofs/internal.h @@ -99,6 +99,7 @@ struct erofs_sb_lz4_info { struct erofs_fscache_context { struct fscache_cookie *cookie; + struct inode *inode; }; struct erofs_sb_info { @@ -626,7 +627,7 @@ int erofs_init_fscache(void); void erofs_exit_fscache(void); struct erofs_fscache_context *erofs_fscache_get_ctx(struct super_block *sb, - char *path); + char *path, bool need_inode); void erofs_fscache_put_ctx(struct erofs_fscache_context *ctx); #define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */ -- 2.27.0