From owner-freebsd-hackers@freebsd.org Sun Mar 3 16:41:06 2019 Return-Path: Delivered-To: freebsd-hackers@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 E777315109D3 for ; Sun, 3 Mar 2019 16:41:05 +0000 (UTC) (envelope-from asomers@gmail.com) Received: from mail-lf1-f65.google.com (mail-lf1-f65.google.com [209.85.167.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "GTS CA 1O1" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 6034D8AECB for ; Sun, 3 Mar 2019 16:41:05 +0000 (UTC) (envelope-from asomers@gmail.com) Received: by mail-lf1-f65.google.com with SMTP id p73so1177672lfe.10 for ; Sun, 03 Mar 2019 08:41:05 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=02ke6Y9nioz7OMFWzwHE0x2KijJllI7UJRyaDPy7VTU=; b=Y16F6QX924mPKerRwCajcgz5SiK6Oo0WzrNF/JzJBUHztpEIA4LPXUm5xIsMu4nEV5 XFm9Zhtw1dXp0kTzTZKkoL8HTpqgt12EMHi7rey4yPTkPTpht25Hj6a7wj+M5Z8wvP/O YSw+DTGkO/Y7SpbxchHMqcEYs21ScL3Wo4VLfgcTlwXyCErfRTAtBK08y3smLuGsZcAO pfL0/qjZRwIQtSbZj6j/saOLUBLPkFKFit5uYQTWQW1RLYaP6SrRUZQbbslVm/YaOTcg erJU9dTVDdna+iCAG6Wv4QEOeFPccD4/kMCwFFU2RD0v1bhCQHP3PdPDn3WkXvYMgMSq rTDQ== X-Gm-Message-State: APjAAAVNPtsQ0vqyLD8cPfd7JuKimA60ri1mvdG7R/jWWo4QZogXqCpy APxZ9qTj1mlo1t7brEZbGBVej0iBmtRf7Uqbtc0= X-Google-Smtp-Source: APXvYqzNsnGg/S6labwB9bvrho+WnYU88Zad7yY3AuWMRFNE2EiJX+vlcmL9UtmOqux9YaGn09TwqvFQJjrjG3hwnls= X-Received: by 2002:a19:c1c4:: with SMTP id r187mr8070925lff.10.1551631257890; Sun, 03 Mar 2019 08:40:57 -0800 (PST) MIME-Version: 1.0 References: <20190303110346.GH68879@kib.kiev.ua> <20190303162518.GK68879@kib.kiev.ua> In-Reply-To: <20190303162518.GK68879@kib.kiev.ua> From: Alan Somers Date: Sun, 3 Mar 2019 09:40:46 -0700 Message-ID: Subject: Re: Adding namecache entries outside of vfs_lookup and vn_open ? To: Konstantin Belousov Cc: FreeBSD Hackers Content-Type: text/plain; charset="UTF-8" X-Rspamd-Queue-Id: 6034D8AECB X-Spamd-Bar: ------ Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-6.98 / 15.00]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; NEURAL_HAM_SHORT(-0.98)[-0.981,0]; REPLY(-4.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000,0] X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 03 Mar 2019 16:41:06 -0000 On Sun, Mar 3, 2019 at 9:25 AM Konstantin Belousov wrote: > > On Sun, Mar 03, 2019 at 09:02:07AM -0700, Alan Somers wrote: > > On Sun, Mar 3, 2019 at 4:03 AM Konstantin Belousov wrote: > > > > > > On Sat, Mar 02, 2019 at 06:02:06PM -0700, Alan Somers wrote: > > > > It looks like lookup and open are the only common vops that create new > > > > namecache entries. At least, those are the only ones that set > > > > MAKEENTRY in the cn_flags field. However, fuse(4)'s create-like > > > > operations (FUSE_CREATE, FUSE_SYMLINK, etc) all return enough > > > > information to create a namecache entry for the newly created file. > > > > As-is, an operation like FUSE_CREATE will almost always be followed up > > > > by a FUSE_LOOKUP, necessitating an extra round-trip to userland. > > > In VFS, creation of the new file is done by VOP_CREATE() after negative > > > VOP_LOOKUP(). VOP_CREATE() returns the new vnode that is installed into > > > file. [A flag VN_OPEN_NAMECACHE was added for vn_open_cred() which results > > > in created name entry insertion into namecache. It was done to handle > > > very specific situation in core dump code, which is no longer relevant. > > > The flag is still there.] > > > > > > Similar discussion occured some time ago. I think that the current > > > selection of the cases where namecache entry is created, is optimized > > > for the scenario where extracting large tarball does not largely affect > > > the non-directory elements of the cache. If you do such extraction, > > > it is unlikely that you will access most of the files shortly. > > > > > > > Would it be possible and wise to add these newly created entries to > > > > the namecache automatically? > > > Not from VFS, but the policy can be overriden by the filesystem by inserting > > > the elements into cache from VOPs as it finds suitable. > > > > So MAKEENTRY is just advisory, and there shouldn't be a problem with > > inserting cache entries from fuse_nop_create even if MAKEENTRY isn't > > set? I might try that. The penalty for not doing so is an extra trip > > to userland, which is greater than the penalty for other file systems > > not doing it. > There can be problems from the too aggressive caching. See below. > > > > > > > > > Does FUSE cache vnodes ? I would find aggressive caching on the kernel > > > side somewhat unexpected for it. > > > > No, it just uses the regular vnode cache. The unique things that it > > does is it caches file attributes within the vnode, and the daemon can > > request a timeout period for either the attr cache or the entry cache. > > When the timeout expires, the kernel is supposed to purge (or ignore) > > its cached values. > > This is what I mean, e.g. one of the strategy there might be to reclaim > fuse vnode on inactivation. This is very harsh, of course, but was done > by nullfs not too long time ago. Currently fuse doesn't do anything special when the timeout expires. It only checks the timeout on lookup, and ignores the cached value if the timeout has already expired. > > For less contrived example, on NFS with its relatively defined semantic, > caching on the client sometimes become problematic. AFAIR, nfs client > re-checks mtime in strategic places, and ensures close-to-open > consistency by always flushing attributes on close, at least for NFS v3. > > I am somewhat surprised that for FUSE it is considered safe (and useful) > to cache at all. The daemon can choose the timeout period. For local filesystems like fusefs-ext2 it might set the timeout to infinity. For simple network filesystems like fusefs-sshfs it might set the timeout to 0, disabling all kernel cacheing. And for more sophisticated network filesystems like an NFSv4 client might set the timeout to a finite non-zero time. Later versions of the fuse protocol also allow the daemon to tell the kernel to immediately expire its cache. -Alan