From patchwork Wed May 9 01:33:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Overstreet X-Patchwork-Id: 10387945 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 BAE08602D8 for ; Wed, 9 May 2018 01:34:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 87E1B28FF5 for ; Wed, 9 May 2018 01:34:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7CB0928FF7; Wed, 9 May 2018 01:34:26 +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 E512C28FF5 for ; Wed, 9 May 2018 01:34:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AAB6D6B030E; Tue, 8 May 2018 21:34:20 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id A2CD06B030F; Tue, 8 May 2018 21:34:20 -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 858696B0310; Tue, 8 May 2018 21:34:20 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qk0-f200.google.com (mail-qk0-f200.google.com [209.85.220.200]) by kanga.kvack.org (Postfix) with ESMTP id 57FA46B030E for ; Tue, 8 May 2018 21:34:20 -0400 (EDT) Received: by mail-qk0-f200.google.com with SMTP id t130so25135246qke.11 for ; Tue, 08 May 2018 18:34:20 -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=qfZjSkEgoLg+xsU5SXglHsf3wrFOEJkvrepypR9pe2zsWojnKpcZS8WyZfxPOs8DaK p2Te4bcK7zK11YVqv9DouywT4Iz8NXf21b147DC3wexddDsjOyrUnQ379mle67SGwtag /0T6lSaDvccXwjlAtZrpRlRokwbmGk+xMBgQkrvYWrPq8PBVC/NEQNdDRlI4hQBtbYdJ vv1Hg4RmQ2mhcdmDfNh/QyvAsUP5fWdk3XMC9KzqsUq7uQutSWopLQoSuScIjRqQOxGR ZL0noDAQH1oiKuURmS16ZHIRXIHUkqZMvJ0kSYYuoeavsZ+LxblwcelMEVPFoUSfq01V aXbg== X-Gm-Message-State: ALQs6tBNnuK4lJDImVP0llVN04/UkG4rxeRjxzr8no/SS3Xj7Z0FS8pt HLkKiD1UohJ03BJOSEJIMLV6YqPkcn7KFnQ24X+WCPy8qqtLt/r6QP6CNPD7PzAyw4P74U8LnxT RWk53LHoyY0pcAf/LfUOEM9CYUkHuSlHtLySV97U5wCt0XPlDnA88SliFGJ3msC8OSrx2mLuJNM ++RztVF8xhs2grWPiiy7vYQeZuRn7JtqLnHVSpOKpfRtOSvKMXSctzl216cIs02gPRsUuMgqBGc bYrxFJa9gYTJgNn8sUeb4IyzVWA2e9NTsrsGKTlP7mWd5ZIspaDvQYzS1tdjXuwive19tSwWUNA TmzQSrL3tkUpWhBbymOZ2hkK1LESxsIL/t4EGaK7b3apLBU87wLP+tSgfesbmEWF2JwSPJ4Et+V E X-Received: by 10.233.235.211 with SMTP id b202mr36888269qkg.27.1525829660130; Tue, 08 May 2018 18:34:20 -0700 (PDT) X-Received: by 10.233.235.211 with SMTP id b202mr36888249qkg.27.1525829659487; Tue, 08 May 2018 18:34:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525829659; cv=none; d=google.com; s=arc-20160816; b=LTbrgK71I4SVSctoqPV/Yt4ni8xIInMrsp57QokoR6Eurdi2TlYX++nF0qP39fALEb QJpcQF6F40JlBdZQGmVxU4dgJH+TiySSFN8hijgq25iKQX2BCJEuZ/a2frEO+bDikpEU ajhdvGMSdkv6Lyr+zJgv62+LvFVysHFJ0825kv/KJg5NJ1TfxqwJJkEETAp1IUBIB3g3 wApSSa89RgKUBMD2Rt743EpClnAkZkRPUKHV8nDRsZ1vKjMrQHPzRFxsw9ZRYn/4PQwM xCI8cZAydp0jB6Y9NxRRe7qCPVyAnbdXBUKocSjCU5V194YbmO0//WBMfPtpm68+TQhH eJwQ== 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=zyCFN+/+XNmUdcopueymJbt9ivpCDx1Ubt9QZuF0OqTjSWJjCK42/Z2pIzP81G6rIv iH9msGYJ3QS9fHXefWRei4VpolwlAB+zUmkPVMzv3sCjDxM02ZUqjkgwKFTVSQjBG7MC Hd7zQ6uOgFcLQSdeZNkYHfaobTQwSpLEqEmCrHjWiN7O5Lcpk7UwPOLQsG+NuH+92qOd siD5dswABqKH/4tiKvDX3ExJxdoNPd8G2uFJd6blk2QXh/3z/EqtLOpIMgdkJhCMhgn2 CXzhuw4CGZIz2hLJeV9HC7uyLxFS8imc/thkFJ375OL3DAbdzxf2W3RliqEglNMi6FID BmTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=iV0LWIeJ; 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 f53-v6sor16507715qtf.115.2018.05.08.18.34.19 for (Google Transport Security); Tue, 08 May 2018 18:34:19 -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=iV0LWIeJ; 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=iV0LWIeJlBcdlDBYNLSB3ZZfif5BSqtnWqxpDGaTliNq+uM0FevVvGKGFcGWnuLoYr E19sK0s3h738ik6i/pOLjD6oLJ/tSvfMoWSS5evlPgFAFzYgBEFUhZg8/eW6lauxydeB Qz7R6hxklGB2Fh6VzAC2XcxxSYtEyszMxBpnh5ies8jW2EJxXcmgdIG/ZMGFvChPPWH8 OYxRF+WlZZjU3/NzbXE4iqXLJlcTOrA4P+dEVCg/geGqONBXhY1USvhETV4P8rzOG9eU ohp/ufhi1QqFpFAERHcJ0rXRBgKMje1xtBBRAmtIorLJ+IfEogvYT8J5lP6p93kzwnxZ c4Lw== X-Google-Smtp-Source: AB8JxZr+dYlvkGFoVTT2KQhBLEyS8svDCwG8Dfj2Ol6yJDmJVaK9JVWTIdJa9sG6HLNbA59ktbE6vg== 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> 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 --- 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),