Lines Matching defs:packer

6 #include "packer.h"
83 * assert_on_packer_thread() - Check that we are on the packer thread.
84 * @packer: The packer.
87 static inline void assert_on_packer_thread(struct packer *packer, const char *caller)
89 VDO_ASSERT_LOG_ONLY((vdo_get_callback_thread_id() == packer->thread_id),
90 "%s() called from packer thread", caller);
95 * @packer: The packer.
101 static void insert_in_sorted_list(struct packer *packer, struct packer_bin *bin)
105 list_for_each_entry(active_bin, &packer->bins, list)
111 list_move_tail(&bin->list, &packer->bins);
115 * make_bin() - Allocate a bin and put it into the packer's list.
116 * @packer: The packer.
118 static int __must_check make_bin(struct packer *packer)
130 list_add_tail(&bin->list, &packer->bins);
135 * vdo_make_packer() - Make a new block packer.
137 * @vdo: The vdo to which this packer belongs.
139 * @packer_ptr: A pointer to hold the new packer.
143 int vdo_make_packer(struct vdo *vdo, block_count_t bin_count, struct packer **packer_ptr)
145 struct packer *packer;
149 result = vdo_allocate(1, struct packer, __func__, &packer);
153 packer->thread_id = vdo->thread_config.packer_thread;
154 packer->size = bin_count;
155 INIT_LIST_HEAD(&packer->bins);
156 vdo_set_admin_state_code(&packer->state, VDO_ADMIN_STATE_NORMAL_OPERATION);
159 result = make_bin(packer);
161 vdo_free_packer(packer);
172 struct vio *, __func__, &packer->canceled_bin);
174 vdo_free_packer(packer);
178 result = vdo_make_default_thread(vdo, packer->thread_id);
180 vdo_free_packer(packer);
184 *packer_ptr = packer;
189 * vdo_free_packer() - Free a block packer.
190 * @packer: The packer to free.
192 void vdo_free_packer(struct packer *packer)
196 if (packer == NULL)
199 list_for_each_entry_safe(bin, tmp, &packer->bins, list) {
204 vdo_free(vdo_forget(packer->canceled_bin));
205 vdo_free(packer);
209 * get_packer_from_data_vio() - Get the packer from a data_vio.
212 * Return: The packer from the VDO to which the data_vio belongs.
214 static inline struct packer *get_packer_from_data_vio(struct data_vio *data_vio)
216 return vdo_from_data_vio(data_vio)->packer;
220 * vdo_get_packer_statistics() - Get the current statistics from the packer.
221 * @packer: The packer to query.
223 * Return: a copy of the current statistics for the packer.
225 struct packer_statistics vdo_get_packer_statistics(const struct packer *packer)
227 const struct packer_statistics *stats = &packer->statistics;
242 struct packer *packer = get_packer_from_data_vio(data_vio);
244 WRITE_ONCE(packer->statistics.compressed_fragments_in_packer,
245 packer->statistics.compressed_fragments_in_packer - 1);
314 /* Now that we've released the batch from the packer, forget the error and continue on. */
334 * @packer: The packer.
340 static struct data_vio *remove_from_bin(struct packer *packer, struct packer_bin *bin)
350 add_to_bin(packer->canceled_bin, data_vio);
421 * @packer: The packer.
424 static void write_bin(struct packer *packer, struct packer_bin *bin)
431 struct data_vio *agent = remove_from_bin(packer, bin);
444 while ((client = remove_from_bin(packer, bin)) != NULL)
476 * Once the compressed write is submitted, the fragments are no longer in the packer, so
479 stats = &packer->statistics;
492 * @packer: The packer.
499 static void add_data_vio_to_packer_bin(struct packer *packer, struct packer_bin *bin,
504 write_bin(packer, bin);
512 write_bin(packer, bin);
515 insert_in_sorted_list(packer, bin);
521 * @packer: The packer.
524 static struct packer_bin * __must_check select_bin(struct packer *packer,
533 list_for_each_entry(bin, &packer->bins, list) {
546 fullest_bin = list_first_entry(&packer->bins, struct packer_bin, list);
553 * incoming data_vio will increase the packer's free space.
568 struct packer *packer = get_packer_from_data_vio(data_vio);
570 assert_on_packer_thread(packer, __func__);
582 WRITE_ONCE(packer->statistics.compressed_fragments_in_packer,
583 packer->statistics.compressed_fragments_in_packer + 1);
589 if (!vdo_is_state_normal(&packer->state) ||
590 (data_vio->flush_generation < packer->flush_generation)) {
599 * before any more requests can be processed by the packer thread. Otherwise, a canceling
600 * data_vio could attempt to remove the canceled data_vio from the packer and fail to
604 bin = select_bin(packer, data_vio);
611 add_data_vio_to_packer_bin(packer, bin, data_vio);
615 * check_for_drain_complete() - Check whether the packer has drained.
616 * @packer: The packer.
618 static void check_for_drain_complete(struct packer *packer)
620 if (vdo_is_state_draining(&packer->state) && (packer->canceled_bin->slots_used == 0))
621 vdo_finish_draining(&packer->state);
626 * @packer: The packer being flushed.
628 static void write_all_non_empty_bins(struct packer *packer)
632 list_for_each_entry(bin, &packer->bins, list)
633 write_bin(packer, bin);
639 check_for_drain_complete(packer);
643 * vdo_flush_packer() - Request that the packer flush asynchronously.
644 * @packer: The packer to flush.
647 * VIOs will be released from the packer. While flushing is in progress, any VIOs submitted to
650 void vdo_flush_packer(struct packer *packer)
652 assert_on_packer_thread(packer, __func__);
653 if (vdo_is_state_normal(&packer->state))
654 write_all_non_empty_bins(packer);
658 * vdo_remove_lock_holder_from_packer() - Remove a lock holder from the packer.
659 * @completion: The data_vio which needs a lock held by a data_vio in the packer. The data_vio's
665 struct packer *packer = get_packer_from_data_vio(data_vio);
674 VDO_ASSERT_LOG_ONLY((bin != NULL), "data_vio in packer has a bin");
686 if (bin != packer->canceled_bin) {
688 insert_in_sorted_list(packer, bin);
692 check_for_drain_complete(packer);
696 * vdo_increment_packer_flush_generation() - Increment the flush generation in the packer.
697 * @packer: The packer.
699 * This will also cause the packer to flush so that any VIOs from previous generations will exit
700 * the packer.
702 void vdo_increment_packer_flush_generation(struct packer *packer)
704 assert_on_packer_thread(packer, __func__);
705 packer->flush_generation++;
706 vdo_flush_packer(packer);
716 struct packer *packer = container_of(state, struct packer, state);
718 write_all_non_empty_bins(packer);
722 * vdo_drain_packer() - Drain the packer by preventing any more VIOs from entering the packer and
724 * @packer: The packer to drain.
725 * @completion: The completion to finish when the packer has drained.
727 void vdo_drain_packer(struct packer *packer, struct vdo_completion *completion)
729 assert_on_packer_thread(packer, __func__);
730 vdo_start_draining(&packer->state, VDO_ADMIN_STATE_SUSPENDING, completion,
735 * vdo_resume_packer() - Resume a packer which has been suspended.
736 * @packer: The packer to resume.
737 * @parent: The completion to finish when the packer has resumed.
739 void vdo_resume_packer(struct packer *packer, struct vdo_completion *parent)
741 assert_on_packer_thread(packer, __func__);
742 vdo_continue_completion(parent, vdo_resume_if_quiescent(&packer->state));
761 * vdo_dump_packer() - Dump the packer.
762 * @packer: The packer.
766 void vdo_dump_packer(const struct packer *packer)
770 vdo_log_info("packer");
772 (unsigned long long) packer->flush_generation,
773 vdo_get_admin_state_code(&packer->state)->name,
774 (unsigned long long) packer->size);
776 list_for_each_entry(bin, &packer->bins, list)
779 dump_packer_bin(packer->canceled_bin, true);