Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp1543007lqe; Mon, 8 Apr 2024 11:58:00 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVyNqucXyZcfEylaGIt28bYd1gER6Ue1E8AanBIYRkrDpzU32nzwa+EwRk+zb+T3tu+YSQHmAWkeSVNaXhh3q9IuieMGbVZwGZ7Lfa6tw== X-Google-Smtp-Source: AGHT+IF35TQT+nqyXhMlkxG6FO4hQGBT+ql0sTXBDMElSzkNnlXkuoU3HkCvXrXlrY/0odsxOxZv X-Received: by 2002:a17:907:60d0:b0:a51:d522:13de with SMTP id hv16-20020a17090760d000b00a51d52213demr2530344ejc.38.1712602680209; Mon, 08 Apr 2024 11:58:00 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712602680; cv=pass; d=google.com; s=arc-20160816; b=uJKsd+vj5lMEpjd1Spn+JJLuRc5uifqHE2dOQnLzhBdOQ9Aig5B8Tb7Feyi3doJ3PV 36hnirvSymSCMYKeYXcCougafrHoQIQbL5gxzqVagBGxZ+iWCv/VkLS1fPkwGcfR0WXO AnkbnIutii0e4ikdrtOWP5bEVXUOXNUFsZWSbcp8/lpbTN0QEzf9QgHAhHF9aCQgElR5 r9ec1Q4HNCsnd/jV7IwgdKKdjdScWufWV8hvSRuKdefXXcwdJjiQcoKGRjX/CMFsDO4A 8mUON5RQ8QY+7iHUPB3LaL3KBegfgMz2rfeARyype6Rd0sjY87WPKYIp81zF1VGbmomx 4SHA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=sIUsC7ptEjq4nnNQVIvjVrCu4VZhInNOgmJrVZovAUM=; fh=ytFnz+FK7KJDZVVTRJOUsmoc8DH+sh5mp/erd8xNAsQ=; b=Au9MXBah7141nn48mM5HDUop+WxVsTY/9BS8H66Wmoa4nLiA34p90vhDaEL9cJE9E/ 7v06lZrg55OaiHhEtaDURDEPTmRJuTET593topzLi6HVNDP5OrLz7KY/lB4oYY1xlWRJ iGJRiAqseyGozbRMaNYBQLNcpEcdxT/Vin1ce4zS3ClfWCxfyrF39xhrXY5qqZ+n/ocN Z/rv8wLzQKSinltXJ6Mavprb7PDGZKF/BOTLNwt1fZ19M+HYhYt1PAg791yksUoiK+2F wKC9HHM5/DyZeW/Kid1vl+KO/8pCmwcHxREvB0kGgKj172iJe0jaVTwZaoHRG1f1fsQF VUFg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QH3VMMm5; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-135837-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-135837-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id i10-20020a1709064fca00b00a51c441c37bsi2486418ejw.89.2024.04.08.11.58.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 11:58:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-135837-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QH3VMMm5; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-135837-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-135837-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id B522A1F25EE2 for ; Mon, 8 Apr 2024 18:47:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E8A4A1448FA; Mon, 8 Apr 2024 18:47:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="QH3VMMm5" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F14B71119A; Mon, 8 Apr 2024 18:47:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712602060; cv=none; b=lgdunCBSJZXSISm5qXrrQnhm7nGiLJ7xu1c/Xvk6ws69gZWjh6/3U1AQ2N1JCTZfKagBBxff7AzAT989NQweuZieIV14peGiyBIuWwpLBIofEck/j6D0oCohmx9UUSSWDxJyQ/f85Ql8rytzDRDwZ57+eNgk+iezWeCafH6Is/g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712602060; c=relaxed/simple; bh=SYyVUdi9VjoNm97IS/XTV920oO6eW28EJnO10HujZm8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=BAD1uGh5/jiEisr7PO2yg9oUKY485YTarDPD1+eXGVLB7fx9XsfUWXQOYwGE6VuOaGCyhEWojXZ1SWneUy9/lAPKHRsjX8JXTVM+JAPFqJwLpGN+PdwGFkPilREbowxgQUMVaRk3U2N87QDV4dqJ9bgf4u7Z5YdV3OgaRlSQgWE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=QH3VMMm5; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7457AC433C7; Mon, 8 Apr 2024 18:47:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712602059; bh=SYyVUdi9VjoNm97IS/XTV920oO6eW28EJnO10HujZm8=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=QH3VMMm5SOy+a5/Le74mjOj7Gdef3Nx9WwKw4QdG6/4a+h1jicQcuUxj5+AbinxgI 5O0WFSLX1tLKfiZqZk9z4W57aYMdLzXxokbye8N4IAJTRT10k5C02VRxNvZLANEXPH 96FljbScvGcjKUjEf5DwEKEM5c1SQmnDIiMku/rAZriOl1SsozESEUU/P8SlrWCidN AipWE/sidcx/TcflQso3P15T0WQ+VhU8rBrSGPPBvGDzMSc4OkBRiugBoJDyCVH95M 4e8DhZGuKYDGFqEyanXAB5XTPjkKaLhR1rfGz4FVPrUCAKzWUpjPKSi5TP6PlVxXdc VWuo/YoxOqJ0w== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 17CC2CE126C; Mon, 8 Apr 2024 11:47:39 -0700 (PDT) Date: Mon, 8 Apr 2024 11:47:39 -0700 From: "Paul E. McKenney" To: Matthew Wilcox Cc: Linus Torvalds , Philipp Stanner , Kent Overstreet , Boqun Feng , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, llvm@lists.linux.dev, Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Gary Guo , =?iso-8859-1?Q?Bj=F6rn?= Roy Baron , Benno Lossin , Andreas Hindborg , Alice Ryhl , Alan Stern , Andrea Parri , Will Deacon , Peter Zijlstra , Nicholas Piggin , David Howells , Jade Alglave , Luc Maranget , Akira Yokosawa , Daniel Lustig , Joel Fernandes , Nathan Chancellor , Nick Desaulniers , kent.overstreet@gmail.com, Greg Kroah-Hartman , elver@google.com, Mark Rutland , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Catalin Marinas , linux-arm-kernel@lists.infradead.org, linux-fsdevel@vger.kernel.org Subject: Re: [WIP 0/3] Memory model and atomic API in Rust Message-ID: Reply-To: paulmck@kernel.org References: <20240322233838.868874-1-boqun.feng@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Mon, Apr 08, 2024 at 06:03:11PM +0100, Matthew Wilcox wrote: > On Mon, Apr 08, 2024 at 09:55:23AM -0700, Paul E. McKenney wrote: > > On Mon, Apr 08, 2024 at 05:02:37PM +0100, Matthew Wilcox wrote: > > > In my ideal world, the compiler would turn this into: > > > > > > newfolio->flags |= folio->flags & MIGRATE_MASK; > > > > Why not accumulate the changes in a mask, and then apply the mask the > > one time? (In situations where __folio_set_foo() need not apply.) > > Yes, absolutely, we can, should and probably eventually will do this > when it gets to the top of somebody's todo list. But it irks me that > we can't tell the compiler this is a safe transformation for it to make. > There are a number of places where similar things happen. > > $ git grep folio_test.*folio_test > > will find you 82 of them (where they happen to be on the same line) > > if (folio_test_dirty(folio) || folio_test_locked(folio) || > folio_test_writeback(folio)) > break; > > turns into: > > 1f41: 48 8b 29 mov (%rcx),%rbp > 1f44: 48 c1 ed 04 shr $0x4,%rbp > 1f48: 83 e5 01 and $0x1,%ebp > 1f4b: 0f 85 d5 00 00 00 jne 2026 > 1f51: 48 8b 29 mov (%rcx),%rbp > 1f54: 83 e5 01 and $0x1,%ebp > 1f57: 0f 85 c9 00 00 00 jne 2026 > 1f5d: 48 8b 29 mov (%rcx),%rbp > 1f60: 48 d1 ed shr $1,%rbp > 1f63: 83 e5 01 and $0x1,%ebp > 1f66: 0f 85 ba 00 00 00 jne 2026 > > rather than _one_ load from rcx and a test against a mask. Agreed, it would be nice if we could convince the compiler to do this for us, preferably without breaking anything. > > If it turns out that we really do need a not-quite-volatile, what exactly > > does it do? You clearly want it to be able to be optimized so as to merge > > similar accesses. Is there a limit to the number of accesses that can > > be merged or to the region of code over which such merging is permitted? > > Either way, how is the compiler informed of these limits? > > Right, like I said, it's not going to be easy to define exactly what we > want. Or to convince the usual suspects that any definition we might come up with is useful/implementable/teacheable/... :-/ Thanx, Paul