Received: by 2002:a17:90b:8d0:0:0:0:0 with SMTP id ds16csp5083227pjb; Mon, 27 Jul 2020 12:30:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy+r94baxKuahNFXoQDwpmQXqnlCVsDdljMZFoC1kpGKkT2LSVoxebQkVgoVgR0IIMFzy1R X-Received: by 2002:a17:906:2e06:: with SMTP id n6mr22161954eji.34.1595878234908; Mon, 27 Jul 2020 12:30:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595878234; cv=none; d=google.com; s=arc-20160816; b=YWVxfEGoArH9qsc8W6OZQJsWX+A/AkFh5yh0KcpNf55737NUGcWdBZjKUiuInjgn5B pmnsmVF5DQJyU8Q7NM8VBViFLRN/PGsHSwn6b8trd7iDBy+XfXTupr0n1fPenVL0oqcA JwFTuLZHBrc0RW14mXLMbYLtDxTEb2oji/8YAhfdce1lvMiKSU7+qsb+Ic7b0xZdkeej NeOLUUFvYn0O+nScqYEQjuUcFtIhwNoEbtO8cUjNSab2TuEeyWa9FRYCbI1AOd3FI36x RbjEsqiSwXQjbKbbgxHA0OwPaTmyb/sbZeTz3ZQp7U47tFbcgA1nMynqPf9XprNpQuG4 Jydw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:smtp-origin-cluster :cc:to:smtp-origin-hostname:from:smtp-origin-hostprefix :dkim-signature; bh=6grKGngZ2EGO1ZEUu9sZ929yloT2DLe+IOdXXOL70cE=; b=fyLh+slC/Yb691xAkn9VjMt/4WfIFDQim/LKQPchpkJUOCsg4Wlt97XS76l1P6PuD/ FsGo+1bUH/pwk+Uu2BkvmX5MaQrTtlpGfNB0yYsLCcpkQW8LRWnoRIcw3xrYQPz2q6+W IkGK0EJ0Fh1b+aRVPJynkUlyCYjvWZjxhynzRDgIxq+2eNg7csTyqY9bLzcGW2fDToz6 sqEtvdXl5e5+ozyYsYUMo4XzKhEthKTNL2S1RuKh5HDZRMaEeB6sYEp0RyptKuzygBji 5C25Ie2qt3+5mBvpccdXVOVi1nL2OgLIB0aHdDf5Zb/5YPe8PbV0wCkyCf/TtnEcENeK APlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=H6B6Il2n; 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 o29si1926905edz.62.2020.07.27.12.30.12; Mon, 27 Jul 2020 12:30:34 -0700 (PDT) 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=H6B6Il2n; 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 S1731430AbgG0Ssg (ORCPT + 99 others); Mon, 27 Jul 2020 14:48:36 -0400 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:36430 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731115AbgG0SpS (ORCPT ); Mon, 27 Jul 2020 14:45:18 -0400 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 06RIf4tK020156 for ; Mon, 27 Jul 2020 11:45:17 -0700 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=6grKGngZ2EGO1ZEUu9sZ929yloT2DLe+IOdXXOL70cE=; b=H6B6Il2ndRd3KIcNwIJSY77fTjsFAiGEUyYZ1ou+t9gsr+VCEdp87/7uuFDddR66YiBh x1JhGCPVRKdUYIUYqdE/8R7qoY/LovEqhUS1o2mrxrSzFbz1oTp3UFBAzracnbqS/8+A JqwUr64q5LahzDfAFRsj2gcU2FOnkGNglyk= Received: from mail.thefacebook.com ([163.114.132.120]) by mx0a-00082601.pphosted.com with ESMTP id 32h4k25ux6-9 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Mon, 27 Jul 2020 11:45:17 -0700 Received: from intmgw002.06.prn3.facebook.com (2620:10d:c085:208::11) by mail.thefacebook.com (2620:10d:c085:21d::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Mon, 27 Jul 2020 11:45:14 -0700 Received: by devvm1096.prn0.facebook.com (Postfix, from userid 111017) id AD3E81DAFE7F; Mon, 27 Jul 2020 11:45:10 -0700 (PDT) Smtp-Origin-Hostprefix: devvm From: Roman Gushchin Smtp-Origin-Hostname: devvm1096.prn0.facebook.com To: CC: , Alexei Starovoitov , Daniel Borkmann , , , Roman Gushchin Smtp-Origin-Cluster: prn0c01 Subject: [PATCH bpf-next v2 07/35] bpf: refine memcg-based memory accounting for hashtab maps Date: Mon, 27 Jul 2020 11:44:38 -0700 Message-ID: <20200727184506.2279656-8-guro@fb.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200727184506.2279656-1-guro@fb.com> References: <20200727184506.2279656-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.235,18.0.687 definitions=2020-07-27_13:2020-07-27,2020-07-27 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 lowpriorityscore=0 clxscore=1015 adultscore=0 malwarescore=0 bulkscore=0 phishscore=0 priorityscore=1501 mlxlogscore=858 mlxscore=0 spamscore=0 suspectscore=38 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007270126 X-FB-Internal: deliver Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Include percpu objects and the size of map metadata into the accounting. Signed-off-by: Roman Gushchin --- kernel/bpf/hashtab.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/kernel/bpf/hashtab.c b/kernel/bpf/hashtab.c index 024276787055..9d0432170812 100644 --- a/kernel/bpf/hashtab.c +++ b/kernel/bpf/hashtab.c @@ -263,10 +263,11 @@ static int prealloc_init(struct bpf_htab *htab) goto skip_percpu_elems; =20 for (i =3D 0; i < num_entries; i++) { + const gfp_t gfp =3D GFP_USER | __GFP_NOWARN | __GFP_ACCOUNT; u32 size =3D round_up(htab->map.value_size, 8); void __percpu *pptr; =20 - pptr =3D __alloc_percpu_gfp(size, 8, GFP_USER | __GFP_NOWARN); + pptr =3D __alloc_percpu_gfp(size, 8, gfp); if (!pptr) goto free_elems; htab_elem_set_ptr(get_htab_elem(htab, i), htab->map.key_size, @@ -321,7 +322,7 @@ static int alloc_extra_elems(struct bpf_htab *htab) int cpu; =20 pptr =3D __alloc_percpu_gfp(sizeof(struct htab_elem *), 8, - GFP_USER | __GFP_NOWARN); + GFP_USER | __GFP_NOWARN | __GFP_ACCOUNT); if (!pptr) return -ENOMEM; =20 @@ -424,7 +425,7 @@ static struct bpf_map *htab_map_alloc(union bpf_attr = *attr) u64 cost; int err; =20 - htab =3D kzalloc(sizeof(*htab), GFP_USER); + htab =3D kzalloc(sizeof(*htab), GFP_USER | __GFP_ACCOUNT); if (!htab) return ERR_PTR(-ENOMEM); =20 @@ -827,6 +828,7 @@ static struct htab_elem *alloc_htab_elem(struct bpf_h= tab *htab, void *key, bool percpu, bool onallcpus, struct htab_elem *old_elem) { + const gfp_t gfp =3D GFP_ATOMIC | __GFP_NOWARN | __GFP_ACCOUNT; u32 size =3D htab->map.value_size; bool prealloc =3D htab_is_prealloc(htab); struct htab_elem *l_new, **pl_new; @@ -859,8 +861,7 @@ static struct htab_elem *alloc_htab_elem(struct bpf_h= tab *htab, void *key, l_new =3D ERR_PTR(-E2BIG); goto dec_count; } - l_new =3D kmalloc_node(htab->elem_size, GFP_ATOMIC | __GFP_NOWARN, - htab->map.numa_node); + l_new =3D kmalloc_node(htab->elem_size, gfp, htab->map.numa_node); if (!l_new) { l_new =3D ERR_PTR(-ENOMEM); goto dec_count; @@ -876,8 +877,7 @@ static struct htab_elem *alloc_htab_elem(struct bpf_h= tab *htab, void *key, pptr =3D htab_elem_get_ptr(l_new, key_size); } else { /* alloc_percpu zero-fills */ - pptr =3D __alloc_percpu_gfp(size, 8, - GFP_ATOMIC | __GFP_NOWARN); + pptr =3D __alloc_percpu_gfp(size, 8, gfp); if (!pptr) { kfree(l_new); l_new =3D ERR_PTR(-ENOMEM); --=20 2.26.2