- Timestamp:
- Nov 20, 2008, 9:39:06 PM (16 years ago)
- Location:
- trunk/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/sh_port2proc.c
r195 r196 555 555 556 556 buf = NULL; 557 bufsize = 1000;557 bufsize = 8192; 558 558 bufsize0 = bufsize; 559 559 retry = 5; -
trunk/src/sh_readconf.c
r194 r196 892 892 #endif 893 893 894 { N_("setdropcache"), SH_SECTION_MISC, SH_SECTION_NONE, 895 sl_set_drop_cache }, 896 894 897 { N_("setiolimit"), SH_SECTION_MISC, SH_SECTION_NONE, 895 898 sh_unix_set_io_limit }, -
trunk/src/slib.c
r192 r196 1 1 #include "config_xor.h" 2 2 3 #if defined(HAVE_POSIX_FADVISE) && defined(HAVE_MINCORE) 4 #define _XOPEN_SOURCE 600 5 #define _BSD_SOURCE 6 #endif 3 7 4 8 #include <stdio.h> … … 17 21 #include <fcntl.h> 18 22 #include <signal.h> 23 24 #if defined(HAVE_POSIX_FADVISE) && defined(HAVE_MINCORE) 25 #include <sys/mman.h> 26 #endif 19 27 20 28 #if TIME_WITH_SYS_TIME … … 1542 1550 int fd; /* The file descriptor. */ 1543 1551 char * path; /* The file path. */ 1552 int flush; /* Whether we want to flush the cache */ 1544 1553 sh_string * content; /* The file content */ 1545 1554 } SL_OFILE; … … 1666 1675 ofiles[fd]->fd = fd; 1667 1676 ofiles[fd]->content = NULL; 1677 ofiles[fd]->flush = SL_FALSE; 1668 1678 1669 1679 SL_IRETURN(ticket, _("sl_make_ticket")); … … 1928 1938 ofiles[fd]->fd = fd; 1929 1939 ofiles[fd]->content = NULL; 1940 ofiles[fd]->flush = SL_FALSE; 1930 1941 1931 1942 SL_IRETURN(ticket, _("sl_open_file")); 1943 } 1944 1945 int get_the_fd (SL_TICKET ticket) 1946 { 1947 int fd; 1948 1949 if (SL_ISERROR(fd = sl_read_ticket(ticket))) 1950 return (fd); 1951 1952 if (ofiles[fd] == NULL || fd != ofiles[fd]->fd || fd < 0) 1953 return (SL_EINTERNAL); 1954 return (fd); 1932 1955 } 1933 1956 … … 1972 1995 } 1973 1996 1997 #if defined(HAVE_POSIX_FADVISE) && defined(HAVE_MINCORE) && defined(POSIX_FADV_DONTNEED) 1998 static int sl_check_mincore(int fd) 1999 { 2000 /* Idea from Tobias Oetiker (http://insights.oetiker.ch/linux/fadvise.html) 2001 */ 2002 struct stat fbuf; 2003 int retval = -1; 2004 2005 if (0 == fstat(fd, &fbuf)) 2006 { 2007 void *f_map; 2008 2009 f_map = mmap((void *)0, fbuf.st_size, PROT_NONE, MAP_SHARED, fd, 0); 2010 if (MAP_FAILED != f_map) 2011 { 2012 extern int sh_unix_pagesize(void); 2013 size_t i; 2014 size_t page_size = sh_unix_pagesize(); 2015 size_t vec_size = (fbuf.st_size+page_size-1)/page_size; 2016 unsigned char * vec = calloc(1, vec_size); 2017 2018 if (vec) 2019 { 2020 mincore(f_map, fbuf.st_size, vec); 2021 // imax = fbuf.st_size/page_size; 2022 for (i = 0; i <= vec_size; ++i) 2023 { 2024 if (vec[i]&1) 2025 { 2026 goto incore; 2027 } 2028 } 2029 retval = 0; 2030 incore: 2031 free(vec); 2032 } 2033 munmap(f_map, fbuf.st_size); 2034 } 2035 } 2036 return retval; 2037 } 2038 #endif 2039 2040 static int sl_drop_cache = SL_FALSE; 2041 2042 int sl_set_drop_cache(const char * str) 2043 { 2044 extern int sh_util_flagval(const char * c, int * fval); 2045 return sh_util_flagval(str, &sl_drop_cache); 2046 } 2047 1974 2048 SL_TICKET sl_open_fastread (const char * fname, int priv) 1975 2049 { … … 1981 2055 1982 2056 status = sl_open_file(fname, SL_OPEN_FOR_FASTREAD, priv); 2057 2058 #if defined(HAVE_POSIX_FADVISE) && defined(HAVE_MINCORE) && defined(POSIX_FADV_DONTNEED) 2059 2060 if (SL_FALSE != sl_drop_cache && !SL_ISERROR(status)) 2061 { 2062 int fd = get_the_fd(status); 2063 if (fd >= 0) 2064 { 2065 if (0 == sl_check_mincore(fd)) 2066 ofiles[fd]->flush = SL_TRUE; 2067 } 2068 } 2069 2070 #endif 2071 1983 2072 SL_IRETURN(status, _("sl_open_fastread")); 1984 2073 } … … 2032 2121 } 2033 2122 2034 2035 int get_the_fd (SL_TICKET ticket)2036 {2037 int fd;2038 2039 if (SL_ISERROR(fd = sl_read_ticket(ticket)))2040 return (fd);2041 2042 if (ofiles[fd] == NULL || fd != ofiles[fd]->fd || fd < 0)2043 return (SL_EINTERNAL);2044 return (fd);2045 }2046 2123 2047 2124 int sl_init_content (SL_TICKET ticket, size_t size) … … 2083 2160 if (SL_ISERROR(fd = get_the_fd (ticket))) 2084 2161 SL_IRETURN(fd, _("sl_close")); 2162 2163 #if defined(HAVE_POSIX_FADVISE) && defined(HAVE_MINCORE) && defined(POSIX_FADV_DONTNEED) 2164 2165 if (ofiles[fd]->flush == SL_TRUE) 2166 { 2167 posix_fadvise(fd, 0, 0, POSIX_FADV_DONTNEED); 2168 } 2169 2170 #endif 2085 2171 2086 2172 /* This may fail, but what to do then ?
Note:
See TracChangeset
for help on using the changeset viewer.