Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp696550pxu; Thu, 26 Nov 2020 09:17:54 -0800 (PST) X-Google-Smtp-Source: ABdhPJxaojJAE7l+Ef4IodXFGHgGTrb2Fz/Hp4DEJd72A4Vu4/EUuUL9F8x5BYEQSra+kbAsGcsk X-Received: by 2002:a50:8f64:: with SMTP id 91mr3537216edy.310.1606411073786; Thu, 26 Nov 2020 09:17:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606411073; cv=none; d=google.com; s=arc-20160816; b=fCoUw5LkPXbSZ76L5RAROKxwpYE6G2NQlhswEfoOJbR+zDOLY9oXlLikjo396ZYxO/ 2ge+EhR+JPdIQM9DO3uovKU44myAKgQRWEAiRKeTHxSxEZ+ZUNB407DB23VwrrKi1CKp ySFiWx0tSKvptzezfGQjmHXEbhgcNJcHWtL6CI0jgYIywmlDfOUwUbrOwT41QsegEAkf PyMZgg/0EcT2OEzt7UozJPfIREXYblWw2nPBb91QQGaBS4XF+rTOf6965a+U/A7TP+7I asE7K2aondX2quRZPZpBNX2t5y92Aqi+xOJjr8iYlUklV+vhupAZY1AScDE3H4A0p/mC u0wA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=VpnUj0vwEBxW6p7ITczWY4IsgxvLvEJLYdLmcYXOZkU=; b=DsKQlZPz3D6Yj9juuEyATTtAiaTeM5Lt5lQ0eZBYtud0advdfrWa7JsVXA5+u6t8K/ aa9D483CKS95v8/qLs+pTg1pqqMrg1C1VsPjJDiu9A/Msk5QpEilaJ49dex/XDSNCytC izDu8W+Jgz6kfdf+zNVzkLD3td6GJFkyfLvHwIbOA2WZnQbAdEKWl0xWp3/1iRcPO+5o ngYX93ljmmMrVP8qytkWbWD8KyIXOU3tD1jbPFccNcCUbF4A9Q5LCqbS0B/ziUwNlWG5 lR/0Yaof7TWzXazZ/mKPA0ti5Mvo2+A9l83T2m3KPszJlNk56LVI9oEEa22gC794WZ4E R1ig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=bNIV9vN0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hq10si3245467ejc.616.2020.11.26.09.17.30; Thu, 26 Nov 2020 09:17:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=bNIV9vN0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404089AbgKZRNK (ORCPT + 99 others); Thu, 26 Nov 2020 12:13:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35102 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404008AbgKZRNJ (ORCPT ); Thu, 26 Nov 2020 12:13:09 -0500 Received: from mail-lj1-x242.google.com (mail-lj1-x242.google.com [IPv6:2a00:1450:4864:20::242]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A998C0613D4; Thu, 26 Nov 2020 09:13:08 -0800 (PST) Received: by mail-lj1-x242.google.com with SMTP id i17so3116523ljd.3; Thu, 26 Nov 2020 09:13:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=VpnUj0vwEBxW6p7ITczWY4IsgxvLvEJLYdLmcYXOZkU=; b=bNIV9vN0a4JsfmKqZ80aejvtZg4VlBh59eCSvINKkY7gI+B3p+OINaw1WT8TbCuYEp w9SieaelhASvFeb55DSGvdrvjXoa8lCwCqZCffodPp7944KO4zJpQSkdVpwDf5B6mmPd MmKveMlfHhcEnUbl1FMte4aJpELc8Wtt3ENVKEEVfMGk/tTXcmS+a84sk9XirGRBFa75 Pz/oTnxPeCwC9u/bNg8DJCn+qRvt7/gQRVVmn2X6jxWNyoVc8ddJy4TbAs/X3poYhsn3 bhlzF+ZVefYRNx2Hi7+3WG1KJ5joQFxklIMgsIEX/v4JUJ+/WE7VLGCtv0ZhEzJ4cHrj L04g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=VpnUj0vwEBxW6p7ITczWY4IsgxvLvEJLYdLmcYXOZkU=; b=fbpdMkrCJUSaX0YDMSQKe64kZJHhjwwFPzFcOX8PpqRbPb7b9fPmAeFZ7qeFIfQmjo hxbrdzx1crE4jwmyaMcVblVDhfztNcSO1evpYFWBL0rXFfY0VLk0kuMytiqUfBD8GVBP cTsrXy5zZYhkE3GqFn1wZaOucc7TSYEWbiPjLztIBEtsAFshXpsRrOti+zqIpmvnWtRA zsc3CSw9f+MbTkeZehEJcPz2WCWk+xZ3m22CKfqZhVSXs8selzqKq866ivxHQ8iqzpCl fkmA2b9nQD+Q0IYjfUm2zZCiXGDBaRVAZHeBV2w0rXXY1OpbwTytgxem9ENuYaf1Fef8 bgjg== X-Gm-Message-State: AOAM531yaOiJ7Mnir8MfZjijtEplQtd25gzyyVmmAMSxNgW8wxT4n5Mp aPssykWM6lonor6x22vXjLPk5zFj4hBcsz9pVf8= X-Received: by 2002:a2e:9648:: with SMTP id z8mr1567183ljh.91.1606410786463; Thu, 26 Nov 2020 09:13:06 -0800 (PST) MIME-Version: 1.0 References: <20201125030119.2864302-1-guro@fb.com> <20201125030119.2864302-7-guro@fb.com> <20201126023000.GB840171@carbon.dhcp.thefacebook.com> In-Reply-To: <20201126023000.GB840171@carbon.dhcp.thefacebook.com> From: Alexei Starovoitov Date: Thu, 26 Nov 2020 09:12:55 -0800 Message-ID: Subject: Re: [PATCH bpf-next v8 06/34] bpf: prepare for memcg-based memory accounting for bpf maps To: Roman Gushchin Cc: Daniel Borkmann , bpf , Alexei Starovoitov , Network Development , Andrii Nakryiko , Andrew Morton , linux-mm , LKML , Kernel Team , Johannes Weiner , Tejun Heo Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Nov 25, 2020 at 6:30 PM Roman Gushchin wrote: > > I did consider this option. There are pros and cons. In general we tend to charge the cgroup > which actually allocates the memory, and I decided to stick with this rule. I agree, it's fairly > easy to come with arguments why always charging the map creator is better. The opposite is > also true: it's not clear why bpf is different here. So I'm fine with both options, if there > is a wide consensus, I'm happy to switch to the other option. In general, I believe that > the current scheme is more flexible. I don't understand the 'more flexible' part. The current_memcg or map_memcg approach makes it less predictable. pre-alloc vs not is somewhat orthogonal. I've grepped through the kernel where set_active_memcg() is used and couldn't find a conditional pattern of its usage. If memcg is known it's used. I couldn't come up with the use case where using current memcg is the more correct thing to do. > In general we tend to charge the cgroup which actually allocates the memory that makes sense where allocation is driven by the user process. Like user space doing a syscall then all kernel allocation would be from memcg of that process. But bpf tracing allocations are not something that the user process requested the kernel to do. It's like another user space process tapped into another. Arguably when bpf prog is running the two user processes are active. One that created the map and loaded the prog and another that is being traced. I think there will be cases where bpf prog will request the kernel to allocate memory on behalf of the process being traced, but that memory should be given back to the process and accessible by it in some form. Like bpf prog could ask the kernel to grow heap of that process or trigger readahead. In such case current_memcg would be the right thing to charge.