From patchwork Wed Mar 29 05:31:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13191930 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4D71AC6FD18 for ; Wed, 29 Mar 2023 06:22:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B0A7A6B0075; Wed, 29 Mar 2023 02:22:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id ABA746B0078; Wed, 29 Mar 2023 02:22:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 982436B007B; Wed, 29 Mar 2023 02:22:16 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 7A77F6B0075 for ; Wed, 29 Mar 2023 02:22:16 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 330D61C5ECB for ; Wed, 29 Mar 2023 06:22:16 +0000 (UTC) X-FDA: 80620941072.05.7A54D91 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf21.hostedemail.com (Postfix) with ESMTP id 191F41C0004 for ; Wed, 29 Mar 2023 06:22:12 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=0s+ZsQtq; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=none); spf=none (imf21.hostedemail.com: domain of mcgrof@infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=mcgrof@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1680070933; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=guyHag9qCqT02ycAP5gFYMiS5Z8MMs8Ps7B6B4e3yQk=; b=1gWUbyr4mqFWeWq/H1PtC0bRlGtgMekR9oxhPKvldrmJY/XB8fsGB0HwyJcyGvm73aGZei zJ+AWJb4QXKi09G7UF4wq/WEZCNm4/yG0DNmcARA0omOLrVv1RTJHZcEAhFYLxHS6j3SQ8 iKRJt+3pMohI0/elWXZfKXC29HPXd0s= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=0s+ZsQtq; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=none); spf=none (imf21.hostedemail.com: domain of mcgrof@infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=mcgrof@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680070933; a=rsa-sha256; cv=none; b=YyA0tvGthA6HVAn5ZWvCYwJOR5uM7QOyX/qgEivoBQHkBGT0ZwGF0a7Q0PS40FVt5BiYg6 xQiFqWh5FHjWZwq/wyILstwVLsvd9s5yTz+4H8Uag7aImshuvURfTR0nbX1RCn4xFGgDmj mxs5pZsdE8GIwUC7JbnH+Jk/ZyQ+NaM= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=guyHag9qCqT02ycAP5gFYMiS5Z8MMs8Ps7B6B4e3yQk=; b=0s+ZsQtqvZrSA+dzaZX4im6LhE WyYiRJxXstb/bqMR3zp8lDLo3bPTmJaJEWSTCh06Aez4lV2UP5frUnAfsl7KhQGMydKgbO1lw7zhb 5jDrZkRjvFJfeHZVno0lB+v2bfAxpKG/fGbbO0mlzuPuljHB9FQjYJ/jVkpBdrh4YEiBJCnK3TUmn hiaTcVuownYisCxprFvcXdMGJps9Idj/5unt/K9XrpcpkHwN+cyMrQDW7fOwdPR91ENj/EqR2BYlX ZDIkrXjOcSqgk2+GqwuSjX7aetm38G9LIM3wHa+55pCtzqIALL7J0jkg4T34ZcZ7/7O5zQ66cDSM2 QzeATbHg==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1phOPW-00GgRb-2M; Wed, 29 Mar 2023 05:31:50 +0000 From: Luis Chamberlain To: david@redhat.com, patches@lists.linux.dev, linux-modules@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, pmladek@suse.com, petr.pavlu@suse.com, prarit@redhat.com, torvalds@linux-foundation.org, gregkh@linuxfoundation.org, rafael@kernel.org Cc: christophe.leroy@csgroup.eu, tglx@linutronix.de, peterz@infradead.org, song@kernel.org, rppt@kernel.org, willy@infradead.org, vbabka@suse.cz, mhocko@suse.com, dave.hansen@linux.intel.com, mcgrof@kernel.org Subject: [PATCH 4/7] sempahore: add a helper for a concurrency limiter Date: Tue, 28 Mar 2023 22:31:46 -0700 Message-Id: <20230329053149.3976378-5-mcgrof@kernel.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230329053149.3976378-1-mcgrof@kernel.org> References: <20230329053149.3976378-1-mcgrof@kernel.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 191F41C0004 X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: cmfkyk4monuh3gsjp19ushbwf3opsogj X-HE-Tag: 1680070932-494479 X-HE-Meta: U2FsdGVkX18rCV4PlTE26liU3clAb/hS/rgWzVUgNFClll4Vp7kVHVrFZ9y5aFpeaexEkZkq/4/u+zTqj1ic8xgBCMFZc6BKRpw/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AGrhlrPg/k/1XgvlOOyWTOAIP6SAWlrtyLs8/CQqxMo5pN4kBPlwfkFPmF34iw1Fcqg3/m8E6ii6yx20KQ5ZaV3nOjTvnYVPq3gGoLYlVgiKEod8C6pVQwWDGayi88tn0TvmxCptvGLpRtT43cj9Lc++30zao1fqo7wFQsmx3AkcxYKiIifvjC5KbJhb/ZMRQ+9fNgwyeXrhXNxSQcnAqOZS3iyvReu4GFvn897vp+dfELxhQsVHWqk7Og1ew1Uu6JkFE3XVpX/mOZKL1m35AEP/CTkWqDA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000049, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: While I looked at re-using the old kernel/kmod.c (now kernel/module/kmod.c) concurrency delimiter methodology for another place in the kernel Linus noted that this could be simply replaced with a sempahore [0]. So add that so we we don't re-invent the wheel and make it obvious to use. [0] https://lore.kernel.org/all/CAHk-=whkj6=wyi201JXkw9iT_eTUTsSx+Yb9d4OgmZFjDJA18g@mail.gmail.com/ Suggested-by: Linus Torvalds Signed-off-by: Luis Chamberlain Signed-off-by: Peter Zijlstra (Intel) Signed-off-by: Peter Zijlstra (Intel) --- include/linux/semaphore.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/linux/semaphore.h b/include/linux/semaphore.h index 6694d0019a68..2ecdffdb9814 100644 --- a/include/linux/semaphore.h +++ b/include/linux/semaphore.h @@ -28,6 +28,9 @@ struct semaphore { #define DEFINE_SEMAPHORE(name) \ struct semaphore name = __SEMAPHORE_INITIALIZER(name, 1) +#define CONCURRENCY_LIMITER(name, n) \ + struct semaphore name = __SEMAPHORE_INITIALIZER(name, n) + static inline void sema_init(struct semaphore *sem, int val) { static struct lock_class_key __key;