All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jingbo Xu <jefflexu@linux.alibaba.com>
To: xiang@kernel.org, chao@kernel.org, linux-erofs@lists.ozlabs.org
Cc: linux-fsdevel@vger.kernel.org, huyue2@coolpad.com,
	linux-kernel@vger.kernel.org
Subject: [RFC PATCH 3/6] erofs: alloc anonymous file for blob in share domain mode
Date: Fri,  6 Jan 2023 20:53:27 +0800	[thread overview]
Message-ID: <20230106125330.55529-4-jefflexu@linux.alibaba.com> (raw)
In-Reply-To: <20230106125330.55529-1-jefflexu@linux.alibaba.com>

In prep for the following support for page cache sharing based mmap,
allocate an anonymous file for each blob, so that we can link
associated vma to blobs later.

Since page cache sharing will be enabled only for share domain mode,
prepare anonymous file only in share domain mode.

Signed-off-by: Jingbo Xu <jefflexu@linux.alibaba.com>
---
 fs/erofs/fscache.c  | 24 +++++++++++++++++++++++-
 fs/erofs/internal.h |  1 +
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c
index 4d7785a70926..ea276884f043 100644
--- a/fs/erofs/fscache.c
+++ b/fs/erofs/fscache.c
@@ -4,6 +4,8 @@
  * Copyright (C) 2022, Bytedance Inc. All rights reserved.
  */
 #include <linux/fscache.h>
+#include <linux/file.h>
+#include <linux/anon_inodes.h>
 #include "internal.h"
 
 static DEFINE_MUTEX(erofs_domain_list_lock);
@@ -316,6 +318,8 @@ const struct address_space_operations erofs_fscache_access_aops = {
 	.readahead = erofs_fscache_readahead,
 };
 
