Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp69077pxu; Tue, 24 Nov 2020 19:05:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJwyw1yiYtPtaXHQKei51LlNw/N2BOgutiIWqMCJ1DS3ZmRn6gIITgvh118kHsMKhAbLrSrg X-Received: by 2002:a17:907:3e96:: with SMTP id hs22mr1272757ejc.203.1606273508208; Tue, 24 Nov 2020 19:05:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606273508; cv=none; d=google.com; s=arc-20160816; b=xFrRVztcQEd/ZeQKOKbbpE37BmOitUkmUz57D/REwqsomrWTd1IXWPwc/NrqBwaH1v G9+RmPJSz4L3Ax68Rzy6CSsZfod2l+GuJek2zXD8ZqLwIDydY2e+btYsX7io5mkt/0Cs h8fKFI3KivFmalTsyTvCqAzYWM7aP3bpGmwt4Ua7vym/PYTedEBzIUuq7d78a7PzTSFD dOe0jHyyPMKOIhzziz4CtrZjd0Rakns44dIQxRR4FEVoDf9jeKWVV8OBFxdYhJpWL4QK 3fEkNRLeZ/3ykZbC2rxAoy4CMkqIzMF3FlDSk8yw8q5IOf9htgH/hX+X6ER9IhheBVYy H1Zg== 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=p7AL5MEv67PXm8tsjFCWY0aTmPqyKn82sJgTxCQ6mgI=; b=Gw7FgmqcmHZDNBdaGnAptZFM23xI7Du+rGXarELFBJjSt9GDeWXwzWbmEt04a4lOCG naFATJAgkS/3542uch/bKgvExUsOzSUWudUmkI4uUT+FBWeklWlCzVmZGrFfTJtsywdw iHDlKUJf/wIRExrcLpTsh4yBYoR0oPmDxiGi9bDa9A6/XI/pLa6jVBDrrkPLmTxb2Zh9 wZdAIqHxVZDpmdmPTXN9G9MIVJ+OEVN7/G6QhQcSF5p1w54VK3PwvIX0WLWpUS9dcQuc 6Ufa7FGPNpPwNgdBSFw1TcgNc7i4BehLZ/KMtVg4wlLQI/ydYKYQ1Njina16uIzJnKUX SySA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b="JqOpge+/"; 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 w8si545664ejv.263.2020.11.24.19.04.45; Tue, 24 Nov 2020 19:05:08 -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="JqOpge+/"; 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 S1727629AbgKYDBj (ORCPT + 99 others); Tue, 24 Nov 2020 22:01:39 -0500 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:52220 "EHLO mx0b-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727646AbgKYDBi (ORCPT ); Tue, 24 Nov 2020 22:01:38 -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 0AP2tOl8015257 for ; Tue, 24 Nov 2020 19:01:37 -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=p7AL5MEv67PXm8tsjFCWY0aTmPqyKn82sJgTxCQ6mgI=; b=JqOpge+/nAfjxoXnbeP398O02nZ1sD6m9Au28ZDctQg89MLnIBxkza5YL7j8wsVMa7OP DSgeF1tT/LXbI8h1SCuZux7l0PubLRYdvkDglmMxqdsV+hs8l6mn15UvhTvDQ0oi4SXC vSZa1k2nkWDW3vVIkCuYzJFCC3SNQpYWEjc= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com with ESMTP id 34ykxgmjxx-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Tue, 24 Nov 2020 19:01:37 -0800 Received: from intmgw001.06.prn3.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:82::c) 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 2F2F716A189F; Tue, 24 Nov 2020 19:01:22 -0800 (PST) From: Roman Gushchin To: CC: , , , , , , , Subject: [PATCH bpf-next v8 15/34] bpf: memcg-based memory accounting for bpf local storage maps Date: Tue, 24 Nov 2020 19:01:00 -0800 Message-ID: <20201125030119.2864302-16-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=13 mlxlogscore=811 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 Account memory used by bpf local storage maps: per-socket, per-inode and per-task storages. Signed-off-by: Roman Gushchin --- kernel/bpf/bpf_local_storage.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/kernel/bpf/bpf_local_storage.c b/kernel/bpf/bpf_local_storag= e.c index 5d3a7af9ba9b..abd0ea385274 100644 --- a/kernel/bpf/bpf_local_storage.c +++ b/kernel/bpf/bpf_local_storage.c @@ -67,7 +67,9 @@ bpf_selem_alloc(struct bpf_local_storage_map *smap, voi= d *owner, if (charge_mem && mem_charge(smap, owner, smap->elem_size)) return NULL; =20 - selem =3D kzalloc(smap->elem_size, GFP_ATOMIC | __GFP_NOWARN); + selem =3D bpf_map_kmalloc_node(&smap->map, smap->elem_size, + GFP_ATOMIC | __GFP_NOWARN | __GFP_ZERO | + __GFP_ACCOUNT, NUMA_NO_NODE); if (selem) { if (value) memcpy(SDATA(selem)->data, value, smap->map.value_size); @@ -264,7 +266,9 @@ int bpf_local_storage_alloc(void *owner, if (err) return err; =20 - storage =3D kzalloc(sizeof(*storage), GFP_ATOMIC | __GFP_NOWARN); + storage =3D bpf_map_kmalloc_node(&smap->map, sizeof(*storage), + GFP_ATOMIC | __GFP_NOWARN | __GFP_ZERO | + __GFP_ACCOUNT, NUMA_NO_NODE); if (!storage) { err =3D -ENOMEM; goto uncharge; @@ -546,7 +550,7 @@ struct bpf_local_storage_map *bpf_local_storage_map_a= lloc(union bpf_attr *attr) u64 cost; int ret; =20 - smap =3D kzalloc(sizeof(*smap), GFP_USER | __GFP_NOWARN); + smap =3D kzalloc(sizeof(*smap), GFP_USER | __GFP_NOWARN | __GFP_ACCOUNT= ); if (!smap) return ERR_PTR(-ENOMEM); bpf_map_init_from_attr(&smap->map, attr); @@ -564,7 +568,7 @@ struct bpf_local_storage_map *bpf_local_storage_map_a= lloc(union bpf_attr *attr) } =20 smap->buckets =3D kvcalloc(sizeof(*smap->buckets), nbuckets, - GFP_USER | __GFP_NOWARN); + GFP_USER | __GFP_NOWARN | __GFP_ACCOUNT); if (!smap->buckets) { bpf_map_charge_finish(&smap->map.memory); kfree(smap); --=20 2.26.2