It's not entirely clear whether do_swap_account or PCG_MEMSW is the
authoritative answer to whether a page is swap-accounted or not. This
currently leads to the following memsw counter underflow when swap
accounting is disabled:
Don't set PCG_MEMSW when swap accounting is disabled, so that uncharging
only has to look at this per-page flag.
mem_cgroup_swapout() could also fully rely on this flag, but as it can
bail out before even looking up the page_cgroup, check do_swap_account as
a performance optimization and only sanity test for PCG_MEMSW.
Signed-off-by: Johannes Weiner <hannes@cmpxchg.org> Reported-by: Fengguang Wu <fengguang.wu@intel.com> Cc: Michal Hocko <mhocko@suse.cz> Tested-by: Jet Chen <jet.chen@intel.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>