Received: by 10.223.164.202 with SMTP id h10csp59970wrb; Tue, 14 Nov 2017 11:05:44 -0800 (PST) X-Google-Smtp-Source: AGs4zMZnTquDdq0SMA2pM4DsX3Q4QXgLtCKWURYKfQFZkdwsKm8ZQ/peJ+mBRxTC+WDIcZNwVOBJ X-Received: by 10.98.64.6 with SMTP id n6mr14726262pfa.129.1510686344662; Tue, 14 Nov 2017 11:05:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510686344; cv=none; d=google.com; s=arc-20160816; b=Tk1/IVF1vplaRa2oe3uWWqBP79kirlOPhvKLXB+tIHbaacKcgnkAfDrXSfugxJjgLP /88E1cd8sk7lEn3f1ypBH3WiIjqof0wfzl4Ykae/fkFh0a/ftu8f273nubRpUDjii1dr O5mLZNIkzyKBu/+ArrzGx9fFGLriqyJN94rRdJFllhnwOaQVJoTbJY2by4YWj51zykrp PbTV252J1AeW64KHTdnBv3kY88NtgDp/i9PAMXH24vVVDu9C6mJXUA4k1qT+8qSSdrJK /Otd3ISWcKMCYxwB6MYLXpYY+QJu5v4BA0+76D+9tjMRe4e6X5aGX7BufTqfh5f8ZJm6 o65g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:spamdiagnosticmetadata :spamdiagnosticoutput:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature:arc-authentication-results; bh=sOjHxquZNXsSpMdLBIjhaXVBVUwyiCpaAKF7SQg8dH8=; b=jiBbeKa/8pNLKipwDiftQokRl9f163v8UmVze2iL848BoWHju+eYxI/IemjV3ViPQg dTWKjZxVlY1j1NCUgR8acaG23EzIuPpQIgQAyVxyFCs75eE8vZA9Q6yyDTb1knuBgak8 REVWui1B7zrWzYHiL/oqyUOAu7ZmTRoUzySGa4tBcMDN9f8achp8r8qUtEi/MNuRw6Yq G2eqJD3doLXhIbObq1BfS23lGG4Uj48Fos4162t5WEHwpg+7WEE+7QBkcmgC9ckZHR5Z MPqDzpoo2hMh0zu5DnSLGVP5yzpGxhyIKka1Pjfdb6+kpZMw6Ihe8jfTgnUHmQgcDEcA bAhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=selector1 header.b=NP5Z2QDW; 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=pass (p=NONE sp=NONE dis=NONE) header.from=virtuozzo.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k189si10795007pgc.133.2017.11.14.11.05.32; Tue, 14 Nov 2017 11:05:44 -0800 (PST) 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=@virtuozzo.com header.s=selector1 header.b=NP5Z2QDW; 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=pass (p=NONE sp=NONE dis=NONE) header.from=virtuozzo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755690AbdKNRpY (ORCPT + 88 others); Tue, 14 Nov 2017 12:45:24 -0500 Received: from mail-eopbgr10122.outbound.protection.outlook.com ([40.107.1.122]:47464 "EHLO EUR02-HE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751736AbdKNRpR (ORCPT ); Tue, 14 Nov 2017 12:45:17 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=sOjHxquZNXsSpMdLBIjhaXVBVUwyiCpaAKF7SQg8dH8=; b=NP5Z2QDWxkbWJrEOWe7Yfp36adz77ruC7n+tX2G12PGCat2Db5Rke4Pm1llU/lF3ecHkByRmzxa5aDInvmK8O6c9Vgzg3m7Fy0plq4KTOJoVeBe2p9EUHXdU9UhdYEdHv8hB7SN56yi75Zg1PPmd9oPdCD2+DAftpmINGYnubQU= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=avagin@virtuozzo.com; Received: from outlook.office365.com (65.152.152.74) by HE1PR08MB0745.eurprd08.prod.outlook.com (2a01:111:e400:59b1::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.218.12; Tue, 14 Nov 2017 17:45:07 +0000 Date: Tue, 14 Nov 2017 09:44:55 -0800 From: Andrei Vagin To: Kirill Tkhai Cc: davem@davemloft.net, vyasevic@redhat.com, kstewart@linuxfoundation.org, pombredanne@nexb.com, vyasevich@gmail.com, mark.rutland@arm.com, gregkh@linuxfoundation.org, adobriyan@gmail.com, fw@strlen.de, nicolas.dichtel@6wind.com, xiyou.wangcong@gmail.com, roman.kapl@sysgo.com, paul@paul-moore.com, dsahern@gmail.com, daniel@iogearbox.net, lucien.xin@gmail.com, mschiffer@universe-factory.net, rshearma@brocade.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, ebiederm@xmission.com, gorcunov@virtuozzo.com Subject: Re: [PATCH] net: Convert net_mutex into rw_semaphore and down read it on net->init/->exit Message-ID: <20171114174454.GA11452@outlook.office365.com> References: <151066759055.14465.9783879083192000862.stgit@localhost.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset=koi8-r Content-Disposition: inline In-Reply-To: <151066759055.14465.9783879083192000862.stgit@localhost.localdomain> User-Agent: Mutt/1.9.1 (2017-09-22) X-Originating-IP: [65.152.152.74] X-ClientProxiedBy: MWHPR09CA0032.namprd09.prod.outlook.com (2603:10b6:300:6d::18) To HE1PR08MB0745.eurprd08.prod.outlook.com (2a01:111:e400:59b1::11) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1d768e6d-0242-46dc-f3f1-08d52b8774bd X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001)(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(2017052603199);SRVR:HE1PR08MB0745; X-Microsoft-Exchange-Diagnostics: 1;HE1PR08MB0745;3:Zwq2O9xiB+Homn7z+xx7X8eqtra7CJ8p+JIJM76SRT+pX0MTWFoZZHld7KXGP3VZm0UIN6Sl9tXzyLOcWcKo47l/iBcUpnf8DsJmWMeZ1iCgGCu3is3ucJtjWFaowp/cyu8y/wThsg2y34miHU3scsl+MmdfMFDSDF4vpi/R0mUk2wwmSAdd0TKSWOGQ5Ve4C8vvLxpX0MyvLTO7gXg9PIdTWjLkxZ19l5N/FKZ7fCvfJGJRsCiZhgMRSAVTbDOe;25:dl6SOZewWAx1MI9Uj5jLKsGNR96saNlXkTqP9b4dZ38b/0tNeFAdqjLXPDJagt6somXrEYZad+F1uCZ2alXKNhbU15q3hvDlsvbFXirIhpleY9FXXYSRZGSCeh7zhI4fonm6iEEYYS/bVttrveBfdeVQggTd0itzw5TNxkIamyjmQGu10ETnT9z2lCdz5ebTBu+NE59MJqH5dGOsZEK4PS4TekYaeNModXmoeAUjpH9guAb0nbdogsqdlk3QTH2Tk4gfupC1KFvlEgXu2KEJIr4KQcPL0JKWX1UPaWN4MbL6phbeGabIHJK7l3uDTNzmLdJpDGXTKRGH2DO9MQ1bcQ==;31:hKNqxMFbDpuGyBNMOMZGwpXJF2U3UU/RbHGmX7hUpbfq0kV2Iraf51kAPvVVcXnFOdpsJsFE4hp7DEgrOKJhiEjt35Qv9RNAV1dJbcGMqeEyx9k5Fht7JL2bKj0/qBlJC3Jkwa07xaUMgIsLfRacJaGr0KSck8OiUJJC0vvju2ztjbe4ru8hEHSg/r77928gvhm0NOkc5tz7wzWjzu3YkOLw2gp/bkPt0v9jhIMopkA= X-MS-TrafficTypeDiagnostic: HE1PR08MB0745: X-Microsoft-Exchange-Diagnostics: 1;HE1PR08MB0745;20:JBLTumfU9oHZesZZvMMofOCkIhJaeDrwIwVq+QB1gSWdN0Pxftcgr96sjbApTOucNTxBlA6rmXLPrGPuQBbF1DHd7VjLJLPwyNtILvf/SvhL0I6QlExwtwkQisEdvHHbveC7HM67ZVGo8UZzWvGvFf6L01Injaz+1liHCGrC5whY0VqE9TSBaYSFxctand1g3+UsOLHRRQInZlaHiWKx6TZykZSE1Q6BexNT0L9v/I257d1Ry8q/JDmHke61Ut+xaHNKbat3l8o/g1rBY9FVkSKUprgW9mdrMRsUobGYweBxd4m6mZCCWfGLFtcto/rFvTDHcnFunGEws2ipJYyPh/RzKSh4VKvFKcFRhEcpKv4iJeBWer27R3ZOqKH0q65UI0z/A3bTpOi1cU1dfNjp8xHtLJ7SVIDjNIaSCPGImc0=;4:kiRnuJChHf4kxlZB6kTe7yxmTMXoLaQ/a+TFvU/9JEis/IfG2q7x5+lw6D2Px1sTP0N9bgd1P+Z3vu4UtWX9ikPxMqOO3cM3kiQRtWlgLgzI6H51AAsaqqMeL7gyy1xbsRyqPjn32eNM0r7tPEuJUw2pkKFVALzZTnaD9/mclWPxk8IWoRJDTlu6qgNSGNDy0mngjdDUs9djtqHBI88P0fkJPXVFzQ68r/IzNYFHXB+rltXzwXnw7QUFAjKWClWopD4kF3nU54Eq4F429v3s+w== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(2401047)(5005006)(8121501046)(3002001)(100000703101)(100105400095)(3231022)(10201501046)(93006095)(93001095)(6041248)(20161123562025)(20161123558100)(20161123560025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123555025)(20161123564025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:HE1PR08MB0745;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:HE1PR08MB0745; X-Forefront-PRVS: 04916EA04C X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(6009001)(376002)(346002)(199003)(24454002)(189002)(16526018)(478600001)(54356999)(6506006)(6862004)(229853002)(76176999)(50986999)(106356001)(50466002)(105586002)(69596002)(97736004)(6116002)(53416004)(58126008)(4326008)(5660300001)(55016002)(189998001)(81166006)(81156014)(86362001)(316002)(3846002)(6666003)(6636002)(53936002)(101416001)(2950100002)(9686003)(6306002)(68736007)(107886003)(16586007)(2906002)(25786009)(66066001)(39060400002)(305945005)(8936002)(7736002)(966005)(7416002)(83506002)(33656002)(47776003)(1076002)(23686003)(6246003)(8676002)(18370500001);DIR:OUT;SFP:1102;SCL:1;SRVR:HE1PR08MB0745;H:outlook.office365.com;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; Received-SPF: None (protection.outlook.com: virtuozzo.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?koi8-r?Q?1;HE1PR08MB0745;23:/zfrIMiDj7WYzDCpAJwVKs7Y2oazzhTjxUuyUBxtNy6?= =?koi8-r?Q?bjJ9Ol0YnOdQ+D7VKl0+AlsQNpC/Ype7JwK1LrG19z0hx44hxsPNgi+D/azcCF?= =?koi8-r?Q?znTnxCTXcZJVEgvTpiuDu8VL+0FpiURoI7nsfYAsS2qd6StWQ717NZ/lsH2iwN?= =?koi8-r?Q?oOQxKXnJWOZLv9aZxzE4lC7Nm/VhADuGd3O+8FAbk3V7wmiMvb3QnsScgq0jGp?= =?koi8-r?Q?FNKsRY/GbT9dZOzi8gbzD0ULIeddONiKgjetqM6i3l050/R5cUJFYiJhN1pRjt?= =?koi8-r?Q?fZk3PBcCb4CBZPAxrAk2Kg3lodo+MMMeS7IVvoTJqD/Fd1wZXdj3w96olsunv+?= =?koi8-r?Q?MRAqM1MmIZfoc5+XcyrDBq3kqgFExvjB0A2gJ7p54C1dGzM53Yn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agnostics: 1;HE1PR08MB0745;20:p8EElU2evQbzMup19n7c4rVNXMJyX6KaV4LuabqUGoZLAJ27f0e1Gt2+rXwMK/+DSbwnb5/9cgUgGJrYWfAPv7+b/JObwSM1KJs6Qv8yEhjbR/7o8oBzlLTNSjCime0zFJ7NjrAlwHTPvf7rXx1aejZiMlbuLth7YCH6xMSO89E= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Nov 2017 17:45:07.6351 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1d768e6d-0242-46dc-f3f1-08d52b8774bd X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR08MB0745 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Nov 14, 2017 at 04:53:33PM +0300, Kirill Tkhai wrote: > Curently mutex is used to protect pernet operations list. It makes > cleanup_net() to execute ->exit methods of the same operations set, > which was used on the time of ->init, even after net namespace is > unlinked from net_namespace_list. > > But the problem is it's need to synchronize_rcu() after net is removed > from net_namespace_list(): > > Destroy net_ns: > cleanup_net() > mutex_lock(&net_mutex) > list_del_rcu(&net->list) > synchronize_rcu() <--- Sleep there for ages > list_for_each_entry_reverse(ops, &pernet_list, list) > ops_exit_list(ops, &net_exit_list) > list_for_each_entry_reverse(ops, &pernet_list, list) > ops_free_list(ops, &net_exit_list) > mutex_unlock(&net_mutex) > > This primitive is not fast, especially on the systems with many processors > and/or when preemptible RCU is enabled in config. So, all the time, while > cleanup_net() is waiting for RCU grace period, creation of new net namespaces > is not possible, the tasks, who makes it, are sleeping on the same mutex: > > Create net_ns: > copy_net_ns() > mutex_lock_killable(&net_mutex) <--- Sleep there for ages > > The solution is to convert net_mutex to the rw_semaphore. Then, > pernet_operations::init/::exit methods, modifying the net-related data, > will require down_read() locking only, while down_write() will be used > for changing pernet_list. > > This gives signify performance increase, like you may see below. There > is measured sequential net namespace creation in a cycle, in single > thread, without other tasks (single user mode): > > 1)int main(int argc, char *argv[]) > { > unsigned nr; > if (argc < 2) { > fprintf(stderr, "Provide nr iterations arg\n"); > return 1; > } > nr = atoi(argv[1]); > while (nr-- > 0) { > if (unshare(CLONE_NEWNET)) { > perror("Can't unshare"); > return 1; > } > } > return 0; > } > > Origin, 100000 unshare(): > 0.03user 23.14system 1:39.85elapsed 23%CPU > > Patched, 100000 unshare(): > 0.03user 67.49system 1:08.34elapsed 98%CPU > > 2)for i in {1..10000}; do unshare -n bash -c exit; done Hi Kirill, This mutex has another role. You know that net namespaces are destroyed asynchronously, and the net mutex gurantees that a backlog will be not big. If we have something in backlog, we know that it will be handled before creating a new net ns. As far as I remember net namespaces are created much faster than they are destroyed, so with this changes we can create a really big backlog, can't we? There was a discussion a few month ago: https://lists.onap.org/pipermail/containers/2016-October/037509.html > > Origin: > real 1m24,190s > user 0m6,225s > sys 0m15,132s Here you measure time of creating and destroying net namespaces. > > Patched: > real 0m18,235s (4.6 times faster) > user 0m4,544s > sys 0m13,796s But here you measure time of crearing namespaces and you know nothing when they will be destroyed. Thanks, Andrei From 1584066129534824912@xxx Tue Nov 14 18:13:03 +0000 2017 X-GM-THRID: 1584049999819820517 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread