From: Andre Noll Date: Mon, 24 Oct 2011 13:31:31 +0000 (+0200) Subject: Merge branch 't/map_populate' X-Git-Tag: v0.4.9~15 X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=commitdiff_plain;h=a5ad3d4c598bafe28e90e5b623e0a754d6e973d5;hp=b307a25ed895caa33684302b502e9e0e70dc78b7 Merge branch 't/map_populate' --- diff --git a/NEWS b/NEWS index 6db72253..3a702729 100644 --- a/NEWS +++ b/NEWS @@ -9,6 +9,8 @@ - Shared memory areas are no longer restricted to 64K. We now detect the maximal size of a shared memory area at runtime. - cleanup of the internal uptime API. + - para_server prefaults the mmapped audio file to avoid + delays on slow media. -------------------------------------- 0.4.8 (2011-08-19) "nested assignment" diff --git a/vss.c b/vss.c index f6da52dd..e336a9e7 100644 --- a/vss.c +++ b/vss.c @@ -953,6 +953,10 @@ static int recv_afs_msg(int afs_socket, int *fd, uint32_t *code, uint32_t *data) return 1; } +#ifndef MAP_POPULATE +#define MAP_POPULATE 0 +#endif + static void recv_afs_result(struct vss_task *vsst, fd_set *rfds) { int ret, passed_fd, shmid; @@ -987,8 +991,8 @@ static void recv_afs_result(struct vss_task *vsst, fd_set *rfds) } mmd->size = statbuf.st_size; mmd->mtime = statbuf.st_mtime; - ret = para_mmap(mmd->size, PROT_READ, MAP_PRIVATE, passed_fd, - 0, &vsst->map); + ret = para_mmap(mmd->size, PROT_READ, MAP_PRIVATE | MAP_POPULATE, + passed_fd, 0, &vsst->map); if (ret < 0) goto err; close(passed_fd); @@ -1077,6 +1081,23 @@ static void vss_send(struct vss_task *vsst) } mmd->chunks_sent++; mmd->current_chunk++; + /* + * Prefault next chunk(s) + * + * If the backing device of the memory-mapped audio file is + * slow and read-ahead is turned off or prevented for some + * reason, e.g. due to memory pressure, it may take much longer + * than the chunk interval to get the next chunk on the wire, + * causing buffer underruns on the client side. Mapping the + * file with MAP_POPULATE seems to help a bit, but it does not + * eliminate the delays completely. Moreover, it is supported + * only on Linux. So we do our own read-ahead here. + */ + buf += len; + for (i = 0; i < 5 && buf < vsst->map + mmd->size; i++) { + __a_unused volatile char x = *buf; + buf += 4096; + } } }