Skip to contentSkip to conversation

src/splice-test.c: use memalign instead of aligned_alloc

PATCH In review David Sterba 3 participants 3 messages Feb 9, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 src/splice-test.c: use memalign instead of aligned_alloc

The build fails on SLE11 as the function aligned_alloc is not available there. Replace it by memalign that has the same semantics and is commonly used in fstests code base. aligned_alloc has additional requirements on the alignment and buffer size but that is ok as the buffer is defined in multiples of the alignment.

---
 src/splice-test.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
src/splice-test.c +3 -2
index 11fb11fa8cc3..2f1ba2baaff0 100644
@@ -17,6 +17,7 @@
 #include <stdbool.h>
 #include <string.h>
 #include <errno.h>
+#include <malloc.h>
 
 #define SECTOR_SIZE 512
 #define BUFFER_SIZE (150 * SECTOR_SIZE)
@@ -143,9 +144,9 @@ int main(int argc, char *argv[])
 		   do_splice == do_splice1 ? "sequential" : "concurrent",
 		   (open_flags & O_DIRECT) ? "with" : "without");
 
-	buffer = aligned_alloc(SECTOR_SIZE, BUFFER_SIZE);
+	buffer = memalign(SECTOR_SIZE, BUFFER_SIZE);
 	if (buffer == NULL)
-		err(1, "aligned_alloc");
+		err(1, "memalign");
 
 	fd = open(filename, open_flags, 0666);
 	if (fd == -1)
Signature · 1 line
2.29.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · David Sterba

The build fails on SLE11 as the function aligned_alloc is not available there. Replace it by memalign that has the same semantics and is commonly used in fstests code base. aligned_alloc has additional requirements on the alignment and buffer size but that is ok as the buffer is defined in multiples of the alignment.

Looks reasonable to me,

--D

Quoted 31 lines
---
 src/splice-test.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
src/splice-test.c +3 -2
index 11fb11fa8cc3..2f1ba2baaff0 100644
@@ -17,6 +17,7 @@
 #include <stdbool.h>
 #include <string.h>
 #include <errno.h>
+#include <malloc.h>
 
 #define SECTOR_SIZE 512
 #define BUFFER_SIZE (150 * SECTOR_SIZE)
@@ -143,9 +144,9 @@ int main(int argc, char *argv[])
 		   do_splice == do_splice1 ? "sequential" : "concurrent",
 		   (open_flags & O_DIRECT) ? "with" : "without");
 
-	buffer = aligned_alloc(SECTOR_SIZE, BUFFER_SIZE);
+	buffer = memalign(SECTOR_SIZE, BUFFER_SIZE);
 	if (buffer == NULL)
-		err(1, "aligned_alloc");
+		err(1, "memalign");
 
 	fd = open(filename, open_flags, 0666);
 	if (fd == -1)
Signature · 1 line
2.29.2
Reviewed-by on v1 1/1
#2 lore raw
In reply to David Sterba
Quoted 8 lines · David Sterba

The build fails on SLE11 as the function aligned_alloc is not available there. Replace it by memalign that has the same semantics and is commonly used in fstests code base. aligned_alloc has additional requirements on the alignment and buffer size but that is ok as the buffer is defined in multiples of the alignment.

---

The manpage said:

aligned_alloc(): _ISOC11_SOURCE

The functions memalign(), valloc(), and pvalloc() have been available in all Linux libc libraries. The function aligned_alloc() was added to glibc in version 2.16.

So looks like aligned_alloc might not be supported on some old system. As the change of this patch won't change the original testing, so it's good to me.

Quoted 30 lines
 src/splice-test.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
src/splice-test.c +3 -2
index 11fb11fa8cc3..2f1ba2baaff0 100644
@@ -17,6 +17,7 @@
 #include <stdbool.h>
 #include <string.h>
 #include <errno.h>
+#include <malloc.h>
 
 #define SECTOR_SIZE 512
 #define BUFFER_SIZE (150 * SECTOR_SIZE)
@@ -143,9 +144,9 @@ int main(int argc, char *argv[])
 		   do_splice == do_splice1 ? "sequential" : "concurrent",
 		   (open_flags & O_DIRECT) ? "with" : "without");
 
-	buffer = aligned_alloc(SECTOR_SIZE, BUFFER_SIZE);
+	buffer = memalign(SECTOR_SIZE, BUFFER_SIZE);
 	if (buffer == NULL)
-		err(1, "aligned_alloc");
+		err(1, "memalign");
 
 	fd = open(filename, open_flags, 0666);
 	if (fd == -1)
Signature · 1 line
2.29.2