From: Jaegeuk Kim <jaegeuk@kernel.org>
To: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
linux-f2fs-devel@lists.sourceforge.net
Cc: Jaegeuk Kim <jaegeuk@kernel.org>
Subject: [PATCH 09/12] f2fs: shrink nat_cache entries
Date: Mon, 29 Jun 2015 11:39:33 -0700 [thread overview]
Message-ID: <1435603176-63219-9-git-send-email-jaegeuk@kernel.org> (raw)
In-Reply-To: <1435603176-63219-1-git-send-email-jaegeuk@kernel.org>
This patch registers shrinking nat_cache entries.
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
---
fs/f2fs/node.c | 6 +++---
fs/f2fs/segment.c | 8 ++++++--
fs/f2fs/shrinker.c | 11 +++++++++--
3 files changed, 18 insertions(+), 7 deletions(-)
diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c
index d9c5242..318ee86 100644
--- a/fs/f2fs/node.c
+++ b/fs/f2fs/node.c
@@ -328,11 +328,11 @@ static void set_node_addr(struct f2fs_sb_info *sbi, struct node_info *ni,
int try_to_free_nats(struct f2fs_sb_info *sbi, int nr_shrink)
{
struct f2fs_nm_info *nm_i = NM_I(sbi);
+ int nr = nr_shrink;
- if (available_free_memory(sbi, NAT_ENTRIES))
+ if (!down_write_trylock(&nm_i->nat_tree_lock))
return 0;
- down_write(&nm_i->nat_tree_lock);
while (nr_shrink && !list_empty(&nm_i->nat_entries)) {
struct nat_entry *ne;
ne = list_first_entry(&nm_i->nat_entries,
@@ -341,7 +341,7 @@ int try_to_free_nats(struct f2fs_sb_info *sbi, int nr_shrink)
nr_shrink--;
}
up_write(&nm_i->nat_tree_lock);
- return nr_shrink;
+ return nr - nr_shrink;
}
/*
diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index 1eb3437..dec3afb 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -305,8 +305,12 @@ void f2fs_balance_fs_bg(struct f2fs_sb_info *sbi)
/* try to shrink extent cache when there is no enough memory */
f2fs_shrink_extent_tree(sbi, EXTENT_CACHE_SHRINK_NUMBER);
- /* check the # of cached NAT entries and prefree segments */
- if (try_to_free_nats(sbi, NAT_ENTRY_PER_BLOCK) ||
+ /* check the # of cached NAT entries */
+ if (!available_free_memory(sbi, NAT_ENTRIES))
+ try_to_free_nats(sbi, NAT_ENTRY_PER_BLOCK);
+
+ /* checkpoint is the only way to shrink partial cached entries */
+ if (!available_free_memory(sbi, NAT_ENTRIES) ||
excess_prefree_segs(sbi) ||
!available_free_memory(sbi, INO_ENTRIES))
f2fs_sync_fs(sbi->sb, true);
diff --git a/fs/f2fs/shrinker.c b/fs/f2fs/shrinker.c
index a680145..3350ac3 100644
--- a/fs/f2fs/shrinker.c
+++ b/fs/f2fs/shrinker.c
@@ -18,6 +18,11 @@ static LIST_HEAD(f2fs_list);
static DEFINE_SPINLOCK(f2fs_list_lock);
static unsigned int shrinker_run_no;
+static unsigned long __count_nat_entries(struct f2fs_sb_info *sbi)
+{
+ return NM_I(sbi)->nat_cnt - NM_I(sbi)->dirty_nat_cnt;
+}
+
unsigned long f2fs_shrink_count(struct shrinker *shrink,
struct shrink_control *sc)
{
@@ -37,7 +42,8 @@ unsigned long f2fs_shrink_count(struct shrinker *shrink,
}
spin_unlock(&f2fs_list_lock);
- /* TODO: count # of objects */
+ /* shrink clean nat cache entries */
+ count += __count_nat_entries(sbi);
spin_lock(&f2fs_list_lock);
p = p->next;
@@ -76,7 +82,8 @@ unsigned long f2fs_shrink_scan(struct shrinker *shrink,
sbi->shrinker_run_no = run_no;
- /* TODO: shrink caches */
+ /* shrink clean nat cache entries */
+ freed += try_to_free_nats(sbi, nr);
spin_lock(&f2fs_list_lock);
p = p->next;
--
2.1.1
------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
next prev parent reply other threads:[~2015-06-29 18:39 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-29 18:39 [PATCH 01/12] f2fs: avoid freed stat information Jaegeuk Kim
2015-06-29 18:39 ` [PATCH 02/12] f2fs: avoid to use failed inode immediately Jaegeuk Kim
2015-06-30 2:54 ` [f2fs-dev] " Chao Yu
2015-06-29 18:39 ` [PATCH 03/12] f2fs: convert inline_data for various fallocate Jaegeuk Kim
2015-06-30 2:58 ` [f2fs-dev] " Chao Yu
2015-06-29 18:39 ` [PATCH 04/12] f2fs: remove wrong f2fs_bug_on when merging extents Jaegeuk Kim
2015-06-30 3:00 ` Chao Yu
2015-07-01 1:02 ` [f2fs-dev] " Jaegeuk Kim
2015-06-29 18:39 ` [PATCH 05/12] f2fs: fix wrong block address calculation for a split extent Jaegeuk Kim
2015-06-30 3:08 ` Chao Yu
2015-06-29 18:39 ` [PATCH 06/12] f2fs: update on-disk extents even under extent_cache Jaegeuk Kim
2015-06-30 3:10 ` [f2fs-dev] " Chao Yu
2015-06-29 18:39 ` [PATCH 07/12] f2fs: set cached_en after checking finally Jaegeuk Kim
2015-06-30 3:26 ` Chao Yu
2015-06-29 18:39 ` [PATCH 08/12] f2fs: introduce a shrinker for mounted fs Jaegeuk Kim
2015-06-30 3:43 ` Chao Yu
2015-07-01 1:28 ` [f2fs-dev] " Jaegeuk Kim
2015-07-02 12:32 ` Chao Yu
2015-07-04 4:51 ` Jaegeuk Kim
2015-06-29 18:39 ` Jaegeuk Kim [this message]
2015-07-02 12:33 ` [PATCH 09/12] f2fs: shrink nat_cache entries Chao Yu
2015-06-29 18:39 ` [PATCH 10/12] f2fs: shrink extent_cache entries Jaegeuk Kim
2015-07-02 12:34 ` Chao Yu
2015-06-29 18:39 ` [PATCH 11/12] f2fs: add noextent_cache mount option Jaegeuk Kim
2015-07-02 12:35 ` Chao Yu
2015-07-04 4:57 ` Jaegeuk Kim
2015-06-29 18:39 ` [PATCH 12/12] f2fs: use extent_cache by default Jaegeuk Kim
2015-07-02 12:36 ` Chao Yu
2015-07-04 5:16 ` Jaegeuk Kim
2015-07-04 6:30 ` Chao Yu
2015-07-06 12:26 ` [f2fs-dev] " Chao Yu
2015-06-30 2:45 ` [PATCH 01/12] f2fs: avoid freed stat information 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=1435603176-63219-9-git-send-email-jaegeuk@kernel.org \
--to=jaegeuk@kernel.org \
--cc=linux-f2fs-devel@lists.sourceforge.net \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@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).