From patchwork Fri Sep 2 21:10:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexei Starovoitov X-Patchwork-Id: 12964681 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 4F30DECAAA1 for ; Fri, 2 Sep 2022 21:11:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E807280130; Fri, 2 Sep 2022 17:11:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E0A0180120; Fri, 2 Sep 2022 17:11:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C5C4880130; Fri, 2 Sep 2022 17:11:14 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id B026880120 for ; Fri, 2 Sep 2022 17:11:14 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 8C0F1C02CA for ; Fri, 2 Sep 2022 21:11:14 +0000 (UTC) X-FDA: 79868390868.20.B452DFE Received: from mail-pg1-f173.google.com (mail-pg1-f173.google.com [209.85.215.173]) by imf04.hostedemail.com (Postfix) with ESMTP id 35DB84004E for ; Fri, 2 Sep 2022 21:11:14 +0000 (UTC) Received: by mail-pg1-f173.google.com with SMTP id r69so2980677pgr.2 for ; Fri, 02 Sep 2022 14:11:13 -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=fN5UTsD9/UNy4JwRwsLxsSRdDj8AsSF1mCpGXo1LAXw=; b=MzhJb7DeGqrdXTr68P9EuoEFICUOC+F3zkwB7lo4l3TqEH95m7Ve+aXypNk19AOh65 yZM0CMp01BZtiR4vXFlq4EEevvOJ3oQ9RBArId6AYe6xSMGcYqVJW6tU+OGn2222jYR/ 7tfsLlZVy8VP0QZkj1BTy3Sews6BaMbsOzdTLZ1FUyIqthRuRTw4GdnmISsz6aKRflqZ 8oRAON32QbXfkaVS4wbQw4MQhUGUB542Anpw2ESQv7RCQ4sOKlNmPWQN+eXBTMhO31dl HSWYQ4OlnSIJYxljp4c7UNYtBJZFh2nBrhKBmuRUNDiKMpYw3z5ddbBdbazRAew0lxL/ BVhQ== 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=fN5UTsD9/UNy4JwRwsLxsSRdDj8AsSF1mCpGXo1LAXw=; b=OwcLR8eSIuBenF/KfAohYwxvE3sGJFV8/0e7MQP9lzwcwEZFnwA1Y1S0m5ZPLDWUbh h+9YvO8Te/ZBNPsNo1lBsBtCslOkAweULKwXLhTimbHy9pfqanMXi0g/qT3qFgfZNzg0 m2f6vhqG8QP1LLkYqG+segWEolIl7Guc0vMAo/GjOP8vXL2SSkzXH0ZNXUt9hgY/hYOr MUMhSQ65tiTHntfnrBp2mQZWMsI8yhkMY4fLWtkb0iC7AETNMQf9qEbyQDvZ6aUJxhCM +fTdcjSYqgz1pnp4A+PnpRhTA/6cAiv6OG8+ZamrF8mZ9uqO9jtWhGSywHyuKHGUxtAD hmlw== X-Gm-Message-State: ACgBeo1cGaf8gW7Vj0bf23G7bzaPi2JbX0WnFI3SU06yV8UCawxP7qjD ZPg78rD1b2FD2aPi4yl3BDA= X-Google-Smtp-Source: AA6agR4Aia0MYvf8H9EHnMwCgvO736xTHM4ggch+Tusz/FffOHXj94vbODIdwLjAsXKUMbxG2UXe9Q== X-Received: by 2002:a63:564f:0:b0:425:f2cd:d0ce with SMTP id g15-20020a63564f000000b00425f2cdd0cemr31670185pgm.143.1662153073177; Fri, 02 Sep 2022 14:11:13 -0700 (PDT) Received: from localhost.localdomain ([2620:10d:c090:500::c978]) by smtp.gmail.com with ESMTPSA id z8-20020aa79f88000000b0052e57ed8cdasm2321374pfr.55.2022.09.02.14.11.11 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 02 Sep 2022 14:11:12 -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 v6 bpf-next 03/16] selftests/bpf: Improve test coverage of test_maps Date: Fri, 2 Sep 2022 14:10:45 -0700 Message-Id: <20220902211058.60789-4-alexei.starovoitov@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220902211058.60789-1-alexei.starovoitov@gmail.com> References: <20220902211058.60789-1-alexei.starovoitov@gmail.com> MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1662153074; 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=fN5UTsD9/UNy4JwRwsLxsSRdDj8AsSF1mCpGXo1LAXw=; b=YxsEY+TJXJhyFYaytwhxmonrWL+BpK+AbWBzSe99q3oUGezNci0BZZ27B8zUqof41yru3M a+Uthm9OuA7OuA0903XZHZQKRRpxPauhcKH06NqBCMRqiXhHJaegZ7SHOw8ZKPaG/GKOGa zqj1A1mKFTAofy8fm2mIIXm/m6Vg+Gs= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=MzhJb7De; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf04.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.215.173 as permitted sender) smtp.mailfrom=alexei.starovoitov@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1662153074; a=rsa-sha256; cv=none; b=YLZhYu6r8iF4xEBg/at5g02DCgYMxTGYTcPA/SI6OEgw38pLeVXoY/9F2TlaBOGgOoJNri 11a9MFuZA65j5rhwKg4ZK3Ey6W8xcgy3LfggQVkxCCmPPWI9LWj4EcB4Lzh2rGDjuApcl+ EsFGoJBKAE5zxFrF2B6pcEnXwl7tAcI= X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 35DB84004E Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=MzhJb7De; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf04.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.215.173 as permitted sender) smtp.mailfrom=alexei.starovoitov@gmail.com X-Rspam-User: X-Stat-Signature: ufkamdd78q4518xshcb8yoahk8z7scpy X-HE-Tag: 1662153074-27152 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 Make test_maps more stressful with more parallelism in update/delete/lookup/walk including different value sizes. Acked-by: Kumar Kartikeya Dwivedi Acked-by: Andrii Nakryiko Signed-off-by: Alexei Starovoitov --- tools/testing/selftests/bpf/test_maps.c | 38 ++++++++++++++++--------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/tools/testing/selftests/bpf/test_maps.c b/tools/testing/selftests/bpf/test_maps.c index c49f2056e14f..00b9cc305e58 100644 --- a/tools/testing/selftests/bpf/test_maps.c +++ b/tools/testing/selftests/bpf/test_maps.c @@ -264,10 +264,11 @@ static void test_hashmap_percpu(unsigned int task, void *data) close(fd); } +#define VALUE_SIZE 3 static int helper_fill_hashmap(int max_entries) { int i, fd, ret; - long long key, value; + long long key, value[VALUE_SIZE] = {}; fd = bpf_map_create(BPF_MAP_TYPE_HASH, NULL, sizeof(key), sizeof(value), max_entries, &map_opts); @@ -276,8 +277,8 @@ static int helper_fill_hashmap(int max_entries) "err: %s, flags: 0x%x\n", strerror(errno), map_opts.map_flags); for (i = 0; i < max_entries; i++) { - key = i; value = key; - ret = bpf_map_update_elem(fd, &key, &value, BPF_NOEXIST); + key = i; value[0] = key; + ret = bpf_map_update_elem(fd, &key, value, BPF_NOEXIST); CHECK(ret != 0, "can't update hashmap", "err: %s\n", strerror(ret)); @@ -288,8 +289,8 @@ static int helper_fill_hashmap(int max_entries) static void test_hashmap_walk(unsigned int task, void *data) { - int fd, i, max_entries = 1000; - long long key, value, next_key; + int fd, i, max_entries = 10000; + long long key, value[VALUE_SIZE], next_key; bool next_key_valid = true; fd = helper_fill_hashmap(max_entries); @@ -297,7 +298,7 @@ static void test_hashmap_walk(unsigned int task, void *data) for (i = 0; bpf_map_get_next_key(fd, !i ? NULL : &key, &next_key) == 0; i++) { key = next_key; - assert(bpf_map_lookup_elem(fd, &key, &value) == 0); + assert(bpf_map_lookup_elem(fd, &key, value) == 0); } assert(i == max_entries); @@ -305,9 +306,9 @@ static void test_hashmap_walk(unsigned int task, void *data) assert(bpf_map_get_next_key(fd, NULL, &key) == 0); for (i = 0; next_key_valid; i++) { next_key_valid = bpf_map_get_next_key(fd, &key, &next_key) == 0; - assert(bpf_map_lookup_elem(fd, &key, &value) == 0); - value++; - assert(bpf_map_update_elem(fd, &key, &value, BPF_EXIST) == 0); + assert(bpf_map_lookup_elem(fd, &key, value) == 0); + value[0]++; + assert(bpf_map_update_elem(fd, &key, value, BPF_EXIST) == 0); key = next_key; } @@ -316,8 +317,8 @@ static void test_hashmap_walk(unsigned int task, void *data) for (i = 0; bpf_map_get_next_key(fd, !i ? NULL : &key, &next_key) == 0; i++) { key = next_key; - assert(bpf_map_lookup_elem(fd, &key, &value) == 0); - assert(value - 1 == key); + assert(bpf_map_lookup_elem(fd, &key, value) == 0); + assert(value[0] - 1 == key); } assert(i == max_entries); @@ -1371,16 +1372,16 @@ static void __run_parallel(unsigned int tasks, static void test_map_stress(void) { + run_parallel(100, test_hashmap_walk, NULL); run_parallel(100, test_hashmap, NULL); run_parallel(100, test_hashmap_percpu, NULL); run_parallel(100, test_hashmap_sizes, NULL); - run_parallel(100, test_hashmap_walk, NULL); run_parallel(100, test_arraymap, NULL); run_parallel(100, test_arraymap_percpu, NULL); } -#define TASKS 1024 +#define TASKS 100 #define DO_UPDATE 1 #define DO_DELETE 0 @@ -1432,6 +1433,8 @@ static void test_update_delete(unsigned int fn, void *data) int fd = ((int *)data)[0]; int i, key, value, err; + if (fn & 1) + test_hashmap_walk(fn, NULL); for (i = fn; i < MAP_SIZE; i += TASKS) { key = value = i; @@ -1455,7 +1458,7 @@ static void test_update_delete(unsigned int fn, void *data) static void test_map_parallel(void) { - int i, fd, key = 0, value = 0; + int i, fd, key = 0, value = 0, j = 0; int data[2]; fd = bpf_map_create(BPF_MAP_TYPE_HASH, NULL, sizeof(key), sizeof(value), @@ -1466,6 +1469,7 @@ static void test_map_parallel(void) exit(1); } +again: /* Use the same fd in children to add elements to this map: * child_0 adds key=0, key=1024, key=2048, ... * child_1 adds key=1, key=1025, key=2049, ... @@ -1502,6 +1506,12 @@ static void test_map_parallel(void) key = -1; assert(bpf_map_get_next_key(fd, NULL, &key) < 0 && errno == ENOENT); assert(bpf_map_get_next_key(fd, &key, &key) < 0 && errno == ENOENT); + + key = 0; + bpf_map_delete_elem(fd, &key); + if (j++ < 5) + goto again; + close(fd); } static void test_map_rdonly(void)