From: Jens Axboe <axboe@kernel.dk>
To: Ammar Faizi <ammar.faizi@students.amikom.ac.id>,
Pavel Begunkov <asml.silence@gmail.com>,
io-uring Mailing List <io-uring@vger.kernel.org>
Cc: Bedirhan KURT <windowz414@gnuweeb.org>,
Louvian Lyndal <louvianlyndal@gmail.com>
Subject: Re: [PATCH liburing] src/nolibc: Fix `malloc()` alignment
Date: Mon, 11 Oct 2021 06:13:40 -0600 [thread overview]
Message-ID: <ae6aa009-765a-82b0-022c-d6696c6d3ee2@kernel.dk> (raw)
In-Reply-To: <20211011064927.444704-1-ammar.faizi@students.amikom.ac.id>
On 10/11/21 12:49 AM, Ammar Faizi wrote:
> Add `__attribute__((__aligned__))` to the `user_p` to guarantee
> pointer returned by the `malloc()` is properly aligned for user.
>
> This attribute asks the compiler to align a type to the maximum
> useful alignment for the target machine we are compiling for,
> which is often, but by no means always, 8 or 16 bytes [1].
>
> Link: https://gcc.gnu.org/onlinedocs/gcc-11.2.0/gcc/Common-Variable-Attributes.html#Common-Variable-Attributes [1]
> Fixes: https://github.com/axboe/liburing/issues/454
> Reported-by: Louvian Lyndal <louvianlyndal@gmail.com>
> Signed-off-by: Ammar Faizi <ammar.faizi@students.amikom.ac.id>
> ---
> src/nolibc.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/src/nolibc.c b/src/nolibc.c
> index 5582ca0..251780b 100644
> --- a/src/nolibc.c
> +++ b/src/nolibc.c
> @@ -20,7 +20,7 @@ void *memset(void *s, int c, size_t n)
>
> struct uring_heap {
> size_t len;
> - char user_p[];
> + char user_p[] __attribute__((__aligned__));
> };
This seems to over-align for me, at 16 bytes where 8 bytes would be fine.
What guarantees does malloc() give?
--
Jens Axboe
next prev parent reply other threads:[~2021-10-11 12:13 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-11 6:49 [PATCH liburing] src/nolibc: Fix `malloc()` alignment Ammar Faizi
2021-10-11 12:13 ` Jens Axboe [this message]
2021-10-11 12:56 ` Ammar Faizi
2021-10-11 13:00 ` Jens Axboe
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=ae6aa009-765a-82b0-022c-d6696c6d3ee2@kernel.dk \
--to=axboe@kernel.dk \
--cc=ammar.faizi@students.amikom.ac.id \
--cc=asml.silence@gmail.com \
--cc=io-uring@vger.kernel.org \
--cc=louvianlyndal@gmail.com \
--cc=windowz414@gnuweeb.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox