From patchwork Thu Feb 28 18:47:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Waiman Long X-Patchwork-Id: 10833615 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 F358A139A for ; Thu, 28 Feb 2019 18:47:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DF43A2F767 for ; Thu, 28 Feb 2019 18:47:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D03752F779; Thu, 28 Feb 2019 18:47:56 +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,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 6257B2F767 for ; Thu, 28 Feb 2019 18:47:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388546AbfB1Sru (ORCPT ); Thu, 28 Feb 2019 13:47:50 -0500 Received: from mx1.redhat.com ([209.132.183.28]:36886 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388466AbfB1Srt (ORCPT ); Thu, 28 Feb 2019 13:47:49 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AF644316278D; Thu, 28 Feb 2019 18:47:48 +0000 (UTC) Received: from llong.com (ovpn-121-201.rdu2.redhat.com [10.10.121.201]) by smtp.corp.redhat.com (Postfix) with ESMTP id E0CE51973C; Thu, 28 Feb 2019 18:47:43 +0000 (UTC) From: Waiman Long To: "Luis R. Rodriguez" , Kees Cook , Andrew Morton , Jonathan Corbet Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-doc@vger.kernel.org, Al Viro , Matthew Wilcox , "Eric W. Biederman" , Takashi Iwai , Davidlohr Bueso , Manfred Spraul , Waiman Long Subject: [PATCH v12 3/3] ipc: Do cyclic id allocation with ipcmni_extend mode Date: Thu, 28 Feb 2019 13:47:25 -0500 Message-Id: <1551379645-819-4-git-send-email-longman@redhat.com> In-Reply-To: <1551379645-819-1-git-send-email-longman@redhat.com> References: <1551379645-819-1-git-send-email-longman@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Thu, 28 Feb 2019 18:47:48 +0000 (UTC) Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP For ipcmni_extend mode, the sequence number space is only 7 bits. So the chance of id reuse is relatively high compared with the non-extended mode. To alleviate this id reuse problem, the id allocation will be done cyclically to cycle through all the 24-bit id space before wrapping around when in ipcmni_extend mode. This may cause the use of more memory in term of the number of xa_nodes allocated as well as potentially more cachelines used as the xa_nodes may be spread more sparsely in this case. There is probably a slight memory and performance cost in doing cyclic id allocation. For applications that really need more than 32k unique IPC identifiers, this is a small price to pay to avoid the id reuse problem. As a result, the chance of id reuse should be even smaller in the ipcmni_extend mode. For users who worry about id reuse, they can turn on ipcmni_extend mode, even if they don't need more than 32k IPC identifiers. Signed-off-by: Waiman Long Signed-off-by: Manfred Spraul Signed-off-by: Manfred Spraul Acked-by: Waiman Long --- Documentation/admin-guide/kernel-parameters.txt | 5 ++++- ipc/ipc_sysctl.c | 2 ++ ipc/util.c | 7 ++++++- ipc/util.h | 2 ++ 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index 074b775..bb851d0 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -1813,7 +1813,10 @@ See Documentation/filesystems/nfs/nfsroot.txt. ipcmni_extend [KNL] Extend the maximum number of unique System V - IPC identifiers from 32,768 to 16,777,216. + IPC identifiers from 32,768 to 16,777,216. Also do + cyclical identifier allocation through the entire + 24-bit identifier space to reduce the chance of + identifier reuse. irqaffinity= [SMP] Set the default irq affinity mask The argument is a cpu list, as described above. diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c index 73b7782..d9ac6ca 100644 --- a/ipc/ipc_sysctl.c +++ b/ipc/ipc_sysctl.c @@ -122,6 +122,7 @@ static int proc_ipc_sem_dointvec(struct ctl_table *table, int write, static int int_max = INT_MAX; int ipc_mni = IPCMNI; int ipc_mni_shift = IPCMNI_SHIFT; +bool ipc_mni_extended; static struct ctl_table ipc_kern_table[] = { { @@ -252,6 +253,7 @@ static int __init ipc_mni_extend(char *str) { ipc_mni = IPCMNI_EXTEND; ipc_mni_shift = IPCMNI_EXTEND_SHIFT; + ipc_mni_extended = true; pr_info("IPCMNI extended to %d.\n", ipc_mni); return 0; } diff --git a/ipc/util.c b/ipc/util.c index 0a835a4..78e14ac 100644 --- a/ipc/util.c +++ b/ipc/util.c @@ -221,7 +221,12 @@ static inline int ipc_idr_alloc(struct ipc_ids *ids, struct kern_ipc_perm *new) */ if (next_id < 0) { /* !CHECKPOINT_RESTORE or next_id is unset */ - idx = idr_alloc(&ids->ipcs_idr, new, 0, 0, GFP_NOWAIT); + if (ipc_mni_extended) + idx = idr_alloc_cyclic(&ids->ipcs_idr, new, 0, ipc_mni, + GFP_NOWAIT); + else + idx = idr_alloc(&ids->ipcs_idr, new, 0, 0, GFP_NOWAIT); + if ((idx <= ids->last_idx) && (++ids->seq > IPCID_SEQ_MAX)) ids->seq = 0; new->seq = ids->seq; diff --git a/ipc/util.h b/ipc/util.h index 6a88d51..9f0dd79 100644 --- a/ipc/util.h +++ b/ipc/util.h @@ -33,6 +33,7 @@ #ifdef CONFIG_SYSVIPC_SYSCTL extern int ipc_mni; extern int ipc_mni_shift; +extern bool ipc_mni_extended; #define IPCMNI_SEQ_SHIFT ipc_mni_shift #define IPCMNI_IDX_MASK ((1 << ipc_mni_shift) - 1) @@ -40,6 +41,7 @@ #else /* CONFIG_SYSVIPC_SYSCTL */ #define ipc_mni IPCMNI +#define ipc_mni_extended false #define IPCMNI_SEQ_SHIFT IPCMNI_SHIFT #define IPCMNI_IDX_MASK ((1 << IPCMNI_SHIFT) - 1) #endif /* CONFIG_SYSVIPC_SYSCTL */