Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp392138pxu; Tue, 1 Dec 2020 14:03:45 -0800 (PST) X-Google-Smtp-Source: ABdhPJw9vB6iRqvtzO/NJGx1fuOpy+slBbwBWaj6oHxhRzD8mLUWKpz0ZHFevTvC+8QZK2X7bB3m X-Received: by 2002:a17:906:8052:: with SMTP id x18mr5006259ejw.78.1606860225067; Tue, 01 Dec 2020 14:03:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606860225; cv=none; d=google.com; s=arc-20160816; b=L0V0wrcjRLE36JFv5dxIqcYiuWGIhEPEkEO21MKWfnPgd0AFy0MgmzOWmKLRYggM9G 11nNaGS1pMa/yjoRebj+Oaqhml8Ob4DHzRV604wqgkR214nBY9w5x1UUB41DVwcn7gG+ aFAFs4Tv88uy7m1WV3UreqbJTgvnxZCNqMFxEWR9EG3RgybQi6Za8xl4/1qxyvtEQsuM 6YBwHmHIuUYiUn6dSt4DtoLezRUdK7jUgNDAnWC2tXSbtB1YBKltbYIJH6xoBP20/cyq XrPwXFiFBAdE9bDFWWegfp885d4WMzH4kW4l2fG8l4XvdZDbIWlqSr9TaCcjr4vTUR+b v20g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=O7tHJPPMX1n8XVlMLHDhzJco9LceDdYtFho1yxWVAM8=; b=vzUKqnsdrlG9zcAnrdHRgFYam9DXBy0rlWR04OEDk22ZMRea1O5uCHxZYr3Lkqb0LX rhFM91oJ78iYiE/lKvnSEOw8LK4LrLtkvUksPrt0ea2Jy662CNSSAB3jBWb9SOpdBSXQ VnCCz/TcQe/riR3YVI0QtzyND88h5uZLat2KMEFDDRm3gLGV9Zi4t/ZzVU9gIVKcdASF vTDRQ3VtI8xnuttCG+setKLgbpSealBSWpoIZRWSzmyhEE3uXr/ITmf8QjVr1gdldzS2 omJSScz7EvOeXezbC2KMaiObzXQdsasWITkrNa24+60QJlWUvMJwxGPmXhwEKwmp7qFL YPwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=ivtPYvrd; 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=REJECT sp=REJECT dis=NONE) header.from=fb.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t17si750219ejj.562.2020.12.01.14.03.22; Tue, 01 Dec 2020 14:03:45 -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=@fb.com header.s=facebook header.b=ivtPYvrd; 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=REJECT sp=REJECT dis=NONE) header.from=fb.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387470AbgLAV7u (ORCPT + 99 others); Tue, 1 Dec 2020 16:59:50 -0500 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:20178 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730025AbgLAV7u (ORCPT ); Tue, 1 Dec 2020 16:59:50 -0500 Received: from pps.filterd (m0109333.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 0B1LpZDD001936 for ; Tue, 1 Dec 2020 13:59:09 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=facebook; bh=O7tHJPPMX1n8XVlMLHDhzJco9LceDdYtFho1yxWVAM8=; b=ivtPYvrd2eiAnul1qx30d0xh/NYgmP1xvxKrXyYbUPxLuV16hLO1OsjLwzWIxdMXWsyI U3vjJ1A4/8l/RJbML/8/64TeibeybyFV59U7Gk3xZ4nDhEvq3rKYgcWZnXxNZrgFUI1A UKB6NUQWv5TagM/TroukytW5LVGlrz3gQh0= Received: from mail.thefacebook.com ([163.114.132.120]) by mx0a-00082601.pphosted.com with ESMTP id 355qvjk193-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Tue, 01 Dec 2020 13:59:09 -0800 Received: from intmgw003.06.prn3.facebook.com (2620:10d:c085:108::8) by mail.thefacebook.com (2620:10d:c085:21d::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Tue, 1 Dec 2020 13:59:08 -0800 Received: by devvm3388.prn0.facebook.com (Postfix, from userid 111017) id 536D319702A8; Tue, 1 Dec 2020 13:59:06 -0800 (PST) From: Roman Gushchin To: CC: , , , , , , , Subject: [PATCH bpf-next v9 05/34] bpf: memcg-based memory accounting for bpf progs Date: Tue, 1 Dec 2020 13:58:31 -0800 Message-ID: <20201201215900.3569844-6-guro@fb.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20201201215900.3569844-1-guro@fb.com> References: <20201201215900.3569844-1-guro@fb.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-FB-Internal: Safe Content-Type: text/plain X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.312,18.0.737 definitions=2020-12-01_11:2020-11-30,2020-12-01 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 lowpriorityscore=0 clxscore=1015 impostorscore=0 suspectscore=38 malwarescore=0 adultscore=0 spamscore=0 mlxlogscore=734 priorityscore=1501 phishscore=0 bulkscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012010131 X-FB-Internal: deliver Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Include memory used by bpf programs into the memcg-based accounting. This includes the memory used by programs itself, auxiliary data, statistics and bpf line info. A memory cgroup containing the process which loads the program is getting charged. Signed-off-by: Roman Gushchin Acked-by: Song Liu --- kernel/bpf/core.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c index ff55cbcfbab4..2921f58c03a8 100644 --- a/kernel/bpf/core.c +++ b/kernel/bpf/core.c @@ -77,7 +77,7 @@ void *bpf_internal_load_pointer_neg_helper(const struct= sk_buff *skb, int k, uns =20 struct bpf_prog *bpf_prog_alloc_no_stats(unsigned int size, gfp_t gfp_ex= tra_flags) { - gfp_t gfp_flags =3D GFP_KERNEL | __GFP_ZERO | gfp_extra_flags; + gfp_t gfp_flags =3D GFP_KERNEL_ACCOUNT | __GFP_ZERO | gfp_extra_flags; struct bpf_prog_aux *aux; struct bpf_prog *fp; =20 @@ -86,7 +86,7 @@ struct bpf_prog *bpf_prog_alloc_no_stats(unsigned int s= ize, gfp_t gfp_extra_flag if (fp =3D=3D NULL) return NULL; =20 - aux =3D kzalloc(sizeof(*aux), GFP_KERNEL | gfp_extra_flags); + aux =3D kzalloc(sizeof(*aux), GFP_KERNEL_ACCOUNT | gfp_extra_flags); if (aux =3D=3D NULL) { vfree(fp); return NULL; @@ -106,7 +106,7 @@ struct bpf_prog *bpf_prog_alloc_no_stats(unsigned int= size, gfp_t gfp_extra_flag =20 struct bpf_prog *bpf_prog_alloc(unsigned int size, gfp_t gfp_extra_flags= ) { - gfp_t gfp_flags =3D GFP_KERNEL | __GFP_ZERO | gfp_extra_flags; + gfp_t gfp_flags =3D GFP_KERNEL_ACCOUNT | __GFP_ZERO | gfp_extra_flags; struct bpf_prog *prog; int cpu; =20 @@ -138,7 +138,7 @@ int bpf_prog_alloc_jited_linfo(struct bpf_prog *prog) =20 prog->aux->jited_linfo =3D kcalloc(prog->aux->nr_linfo, sizeof(*prog->aux->jited_linfo), - GFP_KERNEL | __GFP_NOWARN); + GFP_KERNEL_ACCOUNT | __GFP_NOWARN); if (!prog->aux->jited_linfo) return -ENOMEM; =20 @@ -219,7 +219,7 @@ void bpf_prog_free_linfo(struct bpf_prog *prog) struct bpf_prog *bpf_prog_realloc(struct bpf_prog *fp_old, unsigned int = size, gfp_t gfp_extra_flags) { - gfp_t gfp_flags =3D GFP_KERNEL | __GFP_ZERO | gfp_extra_flags; + gfp_t gfp_flags =3D GFP_KERNEL_ACCOUNT | __GFP_ZERO | gfp_extra_flags; struct bpf_prog *fp; u32 pages, delta; int ret; --=20 2.26.2