From: drh <> Date: Mon, 27 Feb 2023 21:53:44 +0000 (+0000) Subject: Make the "unref" operation on database pages a method which is part of the X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fheads%2Funref-opt;p=thirdparty%2Fsqlite.git Make the "unref" operation on database pages a method which is part of the PgHdr object. This is a potential performance optimization. FossilOrigin-Name: 37c5c8aa0ed93a39169f26297c4c145224e7f612260aed010c2e6add5a99d03d --- diff --git a/manifest b/manifest index 3f9b6c68df..3ba9073cf2 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Minor\sperformance\soptimization\sin\sthe\scomputation\sof\san\saffinity\sstring\nfor\san\sindex. -D 2023-02-27T18:55:37.933 +C Make\sthe\s"unref"\soperation\son\sdatabase\spages\sa\smethod\swhich\sis\spart\sof\sthe\nPgHdr\sobject.\s\sThis\sis\sa\spotential\sperformance\soptimization. +D 2023-02-27T21:53:44.955 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -609,11 +609,11 @@ F src/os_setup.h 6011ad7af5db4e05155f385eb3a9b4470688de6f65d6166b8956e58a3d87210 F src/os_unix.c 90c4fa0a88c8b0817c7ce4dbea0ac3aebfd7deb0797945ac34dfd25006ba393a F src/os_win.c 295fe45f18bd86f2477f4cd79f3377c6f883ceb941b1f46808665c73747f2345 F src/os_win.h 7b073010f1451abe501be30d12f6bc599824944a -F src/pager.c 39af8ff7c73a991f61f4d1e3a6f8f98b1c8e29144723507822774cac5e6ee0b5 +F src/pager.c b056782430e5f93db75e884d91dde1fbbb56109c7a8c1d75b7dc1ef0f35440dd F src/pager.h f82e9844166e1585f5786837ddc7709966138ced17f568c16af7ccf946c2baa3 F src/parse.y 960d2da92a23f8ba2ca22748a51bd75ee2c575564f2cbc59f119640e7f5b4c5d F src/pcache.c f4268f7f73c6a3db12ce22fd25bc68dc42315d19599414ab1207d7cf32f79197 -F src/pcache.h 4f87acd914cef5016fae3030343540d75f5b85a1877eed1a2a19b9f284248586 +F src/pcache.h 1ecc890f77edec796f6ab31c7bee576243a31d9ed1208ae06ff37cd7b3c89b77 F src/pcache1.c dee95e3cd2b61e6512dc814c5ab76d5eb36f0bfc9441dbb4260fccc0d12bbddc F src/pragma.c 82d5090a35eac75876d3b41f48d06b2370553c9576bf2942233c462e03eb94c9 F src/pragma.h e690a356c18e98414d2e870ea791c1be1545a714ba623719deb63f7f226d8bb7 @@ -2047,8 +2047,11 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 18ee689de3d1ae43b05ca52e0b62c49442ebf68a88814a7c679e8856250a4b0d -R eb05b938ae3801da35ea0ed3c7e2ba02 +P 07334aa17b6ded27c5bd353998d96645a94cdcf32440abb59d127a002cd98ce9 +R 884ad767d802c01a8177e09c501a4836 +T *branch * unref-opt +T *sym-unref-opt * +T -sym-trunk * U drh -Z 906f03c389d933535de5a426ca60838f +Z f513eba7828052324439b98223896c77 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 3a4fc9a3f7..277fc2b26c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -07334aa17b6ded27c5bd353998d96645a94cdcf32440abb59d127a002cd98ce9 \ No newline at end of file +37c5c8aa0ed93a39169f26297c4c145224e7f612260aed010c2e6add5a99d03d \ No newline at end of file diff --git a/src/pager.c b/src/pager.c index 89073b8c78..4c49a73381 100644 --- a/src/pager.c +++ b/src/pager.c @@ -3990,6 +3990,20 @@ static int pagerSyncHotJournal(Pager *pPager){ return rc; } +/* +** Release a reference to page pPg. pPg must have been returned by an +** earlier call to pagerAcquireMapPage(). +*/ +static void pagerReleaseMapPage(PgHdr *pPg){ + Pager *pPager = pPg->pPager; + pPager->nMmapOut--; + pPg->pDirty = pPager->pMmapFreelist; + pPager->pMmapFreelist = pPg; + + assert( pPager->fd->pMethods->iVersion>=3 ); + sqlite3OsUnfetch(pPager->fd, (i64)(pPg->pgno-1)*pPager->pageSize, pPg->pData); +} + #if SQLITE_MAX_MMAP_SIZE>0 /* ** Obtain a reference to a memory mapped page object for page number pgno. @@ -4023,6 +4037,7 @@ static int pagerAcquireMapPage( } p->pExtra = (void *)&p[1]; p->flags = PGHDR_MMAP; + p->xUnref = pagerReleaseMapPage; p->nRef = 1; p->pPager = pPager; } @@ -4030,6 +4045,7 @@ static int pagerAcquireMapPage( assert( p->pExtra==(void *)&p[1] ); assert( p->pPage==0 ); assert( p->flags==PGHDR_MMAP ); + assert( p->xUnref==pagerReleaseMapPage ); assert( p->pPager==pPager ); assert( p->nRef==1 ); @@ -4041,20 +4057,6 @@ static int pagerAcquireMapPage( } #endif -/* -** Release a reference to page pPg. pPg must have been returned by an -** earlier call to pagerAcquireMapPage(). -*/ -static void pagerReleaseMapPage(PgHdr *pPg){ - Pager *pPager = pPg->pPager; - pPager->nMmapOut--; - pPg->pDirty = pPager->pMmapFreelist; - pPager->pMmapFreelist = pPg; - - assert( pPager->fd->pMethods->iVersion>=3 ); - sqlite3OsUnfetch(pPager->fd, (i64)(pPg->pgno-1)*pPager->pageSize, pPg->pData); -} - /* ** Free all PgHdr objects stored in the Pager.pMmapFreelist list. */ @@ -5517,6 +5519,7 @@ static int getPageNormal( } pPg->pPager = pPager; + pPg->xUnref = sqlite3PcacheRelease; assert( !isOpen(pPager->fd) || !MEMDB ); if( !isOpen(pPager->fd) || pPager->dbSizepPager; ) assert( pPg!=0 ); - if( pPg->flags & PGHDR_MMAP ){ - assert( pPg->pgno!=1 ); /* Page1 is never memory mapped */ - pagerReleaseMapPage(pPg); - }else{ - sqlite3PcacheRelease(pPg); - } + assert( (pPg->flags & PGHDR_MMAP)==0 || pPg->xUnref==pagerReleaseMapPage ); + assert( (pPg->flags & PGHDR_MMAP)!=0 || pPg->xUnref==sqlite3PcacheRelease ); + pPg->xUnref(pPg); /* Do not use this routine to release the last reference to page1 */ assert( sqlite3PcacheRefCount(pPager->pPCache)>0 ); } diff --git a/src/pcache.h b/src/pcache.h index eb55396afa..620b55fc31 100644 --- a/src/pcache.h +++ b/src/pcache.h @@ -29,6 +29,7 @@ struct PgHdr { PCache *pCache; /* PRIVATE: Cache that owns this page */ PgHdr *pDirty; /* Transient list of dirty sorted by pgno */ Pager *pPager; /* The pager this page is part of */ + void (*xUnref)(PgHdr*); /* Release function */ Pgno pgno; /* Page number for this page */ #ifdef SQLITE_CHECK_PAGES u32 pageHash; /* Hash of page content */