From patchwork Wed Sep 21 16:59:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 12984023 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 E5B26ECAAD8 for ; Wed, 21 Sep 2022 17:00:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 824C16B0072; Wed, 21 Sep 2022 13:00:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7AD7D6B0073; Wed, 21 Sep 2022 13:00:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6261F940007; Wed, 21 Sep 2022 13:00:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 4ED326B0072 for ; Wed, 21 Sep 2022 13:00:12 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 2475980F7E for ; Wed, 21 Sep 2022 17:00:12 +0000 (UTC) X-FDA: 79936705464.13.B1240A4 Received: from mail-pg1-f169.google.com (mail-pg1-f169.google.com [209.85.215.169]) by imf23.hostedemail.com (Postfix) with ESMTP id ADCCE140028 for ; Wed, 21 Sep 2022 17:00:11 +0000 (UTC) Received: by mail-pg1-f169.google.com with SMTP id 78so6505537pgb.13 for ; Wed, 21 Sep 2022 10:00:11 -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=Uc034YbXLe4uSOJi2Giv7PoxUQGtDra34gKYHPXI91g=; b=YH4e0M93/zwgxts/4p2PWviNzWQigMOF4qZN4QnqPvGBdnj4aBKylgRGfgksaqFVt3 uXgL1W+nJvpKKKY4mhvcnJPNc05aAwCwBr6okJ/N55sz0zmm80oMEtJF2tqJ41VaRqLl OJmVR11MfPb0vTYFi1XU2wURqMcoAp/H6cLE6AF6ZBy41JeBoV15yrUyLR61fgysl6Wu WiIyzXyERFPVOgV1APZL4yirViwmqoPokXppwYFwLQu/EwhUO9GPtQYORtPwYHMNvKZA dfM4yOYAXYE0nSs1KEzaZckLVHVolUTeu3vpNCp9pwBHspL12xGT21zHdj46zM2RVdW4 znfw== 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=Uc034YbXLe4uSOJi2Giv7PoxUQGtDra34gKYHPXI91g=; b=nWTIXXcMQwEYknA+YoWkTwzl6BmZzv8tXMyentvAL5bBL7xmSmC/xkb0BzHDkydZOh 0PIOR8UvH9DTivv7mT1n908xrX8gz3/O5IoIeqUrgdfssARQCS/+JlxMRbNnXWLufqfZ DHE/oVVyOkhGEtEsX/MnCK+gD05yderChXS8thnXsUenu7OltIdL3iEAugkkf7GS93y9 tKOussCMznz9QrxI4OEbuqHcBFewa7JmwzBzvz7SOxYIcc8aWE9oJy+TUeiChetIMiKg OlfnQ/wCKZsMemlg6cOyxb8jmwIQcf4Z1d2c2cPOkyyqNt7ay0fxfiQwfSoTMKkz9o6L OYDg== X-Gm-Message-State: ACrzQf1HuHXWIv5rkGKLcLQZNv83c/G4XSZ05c/zLVgzhT8m4b9XiGT9 alvJs3mri9quoUIi4QtRLY0= X-Google-Smtp-Source: AMsMyM4uy0dKCw/P2UdR/ehiaNLiN9bDGO5ET+mXRA6NW2qjr04hx9bZzdjbgfNvCsKVHP2VALThGg== X-Received: by 2002:a63:4705:0:b0:43b:fc70:2464 with SMTP id u5-20020a634705000000b0043bfc702464mr1534798pga.540.1663779610654; Wed, 21 Sep 2022 10:00:10 -0700 (PDT) Received: from vultr.guest ([2001:19f0:6001:488e:5400:4ff:fe25:7db8]) by smtp.gmail.com with ESMTPSA id mp4-20020a17090b190400b002006f8e7688sm2102495pjb.32.2022.09.21.10.00.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Sep 2022 10:00:09 -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: [RFC PATCH bpf-next 01/10] bpf: Introduce new helper bpf_map_put_memcg() Date: Wed, 21 Sep 2022 16:59:53 +0000 Message-Id: <20220921170002.29557-2-laoar.shao@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220921170002.29557-1-laoar.shao@gmail.com> References: <20220921170002.29557-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=1663779611; 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=Uc034YbXLe4uSOJi2Giv7PoxUQGtDra34gKYHPXI91g=; b=2M2egDgQJ0re/6J2V09bx5pXuNa0XV1ohbsVLcflvrDI4y4kLDwaIvqY79PIcknGhlr73A qBOrDsNSKl1911oV4rVBFyx4E43Rc0V2KCfGBSvRJ4ZPDzVQUONbcOBemZHQCEn4lK3HVV QdJIrV2XivyCwzrHGigE5DRYIgYjjqk= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=YH4e0M93; spf=pass (imf23.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.215.169 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=1663779611; a=rsa-sha256; cv=none; b=bn9iqErC2deem6VeHR4IpjIVDw5J1BEP8qVEJo4qhCuiHd0MRm2z94FDS+3oPKZ+OYUPqC TvrDlAUkBSpd1OAfX2TJoStTWz2/1vs1feEWXI2CsH7GRmgu5ZH1v7ukCI34/FMk/zYcJi pCKn4tfiFMcESn8UXtwU3dJ/hg4B4bI= Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=YH4e0M93; spf=pass (imf23.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.215.169 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Stat-Signature: k8hmrg5jk6nzaeo969npn1kpgfok7i7h X-Rspamd-Queue-Id: ADCCE140028 X-Rspam-User: X-Rspamd-Server: rspam12 X-HE-Tag: 1663779611-297337 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 dab156f..70d5f70 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; }