Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp902565pxb; Tue, 1 Feb 2022 12:48:56 -0800 (PST) X-Google-Smtp-Source: ABdhPJwVUYXZhKQwSR+S+srFM7MpHMv1w1FNx4vrpWwwvUhe7e6NqaT+eGhY374KwdmlRTMdV3rl X-Received: by 2002:a17:902:ecc5:: with SMTP id a5mr28311397plh.54.1643748388535; Tue, 01 Feb 2022 12:46:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643748388; cv=none; d=google.com; s=arc-20160816; b=m8ir/BRDaxObKScxiAr6+gS63zl0iBp7Z+scbSIs70a2F1AmjUEctRj35IHQMYlzya uUi9n15IpDX1xYdFlRTVLuOJMvzblzbxC3g9nTuLLp8FS6T0ozzodr30UXjxx/RisRDf tOHUlDmyXJVfx5rV+IbVEHE8I02E4Xb9DpgeqF4wQ+sJnQjQga4TdxgvwY7EsfcKVvhS cgN0NAytP6Bz3LV7IjKeGGlwPWymk4fEqvLani+1RNNeZrd8e04mhRVqjHe6mdOXDjA4 LKwFfN+G4Q88sk9WTa/7OofqNbSqsoRvueb58S4VRUtnv+gcBXcByJ+A5nupVY2sxbLs 3xIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=jKOkqEsF/LF5CvREpOhl/oWeS4V81mya8jnYw1wCDFw=; b=GsDmjO3h0yAhL7Ll3D6AMJfwtjOJhK9gRsbPgQDtJ1gxpsnpp3hWH3xd50bPL2Dis0 KnqdKoOpKKYgKLbN/5tteXajyln4Q52bSK0ASX84HjZA6dbFKPqZmPEarI+6eK3xOJ/y icOQtoyBZPCWzJf506+Y8DC5HXGshJUICw4CWODguGNjKBa3Jwm5gjdgl2Iu+kInNEZk ZnQn9BqUWYBYItseQn9QC52PimDwucF4x8LotG2Rqb8utZuNQSTxTedOOrjy0tGMVTOW AjeEm5pdEvBcyRabFvD2omN++ngd1rVV5A90G+lxxTHtyKTXMlCL195GD320rh2chyq4 hong== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=ZoEoPhFI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id fw11si3105222pjb.94.2022.02.01.12.46.16; Tue, 01 Feb 2022 12:46:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=ZoEoPhFI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234850AbiAaSEa (ORCPT + 99 others); Mon, 31 Jan 2022 13:04:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58550 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230425AbiAaSE2 (ORCPT ); Mon, 31 Jan 2022 13:04:28 -0500 Received: from mail-yb1-xb2f.google.com (mail-yb1-xb2f.google.com [IPv6:2607:f8b0:4864:20::b2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B5CFBC061714 for ; Mon, 31 Jan 2022 10:04:28 -0800 (PST) Received: by mail-yb1-xb2f.google.com with SMTP id g14so42956291ybs.8 for ; Mon, 31 Jan 2022 10:04:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=jKOkqEsF/LF5CvREpOhl/oWeS4V81mya8jnYw1wCDFw=; b=ZoEoPhFI/SkB8VO31hL0sxmvpM9bvkaNazc4+33voZ+d+Jq5CVfcf/4q4i0xfFVF+K 6K3x1JC51OSZS84XuLrcAnSAKYqNlF3njdyY4m4M/pKKeCHTbzs+Xq85lzme9M8UxF4I 1WfKC4mIWOsksRwShjtGW08RG0g2y8tChKAdjmFXp7Q3TjfNzMl9p/WhNHEqW/+QkIFr Yr5a3t+LeDzoi58dWsvqQRJ8qK6GGOHZzpXWEpXhYHvp2noblx7S6Gzn1tb7BLZHKN7X e23AKSODY44B7jDfGz4rsRiFIXwRylsE/dpWc9z9mafZeHrt3om02GsVon7YI8i/miOP c+Mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=jKOkqEsF/LF5CvREpOhl/oWeS4V81mya8jnYw1wCDFw=; b=GMFZVyRQiyzYcryFBYwZdIWcC6iTBLvngQTRYRrZ7ei80gsFCoBxBXVnjo5NaT7tWm cGy/Unrff0iGmGi7aYuccOxqQqYxopVLppLctIQAqKteLRwIG9o3GH4nrl9ENtHvaSJX n5I0qrplutN7oxmFbRwmh6k9b3DLnPBXYEfj7+pCqMRE9Q+lhlBLi8HOiQptVve0BwXT q2wSEn85JUtMeyc8aMxBOa8Ch/89uB8ABaeRcVav8y1DwblIfOiI5K/m9Xf7f8BP+Hsb NzMPy1VBrumHvZ8kuwwDQzyJ8EFWQ5Lf1WiHMxj3JBPBEk8tMQLOG8qsvJiujYFzmi3p 9Chg== X-Gm-Message-State: AOAM530krmdnpzefL5XJjPE/KI4j/fFsdJYBmTbwQilfQrsrQMY+64V0 weaqd7cE3NUdONvrrpRAx2zgTrTMVBo0CzMp/qzfYg== X-Received: by 2002:a25:be41:: with SMTP id d1mr33068235ybm.488.1643652267644; Mon, 31 Jan 2022 10:04:27 -0800 (PST) MIME-Version: 1.0 References: <20220128131006.67712-1-michel@lespinasse.org> <20220128131006.67712-23-michel@lespinasse.org> <20220129121319.3593-1-hdanton@sina.com> In-Reply-To: <20220129121319.3593-1-hdanton@sina.com> From: Suren Baghdasaryan Date: Mon, 31 Jan 2022 10:04:16 -0800 Message-ID: Subject: Re: [PATCH v2 22/35] percpu-rwsem: enable percpu_sem destruction in atomic context To: Hillf Danton Cc: Michel Lespinasse , Linux-MM , LKML Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 = false; > spin_unlock(&destroy_list_lock); > return; > } > destroyer_running = 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); Thanks for the review! Just to clarify, are you suggesting simplifications to the current patch or do you see a function issue? > > +} > > -- > > 2.20.1 >