• Yu Zhao's avatar
    mm/swap: reduce indentation level · b03484c2
    Yu Zhao authored
    Patch series "mm/swap: remove boilerplate".
    
    
    This patch (of 5):
    
    Use folio_activate() as an example:
    
    Before this series
    ------------------
        if (!folio_test_active(folio) && !folio_test_unevictable(folio)) {
          struct folio_batch *fbatch;
    
          folio_get(folio);
          if (!folio_test_clear_lru(folio)) {
            folio_put(folio);
            return;
          }
    
          local_lock(&cpu_fbatches.lock);
          fbatch = this_cpu_ptr(&cpu_fbatches.activate);
          folio_batch_add_and_move(fbatch, folio, folio_activate_fn);
          local_unlock(&cpu_fbatches.lock);
        }
      }
    
    After this series
    -----------------
      void folio_activate(struct folio *folio)
      {
        if (folio_test_active(folio) || folio_test_unevictable(folio))
          return;
      
        folio_batch_add_and_move(folio, lru_activate, true);
      }
    
    And this is applied to all 6 folio_batch handlers in mm/swap.c.
    
    bloat-o-meter
    -------------
      add/remove: 12/13 grow/shrink: 3/2 up/down: 4653/-4721 (-68)
      ...
      Total: Before=28083019, After=28082951, chg -0.00%
    
    
    This patch (of 5):
    
    Reduce indentation level by returning directly when there is no cleanup
    needed, i.e.,
    
      if (condition) {    |    if (condition) {
        do_this();        |      do_this();
        return;           |      return;
      } else {            |    }
        do_that();        |
      }                   |    do_that();
    
    and
    
      if (condition) {    |    if (!condition)
        do_this();        |      return;
        do_that();        |
      }                   |    do_this();
      return;             |    do_that();
    
    Presumably the old style became repetitive as the result of copy and
    paste.
    
    Link: https://lkml.kernel.org/r/20240711021317.596178-1-yuzhao@google.com
    Link: https://lkml.kernel.org/r/20240711021317.596178-2-yuzhao@google.comSigned-off-by: default avatarYu Zhao <yuzhao@google.com>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    b03484c2
swap.c 31.4 KB