Lines Matching defs:cleaner
88 * Accesses to a cache cleaner object are synchronized through
105 isc_event_t *resched_event; /*% Sent by cleaner task to
134 cache_cleaner_t cleaner;
150 isc_timermgr_t *timermgr, cache_cleaner_t *cleaner);
291 * need the control of the generic cleaner.
294 result = cache_cleaner_init(cache, NULL, NULL, &cache->cleaner);
297 &cache->cleaner);
335 if (cache->cleaner.task != NULL)
336 isc_task_detach(&cache->cleaner.task);
338 if (cache->cleaner.overmem_event != NULL)
339 isc_event_free(&cache->cleaner.overmem_event);
341 if (cache->cleaner.resched_event != NULL)
342 isc_event_free(&cache->cleaner.resched_event);
344 if (cache->cleaner.iterator != NULL)
345 dns_dbiterator_destroy(&cache->cleaner.iterator);
347 DESTROYLOCK(&cache->cleaner.lock);
410 cache->cleaner.overmem = ISC_FALSE;
429 * If the cleaner task exists, let it free the cache.
432 isc_task_shutdown(cache->cleaner.task);
519 if (cache->cleaner.cleaning_timer == NULL)
522 cache->cleaner.cleaning_interval = t;
525 result = isc_timer_reset(cache->cleaner.cleaning_timer,
529 isc_interval_set(&interval, cache->cleaner.cleaning_interval,
531 result = isc_timer_reset(cache->cleaner.cleaning_timer,
546 * Initialize the cache cleaner object at *cleaner.
552 isc_timermgr_t *timermgr, cache_cleaner_t *cleaner)
556 result = isc_mutex_init(&cleaner->lock);
560 cleaner->increment = DNS_CACHE_CLEANERINCREMENT;
561 cleaner->state = cleaner_s_idle;
562 cleaner->cache = cache;
563 cleaner->iterator = NULL;
564 cleaner->overmem = ISC_FALSE;
565 cleaner->replaceiterator = ISC_FALSE;
567 cleaner->task = NULL;
568 cleaner->cleaning_timer = NULL;
569 cleaner->resched_event = NULL;
570 cleaner->overmem_event = NULL;
572 result = dns_db_createiterator(cleaner->cache->db, ISC_FALSE,
573 &cleaner->iterator);
578 result = isc_task_create(taskmgr, 1, &cleaner->task);
586 cleaner->cache->live_tasks++;
587 isc_task_setname(cleaner->task, "cachecleaner", cleaner);
589 result = isc_task_onshutdown(cleaner->task,
593 "cache cleaner: "
599 cleaner->cleaning_interval = 0; /* Initially turned off. */
601 NULL, NULL, cleaner->task,
602 cleaning_timer_action, cleaner,
603 &cleaner->cleaning_timer);
612 cleaner->resched_event =
613 isc_event_allocate(cache->mctx, cleaner,
616 cleaner, sizeof(isc_event_t));
617 if (cleaner->resched_event == NULL) {
622 cleaner->overmem_event =
623 isc_event_allocate(cache->mctx, cleaner,
626 cleaner, sizeof(isc_event_t));
627 if (cleaner->overmem_event == NULL) {
636 if (cleaner->overmem_event != NULL)
637 isc_event_free(&cleaner->overmem_event);
638 if (cleaner->resched_event != NULL)
639 isc_event_free(&cleaner->resched_event);
640 if (cleaner->cleaning_timer != NULL)
641 isc_timer_detach(&cleaner->cleaning_timer);
642 if (cleaner->task != NULL)
643 isc_task_detach(&cleaner->task);
644 if (cleaner->iterator != NULL)
645 dns_dbiterator_destroy(&cleaner->iterator);
646 DESTROYLOCK(&cleaner->lock);
652 begin_cleaning(cache_cleaner_t *cleaner) {
655 REQUIRE(CLEANER_IDLE(cleaner));
661 if (cleaner->iterator == NULL)
662 result = dns_db_createiterator(cleaner->cache->db, ISC_FALSE,
663 &cleaner->iterator);
667 "cache cleaner could not create "
670 dns_dbiterator_setcleanmode(cleaner->iterator, ISC_TRUE);
671 result = dns_dbiterator_first(cleaner->iterator);
678 if (result != ISC_R_NOMORE && cleaner->iterator != NULL) {
680 "cache cleaner: "
683 dns_dbiterator_destroy(&cleaner->iterator);
684 } else if (cleaner->iterator != NULL) {
685 result = dns_dbiterator_pause(cleaner->iterator);
692 result = dns_dbiterator_pause(cleaner->iterator);
698 (unsigned long)isc_mem_inuse(cleaner->cache->mctx));
699 cleaner->state = cleaner_s_busy;
700 isc_task_send(cleaner->task, &cleaner->resched_event);
707 end_cleaning(cache_cleaner_t *cleaner, isc_event_t *event) {
710 REQUIRE(CLEANER_BUSY(cleaner));
713 result = dns_dbiterator_pause(cleaner->iterator);
715 dns_dbiterator_destroy(&cleaner->iterator);
717 dns_cache_setcleaninginterval(cleaner->cache,
718 cleaner->cleaning_interval);
722 (unsigned long)isc_mem_inuse(cleaner->cache->mctx));
724 cleaner->state = cleaner_s_idle;
725 cleaner->resched_event = event;
733 cache_cleaner_t *cleaner = event->ev_arg;
737 INSIST(task == cleaner->task);
742 "cleaner state = %d", cleaner->state);
744 if (cleaner->state == cleaner_s_idle)
745 begin_cleaning(cleaner);
756 cache_cleaner_t *cleaner = event->ev_arg;
761 INSIST(task == cleaner->task);
763 INSIST(cleaner->overmem_event == NULL);
767 "overmem = %d, state = %d", cleaner->overmem,
768 cleaner->state);
770 LOCK(&cleaner->lock);
772 if (cleaner->overmem) {
773 if (cleaner->state == cleaner_s_idle)
776 if (cleaner->state == cleaner_s_busy)
779 * then both cleaner->overmem_event and
780 * cleaner->resched_event will point to this
785 cleaner->state = cleaner_s_done;
788 cleaner->overmem_event = event;
790 UNLOCK(&cleaner->lock);
793 begin_cleaning(cleaner);
801 cache_cleaner_t *cleaner = event->ev_arg;
808 INSIST(task == cleaner->task);
811 if (cleaner->state == cleaner_s_done) {
812 cleaner->state = cleaner_s_busy;
813 end_cleaning(cleaner, event);
814 LOCK(&cleaner->cache->lock);
815 LOCK(&cleaner->lock);
816 if (cleaner->replaceiterator) {
817 dns_dbiterator_destroy(&cleaner->iterator);
818 (void) dns_db_createiterator(cleaner->cache->db,
820 &cleaner->iterator);
821 cleaner->replaceiterator = ISC_FALSE;
823 UNLOCK(&cleaner->lock);
824 UNLOCK(&cleaner->cache->lock);
828 INSIST(CLEANER_BUSY(cleaner));
830 n_names = cleaner->increment;
832 REQUIRE(DNS_DBITERATOR_VALID(cleaner->iterator));
838 result = dns_dbiterator_current(cleaner->iterator, &node,
842 "cache cleaner: dns_dbiterator_current() "
845 end_cleaning(cleaner, event);
853 dns_db_detachnode(cleaner->cache->db, &node);
858 result = dns_dbiterator_next(cleaner->iterator);
869 "cache cleaner: "
873 else if (cleaner->overmem) {
874 result = dns_dbiterator_first(cleaner->
881 "cache cleaner: "
888 end_cleaning(cleaner, event);
899 result = dns_dbiterator_pause(cleaner->iterator);
903 ISC_LOG_DEBUG(1), "cache cleaner: checked %u nodes, "
904 "mem inuse %lu, sleeping", cleaner->increment,
905 (unsigned long)isc_mem_inuse(cleaner->cache->mctx));
908 INSIST(CLEANER_BUSY(cleaner));
941 "cache cleaner: dns_db_expirenode() "
972 LOCK(&cache->cleaner.lock);
974 if (overmem != cache->cleaner.overmem) {
976 cache->cleaner.overmem = overmem;
980 if (cache->cleaner.overmem_event != NULL)
981 isc_task_send(cache->cleaner.task,
982 &cache->cleaner.overmem_event);
984 UNLOCK(&cache->cleaner.lock);
1025 * The cleaner task is shutting down; do the necessary cleanup.
1034 INSIST(task == cache->cleaner.task);
1037 if (CLEANER_BUSY(&cache->cleaner))
1038 end_cleaning(&cache->cleaner, event);
1055 if (cache->cleaner.cleaning_timer != NULL)
1056 isc_timer_detach(&cache->cleaner.cleaning_timer);
1077 LOCK(&cache->cleaner.lock);
1078 if (cache->cleaner.state == cleaner_s_idle) {
1079 if (cache->cleaner.iterator != NULL)
1080 dns_dbiterator_destroy(&cache->cleaner.iterator);
1082 &cache->cleaner.iterator);
1084 if (cache->cleaner.state == cleaner_s_busy)
1085 cache->cleaner.state = cleaner_s_done;
1086 cache->cleaner.replaceiterator = ISC_TRUE;
1090 UNLOCK(&cache->cleaner.lock);