I am trying to make some changes to the source code of sqlite. As I found there will be a little improvement if I support MMAP to wal file. I guess the optimization is micro but it is useful in my test and this is a good way for me to study the code of sqlite :D
1.wal+mmap I could use unixMapfile() to map the wal file while MMAP may cause SIGBUS if the mapped file is truncated. This could happen when reseting the wal file, in another word, if journal_size_limit is reached or SQLITE_CHECKPOINT_TRUNCATE is called. But I guess it works if these two APIs will always not be called in my application. So, I want to create file holes to get a 4M wal-file in sqlite3WalOpen(), and always set journal_size_limit to 4M. Then mmap will be supported by simply calling unixMapfile(4M) in sqlite3WalOpen(). After that, memcpy() instead of read() will be used when read the first 4M of wal file. I am wondering if it is all right in my Android applications? 2.Further more. I know mmap is supported when fetching db file: To map file: In getPageMMap(), sqlite3OsFetch() MMAPs the whole db file, and return the mapped page through *pData. Then pagerAcquireMapPage will obtain a page reference PgHdr based on the pData. (A small question here, why pData is needed? As xRead() will always use memcpy instead of read() after unixMapfile(-1) is called.) sqlite3OsFileControlHint is called to remap the db file when the db grows as a result of a checkpoint. To avoid SIGBUS: Process will catch the CHANGE of other processes by comparing pWal->hdr.iChange and the corresponding number in wal-index. Whenever a read, write or checkpoint operation happens, unixUnmapfile() will be called if there is a CHANGE. 3.Thus another way of wal+mmap: I want to use pWal->hdr.unused to catch the CHANGE when other process truncate the wal file(journal_size_limit or SQLITE_CHECKPOINT_TRUNCATE). Then I will check the hdr.unused to call unixMapfile(-1) before whenever sqlite3OsRead(pWal->pWalFd) is called. Is there a better timing to remap the file? Just like sqlite3WalBeginReadTransaction and walcheckpoint in db+mmap; I run sqlite test to check my code, but I find pVfs->szOsFile is 16 when test_vfs.c is called, which means pRet->pWalFd is no longer a unixFile struct. At this time, sqlite3OsOpen() binds to tvfsOpen() instead of unixOpen(). So I cannot use unixMapfile() and the test that uses test_vfs.c will not pass. So could you give me some advices to pass the test? Thank you. -- Sent from: http://sqlite.1065341.n5.nabble.com/ _______________________________________________ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users