Changeset: 5a990bb97ebf for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=5a990bb97ebf
Modified Files:
NT/monetdb_config.h.in
configure.ag
gdk/gdk_posix.c
gdk/gdk_select.c
gdk/gdk_storage.c
Branch: default
Log Message:
Merge with Oct2014 branch.
diffs (183 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
@@ -130,6 +130,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
@@ -2899,6 +2899,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_select.c b/gdk/gdk_select.c
--- a/gdk/gdk_select.c
+++ b/gdk/gdk_select.c
@@ -163,22 +163,35 @@ doubleslice(BAT *b, BUN l1, BUN h1, BUN
return virtualize(bn);
}
+#define HASHloop_bound(bi, h, hb, v, lo, hi) \
+ for (hb = HASHget(h, HASHprobe((h), v)); \
+ hb != HASHnil(h); \
+ hb = HASHgetlink(h,hb)) \
+ if (hb >= (lo) && hb < (hi) && \
+ ATOMcmp(h->type, v, BUNtail(bi, hb)) == 0)
+
static BAT *
BAT_hashselect(BAT *b, BAT *s, BAT *bn, const void *tl, BUN maximum)
{
BATiter bi;
BUN i, cnt;
oid o, *restrict dst;
- /* off must be signed as it can be negative,
- * e.g., if b->hseqbase == 0 and b->batFirst > 0;
- * instead of wrd, we could also use ssize_t or int/lng with
- * 32/64-bit OIDs */
- wrd off;
+ BUN l, h;
+ oid seq;
assert(bn->htype == TYPE_void);
assert(bn->ttype == TYPE_oid);
assert(BAThdense(b));
- off = b->hseqbase - b->batFirst;
+ seq = b->hseqbase;
+ if (VIEWtparent(b)) {
+ BAT *b2 = BBPdescriptor(-VIEWtparent(b));
+ l = ((b->T->heap.base - b2->T->heap.base) >> b->T->shift) +
BUNfirst(b);
+ h = l + BATcount(b);
+ b = b2;
+ } else {
+ l = BUNfirst(b);
+ h = BUNlast(b);
+ }
if (BATprepareHash(b)) {
BBPreclaim(bn);
return NULL;
@@ -188,8 +201,8 @@ BAT_hashselect(BAT *b, BAT *s, BAT *bn,
cnt = 0;
if (s) {
assert(s->tsorted);
- HASHloop(bi, b->T->hash, i, tl) {
- o = (oid) (i + off);
+ HASHloop_bound(bi, b->T->hash, i, tl, l, h) {
+ o = (oid) (i - l + seq);
if (SORTfnd(s, &o) != BUN_NONE) {
buninsfix(bn, dst, cnt, o,
maximum - BATcapacity(bn),
@@ -198,8 +211,8 @@ BAT_hashselect(BAT *b, BAT *s, BAT *bn,
}
}
} else {
- HASHloop(bi, b->T->hash, i, tl) {
- o = (oid) (i + off);
+ HASHloop_bound(bi, b->T->hash, i, tl, l, h) {
+ o = (oid) (i - l + seq);
buninsfix(bn, dst, cnt, o,
maximum - BATcapacity(bn),
maximum, NULL);
@@ -1454,9 +1467,11 @@ BATsubselect(BAT *b, BAT *s, const void
/* refine upper limit by exact size (if known) */
maximum = MIN(maximum, estimate);
hash = equi &&
- b->batPersistence == PERSISTENT &&
- (size_t) ATOMsize(b->ttype) > sizeof(BUN) / 4 &&
- BATcount(b) * (ATOMsize(b->ttype) + 2 * sizeof(BUN)) <
GDK_mem_maxsize / 2;
+ (b->batPersistence == PERSISTENT ||
+ ((parent = VIEWtparent(b)) != 0 &&
+ BBPquickdesc(abs(parent),0)->batPersistence == PERSISTENT)) &&
+ (size_t) ATOMsize(b->ttype) > sizeof(BUN) / 4 &&
+ BATcount(b) * (ATOMsize(b->ttype) + 2 * sizeof(BUN)) <
GDK_mem_maxsize / 2;
if (hash && estimate == BUN_NONE && !b->T->hash) {
/* no exact result size, but we need estimate to choose
* between hash- & scan-select */
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