[PATCH] memcg: nano-optimize VM_BUG_ON in uncharge_page

From: Michal Hocko
Date: Mon Sep 18 2017 - 02:27:43 EST


Even though VM_BUG* is usually not compiled in there are systems which
enable CONFIG_DEBUG_VM by default. VM_BUG_ON_PAGE in uncharge_page is
not very optimal for the normal case. All pages should have counter==0
so that is the first thing to check. is_zone_device_page is nicely
noop if ZONE_DEVICE is not compiled in and finally HW poison pages
should be least probable. So reorder the check to bail out as early as
possible on normal case.

Signed-off-by: Michal Hocko <mhocko@xxxxxxxx>
---
mm/memcontrol.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index ae37b5624eb2..d5f3a62887cf 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -5658,8 +5658,8 @@ static void uncharge_batch(const struct uncharge_gather *ug)
static void uncharge_page(struct page *page, struct uncharge_gather *ug)
{
VM_BUG_ON_PAGE(PageLRU(page), page);
- VM_BUG_ON_PAGE(!PageHWPoison(page) && !is_zone_device_page(page) &&
- page_count(page), page);
+ VM_BUG_ON_PAGE(page_count(page) && !is_zone_device_page(page) &&
+ !PageHWPoison(page) , page);

if (!page->mem_cgroup)
return;
--
2.14.1

--
Michal Hocko
SUSE Labs