From 566c3c7a22c0ec217c40f7a95db2bb83c8cc16c7 Mon Sep 17 00:00:00 2001 From: antirez Date: Tue, 20 Apr 2010 18:25:30 +0200 Subject: [PATCH 1/2] fsync always now uses O_DIRECT on Linux --- config.h | 5 +++++ redis.c | 11 ++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/config.h b/config.h index 754d3aa86..d1da9887d 100644 --- a/config.h +++ b/config.h @@ -35,4 +35,9 @@ #define HAVE_KQUEUE 1 #endif +/* test for O_DIRECT */ +#ifdef __linux__ +#define HAVE_O_DIRECT 1 +#endif + #endif diff --git a/redis.c b/redis.c index 53d5c215c..de4f5763d 100644 --- a/redis.c +++ b/redis.c @@ -1673,7 +1673,16 @@ static void initServer() { acceptHandler, NULL) == AE_ERR) oom("creating file event"); if (server.appendonly) { - server.appendfd = open(server.appendfilename,O_WRONLY|O_APPEND|O_CREAT,0644); + int flags = O_WRONLY|O_APPEND|O_CREAT; + +#ifdef HAVE_O_DIRECT + if (server.appendfsync == APPENDFSYNC_ALWAYS) { + flags |= O_DIRECT; + server.appendfsync = APPENDFSYNC_NO; + } +#endif + + server.appendfd = open(server.appendfilename,flags,0644); if (server.appendfd == -1) { redisLog(REDIS_WARNING, "Can't open the append-only file: %s", strerror(errno)); From 122c04983400a076423811740f2b87163ea95c00 Mon Sep 17 00:00:00 2001 From: antirez Date: Tue, 20 Apr 2010 18:29:06 +0200 Subject: [PATCH 2/2] define __USE_GNU to get O_DIRECT --- redis.c | 1 + 1 file changed, 1 insertion(+) diff --git a/redis.c b/redis.c index de4f5763d..7907bb9f1 100644 --- a/redis.c +++ b/redis.c @@ -54,6 +54,7 @@ #include #include #include +#define __USE_GNU #include #include #include