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 A62FCC433F5 for ; Tue, 1 Feb 2022 02:10:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 09F858D0049; Mon, 31 Jan 2022 21:10:16 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 027F98D0028; Mon, 31 Jan 2022 21:10:15 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E0AB58D0049; Mon, 31 Jan 2022 21:10:15 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0100.hostedemail.com [216.40.44.100]) by kanga.kvack.org (Postfix) with ESMTP id CD8298D0028 for ; Mon, 31 Jan 2022 21:10:15 -0500 (EST) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 732E3181C49CA for ; Tue, 1 Feb 2022 02:10:15 +0000 (UTC) X-FDA: 79092581190.24.DB41A2E Received: from mail3-165.sinamail.sina.com.cn (mail3-165.sinamail.sina.com.cn [202.108.3.165]) by imf08.hostedemail.com (Postfix) with SMTP id A21E9160003 for ; Tue, 1 Feb 2022 02:10:12 +0000 (UTC) Received: from unknown (HELO localhost.localdomain)([114.249.61.131]) by sina.com (172.16.97.32) with ESMTP id 61F8967100025A8E; Tue, 1 Feb 2022 10:09:55 +0800 (CST) X-Sender: hdanton@sina.com X-Auth-ID: hdanton@sina.com X-SMAIL-MID: 499040628775 From: Hillf Danton To: Suren Baghdasaryan Cc: Michel Lespinasse , Linux-MM , LKML Subject: Re: [PATCH v2 22/35] percpu-rwsem: enable percpu_sem destruction in atomic context Date: Tue, 1 Feb 2022 10:09:58 +0800 Message-Id: <20220201020958.3720-1-hdanton@sina.com> In-Reply-To: References: <20220128131006.67712-1-michel@lespinasse.org> <20220128131006.67712-23-michel@lespinasse.org> <20220129121319.3593-1-hdanton@sina.com> MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: A21E9160003 X-Stat-Signature: m5esap3xaeo9n551c8pucqu49t5ngsdi X-Rspam-User: nil Authentication-Results: imf08.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf08.hostedemail.com: domain of hdanton@sina.com designates 202.108.3.165 as permitted sender) smtp.mailfrom=hdanton@sina.com X-HE-Tag: 1643681412-84712 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000006, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Mon, 31 Jan 2022 10:04:16 -0800 Suren Baghdasaryan wrote: > On Sat, Jan 29, 2022 at 4:13 AM Hillf Danton wrote: > > > > 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 > Thanks for the review! Just to clarify, are you suggesting > simplifications to the current patch or do you see a function issue? Apart from the nits that can be safely ignored in usual spins, I wonder i= f the async destroy can be used in the contexts wrt raw_spin_lock. Hillf raw_spin_lock_irq(&foo->lock); ... percpu_rwsem_async_destroy(*sem); ... raw_spin_unlock_irq(&foo->lock);