linux-f2fs-devel.lists.sourceforge.net archive mirror
 help / color / mirror / Atom feed
From: Chao Yu <chao2.yu@samsung.com>
To: 'Jaegeuk Kim' <jaegeuk@kernel.org>
Cc: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net
Subject: RE: [f2fs-dev] [PATCH v2] f2fs: shrink free_nids entries
Date: Wed, 05 Aug 2015 17:27:29 +0800	[thread overview]
Message-ID: <00a101d0cf61$0b20ca20$21625e60$@samsung.com> (raw)
In-Reply-To: <00e701d0c920$f9add580$ed098080$@samsung.com>

Hi Jaegeuk,

Any comments?

> -----Original Message-----
> From: Chao Yu [mailto:chao2.yu@samsung.com]
> Sent: Tuesday, July 28, 2015 6:34 PM
> To: Jaegeuk Kim
> Cc: linux-kernel@vger.kernel.org; linux-f2fs-devel@lists.sourceforge.net
> Subject: [f2fs-dev] [PATCH v2] f2fs: shrink free_nids entries
> 
> This patch introduces __count_free_nids/try_to_free_nids and registers
> them in slab shrinker for shrinking under memory pressure.
> 
> Signed-off-by: Chao Yu <chao2.yu@samsung.com>
> ---
> v2:
>  * fix wrong bug_on in try_to_free_nids.
> 
>  fs/f2fs/f2fs.h     |  1 +
>  fs/f2fs/node.c     | 28 ++++++++++++++++++++++++++++
>  fs/f2fs/segment.c  |  3 +++
>  fs/f2fs/shrinker.c | 14 ++++++++++++++
>  4 files changed, 46 insertions(+)
> 
> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
> index 58b05b5..a8e07cd 100644
> --- a/fs/f2fs/f2fs.h
> +++ b/fs/f2fs/f2fs.h
> @@ -1682,6 +1682,7 @@ int sync_node_pages(struct f2fs_sb_info *, nid_t, struct writeback_control
> *);
>  bool alloc_nid(struct f2fs_sb_info *, nid_t *);
>  void alloc_nid_done(struct f2fs_sb_info *, nid_t);
>  void alloc_nid_failed(struct f2fs_sb_info *, nid_t);
> +int try_to_free_nids(struct f2fs_sb_info *, int);
>  void recover_inline_xattr(struct inode *, struct page *);
>  void recover_xattr_data(struct inode *, struct page *, block_t);
>  int recover_inode_page(struct f2fs_sb_info *, struct page *);
> diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c
> index ac91107..6e10c2a 100644
> --- a/fs/f2fs/node.c
> +++ b/fs/f2fs/node.c
> @@ -1635,6 +1635,34 @@ void alloc_nid_failed(struct f2fs_sb_info *sbi, nid_t nid)
>  		kmem_cache_free(free_nid_slab, i);
>  }
> 
> +int try_to_free_nids(struct f2fs_sb_info *sbi, int nr_shrink)
> +{
> +	struct f2fs_nm_info *nm_i = NM_I(sbi);
> +	struct free_nid *i, *next;
> +	int nr = nr_shrink;
> +
> +	if (!mutex_trylock(&nm_i->build_lock))
> +		return 0;
> +
> +	spin_lock(&nm_i->free_nid_list_lock);
> +	list_for_each_entry_safe(i, next, &nm_i->free_nid_list, list) {
> +		if (nr_shrink <= 0 || nm_i->fcnt <= NAT_ENTRY_PER_BLOCK)
> +			break;
> +		if (i->state == NID_ALLOC)
> +			continue;
> +		__del_from_free_nid_list(nm_i, i);
> +		nm_i->fcnt--;
> +		spin_unlock(&nm_i->free_nid_list_lock);
> +		kmem_cache_free(free_nid_slab, i);
> +		nr_shrink--;
> +		spin_lock(&nm_i->free_nid_list_lock);
> +	}
> +	spin_unlock(&nm_i->free_nid_list_lock);
> +	mutex_unlock(&nm_i->build_lock);
> +
> +	return nr - nr_shrink;
> +}
> +
>  void recover_inline_xattr(struct inode *inode, struct page *page)
>  {
>  	void *src_addr, *dst_addr;
> diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
> index 509a2c4..4712dbc 100644
> --- a/fs/f2fs/segment.c
> +++ b/fs/f2fs/segment.c
> @@ -317,6 +317,9 @@ void f2fs_balance_fs_bg(struct f2fs_sb_info *sbi)
>  	if (!available_free_memory(sbi, NAT_ENTRIES))
>  		try_to_free_nats(sbi, NAT_ENTRY_PER_BLOCK);
> 
> +	if (!available_free_memory(sbi, FREE_NIDS))
> +		try_to_free_nids(sbi, NAT_ENTRY_PER_BLOCK * FREE_NID_PAGES);
> +
>  	/* checkpoint is the only way to shrink partial cached entries */
>  	if (!available_free_memory(sbi, NAT_ENTRIES) ||
>  			excess_prefree_segs(sbi) ||
> diff --git a/fs/f2fs/shrinker.c b/fs/f2fs/shrinker.c
> index 9aa4235..da0d8e0 100644
> --- a/fs/f2fs/shrinker.c
> +++ b/fs/f2fs/shrinker.c
> @@ -23,6 +23,13 @@ static unsigned long __count_nat_entries(struct f2fs_sb_info *sbi)
>  	return NM_I(sbi)->nat_cnt - NM_I(sbi)->dirty_nat_cnt;
>  }
> 
> +static unsigned long __count_free_nids(struct f2fs_sb_info *sbi)
> +{
> +	if (NM_I(sbi)->fcnt > NAT_ENTRY_PER_BLOCK)
> +		return NM_I(sbi)->fcnt - NAT_ENTRY_PER_BLOCK;
> +	return 0;
> +}
> +
>  static unsigned long __count_extent_cache(struct f2fs_sb_info *sbi)
>  {
>  	return sbi->total_ext_tree + atomic_read(&sbi->total_ext_node);
> @@ -53,6 +60,9 @@ unsigned long f2fs_shrink_count(struct shrinker *shrink,
>  		/* shrink clean nat cache entries */
>  		count += __count_nat_entries(sbi);
> 
> +		/* count free nids cache entries */
> +		count += __count_free_nids(sbi);
> +
>  		spin_lock(&f2fs_list_lock);
>  		p = p->next;
>  		mutex_unlock(&sbi->umount_mutex);
> @@ -97,6 +107,10 @@ unsigned long f2fs_shrink_scan(struct shrinker *shrink,
>  		if (freed < nr)
>  			freed += try_to_free_nats(sbi, nr - freed);
> 
> +		/* shrink free nids cache entries */
> +		if (freed < nr)
> +			freed += try_to_free_nids(sbi, nr - freed);
> +
>  		spin_lock(&f2fs_list_lock);
>  		p = p->next;
>  		list_move_tail(&sbi->s_list, &f2fs_list);
> --
> 2.4.2
> 
> 
> 
> ------------------------------------------------------------------------------
> _______________________________________________
> Linux-f2fs-devel mailing list
> Linux-f2fs-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

      reply	other threads:[~2015-08-05  9:27 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-28 10:33 [PATCH v2] f2fs: shrink free_nids entries Chao Yu
2015-08-05  9:27 ` Chao Yu [this message]

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='00a101d0cf61$0b20ca20$21625e60$@samsung.com' \
    --to=chao2.yu@samsung.com \
    --cc=jaegeuk@kernel.org \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    --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).