From patchwork Sun Feb 5 06:58:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13128982 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 A026DC636CC for ; Sun, 5 Feb 2023 06:58:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4586D6B007B; Sun, 5 Feb 2023 01:58:50 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4074F6B007D; Sun, 5 Feb 2023 01:58:50 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2A82F6B007E; Sun, 5 Feb 2023 01:58:50 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 1A3116B007B for ; Sun, 5 Feb 2023 01:58:50 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id D73E7AAA95 for ; Sun, 5 Feb 2023 06:58:48 +0000 (UTC) X-FDA: 80432335536.13.785A7F0 Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) by imf30.hostedemail.com (Postfix) with ESMTP id 1E4128000A for ; Sun, 5 Feb 2023 06:58:46 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=a57J4S2w; spf=pass (imf30.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.210.170 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=1675580327; 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=UUYnykaARkkOFageVVuRXJFo/+sLEm/iUIcvMP09NQo=; b=LiIg1HHloKCtjw+5A3RkVEA58NL/lRfFsnkH2O/sL5ere1SLAoCk0A9KVEggRFtd27/4fw E8AqDxGVrmcfqu+L0yfemyBnD/x+wb5eHU1IAjCtgV29/CcJ/5Hliw7291raBLyKFe2p7Y F96Vh4WiocFgaSDLbzryJaxnmXjWC/c= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=a57J4S2w; spf=pass (imf30.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.210.170 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=1675580327; a=rsa-sha256; cv=none; b=FGEgYNazDZUHu1pka+mxSKyxh0ef+mG82Zsv1mOSKPa0O/6K+Nrl5ZlhDfWbecHeEtZ+Ae 5arUyUXWMUeptiEpCoB5yvAHp8j1ys5HsNSUDLbsuO9oOOfUn6wi7Nf0sANTB35dYY0R4z sScjFMo2hwHSDrTJsiv77ogC11Vh6tQ= Received: by mail-pf1-f170.google.com with SMTP id g9so6379120pfo.5 for ; Sat, 04 Feb 2023 22:58:46 -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=UUYnykaARkkOFageVVuRXJFo/+sLEm/iUIcvMP09NQo=; b=a57J4S2w9eyKDMZ9OBUJ6kf6vR1VHJuYUOYq6cGgNDezvgehxMQxiQLzN51fOnil+5 DlIcYvlG4h0xQaPY+WdBD9SdZIQsg67KK4axSoellK3vUZSqXtJocopfFVARTJnLQbk4 xGzbd3RY72M2M5MSGcfKyymLNNeBoSbRbgxq8BZo9nqCyaZDW83JoZ98YMhPHNIIUdQH AplmWxymxSsBbTx3vRXRWPAve2uLvQTLdcAEMGTrQeiRQJ+2zB1nbaw+WBuBwBQaXiuW T8HRsVyFsv8OzuyK0mXraJ8183a5zu/RW4pS7pQ7r/omuWkXLEv8TbXEHyl5OEJmZyfP HLsQ== 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=UUYnykaARkkOFageVVuRXJFo/+sLEm/iUIcvMP09NQo=; b=WHt4pcVwz3WqMjLDbRLT4aaTyH4z36dAsTdnMZcDgHvmYXBhUUhC7nyX1H/D0+9nE5 J2yPq47+tW7k57BudUhxiFraEJW/zlx4al0AtG3VsT4rMpuUjcJ/5ILwSJbiaWrt8OPg BLF5BTBNg5WlwDI0KFdq6lRHuYEkgvARdvXO+SEkQi0eSOtPFGjZjveZKxDcZ3f6e3Is MqIUFZqKS7Cf43alZVyqeIqxzFWsMXXs6eLLWwExAZfv1NI3YCI1+qlWp2eerm3a2yq8 /AhU2FWLS2mwrnyPNLSnVU51H3EHt8eAgcYxL4HUAoOrv1Q8AYoIV2y2JHM8F5uWZ+Ru X4Ag== X-Gm-Message-State: AO0yUKWSZ67xfXyjG2hmgv834agdvOd/Vo5wBYwDYbgYUJH7tm+OCFAm 4WvYCiHmRc2yiiDEV8T/s78= X-Google-Smtp-Source: AK7set/w6dPubyS97p4WKEL9Dv1iFkX3k0KUGaY6uG6A7WSUm6tHBNwMv7hcZLwgEx+QbevpeIc8Rg== X-Received: by 2002:a05:6a00:1a47:b0:593:b309:aa55 with SMTP id h7-20020a056a001a4700b00593b309aa55mr16799764pfv.28.1675580326085; Sat, 04 Feb 2023 22:58:46 -0800 (PST) Received: from vultr.guest ([2401:c080:1c02:6a5:5400:4ff:fe4b:6fe6]) by smtp.gmail.com with ESMTPSA id 144-20020a621596000000b00593ce7ebbaasm4596114pfv.184.2023.02.04.22.58.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Feb 2023 22:58:45 -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 5/5] bpf: allow to disable bpf prog memory accounting Date: Sun, 5 Feb 2023 06:58:05 +0000 Message-Id: <20230205065805.19598-6-laoar.shao@gmail.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230205065805.19598-1-laoar.shao@gmail.com> References: <20230205065805.19598-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: h4b4dxw7j63du85k3xzbzgznzj9rwdny X-Rspamd-Queue-Id: 1E4128000A X-HE-Tag: 1675580326-71659 X-HE-Meta: U2FsdGVkX1+R1SsR4+PE82LK79JOf7E6rAHuik3nPcqt9f+r493jdhRSPv0s9drFwaok8ZQqXSp1H2/VCBNGnywO0JYvabbKkTxVd6XLiqx7MwOJcasfqtOgzgdsSU73FQQy0Oh7oHk6QgAqaWdz7brBt6gIdqscgaj3+MjZfx0MlTx3XM0QUoveVuOhaEJ9XKSHZiUuTaIBjupkNz3MEi+1FdIi66qiSXYpbztZ/ydu0vkQhR2V8MQb63ajak+OGYIY6WqC3Tc0p4p7xZyLCL/GqxkpxswJLbnyoCrXEcs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2pr1y6bmzrmdCSxpeZJQL6CpAKhMfWzt0CKDk+sV9Oa1vLW6Dbk2ohtyjTPFqJHcOe4LaflKQrGGeUYzrwOHYiyPKdxOFylkA2KIEK9p0mOLSstVCdSkR0mh3nYVW1xJZ6C1zdbeat5ELXM3uvFCfjNoaB6wWr5er2TUF9ogj8QkcQqV5hc++Wxjfo1xwwLWqKn4Ms3lo71mQ== 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 --- 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;