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: 10408373 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 0E2D4601F9 for ; Fri, 18 May 2018 07:50:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F38AE2886E for ; Fri, 18 May 2018 07:49:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E82D328892; Fri, 18 May 2018 07:49:59 +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=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6F4522887D for ; Fri, 18 May 2018 07:49:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F2FC36B0588; Fri, 18 May 2018 03:49:57 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id EDFC16B0589; Fri, 18 May 2018 03:49:57 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DCF5B6B058A; Fri, 18 May 2018 03:49:57 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt0-f199.google.com (mail-qt0-f199.google.com [209.85.216.199]) by kanga.kvack.org (Postfix) with ESMTP id AE0626B0588 for ; Fri, 18 May 2018 03:49:57 -0400 (EDT) Received: by mail-qt0-f199.google.com with SMTP id t24-v6so6016401qtn.7 for ; Fri, 18 May 2018 00:49:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references; bh=uBsSVcy5JNVxySpLYvu6S7XLmYJGti7WAHsSQ4rF3Vc=; b=G/9tLIKx1eja1dXTMFLSENoM2m0Z8QD/riewadorUky5rOZRf6s64ukXQ1H7m0oncp QwLnQxd9VttiJQO2Thdjo+Wrdx9k++C8dis0ZFEUKWN/NugmWcutGfM4XmgRSVjt4vs0 TrD5xlFQu7pL6wdUZXQP5gogGcj29/tdYNA9cSYM0mCmoBhWFp41DHXyXTyYncXpCqxH lH3zfIEtZWwwd6GltxHxmHsvUyhV6Qd7NC2Iac49/O6RvzqiL6AAismgBkI+fkpt6N6t itI2QNhvzRJxuYo1VBvpsNXlWZfI+RyfU0ZPV1kCwOcCKsxh1i6EEXNEQWLxhWtJnCSS fz7g== X-Gm-Message-State: ALKqPwf/8p9FM4YHcboGyUw4+vinVltL5JwVI7j54o6P+PqtsFsFt6nq saDlow/FjpY/wNSiQAoLxpUBdIs6O2Np1kGaFgg2TKhFbkrAupEV/uYrz21WAUx2D6Qg9mRZbfX tudgODkAiO314z4EEgjxrW+zPm8H19WfwU2qzOR16BOLWJbIr7k5QNkqh7vPcRGxFgFMNBLahKg TILR5YfnHXLibVerqJ34aClfYFbQV4Gg8Ya2YNw/lRlv6xDl1jMECHfmOGOlf+0gWqfzBXqNapC lhnv1cNabbj9lSXouUs19DjbEH+XWezpvUHchlqik311ahcvCdGIOVKhRknAsFBFJVwO0rA/ULH ak0odDcSleNCWEJOzN6vSC5heNgrXzUV+Fjjw6O2XKeRMCDgiTHcnhI9nECbj6IZj/7qdKU7o2M P X-Received: by 2002:ac8:4611:: with SMTP id p17-v6mr7891608qtn.320.1526629797503; Fri, 18 May 2018 00:49:57 -0700 (PDT) X-Received: by 2002:ac8:4611:: with SMTP id p17-v6mr7891589qtn.320.1526629796981; Fri, 18 May 2018 00:49:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526629796; cv=none; d=google.com; s=arc-20160816; b=Pg6C89aWTS8p+YjNVi/7x/n0eq0c+G8EbHdmftRXRB00+UhD3UplF+17ZGqxM3DUF0 6cJc56FkwFcnQz+FCezrxNLrTmyo3mX9Lue503JHIETPxKe31rjCkg7PMS1pschq45MJ 3x55JaZLo76CgywrUfLyYTbkytNHO+j7stRd3Nr7pZ25R9SCrvDgvxEZFvicF+od93+e 1Kgi7Sxfokthhs5lvumh+BM6/MUBfgBcU6svitT/+YqUotk1BHfy7spbpTHPh6IYO11I 9pnircfotHww0DwrLaF/oiSsc3IiADqIHRsPo6nTdc80nIE/MT638ucJHhsfZjkx/WKC SVAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=uBsSVcy5JNVxySpLYvu6S7XLmYJGti7WAHsSQ4rF3Vc=; b=NtYqxOtPL/G15XAyrbhV8Lzk7SYTRTKi3PxGsR//EbZn7Fnt+aRe5qN7ca+I1TPu52 6Q33vqgp5w4r+tfadjbfDof3lWiSSO8/fabHv6oKhghSfEMNc6O7ydCs2iG+1/Os25FK LfSBSbj8RRpqBCVUphoOwUZbjRqTl1rDbMeieU38tx4QaPYglFpK0R0ungArrbGeEEu9 rnv9kOp4EGjhXe5xJ40Mblv/3n5Z5MOUq7sLtzNM1dlQcz0OZV8ht7L1WPKAwOlxXVlY p/ILg3ws1IFsxnOvbj+4NwfEcMJTySaWtM+ObarZ96MfQ4KP3Gnm1MjsJTVnB/P6VURl yeqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=KRjwOIXM; spf=pass (google.com: domain of kent.overstreet@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=kent.overstreet@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id m62-v6sor5762973qkf.143.2018.05.18.00.49.56 for (Google Transport Security); Fri, 18 May 2018 00:49:56 -0700 (PDT) Received-SPF: pass (google.com: domain of kent.overstreet@gmail.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=KRjwOIXM; spf=pass (google.com: domain of kent.overstreet@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=kent.overstreet@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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-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> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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),