Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp69836pxu; Tue, 24 Nov 2020 19:06:39 -0800 (PST) X-Google-Smtp-Source: ABdhPJxcusBwzx3WwzbLVXJ03LIyIouS053NqOR9b4AWzwshj+Lvo2dQgGO0tiAEwsSnL+uCVWTe X-Received: by 2002:a17:906:1945:: with SMTP id b5mr1403357eje.388.1606273598921; Tue, 24 Nov 2020 19:06:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606273598; cv=none; d=google.com; s=arc-20160816; b=Usg2+qKpA/YSBoaDR4QEs6F9+1iJO/zKS6dEyo8LG3wPJIDj4QAGUmQPl4i3T7hDXh J8Q7hGrkPDEAMMPkVRaIM8624LJUq5HRInzX8r2mP6iQgWsMEBbbaOL38hHaYh1HKy4B KOOcs1mOThkkVAvmhO2KdWM3aLEpOrZ2W1qbIl8lTrfhLeAhTp+uKEx9JYZRv88t0116 D9hgO1oh2FatWrDD7FfIiVnXqZSqN+kOjMMpVUJ1PG0B73VbO0a9UE1CfeLdsWVCsKeD 6b138XX7o+UjPTvl7LldaHGaF7SGtFI+6LWEq8/5BhNTxY9IrjmJxkqYRFWKkXT1bGLi VdDQ== 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=K7fXzxay6fb6903lI98/XPMsc8fYblomdsVeJQ8cksxrrO2HSuDbZhJ/iW7s1ydYDi gC6oNjjCjCGeKqTe9BEu8orYNCUdzJk7jc19TL264AU9Ph/9jC5OWo6w78egJNanp2BJ cDLseU8puJWeryCsxGBQvj1zq9GQuO+xX+Kb3S6wrQUVtfuTM7yAE2V2vlAeycB56J/f tprRhSpTffW1PvSvMtiIn+YKb8RYwehEARykmTv/WkwV4d7K4B2kr7z1r7O9hcqUaHWI R65qdQ3NiMFD1voUm+bFfh+Bgi68CK9PjNFSQyyUtFmABFbMSvektW29No/WlMPTspnc rB+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=gYYSskLO; 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 l7si474255eja.665.2020.11.24.19.06.16; Tue, 24 Nov 2020 19:06:38 -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=gYYSskLO; 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 S1728304AbgKYDCq (ORCPT + 99 others); Tue, 24 Nov 2020 22:02:46 -0500 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:41320 "EHLO mx0b-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727476AbgKYDBe (ORCPT ); Tue, 24 Nov 2020 22:01:34 -0500 Received: from pps.filterd (m0109332.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 0AP2skws014300 for ; Tue, 24 Nov 2020 19:01:33 -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=gYYSskLOkFm56Lbrpc+PcWPT7PdCfFSPwVEqZthAV4TwI+KOeyYEonxmC6d4InW6Jnkh ABRWd7NiPeMyUX4o3suE+E/cZTJTRLf7WOA8PytmnV4iryKEv5CRlmogxM58bTj2U8hx eWqjUYsixvJQgfWm5IABabX/aFAGNXmbOu8= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com with ESMTP id 34ykxgmjxs-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Tue, 24 Nov 2020 19:01:33 -0800 Received: from intmgw001.06.prn3.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:83::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Tue, 24 Nov 2020 19:01:32 -0800 Received: by devvm3388.prn0.facebook.com (Postfix, from userid 111017) id F22EE16A188B; Tue, 24 Nov 2020 19:01:21 -0800 (PST) From: Roman Gushchin To: CC: , , , , , , , Subject: [PATCH bpf-next v8 05/34] bpf: memcg-based memory accounting for bpf progs Date: Tue, 24 Nov 2020 19:00:50 -0800 Message-ID: <20201125030119.2864302-6-guro@fb.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20201125030119.2864302-1-guro@fb.com> References: <20201125030119.2864302-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-11-24_11:2020-11-24,2020-11-24 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 adultscore=0 lowpriorityscore=0 suspectscore=38 mlxlogscore=734 priorityscore=1501 spamscore=0 impostorscore=0 bulkscore=0 malwarescore=0 mlxscore=0 phishscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2011250018 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