From patchwork Mon Jun 22 21:08:25 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fabian Frederick X-Patchwork-Id: 6657561 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 3F1479F39B for ; Mon, 22 Jun 2015 21:08:35 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 892BB205BD for ; Mon, 22 Jun 2015 21:08:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 26FB82055D for ; Mon, 22 Jun 2015 21:08:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752250AbbFVVIb (ORCPT ); Mon, 22 Jun 2015 17:08:31 -0400 Received: from mailrelay110.isp.belgacom.be ([195.238.20.137]:54374 "EHLO mailrelay110.isp.belgacom.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751879AbbFVVIa (ORCPT ); Mon, 22 Jun 2015 17:08:30 -0400 X-Belgacom-Dynamic: yes X-Cloudmark-SP-Filtered: true X-Cloudmark-SP-Result: v=1.1 cv=eWtaKQUTUbzTvYESxgzcVvJXO5dQmjbJ/tTWSlQWV0k= c=1 sm=2 a=ncqoqTVcCEGWkW5lmYwA:9 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A2CCCgAxeIhV/+8FQFdcgxCBM6tmBQGBBJkEgUA9EAEBAQEBAQGBCoRQLyOBGjeIMwHLTSyGG4owHYQVBYcDhQuHb4tOgTqOdogBJmNmAUEcgVQ8MYJIAQEB Received: from 239.5-64-87.adsl-dyn.isp.belgacom.be (HELO localhost.home.) ([87.64.5.239]) by relay.skynet.be with ESMTP; 22 Jun 2015 23:08:28 +0200 From: Fabian Frederick To: linux-fsdevel@vger.kernel.org Cc: Alexander Viro , Jan Kara , Fabian Frederick Subject: [RFC 1/1 linux-next] FS: consolidate inode cache initialization Date: Mon, 22 Jun 2015 23:08:25 +0200 Message-Id: <1435007305-19129-1-git-send-email-fabf@skynet.be> X-Mailer: git-send-email 2.4.2 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Currently, all filesystems directly call kmem_cache_create() through static init_inodecache() and generally use the same slab flags with _inode_cache. This patch declares _init_inode_cache() in libfs which uses file_system_fs name to forge cache name and applies the update on AFFS as an example. If the idea is interesting, should I send 1 patch for _init_inode_cache() addition and 1 patch for each FS update ? Regards, Fabian Signed-off-by: Fabian Frederick --- fs/affs/super.c | 17 ++++------------- fs/libfs.c | 15 +++++++++++++++ include/linux/fs.h | 3 +++ 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/fs/affs/super.c b/fs/affs/super.c index 3f89c9e..e7068d6 100644 --- a/fs/affs/super.c +++ b/fs/affs/super.c @@ -126,18 +126,6 @@ static void init_once(void *foo) inode_init_once(&ei->vfs_inode); } -static int __init init_inodecache(void) -{ - affs_inode_cachep = kmem_cache_create("affs_inode_cache", - sizeof(struct affs_inode_info), - 0, (SLAB_RECLAIM_ACCOUNT| - SLAB_MEM_SPREAD), - init_once); - if (affs_inode_cachep == NULL) - return -ENOMEM; - return 0; -} - static void destroy_inodecache(void) { /* @@ -623,7 +611,10 @@ MODULE_ALIAS_FS("affs"); static int __init init_affs_fs(void) { - int err = init_inodecache(); + int err; + + err = _init_inodecache(&affs_inode_cachep, &affs_fs_type, + sizeof(struct affs_inode_info), init_once); if (err) goto out1; err = register_filesystem(&affs_fs_type); diff --git a/fs/libfs.c b/fs/libfs.c index 88a4cb4..84531a9 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -1203,3 +1203,18 @@ bool is_empty_dir_inode(struct inode *inode) return (inode->i_fop == &empty_dir_operations) && (inode->i_op == &empty_dir_inode_operations); } + +int _init_inodecache(struct kmem_cache **cachep, struct file_system_type *fs, + size_t fs_inodeinfo_len, void *init_once) +{ + char buf[32]; + + sprintf(buf, "%s_inode_cache", fs->name); + *cachep = kmem_cache_create(buf, fs_inodeinfo_len, 0, + (SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD), + init_once); + if (!*cachep) + return -ENOMEM; + return 0; +} +EXPORT_SYMBOL(_init_inodecache); diff --git a/include/linux/fs.h b/include/linux/fs.h index 8a81fcb..036a8a2 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -2834,6 +2834,9 @@ extern int generic_file_fsync(struct file *, loff_t, loff_t, int); extern int generic_check_addressable(unsigned, u64); +extern int _init_inodecache(struct kmem_cache **, struct file_system_type *, + size_t, void *); + #ifdef CONFIG_MIGRATION extern int buffer_migrate_page(struct address_space *, struct page *, struct page *,