bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Borkmann <daniel@iogearbox.net>
To: Yonghong Song <yhs@fb.com>, Brian Vazquez <brianvv@google.com>,
	Brian Vazquez <brianvv.kernel@gmail.com>,
	Alexei Starovoitov <ast@kernel.org>,
	"David S . Miller" <davem@davemloft.net>
Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
	bpf@vger.kernel.org
Subject: Re: [PATCH bpf] bpf: Do not grab the bucket spinlock by default on htab batch ops
Date: Tue, 18 Feb 2020 16:56:24 +0100	[thread overview]
Message-ID: <63fa17bf-a109-65c1-6cc5-581dd84fc93b@iogearbox.net> (raw)
In-Reply-To: <8ac06749-491f-9a77-3899-641b4f40afe2@fb.com>

On 2/18/20 4:43 PM, Yonghong Song wrote:
> On 2/14/20 2:43 PM, Brian Vazquez wrote:
>> Grabbing the spinlock for every bucket even if it's empty, was causing
>> significant perfomance cost when traversing htab maps that have only a
>> few entries. This patch addresses the issue by checking first the
>> bucket_cnt, if the bucket has some entries then we go and grab the
>> spinlock and proceed with the batching.
>>
>> Tested with a htab of size 50K and different value of populated entries.
>>
>> Before:
>>    Benchmark             Time(ns)        CPU(ns)
>>    ---------------------------------------------
>>    BM_DumpHashMap/1       2759655        2752033
>>    BM_DumpHashMap/10      2933722        2930825
>>    BM_DumpHashMap/200     3171680        3170265
>>    BM_DumpHashMap/500     3639607        3635511
>>    BM_DumpHashMap/1000    4369008        4364981
>>    BM_DumpHashMap/5k     11171919       11134028
>>    BM_DumpHashMap/20k    69150080       69033496
>>    BM_DumpHashMap/39k   190501036      190226162
>>
>> After:
>>    Benchmark             Time(ns)        CPU(ns)
>>    ---------------------------------------------
>>    BM_DumpHashMap/1        202707         200109
>>    BM_DumpHashMap/10       213441         210569
>>    BM_DumpHashMap/200      478641         472350
>>    BM_DumpHashMap/500      980061         967102
>>    BM_DumpHashMap/1000    1863835        1839575
>>    BM_DumpHashMap/5k      8961836        8902540
>>    BM_DumpHashMap/20k    69761497       69322756
>>    BM_DumpHashMap/39k   187437830      186551111
>>
>> Fixes: 057996380a42 ("bpf: Add batch ops to all htab bpf map")
>> Cc: Yonghong Song <yhs@fb.com>
>> Signed-off-by: Brian Vazquez <brianvv@google.com>
> 
> Acked-by: Yonghong Song <yhs@fb.com>

I must probably be missing something, but how is this safe? Presume we
traverse in the walk with bucket_cnt = 0. Meanwhile a different CPU added
entries to this bucket since not locked. Same reader on the other CPU with
bucket_cnt = 0 then starts to traverse the second
hlist_nulls_for_each_entry_safe() unlocked e.g. deleting entries?

  reply	other threads:[~2020-02-18 15:56 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-14 22:43 [PATCH bpf] bpf: Do not grab the bucket spinlock by default on htab batch ops Brian Vazquez
2020-02-18 15:43 ` Yonghong Song
2020-02-18 15:56   ` Daniel Borkmann [this message]
2020-02-18 16:34     ` Yonghong Song
2020-02-18 17:17       ` Brian Vazquez

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=63fa17bf-a109-65c1-6cc5-581dd84fc93b@iogearbox.net \
    --to=daniel@iogearbox.net \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=brianvv.kernel@gmail.com \
    --cc=brianvv@google.com \
    --cc=davem@davemloft.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=yhs@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).