+
+int
+mansearch_setup(int start)
+{
+ static void *pagecache;
+ int c;
+
+#define PC_PAGESIZE 1280
+#define PC_NUMPAGES 256
+
+ if (start) {
+ if (NULL != pagecache) {
+ warnx("pagecache already enabled");
+ return (int)MANDOCLEVEL_BADARG;
+ }
+
+ pagecache = mmap(NULL, PC_PAGESIZE * PC_NUMPAGES,
+ PROT_READ | PROT_WRITE,
+ MAP_SHARED | MAP_ANON, -1, 0);
+
+ if (MAP_FAILED == pagecache) {
+ warn("mmap");
+ pagecache = NULL;
+ return (int)MANDOCLEVEL_SYSERR;
+ }
+
+ c = sqlite3_config(SQLITE_CONFIG_PAGECACHE,
+ pagecache, PC_PAGESIZE, PC_NUMPAGES);
+
+ if (SQLITE_OK == c)
+ return (int)MANDOCLEVEL_OK;
+
+ warnx("pagecache: %s", sqlite3_errstr(c));
+
+ } else if (NULL == pagecache) {
+ warnx("pagecache missing");
+ return (int)MANDOCLEVEL_BADARG;
+ }
+
+ if (-1 == munmap(pagecache, PC_PAGESIZE * PC_NUMPAGES)) {
+ warn("munmap");
+ pagecache = NULL;
+ return (int)MANDOCLEVEL_SYSERR;
+ }
+
+ pagecache = NULL;
+ return (int)MANDOCLEVEL_OK;
+}
+