Index: trunk/src/sh_port2proc.c
===================================================================
--- trunk/src/sh_port2proc.c	(revision 195)
+++ trunk/src/sh_port2proc.c	(revision 196)
@@ -555,5 +555,5 @@
 
         buf = NULL;
-        bufsize  = 1000;
+        bufsize  = 8192;
 	bufsize0 = bufsize;
         retry = 5;
Index: trunk/src/sh_readconf.c
===================================================================
--- trunk/src/sh_readconf.c	(revision 195)
+++ trunk/src/sh_readconf.c	(revision 196)
@@ -892,4 +892,7 @@
 #endif
 
+  { N_("setdropcache"),   SH_SECTION_MISC,   SH_SECTION_NONE, 
+    sl_set_drop_cache },
+
   { N_("setiolimit"),   SH_SECTION_MISC,   SH_SECTION_NONE, 
     sh_unix_set_io_limit },
Index: trunk/src/slib.c
===================================================================
--- trunk/src/slib.c	(revision 195)
+++ trunk/src/slib.c	(revision 196)
@@ -1,4 +1,8 @@
 #include "config_xor.h"
 
+#if defined(HAVE_POSIX_FADVISE) && defined(HAVE_MINCORE)
+#define _XOPEN_SOURCE 600
+#define _BSD_SOURCE
+#endif
 
 #include <stdio.h>
@@ -17,4 +21,8 @@
 #include <fcntl.h>
 #include <signal.h>
+
+#if defined(HAVE_POSIX_FADVISE) && defined(HAVE_MINCORE)
+#include <sys/mman.h>
+#endif
 
 #if TIME_WITH_SYS_TIME
@@ -1542,4 +1550,5 @@
   int fd;               /* The file descriptor. */
   char * path;          /* The file path.       */
+  int flush;            /* Whether we want to flush the cache */
   sh_string * content;  /* The file content     */
 } SL_OFILE; 
@@ -1666,4 +1675,5 @@
   ofiles[fd]->fd      = fd;
   ofiles[fd]->content = NULL;
+  ofiles[fd]->flush   = SL_FALSE;
 
   SL_IRETURN(ticket, _("sl_make_ticket"));
@@ -1928,6 +1938,19 @@
   ofiles[fd]->fd      = fd;
   ofiles[fd]->content = NULL;
+  ofiles[fd]->flush   = SL_FALSE;
 
   SL_IRETURN(ticket, _("sl_open_file"));
+}
+
+int get_the_fd (SL_TICKET ticket)
+{
+  int fd;
+
+  if (SL_ISERROR(fd = sl_read_ticket(ticket)))
+    return (fd);
+
+  if (ofiles[fd] == NULL || fd != ofiles[fd]->fd || fd < 0)
+    return (SL_EINTERNAL);
+  return (fd);
 }
 
@@ -1972,4 +1995,55 @@
 }
 
+#if defined(HAVE_POSIX_FADVISE) && defined(HAVE_MINCORE) && defined(POSIX_FADV_DONTNEED)
+static int sl_check_mincore(int fd)
+{
+  /* Idea from Tobias Oetiker (http://insights.oetiker.ch/linux/fadvise.html)
+   */
+  struct stat fbuf;
+  int retval = -1;
+
+  if (0 == fstat(fd, &fbuf))
+    {
+      void *f_map;
+      
+      f_map = mmap((void *)0, fbuf.st_size, PROT_NONE, MAP_SHARED, fd, 0);
+      if (MAP_FAILED != f_map)
+	{
+	  extern int sh_unix_pagesize(void);
+	  size_t i;
+	  size_t page_size    = sh_unix_pagesize();
+	  size_t vec_size     = (fbuf.st_size+page_size-1)/page_size;
+	  unsigned char * vec = calloc(1, vec_size);
+
+	  if (vec)
+	    {
+	      mincore(f_map, fbuf.st_size, vec);
+	      // imax = fbuf.st_size/page_size;
+	      for (i = 0; i <= vec_size; ++i)
+		{
+		  if (vec[i]&1)
+		    {
+		      goto incore;
+		    }
+		}
+	      retval = 0;
+	    incore:
+	      free(vec);
+	    }
+	  munmap(f_map, fbuf.st_size);
+	}
+    }
+  return retval;
+}
+#endif
+
+static int sl_drop_cache = SL_FALSE;
+
+int sl_set_drop_cache(const char * str)
+{
+  extern int sh_util_flagval(const char * c, int * fval);
+  return sh_util_flagval(str, &sl_drop_cache);
+}
+
 SL_TICKET sl_open_fastread (const char * fname, int priv)
 {
@@ -1981,4 +2055,19 @@
 
   status = sl_open_file(fname, SL_OPEN_FOR_FASTREAD, priv);
+
+#if defined(HAVE_POSIX_FADVISE) && defined(HAVE_MINCORE) && defined(POSIX_FADV_DONTNEED)
+
+  if (SL_FALSE != sl_drop_cache && !SL_ISERROR(status))
+    {
+      int fd = get_the_fd(status);
+      if (fd >= 0)
+	{
+	  if (0 == sl_check_mincore(fd))
+	    ofiles[fd]->flush = SL_TRUE;
+	}
+    }
+
+#endif
+
   SL_IRETURN(status, _("sl_open_fastread"));
 }
@@ -2032,16 +2121,4 @@
 }
 
-
-int get_the_fd (SL_TICKET ticket)
-{
-  int fd;
-
-  if (SL_ISERROR(fd = sl_read_ticket(ticket)))
-    return (fd);
-
-  if (ofiles[fd] == NULL || fd != ofiles[fd]->fd || fd < 0)
-    return (SL_EINTERNAL);
-  return (fd);
-}
 
 int sl_init_content (SL_TICKET ticket, size_t size)
@@ -2083,4 +2160,13 @@
   if (SL_ISERROR(fd = get_the_fd (ticket)))
     SL_IRETURN(fd, _("sl_close"));
+
+#if defined(HAVE_POSIX_FADVISE) && defined(HAVE_MINCORE) && defined(POSIX_FADV_DONTNEED)
+
+  if (ofiles[fd]->flush == SL_TRUE)
+    {
+      posix_fadvise(fd, 0, 0, POSIX_FADV_DONTNEED);
+    }
+
+#endif
 
   /* This may fail, but what to do then ?
