From patchwork Fri May 18 07:49:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Overstreet X-Patchwork-Id: 10408481 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D0656602CB for ; Fri, 18 May 2018 07:55:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C367128875 for ; Fri, 18 May 2018 07:55:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B7E3328899; Fri, 18 May 2018 07:55:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 51AAC28875 for ; Fri, 18 May 2018 07:55:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750888AbeERHzO (ORCPT ); Fri, 18 May 2018 03:55:14 -0400 Received: from mail-qk0-f195.google.com ([209.85.220.195]:41912 "EHLO mail-qk0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751112AbeERHt6 (ORCPT ); Fri, 18 May 2018 03:49:58 -0400 Received: by mail-qk0-f195.google.com with SMTP id d125-v6so5724327qkb.8; Fri, 18 May 2018 00:49:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=uBsSVcy5JNVxySpLYvu6S7XLmYJGti7WAHsSQ4rF3Vc=; b=KRjwOIXMlcxEaHDz7Aj8jB6t8KoSeL0QOt5tq8ZM+RqW80shBrY6tsTtybB6ciVU97 1HqikxY0hPaywRgYhm5o7FE5BnlIs+tQZkf6ONn5cWjyvLtBn+jXsuhqcEEZ0iIXkrsQ u9RcBNf8kPzKwcvwzlmhWCx2c7T824pkgcuK3T5lNK82LfE9mg7Scm2wVws7Jd7SPELq arenVoZXk/1HQWvktlriMSDCZT5SzIa5yMrQBTNjjo4GpavXPcJtiS6Fv13jPxFD1Z5U JmK+ACaD/z4Scs/FQ+H+I01K9BkfTwuJC2QFFO5hlMHcNCaZV6VSH6Y+PdiNHAcoR+kf Maqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=uBsSVcy5JNVxySpLYvu6S7XLmYJGti7WAHsSQ4rF3Vc=; b=QfxBU2QEKRLbVH6ENuoZ32Dlebpa4CLp7tniaSSfyJQgt1fB8qjVuV7gf/Yo2XfNhZ 9u1z0enmywV2DfQHCiTxgxf+Vqq+5C4Kd9RryG1GyzmNgSWD+AHWJI4aEn8WPpb9pSwT Vn9UShlTZU79u0b36Ron54wGIICrQv3bNeK735Wyonwc3TaFwL3TsD+MpQYMeJ1wYdyG Pk1VMN3T7F1N+bflr1d2SJndQSqrlcClP0yySE03QuGSOlIPCUoLkd0gXQHQglvJ8LLV oscWqiDsLdm3IAx3nCbI252WxpmJt38CsGTTcyWU8dctGkRSTc4bEsvAejErpaUjnZak OOwQ== X-Gm-Message-State: ALKqPwfFgHMDrCwDVUA6gCEx+Kda9I4Nofvfdgf+1hLG84e8EzypB+c9 uXdCIBxcQ5WyGGBsD29tVw1uYaY5UA== X-Google-Smtp-Source: AB8JxZpkZZaEp9+wqUh80aqQt5apTLotFEbqs2AsQJ4h6hw8wGKRazZy8sgMPmB1xFPLH1AF8ZJ/aQ== X-Received: by 2002:a37:85c6:: with SMTP id h189-v6mr2188931qkd.360.1526629796648; Fri, 18 May 2018 00:49:56 -0700 (PDT) Received: from localhost.localdomain (c-71-234-172-214.hsd1.vt.comcast.net. [71.234.172.214]) by smtp.gmail.com with ESMTPSA id s64-v6sm5443004qkl.85.2018.05.18.00.49.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 May 2018 00:49:55 -0700 (PDT) From: Kent Overstreet To: linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, linux-mm@kvack.org, Jens Axboe , Ingo Molnar Cc: Kent Overstreet Subject: [PATCH 03/10] block: Add bioset_init()/bioset_exit() Date: Fri, 18 May 2018 03:49:03 -0400 Message-Id: <20180518074918.13816-6-kent.overstreet@gmail.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180518074918.13816-1-kent.overstreet@gmail.com> References: <20180518074918.13816-1-kent.overstreet@gmail.com> Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Similarly to mempool_init()/mempool_exit(), take a pointer indirection out of allocation/freeing by allowing biosets to be embedded in other structs. Signed-off-by: Kent Overstreet Reviewed-by: Johannes Thumshirn --- block/bio.c | 93 +++++++++++++++++++++++++++++++-------------- include/linux/bio.h | 2 + 2 files changed, 67 insertions(+), 28 deletions(-) diff --git a/block/bio.c b/block/bio.c index 360e9bcea5..980befd919 100644 --- a/block/bio.c +++ b/block/bio.c @@ -1856,21 +1856,83 @@ int biovec_init_pool(mempool_t *pool, int pool_entries) return mempool_init_slab_pool(pool, pool_entries, bp->slab); } -void bioset_free(struct bio_set *bs) +/* + * bioset_exit - exit a bioset initialized with bioset_init() + * + * May be called on a zeroed but uninitialized bioset (i.e. allocated with + * kzalloc()). + */ +void bioset_exit(struct bio_set *bs) { if (bs->rescue_workqueue) destroy_workqueue(bs->rescue_workqueue); + bs->rescue_workqueue = NULL; mempool_exit(&bs->bio_pool); mempool_exit(&bs->bvec_pool); bioset_integrity_free(bs); - bio_put_slab(bs); + if (bs->bio_slab) + bio_put_slab(bs); + bs->bio_slab = NULL; +} +EXPORT_SYMBOL(bioset_exit); +void bioset_free(struct bio_set *bs) +{ + bioset_exit(bs); kfree(bs); } EXPORT_SYMBOL(bioset_free); +/** + * bioset_init - Initialize a bio_set + * @pool_size: Number of bio and bio_vecs to cache in the mempool + * @front_pad: Number of bytes to allocate in front of the returned bio + * @flags: Flags to modify behavior, currently %BIOSET_NEED_BVECS + * and %BIOSET_NEED_RESCUER + * + * Similar to bioset_create(), but initializes a passed-in bioset instead of + * separately allocating it. + */ +int bioset_init(struct bio_set *bs, + unsigned int pool_size, + unsigned int front_pad, + int flags) +{ + unsigned int back_pad = BIO_INLINE_VECS * sizeof(struct bio_vec); + + bs->front_pad = front_pad; + + spin_lock_init(&bs->rescue_lock); + bio_list_init(&bs->rescue_list); + INIT_WORK(&bs->rescue_work, bio_alloc_rescue); + + bs->bio_slab = bio_find_or_create_slab(front_pad + back_pad); + if (!bs->bio_slab) + return -ENOMEM; + + if (mempool_init_slab_pool(&bs->bio_pool, pool_size, bs->bio_slab)) + goto bad; + + if ((flags & BIOSET_NEED_BVECS) && + biovec_init_pool(&bs->bvec_pool, pool_size)) + goto bad; + + if (!(flags & BIOSET_NEED_RESCUER)) + return 0; + + bs->rescue_workqueue = alloc_workqueue("bioset", WQ_MEM_RECLAIM, 0); + if (!bs->rescue_workqueue) + goto bad; + + return 0; +bad: + bioset_exit(bs); + return -ENOMEM; +} +EXPORT_SYMBOL(bioset_init); + /** * bioset_create - Create a bio_set * @pool_size: Number of bio and bio_vecs to cache in the mempool @@ -1895,43 +1957,18 @@ struct bio_set *bioset_create(unsigned int pool_size, unsigned int front_pad, int flags) { - unsigned int back_pad = BIO_INLINE_VECS * sizeof(struct bio_vec); struct bio_set *bs; bs = kzalloc(sizeof(*bs), GFP_KERNEL); if (!bs) return NULL; - bs->front_pad = front_pad; - - spin_lock_init(&bs->rescue_lock); - bio_list_init(&bs->rescue_list); - INIT_WORK(&bs->rescue_work, bio_alloc_rescue); - - bs->bio_slab = bio_find_or_create_slab(front_pad + back_pad); - if (!bs->bio_slab) { + if (bioset_init(bs, pool_size, front_pad, flags)) { kfree(bs); return NULL; } - if (mempool_init_slab_pool(&bs->bio_pool, pool_size, bs->bio_slab)) - goto bad; - - if ((flags & BIOSET_NEED_BVECS) && - biovec_init_pool(&bs->bvec_pool, pool_size)) - goto bad; - - if (!(flags & BIOSET_NEED_RESCUER)) - return bs; - - bs->rescue_workqueue = alloc_workqueue("bioset", WQ_MEM_RECLAIM, 0); - if (!bs->rescue_workqueue) - goto bad; - return bs; -bad: - bioset_free(bs); - return NULL; } EXPORT_SYMBOL(bioset_create); diff --git a/include/linux/bio.h b/include/linux/bio.h index 720f7261d0..fa3cf94a50 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -406,6 +406,8 @@ static inline struct bio *bio_next_split(struct bio *bio, int sectors, return bio_split(bio, sectors, gfp, bs); } +extern int bioset_init(struct bio_set *, unsigned int, unsigned int, int flags); +extern void bioset_exit(struct bio_set *); extern struct bio_set *bioset_create(unsigned int, unsigned int, int flags); enum { BIOSET_NEED_BVECS = BIT(0),