From patchwork Fri Sep 2 02:29:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 12963562 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 12F5BC6FA82 for ; Fri, 2 Sep 2022 02:30:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 711A080099; Thu, 1 Sep 2022 22:30:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6BF608008D; Thu, 1 Sep 2022 22:30:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5607B80099; Thu, 1 Sep 2022 22:30:17 -0400 (EDT) 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 469008008D for ; Thu, 1 Sep 2022 22:30:17 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 15160C0987 for ; Fri, 2 Sep 2022 02:30:17 +0000 (UTC) X-FDA: 79865566074.06.6911B17 Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.170]) by imf23.hostedemail.com (Postfix) with ESMTP id BC48914005A for ; Fri, 2 Sep 2022 02:30:15 +0000 (UTC) Received: by mail-pg1-f170.google.com with SMTP id h188so737889pgc.12 for ; Thu, 01 Sep 2022 19:30:15 -0700 (PDT) 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; bh=Ia4obLCjxStcu+ICWYF8jUpLC+DBctMa/v2GHxl/gGU=; b=mGoieldFRW2ZsDHdEN4SGCykyr50uN6imE/RwcMpTgP+UImu3qxKPcjshQFMbcPCH0 uYa4R3RNELwqch3SIr0C74TTS/jL857Xy8RcS9/k21JMyxJJUf2YNaFFVlcjqcqfB+yw /Oe8BEVARTMeYoQ3hPeJvdKL3YSyxw/d0xpdKh1Zngx9QJIJ82ylFj4vVhnLCIQzPjcC DlDpvggQJ9jWbT5zHIXw4sJqpNqrnagdYX8K6LbXA8oO+uLEspmkDZS/yf3+UxDeUQi3 YNWr/PkVUiPiWmBkX+/KeXFXBAEVgHn2Ex8HMJ5uO9B1PmrOuU68MCDIg8ElFlywwvOx Ovkg== 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; bh=Ia4obLCjxStcu+ICWYF8jUpLC+DBctMa/v2GHxl/gGU=; b=XMSjhi7d7UlALtyPJjqRotLDxVxPxheHdZBn3T/aoyIMrH+t9aaWVvCD+FA2QTVkAg eLo4colLvmPnUmWtGQ5bry/AZya1SkKSvpj2QBaJll85e50ojISWFrvyqYac/fYtqJ0d trhNLMMjEiGgB1So8VQ8SWSeawW8QwWV8t7+p5cgd89nUWta7ej00TDZKCfffKvJ8RDU lRYExc2bH2Hx7rLAb5hY38y8u82QJ3MytOEr2JVhaTC3Fj/98lVyE5tKBMg3phAPEbkX gdS0eZayE2yRaR9jHS36O/jl1UgtIMnmt+ry3t5f4clndykxvKAYtFulw4BgaZpyPPLv 55Mg== X-Gm-Message-State: ACgBeo3xcoZkpoc+mwge2KBVi88jSzFYc4IACfQbJHHtn0lg6fLvnc6B 8+Uvw4YCLFULNbKIwWJ8TRg= X-Google-Smtp-Source: AA6agR5zZ7j+yw+Nu++fMWh4vrCtPC8eJ/5esneE7CzVfU+r/WXj/ixS9SxXhktPvUmgl1TQfxfquA== X-Received: by 2002:a63:a516:0:b0:42b:8bb2:7036 with SMTP id n22-20020a63a516000000b0042b8bb27036mr24798037pgf.389.1662085814905; Thu, 01 Sep 2022 19:30:14 -0700 (PDT) Received: from vultr.guest ([2001:19f0:6001:50ea:5400:4ff:fe1f:fbe2]) by smtp.gmail.com with ESMTPSA id j4-20020a170902da8400b0017297a6b39dsm269719plx.265.2022.09.01.19.30.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Sep 2022 19:30:14 -0700 (PDT) From: Yafang Shao To: 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, songmuchun@bytedance.com, akpm@linux-foundation.org, tj@kernel.org, lizefan.x@bytedance.com Cc: cgroups@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-mm@kvack.org, Yafang Shao Subject: [PATCH bpf-next v3 02/13] bpf: Introduce new helper bpf_map_put_memcg() Date: Fri, 2 Sep 2022 02:29:52 +0000 Message-Id: <20220902023003.47124-3-laoar.shao@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220902023003.47124-1-laoar.shao@gmail.com> References: <20220902023003.47124-1-laoar.shao@gmail.com> MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1662085815; 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=Ia4obLCjxStcu+ICWYF8jUpLC+DBctMa/v2GHxl/gGU=; b=tEu7pqaLGOF0Q0joRLTPOmXKS/VJkjHV5LXehtqlbb+FIQpZRiGBPSLzt3gmorRGY16IF/ UIbNuZvHZ9aF5gyCWL7V/XfZFTaae0g0ZR8W9vRuyAh3DVBxp0Hl3s8Tbs7Px/uuHAKCFI q0g6thq87Na+aBs9dr9cG8FgybGqJM0= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=mGoieldF; spf=pass (imf23.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.215.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=1662085815; a=rsa-sha256; cv=none; b=mPBugVKiiKWRHmFZXw1YlWaPvp4JQtb1wG9IxneROGpHylyKbxJpvVaMqSKydi9YoboqlE Ic5iVhCAUmO7mPV5uD1C10qbj5TU/KWVdgMH5SU+7lNgi7XKhrYVPyIHm1Q3Biw0eAqLp3 UAmg/qQNLvxRhdNrOmQKpmpLmzZVINk= X-Stat-Signature: iidwsrmz8e4h9apqae8dfy711xmcwy9f X-Rspamd-Queue-Id: BC48914005A X-Rspam-User: Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=mGoieldF; spf=pass (imf23.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.215.170 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspamd-Server: rspam01 X-HE-Tag: 1662085815-342362 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: Replace the open-coded mem_cgroup_put() with a new helper bpf_map_put_memcg(). That could make it more clear. Signed-off-by: Yafang Shao --- kernel/bpf/syscall.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index 4e9d462..7ce024c 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -441,6 +441,11 @@ static struct mem_cgroup *bpf_map_get_memcg(const struct bpf_map *map) return root_mem_cgroup; } +static void bpf_map_put_memcg(struct mem_cgroup *memcg) +{ + mem_cgroup_put(memcg); +} + void *bpf_map_kmalloc_node(const struct bpf_map *map, size_t size, gfp_t flags, int node) { @@ -451,7 +456,7 @@ void *bpf_map_kmalloc_node(const struct bpf_map *map, size_t size, gfp_t flags, old_memcg = set_active_memcg(memcg); ptr = kmalloc_node(size, flags | __GFP_ACCOUNT, node); set_active_memcg(old_memcg); - mem_cgroup_put(memcg); + bpf_map_put_memcg(memcg); return ptr; } @@ -465,7 +470,7 @@ void *bpf_map_kzalloc(const struct bpf_map *map, size_t size, gfp_t flags) old_memcg = set_active_memcg(memcg); ptr = kzalloc(size, flags | __GFP_ACCOUNT); set_active_memcg(old_memcg); - mem_cgroup_put(memcg); + bpf_map_put_memcg(memcg); return ptr; } @@ -480,7 +485,7 @@ void __percpu *bpf_map_alloc_percpu(const struct bpf_map *map, size_t size, old_memcg = set_active_memcg(memcg); ptr = __alloc_percpu_gfp(size, align, flags | __GFP_ACCOUNT); set_active_memcg(old_memcg); - mem_cgroup_put(memcg); + bpf_map_put_memcg(memcg); return ptr; }