Received: by 10.223.164.202 with SMTP id h10csp660304wrb; Wed, 22 Nov 2017 13:13:48 -0800 (PST) X-Google-Smtp-Source: AGs4zMZ928OMhLdfgJ7btFZ7M6vM7z8tipW43N8d+Iqpdh/bUxo4og5qjbJT3AaFHL+voIsQ8Mnw X-Received: by 10.84.128.77 with SMTP id 71mr22741043pla.197.1511385228065; Wed, 22 Nov 2017 13:13:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511385228; cv=none; d=google.com; s=arc-20160816; b=vznkhArPJjriIZlkMlLS/8s2JQv6edPOne8mRYFH8YHLwQnSkpdP7w5BNiEmBrlJxh exyxIgTNpI2Smr+rfCrziciIgmvpvl+/77GkkiNCOmzleifNFa4X2xuQggzZjlNjLuro W5yWRr6rONiQtOROknlCSplq2LGX1Ij6AI7KEY3q5g/ftzXH5s/uS/e/d2lPtK5CAtmF +nhYY43AR+BQTmf9CeJVSrjKsDxrBdFQCoSe+3XNF/9vBtEw9Px7dpPftGTVZ2sWRih0 FvsgE9iW4mPxpgMkQ5W4pbqtfNBq2yem9KNAKKL7XOiV8KSb/67OFdrLrFQ3qxPBwD32 5bkg== 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=G9x8tP8vKUsHETqunh3tHWJIQKjvF6To3l7N6RqjHVM=; b=PHJxgfBQdwZ2OaotFrJOVMQBYIGp0nC61sYZ682azUivPxEuZZb198IrBbRcgWHGLf u6S/kK/YRvJR9EI4fyJaqnfcKB6Culh3P9wXXNC0NroqkurEkYWsNAjt9+H8/AUXExa9 LhWZr9NTCGLgYr5+tLh01Smfg5R0Gag47WdPcVvr5iBC9hSdRTM64q9P8qf3MrUpw666 SC17eeLgAfTqaJN7CTUw6Jo8AXfudB8Bcmt97AM4JGaN0EioQF93ErxQgYu86Wr+VxH0 UQv1Uxbki4rxuXmR2mK1oKH4SSwhtqEu2cQVt0XCT0qr0QOn2v2l3IHV2uCjrszW2JuR srVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=QWd2RTfm; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i2si5776404pgr.99.2017.11.22.13.13.36; Wed, 22 Nov 2017 13:13:48 -0800 (PST) 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=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=QWd2RTfm; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752200AbdKVVLi (ORCPT + 77 others); Wed, 22 Nov 2017 16:11:38 -0500 Received: from bombadil.infradead.org ([65.50.211.133]:58121 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751724AbdKVVIU (ORCPT ); Wed, 22 Nov 2017 16:08:20 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=G9x8tP8vKUsHETqunh3tHWJIQKjvF6To3l7N6RqjHVM=; b=QWd2RTfmXtiOpEnycyuh84i3G 2JfObCmPluhXxqzBgOgd5lVEtZvEA8tDALx1j439H8wDoeARDXSucpWY8NBnHXIxEKV5d3Es4lmd5 Izif/cO8CjemSq3ReuKjxMLgffTLlDaSq53VPIr5+aXHtlx4C9rLgGAoC7Ujmaq7lDpMxTfPe59Bm r0d0SwXUQPzdlRfuECmhDRR/ZqDJcpugmkERsLeDoeUM69+h4ZsulBcL6XUDKkPAdIXn491MazE4E XWoXWRlmbO2aBGACWVdr2TGuRTfvLyKIHXrk+SoSzmKbU5m/vBVIQwmjpSl3HvcO+5czAv63ng9NT DiNguZGmA==; Received: from willy by bombadil.infradead.org with local (Exim 4.87 #1 (Red Hat Linux)) id 1eHcFn-0007y7-Tk; Wed, 22 Nov 2017 21:08:19 +0000 From: Matthew Wilcox To: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Matthew Wilcox Subject: [PATCH 52/62] ipc: Remove call to idr_preload Date: Wed, 22 Nov 2017 13:07:29 -0800 Message-Id: <20171122210739.29916-53-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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Matthew Wilcox The ipc code follows a different pattern to most IDR preload users; the lock that it is holding is embedded in the object, not protecting the IDR (the IDR is protected by an rwsem). Instead of dropping the lock, allocating memory and retrying, we reserve a slot in the tree before grabbing the lock, then merely replace the NULL entry with the initialised object. Signed-off-by: Matthew Wilcox --- ipc/util.c | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/ipc/util.c b/ipc/util.c index ff045fec8d83..9a20354ce4fb 100644 --- a/ipc/util.c +++ b/ipc/util.c @@ -193,10 +193,10 @@ static struct kern_ipc_perm *ipc_findkey(struct ipc_ids *ids, key_t key) /* * Specify desired id for next allocated IPC object. */ -#define ipc_idr_alloc(ids, new) \ - idr_alloc(&(ids)->ipcs_idr, (new), \ +#define ipc_idr_alloc(ids) \ + idr_alloc(&(ids)->ipcs_idr, NULL, \ (ids)->next_id < 0 ? 0 : ipcid_to_idx((ids)->next_id),\ - 0, GFP_NOWAIT) + 0, GFP_KERNEL) static inline int ipc_buildid(int id, struct ipc_ids *ids, struct kern_ipc_perm *new) @@ -214,8 +214,8 @@ static inline int ipc_buildid(int id, struct ipc_ids *ids, } #else -#define ipc_idr_alloc(ids, new) \ - idr_alloc(&(ids)->ipcs_idr, (new), 0, 0, GFP_NOWAIT) +#define ipc_idr_alloc(ids) \ + idr_alloc(&(ids)->ipcs_idr, NULL, 0, 0, GFP_KERNEL) static inline int ipc_buildid(int id, struct ipc_ids *ids, struct kern_ipc_perm *new) @@ -254,34 +254,30 @@ int ipc_addid(struct ipc_ids *ids, struct kern_ipc_perm *new, int limit) if (!ids->tables_initialized || ids->in_use >= limit) return -ENOSPC; - idr_preload(GFP_KERNEL); + id = ipc_idr_alloc(ids); + if (id < 0) + return id; refcount_set(&new->refcount, 1); spin_lock_init(&new->lock); new->deleted = false; - rcu_read_lock(); spin_lock(&new->lock); current_euid_egid(&euid, &egid); new->cuid = new->uid = euid; new->gid = new->cgid = egid; - id = ipc_idr_alloc(ids, new); - idr_preload_end(); + idr_replace(&ids->ipcs_idr, new, id); - if (id >= 0 && new->key != IPC_PRIVATE) { + if (new->key != IPC_PRIVATE) { err = rhashtable_insert_fast(&ids->key_ht, &new->khtnode, ipc_kht_params); if (err < 0) { idr_remove(&ids->ipcs_idr, id); - id = err; + spin_unlock(&new->lock); + return err; } } - if (id < 0) { - spin_unlock(&new->lock); - rcu_read_unlock(); - return id; - } ids->in_use++; if (id > ids->max_id) -- 2.15.0 From 1586134443277667864@xxx Thu Dec 07 14:08:00 +0000 2017 X-GM-THRID: 1586134443277667864 X-Gmail-Labels: Inbox,Category Promotions,HistoricalUnread