linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Damien Le Moal <damien.lemoal@opensource.wdc.com>
To: linux-fsdevel@vger.kernel.org
Cc: Johannes Thumshirn <johannes.thumshirn@wdc.com>,
	Jorgen Hansen <Jorgen.Hansen@wdc.com>
Subject: [PATCH 7/7] zonefs: Cache zone group directory inodes
Date: Tue, 10 Jan 2023 22:08:30 +0900	[thread overview]
Message-ID: <20230110130830.246019-8-damien.lemoal@opensource.wdc.com> (raw)
In-Reply-To: <20230110130830.246019-1-damien.lemoal@opensource.wdc.com>

Since looking up any zone file inode requires looking up first the inode
for the directory representing the zone group of the file, ensuring that
the zone group inodes are always cached is desired. To do so, take an
extra reference on the zone groups directory inodes on mount, thus
avoiding the eviction of these inodes from the inode cache until the
volume is unmounted.

Signed-off-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>
---
 fs/zonefs/super.c  | 48 ++++++++++++++++++++++++++++++++++++++++++++++
 fs/zonefs/zonefs.h |  1 +
 2 files changed, 49 insertions(+)

diff --git a/fs/zonefs/super.c b/fs/zonefs/super.c
index 7d70c327883e..010b53545e5b 100644
--- a/fs/zonefs/super.c
+++ b/fs/zonefs/super.c
@@ -1199,6 +1199,42 @@ static const struct super_operations zonefs_sops = {
 	.show_options	= zonefs_show_options,
 };
 
+static int zonefs_get_zgroup_inodes(struct super_block *sb)
+{
+	struct zonefs_sb_info *sbi = ZONEFS_SB(sb);
+	struct inode *dir_inode;
+	enum zonefs_ztype ztype;
+
+	for (ztype = 0; ztype < ZONEFS_ZTYPE_MAX; ztype++) {
+		if (!sbi->s_zgroup[ztype].g_nr_zones)
+			continue;
+
+		dir_inode = zonefs_get_zgroup_inode(sb, ztype);
+		if (IS_ERR(dir_inode))
+			return PTR_ERR(dir_inode);
+
+		sbi->s_zgroup[ztype].g_inode = dir_inode;
+	}
+
+	return 0;
+}
+
+static void zonefs_release_zgroup_inodes(struct super_block *sb)
+{
+	struct zonefs_sb_info *sbi = ZONEFS_SB(sb);
+	enum zonefs_ztype ztype;
+
+	if (!sbi)
+		return;
+
+	for (ztype = 0; ztype < ZONEFS_ZTYPE_MAX; ztype++) {
+		if (sbi->s_zgroup[ztype].g_inode) {
+			iput(sbi->s_zgroup[ztype].g_inode);
+			sbi->s_zgroup[ztype].g_inode = NULL;
+		}
+	}
+}
+
 /*
  * Check that the device is zoned. If it is, get the list of zones and create
  * sub-directories and files according to the device zone configuration and
@@ -1297,6 +1333,14 @@ static int zonefs_fill_super(struct super_block *sb, void *data, int silent)
 	if (!sb->s_root)
 		goto cleanup;
 
+	/*
+	 * Take a reference on the zone groups directory inodes
+	 * to keep them in the inode cache.
+	 */
+	ret = zonefs_get_zgroup_inodes(sb);
+	if (ret)
+		goto cleanup;
+
 	ret = zonefs_sysfs_register(sb);
 	if (ret)
 		goto cleanup;
@@ -1304,6 +1348,7 @@ static int zonefs_fill_super(struct super_block *sb, void *data, int silent)
 	return 0;
 
 cleanup:
+	zonefs_release_zgroup_inodes(sb);
 	zonefs_free_zgroups(sb);
 
 	return ret;
@@ -1319,6 +1364,9 @@ static void zonefs_kill_super(struct super_block *sb)
 {
 	struct zonefs_sb_info *sbi = ZONEFS_SB(sb);
 
+	/* Release the reference on the zone group directory inodes */
+	zonefs_release_zgroup_inodes(sb);
+
 	kill_block_super(sb);
 
 	zonefs_sysfs_unregister(sb);
diff --git a/fs/zonefs/zonefs.h b/fs/zonefs/zonefs.h
index f88466a4158b..8175652241b5 100644
--- a/fs/zonefs/zonefs.h
+++ b/fs/zonefs/zonefs.h
@@ -76,6 +76,7 @@ struct zonefs_zone {
  * as files, one file per zone.
  */
 struct zonefs_zone_group {
+	struct inode		*g_inode;
 	unsigned int		g_nr_zones;
 	struct zonefs_zone	*g_zones;
 };
-- 
2.39.0


  parent reply	other threads:[~2023-01-10 13:08 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-10 13:08 [PATCH 0/7] Reduce zonefs memory usage Damien Le Moal
2023-01-10 13:08 ` [PATCH 1/7] zonefs: Detect append writes at invalid locations Damien Le Moal
2023-01-11 12:23   ` Johannes Thumshirn
2023-01-11 22:08     ` Damien Le Moal
2023-01-12  5:18       ` Damien Le Moal
2023-01-12  7:33         ` Johannes Thumshirn
2023-01-12  8:26           ` Damien Le Moal
2023-01-10 13:08 ` [PATCH 2/7] zonefs: Reorganize code Damien Le Moal
2023-01-11 16:12   ` Johannes Thumshirn
2023-01-10 13:08 ` [PATCH 3/7] zonefs: Simplify IO error handling Damien Le Moal
2023-01-13 10:09   ` Johannes Thumshirn
2023-01-10 13:08 ` [PATCH 4/7] zonefs: Reduce struct zonefs_inode_info size Damien Le Moal
2023-01-13 10:11   ` Johannes Thumshirn
2023-01-10 13:08 ` [PATCH 5/7] zonefs: Separate zone information from inode information Damien Le Moal
2023-01-13 11:30   ` Johannes Thumshirn
2023-01-10 13:08 ` [PATCH 6/7] zonefs: Dynamically create file inodes when needed Damien Le Moal
2023-01-16 11:46   ` Johannes Thumshirn
2023-01-16 12:17     ` Damien Le Moal
2023-01-10 13:08 ` Damien Le Moal [this message]
2023-01-16 11:49   ` [PATCH 7/7] zonefs: Cache zone group directory inodes Johannes Thumshirn

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=20230110130830.246019-8-damien.lemoal@opensource.wdc.com \
    --to=damien.lemoal@opensource.wdc.com \
    --cc=Jorgen.Hansen@wdc.com \
    --cc=johannes.thumshirn@wdc.com \
    --cc=linux-fsdevel@vger.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).