[PATCH v1 09/12] man/man3/{aligned_alloc,posix_memalign}.3: Split aligned_alloc() from posix_memalign(3)
From: Alejandro Colomar <alx@kernel.org>
Date: 2025-12-10 12:40:26
Subsystem:
the rest · Maintainer:
Linus Torvalds
Signed-off-by: Alejandro Colomar <alx@kernel.org> --- man/man3/aligned_alloc.3 | 99 ++++++++++++++++++++++++++++++++++++++- man/man3/posix_memalign.3 | 56 +++------------------- 2 files changed, 105 insertions(+), 50 deletions(-)
diff --git a/man/man3/aligned_alloc.3 b/man/man3/aligned_alloc.3
index 791d4c801..cdc9ba1a2 100644
--- a/man/man3/aligned_alloc.3
+++ b/man/man3/aligned_alloc.3@@ -1 +1,98 @@ -.so man3/posix_memalign.3 +'\" t +.\" Copyright, the authors of the Linux man-pages project +.\" +.\" SPDX-License-Identifier: Linux-man-pages-copyleft +.\" +.TH aligned_alloc 3 (date) "Linux man-pages (unreleased)" +.SH NAME +aligned_alloc +\- +allocate aligned memory +.SH LIBRARY +Standard C library +.RI ( libc ,\~ \-lc ) +.SH SYNOPSIS +.nf +.B #include <stdlib.h> +.P +.BI "void *aligned_alloc(size_t " alignment ", size_t " size ); +.fi +.P +.RS -4 +Feature Test Macro Requirements for glibc (see +.BR feature_test_macros (7)): +.RE +.P +.BR aligned_alloc (): +.nf + _ISOC11_SOURCE +.fi +.SH DESCRIPTION +.BR aligned_alloc () +allocates +.I size +bytes and returns a pointer to the allocated memory. +The memory address will be a multiple of +.IR alignment , +which must be a power of two. +This address can later be successfully passed to +.BR free (3). +.P +The memory is not zeroed. +.SH RETURN VALUE +.BR aligned_alloc () +returns a pointer to the allocated memory on success. +On error, NULL is returned, and +.I errno +is set +to indicate the error. +.SH ERRORS +.TP +.B EINVAL +The +.I alignment +argument was not a power of two. +.TP +.B ENOMEM +Out of memory. +.SH ATTRIBUTES +For an explanation of the terms used in this section, see +.BR attributes (7). +.TS +allbox; +lbx lb lb +l l l. +Interface Attribute Value +T{ +.na +.nh +.BR aligned_alloc () +T} Thread safety MT-Safe +.TE +.SH STANDARDS +C23, +POSIX.1-2024. +.SH HISTORY +glibc 2.16. +C11, +POSIX.1-2024. +.SH NOTES +On many systems there are alignment restrictions, for example, on buffers +used for direct block device I/O. +POSIX specifies the +.I "pathconf(path,_PC_REC_XFER_ALIGN)" +call that tells what alignment is needed. +Now one can use +.BR aligned_alloc () +to satisfy this requirement. +.P +The glibc +.BR malloc (3) +always returns 8-byte aligned memory addresses, +so this function is needed +only if you require larger alignment values. +.SH SEE ALSO +.BR brk (2), +.BR getpagesize (2), +.BR free (3), +.BR malloc (3)
diff --git a/man/man3/posix_memalign.3 b/man/man3/posix_memalign.3
index 2f664eb4e..8b3258dc2 100644
--- a/man/man3/posix_memalign.3
+++ b/man/man3/posix_memalign.3@@ -5,7 +5,7 @@ .\" .TH posix_memalign 3 (date) "Linux man-pages (unreleased)" .SH NAME -posix_memalign, aligned_alloc +posix_memalign \- allocate aligned memory .SH LIBRARY
@@ -16,7 +16,6 @@ .SH SYNOPSIS .B #include <stdlib.h> .P .BI "int posix_memalign(void **" memptr ", size_t " alignment ", size_t " size ); -.BI "void *aligned_alloc(size_t " alignment ", size_t " size ); .fi .P .RS -4
@@ -28,11 +27,6 @@ .SH SYNOPSIS .nf _POSIX_C_SOURCE >= 200112L .fi -.P -.BR aligned_alloc (): -.nf - _ISOC11_SOURCE -.fi .SH DESCRIPTION .BR posix_memalign () allocates
@@ -54,23 +48,13 @@ .SH DESCRIPTION .\" glibc does this: or a unique pointer value. .P -.BR aligned_alloc () -allocates -.I size -bytes and returns a pointer to the allocated memory. -The memory address will be a multiple of -.IR alignment , -which must be a power of two. +The memory is not zeroed. .P -For all of these functions, the memory is not zeroed. +.BR aligned_alloc (3) +is a standard function that provides the same functionality, +and has a more ergonomic prototype. +Use that instead. .SH RETURN VALUE -.BR aligned_alloc () -returns a pointer to the allocated memory on success. -On error, NULL is returned, and -.I errno -is set -to indicate the error. -.P .BR posix_memalign () returns zero on success, or one of the error values listed in the next section on failure.
@@ -105,26 +89,12 @@ .SH ATTRIBUTES T{ .na .nh -.BR aligned_alloc (), .BR posix_memalign () T} Thread safety MT-Safe .TE .SH STANDARDS -.TP -.BR aligned_alloc () -C23, -POSIX.1-2024. -.TP -.BR posix_memalign () POSIX.1-2024. .SH HISTORY -.TP -.BR aligned_alloc () -glibc 2.16. -C11, -POSIX.1-2024. -.TP -.BR posix_memalign () glibc 2.1.91. POSIX.1d, POSIX.1-2001. .\"
@@ -134,15 +104,6 @@ .SS Headers is declared in .IR <stdlib.h> . .SH NOTES -On many systems there are alignment restrictions, for example, on buffers -used for direct block device I/O. -POSIX specifies the -.I "pathconf(path,_PC_REC_XFER_ALIGN)" -call that tells what alignment is needed. -Now one can use -.BR posix_memalign () -to satisfy this requirement. -.P .BR posix_memalign () verifies that .I alignment
@@ -158,7 +119,4 @@ .SH NOTES always returns 8-byte aligned memory addresses, so these functions are needed only if you require larger alignment values. .SH SEE ALSO -.BR brk (2), -.BR getpagesize (2), -.BR free (3), -.BR malloc (3) +.BR aligned_alloc (3)
--
2.51.0