Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp967160ybm; Tue, 21 May 2019 06:41:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqyixF2gwf6/BffsGYzxJTOO5hSANqbN2Mcv+56U/htXcvhUoCC/lkh9lcwmfbwEfCB6cXS2 X-Received: by 2002:a17:902:2c01:: with SMTP id m1mr78582837plb.108.1558446109040; Tue, 21 May 2019 06:41:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558446109; cv=none; d=google.com; s=arc-20160816; b=E/G07Q3MN9ijNKOk02o5lgH31Qtbh3DqshKOAKnJ65kyES7/M0WTDlcOosBji+EwE5 32Fa6xDxY1ERMxDfd19YNzTeKYia0E3/veETzxOZpGpphRByHAfFxrbYeFdhH7tY4RtG KW7hpqSyNfOr5ZKVKtShmsJwmqJiYZ9cT7/40uyDOzfgCDaR/MOCALlpP747+5yLF3zS mtru58xvl6XOks8SrO0YW6igt2BNbF7hZNtNEtYoaIPSvmCoANx0U3Hn/9oh8v/ltyO1 KSLJdziOXlW24H6bqE1hVYmdqkDJzARAluE1E2h0FuJe8w6ub53PVI5nqWOCWYfnXYkO 2uaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:to:subject:dkim-signature; bh=DGZ7ZHyxHghlyk00GjOL+Su8tQVyBxRwxWt505Mwkr8=; b=SWW5YpOidpUbdmcIDM4iuaYjnsT4gEb16iOeW7dW/Lja7/6Kpy3OOLECfIm2b8lgMv Dx1wVEEDAVgu0sJ5hNY0mTTwlA4dS0A0rpGNToUtUTLdmHg7+PffvUMlk6UXtmy7gXnP D4YSZn+YEXy8MGH115JBDzwE2EQ71sQnc4Y6rxWyzknABnFcPeTDSw6nI7ntHxG1AOCS 3nzzoo2neASKIJ691GXUPZsZgnhifMsXMxv57/QMJOXT7L3moWNOcCb8dyYicsk5GpMU c8ckewas9xoiYhkeAUWLLx8celAmDpjy/3oll3CB6a5fCRIGY+u9ZGIft0TehhsPlq1/ R1Aw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=UUsV50XW; 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 35si19518420plb.228.2019.05.21.06.41.33; Tue, 21 May 2019 06:41:49 -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=@rasmusvillemoes.dk header.s=google header.b=UUsV50XW; 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 S1728053AbfEUNj6 (ORCPT + 99 others); Tue, 21 May 2019 09:39:58 -0400 Received: from mail-lf1-f67.google.com ([209.85.167.67]:35311 "EHLO mail-lf1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728176AbfEUNj5 (ORCPT ); Tue, 21 May 2019 09:39:57 -0400 Received: by mail-lf1-f67.google.com with SMTP id c17so13160192lfi.2 for ; Tue, 21 May 2019 06:39:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=DGZ7ZHyxHghlyk00GjOL+Su8tQVyBxRwxWt505Mwkr8=; b=UUsV50XWdVARTWvdiywE4LnO/Bgl22uVqIvj5DiL4yTqSSX691QJuUM5FH7mGHFNYk Q0+0Bk1dY9Y5jYUMp6VxvQCJ668wo7gKKnk7wKdAbO6uXmyxdHg1D3dyjo/e1Z67HVYz ek1VF3gFyvtiDXkBXE/5DNTwuCl20PqPvKDr8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=DGZ7ZHyxHghlyk00GjOL+Su8tQVyBxRwxWt505Mwkr8=; b=t8aGu7jKNXCDQXG0Urx9ku5lwt2ekjbfamE1MCEHwEJEKHvy4RsHVL4LJ33RG7Yq8W ofoJgP2cLxdhwwzk8fFHf57aBOPEGB4YxT62I+ydFVxk5XA3MdRneCmmLGVc7Eb+0mWt JOlv+Qi+EFiT4vdWMIoKvgHQJiM/7GgEXreLa0F7thBlTCJ8zd+MgNHWfxFF/CFbNLyZ HTdAbmAoqbR9v8Zejf8fZtUBNahq+0GnxmQy+H7vPSzbwgG49erL1ZXnirI23appMMsz jCWTGuvYl/nH6X4GatoG7ezH0m7Ju7jeALaf2hR7xY+Qupka6Sq/2kL2jFfIuG8NEbPW lnyw== X-Gm-Message-State: APjAAAUxMI6Os6XaIwgkfX/BTB/iUeURVbg+imh0KP5ytTC1eI1qGr4z f3udLSIlsXmnHG0+ezTnWR1K1w== X-Received: by 2002:ac2:5490:: with SMTP id t16mr2238952lfk.154.1558445996105; Tue, 21 May 2019 06:39:56 -0700 (PDT) Received: from [172.16.11.26] ([81.216.59.226]) by smtp.gmail.com with ESMTPSA id r26sm4706723lfa.62.2019.05.21.06.39.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 21 May 2019 06:39:55 -0700 (PDT) Subject: Re: [PATCH 1/2] open: add close_range() To: Christian Brauner , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org References: <20190521113448.20654-1-christian@brauner.io> From: Rasmus Villemoes Message-ID: <82d34133-e174-efc3-48ed-332304028595@rasmusvillemoes.dk> Date: Tue, 21 May 2019 15:39:53 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: <20190521113448.20654-1-christian@brauner.io> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 21/05/2019 13.34, Christian Brauner wrote: > The performance is striking. For good measure, comparing the following > simple close_all_fds() userspace implementation that is essentially just > glibc's version in [6]: > > static int close_all_fds(void) > { > DIR *dir; > struct dirent *direntp; > > dir = opendir("/proc/self/fd"); > if (!dir) > return -1; > > while ((direntp = readdir(dir))) { > int fd; > if (strcmp(direntp->d_name, ".") == 0) > continue; > if (strcmp(direntp->d_name, "..") == 0) > continue; > fd = atoi(direntp->d_name); > if (fd == 0 || fd == 1 || fd == 2) > continue; > close(fd); > } > > closedir(dir); /* cannot fail */ > return 0; > } Before anybody copy-pastes this, please note that it lacks a check for fd == dirfd(dir). If all of /proc/self/fd is returned in the first getdents() syscall one won't notice, but... Rasmus