diff --git a/configure.ac b/configure.ac index 73f7a2c2f..d860a74fe 100644 --- a/configure.ac +++ b/configure.ac @@ -326,7 +326,7 @@ HTS_HIDE_DYNAMIC_SYMBOLS dnl FIXME This pulls in dozens of standard header checks AC_FUNC_MMAP -AC_CHECK_FUNCS([gmtime_r fsync drand48 srand48_deterministic getauxval elf_aux_info]) +AC_CHECK_FUNCS([gmtime_r fsync drand48 srand48_deterministic getauxval elf_aux_info posix_memalign]) # Darwin has a dubious fdatasync() symbol, but no declaration in AC_CHECK_DECL([fdatasync(int)], [AC_CHECK_FUNCS(fdatasync)]) diff --git a/hfile.c b/hfile.c index 552b71774..3b60bedda 100644 --- a/hfile.c +++ b/hfile.c @@ -107,12 +107,20 @@ hFILE *hfile_init(size_t struct_size, const char *mode, size_t capacity) hFILE *fp = (hFILE *) malloc(struct_size); if (fp == NULL) goto error; - if (capacity == 0) capacity = 32768; + const int maxcap = 128*1024; + + if (capacity == 0) capacity = maxcap; // FIXME For now, clamp input buffer sizes so mpileup doesn't eat memory - if (strchr(mode, 'r') && capacity > 32768) capacity = 32768; + if (strchr(mode, 'r') && capacity > maxcap) capacity = maxcap; +#ifdef HAVE_POSIX_MEMALIGN + fp->buffer = NULL; + if (posix_memalign((void **)&fp->buffer, 256, capacity) < 0) + goto error; +#else fp->buffer = (char *) malloc(capacity); if (fp->buffer == NULL) goto error; +#endif fp->begin = fp->end = fp->buffer; fp->limit = &fp->buffer[capacity]; @@ -629,7 +637,12 @@ static size_t blksize(int fd) #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE struct stat sbuf; if (fstat(fd, &sbuf) != 0) return 0; - return sbuf.st_blksize; + + // Pipes/FIFOs on linux return 4Kb here often, but it's much too small + // for performant I/O. + return S_ISFIFO(sbuf.st_mode) + ? 128*1024 + : sbuf.st_blksize; #else return 0; #endif