@@ -694,6 +694,68 @@ int dmem_cgroup_try_charge(struct dmem_cgroup_region *region, u64 size,
694694}
695695EXPORT_SYMBOL_GPL (dmem_cgroup_try_charge );
696696
697+ /**
698+ * dmem_cgroup_below_min() - Tests whether current usage is within min limit.
699+ *
700+ * @root: Root of the subtree to calculate protection for, or NULL to calculate global protection.
701+ * @test: The pool to test the usage/min limit of.
702+ *
703+ * Return: true if usage is below min and the cgroup is protected, false otherwise.
704+ */
705+ bool dmem_cgroup_below_min (struct dmem_cgroup_pool_state * root ,
706+ struct dmem_cgroup_pool_state * test )
707+ {
708+ if (root == test || !pool_parent (test ))
709+ return false;
710+
711+ if (!root ) {
712+ for (root = test ; pool_parent (root ); root = pool_parent (root ))
713+ {}
714+ }
715+
716+ /*
717+ * In mem_cgroup_below_min(), the memcg pendant, this call is missing.
718+ * mem_cgroup_below_min() gets called during traversal of the cgroup tree, where
719+ * protection is already calculated as part of the traversal. dmem cgroup eviction
720+ * does not traverse the cgroup tree, so we need to recalculate effective protection
721+ * here.
722+ */
723+ dmem_cgroup_calculate_protection (root , test );
724+ return page_counter_read (& test -> cnt ) <= READ_ONCE (test -> cnt .emin );
725+ }
726+ EXPORT_SYMBOL_GPL (dmem_cgroup_below_min );
727+
728+ /**
729+ * dmem_cgroup_below_low() - Tests whether current usage is within low limit.
730+ *
731+ * @root: Root of the subtree to calculate protection for, or NULL to calculate global protection.
732+ * @test: The pool to test the usage/low limit of.
733+ *
734+ * Return: true if usage is below low and the cgroup is protected, false otherwise.
735+ */
736+ bool dmem_cgroup_below_low (struct dmem_cgroup_pool_state * root ,
737+ struct dmem_cgroup_pool_state * test )
738+ {
739+ if (root == test || !pool_parent (test ))
740+ return false;
741+
742+ if (!root ) {
743+ for (root = test ; pool_parent (root ); root = pool_parent (root ))
744+ {}
745+ }
746+
747+ /*
748+ * In mem_cgroup_below_low(), the memcg pendant, this call is missing.
749+ * mem_cgroup_below_low() gets called during traversal of the cgroup tree, where
750+ * protection is already calculated as part of the traversal. dmem cgroup eviction
751+ * does not traverse the cgroup tree, so we need to recalculate effective protection
752+ * here.
753+ */
754+ dmem_cgroup_calculate_protection (root , test );
755+ return page_counter_read (& test -> cnt ) <= READ_ONCE (test -> cnt .elow );
756+ }
757+ EXPORT_SYMBOL_GPL (dmem_cgroup_below_low );
758+
697759static int dmem_cgroup_region_capacity_show (struct seq_file * sf , void * v )
698760{
699761 struct dmem_cgroup_region * region ;
0 commit comments