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=-3.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no 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 09EB0C2B9F4 for ; Thu, 17 Jun 2021 09:14:25 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8BEBC6128C for ; Thu, 17 Jun 2021 09:14:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8BEBC6128C Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 253C36B0070; Thu, 17 Jun 2021 05:14:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 203C66B0071; Thu, 17 Jun 2021 05:14:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 07DB76B0072; Thu, 17 Jun 2021 05:14:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0211.hostedemail.com [216.40.44.211]) by kanga.kvack.org (Postfix) with ESMTP id C6A386B0070 for ; Thu, 17 Jun 2021 05:14:23 -0400 (EDT) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 63D9A824C43C for ; Thu, 17 Jun 2021 09:14:23 +0000 (UTC) X-FDA: 78262654806.02.022428E Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf28.hostedemail.com (Postfix) with ESMTP id 79749200106B for ; Thu, 17 Jun 2021 09:14:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=7jAeVf7uw57mNPZls65uRWl6PqalkSrQAoEl/FmahJE=; b=pWPWDEgL4BQnJvYIYppPMUvpsd zJxX+iiGfKLz+q7Aj95iKzsWn1CEnnjLZISXkCEtpZz0/7bMJU8ofRdj9q3g4qPbOXVJJ5hFod1OF HWAktJz3khNNBFW7UpnYze0TwC4EK28l6kaayFV4W51SYnTyQ9u9JhMx6ELvJR9xvSVfe0UkPN+Qx Lau9jz3fDDgj1zPnOtXs2YjqaaIO/uzJRplrCwmkRspne6h3FXy42Upe6yeJhawGEVVnF2eOjO/4l yWuASdgHgwG3RStcwz4yK4oYJJmjPIFriPJ0gO88QMFHYtMtJDUcaNjl5TA1d9VTLPPzfAy1sl2Zg 5O+wb0LA==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1lto61-008xGF-DS; Thu, 17 Jun 2021 09:13:59 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id D68C93001DB; Thu, 17 Jun 2021 11:13:56 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id B86B4203C0549; Thu, 17 Jun 2021 11:13:56 +0200 (CEST) Date: Thu, 17 Jun 2021 11:13:56 +0200 From: Peter Zijlstra To: Andy Lutomirski 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: Re: [RFC][PATCH] sched: Use lightweight hazard pointers to grab lazy mms Message-ID: 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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 79749200106B X-Stat-Signature: 36km796kdfmm6sdx47mm8udw377qfr4o Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=pWPWDEgL; dmarc=none; spf=none (imf28.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=peterz@infradead.org X-HE-Tag: 1623921252-246073 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Thu, Jun 17, 2021 at 11:08:03AM +0200, Peter Zijlstra wrote: > +static void mmdrop_lazy(struct rq *rq) > +{ > + struct mm_struct *old_mm; > + > + if (likely(!READ_ONCE(rq->drop_mm))) > + return; > + > + /* > + * Slow path. This only happens when we recently stopped using > + * an mm that is exiting. > + */ > + old_mm = xchg(&rq->drop_mm, NULL); > + if (old_mm) > + mmdrop(old_mm); > +} AFAICT if we observe a !NULL value on the load, the xchg() *MUST* also see !NULL (although it might see a different !NULL value). So do we want to write it something like so instead? static void mmdrop_lazy(struct rq *rq) { struct mm_struct *old_mm; if (likely(!READ_ONCE(rq->drop_mm))) return; /* * Slow path. This only happens when we recently stopped using * an mm that is exiting. */ old_mm = xchg(&rq->drop_mm, NULL); if (WARN_ON_ONCE(!old_mm)) return; mmdrop(old_mm); }