From patchwork Wed May 1 21:35:33 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 2508931 Return-Path: X-Original-To: patchwork-ceph-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 4F6853FD85 for ; Wed, 1 May 2013 21:35:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758511Ab3EAVfh (ORCPT ); Wed, 1 May 2013 17:35:37 -0400 Received: from mail-ia0-f180.google.com ([209.85.210.180]:50942 "EHLO mail-ia0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932555Ab3EAVfg (ORCPT ); Wed, 1 May 2013 17:35:36 -0400 Received: by mail-ia0-f180.google.com with SMTP id t4so36943iag.11 for ; Wed, 01 May 2013 14:35:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:message-id:date:from:user-agent:mime-version:to:subject :references:in-reply-to:content-type:content-transfer-encoding :x-gm-message-state; bh=FkTyS8lUxThfnlaX7SJ0uqbNw805ZC3bLGHOusYJYFc=; b=A8R5UUSDl6WyBAcdzgapKWrDyRbHTPhwgMNaLH0a6SyKOGGjf1JrTAJSkXLmfvWi5E cSPa+nSOwUB0aRKmjvDhuHfPSSTGxEOfsk6iP0aWKG9BzWe8mLsKP/+PPUyqkNNx67TI ztxSdq3Tci9u4wPo7fV+0Y/28G14PoS3J5zzSPw/hccFrAuPVSS2Pn2x+ZasbJvYn3/Z ZiH6KQanbmqc1q+JhiouVZbEpXoqG7InxxISkd4dsa3+uIf1nbail2NAMfR4Xp85MD7A 7httpN3Cbrb2IeH8ehIwOGqeWw7vNiLUzBCDonucrykOTjMk1F5Y0IZD2ENo6I/oJ/Tu /DBw== X-Received: by 10.50.107.106 with SMTP id hb10mr7455072igb.25.1367444135471; Wed, 01 May 2013 14:35:35 -0700 (PDT) Received: from [172.22.22.4] (c-71-195-31-37.hsd1.mn.comcast.net. [71.195.31.37]) by mx.google.com with ESMTPSA id f16sm5720912igt.8.2013.05.01.14.35.34 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 01 May 2013 14:35:34 -0700 (PDT) Message-ID: <51818AA5.6070200@inktank.com> Date: Wed, 01 May 2013 16:35:33 -0500 From: Alex Elder User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130329 Thunderbird/17.0.5 MIME-Version: 1.0 To: ceph-devel@vger.kernel.org Subject: [PATCH 1/4] rbd: allocate image requests with a slab allocator References: <51818A5C.1080903@inktank.com> In-Reply-To: <51818A5C.1080903@inktank.com> X-Gm-Message-State: ALoCoQnpykQMjfSG9GEBBrOYm/R7SUqlQmQcet2OSCLqbihCHcHd0GIpMvWC9LnEVVfUzyg4ujJS Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org Create a slab cache to manage rbd_img_request allocation. Nothing too fancy at this point--we'll still initialize everything at allocation time (no constructor) This is part of: http://tracker.ceph.com/issues/3926 Signed-off-by: Alex Elder Reviewed-by: Josh Durgin --- drivers/block/rbd.c | 39 ++++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index a6e5fe3..005c397 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -40,6 +40,7 @@ #include #include #include +#include #include "rbd_types.h" @@ -344,6 +345,8 @@ static DEFINE_SPINLOCK(rbd_dev_list_lock); static LIST_HEAD(rbd_client_list); /* clients */ static DEFINE_SPINLOCK(rbd_client_list_lock); +static struct kmem_cache *rbd_img_request_cache; + static int rbd_img_request_submit(struct rbd_img_request *img_request); static void rbd_dev_device_release(struct device *dev); @@ -1821,7 +1824,7 @@ static struct rbd_img_request *rbd_img_request_create( { struct rbd_img_request *img_request; - img_request = kmalloc(sizeof (*img_request), GFP_ATOMIC); + img_request = kmem_cache_alloc(rbd_img_request_cache, GFP_KERNEL); if (!img_request) return NULL; @@ -1884,7 +1887,7 @@ static void rbd_img_request_destroy(struct kref *kref) if (img_request_child_test(img_request)) rbd_obj_request_put(img_request->obj_request); - kfree(img_request); + kmem_cache_free(rbd_img_request_cache, img_request); } static bool rbd_img_obj_end_request(struct rbd_obj_request *obj_request) @@ -4992,6 +4995,26 @@ static void rbd_sysfs_cleanup(void) device_unregister(&rbd_root_dev); } +static int rbd_slab_init(void) +{ + rbd_assert(!rbd_img_request_cache); + rbd_img_request_cache = kmem_cache_create("rbd_img_request", + sizeof (struct rbd_img_request), + __alignof__(struct rbd_img_request), + 0, NULL); + if (rbd_img_request_cache) + return 0; + + return -ENOMEM; +} + +static void rbd_slab_exit(void) +{ + rbd_assert(rbd_img_request_cache); + kmem_cache_destroy(rbd_img_request_cache); + rbd_img_request_cache = NULL; +} + static int __init rbd_init(void) { int rc; @@ -5001,16 +5024,22 @@ static int __init rbd_init(void) return -EINVAL; } - rc = rbd_sysfs_init(); + rc = rbd_slab_init(); if (rc) return rc; - pr_info("loaded " RBD_DRV_NAME_LONG "\n"); - return 0; + rc = rbd_sysfs_init(); + if (rc) + rbd_slab_exit(); + else + pr_info("loaded " RBD_DRV_NAME_LONG "\n"); + + return rc; } static void __exit rbd_exit(void) { rbd_sysfs_cleanup(); + rbd_slab_exit(); } module_init(rbd_init);