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 76544C433EF for ; Tue, 12 Jul 2022 07:40:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 010FA6B0153; Tue, 12 Jul 2022 03:40:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F02E16B0154; Tue, 12 Jul 2022 03:40:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DF2856B0155; Tue, 12 Jul 2022 03:40:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id D17AB6B0153 for ; Tue, 12 Jul 2022 03:40:19 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 95D46D31 for ; Tue, 12 Jul 2022 07:40:19 +0000 (UTC) X-FDA: 79677649758.10.81C94B8 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf21.hostedemail.com (Postfix) with ESMTP id 9E4DE1C0072 for ; Tue, 12 Jul 2022 07:40:18 +0000 (UTC) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 2CC5A224B2; Tue, 12 Jul 2022 07:40:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1657611617; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=rTjDzCNpfxhZGcYtkev/Rnoy7y1rs+QCsKHXbF2i1iE=; b=qdRyPo4qbd0Mt2tkpFnRDlarOa++Hb3y5LeOX8dFE5YCSIKhAOWuuk7BsQBDMTf5cfjYfo bNvAc4qJjFhDSRX2utfwjGZIuKf79iMIAWZ+ltg4JefS6ZsBL0SFV63o+qPQWUhi8aZ+q6 CcUsdndnPAhBNEQZ5wepPaoN68EVxac= Received: from suse.cz (unknown [10.100.201.86]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 0922F2C141; Tue, 12 Jul 2022 07:40:14 +0000 (UTC) Date: Tue, 12 Jul 2022 09:40:13 +0200 From: Michal Hocko To: Alexei Starovoitov Cc: Shakeel Butt , Matthew Wilcox , Christoph Hellwig , "David S. Miller" , Daniel Borkmann , Andrii Nakryiko , Tejun Heo , Martin KaFai Lau , bpf , Kernel Team , linux-mm , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Vlastimil Babka Subject: Re: [PATCH bpf-next 0/5] bpf: BPF specific memory allocator. Message-ID: References: <20220706175034.y4hw5gfbswxya36z@MacBook-Pro-3.local> <20220706180525.ozkxnbifgd4vzxym@MacBook-Pro-3.local.dhcp.thefacebook.com> <20220708174858.6gl2ag3asmoimpoe@macbook-pro-3.dhcp.thefacebook.com> <20220708215536.pqclxdqvtrfll2y4@google.com> <20220710073213.bkkdweiqrlnr35sv@google.com> <20220712043914.pxmbm7vockuvpmmh@macbook-pro-3.dhcp.thefacebook.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220712043914.pxmbm7vockuvpmmh@macbook-pro-3.dhcp.thefacebook.com> ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=qdRyPo4q; dmarc=pass (policy=quarantine) header.from=suse.com; spf=pass (imf21.hostedemail.com: domain of mhocko@suse.com designates 195.135.220.28 as permitted sender) smtp.mailfrom=mhocko@suse.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1657611618; h=from:from:sender: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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=rTjDzCNpfxhZGcYtkev/Rnoy7y1rs+QCsKHXbF2i1iE=; b=OeDAVVmTOxS3xx9XVp3DiFwbSj8+WsA11ZS4Q8YaInQ/ds7Qe5XJXFLNEMl76RBfLNP8nK CEQTZKu6CY/E2K2z1AoJV1CX/DeAk4t0S9RkdcKOGFLx7jsqTQkZ1b3a6lQOG8Vvm5kas5 YQtYqBRp4vPzHj/lfQMv26JwSfP2EXY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1657611618; a=rsa-sha256; cv=none; b=DuCI339NPfM2qhi85MDg60dlEljjZA/wNBFZk44DAgYTKEJtZzACEjrHAAHfrHCJpaqqQU 7tgCtTsYUEnoTGHv3Kd00M43EE+hVBYedRma0VdqQFUKJkNdrXU2ov7OM3fw9QIWcANNYA TY7L7PV+Hnbn8rGCnq7FlyG6IRuGo/s= Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=qdRyPo4q; dmarc=pass (policy=quarantine) header.from=suse.com; spf=pass (imf21.hostedemail.com: domain of mhocko@suse.com designates 195.135.220.28 as permitted sender) smtp.mailfrom=mhocko@suse.com X-Rspam-User: X-Rspamd-Server: rspam08 X-Stat-Signature: 6iswijwrhgntgzizy1fj9uh8dp8fmj4y X-Rspamd-Queue-Id: 9E4DE1C0072 X-HE-Tag: 1657611618-723098 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 Mon 11-07-22 21:39:14, Alexei Starovoitov wrote: > On Mon, Jul 11, 2022 at 02:15:07PM +0200, Michal Hocko wrote: > > On Sun 10-07-22 07:32:13, Shakeel Butt wrote: > > > On Sat, Jul 09, 2022 at 10:26:23PM -0700, Alexei Starovoitov wrote: > > > > On Fri, Jul 8, 2022 at 2:55 PM Shakeel Butt wrote: > > > [...] > > > > > > > > > > Most probably Michal's comment was on free objects sitting in the caches > > > > > (also pointed out by Yosry). Should we drain them on memory pressure / > > > > > OOM or should we ignore them as the amount of memory is not significant? > > > > > > > > Are you suggesting to design a shrinker for 0.01% of the memory > > > > consumed by bpf? > > > > > > No, just claim that the memory sitting on such caches is insignificant. > > > > yes, that is not really clear from the patch description. Earlier you > > have said that the memory consumed might go into GBs. If that is a > > memory that is actively used and not really reclaimable then bad luck. > > There are other users like that in the kernel and this is not a new > > problem. I think it would really help to add a counter to describe both > > the overall memory claimed by the bpf allocator and actively used > > portion of it. If you use our standard vmstat infrastructure then we can > > easily show that information in the OOM report. > > OOM report can potentially be extended with info about bpf consumed > memory, but it's not clear whether it will help OOM analysis. If GBs of memory can be sitting there then it is surely an interesting information to have when seeing OOM. One of the big shortcomings of the OOM analysis is unaccounted memory. > bpftool map show > prints all map data already. > Some devs use bpf to inspect bpf maps for finer details in run-time. > drgn scripts pull that data from crash dumps. > There is no need for new counters. > The idea of bpf specific counters/limits was rejected by memcg folks. I would argue that integration into vmstat is useful not only for oom analysis but also for regular health check scripts watching /proc/vmstat content. I do not think most of those generic tools are BPF aware. So unless there is a good reason to not account this memory there then I would vote for adding them. They are cheap and easy to integrate. > > OK, thanks for the clarification. There is still one thing that is not > > really clear to me. Without a proper ownership bound to any process why > > is it desired/helpful to account the memory to a memcg? > > The first step is to have a limit. memcg provides it. I am sorry but this doesn't really explain it. Could you elaborate please? Is the limit supposed to protect against adversaries? Or is it just to prevent from accidental runaways? Is it purely for accounting purposes? > > We have discussed something similar in a different email thread and I > > still didn't manage to find time to put all the parts together. But if > > the initiator (or however you call the process which loads the program) > > exits then this might be the last process in the specific cgroup and so > > it can be offlined and mostly invisible to an admin. > > Roman already sent reparenting fix: > https://patchwork.kernel.org/project/netdevbpf/patch/20220711162827.184743-1-roman.gushchin@linux.dev/ Reparenting is nice but not a silver bullet. Consider a shallow hierarchy where the charging happens in the first level under the root memcg. Reparenting to the root is just pushing everything under the system resources category. > > As you have explained there is nothing really actionable on this memory > > by the OOM killer either. So does it actually buy us much to account? > > It will be actionable. One step at a time. > In the other thread we've discussed an idea to make memcg selectable when > bpf objects are created. The user might create a special memcg and use it for > all things bpf. This might be the way to provide bpf specific accounting > and limits. Do you have a reference for those discussions? -- Michal Hocko SUSE Labs