Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp4261826pxb; Tue, 2 Mar 2021 10:28:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJx7HBDJnFc4DYzwNK7GK4ZLcMqV9hKeh7dhl+wKDG6IGnkiIvJTiXxkPqGH5kZhi/P0AbLE X-Received: by 2002:a17:906:f9cc:: with SMTP id lj12mr21530063ejb.544.1614709703468; Tue, 02 Mar 2021 10:28:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614709703; cv=none; d=google.com; s=arc-20160816; b=rRuodSb5YeCwBwzvMYPEIyy2I5+rivHNPowJcK9TWaPRH5Ea6PFStG4Pp6nqh2tZ21 Jpcm5YG1nkrcn/lHF9gvDg170oSuVWtGr8o2I0m1pgmduA2oMEAc4YNjAb0IBS8AB8YZ /RGjH5y1FvLJu3QN20SBF2OtKLxWf4r9HpZ74SYKFc9KETkgfHPn70SCaNrtYKwNJdyI GJyB86DzplXG6J5FtGV9gZ5c87S9++mDp/HQl7jbLGVUa7/AKRN1XNtWthZpdz/fxwDW ErOw11dD69Nlb++yNlYC7CZb94otu8AexTM5P2BXz8WTfsJfUxrQXBvOwLJ0W+ECWqqQ z+yA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=0ERSQBPRK+ZCOZB9XANmbIf7BarYdSoj/kKFDv5T1Gw=; b=wq6lG3lNguxOMpBComBjsEuKJWurpVsrXRHVoCqRfk32+7xMPwdTOs+17f4elmK9KS p+WgKlql5RPHFzR6wA+3NrivOAH0fdtGtVGMvRSXEzHN4qK1UTQxANtzp2PnbTxH3iHi Jt1hJnsXzYNK5CD8ZJc5o+G8+17ff8oO9aSHp6XrdPRFTWPoBG5ZXZS/QCW99dj51AqB wgCguWX92fuo7w1sjqCitMh0cVlTFO1AsIfWAwi+23jHT0uAJy1wrnQgTsbKldqFR+2K XfR0XA96ar3bvo0yGYIqVRw7Jaet3k0vw/8RPiONDQnQ5l4LK0itNL4vN3QM5uFasMqV bwkA== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ju25si8257169ejc.668.2021.03.02.10.28.00; Tue, 02 Mar 2021 10:28:23 -0800 (PST) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1576432AbhCBE3A (ORCPT + 99 others); Mon, 1 Mar 2021 23:29:00 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:13018 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235221AbhCBBhq (ORCPT ); Mon, 1 Mar 2021 20:37:46 -0500 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4DqKSS1k6szjVBC; Tue, 2 Mar 2021 09:35:04 +0800 (CST) Received: from huawei.com (10.175.112.208) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.498.0; Tue, 2 Mar 2021 09:36:37 +0800 From: Zhou Guanghui To: , CC: , , , , , , Subject: [PATCH] mm/memcg: set memcg when split pages Date: Tue, 2 Mar 2021 01:34:51 +0000 Message-ID: <20210302013451.118701-1-zhouguanghui1@huawei.com> X-Mailer: git-send-email 2.25.0 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.112.208] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When split page, the memory cgroup info recorded in first page is not copied to tail pages. In this case, when the tail pages are freed, the uncharge operation is not performed. As a result, the usage of this memcg keeps increasing, and the OOM may occur. So, the copying of first page's memory cgroup info to tail pages is needed when split page. Signed-off-by: Zhou Guanghui --- include/linux/memcontrol.h | 10 ++++++++++ mm/page_alloc.c | 4 +++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index e6dc793d587d..c7e2b4421dc1 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -867,6 +867,12 @@ void mem_cgroup_print_oom_group(struct mem_cgroup *memcg); extern bool cgroup_memory_noswap; #endif +static inline void copy_page_memcg(struct page *dst, struct page *src) +{ + if (src->memcg_data) + dst->memcg_data = src->memcg_data; +} + struct mem_cgroup *lock_page_memcg(struct page *page); void __unlock_page_memcg(struct mem_cgroup *memcg); void unlock_page_memcg(struct page *page); @@ -1291,6 +1297,10 @@ mem_cgroup_print_oom_meminfo(struct mem_cgroup *memcg) { } +static inline void copy_page_memcg(struct page *dst, struct page *src) +{ +} + static inline struct mem_cgroup *lock_page_memcg(struct page *page) { return NULL; diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 3e4b29ee2b1e..ee0a63dc1c9b 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -3307,8 +3307,10 @@ void split_page(struct page *page, unsigned int order) VM_BUG_ON_PAGE(PageCompound(page), page); VM_BUG_ON_PAGE(!page_count(page), page); - for (i = 1; i < (1 << order); i++) + for (i = 1; i < (1 << order); i++) { set_page_refcounted(page + i); + copy_page_memcg(page + i, page); + } split_page_owner(page, 1 << order); } EXPORT_SYMBOL_GPL(split_page); -- 2.25.0