mirror of
				https://github.com/isar/libmdbx.git
				synced 2025-11-01 03:48:57 +08:00 
			
		
		
		
	mdbx: refine/optimize update-gc (filter-out list of dirty-pages from loose-pages).
Change-Id: I73caa11e8a6378c307eb2e0a8199d0428dc14e05
This commit is contained in:
		| @@ -1575,37 +1575,6 @@ static __inline bool mdbx_dpl_mark4removal(MDBX_DPL dl, MDBX_page *mp) { | |||||||
|   return false; |   return false; | ||||||
| } | } | ||||||
|  |  | ||||||
| static __hot void mdbx_dpl_remove_marked(MDBX_DPL dl) { |  | ||||||
|   assert(dl->sorted <= dl->length); |  | ||||||
|   assert(dl->length <= MDBX_DPL_TXNFULL); |  | ||||||
|  |  | ||||||
|   MDBX_DPL r, w; |  | ||||||
|   const MDBX_DPL end_sorted = dl + dl->sorted; |  | ||||||
|   for (r = w = dl + 1; r <= end_sorted; r++) { |  | ||||||
|     if (r->ptr) { |  | ||||||
|       if (r != w) |  | ||||||
|         *w = *r; |  | ||||||
|       ++w; |  | ||||||
|     } |  | ||||||
|   } |  | ||||||
|   dl->sorted = (unsigned)(w - dl - 1); |  | ||||||
|  |  | ||||||
|   const MDBX_DPL end = dl + dl->length; |  | ||||||
|   for (; r <= end; r++) { |  | ||||||
|     if (r->ptr) { |  | ||||||
|       if (r != w) |  | ||||||
|         *w = *r; |  | ||||||
|       ++w; |  | ||||||
|     } |  | ||||||
|   } |  | ||||||
|   dl->length = (unsigned)(w - dl - 1); |  | ||||||
|  |  | ||||||
| #if MDBX_DEBUG |  | ||||||
|   for (const MDBX_DP *ptr = dl + dl->sorted; --ptr > dl;) |  | ||||||
|     assert(ptr[0].pgno < ptr[1].pgno); |  | ||||||
| #endif |  | ||||||
| } |  | ||||||
|  |  | ||||||
| static __inline int __must_check_result mdbx_dpl_append(MDBX_DPL dl, | static __inline int __must_check_result mdbx_dpl_append(MDBX_DPL dl, | ||||||
|                                                         pgno_t pgno, |                                                         pgno_t pgno, | ||||||
|                                                         MDBX_page *page) { |                                                         MDBX_page *page) { | ||||||
| @@ -5268,41 +5237,31 @@ retry: | |||||||
|                    dbg_prefix_mode, txn->tw.loose_count); |                    dbg_prefix_mode, txn->tw.loose_count); | ||||||
|       } |       } | ||||||
|  |  | ||||||
|       // filter-out list of dirty-pages from loose-pages |       /* filter-out list of dirty-pages from loose-pages */ | ||||||
|       MDBX_DPL dl = txn->tw.dirtylist; |       const MDBX_DPL dl = txn->tw.dirtylist; | ||||||
|       unsigned left = dl->length; |       unsigned w = 0; | ||||||
|       for (MDBX_page *mp = txn->tw.loose_pages; mp;) { |       for (unsigned r = w; ++r <= dl->length;) { | ||||||
|         mdbx_tassert(txn, mp->mp_pgno < txn->mt_next_pgno); |         MDBX_page *dp = dl[r].ptr; | ||||||
|         mdbx_ensure(env, mp->mp_pgno >= NUM_METAS); |         mdbx_tassert(txn, (dp->mp_flags & P_DIRTY)); | ||||||
|  |         mdbx_tassert(txn, dl[r].pgno + (IS_OVERFLOW(dp) ? dp->mp_pages : 1) <= | ||||||
|         if (left > 0) |                               txn->mt_next_pgno); | ||||||
|           left -= mdbx_dpl_mark4removal(dl, mp); |         if ((dp->mp_flags & P_LOOSE) == 0) { | ||||||
|  |           if (++w != r) | ||||||
|         MDBX_page *dp = mp; |             dl[w] = dl[r]; | ||||||
|         mp = mp->mp_next; |         } else { | ||||||
|  |           mdbx_tassert(txn, dp->mp_flags == (P_LOOSE | P_DIRTY)); | ||||||
|           if ((env->me_flags & MDBX_WRITEMAP) == 0) |           if ((env->me_flags & MDBX_WRITEMAP) == 0) | ||||||
|             mdbx_dpage_free(env, dp, 1); |             mdbx_dpage_free(env, dp, 1); | ||||||
|         } |         } | ||||||
|       if (left != dl->length) { |  | ||||||
|         mdbx_trace("%s: filtered-out loose-pages from %u -> %u dirty-pages", |  | ||||||
|                    dbg_prefix_mode, dl->length, left); |  | ||||||
|         txn->tw.dirtyroom += dl->length - left; |  | ||||||
|         if (!MDBX_DEBUG && unlikely(left == 0)) |  | ||||||
|           mdbx_dpl_clear(dl); |  | ||||||
|         else |  | ||||||
|           mdbx_dpl_remove_marked(dl); |  | ||||||
|         mdbx_tassert(txn, dl->length == left); |  | ||||||
|       } |       } | ||||||
|       mdbx_tassert(txn, txn->tw.dirtyroom + txn->tw.dirtylist->length == |       mdbx_trace("%s: filtered-out loose-pages from %u -> %u dirty-pages", | ||||||
|                             MDBX_DPL_TXNFULL); |                  dbg_prefix_mode, dl->length, w); | ||||||
|  |       mdbx_tassert(txn, txn->tw.loose_count == dl->length - w); | ||||||
|  |       dl->length = w; | ||||||
|  |       dl->sorted = 0; | ||||||
|  |       txn->tw.dirtyroom += txn->tw.loose_count; | ||||||
|       txn->tw.loose_pages = NULL; |       txn->tw.loose_pages = NULL; | ||||||
|       txn->tw.loose_count = 0; |       txn->tw.loose_count = 0; | ||||||
|       if (mdbx_audit_enabled()) { |  | ||||||
|         rc = mdbx_audit_ex(txn, retired_stored, false); |  | ||||||
|         if (unlikely(rc != MDBX_SUCCESS)) |  | ||||||
|           goto bailout; |  | ||||||
|       } |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     // handle retired-list - store ones into single gc-record |     // handle retired-list - store ones into single gc-record | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user