All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] bpf: follow idr code convention
@ 2018-03-27 18:53 Shaohua Li
  2018-03-27 20:58 ` Daniel Borkmann
  0 siblings, 1 reply; 2+ messages in thread
From: Shaohua Li @ 2018-03-27 18:53 UTC (permalink / raw)
  To: netdev @ vger . kernel . org
  Cc: Kernel Team, Shaohua Li, Daniel Borkmann, Alexei Starovoitov

From: Shaohua Li <shli@fb.com>

Generally we do a preload before doing idr allocation. This also help
improve the allocation success rate in memory pressure.

Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Shaohua Li <shli@fb.com>
---
 kernel/bpf/syscall.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index 43f95d1..beab5de 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -203,11 +203,13 @@ static int bpf_map_alloc_id(struct bpf_map *map)
 {
 	int id;
 
+	idr_preload(GFP_KERNEL);
 	spin_lock_bh(&map_idr_lock);
 	id = idr_alloc_cyclic(&map_idr, map, 1, INT_MAX, GFP_ATOMIC);
 	if (id > 0)
 		map->id = id;
 	spin_unlock_bh(&map_idr_lock);
+	idr_preload_end();
 
 	if (WARN_ON_ONCE(!id))
 		return -ENOSPC;
@@ -940,11 +942,13 @@ static int bpf_prog_alloc_id(struct bpf_prog *prog)
 {
 	int id;
 
+	idr_preload(GFP_KERNEL);
 	spin_lock_bh(&prog_idr_lock);
 	id = idr_alloc_cyclic(&prog_idr, prog, 1, INT_MAX, GFP_ATOMIC);
 	if (id > 0)
 		prog->aux->id = id;
 	spin_unlock_bh(&prog_idr_lock);
+	idr_preload_end();
 
 	/* id is in [1, INT_MAX) */
 	if (WARN_ON_ONCE(!id))
-- 
2.9.5

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] bpf: follow idr code convention
  2018-03-27 18:53 [PATCH] bpf: follow idr code convention Shaohua Li
@ 2018-03-27 20:58 ` Daniel Borkmann
  0 siblings, 0 replies; 2+ messages in thread
From: Daniel Borkmann @ 2018-03-27 20:58 UTC (permalink / raw)
  To: Shaohua Li, netdev @ vger . kernel . org
  Cc: Kernel Team, Shaohua Li, Alexei Starovoitov

On 03/27/2018 08:53 PM, Shaohua Li wrote:
> From: Shaohua Li <shli@fb.com>
> 
> Generally we do a preload before doing idr allocation. This also help
> improve the allocation success rate in memory pressure.
> 
> Cc: Daniel Borkmann <daniel@iogearbox.net>
> Cc: Alexei Starovoitov <ast@kernel.org>
> Signed-off-by: Shaohua Li <shli@fb.com>

Looks good, applied to bpf-next, thanks Shaohua!

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-03-27 20:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-27 18:53 [PATCH] bpf: follow idr code convention Shaohua Li
2018-03-27 20:58 ` Daniel Borkmann

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.