    OVS_REQUIRES(ctb->lock)
{
    struct conn *conn, *next;
    long long min_expiration = LLONG_MAX;
    unsigned i;
    size_t count = 0;

    for (i = 0; i < N_CT_TM; i++) {
        LIST_FOR_EACH_SAFE (conn, next, exp_node, &ctb->exp_lists[i]) {
            if (conn->conn_type == CT_CONN_TYPE_DEFAULT) {
                if (!conn_expired(conn, now) || count >= limit) {
                    min_expiration = MIN(min_expiration, conn->expiration);
                    if (count >= limit) {
                        /* Do not check other lists. */
                        COVERAGE_INC(conntrack_long_cleanup);
                        return min_expiration;
                    }
                    break;
                }
                conn_clean(ct, conn, ctb);
                count++;
            }
        }
    }

    enum { MAX_ALG_EXP_TO_EXPIRE = 1000 };
    size_t alg_exp_count = hmap_count(&ct->alg_expectations);
    /* XXX: revisit this. */
    size_t max_to_expire = MAX(alg_exp_count/10, MAX_ALG_EXP_TO_EXPIRE);
    count = 0;
    ct_rwlock_wrlock(&ct->resources_lock);
    struct alg_exp_node *alg_exp_node, *alg_exp_node_next;
    LIST_FOR_EACH_SAFE (alg_exp_node, alg_exp_node_next,
                        exp_node, &ct->alg_exp_list) {
        if (now < alg_exp_node->expiration || count >= max_to_expire) {
            min_expiration = MIN(min_expiration, alg_exp_node->expiration);
            break;
        }
        ovs_list_remove(&alg_exp_node->exp_node);
        hmap_remove(&ct->alg_expectations, &alg_exp_node->node);
        free(alg_exp_node);
        count++;
    }
    ct_rwlock_unlock(&ct->resources_lock);

    return min_expiration;
}
    OVS_REQUIRES(ctb->lock)
{
    struct conn *conn, *next;
    long long min_expiration = LLONG_MAX;
    unsigned i;
    size_t count = 0;

    for (i = 0; i < N_CT_TM; i++) {
        LIST_FOR_EACH_SAFE (conn, next, exp_node, &ctb->exp_lists[i]) {
            if (conn->conn_type == CT_CONN_TYPE_DEFAULT) {
                if (!conn_expired(conn, now) || count >= limit) {
                    min_expiration = MIN(min_expiration, conn->expiration);
                    if (count >= limit) {
                         
                        COVERAGE_INC(conntrack_long_cleanup);
                        return min_expiration;
                    }
                    break;
                }
                conn_clean(ct, conn, ctb);
                count++;
            }
        }
    }

    enum { MAX_ALG_EXP_TO_EXPIRE = 1000 };
    size_t alg_exp_count = hmap_count(&ct->alg_expectations);
     
    size_t max_to_expire = MAX(alg_exp_count/10, MAX_ALG_EXP_TO_EXPIRE);
    count = 0;
    ct_rwlock_wrlock(&ct->resources_lock);
    struct alg_exp_node *alg_exp_node, *alg_exp_node_next;
    LIST_FOR_EACH_SAFE (alg_exp_node, alg_exp_node_next,
                        exp_node, &ct->alg_exp_list) {
        if (now < alg_exp_node->expiration || count >= max_to_expire) {
            min_expiration = MIN(min_expiration, alg_exp_node->expiration);
            break;
        }
        ovs_list_remove(&alg_exp_node->exp_node);
        hmap_remove(&ct->alg_expectations, &alg_exp_node->node);
        free(alg_exp_node);
        count++;
    }
    ct_rwlock_unlock(&ct->resources_lock);

    return min_expiration;
}