Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934067AbcLHBbC (ORCPT ); Wed, 7 Dec 2016 20:31:02 -0500 Received: from mail-wm0-f46.google.com ([74.125.82.46]:38373 "EHLO mail-wm0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932372AbcLHBbB (ORCPT ); Wed, 7 Dec 2016 20:31:01 -0500 From: Rasmus Villemoes To: Tejun Heo , Andrew Morton Cc: linux-kernel@vger.kernel.org, Lai Jiangshan , Jens Axboe , Greg Kroah-Hartman , Rasmus Villemoes Subject: [RFC 01/10] lib/idr.c: reused free bitmaps are already clear Date: Thu, 8 Dec 2016 02:22:56 +0100 Message-Id: <1481160187-9652-2-git-send-email-linux@rasmusvillemoes.dk> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1481160187-9652-1-git-send-email-linux@rasmusvillemoes.dk> References: <1481160187-9652-1-git-send-email-linux@rasmusvillemoes.dk> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1157 Lines: 35 If we're recycling a previously used struct ida_bitmap, it ended up in ->free_bitmap precisely because it was all zeroes. Thus, by using kzalloc in ida_pre_get we can avoid doing the memset while holding whatever locks protects the ida (which, judging by the number of callers of ida_simple_get vs ida_get_new_above, is usually always the global simple_ida_lock). Signed-off-by: Rasmus Villemoes --- lib/idr.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/idr.c b/lib/idr.c index 6098336df267..9cbfae251d77 100644 --- a/lib/idr.c +++ b/lib/idr.c @@ -903,7 +903,7 @@ int ida_pre_get(struct ida *ida, gfp_t gfp_mask) if (!ida->free_bitmap) { struct ida_bitmap *bitmap; - bitmap = kmalloc(sizeof(struct ida_bitmap), gfp_mask); + bitmap = kzalloc(sizeof(struct ida_bitmap), gfp_mask); if (!bitmap) return 0; @@ -962,7 +962,6 @@ int ida_get_new_above(struct ida *ida, int starting_id, int *p_id) if (!bitmap) return -EAGAIN; - memset(bitmap, 0, sizeof(struct ida_bitmap)); rcu_assign_pointer(pa[0]->ary[idr_id & IDR_MASK], (void *)bitmap); pa[0]->count++; -- 2.1.4