From patchwork Wed Aug 17 21:04:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexei Starovoitov X-Patchwork-Id: 12946472 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 449D3C25B08 for ; Wed, 17 Aug 2022 21:04:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B1B248D0005; Wed, 17 Aug 2022 17:04:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id ACB6C8D0003; Wed, 17 Aug 2022 17:04:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 96C518D0005; Wed, 17 Aug 2022 17:04:31 -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 89A348D0003 for ; Wed, 17 Aug 2022 17:04:31 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 59DAA1C70DD for ; Wed, 17 Aug 2022 21:04:31 +0000 (UTC) X-FDA: 79810313142.12.095CEF6 Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) by imf08.hostedemail.com (Postfix) with ESMTP id 0672A160046 for ; Wed, 17 Aug 2022 21:04:30 +0000 (UTC) Received: by mail-pj1-f41.google.com with SMTP id a8so13549095pjg.5 for ; Wed, 17 Aug 2022 14:04:30 -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; bh=EubkRMPFW1FZ5vCml4J7uu3XUib2x53PZwts9RYBHO8=; b=AAhwi0tpS4dbREsxaD/kUt5rCbyZ8yEGdUp76wDDzCpvtyVv5MYPF6RTs2SSFMmyQy w+H0pm9UCp9dLYVZqb3Lb3f5mucK+GbCfmbcnNPtQ90brrvmM1x/MqW8AN84Qwn4Z4ZC q1aHKvHw6LBUiRbNYkLeQ8AhXQ3hyjWWZ30chmXF3fbnYz+kSVsqRKzamRLsCjZtZJME rOD6aCHyhI2sPZTz2ajpcS7OMfmwoNJOaHCBTPplod7pedw/i5AHoSumZKffdu4ATflc Jo4ywTY//+WdDfcvsCfc0kiY+4JmqkMXNfeTi75wF2ZzH6btvE0zf+mV9UBZxvoEZ2Kd uqIA== 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; bh=EubkRMPFW1FZ5vCml4J7uu3XUib2x53PZwts9RYBHO8=; b=HlWjPLzylxkyVnUXKJjxFkVhK0DJDb1cjW3JAtHqt2r/ApQqnFiEma+/wgGMl2rysT 3VTBdvqOTZh9J7nqDagt2uKwqvfzQMdyofHzaPNqrxF5zOP6LTNX9IhPgHhkLqbFO2mw wmDEEiTTUJAC+BEu+DaaTPQBLvILzIprCTp1y8Cy5mQyQQ1XfcKcJf2oVBwZUFZWJXes Fua2WtYVOzaBHXMLJ1SoLmKbyfHkUCvfyvtgEVzlDPaM+d55KqWx2lIVBXoyQqn2MgEY PM06E9XV7GvESk5xWDvUKiWp8eOH3PPU6fgGieSRS6qRYtMr4ZaUMlVM2pxoSxE7Z9Z7 8SJg== X-Gm-Message-State: ACgBeo1Y3C/gvIMisbsetPcNBab3ijmlkPPHoex0glqLBGc+7MeKv/JM ubogpAdegqZ4MZ2ztswulOo= X-Google-Smtp-Source: AA6agR4KFIdGL5gh6mAYPvLrDjOYiB5IktxSi6KOoCq7JQA56D/JsgK3X6oe2k+xhcAVGSxzrq0/Bg== X-Received: by 2002:a17:90a:b703:b0:1dd:1e2f:97d7 with SMTP id l3-20020a17090ab70300b001dd1e2f97d7mr5471744pjr.62.1660770270036; Wed, 17 Aug 2022 14:04:30 -0700 (PDT) Received: from localhost.localdomain ([2620:10d:c090:500::1:ccd6]) by smtp.gmail.com with ESMTPSA id x28-20020aa7941c000000b0052d63fb109asm10912430pfo.20.2022.08.17.14.04.28 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 17 Aug 2022 14:04:29 -0700 (PDT) From: Alexei Starovoitov To: davem@davemloft.net Cc: daniel@iogearbox.net, andrii@kernel.org, tj@kernel.org, memxor@gmail.com, delyank@fb.com, linux-mm@kvack.org, bpf@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v2 bpf-next 02/12] bpf: Convert hash map to bpf_mem_alloc. Date: Wed, 17 Aug 2022 14:04:09 -0700 Message-Id: <20220817210419.95560-3-alexei.starovoitov@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220817210419.95560-1-alexei.starovoitov@gmail.com> References: <20220817210419.95560-1-alexei.starovoitov@gmail.com> MIME-Version: 1.0 ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=AAhwi0tp; spf=pass (imf08.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.216.41 as permitted sender) smtp.mailfrom=alexei.starovoitov@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660770270; a=rsa-sha256; cv=none; b=CGGW7lZUgKbyAVXQHd91g1JnVyZJciUelmvGCqOuZUdG0KmDf0Aok7n+a02TZCVfS0RPpB PVVWNmx4L+7Z4SBcqWe9BM7qcSugtZHkko3riAH76aAZLfuMDs/WdSDbz86Sd81UMLVgvg 8hFPlq3QQ5QytK0woIBWZZHBXX7rVAw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660770270; 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=EubkRMPFW1FZ5vCml4J7uu3XUib2x53PZwts9RYBHO8=; b=EFNzmZw29h3qFvjACsrOCDC/8zYb4PpAeB6wHQ8yjmSOGd6TOHLZKJCHeHN0i6Zwdp0XAz 3GUatHMUCyQoY9M+B2kUxPE6IF7v1adI9geLRO3ArhzMjyKiHFSMwtNa8Xr/WqOVxQopk1 +swogmaUoPGOoJh2GghhlwGRzD8qM1Q= X-Stat-Signature: etjx5uxpm9wdiqu1t4taw4yajrbnc1f4 Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=AAhwi0tp; spf=pass (imf08.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.216.41 as permitted sender) smtp.mailfrom=alexei.starovoitov@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 0672A160046 X-Rspam-User: X-HE-Tag: 1660770270-846778 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: From: Alexei Starovoitov Convert bpf hash map to use bpf memory allocator. Signed-off-by: Alexei Starovoitov --- kernel/bpf/hashtab.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/kernel/bpf/hashtab.c b/kernel/bpf/hashtab.c index 8392f7f8a8ac..6c0db430507a 100644 --- a/kernel/bpf/hashtab.c +++ b/kernel/bpf/hashtab.c @@ -14,6 +14,7 @@ #include "percpu_freelist.h" #include "bpf_lru_list.h" #include "map_in_map.h" +#include #define HTAB_CREATE_FLAG_MASK \ (BPF_F_NO_PREALLOC | BPF_F_NO_COMMON_LRU | BPF_F_NUMA_NODE | \ @@ -92,6 +93,7 @@ struct bucket { struct bpf_htab { struct bpf_map map; + struct bpf_mem_alloc ma; struct bucket *buckets; void *elems; union { @@ -567,6 +569,10 @@ static struct bpf_map *htab_map_alloc(union bpf_attr *attr) if (err) goto free_prealloc; } + } else { + err = bpf_mem_alloc_init(&htab->ma, htab->elem_size); + if (err) + goto free_map_locked; } return &htab->map; @@ -577,6 +583,7 @@ static struct bpf_map *htab_map_alloc(union bpf_attr *attr) for (i = 0; i < HASHTAB_MAP_LOCK_COUNT; i++) free_percpu(htab->map_locked[i]); bpf_map_area_free(htab->buckets); + bpf_mem_alloc_destroy(&htab->ma); free_htab: lockdep_unregister_key(&htab->lockdep_key); bpf_map_area_free(htab); @@ -853,7 +860,7 @@ static void htab_elem_free(struct bpf_htab *htab, struct htab_elem *l) if (htab->map.map_type == BPF_MAP_TYPE_PERCPU_HASH) free_percpu(htab_elem_get_ptr(l, htab->map.key_size)); check_and_free_fields(htab, l); - kfree(l); + bpf_mem_cache_free(&htab->ma, l); } static void htab_elem_free_rcu(struct rcu_head *head) @@ -977,9 +984,7 @@ static struct htab_elem *alloc_htab_elem(struct bpf_htab *htab, void *key, l_new = ERR_PTR(-E2BIG); goto dec_count; } - l_new = bpf_map_kmalloc_node(&htab->map, htab->elem_size, - GFP_NOWAIT | __GFP_NOWARN, - htab->map.numa_node); + l_new = bpf_mem_cache_alloc(&htab->ma); if (!l_new) { l_new = ERR_PTR(-ENOMEM); goto dec_count; @@ -998,7 +1003,7 @@ static struct htab_elem *alloc_htab_elem(struct bpf_htab *htab, void *key, pptr = bpf_map_alloc_percpu(&htab->map, size, 8, GFP_NOWAIT | __GFP_NOWARN); if (!pptr) { - kfree(l_new); + bpf_mem_cache_free(&htab->ma, l_new); l_new = ERR_PTR(-ENOMEM); goto dec_count; } @@ -1493,6 +1498,7 @@ static void htab_map_free(struct bpf_map *map) bpf_map_free_kptr_off_tab(map); free_percpu(htab->extra_elems); bpf_map_area_free(htab->buckets); + bpf_mem_alloc_destroy(&htab->ma); for (i = 0; i < HASHTAB_MAP_LOCK_COUNT; i++) free_percpu(htab->map_locked[i]); lockdep_unregister_key(&htab->lockdep_key);