Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp391500pxu; Tue, 1 Dec 2020 14:02:46 -0800 (PST) X-Google-Smtp-Source: ABdhPJzUy9KALj4Bi8Dwu5Oqryid0WC4o8NZ/XiiwcRcjeIEDnsfS30gv2hschUt0m8wh7VETkei X-Received: by 2002:a50:ac86:: with SMTP id x6mr1765709edc.197.1606860166444; Tue, 01 Dec 2020 14:02:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606860166; cv=none; d=google.com; s=arc-20160816; b=spnwiDiA+Cvop7AF4hoqNKdLWuj3LBGx/B1plXkM7UfyiU/SBvIc8iKpC4bDwEVoaY zpUuTckbqmxlvGnhyRravGfdSLyf8LLe4METvpObrRr3022fBEC5l4VtAiON4VYzlv6g Mc9gcUDahgfg+qpduHc+6CJzmwyvm2pmN5uVyuob4th5aXi3/4+gW0qdaziueFj4646z THvda5p6pAjTRvs6s7R5A6iyxqvLZL0rg5nO3n/ApzgZnuGe2EYNjs7zeD2an3tqr/Kq qOB0pjjyn/NqeyNNrBcaVZYaeHoHrHxKiINpuUjsLA6gLy322KVibNkUfDqKAhYrXKkS 0G1A== 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=OsW+YgsUMKIkwiLI58nQIqOmhb5BolGzaeK0LwveQiU=; b=dCblAk8d1ESj4SYec1HNF+nFbPCHI/amkXdxzh6pZnS3eq62iRSDMkz8Lzqsziijh8 d48GaFtXsH0V+YH61mVjDI0kMVBSy+b1sUGVZyuSYI426rhuze9TzcCV2TNj+AHG7joS CE0YfUzfF9C3HYDZ/8Q55NWpEENEs2kZ8LNlDvQOt2IBeZb6rewW0xhmaYY7oiAlHbWH ixZOwvqsOWCt43GBnNI9YU/UAVA/spgO00OZJ1SmCRpn/kaiaq3rVg+UV3r9s5t7UvzJ kSyyK+t85rAFUsV+cdXgZQ/oQhk/f6LlBTFx2lOOUP6xd1nNnW7aHPF3jFYm5v/ah8eq 77lw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=E+u36fC3; 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 v5si1008653edi.183.2020.12.01.14.02.23; Tue, 01 Dec 2020 14:02: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=E+u36fC3; 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 S2390381AbgLAV74 (ORCPT + 99 others); Tue, 1 Dec 2020 16:59:56 -0500 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:43826 "EHLO mx0b-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389826AbgLAV74 (ORCPT ); Tue, 1 Dec 2020 16:59:56 -0500 Received: from pps.filterd (m0109331.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 0B1LnWed024474 for ; Tue, 1 Dec 2020 13:59:14 -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=OsW+YgsUMKIkwiLI58nQIqOmhb5BolGzaeK0LwveQiU=; b=E+u36fC33PUG7iamCK81UHGY4ph/VQecgtOYQvj9AuL6e/WZji0ikXJ/eg8qtog3Ye6o 0spUq4draCeJORiA+rExrWAQ5LcLg9VGt+oOFcUqkF8ObJRLTHP850f4A3Wzy2z4cQD0 Cfu0ODK3JWFGDGoBJM8bo+tpstp+2zZ/ELg= Received: from mail.thefacebook.com ([163.114.132.120]) by mx0a-00082601.pphosted.com with ESMTP id 353uh50v0a-12 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Tue, 01 Dec 2020 13:59:14 -0800 Received: from intmgw002.41.prn1.facebook.com (2620:10d:c085:108::8) by mail.thefacebook.com (2620:10d:c085:11d::5) 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:09 -0800 Received: by devvm3388.prn0.facebook.com (Postfix, from userid 111017) id 6C96D19702B2; Tue, 1 Dec 2020 13:59:06 -0800 (PST) From: Roman Gushchin To: CC: , , , , , , , Subject: [PATCH bpf-next v9 10/34] bpf: memcg-based memory accounting for cgroup storage maps Date: Tue, 1 Dec 2020 13:58:36 -0800 Message-ID: <20201201215900.3569844-11-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 clxscore=1015 malwarescore=0 adultscore=0 lowpriorityscore=0 suspectscore=13 priorityscore=1501 mlxscore=0 phishscore=0 bulkscore=0 spamscore=0 impostorscore=0 mlxlogscore=999 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 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 | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/kernel/bpf/local_storage.c b/kernel/bpf/local_storage.c index 571bb351ed3b..74dcee8926e5 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, + 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; struct bpf_cgroup_storage *storage; struct bpf_map *map; - gfp_t flags; size_t size; u32 pages; =20 @@ -511,20 +511,19 @@ 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 bpf_map_kmalloc_node(map, 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 bpf_map_kmalloc_node(map, 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 bpf_map_alloc_percpu(map, size, 8, gfp); if (!storage->percpu_buf) goto enomem; } --=20 2.26.2