From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752108AbdKVVJT (ORCPT ); Wed, 22 Nov 2017 16:09:19 -0500 Received: from bombadil.infradead.org ([65.50.211.133]:58689 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751888AbdKVVIU (ORCPT ); Wed, 22 Nov 2017 16:08:20 -0500 From: Matthew Wilcox To: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Matthew Wilcox Subject: [PATCH 48/62] block: Remove IDR preloading Date: Wed, 22 Nov 2017 13:07:25 -0800 Message-Id: <20171122210739.29916-49-willy@infradead.org> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20171122210739.29916-1-willy@infradead.org> References: <20171122210739.29916-1-willy@infradead.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Matthew Wilcox The IDR now handles its own locking, so if we remove the locking in genhd, we can also remove the memory preloading. The genhd needs to protect the object retrieved from the IDR against removal until its refcount has been elevated, so hold the IDR's lock during lookup. Signed-off-by: Matthew Wilcox --- block/genhd.c | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/block/genhd.c b/block/genhd.c index c2223f12a805..d50bd99e8ce2 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -30,10 +30,7 @@ struct kobject *block_depr; /* for extended dynamic devt allocation, currently only one major is used */ #define NR_EXT_DEVT (1 << MINORBITS) -/* For extended devt allocation. ext_devt_lock prevents look up - * results from going away underneath its user. - */ -static DEFINE_SPINLOCK(ext_devt_lock); +/* For extended devt allocation. */ static DEFINE_IDR(ext_devt_idr); static const struct device_type disk_type; @@ -467,14 +464,7 @@ int blk_alloc_devt(struct hd_struct *part, dev_t *devt) return 0; } - /* allocate ext devt */ - idr_preload(GFP_KERNEL); - - spin_lock_bh(&ext_devt_lock); - idx = idr_alloc(&ext_devt_idr, part, 0, NR_EXT_DEVT, GFP_NOWAIT); - spin_unlock_bh(&ext_devt_lock); - - idr_preload_end(); + idx = idr_alloc(&ext_devt_idr, part, 0, NR_EXT_DEVT, GFP_KERNEL); if (idx < 0) return idx == -ENOSPC ? -EBUSY : idx; @@ -496,11 +486,8 @@ void blk_free_devt(dev_t devt) if (devt == MKDEV(0, 0)) return; - if (MAJOR(devt) == BLOCK_EXT_MAJOR) { - spin_lock_bh(&ext_devt_lock); + if (MAJOR(devt) == BLOCK_EXT_MAJOR) idr_remove(&ext_devt_idr, blk_mangle_minor(MINOR(devt))); - spin_unlock_bh(&ext_devt_lock); - } } static char *bdevt_str(dev_t devt, char *buf) @@ -789,13 +776,13 @@ struct gendisk *get_gendisk(dev_t devt, int *partno) } else { struct hd_struct *part; - spin_lock_bh(&ext_devt_lock); + idr_lock_bh(&ext_devt_idr); part = idr_find(&ext_devt_idr, blk_mangle_minor(MINOR(devt))); if (part && get_disk(part_to_disk(part))) { *partno = part->partno; disk = part_to_disk(part); } - spin_unlock_bh(&ext_devt_lock); + idr_unlock_bh(&ext_devt_idr); } if (disk && unlikely(disk->flags & GENHD_FL_HIDDEN)) { -- 2.15.0