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 E0B79C2B9F4 for ; Thu, 17 Jun 2021 08:46:24 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5B5266135C for ; Thu, 17 Jun 2021 08:46:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5B5266135C 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 C851D6B0074; Thu, 17 Jun 2021 04:46:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C353F6B0075; Thu, 17 Jun 2021 04:46:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AAEF26B0078; Thu, 17 Jun 2021 04:46:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0168.hostedemail.com [216.40.44.168]) by kanga.kvack.org (Postfix) with ESMTP id 789596B0074 for ; Thu, 17 Jun 2021 04:46:23 -0400 (EDT) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 0C999180AD802 for ; Thu, 17 Jun 2021 08:46:23 +0000 (UTC) X-FDA: 78262584246.19.6645C5C Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf17.hostedemail.com (Postfix) with ESMTP id 7BE9C4202A19 for ; Thu, 17 Jun 2021 08:46:14 +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=KZl/Wka2k1ddujQH+TFRsFdpimwLd/Gy1bZGIFO9vgw=; b=M9U1xfKesPpxfW7j41eixKbnwb 8p2j+GwHJo3jshsKXSpsdAqo1ZaoAugZIna6cjJbMxg8GuscfOm/7P/n4rWxbOaOOQszQU0BVUIZV 4T6SVHvtd2YUwE401qrIFwm8FW6XBzoBVkHtZcMbp1ux1zH6KA/KrZHHJgHHQ0tBFtg2heCDgbNUM R0G/vhzqvSB1mbqa3i2aC96vnMf89kiXNFvVxHggge7YXuX/+B3PbS1lWCVURwBODi3NKTBhhNnml dhrtHa9TJX4nX16RQLszcwbAWH0Cg0caPpiL+kWQOYfSqZTlaEX7DHNm4yLcHFVZmuAHAJiFVIil+ id8SQR3A==; 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 1ltnei-008vvm-Hu; Thu, 17 Jun 2021 08:45:51 +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) server-digest SHA256) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id B0013300252; Thu, 17 Jun 2021 10:45:42 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 76ACA2BF4234B; Thu, 17 Jun 2021 10:45:42 +0200 (CEST) Date: Thu, 17 Jun 2021 10:45:42 +0200 From: Peter Zijlstra To: Andy Lutomirski Cc: Nicholas Piggin , x86@kernel.org, Andrew Morton , Dave Hansen , LKML , linux-mm@kvack.org, Mathieu Desnoyers Subject: Re: [PATCH 4/8] membarrier: Make the post-switch-mm barrier explicit Message-ID: References: <1623816595.myt8wbkcar.astroid@bobo.none> <617cb897-58b1-8266-ecec-ef210832e927@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <617cb897-58b1-8266-ecec-ef210832e927@kernel.org> X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 7BE9C4202A19 X-Stat-Signature: 4q4mktec5pdrrxjxkyuckz3yp3di4pjc Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=M9U1xfKe; dmarc=none; spf=none (imf17.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: 1623919574-345641 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 Wed, Jun 16, 2021 at 11:41:19AM -0700, Andy Lutomirski wrote: > mmgrab() and mmdrop() would be better if they were not full barriers. As a > trivial optimization, > mmgrab() could use a relaxed atomic and mmdrop() > could use a release on architectures that have these operations. mmgrab() *is* relaxed, mmdrop() is a full barrier but could trivially be made weaker once membarrier stops caring about it. static inline void mmdrop(struct mm_struct *mm) { unsigned int val = atomic_dec_return_release(&mm->mm_count); if (unlikely(!val)) { /* Provide REL+ACQ ordering for free() */ smp_acquire__after_ctrl_dep(); __mmdrop(mm); } } It's slightly less optimal for not being able to use the flags from the decrement. Or convert the whole thing to refcount_t (if appropriate) which already does something like the above.