Received: by 10.192.165.148 with SMTP id m20csp4961316imm; Tue, 8 May 2018 18:37:31 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoV/C9CElgQKNFveSBLNQ/He6XndyzqkQE+pAt+oLOrY92R3mv7GB4/StJTJQE8dTlCjoG5 X-Received: by 2002:a65:4a87:: with SMTP id b7-v6mr11934953pgu.36.1525829851567; Tue, 08 May 2018 18:37:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525829851; cv=none; d=google.com; s=arc-20160816; b=oWakIOAkv3uZXxePoVg1MwjmyAWQYC+YOJrSoJgIT/tH5D0hDcNkp98mbcC7r7ncwk ZWdN19WIZ4CcfmfkoQc132phc9GrkRWqeECCNbdX6SSlhWkE9LfP+x9g7rr/1kSSQW4W Y8tptUPRRQnPsTVWXWDv06BPa8osiY5htLn/C8HX6FYQhHlzasqPNdv7YzCoB5wTkIR3 i/qT6OX2z7JXcpMOrh08IhFopnKFx3tnU7KCucCAEELfuClucw8IxGXve9rAc3H2lfhq uF8OkuwWd7fJ00l30yYu/Bb+ccz9WQ4p4PU2rMV37IU4xP081AQXmorsRnGQBH9FtlHl tSDA== 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=hNnpmGdfXwGiy9aHzkFKQywkf6doZmx2bTA/opvAwUTG0kULAtjg6ivkifGKzafj50 Mosulc0Z8k8N9Rkr9gA7q68kx49jRKa6ylgP7MhnEO2ZFwAsC06IHhlgoQbBzBL8bYBw Pz9ryBQNnk2dxbBELN8XWhqs0KRqJa2WtRw+/dA81V5GPQlhypmOhViDKYgqyaq6uYwv zBVKcY8534cFGGSfd4PMiSjrr3B4YIbKW/0Lyd3WHw694lExBl0O2EwgPV+XPPm93e3D WX+UeQ0aGjRF6qs8WCjIVpg+HcifNSie54OQBiXb97tqRvyPcCXt8ib4usMGt5oM/c22 Njgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=iV0LWIeJ; 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 f1-v6si25067037pld.168.2018.05.08.18.37.17; Tue, 08 May 2018 18:37:31 -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=iV0LWIeJ; 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 S933669AbeEIBg3 (ORCPT + 99 others); Tue, 8 May 2018 21:36:29 -0400 Received: from mail-qt0-f195.google.com ([209.85.216.195]:39185 "EHLO mail-qt0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933461AbeEIBeU (ORCPT ); Tue, 8 May 2018 21:34:20 -0400 Received: by mail-qt0-f195.google.com with SMTP id f1-v6so43693778qtj.6; Tue, 08 May 2018 18:34:20 -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=iV0LWIeJlBcdlDBYNLSB3ZZfif5BSqtnWqxpDGaTliNq+uM0FevVvGKGFcGWnuLoYr E19sK0s3h738ik6i/pOLjD6oLJ/tSvfMoWSS5evlPgFAFzYgBEFUhZg8/eW6lauxydeB Qz7R6hxklGB2Fh6VzAC2XcxxSYtEyszMxBpnh5ies8jW2EJxXcmgdIG/ZMGFvChPPWH8 OYxRF+WlZZjU3/NzbXE4iqXLJlcTOrA4P+dEVCg/geGqONBXhY1USvhETV4P8rzOG9eU ohp/ufhi1QqFpFAERHcJ0rXRBgKMje1xtBBRAmtIorLJ+IfEogvYT8J5lP6p93kzwnxZ c4Lw== 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=I18LCzcgxRMsBERWoGIKZ11flqr0mPV+D0P/j3YSoKunqYXWLj2QBTaLwE5PHaWMRi EOsv7ndGu+CqcQMuZ8BRpPHPGu1c8yDg7hcgLaEcsjG9tlOQZ++5DKvO/TaaEJh9Wrqr cv7O4rUMdK4twaftHH1tyd6ybbrfw2+oJhtYdYi8EaDPhJnu/bTUgcWlRz3jo2yCKevQ rY2q8ocguvD9PXCAj+OIYt/GpJ68imn12ul2XT+A9M3cMhsroU+Usm7FJ0yU1hjzUz/Y kG+3N8Sz4+ilXWaGqeIhIWn6k9t+/AlLXCa72OKtej+rUqDI7S8g+3tIgYgzbFCBnjPm hl0Q== X-Gm-Message-State: ALQs6tBavS2mFp6nym52fkLIuH5uIoyRK9+V34AebVExp3U9yyATtyTG eqswUtjcpBOeSjlasWl/FxOGngf0dw== X-Received: by 2002:ac8:37e9:: with SMTP id e38-v6mr25629505qtc.408.1525829659108; Tue, 08 May 2018 18:34:19 -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 x28-v6sm23719003qtx.95.2018.05.08.18.34.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 08 May 2018 18:34:18 -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: Tue, 8 May 2018 21:33:51 -0400 Message-Id: <20180509013358.16399-4-kent.overstreet@gmail.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180509013358.16399-1-kent.overstreet@gmail.com> References: <20180509013358.16399-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