From: Martin KaFai Lau <martin.lau@linux.dev>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: Yonghong Song <yhs@meta.com>, Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
kernel-team@meta.com, bpf <bpf@vger.kernel.org>
Subject: Re: [PATCH bpf-next] bpf: Reduce smap->elem_size
Date: Tue, 20 Dec 2022 16:56:29 -0800 [thread overview]
Message-ID: <34389727-b9ee-4745-debf-935292bdaf3a@linux.dev> (raw)
In-Reply-To: <CAEf4BzbJGpkhyio9+S1U=bnYycaknw0SNada6orzNV_+VfPwGw@mail.gmail.com>
[ Cc: the bpf list back. I dropped it by mistake in my last reply. ]
On 12/20/22 3:43 PM, Andrii Nakryiko wrote:
> On Mon, Dec 19, 2022 at 11:47 AM Martin KaFai Lau <martin.lau@linux.dev> wrote:
>>
>> On 12/16/22 5:23 PM, Yonghong Song wrote:
>>>
>>>
>>> On 12/16/22 3:29 PM, Martin KaFai Lau wrote:
>>>> From: Martin KaFai Lau <martin.lau@kernel.org>
>>>>
>>>> 'struct bpf_local_storage_elem' has a 56 bytes padding at the end
>>>> which can be used for attr->value_size. The current smap->elem_size
>>>
>>> 'can be' => 'will be'?
>>
>> I used 'can be' to describe the current situation that the padding is not used
>> for the map's value. I may have used the wrong tense?
>>
>> I can rephrase it to something like,
>>
>> 'struct bpf_local_storage_elem' has a 56 bytes padding at the end which is
>> currently not used for the attr->value_size.
>
> I actually found the use of attr->value_size to mean "value content"
> more confusing than can vs will be.
>
> As a suggestion something like the below?
>
>
> 'struct bpf_local_storage_elem' has an unused 56 byte padding at the
> end due to struct's cache-line alignment requirement. This padding
> space is overlapped by storage value contents, so if we use sizeof()
> to calculate the total size, we overinflate it by 56 bytes. Use
> offsetof() instead to calculate more exact memory use.
SGTM.
>
>
> btw, I think you can calculate the same arguably a bit more
> straightforwardly as:
>
> smap->elem_size = offsetofend(struct bpf_local_storage_elem, sdata) +
> attr->value_size;
Sure. will change.
>
> right?
>
> but TIL that offsetof(struct bpf_local_storage_data,
> data[attr->value_size]) does the right thing
Yeah, I think I have seen other places using it also. I found it more intuitive
to read with array[size] to tell there is a flexible array at the end. I am not
super attached to it and will change to the way above.
next prev parent reply other threads:[~2022-12-21 0:56 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-16 23:29 [PATCH bpf-next] bpf: Reduce smap->elem_size Martin KaFai Lau
2022-12-17 1:23 ` Yonghong Song
[not found] ` <844f94a4-a003-55da-dc29-adf9f448fc45@linux.dev>
[not found] ` <CAEf4BzbJGpkhyio9+S1U=bnYycaknw0SNada6orzNV_+VfPwGw@mail.gmail.com>
2022-12-21 0:56 ` Martin KaFai Lau [this message]
2022-12-21 1:15 ` Andrii Nakryiko
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=34389727-b9ee-4745-debf-935292bdaf3a@linux.dev \
--to=martin.lau@linux.dev \
--cc=andrii.nakryiko@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=kernel-team@meta.com \
--cc=yhs@meta.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 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.