Skip to content
  • Vlastimil Babka's avatar
    mm, frontswap: convert frontswap_enabled to static key · 8ea1d2a1
    Vlastimil Babka authored
    I have noticed that frontswap.h first declares "frontswap_enabled" as
    extern bool variable, and then overrides it with "#define
    frontswap_enabled (1)" for CONFIG_FRONTSWAP=Y or (0) when disabled.  The
    bool variable isn't actually instantiated anywhere.
    
    This all looks like an unfinished attempt to make frontswap_enabled
    reflect whether a backend is instantiated.  But in the current state,
    all frontswap hooks call unconditionally into frontswap.c just to check
    if frontswap_ops is non-NULL.  This should at least be checked inline,
    but we can further eliminate the overhead when CONFIG_FRONTSWAP is
    enabled and no backend registered, using a static key that is initially
    disabled, and gets enabled only upon first backend registration.
    
    Thus, checks for "frontswap_enabled" are replaced with
    "frontswap_enabled()" wrapping the static key check.  There are two
    exceptions:
    
    - xen's selfballoon_process() was testing frontswap_enabled in code guarded
      by #ifdef C...
    8ea1d2a1