From patchwork Fri Mar 8 10:15:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengguang Xu X-Patchwork-Id: 10844479 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8BDDE139A for ; Fri, 8 Mar 2019 10:16:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 76CB92E3C8 for ; Fri, 8 Mar 2019 10:16:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 69E612E614; Fri, 8 Mar 2019 10:16:17 +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=-7.9 required=2.0 tests=BAYES_00,FREEMAIL_FROM, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham 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 00CE62E3C8 for ; Fri, 8 Mar 2019 10:16:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725975AbfCHKQQ (ORCPT ); Fri, 8 Mar 2019 05:16:16 -0500 Received: from mout.gmx.net ([212.227.15.19]:35409 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725789AbfCHKQQ (ORCPT ); Fri, 8 Mar 2019 05:16:16 -0500 Received: from localhost.localdomain ([218.18.229.179]) by mail.gmx.com (mrgmx003 [212.227.17.184]) with ESMTPSA (Nemesis) id 0MbgKD-1hL6yW0qIP-00J4Dx; Fri, 08 Mar 2019 11:16:13 +0100 From: Chengguang Xu To: axboe@kernel.dk Cc: linux-block@vger.kernel.org, Chengguang Xu Subject: [PATCH 1/2] block: increase bio_slab_nr only for necessary case Date: Fri, 8 Mar 2019 18:15:39 +0800 Message-Id: <20190308101540.24337-1-cgxu519@gmx.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-Provags-ID: V03:K1:NJDGC73ptg56T/6PaU11+peg/vXB/xH6KytvXqBjWctczMg2eP5 YdV1cWDthcvwqtkDV1fkZknscnzd85RUbbhB5tAV/GkSh0nE1tixENqbsmJ7y3ucrBKrn6z DtzuvNEnTpaVEuhV1CKGz3Txyin7vBM8k6CBsmIUzw/8oDaxj4Af7C69L9EoJ7O86+4L/AN 9hzAN8A+PfwqZGOan/MFw== X-UI-Out-Filterresults: notjunk:1;V03:K0:yRDS1EQYRSE=:NkSoPHc0/qrC6pCYPoPCNh aL+ldbRrA1LACGHD9E0Q0vS6n/I3Xx/ctLUwf+tB4VY1rmDou+qzwKV5qqKC5XWIKbGaz0ogl 5t4JmCCp+v8F/nksg3SyKVnvHKSyE+m7XIQB0tOQWWPVJJC+EUb6MAAghi2fOEwXCVbQn45b3 NCCJAQLmSfcuf51/IT0h0VU/OnLYH2Vrx+2drgx32RBk3V0IK3Y3RlpZw/0GY9RDWSnBF559S lWDeevk7TCX1mHtxY2TcFWFGyoEefcarGRaew0wpD//U0GfD4K3+QIb3qI/+qMjlLVK25ESGh 9ECQKcrOLD5LcG4ZXy0jJB2cSqsxNzeQWXT+2AA2W2uIW1GzjunBjRcsC6g8qlJAei+E7TMqP PicmfBf1R5zCCItNh3JXPS+K2waCFwZq9HBLzV6Izl5WI1fd5cCtF4DgQBxmhBWEItyFSNkVN WKsUZ5cyQNXVmotmxoqiOMflU1OU8o+vp0c0iEeJ+iQpclo/CafYLbZOZP0tyYGlEFf/znfh2 PmAgxGH0DuzYw4e6ai/0oMNRiAeMjWWdWGTWLBTJ1fNPtXcWLWxWfPZ59/vyKjp3W3ByAb1sk 4UCzFWpcDd6qlysaH/iogc4q0+QPtvIABPVCexT+P+b2Vpk59eAZUtTVgqwfoucPkRTdDZbeL h6D6Kpc5i2RtW/qtQ3VrQUyn2hT3A4Xay6/7FriAeC6mMfeSvcLIyP4O+ktdAFlv/M1Zvt9Px ypGj9kMMASB/b2IdwDUpHJ//i+k3cWvwIhE6DCWg8Vu9rHgb/DPowLaXOleY0pvuBpiOf7kCk FxEsBxX9brjKlUM37HblpmxxRxSiq1ZYZkBLvnYya5PZKC93BjUXTHUTrDbeNiSkR3dwLz6Te STw2k2z0Qy4YlCPGU9C8Y/SnhWxmGAI8CJHWa89HCvuQ7bebj8TR87l1NKL2um 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 When fail to create new cache in bio_find_or_create_slab(), we should not increase bio_slab_nr because it will cause referring uninitilized data in subsequent search. Signed-off-by: Chengguang Xu --- block/bio.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/block/bio.c b/block/bio.c index 4db1008309ed..8081906f5d01 100644 --- a/block/bio.c +++ b/block/bio.c @@ -109,7 +109,7 @@ static struct kmem_cache *bio_find_or_create_slab(unsigned int extra_size) bio_slabs = new_bio_slabs; } if (entry == -1) - entry = bio_slab_nr++; + entry = bio_slab_nr; bslab = &bio_slabs[entry]; @@ -122,6 +122,10 @@ static struct kmem_cache *bio_find_or_create_slab(unsigned int extra_size) bslab->slab = slab; bslab->slab_ref = 1; bslab->slab_size = sz; + + if (entry == bio_slab_nr) + bio_slab_nr++; + out_unlock: mutex_unlock(&bio_slab_lock); return slab; From patchwork Fri Mar 8 10:15:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengguang Xu X-Patchwork-Id: 10844481 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0D7321515 for ; Fri, 8 Mar 2019 10:16:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EC9FE2E3C8 for ; Fri, 8 Mar 2019 10:16:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DFFE62E614; Fri, 8 Mar 2019 10:16:21 +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=-7.9 required=2.0 tests=BAYES_00,FREEMAIL_FROM, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham 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 924532E3C8 for ; Fri, 8 Mar 2019 10:16:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726249AbfCHKQU (ORCPT ); Fri, 8 Mar 2019 05:16:20 -0500 Received: from mout.gmx.net ([212.227.15.19]:47579 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725789AbfCHKQU (ORCPT ); Fri, 8 Mar 2019 05:16:20 -0500 Received: from localhost.localdomain ([218.18.229.179]) by mail.gmx.com (mrgmx003 [212.227.17.184]) with ESMTPSA (Nemesis) id 0Lhfu5-1ggfQZ0ULZ-00mqWT; Fri, 08 Mar 2019 11:16:18 +0100 From: Chengguang Xu To: axboe@kernel.dk Cc: linux-block@vger.kernel.org, Chengguang Xu Subject: [PATCH 2/2] block: code cleanup for bio_find_or_create_slab() Date: Fri, 8 Mar 2019 18:15:40 +0800 Message-Id: <20190308101540.24337-2-cgxu519@gmx.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190308101540.24337-1-cgxu519@gmx.com> References: <20190308101540.24337-1-cgxu519@gmx.com> MIME-Version: 1.0 X-Provags-ID: V03:K1:useDhvtVRU6tlxRXQy99R+6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8 E9h2ELWjdLF9An+01GD5nyLxAd3lTqNexvnOs4VY/6gDi6Y7gs4cG6Wflzu+YauXLEqVhSSno 2UO4nT1Q4iP+bMpNe8qXtnklbJ6+KElp/oPzzxrLoegJoVoC6mflJpdCfabRdC 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 It's just a simple code cleanup, not functional change. Signed-off-by: Chengguang Xu --- block/bio.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/block/bio.c b/block/bio.c index 8081906f5d01..fefd49a561ab 100644 --- a/block/bio.c +++ b/block/bio.c @@ -90,29 +90,27 @@ static struct kmem_cache *bio_find_or_create_slab(unsigned int extra_size) else if (bslab->slab_size == sz) { slab = bslab->slab; bslab->slab_ref++; - break; + goto out_unlock; } i++; } - if (slab) - goto out_unlock; - - if (bio_slab_nr == bio_slab_max && entry == -1) { - new_bio_slab_max = bio_slab_max << 1; - new_bio_slabs = krealloc(bio_slabs, + if (entry == -1) { + if (bio_slab_nr == bio_slab_max) { + new_bio_slab_max = bio_slab_max << 1; + new_bio_slabs = krealloc(bio_slabs, new_bio_slab_max * sizeof(struct bio_slab), GFP_KERNEL); - if (!new_bio_slabs) - goto out_unlock; - bio_slab_max = new_bio_slab_max; - bio_slabs = new_bio_slabs; - } - if (entry == -1) + if (!new_bio_slabs) + goto out_unlock; + bio_slab_max = new_bio_slab_max; + bio_slabs = new_bio_slabs; + } + entry = bio_slab_nr; + } bslab = &bio_slabs[entry]; - snprintf(bslab->name, sizeof(bslab->name), "bio-%d", entry); slab = kmem_cache_create(bslab->name, sz, ARCH_KMALLOC_MINALIGN, SLAB_HWCACHE_ALIGN, NULL);