+static const struct file_operations erofs_fscache_meta_fops = {};
+
 static void erofs_fscache_domain_put(struct erofs_domain *domain)
 {
 	mutex_lock(&erofs_domain_list_lock);
@@ -428,6 +432,7 @@ struct erofs_fscache *erofs_fscache_acquire_cookie(struct super_block *sb,
 	struct fscache_cookie *cookie;
 	struct super_block *psb = sb;
 	struct inode *inode;
+	struct file *file;
 	int ret;
 
 	ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
@@ -457,10 +462,24 @@ struct erofs_fscache *erofs_fscache_acquire_cookie(struct super_block *sb,
 	mapping_set_gfp_mask(inode->i_mapping, GFP_NOFS);
 	inode->i_private = ctx;
 
+	if (EROFS_SB(sb)->domain_id) {
+		ihold(inode);
+		file = alloc_file_pseudo(inode, erofs_pseudo_mnt, "[erofs]",
+				O_RDONLY, &erofs_fscache_meta_fops);
+		if (IS_ERR(file)) {
+			ret = PTR_ERR(file);
+			iput(inode);
+			goto err_inode;
+		}
+		ctx->file = file;
+	}
+
 	ctx->cookie = cookie;
 	ctx->inode = inode;
 	return ctx;
 
+err_inode:
+	iput(inode);
 err_cookie:
 	fscache_unuse_cookie(cookie, NULL, NULL);
 	fscache_relinquish_cookie(cookie, false);
@@ -473,6 +492,8 @@ static void erofs_fscache_relinquish_cookie(struct erofs_fscache *ctx)
 {
 	fscache_unuse_cookie(ctx->cookie, NULL, NULL);
 	fscache_relinquish_cookie(ctx->cookie, false);
+	if (ctx->file)
+		fput(ctx->file);
 	iput(ctx->inode);
 	kfree(ctx->name);
 	kfree(ctx);
@@ -565,7 +586,8 @@ void erofs_fscache_unregister_cookie(struct erofs_fscache *ctx)
 		mutex_lock(&erofs_domain_cookies_lock);
 		/* drop the ref for the sentinel in pseudo mount */
 		iput(ctx->inode);
-		drop = atomic_read(&ctx->inode->i_count) == 1;
+		/* one initial ref, and one ref for anonymous file */
+		drop = atomic_read(&ctx->inode->i_count) == 2;
 		if (drop)
 			erofs_fscache_relinquish_cookie(ctx);
 		mutex_unlock(&erofs_domain_cookies_lock);
diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h
index b3d04bc2d279..24d471fe2fa4 100644
--- a/fs/erofs/internal.h
+++ b/fs/erofs/internal.h
@@ -109,6 +109,7 @@ struct erofs_domain {
 struct erofs_fscache {
 	struct fscache_cookie *cookie;
 	struct inode *inode;	/* anonymous indoe for the blob */
+	struct file *file;	/* anonymous file */
 	struct erofs_domain *domain;
 	char *name;
 };
-- 
2.19.1.6.gb485710b


WARNING: multiple messages have this Message-ID (diff)
From: Jingbo Xu <jefflexu@linux.alibaba.com>
To: xiang@kernel.org, chao@kernel.org, linux-erofs@lists.ozlabs.org
Cc: huyue2@coolpad.com, linux-kernel@vger.kernel.org,
	linux-fsdevel@vger.kernel.org
Subject: [RFC PATCH 3/6] erofs: alloc anonymous file for blob in share domain mode
Date: Fri,  6 Jan 2023 20:53:27 +0800	[thread overview]
Message-ID: <20230106125330.55529-4-jefflexu@linux.alibaba.com> (raw)
In-Reply-To: <20230106125330.55529-1-jefflexu@linux.alibaba.com>

In prep for the following support for page cache sharing based mmap,
allocate an anonymous file for each blob, so that we can link
associated vma to blobs later.

Since page cache sharing will be enabled only for share domain mode,
prepare anonymous file only in share domain mode.

Signed-off-by: Jingbo Xu <jefflexu@linux.alibaba.com>
---
 fs/erofs/fscache.c  | 24 +++++++++++++++++++++++-
 fs/erofs/internal.h |  1 +
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c
index 4d7785a70926..ea276884f043 100644
--- a/fs/erofs/fscache.c
+++ b/fs/erofs/fscache.c
@@ -4,6 +4,8 @@
  * Copyright (C) 2022, Bytedance Inc. All rights reserved.
  */
 #include <linux/fscache.h>
+#include <linux/file.h>
+#include <linux/anon_inodes.h>
 #include "internal.h"
 
 static DEFINE_MUTEX(erofs_domain_list_lock);
@@ -316,6 +318,8 @@ const struct address_space_operations erofs_fscache_access_aops = {
 	.readahead = erofs_fscache_readahead,
 };
 
+static const struct file_operations erofs_fscache_meta_fops = {};
+
 static void erofs_fscache_domain_put(struct erofs_domain *domain)
 {
 	mutex_lock(&erofs_domain_list_lock);
@@ -428,6 +432,7 @@ struct erofs_fscache *erofs_fscache_acquire_cookie(struct super_block *sb,
 	struct fscache_cookie *cookie;
 	struct super_block *psb = sb;
 	struct inode *inode;
+	struct file *file;
 	int ret;
 
 	ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
@@ -457,10 +462,24 @@ struct erofs_fscache *erofs_fscache_acquire_cookie(struct super_block *sb,
 	mapping_set_gfp_mask(inode->i_mapping, GFP_NOFS);
 	inode->i_private = ctx;
 
+	if (EROFS_SB(sb)->domain_id) {
+		ihold(inode);
+		file = alloc_file_pseudo(inode, erofs_pseudo_mnt, "[erofs]",
+				O_RDONLY, &erofs_fscache_meta_fops);
+		if (IS_ERR(file)) {
+			ret = PTR_ERR(file);
+			iput(inode);
+			goto err_inode;
+		}
+		ctx->file = file;
+	}
+
 	ctx->cookie = cookie;
 	ctx->inode = inode;
 	return ctx;
 
+err_inode:
+	iput(inode);
 err_cookie:
 	fscache_unuse_cookie(cookie, NULL, NULL);
 	fscache_relinquish_cookie(cookie, false);
@@ -473,6 +492,8 @@ static void erofs_fscache_relinquish_cookie(struct erofs_fscache *ctx)
 {
 	fscache_unuse_cookie(ctx->cookie, NULL, NULL);
 	fscache_relinquish_cookie(ctx->cookie, false);
+	if (ctx->file)
+		fput(ctx->file);
 	iput(ctx->inode);
 	kfree(ctx->name);
 	kfree(ctx);
@@ -565,7 +586,8 @@ void erofs_fscache_unregister_cookie(struct erofs_fscache *ctx)
 		mutex_lock(&erofs_domain_cookies_lock);
 		/* drop the ref for the sentinel in pseudo mount */
 		iput(ctx->inode);
-		drop = atomic_read(&ctx->inode->i_count) == 1;
+		/* one initial ref, and one ref for anonymous file */
+		drop = atomic_read(&ctx->inode->i_count) == 2;
 		if (drop)
 			erofs_fscache_relinquish_cookie(ctx);
 		mutex_unlock(&erofs_domain_cookies_lock);
diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h
index b3d04bc2d279..24d471fe2fa4 100644
--- a/fs/erofs/internal.h
+++ b/fs/erofs/internal.h
@@ -109,6 +109,7 @@ struct erofs_domain {
 struct erofs_fscache {
 	struct fscache_cookie *cookie;
 	struct inode *inode;	/* anonymous indoe for the blob */
+	struct file *file;	/* anonymous file */
 	struct erofs_domain *domain;
 	char *name;
 };
-- 
2.19.1.6.gb485710b


  parent reply	other threads:[~2023-01-06 12:58 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-06 12:53 [RFC PATCH 0/6] erofs: support page cache sharing between EROFS images in fscache mode Jingbo Xu
2023-01-06 12:53 ` Jingbo Xu
2023-01-06 12:53 ` [RFC PATCH 1/6] erofs: remove unused device mapping in the meta routine Jingbo Xu
2023-01-06 12:53   ` Jingbo Xu
2023-01-06 12:53 ` [RFC PATCH 2/6] erofs: unify anonymous inodes for blob Jingbo Xu
2023-01-06 12:53   ` Jingbo Xu
2023-01-06 12:53 ` Jingbo Xu [this message]
2023-01-06 12:53   ` [RFC PATCH 3/6] erofs: alloc anonymous file for blob in share domain mode Jingbo Xu
2023-01-06 12:53 ` [RFC PATCH 4/6] erofs: implement .read_iter for page cache sharing Jingbo Xu
2023-01-06 12:53   ` Jingbo Xu
2023-01-06 12:53 ` [RFC PATCH 5/6] erofs: implement .mmap " Jingbo Xu
2023-01-06 12:53   ` Jingbo Xu
2023-01-06 12:53 ` [RFC PATCH 6/6] erofs: enable page cache sharing in fscache mode Jingbo Xu
2023-01-06 12:53   ` Jingbo Xu
2023-01-19  8:54   ` kernel test robot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230106125330.55529-4-jefflexu@linux.alibaba.com \
    --to=jefflexu@linux.alibaba.com \
    --cc=chao@kernel.org \
    --cc=huyue2@coolpad.com \
    --cc=linux-erofs@lists.ozlabs.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=xiang@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.