From mboxrd@z Thu Jan 1 00:00:00 1970 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id BB08DC433EF for ; Mon, 11 Apr 2022 09:40:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 431546B0074; Mon, 11 Apr 2022 05:40:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3E1586B0075; Mon, 11 Apr 2022 05:40:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2A9756B0078; Mon, 11 Apr 2022 05:40:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.25]) by kanga.kvack.org (Postfix) with ESMTP id 1ABC86B0074 for ; Mon, 11 Apr 2022 05:40:34 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id DD25B60B29 for ; Mon, 11 Apr 2022 09:40:33 +0000 (UTC) X-FDA: 79344103146.17.E3686E3 Received: from out1.migadu.com (out1.migadu.com [91.121.223.63]) by imf25.hostedemail.com (Postfix) with ESMTP id 4C16FA0002 for ; Mon, 11 Apr 2022 09:40:33 +0000 (UTC) Message-ID: <46c1c59e-1368-620d-e57a-f35c2c82084d@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1649670031; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zS90bcIV3w8B4dGQgPINU7Ih71Ht5FIfbS2dm03ISmU=; b=Yc836Dzso0qwc1FwWYDpdsQm1Jow2ayt3zJVXH80ia38H0Bp5G2gt67LQ3Yb4xQQul3l5b FtCpsSpyHdGQTBeqjGm4eoENjBwuW5aK58UH8TmsBWjTfIUEG1vQPWx+ZFO9+hYUxDv09S lIcGnEmTPBRSkah6VKU7E82P3ke94/0= Date: Mon, 11 Apr 2022 12:40:29 +0300 MIME-Version: 1.0 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Vasily Averin Subject: problem with accounting of allocations called from __net_init hooks Content-Language: en-US To: Shakeel Butt Cc: "Eric W. Biederman" , Vlastimil Babka , NeilBrown , Michal Hocko , Roman Gushchin , Linux MM , netdev@vger.kernel.org, "David S. Miller" , Jakub Kicinski , Tejun Heo , Greg Kroah-Hartman , Eric Dumazet , Kees Cook , Hideaki YOSHIFUJI , David Ahern , linux-kernel@vger.kernel.org, kernel@openvz.org, Luis Chamberlain References: <20220301180917.tkibx7zpcz2faoxy@google.com> In-Reply-To: <20220301180917.tkibx7zpcz2faoxy@google.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev X-Rspam-User: Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=Yc836Dzs; spf=pass (imf25.hostedemail.com: domain of vasily.averin@linux.dev designates 91.121.223.63 as permitted sender) smtp.mailfrom=vasily.averin@linux.dev; dmarc=pass (policy=none) header.from=linux.dev X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 4C16FA0002 X-Stat-Signature: 5np4wunkmqbmpdwuuxreookmmdrnpnr4 X-HE-Tag: 1649670033-759058 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 3/1/22 21:09, Shakeel Butt wrote: > On Mon, Feb 28, 2022 at 06:36:58AM -0800, Luis Chamberlain wrote: >> On Mon, Feb 28, 2022 at 10:17:16AM +0300, Vasily Averin wrote: >> > Following one-liner running inside memcg-limited container consumes >> > huge number of host memory and can trigger global OOM. >> > >> > for i in `seq 1 xxx` ; do ip l a v$i type veth peer name vp$i ; done >> > >> > Patch accounts most part of these allocations and can protect host. >> > ---[cut]--- >> > It is not polished, and perhaps should be splitted. >> > obviously it affects other kind of netdevices too. >> > Unfortunately I'm not sure that I will have enough time to handle it properly >> > and decided to publish current patch version as is. >> > OpenVz workaround it by using per-container limit for number of >> > available netdevices, but upstream does not have any kind of >> > per-container configuration. >> > ------ I've noticed that __register_pernet_operations() executes init hook of registered pernet_operation structure in all found net namespaces. Usually these hooks are called by process related to specified net namespace, and all marked allocation are accounted to related container: i.e. objects related to netns in container A are accounted to memcg of container A, objects allocated inside container B are accounted to corresponding memcg B, and so on. However __register_pernet_operations() calls the same hooks in one context, and as result all marked allocations are accounted to one memcg. It is quite rare scenario, however current processing looks incorrect for me. I expect we can take memcg from 'struct net', because of this structure is accounted per se. then we can use set_active_memcg() before init hook execution. However I'm not sure it is fully correct. Could you please advise some better solution? Thank you, Vasily Averin