Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754025AbbDTVc5 (ORCPT ); Mon, 20 Apr 2015 17:32:57 -0400 Received: from zeniv.linux.org.uk ([195.92.253.2]:35007 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751386AbbDTVcu (ORCPT ); Mon, 20 Apr 2015 17:32:50 -0400 Date: Mon, 20 Apr 2015 22:32:47 +0100 From: Al Viro To: Linus Torvalds Cc: Neil Brown , Linux Kernel Mailing List , linux-fsdevel Subject: Re: [PATCH 16/24] link_path_walk: kill the recursion Message-ID: <20150420213247.GN889@ZenIV.linux.org.uk> References: <20150420181222.GK889@ZenIV.linux.org.uk> <1429553588-24764-16-git-send-email-viro@ZenIV.linux.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2209 Lines: 39 On Mon, Apr 20, 2015 at 02:04:53PM -0700, Linus Torvalds wrote: > That said, you then introduce a stack-allocated "struct saved stack[]" > in path_mountpoint[] instead, *and* nameidata is saved on stack, so > this all ends up being very stack-intensive anyway. > > I might have missed some patch here, but would it be possible to just > allocate a single per-thread nameidata, and just leave it at that? > Because allocating that thing on the stack when it contains what is > now one kilobyte of array data is *not* acceptable. What kilobyte? It's 9*4 pointers, IOW, 288 bytes total (assuming 64bit box). And nd->saved_names[] goes away, so scratch 9 pointers we used to have. Sure, we can allocate that dynamically (or hold a couple of elements on stack and allocate when/if we overgrow that), but it's not particularly large win. Breakeven point is circa the second level of nesting - symlink met when traversing a symlink... That - on amd64; on something with fatter stack frames I would expect the comparison to be even worse for mainline... We need to preserve 4 pointers on stack per level of nesting. Seeing that single link_path_walk() stack frame in mainline is about 5-6 times bigger than that, "just put enough for all levels into auto array" is an obvious approach - a couple of link_path_walk() stack frames will be heavier than that. For renameat() (the worst-case user of link_path_walk() - there are two struct nameidata on stack) we end up with breakeven at *one* level of nesting, what with getting rid of 2*9 pointers in ->saved_names[] of those nameidata. And yes, I've measured the actual stack use before and after... A kilobyte would suffice for 32 levels. _IF_ we go for "lift the restrictions on nesting completely", sure, we want to switch to (on-demand) dynamic allocation. It's not particularly hard to add and it might be worth doing, but it's a separate story. This series leaves the set of accepted pathnames as-is... -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/