Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9ECF1C433EF for ; Mon, 27 Jun 2022 20:18:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238946AbiF0USj (ORCPT ); Mon, 27 Jun 2022 16:18:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38636 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238935AbiF0USi (ORCPT ); Mon, 27 Jun 2022 16:18:38 -0400 Received: from smtp-fw-6001.amazon.com (smtp-fw-6001.amazon.com [52.95.48.154]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 71A6C192A7 for ; Mon, 27 Jun 2022 13:18:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1656361117; x=1687897117; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=vlCz2dmP1ILMyJtMJozt8c1h/LSAyrxFF+ge197D+Xc=; b=qeEffDKLoZXd0PFyBkyO52vi5buEiDDT4QVIku+LKLD+AJRp1Yh3Yla6 zXf3F5Fy9iCsxF5iwRMEdPHlUYJhqoiIMsTuWp+I/5Rp6Se1YWY8i/nNo c3x0S5Jq6VXN5daWDrLyaWwj+7l3ckAoavHdIvJTt9tWgqAxfYXwMSdSQ 4=; Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-pdx-2c-5c4a15b1.us-west-2.amazon.com) ([10.43.8.6]) by smtp-border-fw-6001.iad6.amazon.com with ESMTP; 27 Jun 2022 20:18:25 +0000 Received: from EX13MTAUWB001.ant.amazon.com (pdx1-ws-svc-p6-lb9-vlan2.pdx.amazon.com [10.236.137.194]) by email-inbound-relay-pdx-2c-5c4a15b1.us-west-2.amazon.com (Postfix) with ESMTPS id 16A0843533; Mon, 27 Jun 2022 20:18:24 +0000 (UTC) Received: from EX13D04ANC001.ant.amazon.com (10.43.157.89) by EX13MTAUWB001.ant.amazon.com (10.43.161.207) with Microsoft SMTP Server (TLS) id 15.0.1497.36; Mon, 27 Jun 2022 20:18:23 +0000 Received: from 88665a182662.ant.amazon.com (10.43.162.40) by EX13D04ANC001.ant.amazon.com (10.43.157.89) with Microsoft SMTP Server (TLS) id 15.0.1497.36; Mon, 27 Jun 2022 20:18:18 +0000 From: Kuniyuki Iwashima To: CC: , , , , , , , , Subject: Re: [PATCH v2 net] af_unix: Do not call kmemdup() for init_net's sysctl table. Date: Mon, 27 Jun 2022 13:18:10 -0700 Message-ID: <20220627201810.15642-1-kuniyu@amazon.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.43.162.40] X-ClientProxiedBy: EX13D47UWA002.ant.amazon.com (10.43.163.30) To EX13D04ANC001.ant.amazon.com (10.43.157.89) Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Eric Dumazet Date: Mon, 27 Jun 2022 22:04:07 +0200 > On Mon, Jun 27, 2022 at 10:00 PM Kuniyuki Iwashima wrote: > > > > From: Eric Dumazet > > Date: Mon, 27 Jun 2022 21:36:18 +0200 > > > On Mon, Jun 27, 2022 at 9:16 PM Kuniyuki Iwashima wrote: > > > > > > > > From: Eric Dumazet > > > > Date: Mon, 27 Jun 2022 21:06:14 +0200 > > > > > On Mon, Jun 27, 2022 at 8:59 PM Kuniyuki Iwashima wrote: > > > > > > > > > > > > From: Eric Dumazet > > > > > > Date: Mon, 27 Jun 2022 20:40:24 +0200 > > > > > > > On Mon, Jun 27, 2022 at 8:30 PM Kuniyuki Iwashima wrote: > > > > > > > > > > > > > > > > From: Jakub Kicinski > > > > > > > > Date: Mon, 27 Jun 2022 10:58:59 -0700 > > > > > > > > > On Sun, 26 Jun 2022 11:43:27 -0500 Eric W. Biederman wrote: > > > > > > > > > > Kuniyuki Iwashima writes: > > > > > > > > > > > > > > > > > > > > > While setting up init_net's sysctl table, we need not duplicate the global > > > > > > > > > > > table and can use it directly. > > > > > > > > > > > > > > > > > > > > Acked-by: "Eric W. Biederman" > > > > > > > > > > > > > > > > > > > > I am not quite certain the savings of a single entry table justivies > > > > > > > > > > the complexity. But the looks correct. > > > > > > > > > > > > > > > > > > Yeah, the commit message is a little sparse. The "why" is not addressed. > > > > > > > > > Could you add more details to explain the motivation? > > > > > > > > > > > > > > > > I was working on a series which converts UDP/TCP hash tables into per-netns > > > > > > > > ones like AF_UNIX to speed up looking up sockets. It will consume much > > > > > > > > memory on a host with thousands of netns, but it can be waste if we do not > > > > > > > > have its protocol family's sockets. > > > > > > > > > > > > > > For the record, I doubt we will accept such a patch (per net-ns > > > > > > > TCP/UDP hash tables) > > > > > > > > > > > > Is it because it's risky? > > > > > > > > > > Because it will be very expensive. TCP hash tables are quite big. > > > > > > > > Yes, so I'm wondering if changing the size by sysctl makes sense. If we > > > > have per-netns hash tables, each table should have smaller amount of > > > > sockets and smaller size should be enough, I think. > > > > > > How can a sysctl be safely used if two different threads call "unshare > > > -n" at the same time ? > > > > I think two unshare are safe. Each of them reads its parent netns's sysctl > > knob. Even when the parent is the same, they can read the same value. > > How can one thread create a netns with a TCP ehash table with 1024 buckets, > and a second one create a netns with a TCP ehash table with 1 million > buckets at the same time, > if they share the same sysctl ??? Oh, I undertood. In the example, I added net.unix.hash_entries so we can confirm if the size is intended one, but yes, checking it and recreating netns is crazy... # sysctl -w net.unix.child_hash_entries=128 # ip net add test # created with the hash table size 128 # ip net exec test sh # sysctl net.unix.hash_entries # read-only 128 Do you have good idea? > > > > > But I think we need READ_ONCE()/WRITE_ONCE() in such a sysctl. > > Like all sysctls really. > > While > > creating a child netns, another one can change the value and there can be > > a data-race. So we have to use custome handler and pass write/read handler > > as conv of do_proc_douintvec(), like do_proc_douintvec_conv_lockless(). > > > > If there are some sysctls missing READ_ONCE/WRITE_ONCE(), I will add > > more general one, proc_douintvec_lockless(). > > Seriously, all sysctls can be set while being read. That is not something new. Ok, I added that on TODO.