@@ -81,6 +81,8 @@ int init_iocb(int n, int iosize)
for (i = 0; i < n; i++) {
if (!(iocb_free[i] = (struct iocb *) malloc(sizeof(struct iocb))))
return -1;
+ if (alignment < sizeof(long))
+ alignment = sizeof(long);
if (posix_memalign(&buf, alignment, iosize))
return -1;
if (debug > 1) {
@@ -115,9 +115,10 @@ void aiodio_sparse(char *filename, int align, int writesize, int startoffset, in
*/
offset = startoffset;
for (i = 0; i < num_aio; i++) {
+ unsigned int mem_align = (align >= sizeof(long) ? align : sizeof(long));
void *bufptr;
- w = posix_memalign(&bufptr, align, writesize);
+ w = posix_memalign(&bufptr, mem_align, writesize);
if (w) {
fprintf(stderr, "cannot malloc aligned memory: %s\n",
strerror(w));
@@ -24,11 +24,14 @@ struct dio_thread_data {
static void *dio_thread(void *arg)
{
struct dio_thread_data *data = arg;
+ unsigned long mem_align;
off_t off;
ssize_t ret;
void *buf;
- if ((errno = posix_memalign(&buf, extent_size / 2, extent_size / 2))) {
+ mem_align = extent_size / 2;
+ mem_align = (mem_align >= sizeof(long) ? mem_align : sizeof(long));
+ if ((errno = posix_memalign(&buf, mem_align, extent_size / 2))) {
perror("malloc");
return NULL;
}
Fix the passing of an alignment that's less than sizeof(long) to posix_memalign() in some other places by making sure the minimum is used (AFS has a DIO alignment of 1). Note that I haven't altered randholes.c as that has an explicit check for a small alignment and gives an error in such a case. Possibly this should just round it up to sizeof(long) instead. Another alternative is that rather than using posix_memalign() is to allocate a buffer big enough that the base pointer we're going to actually use can be cranked forward to the appropriate alignment. Signed-off-by: David Howells <dhowells@redhat.com> --- src/aio-dio-regress/aiocp.c | 2 ++ src/aio-dio-regress/aiodio_sparse2.c | 3 ++- src/dio-interleaved.c | 5 ++++- 3 files changed, 8 insertions(+), 2 deletions(-)