All of lore.kernel.org
 help / color / mirror / Atom feed
From: gaoxiang25@huawei.com (Gao Xiang)
Subject: [WIP] [NOMERGE] [RFC PATCH v0.5 RESEND 08/10] erofs: introduce erofs shrinker
Date: Thu, 5 Jul 2018 17:09:02 +0800	[thread overview]
Message-ID: <1530781742-93912-1-git-send-email-gaoxiang25@huawei.com> (raw)
In-Reply-To: <1530780250-77563-4-git-send-email-gaoxiang25@huawei.com>

Signed-off-by: Gao Xiang <gaoxiang25 at huawei.com>
---

change log v0.5 RESEND:
 - add the missing mutex_init(&sbi->umount_mutex);

 fs/erofs/internal.h |  7 +++++
 fs/erofs/super.c    | 15 ++++++++++
 fs/erofs/utils.c    | 85 +++++++++++++++++++++++++++++++++++++++++++++++++----
 3 files changed, 101 insertions(+), 6 deletions(-)

diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h
index cc898b4..e202ef3 100644
--- a/fs/erofs/internal.h
+++ b/fs/erofs/internal.h
@@ -67,6 +67,7 @@ struct erofs_fault_info {
 struct erofs_sb_info {
 	/* list for all registered superblocks, mainly for shrinker */
 	struct list_head list;
+	struct mutex umount_mutex;
 
 	u32 blocks;
 	u32 meta_blkaddr;
@@ -94,6 +95,7 @@ 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 */
@@ -436,5 +438,10 @@ static inline void erofs_vunmap(const void *mem, unsigned int count)
 extern void erofs_register_super(struct super_block *sb);
 extern void erofs_unregister_super(struct super_block *sb);
 
+extern unsigned long erofs_shrink_count(struct shrinker *shrink,
+	struct shrink_control *sc);
+extern unsigned long erofs_shrink_scan(struct shrinker *shrink,
+	struct shrink_control *sc);
+
 #endif
 
diff --git a/fs/erofs/super.c b/fs/erofs/super.c
index a91399f..9452a89 100644
--- a/fs/erofs/super.c
+++ b/fs/erofs/super.c
@@ -354,7 +354,9 @@ static void erofs_put_super(struct super_block *sb)
 	infoln("unmounted for %s", sbi->dev_name);
 	__putname(sbi->dev_name);
 
+	mutex_lock(&sbi->umount_mutex);
 	erofs_unregister_super(sb);
+	mutex_unlock(&sbi->umount_mutex);
 
 	kfree(sbi);
 	sb->s_fs_info = NULL;
@@ -396,6 +398,12 @@ static void erofs_kill_sb(struct super_block *sb)
 	kill_block_super(sb);
 }
 
+static struct shrinker erofs_shrinker_info = {
+	.scan_objects = erofs_shrink_scan,
+	.count_objects = erofs_shrink_count,
+	.seeks = DEFAULT_SEEKS,
+};
+
 static struct file_system_type erofs_fs_type = {
 	.owner          = THIS_MODULE,
 	.name           = "erofs",
@@ -415,6 +423,10 @@ int __init erofs_module_init(void)
 	if (err)
 		goto icache_err;
 
+	err = register_shrinker(&erofs_shrinker_info);
+	if (err)
+		goto shrinker_err;
+
 	err = register_filesystem(&erofs_fs_type);
 	if (err)
 		goto fs_err;
@@ -423,6 +435,8 @@ int __init erofs_module_init(void)
 	return 0;
 
 fs_err:
+	unregister_shrinker(&erofs_shrinker_info);
+shrinker_err:
 	erofs_exit_inode_cache();
 icache_err:
 	return err;
@@ -431,6 +445,7 @@ int __init erofs_module_init(void)
 void __exit erofs_module_exit(void)
 {
 	unregister_filesystem(&erofs_fs_type);
+	unregister_shrinker(&erofs_shrinker_info);
 	erofs_exit_inode_cache();
 	infoln("Successfully finalize erofs");
 }
diff --git a/fs/erofs/utils.c b/fs/erofs/utils.c
index 78731c5..685e885 100644
--- a/fs/erofs/utils.c
+++ b/fs/erofs/utils.c
@@ -29,20 +29,93 @@ struct page *erofs_allocpage(struct list_head *pool, gfp_t gfp)
 	return page;
 }
 
-static DEFINE_MUTEX(erofs_sb_list_lock);
+
+/* protected by 'erofs_sb_list_lock' */
+static unsigned int shrinker_run_no;
+
+/* protects the mounted 'erofs_sb_list' */
+static DEFINE_SPINLOCK(erofs_sb_list_lock);
 static LIST_HEAD(erofs_sb_list);
 
+/* global shrink count (for all mounted EROFS instances) */
+static atomic_long_t erofs_global_shrink_cnt;
+
 void erofs_register_super(struct super_block *sb)
 {
-	mutex_lock(&erofs_sb_list_lock);
-	list_add(&EROFS_SB(sb)->list, &erofs_sb_list);
-	mutex_unlock(&erofs_sb_list_lock);
+	struct erofs_sb_info *sbi = EROFS_SB(sb);
+
+	mutex_init(&sbi->umount_mutex);
+
+	spin_lock(&erofs_sb_list_lock);
+	list_add(&sbi->list, &erofs_sb_list);
+	spin_unlock(&erofs_sb_list_lock);
 }
 
 void erofs_unregister_super(struct super_block *sb)
 {
-	mutex_lock(&erofs_sb_list_lock);
+	spin_lock(&erofs_sb_list_lock);
 	list_del(&EROFS_SB(sb)->list);
-	mutex_unlock(&erofs_sb_list_lock);
+	spin_unlock(&erofs_sb_list_lock);
+}
+
+unsigned long erofs_shrink_count(struct shrinker *shrink,
+				 struct shrink_control *sc)
+{
+	return atomic_long_read(&erofs_global_shrink_cnt);
+}
+
+unsigned long erofs_shrink_scan(struct shrinker *shrink,
+				struct shrink_control *sc)
+{
+	struct erofs_sb_info *sbi;
+	struct list_head *p;
+
+	unsigned long nr = sc->nr_to_scan;
+	unsigned int run_no;
+	unsigned long freed = 0;
+
+	spin_lock(&erofs_sb_list_lock);
+	do
+		run_no = ++shrinker_run_no;
+	while (run_no == 0);
+
+	/* Iterate over all mounted superblocks and try to shrink them */
+	p = erofs_sb_list.next;
+	while (p != &erofs_sb_list) {
+		sbi = list_entry(p, struct erofs_sb_info, list);
+
+		/*
+		 * We move the ones we do to the end of the list, so we stop
+		 * when we see one we have already done.
+		 */
+		if (sbi->shrinker_run_no == run_no)
+			break;
+
+		if (!mutex_trylock(&sbi->umount_mutex)) {
+			p = p->next;
+			continue;
+		}
+
+		spin_unlock(&erofs_sb_list_lock);
+		sbi->shrinker_run_no = run_no;
+
+		/* add scan handlers here */
+
+		spin_lock(&erofs_sb_list_lock);
+		/* Get the next list element before we move this one */
+		p = p->next;
+
+		/*
+		 * Move this one to the end of the list to provide some
+		 * fairness.
+		 */
+		list_move_tail(&sbi->list, &erofs_sb_list);
+		mutex_unlock(&sbi->umount_mutex);
+
+		if (freed >= nr)
+			break;
+	}
+	spin_unlock(&erofs_sb_list_lock);
+	return freed;
 }
 
-- 
1.9.1

  reply	other threads:[~2018-07-05  9:09 UTC|newest]

Thread overview: 102+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-27 14:20 [WIP] [NOMERGE] [RFC PATCH v0] erofs: introduce the new unzip subsystem Gao Xiang
2018-06-29 23:45 ` Chao Yu
2018-06-30  0:25   ` Gao Xiang
2018-06-30  9:18 ` [WIP] [NOMERGE] [RFC PATCH v0.2 1/2] <linux/tagptr.h>: Introduce tagged pointer Gao Xiang
2018-06-30  9:18   ` [WIP] [NOMERGE] [RFC PATCH v0.2 2/2] erofs: introduce the new VLE unzip subsystem Gao Xiang
2018-06-30 15:17 ` [WIP] [NOMERGE] [RFC PATCH v0.3 1/6] <linux/tagptr.h>: Introduce tagged pointer Gao Xiang
2018-06-30 15:17   ` [WIP] [NOMERGE] [RFC PATCH v0.3 2/6] erofs: introduce pagevec for unzip subsystem Gao Xiang
2018-06-30 15:17   ` [WIP] [NOMERGE] [RFC PATCH v0.3 3/6] erofs: introduce erofs_map_blocks_iter Gao Xiang
2018-07-01  3:56     ` Chao Yu
2018-07-01  4:17       ` Gao Xiang
2018-07-01  4:26         ` Gao Xiang
2018-07-02  1:47           ` Chao Yu
2018-07-02  2:48             ` Gao Xiang
2018-07-02  3:36               ` Chao Yu
2018-07-02  3:47                 ` Gao Xiang
2018-07-02 10:48                   ` Chao Yu
2018-07-02 11:53                     ` Gao Xiang
2018-06-30 15:17   ` [WIP] [NOMERGE] [RFC PATCH v0.3 4/6] erofs: add erofs_allocpage Gao Xiang
2018-06-30 15:17   ` [WIP] [NOMERGE] [RFC PATCH v0.3 5/6] erofs: globalize prepare_bio and __submit_bio Gao Xiang
2018-06-30 15:17   ` [WIP] [NOMERGE] [RFC PATCH v0.3 6/6] erofs: introduce VLE decompression subsystem Gao Xiang
2018-07-02 14:53 ` [WIP] [NOMERGE] [RFC PATCH v0.4 0/7] erofs: introduce the new unzip subsystem Gao Xiang
2018-07-02 14:53   ` [WIP] [NOMERGE] [RFC PATCH v0.4 1/7] <linux/tagptr.h>: Introduce tagged pointer Gao Xiang
2018-07-02 14:53     ` Gao Xiang
2018-07-02 14:53   ` [WIP] [NOMERGE] [RFC PATCH v0.4 2/7] erofs: introduce pagevec for unzip subsystem Gao Xiang
2018-07-02 14:53   ` [WIP] [NOMERGE] [RFC PATCH v0.4 3/7] erofs: add erofs_map_blocks_iter Gao Xiang
2018-07-02 14:53   ` [WIP] [NOMERGE] [RFC PATCH v0.4 4/7] erofs: add erofs_allocpage Gao Xiang
2018-07-02 14:53   ` [WIP] [NOMERGE] [RFC PATCH v0.4 5/7] erofs: globalize prepare_bio and __submit_bio Gao Xiang
2018-07-02 14:53   ` [WIP] [NOMERGE] [RFC PATCH v0.4 6/7] erofs: add a generic z_erofs VLE decompressor Gao Xiang
2018-07-02 14:53   ` [WIP] [NOMERGE] [RFC PATCH v0.4 7/7] erofs: introduce VLE decompression subsystem Gao Xiang
2018-07-03 16:12 ` [WIP] [NOMERGE] [RFC PATCH v0.4 0/7] erofs: introduce the new unzip subsystem Gao Xiang
2018-07-03 16:13 ` [WIP] [NOMERGE] [RFC PATCH v0.4 RESEND " Gao Xiang
2018-07-03 16:13   ` [WIP] [NOMERGE] [RFC PATCH RESEND v0.4 1/7] <linux/tagptr.h>: Introduce tagged pointer Gao Xiang
2018-07-03 16:13   ` [WIP] [NOMERGE] [RFC PATCH RESEND v0.4 2/7] erofs: introduce pagevec for unzip subsystem Gao Xiang
2018-07-03 16:13   ` [WIP] [NOMERGE] [RFC PATCH RESEND v0.4 3/7] erofs: add erofs_map_blocks_iter Gao Xiang
2018-07-03 16:13   ` [WIP] [NOMERGE] [RFC PATCH RESEND v0.4 4/7] erofs: add erofs_allocpage Gao Xiang
2018-07-03 16:13   ` [WIP] [NOMERGE] [RFC PATCH RESEND v0.4 5/7] erofs: globalize prepare_bio and __submit_bio Gao Xiang
2018-07-03 16:13   ` [WIP] [NOMERGE] [RFC PATCH RESEND v0.4 6/7] erofs: add a generic z_erofs VLE decompressor Gao Xiang
2018-07-03 16:13   ` [WIP] [NOMERGE] [RFC PATCH RESEND v0.4 7/7] erofs: introduce VLE decompression subsystem Gao Xiang
2018-07-05  8:41 ` [WIP] [NOMERGE] [RFC PATCH v0.5 00/10] erofs: introduce the new unzip subsystem Gao Xiang
2018-07-05  8:41   ` [WIP] [NOMERGE] [RFC PATCH v0.5 01/10] <linux/tagptr.h>: Introduce tagged pointer Gao Xiang
2018-07-05  8:41   ` [WIP] [NOMERGE] [RFC PATCH v0.5 02/10] erofs: introduce pagevec for unzip subsystem Gao Xiang
2018-07-05  8:41   ` [WIP] [NOMERGE] [RFC PATCH v0.5 03/10] erofs: add erofs_map_blocks_iter Gao Xiang
2018-07-05  8:41   ` [WIP] [NOMERGE] [RFC PATCH v0.5 04/10] erofs: add erofs_allocpage Gao Xiang
2018-07-05  8:44   ` [WIP] [NOMERGE] [RFC PATCH v0.5 05/10] erofs: globalize prepare_bio and __submit_bio Gao Xiang
2018-07-05  8:44     ` [WIP] [NOMERGE] [RFC PATCH v0.5 06/10] erofs: add a generic z_erofs VLE decompressor Gao Xiang
2018-07-05  8:44     ` [WIP] [NOMERGE] [RFC PATCH v0.5 07/10] erofs: introduce superblock registration Gao Xiang
2018-07-05  8:44     ` [WIP] [NOMERGE] [RFC PATCH v0.5 08/10] erofs: introduce erofs shrinker Gao Xiang
2018-07-05  9:09       ` Gao Xiang [this message]
2018-07-05  8:44     ` [WIP] [NOMERGE] [RFC PATCH v0.5 09/10] erofs: introduce workstation for decompression Gao Xiang
2018-07-05  8:44     ` [WIP] [NOMERGE] [RFC PATCH v0.5 10/10] erofs: introduce VLE decompression support Gao Xiang
2018-07-05  9:37       ` [WIP] [NOMERGE] [RFC PATCH v0.5 RESEND " Gao Xiang
2018-07-06 16:50 ` [WIP] [NOMERGE] [RFC PATCH v0.6 00/10] erofs: introduce the new unzip subsystem Gao Xiang
2018-07-06 16:50   ` [WIP] [NOMERGE] [RFC PATCH v0.6 01/10] <linux/tagptr.h>: Introduce tagged pointer Gao Xiang
2018-07-06 16:50   ` [WIP] [NOMERGE] [RFC PATCH v0.6 02/10] erofs: introduce pagevec for unzip subsystem Gao Xiang
2018-07-06 16:50   ` [WIP] [NOMERGE] [RFC PATCH v0.6 03/10] erofs: add erofs_map_blocks_iter Gao Xiang
2018-07-06 16:50   ` [WIP] [NOMERGE] [RFC PATCH v0.6 04/10] erofs: add erofs_allocpage Gao Xiang
2018-07-06 16:50   ` [WIP] [NOMERGE] [RFC PATCH v0.6 05/10] erofs: globalize prepare_bio and __submit_bio Gao Xiang
2018-07-06 16:50   ` [WIP] [NOMERGE] [RFC PATCH v0.6 06/10] erofs: add a generic z_erofs VLE decompressor Gao Xiang
2018-07-06 16:50   ` [WIP] [NOMERGE] [RFC PATCH v0.6 07/10] erofs: introduce superblock registration Gao Xiang
2018-07-06 16:50   ` [WIP] [NOMERGE] [RFC PATCH v0.6 08/10] erofs: introduce erofs shrinker Gao Xiang
2018-07-06 16:50   ` [WIP] [NOMERGE] [RFC PATCH v0.6 09/10] erofs: introduce workstation for decompression Gao Xiang
2018-07-06 16:50   ` [WIP] [NOMERGE] [RFC PATCH v0.6 10/10] erofs: introduce VLE decompression support Gao Xiang
2018-07-09 19:17 ` [WIP] [NOMERGE] [RFC PATCH v0.7 00/10] erofs: introduce the new unzip subsystem Gao Xiang
2018-07-09 19:17   ` [WIP] [NOMERGE] [RFC PATCH v0.7 01/10] <linux/tagptr.h>: Introduce tagged pointer Gao Xiang
2018-07-09 19:17   ` [WIP] [NOMERGE] [RFC PATCH v0.7 02/10] erofs: introduce pagevec for unzip subsystem Gao Xiang
2018-07-09 19:17   ` [WIP] [NOMERGE] [RFC PATCH v0.7 03/10] erofs: add erofs_map_blocks_iter Gao Xiang
2018-07-09 19:17   ` [WIP] [NOMERGE] [RFC PATCH v0.7 04/10] erofs: add erofs_allocpage Gao Xiang
2018-07-09 19:17   ` [WIP] [NOMERGE] [RFC PATCH v0.7 05/10] erofs: globalize prepare_bio and __submit_bio Gao Xiang
2018-07-09 19:17   ` [WIP] [NOMERGE] [RFC PATCH v0.7 06/10] erofs: add a generic z_erofs VLE decompressor Gao Xiang
2018-07-09 19:17   ` [WIP] [NOMERGE] [RFC PATCH v0.7 07/10] erofs: introduce superblock registration Gao Xiang
2018-07-09 19:17   ` [WIP] [NOMERGE] [RFC PATCH v0.7 08/10] erofs: introduce erofs shrinker Gao Xiang
2018-07-09 19:17   ` [WIP] [NOMERGE] [RFC PATCH v0.7 09/10] erofs: introduce workstation for decompression Gao Xiang
2018-07-09 19:17   ` [WIP] [NOMERGE] [RFC PATCH v0.7 10/10] erofs: introduce VLE decompression support Gao Xiang
2018-07-13 13:17     ` [PATCH 1/2] temp commit 1 Gao Xiang
2018-07-13 13:17       ` [PATCH 2/2] temp commit 2 Gao Xiang
2018-07-17 14:18 ` [RFC PATCH v1 00/11] erofs: introduce the new unzip subsystem Gao Xiang
2018-07-17 14:18   ` [RFC PATCH v1 01/11] <linux/tagptr.h>: Introduce tagged pointer Gao Xiang
2018-07-17 14:18   ` [RFC PATCH v1 02/11] erofs: introduce pagevec for unzip subsystem Gao Xiang
2018-07-17 14:18   ` [RFC PATCH v1 03/11] erofs: add erofs_map_blocks_iter Gao Xiang
2018-07-17 14:18   ` [RFC PATCH v1 04/11] erofs: add erofs_allocpage Gao Xiang
2018-07-17 14:18   ` [RFC PATCH v1 05/11] erofs: globalize prepare_bio and __submit_bio Gao Xiang
2018-07-17 14:18   ` [RFC PATCH v1 06/11] erofs: add a generic z_erofs VLE decompressor Gao Xiang
2018-07-17 14:18   ` [RFC PATCH v1 07/11] erofs: introduce superblock registration Gao Xiang
2018-07-17 14:18   ` [RFC PATCH v1 08/11] erofs: introduce erofs shrinker Gao Xiang
2018-07-17 14:18   ` [RFC PATCH v1 09/11] erofs: introduce workstation for decompression Gao Xiang
2018-07-17 14:18   ` [RFC PATCH v1 10/11] erofs: introduce VLE decompression support Gao Xiang
2018-07-17 14:18   ` [RFC PATCH v1 11/11] erofs: introduce cached decompression Gao Xiang
2018-07-20  2:52 ` [RFC PATCH v2 00/11] erofs: introduce the new unzip subsystem Gao Xiang
2018-07-20  2:52   ` [RFC PATCH v2 01/11] <linux/tagptr.h>: Introduce tagged pointer Gao Xiang
2018-07-20  2:52   ` [RFC PATCH v2 02/11] erofs: introduce pagevec for unzip subsystem Gao Xiang
2018-07-20  2:52   ` [RFC PATCH v2 03/11] erofs: add erofs_map_blocks_iter Gao Xiang
2018-07-20  2:52   ` [RFC PATCH v2 04/11] erofs: add erofs_allocpage Gao Xiang
2018-07-20  2:52   ` [RFC PATCH v2 05/11] erofs: globalize prepare_bio and __submit_bio Gao Xiang
2018-07-20  2:52   ` [RFC PATCH v2 06/11] erofs: add a generic z_erofs VLE decompressor Gao Xiang
2018-07-20  2:52   ` [RFC PATCH v2 07/11] erofs: introduce superblock registration Gao Xiang
2018-07-20  2:52   ` [RFC PATCH v2 08/11] erofs: introduce erofs shrinker Gao Xiang
2018-07-20  2:52   ` [RFC PATCH v2 09/11] erofs: introduce workstation for decompression Gao Xiang
2018-07-20  2:52   ` [RFC PATCH v2 10/11] erofs: introduce VLE decompression support Gao Xiang
2018-07-20 16:55     ` [RFC PATCH v3 " Gao Xiang
2018-07-20 16:55       ` [RFC PATCH v3 11/11] erofs: introduce cached decompression Gao Xiang
2018-07-20 17:29       ` [RFC PATCH v3 RESEND 10/11] erofs: introduce VLE decompression support Gao Xiang
2018-07-20  2:52   ` [RFC PATCH v2 11/11] erofs: introduce cached decompression Gao Xiang

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=1530781742-93912-1-git-send-email-gaoxiang25@huawei.com \
    --to=gaoxiang25@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 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.