Hello.

On Wed, Dec 04, 2024 at 02:44:01PM +0100, Maarten Lankhorst <d...@lankhorst.se> 
wrote:
> +bool dmem_cgroup_state_evict_valuable(struct dmem_cgroup_pool_state 
> *limit_pool,
> +                                   struct dmem_cgroup_pool_state *test_pool,
> +                                   bool ignore_low, bool *ret_hit_low)
> +{
> +     struct dmem_cgroup_pool_state *pool = test_pool;
> +     struct page_counter *climit, *ctest;
> +     u64 used, min, low;
> +
> +     /* Can always evict from current pool, despite limits */
> +     if (limit_pool == test_pool)
> +             return true;
> +

> +     if (limit_pool) {
> +             if (!parent_dmemcs(limit_pool->cs))
> +                     return true;
> +
> +             for (pool = test_pool; pool && limit_pool != pool; pool = 
> pool_parent(pool))
> +                     {}
> +
> +             if (!pool)
> +                     return false;
> +     } else {
> +             /*
> +              * If there is no cgroup limiting memory usage, use the root
> +              * cgroup instead for limit calculations.
> +              */
> +             for (limit_pool = test_pool; pool_parent(limit_pool); 
> limit_pool = pool_parent(limit_pool))
> +                     {}
> +     }

I'm trying to understand the two branches above. If limit_pool is a root
one, eviction is granted and no protection is evaluated.

Then it checks that test_pool is below limit_pool (can this ever fail,
given the limit_pool must have been above when charging in test_pool?).
(OK, this may be called arbitrarily by modules.)

I think it could be simplified and corrected like this:

        /* Resolve NULL limit_pool */
        if (!limit_pool)
                for (limit_pool = test_pool; pool_parent(limit_pool); 
limit_pool = pool_parent(limit_pool));
        
        /* Check ancestry */
        if (!cgroup_is_descendant(test_pool->cs->css.cgroup, 
limit_pool->cs->css.cgroup))
                return false;

HTH,
Michal

Attachment: signature.asc
Description: PGP signature

Reply via email to