From owner-freebsd-fs@freebsd.org Sat Jul 14 07:48:43 2018 Return-Path: Delivered-To: freebsd-fs@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 69A551044559 for ; Sat, 14 Jul 2018 07:48:43 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id BFA6C8F0F8 for ; Sat, 14 Jul 2018 07:48:42 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from tom.home (kib@localhost [127.0.0.1]) by kib.kiev.ua (8.15.2/8.15.2) with ESMTPS id w6E7mT6r029521 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Sat, 14 Jul 2018 10:48:32 +0300 (EEST) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua w6E7mT6r029521 Received: (from kostik@localhost) by tom.home (8.15.2/8.15.2/Submit) id w6E7mTDa029520; Sat, 14 Jul 2018 10:48:29 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Sat, 14 Jul 2018 10:48:29 +0300 From: Konstantin Belousov To: Jack Humphries Cc: freebsd-fs@freebsd.org Subject: Re: tmpfs questions Message-ID: <20180714074829.GR5562@kib.kiev.ua> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.0 (2018-05-17) X-Spam-Status: No, score=-2.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on tom.home X-BeenThere: freebsd-fs@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Filesystems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 14 Jul 2018 07:48:43 -0000 On Fri, Jul 13, 2018 at 05:42:59PM -0700, Jack Humphries wrote: > Hi everyone, > > I'm trying to study the FreeBSD tmpfs implementation as a personal > project, and I had a couple questions. I've been looking through the > code for a week and modifying various parts. I appreciate any help! > > 1. It seems that vnodes are locked before being passed to the various > VOP functions in tmpfs (because there is a call to > MPASS(VOP_ISLOCKED(vp)) near the beginning of each function). > Therefore, is the implicit assumption that a thread that holds the > vnode lock has exclusive access to the corresponding tmpfs_node > struct? In other words, is this why there are accesses to the tmpfs > node variables even though the tmpfs node is not locked? Note: I see > tn_interlock, but based on a comment above it in the source, it only > protects tn_vpstate and tn_status. tmpfs nodes are protected by the vnode locks. Note that vnode lock can be held exclusive or shared. Typically, only exclusive lock allows the code to modify the node, owning shared vnode lock only means that the node can be read safely. Interlock exists because node state must be examined sometimes without owning the vnode lock, in non-sleepable context. > > 2. What is the duplicate node list for (tn_dupindex)? If I had to > guess, it seems to have something to do with the case where one thread > calls readdir on a directory while another is modifying the directory, > but I'm not sure. Can someone explain this deeper? As an optimization, children of the directory node are organized into red/black tree, which cannot hold two entries with the same key value. If a second entry with the existing key is attempted to be created in the directory, it is added to the dup list instead.