prevent repeating errors about madvise(); fixes #625
Costa Tsaousis committed
Aug 1, 2016 at 01:31 UTC
6a551b826bd3a41f365337dcc07d25b27041fa93
1 file changed
+14
-5
src/common.c
+14
-5
@@ -718,8 +718,11 @@ char *trim(char *s)
718
return s;
719
}
720
721
-void *mymmap(const char *filename, size_t size, int flags, int ksm)
722
-{
721
+void *mymmap(const char *filename, size_t size, int flags, int ksm) {
722
+ static int log_madvise_1 = 1;
723
+#ifdef MADV_MERGEABLE
724
+ static int log_madvise_2 = 1, log_madvise_3 = 1;
725
+#endif
726
int fd;
727
void *mem = NULL;
728
@@ -739,8 +742,10 @@ void *mymmap(const char *filename, size_t size, int flags, int ksm)
742
int advise = MADV_SEQUENTIAL|MADV_DONTFORK;
743
if(flags & MAP_SHARED) advise |= MADV_WILLNEED;
744
742
- if(madvise(mem, size, advise) != 0)
745
+ if(madvise(mem, size, advise) != 0 && log_madvise_1) {
746
error("Cannot advise the kernel about the memory usage of file '%s'.", filename);
747
+ log_madvise_1--;
748
+ }
749
}
750
#ifdef MADV_MERGEABLE
751
}
@@ -767,11 +772,15 @@ void *mymmap(const char *filename, size_t size, int flags, int ksm)
772
error("Cannot seek to beginning of file '%s'.", filename);
773
774
// don't use MADV_SEQUENTIAL|MADV_DONTFORK, they disable MADV_MERGEABLE
770
- if(madvise(mem, size, MADV_SEQUENTIAL|MADV_DONTFORK) != 0)
775
+ if(madvise(mem, size, MADV_SEQUENTIAL|MADV_DONTFORK) != 0 && log_madvise_2) {
776
error("Cannot advise the kernel about the memory usage (MADV_SEQUENTIAL|MADV_DONTFORK) of file '%s'.", filename);
777
+ log_madvise_2--;
778
+ }
779
773
- if(madvise(mem, size, MADV_MERGEABLE) != 0)
780
+ if(madvise(mem, size, MADV_MERGEABLE) != 0 && log_madvise_3) {
781
error("Cannot advise the kernel about the memory usage (MADV_MERGEABLE) of file '%s'.", filename);
782
+ log_madvise_3--;
783
+ }
784
}
785
else
786
error("Cannot allocate PRIVATE ANONYMOUS memory for KSM for file '%s'.", filename);