Linux-f2fs-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Chao Yu via Linux-f2fs-devel <linux-f2fs-devel@lists.sourceforge.net>
To: jaegeuk@kernel.org
Cc: linux-f2fs-devel@lists.sourceforge.net
Subject: Re: [f2fs-dev] [PATCH v2] f2fs_io: adapt w/ page_size in aligned_xalloc()
Date: Mon, 29 Jun 2026 09:41:49 +0800	[thread overview]
Message-ID: <7c7dfece-0dc2-45a6-818f-b0cd9bdcd2d3@kernel.org> (raw)
In-Reply-To: <20260617073357.93682-1-chao@kernel.org>

On 6/17/26 15:33, Chao Yu wrote:
> When allocating memory in aligned_xalloc(), if the requested alignment
> (e.g., F2FS_DEFAULT_BLKSIZE) is smaller than the system's page size,
> aligned_alloc() will allocate memory that is not page-aligned on systems
> with 16KB or 64KB page sizes.
> 
> As a result, subsequent calls to madvise(..., MADV_HUGEPAGE) will fail
> because madvise() requires the memory address and length to be page-aligned.
> 
> Fix this by dynamically adjusting the alignment and rounding up the requested
> allocation size (via roundup()) to the system's page size, ensuring that
> memory is correctly page-aligned for madvise().

Minor thing:

Author info seems wrong, please help to correct, thanks.

author	Chao Yu via Linux-f2fs-devel <linux-f2fs-devel@lists.sourceforge.net>

https://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs-tools.git/commit/?h=dev-test&id=94525ec03cbdc3ead2e92c5e4ae229f9868317f2

Thanks,

> 
> Signed-off-by: Chao Yu <chao@kernel.org>
> ---
>   tools/f2fs_io/f2fs_io.c | 17 +++++++++++++++++
>   tools/f2fs_io/f2fs_io.h |  3 +++
>   2 files changed, 20 insertions(+)
> 
> diff --git a/tools/f2fs_io/f2fs_io.c b/tools/f2fs_io/f2fs_io.c
> index 94e61b8..9a866cc 100644
> --- a/tools/f2fs_io/f2fs_io.c
> +++ b/tools/f2fs_io/f2fs_io.c
> @@ -97,6 +97,23 @@ static void *xmalloc(size_t size)
>   
>   static void *aligned_xalloc(size_t alignment, size_t size)
>   {
> +	long page_size = F2FS_DEFAULT_BLKSIZE;
> +
> +#ifdef _SC_PAGESIZE
> +	page_size = sysconf(_SC_PAGESIZE);
> +	if (page_size < 0)
> +		page_size = F2FS_DEFAULT_BLKSIZE;
> +#endif
> +
> +	/*
> +	 * On systems with large page sizes (e.g., 16KB/64KB), alignment and
> +	 * allocation size must be page-aligned to satisfy madvise().
> +	 */
> +	if (alignment < (size_t)page_size)
> +		alignment = page_size;
> +
> +	size = roundup(size, alignment);
> +
>   	void *p = aligned_alloc(alignment, size);
>   
>   	if (!p)
> diff --git a/tools/f2fs_io/f2fs_io.h b/tools/f2fs_io/f2fs_io.h
> index 539964f..cf1c334 100644
> --- a/tools/f2fs_io/f2fs_io.h
> +++ b/tools/f2fs_io/f2fs_io.h
> @@ -49,6 +49,9 @@ typedef u32	__be32;
>   #endif
>   
>   #define F2FS_DEFAULT_BLKSIZE	4096
> +#ifndef roundup
> +#define roundup(x, y)		((((x) + ((y) - 1)) / (y)) * (y))
> +#endif
>   #define NEW_ADDR	0xFFFFFFFF
>   
>   #ifndef FS_IOC_GETFLAGS



_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

      parent reply	other threads:[~2026-06-29  1:42 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-17  7:33 [f2fs-dev] [PATCH v2] f2fs_io: adapt w/ page_size in aligned_xalloc() Chao Yu via Linux-f2fs-devel
2026-06-17  8:56 ` Zhiguo Niu
2026-06-29  1:41 ` Chao Yu via Linux-f2fs-devel [this message]

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=7c7dfece-0dc2-45a6-818f-b0cd9bdcd2d3@kernel.org \
    --to=linux-f2fs-devel@lists.sourceforge.net \
    --cc=chao@kernel.org \
    --cc=jaegeuk@kernel.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