linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Gao Xiang <gaoxiang25@huawei.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	<devel@driverdev.osuosl.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
	<linux-erofs@lists.ozlabs.org>, "Chao Yu" <chao@kernel.org>,
	Miao Xie <miaoxie@huawei.com>, <weidu.du@huawei.com>,
	Fang Wei <fangwei1@huawei.com>, Gao Xiang <gaoxiang25@huawei.com>
Subject: [PATCH 09/22] staging: erofs: clean up shrinker stuffs
Date: Mon, 29 Jul 2019 14:51:46 +0800	[thread overview]
Message-ID: <20190729065159.62378-10-gaoxiang25@huawei.com> (raw)
In-Reply-To: <20190729065159.62378-1-gaoxiang25@huawei.com>

- rename erofs_register_super / erofs_unregister_super
  to erofs_shrinker_register / erofs_shrinker_unregister;
- fold the only erofs_shrink_workstation external call
  to erofs_shrinker_unregister;
- localize erofs_shrink_workstation;
- localize erofs_shrinker_info by introducing
  erofs_init_shrinker and erofs_exit_shrinker.

Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
---
 drivers/staging/erofs/internal.h | 50 +++++++++++++++++---------------
 drivers/staging/erofs/super.c    | 20 ++++---------
 drivers/staging/erofs/utils.c    | 37 +++++++++++++++--------
 3 files changed, 56 insertions(+), 51 deletions(-)

