Changeset: 83725c3a151e for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=83725c3a151e
Modified Files:
        NT/monetdb_config.h.in
        configure.ag
        gdk/gdk_posix.c
        gdk/gdk_storage.c
Branch: Oct2014
Log Message:

On Linux, use fallocate instead of posix_fallocate.
In case fallocate fails because the file system doesn't support the
operation, posix_fallocate would emulate the behavior.  This takes too
much time, so we want to just fall back to ftruncate instead.


diffs (101 lines):

diff --git a/NT/monetdb_config.h.in b/NT/monetdb_config.h.in
--- a/NT/monetdb_config.h.in
+++ b/NT/monetdb_config.h.in
@@ -136,6 +136,9 @@
 /* Define to 1 if you have the `fabsf' function. */
 #define HAVE_FABSF 1
 
+/* Define to 1 if you have the `fallocate' function. */
+/* #undef HAVE_FALLOCATE */
+
 /* Define to 1 if you have the `fcntl' function. */
 /* #undef HAVE_FCNTL */
 
diff --git a/configure.ag b/configure.ag
--- a/configure.ag
+++ b/configure.ag
@@ -2908,6 +2908,7 @@ AC_CHECK_FUNCS([\
                                backtrace \
                                ctime_r \
                                fabsf \
+                               fallocate \
                                fcntl \
                                fpclass \
                                fpclassify \
diff --git a/gdk/gdk_posix.c b/gdk/gdk_posix.c
--- a/gdk/gdk_posix.c
+++ b/gdk/gdk_posix.c
@@ -540,6 +540,19 @@ MT_mremap(const char *path, int mode, vo
                                        }
                                        if (write(fd, old_address,
                                                  old_size) < 0 ||
+#ifdef HAVE_FALLOCATE
+                                           /* prefer Linux-specific
+                                            * fallocate over standard
+                                            * posix_fallocate, since
+                                            * glibc uses a rather
+                                            * slow method of
+                                            * allocating the file if
+                                            * the file system doesn't
+                                            * support the operation,
+                                            * we just use ftruncate
+                                            * in that case */
+                                           (fallocate(fd, 0, (off_t) old_size, 
(off_t) *new_size - (off_t) old_size) < 0 && (errno != EOPNOTSUPP || 
ftruncate(fd, (off_t) *new_size) < 0))
+#else
 #ifdef HAVE_POSIX_FALLOCATE
                                            /* posix_fallocate returns
                                             * error number on
@@ -550,19 +563,24 @@ MT_mremap(const char *path, int mode, vo
                                             * operation, so we then
                                             * need to try
                                             * ftruncate */
-                                           ((rt = posix_fallocate(fd, 0, 
(off_t) *new_size)) == EINVAL ? ftruncate(fd, (off_t) *new_size) < 0 : rt != 0)
+                                           ((rt = posix_fallocate(fd, (off_t) 
old_size, (off_t) *new_size - (off_t) old_size)) == EINVAL ? ftruncate(fd, 
(off_t) *new_size) < 0 : rt != 0)
 #else
                                            ftruncate(fd, (off_t) *new_size) < 0
 #endif
+#endif
                                                ) {
                                                close(fd);
                                                fprintf(stderr,
                                                        "= %s:%d: 
MT_mremap(%s,"PTRFMT","SZFMT","SZFMT"): write() or "
+#ifdef HAVE_FALLOCATE
+                                                       "fallocate()"
+#else
 #ifdef HAVE_POSIX_FALLOCATE
                                                        "posix_fallocate()"
 #else
                                                        "ftruncate()"
 #endif
+#endif
                                                        " failed\n", __FILE__, 
__LINE__, path, PTRFMTCAST old_address, old_size, *new_size);
                                                return NULL;
                                        }
diff --git a/gdk/gdk_storage.c b/gdk/gdk_storage.c
--- a/gdk/gdk_storage.c
+++ b/gdk/gdk_storage.c
@@ -281,14 +281,23 @@ GDKextendf(int fd, size_t size, const ch
        /* if necessary, extend the underlying file */
        IODEBUG t0 = GDKms();
        if (stb.st_size < (off_t) size) {
+#ifdef HAVE_FALLOCATE
+               if (fallocate(fd, 0, stb.st_size, (off_t) size - stb.st_size) < 
0 &&
+                   errno == EOPNOTSUPP)
+                       /* on Linux, posix_fallocate uses a slow
+                        * method to allocate blocks if the underlying
+                        * file system doesn't support the operation,
+                        * so use fallocate instead and just resize
+                        * the file if it fails */
 #ifdef HAVE_POSIX_FALLOCATE
                /* posix_fallocate returns error number on failure,
                 * not -1 :-( */
-               if ((rt = posix_fallocate(fd, 0, (off_t) size)) == EINVAL)
+               if ((rt = posix_fallocate(fd, stb.st_size, (off_t) size - 
stb.st_size)) == EINVAL)
                        /* on Solaris/OpenIndiana, this may mean that
                         * the underlying file system doesn't support
                         * the operation, so just resize the file */
 #endif
+#endif
                rt = ftruncate(fd, (off_t) size);
        }
        IODEBUG fprintf(stderr, "#GDKextend %s " SZFMT " -> " SZFMT " %dms%s\n",
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to