Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2278302pxp; Mon, 21 Mar 2022 15:42:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyF96vy3tCA+JBC3bg21vyz3TextKsfhoBidO4pvV/Uibpxh+307ApWDIetZii+yAad1mTd X-Received: by 2002:a05:6a00:a1d:b0:4f6:d122:cd08 with SMTP id p29-20020a056a000a1d00b004f6d122cd08mr26205550pfh.68.1647902530801; Mon, 21 Mar 2022 15:42:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647902530; cv=none; d=google.com; s=arc-20160816; b=s4vtbPEe1OQnYSKcnLgoCdF3bMtJHp+S0f9sZ+iMZ2A4c8TMu8CICc5hW1C7cBYfGd pCvv7zNv8eapZHeA3vIxjVcpFjnkKri07UUelFQxWr8WJZ24A6mnBcH/1FaaTy4l6mBB 3lC/TayL5rgwOorW7/mRT9hJVomI27VMpbwrU8ZMPC55zUmPBu+Tqjrwzvhq3H0A6XQs xc1L/QxS1b27R818dsznKnXDu5im8XthfIl1JqDD7uCR2Xsv3QU5HTshONXII5bRwPH4 rNC/osY8aDqz+sv58YtPiAOYNC2tW6eW+mJrDIcEKY+5AfElsrR+w20VE0L8a8zvo7x+ G+lQ== 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:sender:dkim-signature; bh=95YhjwXki3u5hxuRlqlEClEXa9Pk9skNf0mQT0wjwEg=; b=VqVeCgdB9Kt+Lg4RSmWk/oDddDdw/2A5X9EuXppGwKlKuOLnkCmwSoqfMOC3EdbFav Bv0oqEOrXJBPzyCrH2pJaDqJETF0bWtaCrkUmb/Ou6Ljt6ogTLs2HE60Lrr6I9o1S7QG pOtpIewPSjXHYgQ4lcAXcHQiNpDuW5PMz2CqubNHIFwxz/7bDv5JN6E/2B6xxm6K5i+S vo8VUrWXu0ddjDm1V9TxIXN+3z1d03ozKqxzpQ/kq87sONvG2KAfz8esEg8TdLA205sg VJTCbyRjaSyljIxBJCUXCUWsgxnz8VITYN4RGKpIKTiFoZET9gn3u3NzMky8o7N9uC94 Fw7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Zf45MCHI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id j4-20020a170902c3c400b00153b2d16543si11393256plj.331.2022.03.21.15.42.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Mar 2022 15:42:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Zf45MCHI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 43E973CA1BE; Mon, 21 Mar 2022 14:54:58 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352649AbiCUTVh (ORCPT + 99 others); Mon, 21 Mar 2022 15:21:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43694 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350210AbiCUTVe (ORCPT ); Mon, 21 Mar 2022 15:21:34 -0400 Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3607265816 for ; Mon, 21 Mar 2022 12:20:09 -0700 (PDT) Received: by mail-pj1-x1036.google.com with SMTP id n7-20020a17090aab8700b001c6aa871860so177232pjq.2 for ; Mon, 21 Mar 2022 12:20:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=95YhjwXki3u5hxuRlqlEClEXa9Pk9skNf0mQT0wjwEg=; b=Zf45MCHIGlLKE4vbREeKCEGQx/HGWqtDoDnYvedfgmmhV585xZ1TRL+B08Os/YW2Nm 4XURP+1dEqaYrlREXrNdJTRRvXMZYYKPfV/SMHpbGH81eiV3wS7YlwBbjbFGJvkr24KK VxV1Zhw3T+g4p3FO+3pxU2qtV4N/VgJE5auxCwvbTtV7hTjW/aOL58m7HEvtPInPycdO +HuX7zlKWL9ThLeJLKwb5fWFHcDv2+7W/adSWnkfsygogW1ryOIMoiFsZCjS96dCo7dp kdLqLeFpppxBkxekOznkiDgexKCSfa4cDK5WSRgoACedT3gllwA1QBoJNxIcFi7Ei6Gv xQXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to; bh=95YhjwXki3u5hxuRlqlEClEXa9Pk9skNf0mQT0wjwEg=; b=raoT45B3d4v/p+JLu5Dxuf5pFpVYmOXwgqjxXzwbvi9aPO12u8KoVoy3392If7NZDT tFtP+rEyMEWKnHo4Ey9N0jJMmhPMlzAI0MdLTtG0eZtvqvfkvyBn9HAoW2h3fLX+lpDM 2N7RtuRXDhCV0d+0dVQxs/pm4o7/NIafGHWgT+JQvEFWNxdWoGJ3ddqMJsdo396hmJNk 7meIbIW8TUzOlRffiEF8IKtnuLS0NvLIaE0VvqQvHW7hhU0CB1vG6c7BfYoUi4oU/euT UpmT4O5FvJKhkAj/RuKxbKJaOaXB7QDeboAdGcNWKrfZdyGPzxowTQN36JSnZXfh04KL AOBw== X-Gm-Message-State: AOAM531ZGvxRUUgLC94tGErJ4friP4WxCSddmrkxkILXeVyQavp3oRZ6 NvZV9zij5rWgCWN3JLXQSdo= X-Received: by 2002:a17:902:70cc:b0:154:1cc8:9df8 with SMTP id l12-20020a17090270cc00b001541cc89df8mr14593851plt.32.1647890408413; Mon, 21 Mar 2022 12:20:08 -0700 (PDT) Received: from localhost (2603-800c-1a02-1bae-e24f-43ff-fee6-449f.res6.spectrum.com. [2603:800c:1a02:1bae:e24f:43ff:fee6:449f]) by smtp.gmail.com with ESMTPSA id k3-20020a056a00168300b004f7e60da26csm20779672pfc.182.2022.03.21.12.20.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Mar 2022 12:20:07 -0700 (PDT) Sender: Tejun Heo Date: Mon, 21 Mar 2022 09:20:06 -1000 From: Tejun Heo To: Al Viro Cc: Imran Khan , gregkh@linuxfoundation.org, akpm@linux-foundation.org, linux-kernel@vger.kernel.org Subject: Re: [RESEND PATCH v7 7/8] kernfs: Replace per-fs rwsem with hashed rwsems. Message-ID: References: <20220317072612.163143-1-imran.f.khan@oracle.com> <20220317072612.163143-8-imran.f.khan@oracle.com> <536f2392-45d2-2f43-5e9d-01ef50e33126@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello, On Mon, Mar 21, 2022 at 05:55:53PM +0000, Al Viro wrote: > Why bother with rwsem, when we don't need anything blocking under it? > DEFINE_RWLOCK instead of DEFINE_SPINLOCK and don't make it static. Oh I mean, in case the common readers get way too hot, percpu_rwsem is a relatively easy way to shift the burder from the readers to the writers. I doubt we'll need that. > kernfs_walk_ns() - this is fucking insane; on the surface, it needs to > be exclusive due to the use of the same static buffer. It uses that > buffer to generate a pathname, *THEN* walks over it with strsep(). > That's an... interesting approach, for the lack of other printable > terms - we walk the chain of ancestors, concatenating their names > into a buffer and separating those names with slashes, then we walk > that buffer, searching for slashes... WTF? It takes the @parent to walk string @path from. Where does it generate the pathname? > kernfs_rename_ns() - exclusive; that's where the tree topology gets > changed. This is the only true writer and it shouldn't be difficult to convert the others to read lock w/ e.g. dynamic allocations or percpu buffers. > So we can just turn that spinlock into rwlock, replace the existing > uses with read_lock()/read_unlock() in kernfs_{name,path_from_node,get_parent} > and with write_lock()/write_unlock() in the rest of fs/kernfs/dir.c, > make it non-static, put extern into kernfs-internal.h and there you > go... > > Wait a sec; what happens if e.g. kernfs_path_from_node() races with > __kernfs_remove()? We do _not_ clear ->parent, but we do drop references > that used to pin what it used to point to, unless I'm misreading that > code... Or is it somehow prevented by drain-related logics? Seeing > that it seems to be possible to have kernfs_path_from_node() called from > an interrupt context, that could be delicate... kernfs_remove() is akin to freeing of the node and all its descendants. The caller shouldn't be racing that against any other operations in the subtree. Thanks. -- tejun