Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp328450pxa; Tue, 11 Aug 2020 04:13:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyB4p14FG7MdH1FWOI4ugQiHxcNL8KPFy+QcZ4mn75Li26+N2TMcxYARkJYHqDZKF7WOa7L X-Received: by 2002:aa7:cc12:: with SMTP id q18mr11551414edt.113.1597144388841; Tue, 11 Aug 2020 04:13:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597144388; cv=none; d=google.com; s=arc-20160816; b=YQpO5k+zIrMNaIVjY8rVRDm+UK8dOGCx3groaANSUAHUslI2FuEAPm53caEB6LOai9 mj4rsKgSkNIjxkcftZ71LMf3KeOVoApS5GYmlEbxPZ9x7LAxI9vhd/RBwgHSwARShYZf LZuN00zC5L40UanHvZ/TWMfCmCIkHyR0395fnc0XQOa+BtunHr9eTkZyNTjnE+SUmRwd tuWy9udxoD90H4hOz5veCimzNAMQmWhH+wYBqrfTxBuOLr73AXIIqtL/3dDj0VsvQfMN 4ETubWezLkrnbRwknlCj82nyN4ruBJD3EyOl6nC7sLTO5d8m71ldXmV8IvnP0d+2QJ/3 c5Tw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=qA2qT+VH+8mjLuQMYQQX6mX00Vz3syH2LPqkN+NIkdI=; b=zR9x5j5qdMt8xDmM15JSXeqGtwIuiZI7uacR4geFpuwGMxmfX2v7+3WPePZ64quYRH APlcIv/bGa0cImvEMFwYBWYm5k9qBHfr4DXblKnVFs6GjlEar9vEr35hymS8yoOpQg5u wl1D2A2RV3iVAFpt9N+2HDzznW6WmYZHtB0KF0Pc8xTVcO7fZVotPRU9cxiDBPsMKWtV LBCQVtDehPlV55Zng/gIB0uyP86x+JSOK29Vuhj42u4h4U6V50du+Zk0vG7GSOwiOsgf YMGlB+ohBtbCK8yYvAYBcfZ29UkPK00hXvMSkvRPIGvKMqGfYg3bSjI/48n2rHgbMtHk o0Ag== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r17si14974449eda.525.2020.08.11.04.12.45; Tue, 11 Aug 2020 04:13:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728669AbgHKLLK (ORCPT + 99 others); Tue, 11 Aug 2020 07:11:10 -0400 Received: from out30-132.freemail.mail.aliyun.com ([115.124.30.132]:40342 "EHLO out30-132.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728469AbgHKLK6 (ORCPT ); Tue, 11 Aug 2020 07:10:58 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R191e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e07484;MF=alex.shi@linux.alibaba.com;NM=1;PH=DS;RN=7;SR=0;TI=SMTPD_---0U5TLMT5_1597144252; Received: from aliy80.localdomain(mailfrom:alex.shi@linux.alibaba.com fp:SMTPD_---0U5TLMT5_1597144252) by smtp.aliyun-inc.com(127.0.0.1); Tue, 11 Aug 2020 19:10:52 +0800 From: Alex Shi To: akpm@linux-foundation.org Cc: Johannes Weiner , Michal Hocko , Vladimir Davydov , cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [Resend PATCH 1/6] mm/memcg: warning on !memcg after readahead page charged Date: Tue, 11 Aug 2020 19:10:27 +0800 Message-Id: <1597144232-11370-1-git-send-email-alex.shi@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Since readahead page is charged on memcg too, in theory we don't have to check this exception now. Before safely remove them all, add a warning for the unexpected !memcg. Signed-off-by: Alex Shi Acked-by: Michal Hocko Cc: Johannes Weiner Cc: Michal Hocko Cc: Vladimir Davydov Cc: Andrew Morton Cc: cgroups@vger.kernel.org Cc: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org --- include/linux/mmdebug.h | 13 +++++++++++++ mm/memcontrol.c | 15 ++++++++------- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/include/linux/mmdebug.h b/include/linux/mmdebug.h index 2ad72d2c8cc5..4ed52879ce55 100644 --- a/include/linux/mmdebug.h +++ b/include/linux/mmdebug.h @@ -37,6 +37,18 @@ BUG(); \ } \ } while (0) +#define VM_WARN_ON_ONCE_PAGE(cond, page) ({ \ + static bool __section(.data.once) __warned; \ + int __ret_warn_once = !!(cond); \ + \ + if (unlikely(__ret_warn_once && !__warned)) { \ + dump_page(page, "VM_WARN_ON_ONCE_PAGE(" __stringify(cond)")");\ + __warned = true; \ + WARN_ON(1); \ + } \ + unlikely(__ret_warn_once); \ +}) + #define VM_WARN_ON(cond) (void)WARN_ON(cond) #define VM_WARN_ON_ONCE(cond) (void)WARN_ON_ONCE(cond) #define VM_WARN_ONCE(cond, format...) (void)WARN_ONCE(cond, format) @@ -48,6 +60,7 @@ #define VM_BUG_ON_MM(cond, mm) VM_BUG_ON(cond) #define VM_WARN_ON(cond) BUILD_BUG_ON_INVALID(cond) #define VM_WARN_ON_ONCE(cond) BUILD_BUG_ON_INVALID(cond) +#define VM_WARN_ON_ONCE_PAGE(cond, page) BUILD_BUG_ON_INVALID(cond) #define VM_WARN_ONCE(cond, format...) BUILD_BUG_ON_INVALID(cond) #define VM_WARN(cond, format...) BUILD_BUG_ON_INVALID(cond) #endif diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 130093bdf74b..299382fc55a9 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -1322,10 +1322,8 @@ struct lruvec *mem_cgroup_page_lruvec(struct page *page, struct pglist_data *pgd } memcg = page->mem_cgroup; - /* - * Swapcache readahead pages are added to the LRU - and - * possibly migrated - before they are charged. - */ + /* Readahead page is charged too, to see if other page uncharged */ + VM_WARN_ON_ONCE_PAGE(!memcg, page); if (!memcg) memcg = root_mem_cgroup; @@ -6906,8 +6904,9 @@ void mem_cgroup_migrate(struct page *oldpage, struct page *newpage) if (newpage->mem_cgroup) return; - /* Swapcache readahead pages can get replaced before being charged */ memcg = oldpage->mem_cgroup; + /* Readahead page is charged too, to see if other page uncharged */ + VM_WARN_ON_ONCE_PAGE(!memcg, oldpage); if (!memcg) return; @@ -7104,7 +7103,8 @@ void mem_cgroup_swapout(struct page *page, swp_entry_t entry) memcg = page->mem_cgroup; - /* Readahead page, never charged */ + /* Readahead page is charged too, to see if other page uncharged */ + VM_WARN_ON_ONCE_PAGE(!memcg, page); if (!memcg) return; @@ -7168,7 +7168,8 @@ int mem_cgroup_try_charge_swap(struct page *page, swp_entry_t entry) memcg = page->mem_cgroup; - /* Readahead page, never charged */ + /* Readahead page is charged too, to see if other page uncharged */ + VM_WARN_ON_ONCE_PAGE(!memcg, page); if (!memcg) return 0; -- 1.8.3.1