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 X-Spam-Level: X-Spam-Status: No, score=-11.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6F46AC2B9F4 for ; Thu, 17 Jun 2021 14:04:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3F23D613E7 for ; Thu, 17 Jun 2021 14:04:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230442AbhFQOGI (ORCPT ); Thu, 17 Jun 2021 10:06:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:57434 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229915AbhFQOGH (ORCPT ); Thu, 17 Jun 2021 10:06:07 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 52C5A611CA; Thu, 17 Jun 2021 14:03:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1623938640; bh=7iMyIFiSoJXd3K14sBheP7uL6Rq2qTf2UHkmkhu2924=; h=In-Reply-To:References:Date:From:To:Cc:Subject:From; b=NhQTimeuQEnwr6Kl7WM4Tidnu+ngXruFZnSrnEEI1FsUNUyvaIn2gysfGMuFIWHWZ LfBd8hRKGaxLXsTjV5DG0VJFh6IKrjx84aMb8n2SXfLmjNj2xKdkDOhZcCun2wWEtv toprt7E23/8cF3mhMVcbm9Y8NxtD5dG6BzEbHSvAiJZMeiKYPstj6oAOjNYoi7Zhlj C2RgHWwJerbblUhskCAElnkzB3mdmtNnRv6JSOGbfuRJjMJqGMAqefocyGf2NlL5ob 9RpnCevYGj6Rv0UZ9r5B1ZJH+65o1xEpua8iQUSIRVgmgXwYsKbRWb+PeWn7iOO88O Q7zanEUwrKIhw== Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailauth.nyi.internal (Postfix) with ESMTP id 659F027C0060; Thu, 17 Jun 2021 10:03:58 -0400 (EDT) Received: from imap21 ([10.202.2.71]) by compute2.internal (MEProxy); Thu, 17 Jun 2021 10:03:58 -0400 X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrfeefuddgjedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgesthdtredtreerjeenucfhrhhomhepfdetnhgu hicunfhuthhomhhirhhskhhifdcuoehluhhtoheskhgvrhhnvghlrdhorhhgqeenucggtf frrghtthgvrhhnpeegjefghfdtledvfeegfeelvedtgfevkeeugfekffdvveeffeetieeh ueetveekfeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhroh hmpegrnhguhidomhgvshhmthhprghuthhhphgvrhhsohhnrghlihhthidqudduiedukeeh ieefvddqvdeifeduieeitdekqdhluhhtoheppehkvghrnhgvlhdrohhrgheslhhinhhugi drlhhuthhordhush X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id 64DEE51C0060; Thu, 17 Jun 2021 10:03:57 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.5.0-alpha0-526-gf020ecf851-fm-20210616.001-gf020ecf8 Mime-Version: 1.0 Message-Id: <616a869c-fd19-4de8-b1c0-68e03955b1b0@www.fastmail.com> In-Reply-To: References: <1623816595.myt8wbkcar.astroid@bobo.none> <617cb897-58b1-8266-ecec-ef210832e927@kernel.org> <1623893358.bbty474jyy.astroid@bobo.none> <58b949fb-663e-4675-8592-25933a3e361c@www.fastmail.com> Date: Thu, 17 Jun 2021 07:03:36 -0700 From: "Andy Lutomirski" To: "Peter Zijlstra (Intel)" Cc: "Nicholas Piggin" , "Rik van Riel" , "Andrew Morton" , "Dave Hansen" , "Linux Kernel Mailing List" , linux-mm@kvack.org, "Mathieu Desnoyers" , "the arch/x86 maintainers" , "Paul E. McKenney" Subject: =?UTF-8?Q?Re:_[RFC][PATCH]_sched:_Use_lightweight_hazard_pointers_to_gra?= =?UTF-8?Q?b_lazy_mms?= Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 17, 2021, at 2:28 AM, Peter Zijlstra wrote: > On Thu, Jun 17, 2021 at 11:08:03AM +0200, Peter Zijlstra wrote: > > > diff --git a/kernel/fork.c b/kernel/fork.c > > index e595e77913eb..57415cca088c 100644 > > --- a/kernel/fork.c > > +++ b/kernel/fork.c > > @@ -1104,6 +1104,8 @@ static inline void __mmput(struct mm_struct *mm) > > } > > if (mm->binfmt) > > module_put(mm->binfmt->module); > > + > > + mm_unlazy_mm_count(mm); > > mmdrop(mm); > > } > > > > diff --git a/kernel/sched/core.c b/kernel/sched/core.c > > index 8ac693d542f6..e102ec53c2f6 100644 > > --- a/kernel/sched/core.c > > +++ b/kernel/sched/core.c > > @@ -19,6 +19,7 @@ > > > +/* > > + * This converts all lazy_mm references to mm to mm_count refcounts. Our > > + * caller holds an mm_count reference, so we don't need to worry about mm > > + * being freed out from under us. > > + */ > > +void mm_unlazy_mm_count(struct mm_struct *mm) > > +{ > > + unsigned int drop_count = num_possible_cpus(); > > + int cpu; > > + > > + /* > > + * mm_users is zero, so no cpu will set its rq->lazy_mm to mm. > > + */ > > + WARN_ON_ONCE(atomic_read(&mm->mm_users) != 0); > > + > > + /* Grab enough references for the rest of this function. */ > > + atomic_add(drop_count, &mm->mm_count); > > So that had me puzzled for a little while. Would something like this be > a better comment? > > /* > * Because this can race with mmdrop_lazy(), mm_count must be > * incremented before setting any rq->drop_mm value, otherwise > * it is possible to free mm early. > */ Nope, because the caller already did it. It's an optimization, but maybe it's a poorly done optimization -- I'd rather do two atomic ops than many. How about: drop_count = 0; ... if (!drop_count) { /* Collect lots of references. We'll drop the ones we don't use. */ drop_count = num_possible_cpus(); atomic_inc(drop_count, &->mm_count); } drop_count--;