Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp4209749imm; Fri, 18 May 2018 00:55:50 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqUO5za+cHDRGn623nU7T+qh1x5PnPq3GtbFNDrLBWuttk1VRQ8pi1KiHWdgBnSm85vim2G X-Received: by 2002:a17:902:2826:: with SMTP id e35-v6mr8475473plb.348.1526630149959; Fri, 18 May 2018 00:55:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526630149; cv=none; d=google.com; s=arc-20160816; b=AaNLtc1uUutd7RsnTwWdXehs1jLXoF7mT3XY+i7YurrhGoVLF0H3w8yQGk6ucOjScd qYD+ZeDDhSqBCNpfnl+O7h0PfZndQ5BzrJxr7nzusENfyyIX/g2iMIr/PxGeVtKhp5V5 Qofa1F9L39Dd2H1HDln2tLcCGnRZHfTugp8j45xQn/pAFQFF2Ig0Gccefp/DmSj6yki3 q+nio6mPoQxp46CBpw8pSi6c9U+7Cv7W+O71ZzENyYpN0VORiX8ARCtSZzruf6XX1EuT e4N179G2zwFM+Mu5osBOqC1d/f10lenwvxxn7UWToIUSOq8E2YwZQ7wmB/SspgbCDIoW NRGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=uBsSVcy5JNVxySpLYvu6S7XLmYJGti7WAHsSQ4rF3Vc=; b=BY5TIiqvrc9VaZICqCsAZtwazmchCC15myibuKQ9RCj/r5vhLM3WB4vw0kibhWnFI1 7CEBUqInt63BLHl9FH29m/zvfd8dsWt1/NL4S9hDGaiDDsj0Bgpun1qFz9bNmeYkiAvg 2wJe8x+T29GZw6wQ4fDxoeV4g1omjN3kLgTe5aZCLEWIwx7y6iQFLKKyHr1EahTNF6P2 M9/7iJ+i89C6fGXU4snSKRT4z/gPufQwiR+klXeRcp3J8EtuR3BUtkfQ4CnHWTCR7iWn 241tIQljTRj611bO6tc48abcuP0Ie/2VC9ZXC7xlMajpxmPovyNdEZOR7to4rP/WsNtU fkGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=KRjwOIXM; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s22-v6si7201053plp.216.2018.05.18.00.55.36; Fri, 18 May 2018 00:55:49 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=KRjwOIXM; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752238AbeERHzP (ORCPT + 99 others); Fri, 18 May 2018 03:55:15 -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-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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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), -- 2.17.0