From patchwork Tue Jan 28 11:13:37 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Shilong X-Patchwork-Id: 3546251 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 7CEFEC02DC for ; Tue, 28 Jan 2014 11:15:13 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7290D20127 for ; Tue, 28 Jan 2014 11:15:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 31302200F2 for ; Tue, 28 Jan 2014 11:15:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755130AbaA1LPE (ORCPT ); Tue, 28 Jan 2014 06:15:04 -0500 Received: from cn.fujitsu.com ([222.73.24.84]:56679 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1754198AbaA1LPC (ORCPT ); Tue, 28 Jan 2014 06:15:02 -0500 X-IronPort-AV: E=Sophos;i="4.95,735,1384272000"; d="scan'208";a="9461948" Received: from unknown (HELO tang.cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 28 Jan 2014 19:11:14 +0800 Received: from fnstmail02.fnst.cn.fujitsu.com (tang.cn.fujitsu.com [127.0.0.1]) by tang.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id s0SBEvvL006860 for ; Tue, 28 Jan 2014 19:14:57 +0800 Received: from wangs.fnst.cn.fujitsu.com ([10.167.226.104]) by fnstmail02.fnst.cn.fujitsu.com (Lotus Domino Release 8.5.3) with ESMTP id 2014012819132343-1423328 ; Tue, 28 Jan 2014 19:13:23 +0800 From: Wang Shilong To: linux-btrfs@vger.kernel.org Subject: [PATCH v2] Btrfs: allocate ulist with a slab allocator Date: Tue, 28 Jan 2014 19:13:37 +0800 Message-Id: <1390907618-2105-1-git-send-email-wangsl.fnst@cn.fujitsu.com> X-Mailer: git-send-email 1.8.3.1 X-MIMETrack: Itemize by SMTP Server on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2014/01/28 19:13:23, Serialize by Router on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2014/01/28 19:13:23, Serialize complete at 2014/01/28 19:13:23 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable 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 Walking backrefs is heavily relying on ulist, so it is better to allocate ulist with a slab allocator especially with autodefrag and quota enabled. Signed-off-by: Wang Shilong --- v1->v2: address david's comments. --- fs/btrfs/super.c | 7 +++++++ fs/btrfs/ulist.c | 22 ++++++++++++++++++++-- fs/btrfs/ulist.h | 2 ++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 461e41c..1a9ac6d 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -1906,6 +1906,10 @@ static int __init init_btrfs_fs(void) if (err) goto free_prelim_ref; + err = btrfs_ulist_init(); + if (err) + goto free_ulist; + err = btrfs_interface_init(); if (err) goto free_delayed_ref; @@ -1926,6 +1930,8 @@ static int __init init_btrfs_fs(void) unregister_ioctl: btrfs_interface_exit(); +free_ulist: + btrfs_ulist_exit(); free_prelim_ref: btrfs_prelim_ref_exit(); free_delayed_ref: @@ -1955,6 +1961,7 @@ static void __exit exit_btrfs_fs(void) btrfs_auto_defrag_exit(); btrfs_delayed_inode_exit(); btrfs_prelim_ref_exit(); + btrfs_ulist_exit(); ordered_data_exit(); extent_map_exit(); extent_io_exit(); diff --git a/fs/btrfs/ulist.c b/fs/btrfs/ulist.c index 84ea442..514804c 100644 --- a/fs/btrfs/ulist.c +++ b/fs/btrfs/ulist.c @@ -8,6 +8,7 @@ #include "ulist.h" #include "ctree.h" +static struct kmem_cache *btrfs_ulist_cache; /* * ulist is a generic data structure to hold a collection of unique u64 * values. The only operations it supports is adding to the list and @@ -66,7 +67,7 @@ static void ulist_fini(struct ulist *ulist) struct ulist_node *next; list_for_each_entry_safe(node, next, &ulist->nodes, list) { - kfree(node); + kmem_cache_free(btrfs_ulist_cache, node); } ulist->root = RB_ROOT; INIT_LIST_HEAD(&ulist->nodes); @@ -156,6 +157,23 @@ static int ulist_rbtree_insert(struct ulist *ulist, struct ulist_node *ins) return 0; } +int __init btrfs_ulist_init(void) +{ + btrfs_ulist_cache = kmem_cache_create("btrfs_ulist_node", + sizeof(struct ulist_node), 0, + SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD, + NULL); + if (!btrfs_ulist_cache) + return -ENOMEM; + return 0; +} + +void btrfs_ulist_exit(void) +{ + if (btrfs_ulist_cache) + kmem_cache_destroy(btrfs_ulist_cache); +} + /** * ulist_add - add an element to the ulist * @ulist: ulist to add the element to @@ -193,7 +211,7 @@ int ulist_add_merge(struct ulist *ulist, u64 val, u64 aux, *old_aux = node->aux; return 0; } - node = kmalloc(sizeof(*node), gfp_mask); + node = kmem_cache_alloc(btrfs_ulist_cache, gfp_mask); if (!node) return -ENOMEM; diff --git a/fs/btrfs/ulist.h b/fs/btrfs/ulist.h index 154117d..d094621 100644 --- a/fs/btrfs/ulist.h +++ b/fs/btrfs/ulist.h @@ -51,6 +51,8 @@ struct ulist { struct rb_root root; }; +int __init btrfs_ulist_init(void); +void btrfs_ulist_exit(void); void ulist_init(struct ulist *ulist); void ulist_reinit(struct ulist *ulist); struct ulist *ulist_alloc(gfp_t gfp_mask);