• Yu Zhao's avatar
    mm/mglru: respect min_ttl_ms with memcgs · 8aa42061
    Yu Zhao authored
    While investigating kswapd "consuming 100% CPU" [1] (also see "mm/mglru:
    try to stop at high watermarks"), it was discovered that the memcg LRU can
    breach the thrashing protection imposed by min_ttl_ms.
    
    Before the memcg LRU:
      kswapd()
        shrink_node_memcgs()
          mem_cgroup_iter()
            inc_max_seq()  // always hit a different memcg
        lru_gen_age_node()
          mem_cgroup_iter()
            check the timestamp of the oldest generation
    
    After the memcg LRU:
      kswapd()
        shrink_many()
          restart:
            iterate the memcg LRU:
              inc_max_seq()  // occasionally hit the same memcg
              if raced with lru_gen_rotate_memcg():
                goto restart
        lru_gen_age_node()
          mem_cgroup_iter()
            check the timestamp of the oldest generation
    
    Specifically, when the restart happens in shrink_many(), it needs to stick
    with the (memcg LRU) generation it began with.  In other words, it should
    neither re-read memcg_lru->seq nor age an lruvec of a different
    generation.  Otherwise it can hit the same memcg multiple times without
    giving lru_gen_age_node() a chance to check the timestamp of that memcg's
    oldest generation (against min_ttl_ms).
    
    [1] https://lore.kernel.org/CAK8fFZ4DY+GtBA40Pm7Nn5xCHy+51w3sfxPqkqpqakSXYyX+Wg@mail.gmail.com/
    
    Link: https://lkml.kernel.org/r/20231208061407.2125867-3-yuzhao@google.com
    Fixes: e4dde56c
    
     ("mm: multi-gen LRU: per-node lru_gen_folio lists")
    Signed-off-by: default avatarYu Zhao <yuzhao@google.com>
    Tested-by: default avatarT.J. Mercier <tjmercier@google.com>
    Cc: Charan Teja Kalla <quic_charante@quicinc.com>
    Cc: Hillf Danton <hdanton@sina.com>
    Cc: Jaroslav Pulchart <jaroslav.pulchart@gooddata.com>
    Cc: Kairui Song <ryncsn@gmail.com>
    Cc: Kalesh Singh <kaleshsingh@google.com>
    Cc: <stable@vger.kernel.org>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    8aa42061
vmscan.c 206 KB