Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp12698pxk; Wed, 23 Sep 2020 20:32:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxqcY2e5k24vJk8D/rf0/scMeL0lkp+zajj3y1ksAcYVW1EHGE8D7C3ukIFromvFCPNnywv X-Received: by 2002:aa7:d8d8:: with SMTP id k24mr2458228eds.97.1600918372651; Wed, 23 Sep 2020 20:32:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600918372; cv=none; d=google.com; s=arc-20160816; b=vLHLsS7h7+0EXh0eiMlyvVycUkl9Az/6rqjwylRzS6LUlMYjZhjikkqbwrx4WYv1O0 ukNjFg7gGR8vbK0DAD0M3/YCAg2Hiz48Z2wFCPk4KJakwdrFjTwPsRBJERAk+twAYKeJ rUFMzb3c3o3VpnoBTiH3DeZEV2dBPvkR+3pbgcW58yXyHVhObVJkhHQtcKDS39dmqUOt BbygIDYvYwXH1NMm9NLe76iBgiZ2VfsSiriO/OUZoxT0nN4g1ifs8I1R+9CH5YsWtriD 8DwGcd/Ih4ff9WWHVrQrMZEqRbbLAvzI05T5/nUolCEpAk7uOKMuncAiTNyGLpeEjez6 WsNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=g9aeZMEgcB0Fc16KXAN1tm9phb2ic8dVefLbcehwrQA=; b=EpCwZps/IGPO2Vgoz+5vg46+KipozXThrguae51bYWDslvQvIeftZiW5m2MH5jVJAG PZznPBWuh8txFelIrTMeau5BByUok4LJUbinAlWzBv/KBI5n9LI6Ud5D4zXy0zPx99ll DY1GAH2v6Vcy2agybkQduBZruilrfVSiarAJ259ACZbBU/tIaiSLW1+KK89f3ZGOpUUx rT0RGl0OHwulrse/fF3fhFgrPkZB/tNMQ1czcYIwiAZ7LQjN+VR62rIvQNdtSostyVyx 0rN0u64hPXxoXbkqEz9raT0ywEqbuBQ9C1Jre03kbyqBivPB7K0dqgwBk0UsNTyCqGBP W8HA== 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 x25si1275867edr.508.2020.09.23.20.32.28; Wed, 23 Sep 2020 20:32:52 -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 S1726810AbgIXD2m (ORCPT + 99 others); Wed, 23 Sep 2020 23:28:42 -0400 Received: from out30-130.freemail.mail.aliyun.com ([115.124.30.130]:33557 "EHLO out30-130.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726667AbgIXD2m (ORCPT ); Wed, 23 Sep 2020 23:28:42 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R311e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04420;MF=alex.shi@linux.alibaba.com;NM=1;PH=DS;RN=23;SR=0;TI=SMTPD_---0U9w0Ss1_1600918116; Received: from aliy80.localdomain(mailfrom:alex.shi@linux.alibaba.com fp:SMTPD_---0U9w0Ss1_1600918116) by smtp.aliyun-inc.com(127.0.0.1); Thu, 24 Sep 2020 11:28:37 +0800 From: Alex Shi To: akpm@linux-foundation.org, mgorman@techsingularity.net, tj@kernel.org, hughd@google.com, khlebnikov@yandex-team.ru, daniel.m.jordan@oracle.com, willy@infradead.org, hannes@cmpxchg.org, lkp@intel.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, shakeelb@google.com, iamjoonsoo.kim@lge.com, richard.weiyang@gmail.com, kirill@shutemov.name, alexander.duyck@gmail.com, rong.a.chen@intel.com, mhocko@suse.com, vdavydov.dev@gmail.com, shy828301@gmail.com, aaron.lwe@gmail.com Cc: Michal Hocko Subject: [PATCH v19 01/20] mm/memcg: warning on !memcg after readahead page charged Date: Thu, 24 Sep 2020 11:28:16 +0800 Message-Id: <1600918115-22007-2-git-send-email-alex.shi@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1600918115-22007-1-git-send-email-alex.shi@linux.alibaba.com> References: <1600918115-22007-1-git-send-email-alex.shi@linux.alibaba.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add VM_WARN_ON_ONCE_PAGE() macro. 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 Acked-by: Hugh Dickins 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 | 11 ++++------- 2 files changed, 17 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 cfa6cbad21d5..f7094a04be07 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -1322,10 +1322,7 @@ 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. - */ + VM_WARN_ON_ONCE_PAGE(!memcg, page); if (!memcg) memcg = root_mem_cgroup; @@ -6912,8 +6909,8 @@ 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; + VM_WARN_ON_ONCE_PAGE(!memcg, oldpage); if (!memcg) return; @@ -7110,7 +7107,7 @@ void mem_cgroup_swapout(struct page *page, swp_entry_t entry) memcg = page->mem_cgroup; - /* Readahead page, never charged */ + VM_WARN_ON_ONCE_PAGE(!memcg, page); if (!memcg) return; @@ -7174,7 +7171,7 @@ int mem_cgroup_try_charge_swap(struct page *page, swp_entry_t entry) memcg = page->mem_cgroup; - /* Readahead page, never charged */ + VM_WARN_ON_ONCE_PAGE(!memcg, page); if (!memcg) return 0; -- 1.8.3.1