Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp1036345rdh; Fri, 27 Oct 2023 02:57:16 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG7a+ty+fYEqUnZc2POWY9Z+cl4T5gXsi5SnabhcnNKi/vPvd4SomjFKid6A6hU6iur6eAU X-Received: by 2002:a54:468f:0:b0:3a8:4d1f:9dd0 with SMTP id k15-20020a54468f000000b003a84d1f9dd0mr2042653oic.30.1698400636561; Fri, 27 Oct 2023 02:57:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698400636; cv=none; d=google.com; s=arc-20160816; b=cSjGr0q7WSKOA0lwbpkRlIk6QPC413dyfGHkrxm6xjikwqjUXBqF4aQQ+o4Hy8q3nb Gm4SbML6Vu6Z7QSNn10r78mJTSKwOZoBeZmn8dNxDO6EgzweA1XDmU6t53A3xy81eNXR 0Hr1W4GkvVYGMoJU8ZeX5guwJ2A545uR30Pw2TZrLDQhn7P3PRNSq12cXEIgGDgGzdGW X6+1bnz1SprvstqBuOBRnvhYy9bDkQu2Y44q3dz9c3L+6SaN1ZMxnJjp+IblPyIq6PRH Ra6WcYAVbsZBlexJ3vzr27QwcITADI8SDhm48EksTRF0ZYqCvXtBAZORVqcLFofLOOQc JLPQ== 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:dkim-signature :dkim-signature; bh=YD1o6sfRvS2RQUo/el5YTc3fUIklZeB7u3TV/v2B32U=; fh=EiRkSfX495s6eGaH7l93AlKUJleuBnVhzVipWbKZNSQ=; b=qV/Y4O8lY+eRbOyZYAH45OWF5OPB+BmYzO3KIcRa23ZAzg1QKZKuyl0Df80JCoVE8/ b1rpqDnC2Y18Jth4SHrYMjXhX6UyjuH2vDKx3C+UcHi4PahwkDQllRhQTLOQCjyWdttn qqJDgbwnSK544HnB7DRBxO0EjxEu8bkGZ5nn7YdOtNeA90Jp6wdH2g5eFssXeNKfw44b 0C6tJJyM6iqLy9s71ga+s+JuAEkpF6HdDio0ahgTXSVz+Swt5BHJoUUybpACJK7OBvya rtMvpNM3SFTEk5CXun3RFbF8EmCU7UV6u0xTftCYkSjT5oXaJORoDBUWrLcq3yRkHg9j 864Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=WhnsnkgU; dkim=neutral (no key) header.i=@suse.cz header.b=ke4guPlc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id g10-20020a5b070a000000b00da03911c356si1892364ybq.275.2023.10.27.02.57.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Oct 2023 02:57:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=WhnsnkgU; dkim=neutral (no key) header.i=@suse.cz header.b=ke4guPlc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 3D1D8808405C; Fri, 27 Oct 2023 02:56:14 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345535AbjJ0J4B (ORCPT + 99 others); Fri, 27 Oct 2023 05:56:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230502AbjJ0Jz7 (ORCPT ); Fri, 27 Oct 2023 05:55:59 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 668E3191; Fri, 27 Oct 2023 02:55:55 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id ED2282189F; Fri, 27 Oct 2023 09:55:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1698400553; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=YD1o6sfRvS2RQUo/el5YTc3fUIklZeB7u3TV/v2B32U=; b=WhnsnkgUiSPGNj9yVikeYVC2OHDoRpPDBDXIJN1U8obNSQrsmwRCBfDFG6TRezTEiMr9C+ 4Wj3og1/lzAsexOaxFMgPOKtBiIurYHfhvtOeZt9JxYIzjKud4IjjOdvomEeDIXRFBvXm0 UrTVyqP1GKapyvVYQxQLnuGYyAiu4Ew= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1698400553; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=YD1o6sfRvS2RQUo/el5YTc3fUIklZeB7u3TV/v2B32U=; b=ke4guPlc+Sq6VnmXl9etET2DE6fltwJnVVxcoCaoQ3CGDim4SGlX8FbNcc9YhBp4CtrHQW RCx6v/Sh/EbDpAAg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id D3A9F13524; Fri, 27 Oct 2023 09:55:53 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id xrM8MymJO2VWagAAMHmgww (envelope-from ); Fri, 27 Oct 2023 09:55:53 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 63479A05BC; Fri, 27 Oct 2023 11:55:53 +0200 (CEST) Date: Fri, 27 Oct 2023 11:55:53 +0200 From: Jan Kara To: Yury Norov Cc: Rasmus Villemoes , kernel test robot , Jan Kara , oe-lkp@lists.linux.dev, lkp@intel.com, linux-kernel@vger.kernel.org, ying.huang@intel.com, feng.tang@intel.com, fengwei.yin@intel.com, Andy Shevchenko , Mirsad Todorovac , Matthew Wilcox , linux-fsdevel@vger.kernel.org Subject: Re: [PATCH 1/2] lib/find: Make functions safe on changing bitmaps Message-ID: <20231027095553.7zdfk36babswvw25@quack3> References: <202310251458.48b4452d-oliver.sang@intel.com> <374465d3-dceb-43b1-930e-dd4e9b7322d2@rasmusvillemoes.dk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Authentication-Results: smtp-out1.suse.de; none X-Spam-Level: X-Spam-Score: -5.10 X-Spamd-Result: default: False [-5.10 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; BAYES_HAM(-3.00)[100.00%]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; TAGGED_RCPT(0.00)[]; MIME_GOOD(-0.10)[text/plain]; NEURAL_HAM_LONG(-3.00)[-1.000]; DKIM_SIGNED(0.00)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519]; NEURAL_HAM_SHORT(-1.00)[-1.000]; RCPT_COUNT_TWELVE(0.00)[14]; FREEMAIL_TO(0.00)[gmail.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; MID_RHS_NOT_FQDN(0.50)[]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[]; SUSPICIOUS_RECIPS(1.50)[] X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Fri, 27 Oct 2023 02:56:14 -0700 (PDT) On Thu 26-10-23 20:51:22, Yury Norov wrote: > On Wed, Oct 25, 2023 at 10:18:00AM +0200, Rasmus Villemoes wrote: > > Yes, users will have to treat results from the find routines carefully > > if their bitmap may be concurrently modified. They do. Nobody wins if > > those users are forced to implement their own bitmap routines for their > > lockless algorithms. > > Again, I agree with this point, and I'm trying to address exactly this. > > I'm working on a series that introduces lockless find_bit functions > based on existing FIND_BIT() engine. It's not ready yet, but I hope > I'll submit it in the next merge window. > > https://github.com/norov/linux/commits/find_and_bit I agree that the find_and_{set|clear}() bit functions are useful and we'll be able to remove some boilerplate code with them. But also note that you will need to duplicate practically all of the bitmap API to provide similar "atomic" functionality - e.g. the sbitmap conversion you have in your branch has a bug that it drops the 'lock' memory ordering from the bitmap manipulation. So you need something like find_and_set_bit_lock() (which you already have) and find_and_set_bit_wrap_lock() (which you don't have yet). If you are to convert bitmap code in filesystems (some of which is lockless as well), you will need to add little and big endian variants of volatile bitmap functions. Finally there are users like lib/xarray.c which don't want to set/clear found bit (we just want to quickly find a good guess for a set bit in the bitmap and we then verify in another structure whether the guess was right or not). So we'll need the volatile variant of plain find_first_bit(), find_next_bit() as well. Also when we have variants of bitmap functions that are safe wrt parallel changes and those that are not, the function names should be probably indicating which are which. So as much as I agree your solution is theorically the cleanest, I personally don't think the cost in terms of code duplication and code churn is really worth it. > Now that we've got a test that presumably works faster if find_bit() > functions are all switched to be volatile, it would be great if we get > into details and understand: > - what find_bit function or functions gives that gain in performance; > - on what bitmap(s); > - is the reason in concurrent memory access (guess yes), and if so, > - can we refactor the code to use lockless find_and_bit() functions > mentioned above; > - if not, how else can we address this. Frankly, I don't think there's any substantial reason why the volatile or non-volatile code should be faster. The guys from compiler team looked at the x86 disassembly and said both variants should be the same speed based on instruction costs. What could be causing these small performance differences is that the resulting code is layed out slightly differently (and the volatile bitmap functions end up being somewhat larger) and that somehow interferes with instruction caching or CPU-internal out-of-order execution. Honza -- Jan Kara SUSE Labs, CR