Received: by 10.192.165.156 with SMTP id m28csp2969016imm; Sun, 15 Apr 2018 13:43:43 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/gqkE9P4vyW9mW5uJyheEcUVM895WlB0txLnxqzaADHYECI30Wc2+7+6LTnmcSoEVutVFc X-Received: by 10.98.7.152 with SMTP id 24mr19154622pfh.94.1523825023602; Sun, 15 Apr 2018 13:43:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523825023; cv=none; d=google.com; s=arc-20160816; b=HPcGP4UFTcGWn/TYfa6nKxL3NJZ6pefEOIC+o5rdWGpUvl/wGWiUCavoe+ms5uBqm8 2szSAnLdgv41MwctFack6VYYKvgjnF2Y4cGsVXdUiT4Zbz8TUDksDZkolzuTSvLEUuXq 0j9QRGXOegfxwl2yQeusK5kkeHFWZoUUt7sa+AccNT0XK2qUJqwNYUZKnkJf+/bldR4n MImGdI8awboz6yK/gIeWGX3RQsl2ZubK0hc2MsD1RdZj90ay86nKMWw75gFrMx/tAH2z pxLhx15vPRhVRLBpcSKz1Pf9U5Dcgp8nJiCoNd6TgpMkae7R7nlJ8SimfQenfOySUvgW sl/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date :arc-authentication-results; bh=z/FaFvu2IT3F+qtalrRhUu67I5QohiG9nyRyOTIiFkY=; b=ebbfAiybgdlst071v6V9PR4K7mL5uQ5OTtDXwAFLxoVkeZ7w9w/OuEgAWp1NzQJGgO U2eBhOrdrpeun65giuaVCBuRTqpeJ1dHsdgw5A+FFR0OC/64S7pOA+ZpWRvJw7i+MvmA 6+n/NoN6Z53eAl3jrQz1M0Jr2wZQR2VYC8lM8nS2X+C88CbyfOoHGBcs0CifxkZOmIUu Few3N1x7KfxklSShXG5mFuptIUdUY6XELbXhl+Xe5CJRk2pzhU0nM7YDkh61M5pfW1no jOxAD81AtbdEk7lf+HgdRZOKcC9bBDS2TUG/OKpKllRE/eiJVQfwvzLs07Jc8B/FGXZj OCYQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a1si8767049pfn.314.2018.04.15.13.43.17; Sun, 15 Apr 2018 13:43:43 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752824AbeDOUlC (ORCPT + 99 others); Sun, 15 Apr 2018 16:41:02 -0400 Received: from zeniv.linux.org.uk ([195.92.253.2]:52994 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752464AbeDOUlA (ORCPT ); Sun, 15 Apr 2018 16:41:00 -0400 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.87 #1 (Red Hat Linux)) id 1f7oSE-0001NW-PO; Sun, 15 Apr 2018 20:40:54 +0000 Date: Sun, 15 Apr 2018 21:40:54 +0100 From: Al Viro To: Linus Torvalds Cc: Nikolay Borisov , Andrew Morton , Khazhismel Kumykov , linux-fsdevel , Linux Kernel Mailing List , David Rientjes , Goldwyn Rodrigues , Jeff Mahoney , Davidlohr Bueso Subject: Re: [PATCH] fs/dcache.c: re-add cond_resched() in shrink_dcache_parent() Message-ID: <20180415204054.GA30522@ZenIV.linux.org.uk> References: <20180413181350.88831-1-khazhy@google.com> <20180413202823.204377-1-khazhy@google.com> <20180413141430.2788e2562e3e24bd273fe78b@linux-foundation.org> <3362fb2d-85ff-86af-399f-698c986e46cc@suse.com> <20180414080206.GV30522@ZenIV.linux.org.uk> <20180414205846.GW30522@ZenIV.linux.org.uk> <20180415005056.GX30522@ZenIV.linux.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.9.1 (2017-09-22) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Apr 15, 2018 at 11:34:17AM -0700, Linus Torvalds wrote: > No, it's obviously not type-safe, but at least it's _legible_, and is > a pattern, while that "let's randomly just do a cast in the middle of > the code" is just nasty. Sure, no problem... I really wish there was a way to say void foo(int (*f)(α *), α *data) ∀ α and have the compiler verify that foo(f, v) is done only when f(v) is well-typed, but that's C, not Haskell... The best approximation is something along the lines of void __foo(int (*f)(void *), void *data); #define foo(f, v) (sizeof((f)((v)), 0), __foo((f),(v))) and that relies upon the identical calling sequence for all pointer arguments. AFAIK, it's true for all ABIs we support, but... Worse, there's no way to get #define in macro expansion, so the above would be impossible to hide behind anything convenient ;-/ > Side note: I do feel like "d_walk()" should be returning whether it > terminated early or not. For example, this very same code in the > caller does > > + struct dentry *victim = NULL; > + d_walk(dentry, &victim, find_submount); > + if (!victim) { > > but in many ways it would be more natural to just check the exit condition, and > > + struct dentry *victim; > + if (!d_walk(dentry, &victim, find_submount)) { > > don't you think? Because that matches the actual setting condition in > the find_submount() callback. > > There are other situations where the same thing is true: that > path_check_mount() currently has that "info->mounted" flag, but again, > it could be replaced by just checking what the quit condition was, and > whether we terminated early or not. Because the two are 100% > equivalent, and the return value in many ways would be more logical, I > feel. > > (I'm not sure if we should just return the actual exit condition - > defaulting to D_WALK_CONTINUE if there was nothing to walk at all - or > whether we should just return a boolean for "terminated early") > > Hmm? Not sure... There are 5 callers: * do_one_tree(), d_genocide() - nothing to return * path_has_submounts(), d_invalidate() - could use your trick, but d_invalidate() wants to look at victim if not buggering off, so that one doesn't win much * shrink_dcache_parent() - no way to use that. Here we normally run the walk to completion and need to repeat it in all cases of early termination *and* in some of the ran-to-completion cases. BTW, the current placement of cond_resched() looks bogus; suppose we have collected a lot of victims and ran into need_resched(). We leave d_walk() and call shrink_dentry_list(). At that point there's a lot of stuff on our shrink list and anybody else running into them will have to keep scanning. Giving up the timeslice before we take care of any of those looks like a bad idea, to put it mildly, and that's precisely what will happen. What about doing that in the end of __dentry_kill() instead? And to hell with both existing call sites - dput() one (before going to the parent) is obviously covered by that (dentry_kill() only returns non-NULL after having called __dentry_kill()) and in shrink_dentry_list() we'll get to it as soon as we go through all dentries that can be immediately kicked off the shrink list. Which, AFAICS, improves the situation, now that shrink_lock_dentry() contains no trylock loops... Comments?