Lines Matching refs:db

107 gc (struct database_dyn *db)  in gc()  argument
110 pthread_rwlock_wrlock (&db->lock); in gc()
113 pthread_mutex_lock (&db->memlock); in gc()
119 assert (db->head->first_free % BLOCK_ALIGN == 0); in gc()
125 size_t stack_used = sizeof (bool) * db->head->module; in gc()
128 size_t nmark = (db->head->first_free / BLOCK_ALIGN + BITS - 1) / BITS; in gc()
144 memory_needed = 2 * db->head->nentries * sizeof (struct hashentry *); in gc()
158 he_data = &he[db->head->nentries]; in gc()
161 for (size_t idx = 0; idx < db->head->module; ++idx) in gc()
163 ref_t *prevp = &db->head->array[idx]; in gc()
168 assert (cnt < db->head->nentries); in gc()
169 he[cnt] = (struct hashentry *) (db->data + run); in gc()
182 = (struct datahead *) (db->data + he[cnt]->packet); in gc()
191 assert (cnt == db->head->nentries); in gc()
215 db->head->first_free = 0; in gc()
248 assert (off_free <= db->head->first_free); in gc()
255 while (next_hash < &he[db->head->nentries] in gc()
256 && *next_hash < (struct hashentry *) (db->data + off_free)) in gc()
259 while (next_data < &he_data[db->head->nentries] in gc()
266 atomic_fetch_add_relaxed (&db->head->gc_cycle, 1); in gc()
267 assert ((db->head->gc_cycle & 1) == 1); in gc()
308 assert (off_alloc <= db->head->first_free); in gc()
332 assert (off_allocend <= db->head->first_free); in gc()
345 new_move->from = db->data + off_alloc; in gc()
346 new_move->to = db->data + off_free; in gc()
364 if ((struct hashentry *) (db->data + off_alloc) == *next_hash) in gc()
374 assert (next_data < &he_data[db->head->nentries]); in gc()
377 struct datahead *dh = (struct datahead *) (db->data + off_alloc); in gc()
388 while (next_data < &he_data[db->head->nentries] in gc()
396 assert (off_alloc <= db->head->first_free); in gc()
397 if (off_alloc == db->head->first_free) in gc()
401 assert (next_hash == &he[db->head->nentries]); in gc()
402 assert (next_data == &he_data[db->head->nentries]); in gc()
410 assert ((char *) runp->to >= db->data); in gc()
412 <= db->data + db->head->first_free); in gc()
413 assert ((char *) runp->from >= db->data); in gc()
415 <= db->data + db->head->first_free); in gc()
425 (size_t) (db->head->first_free in gc()
426 - ((char *) moves->to + moves->size - db->data)), in gc()
427 dbnames[db - dbs]); in gc()
431 db->head->first_free = (char *) moves->to + moves->size - db->data; in gc()
436 for (size_t idx = 0; idx < db->head->module; ++idx) in gc()
438 ref_t run = db->head->array[idx]; in gc()
443 if (run + sizeof (struct hashentry) > db->head->first_free) in gc()
448 (size_t) db->head->first_free); in gc()
452 struct hashentry *he = (struct hashentry *) (db->data + run); in gc()
454 if (he->key + he->len > db->head->first_free) in gc()
458 (size_t) db->head->first_free); in gc()
461 > db->head->first_free) in gc()
465 (size_t) db->head->first_free); in gc()
468 struct datahead *dh = (struct datahead *) (db->data in gc()
471 > db->head->first_free) in gc()
475 (size_t) db->head->first_free); in gc()
486 if (db->persistent) in gc()
487 msync (db->head, db->data + db->head->first_free - (char *) db->head, in gc()
492 atomic_fetch_add_relaxed (&db->head->gc_cycle, 1); in gc()
493 assert ((db->head->gc_cycle & 1) == 0); in gc()
497 pthread_mutex_unlock (&db->memlock); in gc()
498 pthread_rwlock_unlock (&db->lock); in gc()
510 mempool_alloc (struct database_dyn *db, size_t len, int data_alloc) in mempool_alloc() argument
518 pthread_rwlock_rdlock (&db->lock); in mempool_alloc()
520 pthread_mutex_lock (&db->memlock); in mempool_alloc()
522 assert ((db->head->first_free & BLOCK_ALIGN_M1) == 0); in mempool_alloc()
527 res = db->data + db->head->first_free; in mempool_alloc()
529 if (__glibc_unlikely (db->head->first_free + len > db->head->data_size)) in mempool_alloc()
535 + roundup (db->head->module * sizeof (ref_t), in mempool_alloc()
537 + db->head->data_size); in mempool_alloc()
538 size_t new_data_size = (db->head->data_size in mempool_alloc()
539 + MAX (2 * len, db->head->data_size / 8)); in mempool_alloc()
541 + roundup (db->head->module * sizeof (ref_t), ALIGN) in mempool_alloc()
543 if (newtotal > db->max_db_size) in mempool_alloc()
545 new_data_size -= newtotal - db->max_db_size; in mempool_alloc()
546 newtotal = db->max_db_size; in mempool_alloc()
549 if (db->mmap_used && newtotal > oldtotal in mempool_alloc()
552 && TEMP_FAILURE_RETRY_VAL (posix_fallocate (db->wr_fd, oldtotal, in mempool_alloc()
556 db->head->data_size = new_data_size; in mempool_alloc()
563 pthread_rwlock_unlock (&db->lock); in mempool_alloc()
565 if (! db->last_alloc_failed) in mempool_alloc()
567 dbg_log (_("no more memory for database '%s'"), dbnames[db - dbs]); in mempool_alloc()
569 db->last_alloc_failed = true; in mempool_alloc()
572 ++db->head->addfailed; in mempool_alloc()
579 db->head->first_free += len; in mempool_alloc()
581 db->last_alloc_failed = false; in mempool_alloc()
585 pthread_mutex_unlock (&db->memlock); in mempool_alloc()