bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Joanne Koong <joannekoong@fb.com>
To: Martin KaFai Lau <kafai@fb.com>
Cc: <bpf@vger.kernel.org>, <Kernel-team@fb.com>
Subject: Re: [PATCH v5 bpf-next 1/5] bpf: Add bloom filter map implementation
Date: Tue, 26 Oct 2021 12:47:43 -0700	[thread overview]
Message-ID: <421d3144-d3bc-c967-1fa1-3d52e0b1f88f@fb.com> (raw)
In-Reply-To: <20211026004307.34v3uwvnouaazlfa@kafai-mbp.dhcp.thefacebook.com>

On 10/25/21 5:43 PM, Martin KaFai Lau wrote:

> On Fri, Oct 22, 2021 at 03:02:45PM -0700, Joanne Koong wrote:
>
[...]
>> +static struct bpf_map *map_alloc(union bpf_attr *attr)
>> +{
>> +	u32 bitset_bytes, bitset_mask, nr_hash_funcs, nr_bits;
>> +	int numa_node = bpf_map_attr_numa_node(attr);
>> +	struct bpf_bloom_filter *bloom;
>> +
>> +	if (!bpf_capable())
>> +		return ERR_PTR(-EPERM);
>> +
>> +	if (attr->key_size != 0 || attr->value_size == 0 ||
>> +	    attr->max_entries == 0 ||
>> +	    attr->map_flags & ~BLOOM_CREATE_FLAG_MASK ||
>> +	    !bpf_map_flags_access_ok(attr->map_flags) ||
>> +	    (attr->map_extra & ~0xF))
>> +		return ERR_PTR(-EINVAL);
>> +
>> +	/* The lower 4 bits of map_extra specify the number of hash functions */
>> +	nr_hash_funcs = attr->map_extra & 0xF;
>> +	if (nr_hash_funcs == 0)
>> +		/* Default to using 5 hash functions if unspecified */
>> +		nr_hash_funcs = 5;
>> +
>> +	/* For the bloom filter, the optimal bit array size that minimizes the
>> +	 * false positive probability is n * k / ln(2) where n is the number of
>> +	 * expected entries in the bloom filter and k is the number of hash
>> +	 * functions. We use 7 / 5 to approximate 1 / ln(2).
>> +	 *
>> +	 * We round this up to the nearest power of two to enable more efficient
>> +	 * hashing using bitmasks. The bitmask will be the bit array size - 1.
>> +	 *
>> +	 * If this overflows a u32, the bit array size will have 2^32 (4
>> +	 * GB) bits.
>> +	 */
>> +	if (check_mul_overflow(attr->max_entries, nr_hash_funcs, &nr_bits) ||
> Comparing with v4, it is using max_entries to mean number
> of values instead of bits and also not exposing
> BPF_BLOOM_FILTER_BITSET_SZ macro to calculate the number of bits.
> just want to ensure it is the intention in v5 since I don't see it
> in the change log.
Yes, this is the intention. Sorry for not making that clear in the 
change log.
I will add that to the change log!
[...]


  reply	other threads:[~2021-10-26 19:47 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-22 22:02 [PATCH v5 bpf-next 0/5] Implement bloom filter map Joanne Koong
2021-10-22 22:02 ` [PATCH v5 bpf-next 1/5] bpf: Add bloom filter map implementation Joanne Koong
2021-10-26  0:43   ` Martin KaFai Lau
2021-10-26 19:47     ` Joanne Koong [this message]
2021-10-27  3:18   ` Andrii Nakryiko
2021-10-27 19:13     ` Joanne Koong
2021-10-27 19:16       ` Andrii Nakryiko
2021-10-22 22:02 ` [PATCH v5 bpf-next 2/5] libbpf: Add "map_extra" as a per-map-type extra flag Joanne Koong
2021-10-26  1:31   ` Martin KaFai Lau
2021-10-27  3:30   ` Andrii Nakryiko
2021-10-27 18:39     ` Joanne Koong
2021-10-27 18:41       ` Andrii Nakryiko
2021-10-22 22:02 ` [PATCH v5 bpf-next 3/5] selftests/bpf: Add bloom filter map test cases Joanne Koong
2021-10-27  3:35   ` Andrii Nakryiko
2021-10-22 22:02 ` [PATCH v5 bpf-next 4/5] bpf/benchs: Add benchmark tests for bloom filter throughput + false positive Joanne Koong
2021-10-27  3:49   ` Andrii Nakryiko
2021-10-22 22:02 ` [PATCH v5 bpf-next 5/5] bpf/benchs: Add benchmarks for comparing hashmap lookups w/ vs. w/out bloom filter Joanne Koong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=421d3144-d3bc-c967-1fa1-3d52e0b1f88f@fb.com \
    --to=joannekoong@fb.com \
    --cc=Kernel-team@fb.com \
    --cc=bpf@vger.kernel.org \
    --cc=kafai@fb.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).