Received: by 2002:a05:7412:1e0b:b0:fc:a2b0:25d7 with SMTP id kr11csp1192668rdb; Fri, 16 Feb 2024 07:59:35 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUzopC1rg+kCMSlu6rLFNhQwuqlgdDJO3b2KStMIdtWFPj9P2rz8geMyIJHU9rfYt5EL2tzzYS8Gji+geMBxoDIS+fu7iX5WX4zYF65gQ== X-Google-Smtp-Source: AGHT+IFL5he3qdJ1p7GRBsiuLl6L5RYNLWmWSW7E4m9sgSPhZn7m2cmAYKlXk4e/q818SLe7T4KG X-Received: by 2002:a05:6871:878d:b0:219:6e30:54c3 with SMTP id td13-20020a056871878d00b002196e3054c3mr6148385oab.6.1708099175386; Fri, 16 Feb 2024 07:59:35 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708099175; cv=pass; d=google.com; s=arc-20160816; b=Hk8gPJX2DBQ7tzLFNcqdkp/D5L3SJYaUPeqvSbuBlXpFcsgtjoHnsXLwmRET4kYy5I H7epsF7hjvinF1jH25Pg+sjkU87KytB2ZMSWbdIt22EtiJLzsQ4zD1yYSDJR5sRKbKrO dJxrhQ4zQxESekpisLKWcrxj5o8dBIFjS4kEXzAO9+B3wCicWSYZwyyk96giXeW8CIwx wWzyfn/ETqaVSDJXDcNYF8nsjLrV6ZDCoclkFa0vA8C1lNxXvmJZgZFaVrey8C19dThM 8QEGa5xITq+JIV9tcK/T+PIr1DI3Qj4mmvyxYFTnp8q8GhbhaGSA/XQoONEg7pR9BUlP DWGQ== 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:message-id:subject:cc :to:from:date:dkim-signature; bh=zCyJDd9dKPDmdypQXGurJ7KaNpNOw4+5thN7/7/eyiU=; fh=BM8BRNskD4762r+YX71K+rsIx12jgqz9VfqlZu/AT3M=; b=TeLXA4AaARfXUwxTHczaUEV27nkIL8vhuIqLqW7Fda7Bt2Km/sT0jh580dqvCdtQSZ 4uDCYAmF8kcZxoxjDfADIVPr1oUjUpLmQ3si0NC5PalfMUgUvepKrK6jCuAoTUnqKBou xnpxJYrFdp0DT7ciy5omrlkjVq1lb29kPoHZYjIoSlcd3LcfoxpeRKiaTPrp8n6nINVg dqM1pwXQmJN2o6Cj0K+Rzp2Qxg3f+4T2kpogxUVFkuBtTsERu/exdu6KRgRKg1/ynWGg I5f6mdQTAtH6WsJeGUE7QnhilkdMPsBMUZRfnTiV0zOCZwBAQdXLveUDvY+Tw9X42+Sn annQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b="C3dk/DW6"; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-68927-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-68927-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id t13-20020a05620a004d00b007873e889546si151444qkt.129.2024.02.16.07.59.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 07:59:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-68927-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b="C3dk/DW6"; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-68927-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-68927-linux.lists.archive=gmail.com@vger.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 25D0C1C22939 for ; Fri, 16 Feb 2024 15:59:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C52C412C809; Fri, 16 Feb 2024 15:57:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="C3dk/DW6" Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (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 355C4130AC8; Fri, 16 Feb 2024 15:57:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708099073; cv=none; b=kD6QL42ifpZSsLdpHsSPqcZeKz/5tTrnFsqzIpf4LIuaE11xV/bL/x+2u0B8Ys5C/koPeqKJ2Gd/Pm9WrJFqvadPN2gS9bS772fXWnPS1nOADnzwafx6SKy+14XBq97XYtivXbzCgbVGvdZ3AB16mJBhHg8ShM6Tv4IPQsW7TSw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708099073; c=relaxed/simple; bh=ITD6vm4D0hcte0a35hM4My1XHmKxCPQiRxMuV5erL6c=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=TTiXYdF5W+TPPa5YqXJ2URWD52+3m/mR7sQ/0Wu3POHCzSSxT72fHDt7tFtcd8WfT7N6jMgnU0ukI/pdMbeo7LiomQHIBLnvBYgTrBdvO+57UBH+dUBwRnTHt3t4Npkn3mZm7U3EDO3PoZJXBDTJtee56bn4IR9rOzrBW6xGkok= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=C3dk/DW6; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org 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=zCyJDd9dKPDmdypQXGurJ7KaNpNOw4+5thN7/7/eyiU=; b=C3dk/DW6uAoWvTuhYne1bfRsVK AFRFMv8cN14x0aHBmtqjvahsWzQK+FPnbZDYVHperY/+KHBRo1XhXb567u60YCv08qQ8J+MVeSGQ9 1x119URCwWtBQXYV5u3Fp+ktf+Afjf9+nsUaJK0ZIpmn+63y/Im5SUjp7ZE7tKmRq/ZslvmgixOt2 n7hihfuNkMxshd73kzO/yEJcUSTS7FrMe7ixIAu8TEU5eWUaZzyK7H2DC5OzqwyWkPuio4mo83+iB tbNOT59j9CjoFtIoRSKPUX3mgyxqdcuioLt3X5Ufel4z7HraKIzr9R/PBYNEpjMM3ypzTo9Y3duO1 qGjm3Vcw==; Received: from willy by casper.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1rb0as-000000053rW-287p; Fri, 16 Feb 2024 15:57:42 +0000 Date: Fri, 16 Feb 2024 15:57:42 +0000 From: Matthew Wilcox To: Jan Kara Cc: "Liam R. Howlett" , Chuck Lever , viro@zeniv.linux.org.uk, brauner@kernel.org, hughd@google.com, akpm@linux-foundation.org, oliver.sang@intel.com, feng.tang@intel.com, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, maple-tree@lists.infradead.org, linux-mm@kvack.org, lkp@intel.com Subject: Re: [PATCH RFC 7/7] libfs: Re-arrange locking in offset_iterate_dir() Message-ID: References: <170785993027.11135.8830043889278631735.stgit@91.116.238.104.host.secureserver.net> <170786028847.11135.14775608389430603086.stgit@91.116.238.104.host.secureserver.net> <20240215131638.cxipaxanhidb3pev@quack3> <20240215170008.22eisfyzumn5pw3f@revolver> <20240215171622.gsbjbjz6vau3emkh@quack3> <20240215210742.grjwdqdypvgrpwih@revolver> <20240216101546.xjcpzyb3pgf2eqm4@quack3> 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: <20240216101546.xjcpzyb3pgf2eqm4@quack3> On Fri, Feb 16, 2024 at 11:15:46AM +0100, Jan Kara wrote: > On Thu 15-02-24 16:07:42, Liam R. Howlett wrote: > > The limitations are outlined in the documentation as to how and when to > > lock. I'm not familiar with the xarray users, but it does check for > > locking with lockdep, but the way this is written bypasses the lockdep > > checking as the locks are taken and dropped without the proper scope. > > > > If you feel like this is a trap, then maybe we need to figure out a new > > plan to detect incorrect use? > > OK, I was a bit imprecise. What I wanted to say is that this is a shift in > the paradigm in the sense that previously, we mostly had (and still have) > data structure APIs (lists, rb-trees, radix-tree, now xarray) that were > guaranteeing that unless you call into the function to mutate the data > structure it stays intact. hm, no. The radix tree never guaranteed that to you; I just documented that it wasn't guaranteed for the XArray. > Now maple trees are shifting more in a direction > of black-box API where you cannot assume what happens inside. Which is fine > but then we have e.g. these iterators which do not quite follow this > black-box design and you have to remember subtle details like calling > "mas_pause()" before unlocking which is IMHO error-prone. Ideally, users of > the black-box API shouldn't be exposed to the details of the internal > locking at all (but then the performance suffers so I understand why you do > things this way). Second to this ideal variant would be if we could detect > we unlocked the lock without calling xas_pause() and warn on that. Or maybe > xas_unlock*() should be calling xas_pause() automagically and we'd have > similar helpers for RCU to do the magic for you? If you're unlocking the lock that protects a data structure while still using that data structure, you should always be aware that you're doing something very dangerous! It's no different from calling inode_unlock() inside a filesystem. Sure, you can do it, but you'd better be ready to deal with the consequences. The question is, do we want to be able to defragment slabs or not? My thinking is "yes", for objects where we can ensure there are no current users (at least after an RCU grace period), we want to be able to move them. That does impose certain costs (and subtleties), but just like fast-GUP and lockless page-cache, I think it's worth doing. Of course, we don't have slab defragmentation yet, so we're not getting any benefit from this. The most recent attempt was in 2019: https://lore.kernel.org/linux-mm/20190603042637.2018-1-tobin@kernel.org/ but there were earlier attepts in 2017: https://lore.kernel.org/linux-mm/20171227220636.361857279@linux.com/ and 2008: https://lore.kernel.org/linux-mm/20080216004526.763643520@sgi.com/ so I have to believe it's something we want, just haven't been able to push across the "merge this now" line.