Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp447562pxb; Fri, 16 Apr 2021 09:21:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz4w2me8bLyeha03mbf/8fnGE+21lqD/vDtJdEFHtn2XPawmzyg/RgYb6NdBD5NWG4O068k X-Received: by 2002:a17:906:7e53:: with SMTP id z19mr9206546ejr.422.1618590108909; Fri, 16 Apr 2021 09:21:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618590108; cv=none; d=google.com; s=arc-20160816; b=u733Tw5Kn7/sHsjWnmWaO5PDpeA2x1K8l1op74IuX3xKb8Df3KBG/uSmNPGpDqTqb+ Y0X+WoDKWEPYvblgbwOsc8h0lxEdH/Q2/nv9Z51RR+PzJ6J/WSt7RR8Tdhx3CPLV6G+h 6bBvaiczPBatcHX6PVMtCbDyy0DaVGMv1WDkM+lqJVQeRVYO/1OFuUarA9OndNXj5kp3 NbzgcZ9LfrQKoiyRtY3gXknKBt5MsckHg+QAwG5255MXtyjKn86xs9T/CH2KFrScmavw a0vdgSZjafXdpxHjzoolQdchipolBqS6UYgou8HQ758Iib67nPrqZRYAKaACm8tcormL jhMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=V2Rtf/ohp7bYT/1XQf32+r2fwToBN+iwo0KVPCPgxuw=; b=VZl96hW1r6zGHJydyxaGgjg7wLFUBBW5YApq+PBlEfSmFRC94qUdOIBNRB5MNiXxNm H/mMnLwhNR+U+3lLL97o89VwBzcIMAL/K6zkldbMUZYQj1Wu+CKq2XBjs3/tmdO7trOD WVq/pkYwdgr7Vpfi+7qE1AEkymYBM5fs3RzIIxqa12CKxuETKC8/7RZn8/MZZYf8kDJq Atxle6HDIjg4cLsg/LOAINa0QXGrsdlYA2rvKfHvgRJtz3jrVVVF6AIZcreP88LW9UAy caMT19NLRq6jZ7jrYIMi+Uh0Be4XYzYnIZ0I1jRasMwEXOI0WJq7h05eutdj7+aalIbz bt7Q== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m26si5287043edp.104.2021.04.16.09.21.26; Fri, 16 Apr 2021 09:21:48 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237700AbhDPP6v (ORCPT + 99 others); Fri, 16 Apr 2021 11:58:51 -0400 Received: from outgoing-auth-1.mit.edu ([18.9.28.11]:45829 "EHLO outgoing.mit.edu" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S236485AbhDPP6u (ORCPT ); Fri, 16 Apr 2021 11:58:50 -0400 Received: from cwcc.thunk.org (pool-72-74-133-215.bstnma.fios.verizon.net [72.74.133.215]) (authenticated bits=0) (User authenticated as tytso@ATHENA.MIT.EDU) by outgoing.mit.edu (8.14.7/8.12.4) with ESMTP id 13GFw586010940 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 16 Apr 2021 11:58:06 -0400 Received: by cwcc.thunk.org (Postfix, from userid 15806) id 409B115C3B0D; Fri, 16 Apr 2021 11:58:05 -0400 (EDT) Date: Fri, 16 Apr 2021 11:58:05 -0400 From: "Theodore Ts'o" To: Wedson Almeida Filho Cc: Peter Zijlstra , ojeda@kernel.org, Linus Torvalds , Greg Kroah-Hartman , rust-for-linux@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 00/13] [RFC] Rust support Message-ID: References: <20210414184604.23473-1-ojeda@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Apr 16, 2021 at 02:07:49PM +0100, Wedson Almeida Filho wrote: > On Fri, Apr 16, 2021 at 01:24:23PM +0200, Peter Zijlstra wrote: > > On Wed, Apr 14, 2021 at 08:45:51PM +0200, ojeda@kernel.org wrote: > > > - Featureful language: sum types, pattern matching, generics, > > > RAII, lifetimes, shared & exclusive references, modules & > > > visibility, powerful hygienic and procedural macros... > > > > IMO RAII is over-valued, but just in case you care, the below seems to > > work just fine. No fancy new language needed, works today. Similarly you > > can create refcount_t guards, or with a little more work full blown > > smart_ptr crud. > > Peter, we do care, thank you for posting this. It's a great example for us to > discuss some of the minutiae of what we think Rust brings to the table in > addition to what's already possible in C. Another fairly common use case is a lockless, racy test of a particular field, as an optimization before we take the lock before we test it for realsies. In this particular case, we can't allocate memory while holding a spinlock, so we check to see without taking the spinlock to see whether we should allocate memory (which is expensive, and unnecessasry most of the time): alloc_transaction: /* * This check is racy but it is just an optimization of allocating new * transaction early if there are high chances we'll need it. If we * guess wrong, we'll retry or free the unused transaction. */ if (!data_race(journal->j_running_transaction)) { /* * If __GFP_FS is not present, then we may be being called from * inside the fs writeback layer, so we MUST NOT fail. */ if ((gfp_mask & __GFP_FS) == 0) gfp_mask |= __GFP_NOFAIL; new_transaction = kmem_cache_zalloc(transaction_cache, gfp_mask); if (!new_transaction) return -ENOMEM; } ... repeat: read_lock(&journal->j_state_lock); ... if (!journal->j_running_transaction) { read_unlock(&journal->j_state_lock); if (!new_transaction) goto alloc_transaction; write_lock(&journal->j_state_lock); if (!journal->j_running_transaction && (handle->h_reserved || !journal->j_barrier_count)) { jbd2_get_transaction(journal, new_transaction); new_transaction = NULL; } write_unlock(&journal->j_state_lock); goto repeat; } ... The other thing that I'll note is that diferent elements in thet journal structure are protected by different spinlocks; we don't have a global lock protecting the entire structure, which is critical for scalability on systems with a large number of CPU's with a lot of threads all wanting to perform file system operations. So having a guard structure which can't be bypassed on the entire structure would result in a pretty massive performance penalty for the ext4 file system. I know that initially the use of Rust in the kernel is targetted for less performance critical modules, such as device drivers, but I thought I would mention some of the advantages of more advanced locking techniques. Cheers, - Ted