Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp1162852ybm; Tue, 21 May 2019 09:32:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqxb6UKphWnUr0cl6mxQvdodPP6ruuFwUhxZ5KG/QIEhZ8KRz4GQCfLRzseHK6B633lEfLtg X-Received: by 2002:a17:902:184:: with SMTP id b4mr57451894plb.2.1558456355439; Tue, 21 May 2019 09:32:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558456355; cv=none; d=google.com; s=arc-20160816; b=ETfepcUSFiLlKXR9Ad5afx5hjVCqts+J0Y/8CNEujxS0FSm3DpE9he1EahA7s5Pifa 6GZ4NiYPZFE66USzUfudhY5S40+LmGqbGFfNA1tEvyTFX9ve1ieUwgWFPgaxerEyf0cz m9BlwrDvteOmO9KejizX+R9yoV4X2jEkCvrFwa1HFjwARfImp/VwpOJHHdYHlIEs8ZxB 23UOawPkhyi5o4F6QOpsLcI3HKbWRuSdR6ogTCLntUsRmKHpp0FWOVxb+dEem5uMIkdu q6jNe+5Qe6NkBHw4vgHheiP1GQDZpJ1MWA0Xx2p7WkZJ0imr4pdBCBaDzdCevr+AlZhQ i11Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:content-transfer-encoding :content-id:mime-version:subject:cc:to:references:in-reply-to:from :organization; bh=L7uZUDPUJ+o+I3myrZRtOGFojrlUim7lYECdov9oSzs=; b=YaN/K0O3VlipGxgLPwSl8N15ySFH9ju+hAWpP6K8pChhCSbGPvqskWatzIGbgwcDY5 Jc5F7FL5DbmylZ3akROnUGN11Sdz4bS/UL94X3BlPhkCE2ILQeUns+Je3xuxLK8o+zg6 4N1iZeOW/2T8bUOig+6XLOHsD+cMTURsxIkeFItlEoCoHz7jCt2J8f7T4xSyd5VcOO2W jygHlKOupAlhBhuS6PKqwMeK1wjda59Ctn7XbwhwMlfSnLmxfuxIVTjU9GNxUAfPzAhw Qn5xoSs+Dd9nbNdMMlGpmnDY+doLTz224ZO87s88yY/mQR7X68FpH1edXIjNtG3SubFa fH7g== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i184si8548350pfb.123.2019.05.21.09.32.19; Tue, 21 May 2019 09:32:35 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729038AbfEUQa6 convert rfc822-to-8bit (ORCPT + 99 others); Tue, 21 May 2019 12:30:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:61737 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728945AbfEUQa6 (ORCPT ); Tue, 21 May 2019 12:30:58 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 36C037FDEE; Tue, 21 May 2019 16:30:39 +0000 (UTC) Received: from warthog.procyon.org.uk (ovpn-120-170.rdu2.redhat.com [10.10.120.170]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7B1B95E7AF; Tue, 21 May 2019 16:30:28 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 From: David Howells In-Reply-To: <20190521150006.GJ17978@ZenIV.linux.org.uk> References: <20190521150006.GJ17978@ZenIV.linux.org.uk> <20190521113448.20654-1-christian@brauner.io> To: Al Viro Cc: dhowells@redhat.com, Christian Brauner , 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() MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <28113.1558456227.1@warthog.procyon.org.uk> Content-Transfer-Encoding: 8BIT Date: Tue, 21 May 2019 17:30:27 +0100 Message-ID: <28114.1558456227@warthog.procyon.org.uk> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 21 May 2019 16:30:57 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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: new = alloc_fdtable(first); spin_lock(&files->file_lock); old = files_fdtable(files); copy_fds(new, old, 0, first - 1); rcu_assign_pointer(files->fdt, new); spin_unlock(&files->file_lock); clear_fds(old, 0, first - 1); close_fdt_from(old, first); kfree_rcu(old); David