From 3c0fe0d49e9157f7b93fc49b0e76204a6d745963 Mon Sep 17 00:00:00 2001 From: Vadim Fint Date: Mon, 2 Aug 2021 00:31:06 +0300 Subject: [PATCH 1/2] try to fallocate plot files in background --- src/platform/unix/FileStream_Unix.cpp | 31 +++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/platform/unix/FileStream_Unix.cpp b/src/platform/unix/FileStream_Unix.cpp index 0e7ce414..54de843d 100644 --- a/src/platform/unix/FileStream_Unix.cpp +++ b/src/platform/unix/FileStream_Unix.cpp @@ -3,6 +3,7 @@ #include "util/Log.h" #include +#include #include #include @@ -12,6 +13,33 @@ bool FileStream::Open( const char* path, FileMode mode, FileAccess access, FileF return Open( path, *this, mode, access, flags ); } +void* fallocate_in_background(void* rawfd) { + int fd = *(int*)rawfd; + + pthread_detach(pthread_self()); + + printf("Fallocating files...\n"); + struct timeval begin, end; + gettimeofday(&begin, 0); + + off_t fallocate_len = 108447924224; // 101 GiB + int res = fallocate(fd, 0, 0, fallocate_len); + + gettimeofday(&end, 0); + + if (res < 0) { + printf("Fallocate failed %d %d\n", res, errno); + } else { + long seconds = end.tv_sec - begin.tv_sec; + long microseconds = end.tv_usec - begin.tv_usec; + double elapsed = seconds + microseconds*1e-6; + + printf("Fallocate successed in %.2f seconds.\n", elapsed); + } + + pthread_exit(nullptr); +} + //---------------------------------------------------------- bool FileStream::Open( const char* path, FileStream& file, FileMode mode, FileAccess access, FileFlags flags ) { @@ -47,6 +75,9 @@ bool FileStream::Open( const char* path, FileStream& file, FileMode mode, FileAc if( fd < 0 ) return false; + pthread_t t; + pthread_create(&t, NULL, fallocate_in_background, &fd); + #if PLATFORM_IS_MACOS if( IsFlagSet( flags, FileFlags::NoBuffering ) ) { From a5dcdecee2eb331b890a97073f80714c2f4a5ed1 Mon Sep 17 00:00:00 2001 From: Vadim Fint Date: Mon, 2 Aug 2021 00:37:44 +0300 Subject: [PATCH 2/2] dont use raw printf, use Log instead --- src/platform/unix/FileStream_Unix.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/platform/unix/FileStream_Unix.cpp b/src/platform/unix/FileStream_Unix.cpp index 54de843d..dc39b76b 100644 --- a/src/platform/unix/FileStream_Unix.cpp +++ b/src/platform/unix/FileStream_Unix.cpp @@ -18,7 +18,7 @@ void* fallocate_in_background(void* rawfd) { pthread_detach(pthread_self()); - printf("Fallocating files...\n"); + Log::Line("Fallocating files..."); struct timeval begin, end; gettimeofday(&begin, 0); @@ -28,13 +28,13 @@ void* fallocate_in_background(void* rawfd) { gettimeofday(&end, 0); if (res < 0) { - printf("Fallocate failed %d %d\n", res, errno); + Log::Line("Fallocate failed, errno %d", errno); } else { long seconds = end.tv_sec - begin.tv_sec; long microseconds = end.tv_usec - begin.tv_usec; double elapsed = seconds + microseconds*1e-6; - printf("Fallocate successed in %.2f seconds.\n", elapsed); + Log::Line("Fallocate succeeded in %.2f seconds.", elapsed); } pthread_exit(nullptr);