Reduce overhead during write io (#6964)
* Reduce CPU overhead when flushing dirty pages to disk
Markos Fountoulakis committed
Sep 28, 2019 at 08:22 UTC
5b6eaefac5e2ba7d27976d66716fbb794dd3fa2a
1 file changed
+12
-12
database/engine/rrdengine.c
+12
-12
@@ -253,13 +253,10 @@ void flush_pages_cb(uv_fs_t* req)
253
{
254
struct rrdengine_worker_config* wc = req->loop->data;
255
struct rrdengine_instance *ctx = wc->ctx;
256
- struct page_cache *pg_cache = &ctx->pg_cache;
256
struct extent_io_descriptor *xt_io_descr;
257
struct rrdeng_page_descr *descr;
258
struct page_cache_descr *pg_cache_descr;
260
- int ret;
259
unsigned i, count;
262
- Word_t commit_id;
260
261
xt_io_descr = req->data;
262
if (req->result < 0) {
@@ -279,13 +276,6 @@ void flush_pages_cb(uv_fs_t* req)
276
/* care, we don't hold the descriptor mutex */
277
descr = xt_io_descr->descr_array[i];
278
282
- uv_rwlock_wrlock(&pg_cache->commited_page_index.lock);
283
- commit_id = xt_io_descr->descr_commit_idx_array[i];
284
- ret = JudyLDel(&pg_cache->commited_page_index.JudyL_array, commit_id, PJE0);
285
- assert(1 == ret);
286
- --pg_cache->commited_page_index.nr_commited_pages;
287
- uv_rwlock_wrunlock(&pg_cache->commited_page_index.lock);
288
-
279
pg_cache_replaceQ_insert(ctx, descr);
280
281
rrdeng_page_descr_mutex_lock(ctx, descr);
@@ -333,7 +323,7 @@ static int do_flush_pages(struct rrdengine_worker_config* wc, int force, struct
323
if (force) {
324
debug(D_RRDENGINE, "Asynchronous flushing of extent has been forced by page pressure.");
325
}
336
- uv_rwlock_rdlock(&pg_cache->commited_page_index.lock);
326
+ uv_rwlock_wrlock(&pg_cache->commited_page_index.lock);
327
for (Index = 0, count = 0, uncompressed_payload_length = 0,
328
PValue = JudyLFirst(pg_cache->commited_page_index.JudyL_array, &Index, PJE0),
329
descr = unlikely(NULL == PValue) ? NULL : *PValue ;
@@ -342,11 +332,15 @@ static int do_flush_pages(struct rrdengine_worker_config* wc, int force, struct
332
333
PValue = JudyLNext(pg_cache->commited_page_index.JudyL_array, &Index, PJE0),
334
descr = unlikely(NULL == PValue) ? NULL : *PValue) {
335
+ uint8_t page_write_pending;
336
+
337
assert(0 != descr->page_length);
338
+ page_write_pending = 0;
339
340
rrdeng_page_descr_mutex_lock(ctx, descr);
341
pg_cache_descr = descr->pg_cache_descr;
342
if (!(pg_cache_descr->flags & RRD_PAGE_WRITE_PENDING)) {
343
+ page_write_pending = 1;
344
/* care, no reference being held */
345
pg_cache_descr->flags |= RRD_PAGE_WRITE_PENDING;
346
uncompressed_payload_length += descr->page_length;
@@ -354,8 +348,14 @@ static int do_flush_pages(struct rrdengine_worker_config* wc, int force, struct
348
eligible_pages[count++] = descr;
349
}
350
rrdeng_page_descr_mutex_unlock(ctx, descr);
351
+
352
+ if (page_write_pending) {
353
+ ret = JudyLDel(&pg_cache->commited_page_index.JudyL_array, Index, PJE0);
354
+ assert(1 == ret);
355
+ --pg_cache->commited_page_index.nr_commited_pages;
356
+ }
357
}
358
- uv_rwlock_rdunlock(&pg_cache->commited_page_index.lock);
358
+ uv_rwlock_wrunlock(&pg_cache->commited_page_index.lock);
359
360
if (!count) {
361
debug(D_RRDENGINE, "%s: no pages eligible for flushing.", __func__);