Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp222421pxb; Mon, 11 Apr 2022 23:44:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy3dVr2YnOyYiW5uJ88wD2K7JmhmuEHh8UESpA6112gLIJXUb3/qGcLS2tOLoJWmX3mHnbX X-Received: by 2002:a05:6a00:194b:b0:4fb:4ac:de57 with SMTP id s11-20020a056a00194b00b004fb04acde57mr3109133pfk.17.1649745855154; Mon, 11 Apr 2022 23:44:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649745855; cv=none; d=google.com; s=arc-20160816; b=QPrE1VKbEna1g8bOYbz97VX6pHz47+75zKuVdsmXP0ULMwWaeGP6ErlHDnUU4Ts+Oj hFYbyLdaLXR9hLhLVJhZ84JytT0q7s2L2BpfzgdBLB+lAVH1rjcbD4bxTIDo65F0qBXA KEAAHGXfN/ti+QbSkzr+wA51OFCMnrjKtzBZK7933zSlrnoHw8Wq1dL8TaH7RXB1wxA+ ZJap9FgAZJHfffHbwz9jqj5LzRr6pSNlC/4tvxHVXGOmEroMrSlDCT72Lxr9qAwJsoUy GLSuBcQyJj+xx7FCW+ksp7+vplWJ6C8NjYIV5mlcMNC1D8R4fi4hHlq6rF0AtFmFCuYs mXwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:references :cc:to:content-language:subject:from:mime-version:date :dkim-signature:message-id; bh=zS90bcIV3w8B4dGQgPINU7Ih71Ht5FIfbS2dm03ISmU=; b=nXYERgUsZrEVwuxk7gw/xvjPCyCqiTLzfy8fqZ7kbbtpJpy3SxuUsPhl+o7sbvf5iG C6LWbZGatGE9hhA7k4wd50mV+a0PUho/ZwFKs/gpTW/LWMTmVrde50ApPsV0zSzbjkLM ASfTQzduB19LV3ZT43px9yeQXVwemUTwN4c88HxHyyBHTkT8cWGzs95DvZsFDYdNSjzo BadnXsd88fArZwKikb99qwq6eNw0DUMQlcWJ9xdmSHbbjZujWnK1LqHnHE5AoNA89s7M ru1zKohsCW/mDUv2CA/9Ty0dgON7QF9a+7XryCTBj94MwpbP8JuwKcrFCEV90Si5uIdy 2iDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=Yc836Dzs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id il7-20020a17090b164700b001cb278ad6cesi12730068pjb.138.2022.04.11.23.44.01; Mon, 11 Apr 2022 23:44:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=Yc836Dzs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230091AbiDKJnx (ORCPT + 99 others); Mon, 11 Apr 2022 05:43:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45618 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344689AbiDKJmr (ORCPT ); Mon, 11 Apr 2022 05:42:47 -0400 Received: from out1.migadu.com (out1.migadu.com [91.121.223.63]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D8D62F012; Mon, 11 Apr 2022 02:40:33 -0700 (PDT) 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-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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