From mboxrd@z Thu Jan 1 00:00:00 1970 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 7B751C433F5 for ; Sat, 29 Jan 2022 12:13:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9F2A06B00A4; Sat, 29 Jan 2022 07:13:35 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9ABBD6B00A5; Sat, 29 Jan 2022 07:13:35 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 891656B00A6; Sat, 29 Jan 2022 07:13:35 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0231.hostedemail.com [216.40.44.231]) by kanga.kvack.org (Postfix) with ESMTP id 7C5B16B00A4 for ; Sat, 29 Jan 2022 07:13:35 -0500 (EST) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 287F8181D900A for ; Sat, 29 Jan 2022 12:13:35 +0000 (UTC) X-FDA: 79083215190.29.498C069 Received: from mail3-162.sinamail.sina.com.cn (mail3-162.sinamail.sina.com.cn [202.108.3.162]) by imf25.hostedemail.com (Postfix) with SMTP id BBDDDA0004 for ; Sat, 29 Jan 2022 12:13:32 +0000 (UTC) Received: from unknown (HELO localhost.localdomain)([114.249.61.131]) by sina.com (172.16.97.27) with ESMTP id 61F52F620003575D; Sat, 29 Jan 2022 20:13:24 +0800 (CST) X-Sender: hdanton@sina.com X-Auth-ID: hdanton@sina.com X-SMAIL-MID: 52896649283217 From: Hillf Danton To: Michel Lespinasse Cc: Linux-MM , linux-kernel@vger.kernel.org, Suren Baghdasaryan Subject: Re: [PATCH v2 22/35] percpu-rwsem: enable percpu_sem destruction in atomic context Date: Sat, 29 Jan 2022 20:13:19 +0800 Message-Id: <20220129121319.3593-1-hdanton@sina.com> In-Reply-To: <20220128131006.67712-23-michel@lespinasse.org> References: <20220128131006.67712-1-michel@lespinasse.org> MIME-Version: 1.0 X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: BBDDDA0004 X-Stat-Signature: o9jp8cp17w1peqyftx9ki3oizfogdg3m Authentication-Results: imf25.hostedemail.com; dkim=none; spf=pass (imf25.hostedemail.com: domain of hdanton@sina.com designates 202.108.3.162 as permitted sender) smtp.mailfrom=hdanton@sina.com; dmarc=none X-Rspam-User: nil X-HE-Tag: 1643458412-103178 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.002250, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Fri, 28 Jan 2022 05:09:53 -0800 Michel Lespinasse wrote: > + > +static LIST_HEAD(destroy_list); > +static DEFINE_SPINLOCK(destroy_list_lock); static bool destroyer_running; > + > +static void destroy_list_workfn(struct work_struct *work) > +{ > + struct percpu_rw_semaphore *sem, *sem2; > + LIST_HEAD(to_destroy); > + again: > + spin_lock(&destroy_list_lock); if (list_empty(&destroy_list)) { destroyer_running =3D false; spin_unlock(&destroy_list_lock); return; } destroyer_running =3D true; > + list_splice_init(&destroy_list, &to_destroy); > + spin_unlock(&destroy_list_lock); > + > + if (list_empty(&to_destroy)) > + return; > + > + list_for_each_entry_safe(sem, sem2, &to_destroy, destroy_list_entry) = { list_del(&sem->destroy_list_entry); > + percpu_free_rwsem(sem); > + kfree(sem); > + } goto again; > +} > + > +static DECLARE_WORK(destroy_list_work, destroy_list_workfn); > + > +void percpu_rwsem_async_destroy(struct percpu_rw_semaphore *sem) > +{ > + spin_lock(&destroy_list_lock); > + list_add_tail(&sem->destroy_list_entry, &destroy_list); > + spin_unlock(&destroy_list_lock); > + schedule_work(&destroy_list_work); Nits spin_lock(&destroy_list_lock); 1/ /* LIFO */ list_add(&sem->destroy_list_entry, &destroy_list); 2/ /* spawn worker if it is idle */ if (!destroyer_running) 3/ /* this is not critical work */ queue_work(system_unbound_wq, &destroy_list_work); spin_unlock(&destroy_list_lock); > +} > --=20 > 2.20.1