Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp630158pxb; Thu, 19 Nov 2020 09:44:46 -0800 (PST) X-Google-Smtp-Source: ABdhPJxYHiT3mKVDK9ofxDRegbk+1DgWUuwCHVqBB4yVl2MURZYwF7D3orAtjssx/hxgjmFzfqlG X-Received: by 2002:a17:906:46d5:: with SMTP id k21mr29898721ejs.495.1605807886275; Thu, 19 Nov 2020 09:44:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605807886; cv=none; d=google.com; s=arc-20160816; b=S+gj9ekqZtsm+VO5rnrle6KO1beWfzqV2wAIsjDFRLqcTZzEQv3A+TjBJmvEsJ4TrB DAt1HNVvGMbvq8NX7RTYoA4LcJytJxX1oaCmb6fzjHkjs0pKdlcZsBbPv+9gF0X8A/qD hrywRZxU/JcCf/Ku06f/a8oXMWh5Wl6avdFK0g1QjBcv498Jh9wJOA6/eb00aO/aWK0i XoJNNXhx98Hs3N42yfs4hlnoFDIRNA/BiR8O+9/rSNgXeQR09sKu7tzXnJjVCX5HH+Rd zFMYY/N5dhHloiNV6xzpZLptb+dCcnjsrOp2MPrAwtY1fOSI2ENCWX/yfR5rDSovIKaO duKg== 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=mtIjSDYWWmw4Li7CA+9a5qUeSSopzyAJ8NyDIn/Z8ho=; b=H8VDTOMLSl05QRhSoAfDcBuJ7vWbQceNtlBK1/pUPtYMocIaFeRyqDJXO6Uqr2etfE /BpURcCLTX6FJuU84ySfbW0eNWLYVnKXZSICC6pVe1Oz0nn6gSLjaDWqVEvaQWzN4kQ6 XvD3+p9y5YxrVLPfUX1v1GzOy8m+ri9peeBMdDWhoY6mVBOoRgiz9eyWBg80fscT3vL+ ilRmpFZKoF1VElD/aIBjYqNEw1ToXDkF3jQwbLidEfd164HVAVN6ZXpN7DkOPm9m7gYJ leC/D7097VXXfY5mCiNv4u0Ff4A1hXKxstsqo4iVQjEx8uC98uUhub/EOB82YNR9xpTk ZG4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=XlK9Bc4X; 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 lj24si217804ejb.612.2020.11.19.09.44.23; Thu, 19 Nov 2020 09:44:46 -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=XlK9Bc4X; 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 S1729793AbgKSRkm (ORCPT + 99 others); Thu, 19 Nov 2020 12:40:42 -0500 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:16272 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729386AbgKSRiH (ORCPT ); Thu, 19 Nov 2020 12:38:07 -0500 Received: from pps.filterd (m0044010.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 0AJHUXKi012357 for ; Thu, 19 Nov 2020 09:38:07 -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=mtIjSDYWWmw4Li7CA+9a5qUeSSopzyAJ8NyDIn/Z8ho=; b=XlK9Bc4XE4AagH6qPPA0JUjlPetcm/gwa9f0dIxfGi9KIepiogd+Y/JxjOcwo/uD03u/ ZUPudOmISH1QoPoEV8NiN2xj5QftBKfmAHe/xpS5hMHEUDw8hAq7jJbI386YBKARHffC UGKKtbf9NI98MGAHsFhJvWxQLNpaqzuYDTw= Received: from mail.thefacebook.com ([163.114.132.120]) by mx0a-00082601.pphosted.com with ESMTP id 34w2mkbdcy-10 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 19 Nov 2020 09:38:06 -0800 Received: from intmgw001.06.prn3.facebook.com (2620:10d:c085:208::f) by mail.thefacebook.com (2620:10d:c085:11d::4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Thu, 19 Nov 2020 09:38:05 -0800 Received: by devvm3388.prn0.facebook.com (Postfix, from userid 111017) id A4052145BCEB; Thu, 19 Nov 2020 09:37:56 -0800 (PST) From: Roman Gushchin To: CC: , , , , , , , Subject: [PATCH bpf-next v7 10/34] bpf: memcg-based memory accounting for cgroup storage maps Date: Thu, 19 Nov 2020 09:37:30 -0800 Message-ID: <20201119173754.4125257-11-guro@fb.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20201119173754.4125257-1-guro@fb.com> References: <20201119173754.4125257-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-19_09:2020-11-19,2020-11-19 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 suspectscore=13 bulkscore=0 mlxscore=0 adultscore=0 lowpriorityscore=0 mlxlogscore=999 priorityscore=1501 clxscore=1015 phishscore=0 spamscore=0 malwarescore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2011190125 X-FB-Internal: deliver Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Account memory used by cgroup storage maps including metadata structures. Account the percpu memory for the percpu flavor of cgroup storage. Signed-off-by: Roman Gushchin --- kernel/bpf/local_storage.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/kernel/bpf/local_storage.c b/kernel/bpf/local_storage.c index 571bb351ed3b..aae17d29538e 100644 --- a/kernel/bpf/local_storage.c +++ b/kernel/bpf/local_storage.c @@ -164,10 +164,10 @@ static int cgroup_storage_update_elem(struct bpf_ma= p *map, void *key, return 0; } =20 - new =3D kmalloc_node(sizeof(struct bpf_storage_buffer) + - map->value_size, - __GFP_ZERO | GFP_ATOMIC | __GFP_NOWARN, - map->numa_node); + new =3D bpf_map_kmalloc_node(map, sizeof(struct bpf_storage_buffer) + + map->value_size, __GFP_ZERO | GFP_ATOMIC | + __GFP_NOWARN | __GFP_ACCOUNT, + map->numa_node); if (!new) return -ENOMEM; =20 @@ -313,7 +313,7 @@ static struct bpf_map *cgroup_storage_map_alloc(union= bpf_attr *attr) return ERR_PTR(ret); =20 map =3D kmalloc_node(sizeof(struct bpf_cgroup_storage_map), - __GFP_ZERO | GFP_USER, numa_node); + __GFP_ZERO | GFP_USER | __GFP_ACCOUNT, numa_node); if (!map) { bpf_map_charge_finish(&mem); return ERR_PTR(-ENOMEM); @@ -496,9 +496,9 @@ static size_t bpf_cgroup_storage_calculate_size(struc= t bpf_map *map, u32 *pages) struct bpf_cgroup_storage *bpf_cgroup_storage_alloc(struct bpf_prog *pro= g, enum bpf_cgroup_storage_type stype) { + const gfp_t gfp =3D __GFP_ZERO | GFP_USER | __GFP_ACCOUNT; struct bpf_cgroup_storage *storage; struct bpf_map *map; - gfp_t flags; size_t size; u32 pages; =20 @@ -511,20 +511,18 @@ struct bpf_cgroup_storage *bpf_cgroup_storage_alloc= (struct bpf_prog *prog, if (bpf_map_charge_memlock(map, pages)) return ERR_PTR(-EPERM); =20 - storage =3D kmalloc_node(sizeof(struct bpf_cgroup_storage), - __GFP_ZERO | GFP_USER, map->numa_node); + storage =3D kmalloc_node(sizeof(struct bpf_cgroup_storage), gfp, + map->numa_node); if (!storage) goto enomem; =20 - flags =3D __GFP_ZERO | GFP_USER; - if (stype =3D=3D BPF_CGROUP_STORAGE_SHARED) { - storage->buf =3D kmalloc_node(size, flags, map->numa_node); + storage->buf =3D kmalloc_node(size, gfp, map->numa_node); if (!storage->buf) goto enomem; check_and_init_map_lock(map, storage->buf->data); } else { - storage->percpu_buf =3D __alloc_percpu_gfp(size, 8, flags); + storage->percpu_buf =3D __alloc_percpu_gfp(size, 8, gfp); if (!storage->percpu_buf) goto enomem; } --=20 2.26.2