Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753183AbbGXK2W (ORCPT ); Fri, 24 Jul 2015 06:28:22 -0400 Received: from mailout1.samsung.com ([203.254.224.24]:46320 "EHLO mailout1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751181AbbGXK2T (ORCPT ); Fri, 24 Jul 2015 06:28:19 -0400 X-AuditID: cbfee61a-f79516d000006302-75-55b21341c8b1 From: Chao Yu To: Jaegeuk Kim Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org Subject: [PATCH 3/3] f2fs: shrink free_nids entries Date: Fri, 24 Jul 2015 18:27:36 +0800 Message-id: <006401d0c5fb$74760860$5d621920$@samsung.com> MIME-version: 1.0 Content-type: text/plain; charset=us-ascii Content-transfer-encoding: 7bit X-Mailer: Microsoft Outlook 14.0 Thread-index: AdDF+zyXLkfjuU9MS5K3eNXlcR3rMQ== Content-language: zh-cn X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrBLMWRmVeSWpSXmKPExsVy+t9jQV1H4U2hBrOW61g8WT+L2eLSIneL y7vmsDkwe2xa1cnmsXvBZyaPz5vkApijuGxSUnMyy1KL9O0SuDKOblYsOCtXcWVfA3MD4xHJ LkZODgkBE4kFf1sZIWwxiQv31rN1MXJxCAlMZ5T4/qGNHcJ5xSjR9GEnE0gVm4CKxPKO/2C2 CJB9aNFldhCbWcBDorHjOyuILSxgLHGy5QiYzSKgKrG54QAbiM0rYCnRduwxO4QtKPFj8j0W iF4tifU7jzNB2PISm9e8ZYa4SEFix9nXjBC79CTWztrFBlEjLrHxyC2WCYwCs5CMmoVk1Cwk o2YhaVnAyLKKUTS1ILmgOCk911CvODG3uDQvXS85P3cTIzh8n0ntYFzZYHGIUYCDUYmH98Ck jaFCrIllxZW5hxglOJiVRHgZjgGFeFMSK6tSi/Lji0pzUosPMUpzsCiJ857M9wkVEkhPLEnN Tk0tSC2CyTJxcEo1MM5TW/ZVeEfL+8KbjEWpZ01mXxDqWZbCyLrHtT2Td6vHsQ9WE5NC9H1b 2hdItGQ38lT0tM/O27Uohy2lQn6p7VPVmyqGZ1ftkzEtWvNl8lzZGKvd4tOr/hxoTuC92Kxt 5OnzXfMry8xZh6SnifTy+m320NgQEJpq8zGN24n/fWHm4fuZD20DlFiKMxINtZiLihMBjrc1 v1sCAAA= Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4045 Lines: 122 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 --- fs/f2fs/f2fs.h | 1 + fs/f2fs/node.c | 26 ++++++++++++++++++++++++++ fs/f2fs/segment.c | 3 +++ fs/f2fs/shrinker.c | 14 ++++++++++++++ 4 files changed, 44 insertions(+) diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index d0b294f..9052bd2 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..bb0a4d5 100644 --- a/fs/f2fs/node.c +++ b/fs/f2fs/node.c @@ -1635,6 +1635,32 @@ 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); + int nr = nr_shrink; + + if (!mutex_trylock(&nm_i->build_lock)) + return 0; + + spin_lock(&nm_i->free_nid_list_lock); + while (nr_shrink && nm_i->fcnt > NAT_ENTRY_PER_BLOCK) { + struct free_nid *i; + + i = list_first_entry(&nm_i->free_nid_list, + struct free_nid, list); + f2fs_bug_on(sbi, i->state == NID_ALLOC); + __del_from_free_nid_list(nm_i, i); + nm_i->fcnt--; + kmem_cache_free(free_nid_slab, i); + nr_shrink--; + } + 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 08b2ebc..85c0433 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -310,6 +310,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 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/