From: Alexei Starovoitov <alexei.starovoitov@gmail.com>
To: Martin KaFai Lau <kafai@fb.com>
Cc: netdev@vger.kernel.org, David Miller <davem@davemloft.net>,
Alexei Starovoitov <ast@fb.com>,
Daniel Borkmann <daniel@iogearbox.net>,
Kernel Team <kernel-team@fb.com>
Subject: Re: [PATCH v2 net-next 5/6] bpf: Add BPF_MAP_TYPE_LRU_PERCPU_HASH
Date: Mon, 14 Nov 2016 17:34:38 -0800 [thread overview]
Message-ID: <20161115013436.GA8080@ast-mbp.thefacebook.com> (raw)
In-Reply-To: <1478890511-1346984-6-git-send-email-kafai@fb.com>
On Fri, Nov 11, 2016 at 10:55:10AM -0800, Martin KaFai Lau wrote:
> Provide a LRU version of the existing BPF_MAP_TYPE_PERCPU_HASH
>
> Signed-off-by: Martin KaFai Lau <kafai@fb.com>
...
> + /* For LRU, we need to alloc before taking bucket's
> + * spinlock because LRU's elem alloc may need
> + * to remove older elem from htab and this removal
> + * operation will need a bucket lock.
> + */
> + if (map_flags != BPF_EXIST) {
> + l_new = prealloc_lru_pop(htab, key, hash);
> + if (!l_new)
> + return -ENOMEM;
> + }
> +
> + /* bpf_map_update_elem() can be called in_irq() */
> + raw_spin_lock_irqsave(&b->lock, flags);
> +
> + l_old = lookup_elem_raw(head, hash, key, key_size);
> +
> + ret = check_flags(htab, l_old, map_flags);
> + if (ret)
> + goto err;
> +
> + if (l_old) {
> + bpf_lru_node_set_ref(&l_old->lru_node);
> +
> + /* per-cpu hash map can update value in-place */
> + pcpu_copy_value(htab, htab_elem_get_ptr(l_old, key_size),
> + value, onallcpus);
> + } else {
> + pcpu_copy_value(htab, htab_elem_get_ptr(l_new, key_size),
> + value, onallcpus);
> + hlist_add_head_rcu(&l_new->hash_node, head);
> + l_new = NULL;
> + }
> + ret = 0;
> +err:
> + raw_spin_unlock_irqrestore(&b->lock, flags);
> + if (l_new)
> + bpf_lru_push_free(&htab->lru, &l_new->lru_node);
> + return ret;
> +}
definitely tricky code, but all looks correct.
Acked-by: Alexei Starovoitov <ast@kernel.org>
next prev parent reply other threads:[~2016-11-15 1:34 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-11 18:55 [PATCH v2 net-next 0/6] bpf: LRU map Martin KaFai Lau
2016-11-11 18:55 ` [PATCH v2 net-next 1/6] bpf: LRU List Martin KaFai Lau
2016-11-15 1:50 ` Alexei Starovoitov
2016-11-11 18:55 ` [PATCH v2 net-next 2/6] bpf: Add percpu LRU list Martin KaFai Lau
2016-11-15 1:51 ` Alexei Starovoitov
2016-11-11 18:55 ` [PATCH v2 net-next 3/6] bpf: Refactor codes handling percpu map Martin KaFai Lau
2016-11-14 18:43 ` Alexei Starovoitov
2016-11-11 18:55 ` [PATCH v2 net-next 4/6] bpf: Add BPF_MAP_TYPE_LRU_HASH Martin KaFai Lau
2016-11-14 20:52 ` Alexei Starovoitov
2016-11-11 18:55 ` [PATCH v2 net-next 5/6] bpf: Add BPF_MAP_TYPE_LRU_PERCPU_HASH Martin KaFai Lau
2016-11-15 1:34 ` Alexei Starovoitov [this message]
2016-11-11 18:55 ` [PATCH v2 net-next 6/6] bpf: Add tests for the LRU bpf_htab Martin KaFai Lau
2016-11-15 1:43 ` Alexei Starovoitov
2016-11-14 18:19 ` [PATCH v2 net-next 0/6] bpf: LRU map David Miller
2016-11-15 16:51 ` David Miller
2016-11-15 16:59 ` David Miller
2016-11-15 18:12 ` Martin KaFai Lau
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=20161115013436.GA8080@ast-mbp.thefacebook.com \
--to=alexei.starovoitov@gmail.com \
--cc=ast@fb.com \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=kafai@fb.com \
--cc=kernel-team@fb.com \
--cc=netdev@vger.kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.