Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp1193858ybm; Tue, 21 May 2019 10:02:16 -0700 (PDT) X-Google-Smtp-Source: APXvYqxBQ0pZ9M5s7MFs+E2AT9i8h0KQmzMA1pJ6V04xW50AmosU8XwvxifdP6kk22TfCca2fD6n X-Received: by 2002:a17:902:8f98:: with SMTP id z24mr8861983plo.101.1558458136094; Tue, 21 May 2019 10:02:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558458136; cv=none; d=google.com; s=arc-20160816; b=Ggd8S7UDe4AqHZjJUsA4k6BTwOeRER8OXQ1pObRwj4CIarlcPF2ftyPaOcgTjP/fnm tMsIOMYaH9CZpeAJge5LNk2XrfuAw7j4Br4ilmz9Y67auW8mvK2WbSLQOXcR+cqyUU4t RZawKb7FvVcovbJtbNq6RqvJ/wRwrxMB0GmBFPaU27j1wiYoFNyEoq7xJ2mOEcUWN/IF MCpiqa7kEK5uHaNPmU2T4hclUoKbxHabUa+KD1DhRhHQu3qn75hUmCnf9zKl/1TbkaBQ TEtRF1JG9ho7QOIfyH9v6sdKcIOB3kpOtOh/OnplkTxE0OI+ISIw4sxMe4mO48r6MUl/ po0g== 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-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=QRw4dWFrlFKNeC2Hv6jFCNR7pmJ9ZVloUzzaJsWHe3k=; b=xrzdOdalFcAP6IxnUfaP/XpdIsGU4+BHB4dEF5wGwPlL/lhMdHEhGNswidYHVwgcNb ZOK9b/K+AktAj8q2HZ/T29lxp2Db+TNglzkl4Kv7BL2aeWT+yvz9sIm3m4X5xosAp9HH nAEOvrG9AMqQ776rDud5M+htw2mgP4ya+BfjBYvq8oxCj4p5gkJm12H0ORc4e1Du0x5D +smyFRzh1UUOVGVjW7DzJHHz9VPgIUBDoGdLl3vMledoyeG8iwVpQQBRnq9cD15Ujpon 0BYs8vO4CqCYZnLrUnbnL7v6KTK82DhTS9ZRn5lpQEuJ2LZsc0z8LbwgJ5BOurP9uEWJ oepA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@brauner.io header.s=google header.b=DrUfMEDj; 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 m14si14431934pgj.377.2019.05.21.10.02.01; Tue, 21 May 2019 10:02:16 -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; dkim=pass header.i=@brauner.io header.s=google header.b=DrUfMEDj; 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 S1728606AbfEUQlr (ORCPT + 99 others); Tue, 21 May 2019 12:41:47 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:37481 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727965AbfEUQlq (ORCPT ); Tue, 21 May 2019 12:41:46 -0400 Received: by mail-wm1-f68.google.com with SMTP id 7so3585140wmo.2 for ; Tue, 21 May 2019 09:41:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brauner.io; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=QRw4dWFrlFKNeC2Hv6jFCNR7pmJ9ZVloUzzaJsWHe3k=; b=DrUfMEDjMCX/F/kpAns9Xje6tAglSh3UhG5Ut0HpXQH/i/WF067F5FUZoHtyFcz92J B9zO7Q3xmWBLCoBBlKTKoCtUiQsaTMx3Npeppmj4pHHAb15DBLIi9tECGzeTa0qz68HY 5SJCekbjPP909njq82OecOWv07W5VLYr5VkHE6sbSe+2o5Mw73nXEvvOijdE8vUJH9BM uSenbJ2wN1Uv1xiE6qAy9CpI8LAAlCfwF/dLDfgYTm5Xge0CjqlWt1lxcYk7Ou9/XL7L lIMEXS/i0lcGD5hbzAqtPxjiA1/NY2p62maSbnW0JtvlH3GgYQ9nmlSCeM60N0klvzp1 geRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=QRw4dWFrlFKNeC2Hv6jFCNR7pmJ9ZVloUzzaJsWHe3k=; b=q/83jhvc8edM3Fn39g1T2ut1z9oOCECk57WJlsrfqL/qaRH7BS64i5ZVFId2lzaBf5 5q7ZkZllQzDTGIZGoLNwVCiiUq0wA0ZqLxluaoF3DyuWo+MLNi7fX5ziL4H7q0nRQFOu PxvYDmKqeXmowaQHq3I1F0KJua/xfeCLkM/PJN7Ozv5MqcjUf84/WY/+o5t0UnxYWnk9 Aq6HlHm2P3pxpR3cSRdpKOBgUxC8QfFCHqbO3atYM9IMnAMyEEbqsCtSKBSCuTGc3UM/ 08C1bcmURMa6XhGAJ2cqDuWMGGRr3go5yfkN9C2dmqP79BCg7ymedRP6cY/bnoZiWlUo NS+Q== X-Gm-Message-State: APjAAAUQc0EK8iJP02NrOXlnxcr1vrr18eWxdewZHoTfwiaUX+Ltlso5 oDcozJ0BgVNWA8WlUyS9XWpI4w== X-Received: by 2002:a7b:c40e:: with SMTP id k14mr3957899wmi.114.1558456904711; Tue, 21 May 2019 09:41:44 -0700 (PDT) Received: from brauner.io ([212.91.227.56]) by smtp.gmail.com with ESMTPSA id q14sm7089531wrx.86.2019.05.21.09.41.43 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 21 May 2019 09:41:44 -0700 (PDT) Date: Tue, 21 May 2019 18:41:42 +0200 From: Christian Brauner To: David Howells Cc: Al Viro , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org, jannh@google.com, fweimer@redhat.com, oleg@redhat.com, tglx@linutronix.de, torvalds@linux-foundation.org, arnd@arndb.de, shuah@kernel.org, tkjos@android.com, ldv@altlinux.org, miklos@szeredi.hu, linux-alpha@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-ia64@vger.kernel.org, linux-m68k@lists.linux-m68k.org, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, sparclinux@vger.kernel.org, linux-xtensa@linux-xtensa.org, linux-arch@vger.kernel.org, linux-kselftest@vger.kernel.org, x86@kernel.org Subject: Re: [PATCH 1/2] open: add close_range() Message-ID: <20190521164141.rbehqnghiej3gfua@brauner.io> References: <20190521150006.GJ17978@ZenIV.linux.org.uk> <20190521113448.20654-1-christian@brauner.io> <28114.1558456227@warthog.procyon.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <28114.1558456227@warthog.procyon.org.uk> User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, May 21, 2019 at 05:30:27PM +0100, David Howells wrote: > Al Viro wrote: > > > Umm... That's going to be very painful if you dup2() something to MAX_INT and > > then run that; roughly 2G iterations of bouncing ->file_lock up and down, > > without anything that would yield CPU in process. > > > > If anything, I would suggest something like > > > > fd = *start_fd; > > grab the lock > > fdt = files_fdtable(files); > > more: > > look for the next eviction candidate in ->open_fds, starting at fd > > if there's none up to max_fd > > drop the lock > > return NULL > > *start_fd = fd + 1; > > if the fscker is really opened and not just reserved > > rcu_assign_pointer(fdt->fd[fd], NULL); > > __put_unused_fd(files, fd); > > drop the lock > > return the file we'd got > > if (unlikely(need_resched())) > > drop lock > > cond_resched(); > > grab lock > > fdt = files_fdtable(files); > > goto more; > > > > with the main loop being basically > > while ((file = pick_next(files, &start_fd, max_fd)) != NULL) > > filp_close(file, files); > > If we can live with close_from(int first) rather than close_range(), then this > can perhaps be done a lot more efficiently by: Yeah, you mentioned this before. I do like being able to specify an upper bound to have the ability to place fds strategically after said upper bound. I have used this quite a few times where I know that given task may have inherited up to m fds and I want to inherit a specific pipe who's fd I know. Then I'd dup2(pipe_fd, ) and then close all other fds. Is that too much of a corner case? Christian