Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp2403023ybg; Thu, 30 Jul 2020 20:35:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyQ52j8GoIWTQ25gcZzL4GziicTNF//3fXDiZABBZC8JqsSOdhVzDfplJnOfX8dKu9aK8Ax X-Received: by 2002:a17:906:c18d:: with SMTP id g13mr2043543ejz.239.1596166537009; Thu, 30 Jul 2020 20:35:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596166536; cv=none; d=google.com; s=arc-20160816; b=HbWz4z9VaWAvNHGWadBp52RBJsviymW7Jf/4We24nLn5SQX7Ln1Udu76BAhxZBkrSF ZtOL8hQc6LTS3g1TiK4MnZur04DcdUMJUweXxKrW7qKNiKEZqukFXCoOFNFNMz3vpQKd Qy0okQZ1hNs64449fsOe5g9mMRcVm8XY3ndBFJv8CnKKrQxyt7eZh/tudLdxCWJRq0Rb PhO5pGYfQA+lWgIJ4AVTTTToUNhMp4p4k2N+If1MZs4I7S8zmSk7Y8kzm+43lvfl8wXr LDfmaMCc6XKFb0Izstn6WqnigU2ciwdlMusEsI2U49EomVVzDoRPtnv+dZ+pOtpnOeTE LYXg== 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=ebTZzF9CAYExdQBLtvQxtmXSvr9n4mpQlK1zlS29edg=; b=PZJsfTF5nWF6XpUUjkqvT9q824icULCwVvVKDUQH30vCxV3LNOBPVtP0kqwuK2qgap ZwdIm/uFNXC4Cfbqdgmds5ak7P+gNh88KaxlwnEYW6Ku9rg4pGNLXmXguckAMm+kDcH7 TJIAk9rAXI/PU/wacARaF7PgN7k60aUojS+7RMtS8P9+MmjS4ux2VX4VPaWUIHHiUEb1 dVTuOoE0+AMjGowx8SP0EyIHQzVKNfiAwBQmz0JadCRGQvPtcw1yqFLktGqsFB0rFxYV lMcjIOfzXxltLNNhEqeFusp89GDYIGszVwQdaX9TVbHgenAO5lp5weDqvyEHHIvhRduG SQOg== 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 o9si4515544edq.412.2020.07.30.20.35.07; Thu, 30 Jul 2020 20:35:36 -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 S1731272AbgGaDe4 (ORCPT + 99 others); Thu, 30 Jul 2020 23:34:56 -0400 Received: from out30-44.freemail.mail.aliyun.com ([115.124.30.44]:45324 "EHLO out30-44.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730820AbgGaDez (ORCPT ); Thu, 30 Jul 2020 23:34:55 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R131e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e01358;MF=alex.shi@linux.alibaba.com;NM=1;PH=DS;RN=7;SR=0;TI=SMTPD_---0U4HxHq._1596166492; Received: from aliy8.localdomain(mailfrom:alex.shi@linux.alibaba.com fp:SMTPD_---0U4HxHq._1596166492) by smtp.aliyun-inc.com(127.0.0.1); Fri, 31 Jul 2020 11:34:53 +0800 From: Alex Shi To: Johannes Weiner Cc: Michal Hocko , Vladimir Davydov , Andrew Morton , cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH] mm/memcg: remove useless check on page->mem_cgroup Date: Fri, 31 Jul 2020 11:34:40 +0800 Message-Id: <1596166480-22814-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 will be charged on memcg too. We don't need to check this exception now. Rmove them is safe as all user pages are charged before use. Signed-off-by: Alex Shi 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 --- mm/memcontrol.c | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index e84c2b5596f2..9e44ae22d591 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -1322,12 +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. - */ - if (!memcg) - memcg = root_mem_cgroup; + VM_BUG_ON_PAGE(!memcg, page); mz = mem_cgroup_page_nodeinfo(memcg, page); lruvec = &mz->lruvec; @@ -6897,10 +6892,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; - if (!memcg) - return; + VM_BUG_ON_PAGE(!memcg, oldpage); /* Force-charge the new page. The old one will be freed soon */ nr_pages = thp_nr_pages(newpage); @@ -7094,10 +7087,7 @@ void mem_cgroup_swapout(struct page *page, swp_entry_t entry) return; memcg = page->mem_cgroup; - - /* Readahead page, never charged */ - if (!memcg) - return; + VM_BUG_ON_PAGE(!memcg, page); /* * In case the memcg owning these pages has been offlined and doesn't @@ -7158,10 +7148,7 @@ int mem_cgroup_try_charge_swap(struct page *page, swp_entry_t entry) return 0; memcg = page->mem_cgroup; - - /* Readahead page, never charged */ - if (!memcg) - return 0; + VM_BUG_ON_PAGE(!memcg, page); if (!entry.val) { memcg_memory_event(memcg, MEMCG_SWAP_FAIL); -- 1.8.3.1