From patchwork Fri Feb 10 15:47:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13135960 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id B5377C636CD for ; Fri, 10 Feb 2023 15:48:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5327B6B0157; Fri, 10 Feb 2023 10:48:08 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4BBBC6B0159; Fri, 10 Feb 2023 10:48:08 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 335916B015A; Fri, 10 Feb 2023 10:48:08 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 15F286B0157 for ; Fri, 10 Feb 2023 10:48:08 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id C5F8016012C for ; Fri, 10 Feb 2023 15:48:07 +0000 (UTC) X-FDA: 80451813414.08.0D759C0 Received: from mail-pg1-f172.google.com (mail-pg1-f172.google.com [209.85.215.172]) by imf07.hostedemail.com (Postfix) with ESMTP id DE9D24000F for ; Fri, 10 Feb 2023 15:48:05 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=j+gxHQfB; spf=pass (imf07.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.215.172 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1676044085; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=3BzE4dHWY04pl7eRXElI/6nAwQrbbF33iW2gxKhD+d4=; b=7JIG2yKaPzdCpg2JkwLAkDQdm6BtAyV9BFg7jt9w31lnc2WlYBbkikyDoi+d1aYDffAIxO Zq2QXyB9fnMkdC7tgdCNPs28stwgaVoDLqLimMc5DCzgvqsAGxZV2MtwllGxERhlu2MqwF ZCIbZIh2neYkf0A9vg12Aken008UD7A= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=j+gxHQfB; spf=pass (imf07.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.215.172 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676044085; a=rsa-sha256; cv=none; b=NaTpI9kv4TSgRlmJ8mfqvUG4URmEMyBCpU5lDGxETB5IYaJ79hIwGMPAgxR6q9aEbYIcTt iDI5EhRjfpoGW70I//zfGmrebL17PC8HUWbThTf/b0Po1uOON8uZpEeoZgLk1M9/lhDiaR EaJxEb2n/+3/K2YBciLSxqbx5gJIf7I= Received: by mail-pg1-f172.google.com with SMTP id s8so3952884pgg.11 for ; Fri, 10 Feb 2023 07:48:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3BzE4dHWY04pl7eRXElI/6nAwQrbbF33iW2gxKhD+d4=; b=j+gxHQfBd7YR9DKjd+QCY3jhunM0qE502k1Q1kOFjTYec6K5h0eypt2BdeB7fPrask zyOtXXHaIaHjLTKHKppAk+Iy+jmgbTPFqltPNUJ8CKtzG4mVYDU3DV9d/VNVRXP8ypOf lK6HEtis6SdYcjcUu0PABvv/+/8NvYPV7hnLtRbdKElboXcv350wk00qsAXJKMK3Fy+g XXIjW6cnwBzFFcNKYrzsNYgo5j/TBfrHuKQOy5NrkBMgMceLhjn1k0+oWJKmb0Qoq8Z4 qJX68FnAXTZOjPtdUc3wYrlty43ptBoVJ6kLPOUWuI1ZILmy8c8lp1GSGuApFVrT5irw ISmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3BzE4dHWY04pl7eRXElI/6nAwQrbbF33iW2gxKhD+d4=; b=DfUa0ifjIDI00g+cAVwGbqtxbcWFYqabSrtd1hcxEo/a2rYxSTdjs51zzXK5pTyOHx 1i9yokd7Ok/rhs3RQlrOPKxnzo79DjG8QV4CaAOFTzjeX+9mbNqNRbV3dFOUHiQT5k05 ONYFRyh4yod5k5erc88xMx/YWFROKI8vJrX8un0fNUzYrSydZQ+ll2Kl8A6/tGijD2fW dpKpDnKYcdFzKS077axHUIegVqkyhVHKEus1KRyzRYPLbRFQOgkARIXfvDB2ZflZSgiu I7baymGJkOwLmdQ9lHeCHp9nLMLIKj45aT6tyOwU+5uJceLG+RZWWcnwtnfIyY2TggTg 1fHQ== X-Gm-Message-State: AO0yUKWAYi5JMKMQ5ODvpKTorVu/uNUX2ZMrwx1Bmi4Adiv1IIVua4ez qeS3EOOZaGp5NwMmRYUSal0= X-Google-Smtp-Source: AK7set8W5dANe0k+W3DZarFPjaiIci6Hk8I9WJxnZToYOnQzh2s0R3baoCshnGT3Pp6WNhUtjdz6zw== X-Received: by 2002:a62:6d87:0:b0:5a8:58b5:bfa7 with SMTP id i129-20020a626d87000000b005a858b5bfa7mr4558913pfc.5.1676044084887; Fri, 10 Feb 2023 07:48:04 -0800 (PST) Received: from vultr.guest ([2001:19f0:7001:2f6a:5400:4ff:fe4c:e050]) by smtp.gmail.com with ESMTPSA id t20-20020aa79394000000b005921c46cbadsm3520069pfe.99.2023.02.10.07.48.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Feb 2023 07:48:04 -0800 (PST) From: Yafang Shao To: tj@kernel.org, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, kafai@fb.com, songliubraving@fb.com, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, hannes@cmpxchg.org, mhocko@kernel.org, roman.gushchin@linux.dev, shakeelb@google.com, muchun.song@linux.dev, akpm@linux-foundation.org Cc: bpf@vger.kernel.org, cgroups@vger.kernel.org, linux-mm@kvack.org, Yafang Shao Subject: [PATCH bpf-next v2 4/4] bpf: allow to disable bpf prog memory accounting Date: Fri, 10 Feb 2023 15:47:34 +0000 Message-Id: <20230210154734.4416-5-laoar.shao@gmail.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230210154734.4416-1-laoar.shao@gmail.com> References: <20230210154734.4416-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: DE9D24000F X-Rspam-User: X-Stat-Signature: mn1dbonmfry3kbsykf61iuo1i44h7hje X-HE-Tag: 1676044085-353437 X-HE-Meta: U2FsdGVkX18Y16Yp2H9eLCUkSlbC+s5PSiObyd3Chlb551RVAi2wkwXwErjHxVSA2njtLzykv0x5LqdQQULRUrNg25WMYmqgNW4qFzj98loFesGa8aG550Mmbji1HzjP0o8jn40Tee2m+7agARppwN3TjRmc0SDUrqHz+Q86QjXvwOOTWXVEzT7twmqM6Up0z20OnkgnZnz7XGcxJirCoAhnjPrzdJwgWxN/3dbpiHJntNwsAr7+SZG6+WYNpFax4YxIKGfOUbyHmPpLSZb7LLe3NjCXrUbwE8+WkG7oqfMZjqS9/wl3CbEuJNf7s7Q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g74+4nz2eSALh0ARujntPqJd0yAIS44qOmu+i0hg2NcdP/ZSGZW+b4ebg8pIu6H/YiE2t8CP0YR0B6ARoz2B6rrH06GYp9wKX3chP0omkSTOFHdCCg7tdzEXcWcslYxrnnhp5fKbvOKj90y9lMYxtyTeGqVDPGclHGBbw+Fu+d9m0DXqNKG2xa51YsPimSo070dCoEwzX9UDdEMFs= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: We can simply disable the bpf prog memory accouting by not setting the GFP_ACCOUNT. Signed-off-by: Yafang Shao Acked-by: Johannes Weiner Acked-by: Roman Gushchin --- kernel/bpf/core.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c index 16da510..3390961 100644 --- a/kernel/bpf/core.c +++ b/kernel/bpf/core.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include @@ -87,7 +88,7 @@ void *bpf_internal_load_pointer_neg_helper(const struct sk_buff *skb, int k, uns struct bpf_prog *bpf_prog_alloc_no_stats(unsigned int size, gfp_t gfp_extra_flags) { - gfp_t gfp_flags = GFP_KERNEL_ACCOUNT | __GFP_ZERO | gfp_extra_flags; + gfp_t gfp_flags = bpf_memcg_flags(GFP_KERNEL | __GFP_ZERO | gfp_extra_flags); struct bpf_prog_aux *aux; struct bpf_prog *fp; @@ -96,12 +97,12 @@ struct bpf_prog *bpf_prog_alloc_no_stats(unsigned int size, gfp_t gfp_extra_flag if (fp == NULL) return NULL; - aux = kzalloc(sizeof(*aux), GFP_KERNEL_ACCOUNT | gfp_extra_flags); + aux = kzalloc(sizeof(*aux), bpf_memcg_flags(GFP_KERNEL | gfp_extra_flags)); if (aux == NULL) { vfree(fp); return NULL; } - fp->active = alloc_percpu_gfp(int, GFP_KERNEL_ACCOUNT | gfp_extra_flags); + fp->active = alloc_percpu_gfp(int, bpf_memcg_flags(GFP_KERNEL | gfp_extra_flags)); if (!fp->active) { vfree(fp); kfree(aux); @@ -126,7 +127,7 @@ struct bpf_prog *bpf_prog_alloc_no_stats(unsigned int size, gfp_t gfp_extra_flag struct bpf_prog *bpf_prog_alloc(unsigned int size, gfp_t gfp_extra_flags) { - gfp_t gfp_flags = GFP_KERNEL_ACCOUNT | __GFP_ZERO | gfp_extra_flags; + gfp_t gfp_flags = bpf_memcg_flags(GFP_KERNEL | __GFP_ZERO | gfp_extra_flags); struct bpf_prog *prog; int cpu; @@ -159,7 +160,7 @@ int bpf_prog_alloc_jited_linfo(struct bpf_prog *prog) prog->aux->jited_linfo = kvcalloc(prog->aux->nr_linfo, sizeof(*prog->aux->jited_linfo), - GFP_KERNEL_ACCOUNT | __GFP_NOWARN); + bpf_memcg_flags(GFP_KERNEL | __GFP_NOWARN)); if (!prog->aux->jited_linfo) return -ENOMEM; @@ -234,7 +235,7 @@ void bpf_prog_fill_jited_linfo(struct bpf_prog *prog, struct bpf_prog *bpf_prog_realloc(struct bpf_prog *fp_old, unsigned int size, gfp_t gfp_extra_flags) { - gfp_t gfp_flags = GFP_KERNEL_ACCOUNT | __GFP_ZERO | gfp_extra_flags; + gfp_t gfp_flags = bpf_memcg_flags(GFP_KERNEL | __GFP_ZERO | gfp_extra_flags); struct bpf_prog *fp; u32 pages;