diff --git a/drivers/staging/erofs/internal.h b/drivers/staging/erofs/internal.h
index 58b8bb9cbb9f..c082a462baf6 100644
--- a/drivers/staging/erofs/internal.h
+++ b/drivers/staging/erofs/internal.h
@@ -72,34 +72,35 @@ typedef u64 erofs_off_t;
 typedef u32 erofs_blk_t;
 
 struct erofs_sb_info {
+#ifdef CONFIG_EROFS_FS_ZIP
 	/* list for all registered superblocks, mainly for shrinker */
 	struct list_head list;
 	struct mutex umount_mutex;
 
-	u32 blocks;
-	u32 meta_blkaddr;
-#ifdef CONFIG_EROFS_FS_XATTR
-	u32 xattr_blkaddr;
-#endif
-
-	/* inode slot unit size in bit shift */
-	unsigned char islotbits;
-#ifdef CONFIG_EROFS_FS_ZIP
 	/* cluster size in bit shift */
 	unsigned char clusterbits;
-
 	/* the dedicated workstation for compression */
 	struct radix_tree_root workstn_tree;
 
 	/* threshold for decompression synchronously */
 	unsigned int max_sync_decompress_pages;
 
+	unsigned int shrinker_run_no;
+
 #ifdef EROFS_FS_HAS_MANAGED_CACHE
 	struct inode *managed_cache;
 #endif
 
+#endif	/* CONFIG_EROFS_FS_ZIP */
+	u32 blocks;
+	u32 meta_blkaddr;
+#ifdef CONFIG_EROFS_FS_XATTR
+	u32 xattr_blkaddr;
 #endif
 
+	/* inode slot unit size in bit shift */
+	unsigned char islotbits;
+
 	u32 build_time_nsec;
 	u64 build_time;
 
@@ -115,7 +116,6 @@ struct erofs_sb_info {
 	char *dev_name;
 
 	unsigned int mount_opt;
-	unsigned int shrinker_run_no;
 
 #ifdef CONFIG_EROFS_FAULT_INJECTION
 	struct erofs_fault_info fault_info;	/* For fault injection */
@@ -246,13 +246,6 @@ static inline int erofs_wait_on_workgroup_freezed(struct erofs_workgroup *grp)
 	return v;
 }
 #endif
-
-int __init z_erofs_init_zip_subsystem(void);
-void z_erofs_exit_zip_subsystem(void);
-#else
-/* dummy initializer/finalizer for the decompression subsystem */
-static inline int z_erofs_init_zip_subsystem(void) { return 0; }
-static inline void z_erofs_exit_zip_subsystem(void) {}
 #endif	/* CONFIG_EROFS_FS_ZIP */
 
 /* we strictly follow PAGE_SIZE and no buffer head yet */
@@ -526,8 +519,6 @@ int erofs_namei(struct inode *dir, struct qstr *name,
 extern const struct file_operations erofs_dir_fops;
 
 /* utils.c / zdata.c */
-extern struct shrinker erofs_shrinker_info;
-
 struct page *erofs_allocpage(struct list_head *pool, gfp_t gfp);
 
 #if (EROFS_PCPUBUF_NR_PAGES > 0)
@@ -545,20 +536,31 @@ static inline void *erofs_get_pcpubuf(unsigned int pagenr)
 #define erofs_put_pcpubuf(buf) do {} while (0)
 #endif
 
+#ifdef CONFIG_EROFS_FS_ZIP
 int erofs_workgroup_put(struct erofs_workgroup *grp);
 struct erofs_workgroup *erofs_find_workgroup(struct super_block *sb,
 					     pgoff_t index, bool *tag);
 int erofs_register_workgroup(struct super_block *sb,
 			     struct erofs_workgroup *grp, bool tag);
-unsigned long erofs_shrink_workstation(struct erofs_sb_info *sbi,
-				       unsigned long nr_shrink, bool cleanup);
 void erofs_workgroup_free_rcu(struct erofs_workgroup *grp);
+void erofs_shrinker_register(struct super_block *sb);
+void erofs_shrinker_unregister(struct super_block *sb);
+int __init erofs_init_shrinker(void);
+void erofs_exit_shrinker(void);
+int __init z_erofs_init_zip_subsystem(void);
+void z_erofs_exit_zip_subsystem(void);
 int erofs_try_to_free_all_cached_pages(struct erofs_sb_info *sbi,
 				       struct erofs_workgroup *egrp);
 int erofs_try_to_free_cached_page(struct address_space *mapping,
 				  struct page *page);
-void erofs_register_super(struct super_block *sb);
-void erofs_unregister_super(struct super_block *sb);
+#else
+static inline void erofs_shrinker_register(struct super_block *sb) {}
+static inline void erofs_shrinker_unregister(struct super_block *sb) {}
+static inline int erofs_init_shrinker(void) { return 0; }
+static inline void erofs_exit_shrinker(void) {}
+static inline int z_erofs_init_zip_subsystem(void) { return 0; }
+static inline void z_erofs_exit_zip_subsystem(void) {}
+#endif
 
 #endif	/* __EROFS_INTERNAL_H */
 
diff --git a/drivers/staging/erofs/super.c b/drivers/staging/erofs/super.c
index c20a94b035a7..7e6fe9cd45e7 100644
--- a/drivers/staging/erofs/super.c
+++ b/drivers/staging/erofs/super.c
@@ -458,7 +458,7 @@ static int erofs_read_super(struct super_block *sb,
 	snprintf(sbi->dev_name, PATH_MAX, "%s", dev_name);
 	sbi->dev_name[PATH_MAX - 1] = '\0';
 
-	erofs_register_super(sb);
+	erofs_shrinker_register(sb);
 
 	if (!silent)
 		infoln("mounted on %s with opts: %s.", dev_name,
@@ -502,20 +502,10 @@ static void erofs_put_super(struct super_block *sb)
 	infoln("unmounted for %s", sbi->dev_name);
 	__putname(sbi->dev_name);
 
+	erofs_shrinker_unregister(sb);
 #ifdef EROFS_FS_HAS_MANAGED_CACHE
 	iput(sbi->managed_cache);
 #endif
-
-	mutex_lock(&sbi->umount_mutex);
-
-#ifdef CONFIG_EROFS_FS_ZIP
-	/* clean up the compression space of this sb */
-	erofs_shrink_workstation(EROFS_SB(sb), ~0UL, true);
-#endif
-
-	erofs_unregister_super(sb);
-	mutex_unlock(&sbi->umount_mutex);
-
 	kfree(sbi);
 	sb->s_fs_info = NULL;
 }
@@ -569,7 +559,7 @@ static int __init erofs_module_init(void)
 	if (err)
 		goto icache_err;
 
-	err = register_shrinker(&erofs_shrinker_info);
+	err = erofs_init_shrinker();
 	if (err)
 		goto shrinker_err;
 
@@ -587,7 +577,7 @@ static int __init erofs_module_init(void)
 fs_err:
 	z_erofs_exit_zip_subsystem();
 zip_err:
-	unregister_shrinker(&erofs_shrinker_info);
+	erofs_exit_shrinker();
 shrinker_err:
 	erofs_exit_inode_cache();
 icache_err:
@@ -598,7 +588,7 @@ static void __exit erofs_module_exit(void)
 {
 	unregister_filesystem(&erofs_fs_type);
 	z_erofs_exit_zip_subsystem();
-	unregister_shrinker(&erofs_shrinker_info);
+	erofs_exit_shrinker();
 	erofs_exit_inode_cache();
 	infoln("successfully finalize erofs");
 }
diff --git a/drivers/staging/erofs/utils.c b/drivers/staging/erofs/utils.c
index 024806003297..0e86e44d60d0 100644
--- a/drivers/staging/erofs/utils.c
+++ b/drivers/staging/erofs/utils.c
@@ -34,10 +34,10 @@ void *erofs_get_pcpubuf(unsigned int pagenr)
 }
 #endif
 
+#ifdef CONFIG_EROFS_FS_ZIP
 /* global shrink count (for all mounted EROFS instances) */
 static atomic_long_t erofs_global_shrink_cnt;
 
-#ifdef CONFIG_EROFS_FS_ZIP
 #define __erofs_workgroup_get(grp)	atomic_inc(&(grp)->refcount)
 #define __erofs_workgroup_put(grp)	atomic_dec(&(grp)->refcount)
 
@@ -215,9 +215,9 @@ static bool erofs_try_to_release_workgroup(struct erofs_sb_info *sbi,
 
 #endif
 
-unsigned long erofs_shrink_workstation(struct erofs_sb_info *sbi,
-				       unsigned long nr_shrink,
-				       bool cleanup)
+static unsigned long erofs_shrink_workstation(struct erofs_sb_info *sbi,
+					      unsigned long nr_shrink,
+					      bool cleanup)
 {
 	pgoff_t first_index = 0;
 	void *batch[PAGEVEC_SIZE];
@@ -250,8 +250,6 @@ unsigned long erofs_shrink_workstation(struct erofs_sb_info *sbi,
 	return freed;
 }
 
-#endif
-
 /* protected by 'erofs_sb_list_lock' */
 static unsigned int shrinker_run_no;
 
@@ -259,7 +257,7 @@ static unsigned int shrinker_run_no;
 static DEFINE_SPINLOCK(erofs_sb_list_lock);
 static LIST_HEAD(erofs_sb_list);
 
-void erofs_register_super(struct super_block *sb)
+void erofs_shrinker_register(struct super_block *sb)
 {
 	struct erofs_sb_info *sbi = EROFS_SB(sb);
 
@@ -270,11 +268,17 @@ void erofs_register_super(struct super_block *sb)
 	spin_unlock(&erofs_sb_list_lock);
 }
 
-void erofs_unregister_super(struct super_block *sb)
+void erofs_shrinker_unregister(struct super_block *sb)
 {
+	struct erofs_sb_info *const sbi = EROFS_SB(sb);
+
+	mutex_lock(&sbi->umount_mutex);
+	erofs_shrink_workstation(sbi, ~0UL, true);
+
 	spin_lock(&erofs_sb_list_lock);
-	list_del(&EROFS_SB(sb)->list);
+	list_del(&sbi->list);
 	spin_unlock(&erofs_sb_list_lock);
+	mutex_unlock(&sbi->umount_mutex);
 }
 
 static unsigned long erofs_shrink_count(struct shrinker *shrink,
@@ -318,9 +322,7 @@ static unsigned long erofs_shrink_scan(struct shrinker *shrink,
 		spin_unlock(&erofs_sb_list_lock);
 		sbi->shrinker_run_no = run_no;
 
-#ifdef CONFIG_EROFS_FS_ZIP
 		freed += erofs_shrink_workstation(sbi, nr, false);
-#endif
 
 		spin_lock(&erofs_sb_list_lock);
 		/* Get the next list element before we move this one */
@@ -340,9 +342,20 @@ static unsigned long erofs_shrink_scan(struct shrinker *shrink,
 	return freed;
 }
 
-struct shrinker erofs_shrinker_info = {
+static struct shrinker erofs_shrinker_info = {
 	.scan_objects = erofs_shrink_scan,
 	.count_objects = erofs_shrink_count,
 	.seeks = DEFAULT_SEEKS,
 };
 
+int __init erofs_init_shrinker(void)
+{
+	return register_shrinker(&erofs_shrinker_info);
+}
+
+void erofs_exit_shrinker(void)
+{
+	unregister_shrinker(&erofs_shrinker_info);
+}
+#endif	/* !CONFIG_EROFS_FS_ZIP */
+
-- 
2.17.1


  parent reply	other threads:[~2019-07-29  6:53 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-29  6:51 [PATCH 00/22] staging: erofs: updates according to erofs-outofstaging v4 Gao Xiang
2019-07-29  6:51 ` [PATCH 01/22] staging: erofs: update source file headers Gao Xiang
2019-07-30  7:20   ` Greg Kroah-Hartman
2019-07-30  7:26     ` Gao Xiang
2019-07-31  6:36   ` Chao Yu
2019-07-29  6:51 ` [PATCH 02/22] staging: erofs: rename source files for better understanding Gao Xiang
2019-07-31  6:43   ` Chao Yu
2019-07-29  6:51 ` [PATCH 03/22] staging: erofs: fix dummy functions erofs_{get,list}xattr Gao Xiang
2019-07-31  6:44   ` [PATCH 03/22] staging: erofs: fix dummy functions erofs_{get, list}xattr Chao Yu
2019-07-29  6:51 ` [PATCH 04/22] staging: erofs: keep up erofs_fs.h with erofs-outofstaging patchset Gao Xiang
2019-07-31  6:46   ` Chao Yu
2019-07-29  6:51 ` [PATCH 05/22] staging: erofs: sunset erofs_workstn_{lock,unlock} Gao Xiang
2019-07-31  6:49   ` Chao Yu
2019-07-29  6:51 ` [PATCH 06/22] staging: erofs: clean up internal.h Gao Xiang
2019-07-31  6:53   ` Chao Yu
2019-07-29  6:51 ` [PATCH 07/22] staging: erofs: remove redundant #include "internal.h" Gao Xiang
2019-07-31  7:03   ` Chao Yu
2019-07-31  7:08     ` Gao Xiang
2019-07-31 12:07       ` Chao Yu
2019-07-31 12:54         ` Gao Xiang
2019-08-01  1:31           ` Chao Yu
2019-07-29  6:51 ` [PATCH 08/22] staging: erofs: kill CONFIG_EROFS_FS_IO_MAX_RETRIES Gao Xiang
2019-07-31  7:05   ` Chao Yu
2019-07-31  7:11     ` Gao Xiang
2019-07-31 12:10       ` Chao Yu
2019-07-31 12:55         ` Gao Xiang
2019-07-29  6:51 ` Gao Xiang [this message]
2019-07-31  7:41   ` [PATCH 09/22] staging: erofs: clean up shrinker stuffs Chao Yu
2019-07-29  6:51 ` [PATCH 10/22] staging: erofs: kill sbi->dev_name Gao Xiang
2019-07-31  7:46   ` Chao Yu
2019-07-29  6:51 ` [PATCH 11/22] staging: erofs: kill all failure handling in fill_super() Gao Xiang
2019-07-31  8:15   ` Chao Yu
2019-07-31 12:52     ` Gao Xiang
2019-07-29  6:51 ` [PATCH 12/22] staging: erofs: refine erofs_allocpage() Gao Xiang
2019-07-31  8:20   ` Chao Yu
2019-07-29  6:51 ` [PATCH 13/22] staging: erofs: kill CONFIG_EROFS_FS_USE_VM_MAP_RAM Gao Xiang
2019-07-31  8:27   ` Chao Yu
2019-07-29  6:51 ` [PATCH 14/22] staging: erofs: tidy up zpvec.h Gao Xiang
2019-07-31  8:28   ` Chao Yu
2019-07-29  6:51 ` [PATCH 15/22] staging: erofs: remove redundant braces in inode.c Gao Xiang
2019-07-31  8:29   ` Chao Yu
2019-07-29  6:51 ` [PATCH 16/22] staging: erofs: tidy up decompression frontend Gao Xiang
2019-07-31  9:07   ` Chao Yu
2019-07-29  6:51 ` [PATCH 17/22] staging: erofs: remove clusterbits in sbi Gao Xiang
2019-07-31  9:12   ` Chao Yu
2019-07-29  6:51 ` [PATCH 18/22] staging: erofs: turn cache strategies into mount options Gao Xiang
2019-07-31  9:23   ` Chao Yu
2019-07-29  6:51 ` [PATCH 19/22] staging: erofs: tidy up utils.c Gao Xiang
2019-07-31  9:24   ` Chao Yu
2019-07-29  6:51 ` [PATCH 20/22] staging: erofs: tidy up internal.h Gao Xiang
2019-07-31  9:25   ` Chao Yu
2019-07-29  6:51 ` [PATCH 21/22] staging: erofs: update super.c Gao Xiang
2019-07-31  9:40   ` Chao Yu
2019-07-29  6:51 ` [PATCH 22/22] staging: erofs: update Kconfig Gao Xiang
2019-07-31  9:44   ` Chao Yu

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=20190729065159.62378-10-gaoxiang25@huawei.com \
    --to=gaoxiang25@huawei.com \
    --cc=chao@kernel.org \
    --cc=devel@driverdev.osuosl.org \
    --cc=fangwei1@huawei.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-erofs@lists.ozlabs.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=miaoxie@huawei.com \
    --cc=weidu.du@huawei.com \
    /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).