Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp69263pxu; Tue, 24 Nov 2020 19:05:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJzI02b1Y0aQIk8HApLGy5SvtY7+ntrdaL7yzen+41grBMEnpTW270ttvrHzolS9mpBsGIO/ X-Received: by 2002:a05:6402:1352:: with SMTP id y18mr1527674edw.378.1606273531076; Tue, 24 Nov 2020 19:05:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606273531; cv=none; d=google.com; s=arc-20160816; b=PJQNTQTTfs8FsRXT6pFgyglIVamelfVqZKQih7OyWf4DNs7HqRFwrZGq5bu4TINrJl MoRhtVmjM9jVieuR68nyA4itnT/yXvfVputpEITaT4vydnZt3G+00sMuEB0CCkxzrpDB SFbegH2QPbcnVHtDdr+9rr0PeuntrNyuA+9dnbOARmR4Ux5Tki5OMix929tU6G4oSQtC djQvzgZlzzMiZNf2Whtrz4i6Yc0HaqKH5dvuImP+u1gjCAyVVI3vfBSqPfAGxOpZ4mH9 Jt57omhi3i9tRsY5hxRg2b4zgqF0ezSbVf7K+nTunLbekh8ypsFscn2Gp1qSo3CgTNsa 8t8A== 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=FTQq/5NXbfrVFGS1vrBKXa2fxufaWSoHB98RAMt+6e0=; b=z5+iCsg7n49nnF9dzTr7xzaFPdUaOwJRU5X94uGhoXpVjxHLdt+D0rphxKdSs1L7GU hLUpk8/WdCryJjCY2KvkhJkmyCcWvZRsJdEtsg90c5vZPpEkjLMEcV1RxAm/uhLeYQUN /bzAg0y3AFUtM8pETF5qx9cXUbJiie7B+haDqWOTbEaO/BMLh1HsszwAuP5YFiivWlqU r9OGPt6ZArlk8i4+PtUtnkrwIYs64wFnlDHWGe1jHCcry+uvbVnMJ19mzKmByyZSl4cY hoBFlg0L42PXoVTdlouvgezWShGQw/5KzOsTX3ANgwJa2E8J5pkdWEaHYFlLq/zVnNMM qlYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=qJK2Jpaa; 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 d25si421487eds.401.2020.11.24.19.05.08; Tue, 24 Nov 2020 19:05:31 -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=qJK2Jpaa; 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 S1727898AbgKYDBk (ORCPT + 99 others); Tue, 24 Nov 2020 22:01:40 -0500 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:28510 "EHLO mx0b-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727777AbgKYDBi (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 0AP2tOl7015257 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=FTQq/5NXbfrVFGS1vrBKXa2fxufaWSoHB98RAMt+6e0=; b=qJK2JpaaT1LELyMxr6aQbPw3I53hWI9Eg/GZ4YJpY1r4y8NSRgMEPvrL5kEBHqYV6j+K 4QoQzFgITuMYZf/Pj7ITSHPuOLbqTMIjV9hEHzdM3FVE5xAD0FjlPPZgirniSFoY7EYv B8GhBaCmU/idysuTgB3QQR0r5AxVrGB5IBw= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com with ESMTP id 34ykxgmjxx-1 (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 12E7216A1893; Tue, 24 Nov 2020 19:01:22 -0800 (PST) From: Roman Gushchin To: CC: , , , , , , , Subject: [PATCH bpf-next v8 09/34] bpf: refine memcg-based memory accounting for cpumap maps Date: Tue, 24 Nov 2020 19:00:54 -0800 Message-ID: <20201125030119.2864302-10-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=996 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 metadata and percpu data into the memcg-based memory accounting. Switch allocations made from an update path to new bpf_map_* allocation helpers to make the accounting work properly from an interrupt context. Signed-off-by: Roman Gushchin --- kernel/bpf/cpumap.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/kernel/bpf/cpumap.c b/kernel/bpf/cpumap.c index c61a23b564aa..e6b234d5e3a8 100644 --- a/kernel/bpf/cpumap.c +++ b/kernel/bpf/cpumap.c @@ -97,7 +97,7 @@ static struct bpf_map *cpu_map_alloc(union bpf_attr *at= tr) attr->map_flags & ~BPF_F_NUMA_NODE) return ERR_PTR(-EINVAL); =20 - cmap =3D kzalloc(sizeof(*cmap), GFP_USER); + cmap =3D kzalloc(sizeof(*cmap), GFP_USER | __GFP_ACCOUNT); if (!cmap) return ERR_PTR(-ENOMEM); =20 @@ -412,23 +412,24 @@ static int __cpu_map_load_bpf_program(struct bpf_cp= u_map_entry *rcpu, int fd) } =20 static struct bpf_cpu_map_entry * -__cpu_map_entry_alloc(struct bpf_cpumap_val *value, u32 cpu, int map_id) +__cpu_map_entry_alloc(struct bpf_map *map, struct bpf_cpumap_val *value, + u32 cpu) { int numa, err, i, fd =3D value->bpf_prog.fd; - gfp_t gfp =3D GFP_KERNEL | __GFP_NOWARN; + gfp_t gfp =3D __GFP_ZERO | GFP_KERNEL_ACCOUNT | __GFP_NOWARN; struct bpf_cpu_map_entry *rcpu; struct xdp_bulk_queue *bq; =20 /* Have map->numa_node, but choose node of redirect target CPU */ numa =3D cpu_to_node(cpu); =20 - rcpu =3D kzalloc_node(sizeof(*rcpu), gfp, numa); + rcpu =3D bpf_map_kmalloc_node(map, sizeof(*rcpu), gfp, numa); if (!rcpu) return NULL; =20 /* Alloc percpu bulkq */ - rcpu->bulkq =3D __alloc_percpu_gfp(sizeof(*rcpu->bulkq), - sizeof(void *), gfp); + rcpu->bulkq =3D bpf_map_alloc_percpu(map, sizeof(*rcpu->bulkq), + sizeof(void *), gfp); if (!rcpu->bulkq) goto free_rcu; =20 @@ -438,7 +439,8 @@ __cpu_map_entry_alloc(struct bpf_cpumap_val *value, u= 32 cpu, int map_id) } =20 /* Alloc queue */ - rcpu->queue =3D kzalloc_node(sizeof(*rcpu->queue), gfp, numa); + rcpu->queue =3D bpf_map_kmalloc_node(map, sizeof(*rcpu->queue), gfp, + numa); if (!rcpu->queue) goto free_bulkq; =20 @@ -447,7 +449,7 @@ __cpu_map_entry_alloc(struct bpf_cpumap_val *value, u= 32 cpu, int map_id) goto free_queue; =20 rcpu->cpu =3D cpu; - rcpu->map_id =3D map_id; + rcpu->map_id =3D map->id; rcpu->value.qsize =3D value->qsize; =20 if (fd > 0 && __cpu_map_load_bpf_program(rcpu, fd)) @@ -455,7 +457,8 @@ __cpu_map_entry_alloc(struct bpf_cpumap_val *value, u= 32 cpu, int map_id) =20 /* Setup kthread */ rcpu->kthread =3D kthread_create_on_node(cpu_map_kthread_run, rcpu, num= a, - "cpumap/%d/map:%d", cpu, map_id); + "cpumap/%d/map:%d", cpu, + map->id); if (IS_ERR(rcpu->kthread)) goto free_prog; =20 @@ -571,7 +574,7 @@ static int cpu_map_update_elem(struct bpf_map *map, v= oid *key, void *value, rcpu =3D NULL; /* Same as deleting */ } else { /* Updating qsize cause re-allocation of bpf_cpu_map_entry */ - rcpu =3D __cpu_map_entry_alloc(&cpumap_value, key_cpu, map->id); + rcpu =3D __cpu_map_entry_alloc(map, &cpumap_value, key_cpu); if (!rcpu) return -ENOMEM; rcpu->cmap =3D cmap; --=20 2.26.2