//#define ONE_PAGE 1
/* Avoid calling madvise on areas that were already hinted. May be benefical if
* your syscalls are very slow */
-//#define CHECK_MADVISE_OVERLAPS 1
+#define CHECK_MADVISE_OVERLAPS 1
#ifdef HAVE_MMAP
+/* the cast to void* is there to avoid this warning seen on ia64 with certain
+ versions of gcc: 'cast increases required alignment of target type'
+*/
#define __rrd_read(dst, dst_t, cnt) \
- (dst) = (dst_t*) (data + offset); \
+ (dst) = (dst_t*)(void*) (data + offset); \
offset += sizeof(dst_t) * (cnt)
#else
#define __rrd_read(dst, dst_t, cnt) \
if ((rrd_file->fd = open(file_name, flags, mode)) < 0) {
rrd_set_error("opening '%s': %s", file_name, rrd_strerror(errno));
- return NULL;
+ goto out_free;
}
/* Better try to avoid seeks as much as possible. stat may be heavy but
/* lets see if the first read worked */
if (data == MAP_FAILED) {
- rrd_set_error("error mmaping file '%s': %s", file_name,
+ rrd_set_error("mmaping file '%s': %s", file_name,
rrd_strerror(errno));
goto out_close;
}
_madvise(data, rrd_file->file_len, MADV_WILLNEED | MADV_SEQUENTIAL);
goto out_done;
}
+# ifndef ONE_PAGE
/* We do not need to read anything in for the moment */
-#ifndef ONE_PAGE
_madvise(data, rrd_file->file_len, MADV_DONTNEED);
-// _madvise(data, rrd_file->file_len, MADV_RANDOM);
-#else
-/* alternatively: keep 2 pages worth of data, likely headers,
+# else
+/* alternatively: keep 1 page worth of data, likely headers,
* don't need the rest. */
_madvise(data, _page_size, MADV_WILLNEED | MADV_SEQUENTIAL);
_madvise(data + _page_size, (rrd_file->file_len >= _page_size)
? rrd_file->file_len - _page_size : 0, MADV_DONTNEED);
-#endif
+# endif
#endif
#if defined USE_MADVISE && !defined ONE_PAGE
/* the stat_head will be needed soonish, so hint accordingly */
-// too finegrained to calc the individual sizes, just keep 2 pages worth of hdr
_madvise(data + PAGE_ALIGN_DOWN(offset), PAGE_ALIGN(sizeof(stat_head_t)),
- MADV_WILLNEED);
+ MADV_WILLNEED | MADV_RANDOM);
#endif
}
if (rrd->stat_head->float_cookie != FLOAT_COOKIE) {
- rrd_set_error("This RRD was created on other architecture");
+ rrd_set_error("This RRD was created on another architecture");
goto out_nullify_head;
}
rrd->stat_head = NULL;
out_close:
close(rrd_file->fd);
+ out_free:
+ free(rrd_file);
return NULL;
}