Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp1132690ybi; Wed, 3 Jul 2019 10:03:03 -0700 (PDT) X-Google-Smtp-Source: APXvYqwLlghcswKaBpMQEuBF9Pmq93exTxdO9BmoVg/Y/eM3rDQDhpFtz/PifRae7pW0UpHeRGXF X-Received: by 2002:a17:902:28c9:: with SMTP id f67mr44078217plb.19.1562173383874; Wed, 03 Jul 2019 10:03:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562173383; cv=none; d=google.com; s=arc-20160816; b=sMAK6W2ocGmf0maQRRiGa4pBzZkB78fkRUMoY/dLhhMLpAmMNVqjh8bcyu2sMLmKJr +oMNMZXDLaN5kKtAgthGLyJSqtnxHKc/KCqwicNvVtUO6z9MB/wXJDZKwnT+xLYbSZ6R +XpxImJ3R3lMxkB0crrwTvUCXmHXEjmqBMkpIB1cAB9wyBbTOBlROKiebbNHriBHVp2w d0PiXycqdzJg7DFKb1Puf1j3gJIYM3vcp+o2xniS5v8lE3JXn0Pnby0b6QxoRxCXIE2n 2SMypHrh/Cq8g7tA4WxgMRnPa+9ro0bhQ+cST8P8E1QJFNWFbWsyNkSqyGFuFU+NuTwH byaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:mime-version :message-id:date:dkim-signature; bh=PtzfnXHwir5t+OK6oGGR3xyRGAh0lHKhLg6y74Z7SLI=; b=ZMBLui6yXfzAfUApq6pz6JztAQW4zQeDVRU0unYTEmmKt5y1tBSV4DKvSkSE+6cIu7 18lH4yxb7bbQOCL9xgsc3zef27k9o38mO0bizdvsmVHh38F9I52kl3KfjqLjerT82psk 2QN1LlzcsW/PuIUBCMcn+DY78Cjwa2/yuqpWjm77lvS9Eb31CT5YEgMhle6zEgeyW1G9 TFttb9K0gz3dO58xbgWwxsFMwVc3ghwH/M7xHv4bgAWF7K2a2DEk5XZVlYPYAlGyhDq1 tK0xXKZhhA0tsYUASSCurJqRot6bfbFE4duv18OplaN/DuBIG82y3qcw6kt0RmWYKgvI jBWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=FizreZQf; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g31si2739367plb.241.2019.07.03.10.02.45; Wed, 03 Jul 2019 10:03:03 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=FizreZQf; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727230AbfGCRCD (ORCPT + 99 others); Wed, 3 Jul 2019 13:02:03 -0400 Received: from mail-pg1-f201.google.com ([209.85.215.201]:37417 "EHLO mail-pg1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727049AbfGCRCC (ORCPT ); Wed, 3 Jul 2019 13:02:02 -0400 Received: by mail-pg1-f201.google.com with SMTP id s5so1964071pgr.4 for ; Wed, 03 Jul 2019 10:02:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=PtzfnXHwir5t+OK6oGGR3xyRGAh0lHKhLg6y74Z7SLI=; b=FizreZQfOB54x6CBxj83tADQPZPzVR8/wChupBATHtmbdgjnMryGONlVDgnxLjKuYq 3VV5dEtzc3rOyy5BHnKAdcoRvGWEwoVjf/4+gik2NSUYKmlR/p8FJLpB3I4CraYn178/ R/xmnUwfUUzqNmcvqRa/NCBw5cTyAwsSFFBHR5IN84dyIor/8zLJdz85Vq6yeh6BiG3p iMtK0ogb/8C/lHsfN6RP4nJpyWYaK7/S5EDQUK9vud4VnpKOCcjvX9dRX+YJrnb+bMkk OpdJazGd+BNI/aHArshaRwnW1fF14xznm3LZ54tHv8PTFWFF/fkib1YSARjkYPSwmc3l 4y2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=PtzfnXHwir5t+OK6oGGR3xyRGAh0lHKhLg6y74Z7SLI=; b=r2hmCP5BwQkfPkXv0ITtP7JHaig9LOaWqBBKJqDV7wEoJ/o+1noT0p64wLYHZhExCp lzfWcNSabVawzmcM+09EBGIGmttxYH3OH003GrAP39m80mijXYCVS/LSI+gdQ7Rv+794 9gv0Nl1GwcD+d5R5aA42OmYCcM4rUgzlUjWeAaS6/rZ3N/EUM0QT4V9I/47uqSNuzx16 qPBl+SYg19H3oG2YapdMalp9a9Ux9hPrnGQ7cQeK2pNA22/ZSAOm2EExbLJ3FcOyO+G7 GAy0SAKmxBFULa7GbrUhnjLdJXaZsZ9qxykzFf76I352FmJUtwYPJ/4Hdlu/eMDyBBGy CqtQ== X-Gm-Message-State: APjAAAU0DJzh7zSbkeHrR+pSeyXBrq96uzTqAZdYIvvAAbDULdevrQdm R+xFSmcF2l+MwBxeqze5Stf5A58BrGnu X-Received: by 2002:a63:c03:: with SMTP id b3mr38912759pgl.68.1562173321483; Wed, 03 Jul 2019 10:02:01 -0700 (PDT) Date: Wed, 3 Jul 2019 10:01:12 -0700 Message-Id: <20190703170118.196552-1-brianvv@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.22.0.410.gd8fdbe21b5-goog Subject: [PATCH bpf-next RFC v3 0/6] bpf: add BPF_MAP_DUMP command to dump more than one entry per call From: Brian Vazquez To: Brian Vazquez , Alexei Starovoitov , Daniel Borkmann , "David S . Miller" Cc: Stanislav Fomichev , Willem de Bruijn , Petar Penkov , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, Brian Vazquez Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This introduces a new command to retrieve a variable number of entries from a bpf map. This new command can be executed from the existing BPF syscall as follows: err = bpf(BPF_MAP_DUMP, union bpf_attr *attr, u32 size) using attr->dump.map_fd, attr->dump.prev_key, attr->dump.buf, attr->dump.buf_len returns zero or negative error, and populates buf and buf_len on succees This implementation is wrapping the existing bpf methods: map_get_next_key and map_lookup_elem the results show that even with a 1-elem_size buffer, it runs ~40 faster than the current implementation, improvements of ~85% are reported when the buffer size is increased, although, after the buffer size is around 5% of the total number of entries there's no huge difference in increasing it. Tested: Tried different size buffers to handle case where the bulk is bigger, or the elements to retrieve are less than the existing ones, all runs read a map of 100K entries. Below are the results(in ns) from the different runs: buf_len_1: 69038725 entry-by-entry: 112384424 improvement 38.569134 buf_len_2: 40897447 entry-by-entry: 111030546 improvement 63.165590 buf_len_230: 13652714 entry-by-entry: 111694058 improvement 87.776687 buf_len_5000: 13576271 entry-by-entry: 111101169 improvement 87.780263 buf_len_73000: 14694343 entry-by-entry: 111740162 improvement 86.849542 buf_len_100000: 13745969 entry-by-entry: 114151991 improvement 87.958187 buf_len_234567: 14329834 entry-by-entry: 114427589 improvement 87.476941 Changelog: v3: - add explanation of the API in the commit message - fix masked errors and return them to user - copy last_key from return buf into prev_key if it was provided - run test with kpti and retpoline mitigations v2: - use proper bpf-next tag Brian Vazquez (6): bpf: add bpf_map_value_size and bp_map_copy_value helper functions bpf: add BPF_MAP_DUMP command to dump more than one entry per call bpf: keep bpf.h in sync with tools/ libbpf: support BPF_MAP_DUMP command selftests/bpf: test BPF_MAP_DUMP command on a bpf hashmap selftests/bpf: add test to measure performance of BPF_MAP_DUMP include/uapi/linux/bpf.h | 9 + kernel/bpf/syscall.c | 252 ++++++++++++++++++------ tools/include/uapi/linux/bpf.h | 9 + tools/lib/bpf/bpf.c | 28 +++ tools/lib/bpf/bpf.h | 4 + tools/lib/bpf/libbpf.map | 2 + tools/testing/selftests/bpf/test_maps.c | 147 +++++++++++++- 7 files changed, 388 insertions(+), 63 deletions(-) -- 2.22.0.410.gd8fdbe21b5-goog