From: Gao Xiang <hsiangkao@linux.alibaba.com>
To: Michael Walle <mwalle@kernel.org>,
Huang Jianan <jnhuang95@gmail.com>, Tom Rini <trini@konsulko.com>
Cc: linux-erofs@lists.ozlabs.org, u-boot@lists.denx.de
Subject: Re: [PATCH 1/4] fs/erofs: align the malloc'ed data
Date: Mon, 23 Mar 2026 23:13:10 +0800 [thread overview]
Message-ID: <cee1977e-38cc-48f6-a474-7d27fb6c4bc9@linux.alibaba.com> (raw)
In-Reply-To: <DHA98B2R8313.2J0R49KQ2WE1X@kernel.org>
On 2026/3/23 23:08, Michael Walle wrote:
> Hi Gao,
>
> On Mon Mar 23, 2026 at 3:41 PM CET, Gao Xiang wrote:
>> Hi Michael,
>>
>> On 2026/3/23 21:42, Michael Walle wrote:
>>> The data buffers are used to transfer from or to hardware peripherals.
>>> Often, there are restrictions on addresses, i.e. they have to be aligned
>>> at a certain size. Thus, allocate the data on the heap instead of the
>>> stack (at a random address alignment). Use malloc_cache_aligned() to get
>>> an aligned buffer.
>>
>> Many thanks for the patch, I wonder if it's possible to
>> submit the patches to erofs-utils first (even make
>> malloc_cache_aligned() as another malloc() for example)?
>>
>> Since I'd like to make u-boot codebase following
>> erofs-utils, but I don't think Jianan have the
>> bandwidth now, but if you have some use cases,
>> you could help syncing up a bit.
>
> Sorry, I don't have the bandwidth neither. But now I see where all
> this is coming from. In userspace, you have much less (or none at
> all) restrictions. So not sure, if that even makes sense to share. As
> you've already pointed out the malloc_cache_aligned() would have to
> be changed (back!) to malloc() again.
But it can align the codebase between erofs-utils and u-boot,
in that way, all potential bug fixes can be addressed
together.
>
>> Or at least, let's keep these four patches in sync
>> between erofs-utils and u-boot.
>
> Not sure what a DMA alignment has to do with userspace, or do you
> mean moving all the block data from stack to heap?
I think if it's not complex, we could do that, but if some
case is very hard, we can leave them alone.
>
> This is more or less the result from an internal evaluation. You (or
> anybody else) might take it - or leave it.
>
> Do you share code between linux and erofs-utils, too? How does that
> work?
Only the majority of metadata parsing logic is shared by
the linux kernel and erofs-utils, much like XFS shares
libxfs between the kernel and xfsprogs.
Thanks,
Gao Xiang
>
> Thanks,
> -michael
>
>>
>> Many thanks!
>> Gao Xiang
>>
>>>
>>> Signed-off-by: Michael Walle <mwalle@kernel.org>
>>> ---
>>> fs/erofs/data.c | 11 ++++-------
>>> fs/erofs/internal.h | 1 +
>>> 2 files changed, 5 insertions(+), 7 deletions(-)
>>>
>>> diff --git a/fs/erofs/data.c b/fs/erofs/data.c
>>> index b58ec6fcc66..61dbae51a9a 100644
>>> --- a/fs/erofs/data.c
>>> +++ b/fs/erofs/data.c
>>> @@ -319,15 +319,13 @@ static int z_erofs_read_data(struct erofs_inode *inode, char *buffer,
>>> }
>>>
>>> if (map.m_plen > bufsize) {
>>> - char *tmp;
>>> -
>>> bufsize = map.m_plen;
>>> - tmp = realloc(raw, bufsize);
>>> - if (!tmp) {
>>> + free(raw);
>>> + raw = malloc_cache_aligned(bufsize);
>>> + if (!raw) {
>>> ret = -ENOMEM;
>>> break;
>>> }
>>> - raw = tmp;
>>> }
>>>
>>> ret = z_erofs_read_one_data(inode, &map, raw,
>>> @@ -336,8 +334,7 @@ static int z_erofs_read_data(struct erofs_inode *inode, char *buffer,
>>> if (ret < 0)
>>> break;
>>> }
>>> - if (raw)
>>> - free(raw);
>>> + free(raw);
>>> return ret < 0 ? ret : 0;
>>> }
>>>
>>> diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h
>>> index 1875f37fcd2..13c862325a6 100644
>>> --- a/fs/erofs/internal.h
>>> +++ b/fs/erofs/internal.h
>>> @@ -11,6 +11,7 @@
>>> #include <linux/printk.h>
>>> #include <linux/log2.h>
>>> #include <inttypes.h>
>>> +#include <memalign.h>
>>> #include "erofs_fs.h"
>>>
>>> #define erofs_err(fmt, ...) \
>
next prev parent reply other threads:[~2026-03-23 15:13 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-23 13:42 [PATCH 0/4] fs/erofs: major alignment fixes Michael Walle
2026-03-23 13:42 ` [PATCH 1/4] fs/erofs: align the malloc'ed data Michael Walle
2026-03-23 14:41 ` Gao Xiang
2026-03-23 15:08 ` Michael Walle
2026-03-23 15:13 ` Gao Xiang [this message]
2026-03-23 13:42 ` [PATCH 2/4] fs/erofs: allocate data buffers on heap with alignment (1/3) Michael Walle
2026-03-23 13:42 ` [PATCH 3/4] fs/erofs: allocate data buffers on heap with alignment (2/3) Michael Walle
2026-03-23 13:42 ` [PATCH 4/4] fs/erofs: allocate data buffers on heap with alignment (3/3) Michael Walle
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=cee1977e-38cc-48f6-a474-7d27fb6c4bc9@linux.alibaba.com \
--to=hsiangkao@linux.alibaba.com \
--cc=jnhuang95@gmail.com \
--cc=linux-erofs@lists.ozlabs.org \
--cc=mwalle@kernel.org \
--cc=trini@konsulko.com \
--cc=u-boot@lists.denx.de \
/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