From nobody Fri Apr 3 03:53:24 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 38635C32771 for ; Sun, 18 Sep 2022 04:35:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229458AbiIREfg (ORCPT ); Sun, 18 Sep 2022 00:35:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229632AbiIREfM (ORCPT ); Sun, 18 Sep 2022 00:35:12 -0400 Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53096167E5 for ; Sat, 17 Sep 2022 21:35:11 -0700 (PDT) Received: by mail-pj1-x1033.google.com with SMTP id q62-20020a17090a17c400b00202a3497516so3156519pja.1 for ; Sat, 17 Sep 2022 21:35:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=Zz/+Lsdw1NAyt93VpvNl+aPHSPA2CVkBmnUTlKe09/0=; b=Vpal278u2LJ58CGPsEPXqpT0AKbQZCricS4GhbO5+/GBcyr4GKzoi5Qa9e5QNMO2pf w2lPfIK28i3YkAuuaj2/4CImxJf8O6kumBc1rKMr06vxh+8zIdP96KGV3t74Ww5hf+fy v1vBmYRqADaDd+/Hh0QGVTHhkBhEWOTkKg1hBXK5ZjrKikjwBc2Q+jjPIPz37RCZOiuz jPMgcqNZ1AY9dPLgeqdTNrgrWIuoRV69eib0jXc6UUAXSwEkb7bFdeC3RqXyrtWCDhFq wuuvvL6Kr11VxV7fYvzIjSGciTRSuykd65Shkt00XCHD03XFz2LF9RJ4WpE235AxUNXH ERKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=Zz/+Lsdw1NAyt93VpvNl+aPHSPA2CVkBmnUTlKe09/0=; b=pFGLnQe90CBzR0T876bC2oZoOly42V1LQ0DdjdGaRV+U8m8i8TwEVaVssFALRZoGhG F9qvIQl1BNFMh9UNAUqcUetqse5zSQA4EO2aoFaaPYQCjsjXW3i7MU5Sln3Lc4LdsPcK kd03O+M90lVhjzGY6qpyTKjuGmSmesPbMrdWmyTcbjvpbhCKa6W+GqCCokndBWN1cDuo aFHUZkEgegYXlua+NA94fQuodI46w1y9l7VDex0sjHC/lxl2wvk+Wp+g7W45oYyq8mpY Tu97tQYr6BqCapa8GvNkQP70e+wTlrAWIXZNrSKzEUMyZhI+MnoJxywwxbdSUKfFFnaN Vikw== X-Gm-Message-State: ACrzQf3vzTmyU/fBGCLlO3GfDSzDD93zT6RBdOU3kL6BCHcFXuBnQ5Xu oEx/V32ADzw3rZWpAb2fiDhpdeEl47rCwCK7 X-Google-Smtp-Source: AMsMyM6u/ABaKXp7fzLz3VnxEa03VfPh5BNRwHrMVloqKWw4UuRDLgvkR1FkRwo9HxTCHp1mCYkz6Q== X-Received: by 2002:a17:903:1cc:b0:178:44cd:e9e with SMTP id e12-20020a17090301cc00b0017844cd0e9emr7132332plh.158.1663475710647; Sat, 17 Sep 2022 21:35:10 -0700 (PDT) Received: from localhost.localdomain ([111.201.134.95]) by smtp.gmail.com with ESMTPSA id l63-20020a622542000000b0054b5239f7fesm3955248pfl.210.2022.09.17.21.35.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Sep 2022 21:35:10 -0700 (PDT) From: Jia Zhu To: linux-erofs@lists.ozlabs.org Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, yinxin.x@bytedance.com, jefflexu@linux.alibaba.com, Jia Zhu Subject: [PATCH V6 3/6] erofs: introduce fscache-based domain Date: Sun, 18 Sep 2022 12:34:53 +0800 Message-Id: <20220918043456.147-4-zhujia.zj@bytedance.com> X-Mailer: git-send-email 2.37.0 (Apple Git-136) In-Reply-To: <20220918043456.147-1-zhujia.zj@bytedance.com> References: <20220918043456.147-1-zhujia.zj@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" A new fscache-based shared domain mode is going to be introduced for erofs. In which case, same data blobs in same domain will be shared and reused to reduce on-disk space usage. The implementation of sharing blobs will be introduced in subsequent patches. Signed-off-by: Jia Zhu Reviewed-by: Jingbo Xu --- fs/erofs/fscache.c | 129 ++++++++++++++++++++++++++++++++++++++------ fs/erofs/internal.h | 9 ++++ 2 files changed, 121 insertions(+), 17 deletions(-) diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c index d3a90103abb7..9c82284e66ee 100644 --- a/fs/erofs/fscache.c +++ b/fs/erofs/fscache.c @@ -1,10 +1,14 @@ // SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (C) 2022, Alibaba Cloud + * Copyright (C) 2022, Bytedance Inc. All rights reserved. */ #include #include "internal.h" =20 +static DEFINE_MUTEX(erofs_domain_list_lock); +static LIST_HEAD(erofs_domain_list); + static struct netfs_io_request *erofs_fscache_alloc_request(struct address= _space *mapping, loff_t start, size_t len) { @@ -417,6 +421,99 @@ const struct address_space_operations erofs_fscache_ac= cess_aops =3D { .readahead =3D erofs_fscache_readahead, }; =20 +static void erofs_fscache_domain_put(struct erofs_domain *domain) +{ + if (!domain) + return; + mutex_lock(&erofs_domain_list_lock); + if (refcount_dec_and_test(&domain->ref)) { + list_del(&domain->list); + mutex_unlock(&erofs_domain_list_lock); + fscache_relinquish_volume(domain->volume, NULL, false); + kfree(domain->domain_id); + kfree(domain); + return; + } + mutex_unlock(&erofs_domain_list_lock); +} + +static int erofs_fscache_register_volume(struct super_block *sb) +{ + struct erofs_sb_info *sbi =3D EROFS_SB(sb); + char *domain_id =3D sbi->opt.domain_id; + struct fscache_volume *volume; + char *name; + int ret =3D 0; + + name =3D kasprintf(GFP_KERNEL, "erofs,%s", + domain_id ? domain_id : sbi->opt.fsid); + if (!name) + return -ENOMEM; + + volume =3D fscache_acquire_volume(name, NULL, NULL, 0); + if (IS_ERR_OR_NULL(volume)) { + erofs_err(sb, "failed to register volume for %s", name); + ret =3D volume ? PTR_ERR(volume) : -EOPNOTSUPP; + volume =3D NULL; + } + + sbi->volume =3D volume; + kfree(name); + return ret; +} + +static int erofs_fscache_init_domain(struct super_block *sb) +{ + int err; + struct erofs_domain *domain; + struct erofs_sb_info *sbi =3D EROFS_SB(sb); + + domain =3D kzalloc(sizeof(struct erofs_domain), GFP_KERNEL); + if (!domain) + return -ENOMEM; + + domain->domain_id =3D kstrdup(sbi->opt.domain_id, GFP_KERNEL); + if (!domain->domain_id) { + kfree(domain); + return -ENOMEM; + } + + err =3D erofs_fscache_register_volume(sb); + if (err) + goto out; + + domain->volume =3D sbi->volume; + refcount_set(&domain->ref, 1); + list_add(&domain->list, &erofs_domain_list); + sbi->domain =3D domain; + return 0; +out: + kfree(domain->domain_id); + kfree(domain); + return err; +} + +static int erofs_fscache_register_domain(struct super_block *sb) +{ + int err; + struct erofs_domain *domain; + struct erofs_sb_info *sbi =3D EROFS_SB(sb); + + mutex_lock(&erofs_domain_list_lock); + list_for_each_entry(domain, &erofs_domain_list, list) { + if (!strcmp(domain->domain_id, sbi->opt.domain_id)) { + sbi->domain =3D domain; + sbi->volume =3D domain->volume; + refcount_inc(&domain->ref); + mutex_unlock(&erofs_domain_list_lock); + return 0; + } + } + err =3D erofs_fscache_init_domain(sb); + mutex_unlock(&erofs_domain_list_lock); + return err; +} + struct erofs_fscache *erofs_fscache_register_cookie(struct super_block *sb, char *name, bool need_inode) { @@ -480,27 +577,19 @@ void erofs_fscache_unregister_cookie(struct erofs_fsc= ache *ctx) =20 int erofs_fscache_register_fs(struct super_block *sb) { + int ret; struct erofs_sb_info *sbi =3D EROFS_SB(sb); - struct fscache_volume *volume; struct erofs_fscache *fscache; - char *name; - - name =3D kasprintf(GFP_KERNEL, "erofs,%s", sbi->opt.fsid); - if (!name) - return -ENOMEM; =20 - volume =3D fscache_acquire_volume(name, NULL, NULL, 0); - if (IS_ERR_OR_NULL(volume)) { - erofs_err(sb, "failed to register volume for %s", name); - kfree(name); - return volume ? PTR_ERR(volume) : -EOPNOTSUPP; - } - - sbi->volume =3D volume; - kfree(name); + if (sbi->opt.domain_id) + ret =3D erofs_fscache_register_domain(sb); + else + ret =3D erofs_fscache_register_volume(sb); + if (ret) + return ret; =20 + /* acquired domain/volume will be relinquished in kill_sb() on error */ fscache =3D erofs_fscache_register_cookie(sb, sbi->opt.fsid, true); - /* acquired volume will be relinquished in kill_sb() */ if (IS_ERR(fscache)) return PTR_ERR(fscache); =20 @@ -513,7 +602,13 @@ void erofs_fscache_unregister_fs(struct super_block *s= b) struct erofs_sb_info *sbi =3D EROFS_SB(sb); =20 erofs_fscache_unregister_cookie(sbi->s_fscache); - fscache_relinquish_volume(sbi->volume, NULL, false); + + if (sbi->domain) + erofs_fscache_domain_put(sbi->domain); + else + fscache_relinquish_volume(sbi->volume, NULL, false); + sbi->s_fscache =3D NULL; sbi->volume =3D NULL; + sbi->domain =3D NULL; } diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h index b36850dd7813..4c11313a072f 100644 --- a/fs/erofs/internal.h +++ b/fs/erofs/internal.h @@ -76,6 +76,7 @@ struct erofs_mount_opts { #endif unsigned int mount_opt; char *fsid; + char *domain_id; }; =20 struct erofs_dev_context { @@ -98,6 +99,13 @@ struct erofs_sb_lz4_info { u16 max_pclusterblks; }; =20 +struct erofs_domain { + refcount_t ref; + struct list_head list; + struct fscache_volume *volume; + char *domain_id; +}; + struct erofs_fscache { struct fscache_cookie *cookie; struct inode *inode; @@ -157,6 +165,7 @@ struct erofs_sb_info { /* fscache support */ struct fscache_volume *volume; struct erofs_fscache *s_fscache; + struct erofs_domain *domain; }; =20 #define EROFS_SB(sb) ((struct erofs_sb_info *)(sb)->s_fs_info) --=20 2.20.1