From patchwork Tue Feb 13 21:55:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 13555738 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 82373C4829A for ; Tue, 13 Feb 2024 21:55:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9C5988D001B; Tue, 13 Feb 2024 16:55:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9703E8D001A; Tue, 13 Feb 2024 16:55:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7C53F8D001B; Tue, 13 Feb 2024 16:55:52 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 65B748D001A for ; Tue, 13 Feb 2024 16:55:52 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 393B8A20F7 for ; Tue, 13 Feb 2024 21:55:52 +0000 (UTC) X-FDA: 81788138544.08.1CAD402 Received: from out5-smtp.messagingengine.com (out5-smtp.messagingengine.com [66.111.4.29]) by imf05.hostedemail.com (Postfix) with ESMTP id 21C8F100016 for ; Tue, 13 Feb 2024 21:55:49 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=sent.com header.s=fm3 header.b="C70tT3/h"; dkim=pass header.d=messagingengine.com header.s=fm3 header.b=mfJ6oPkF; spf=pass (imf05.hostedemail.com: domain of zi.yan@sent.com designates 66.111.4.29 as permitted sender) smtp.mailfrom=zi.yan@sent.com; dmarc=pass (policy=none) header.from=sent.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707861350; a=rsa-sha256; cv=none; b=rs6IqusDJZDJFbUk4uOqT1NH41jDaQF931llPfmDGMKyk1eAUHYMS+o4hvWq+agIlK7boL bHQDTvQJfXq3GRIFPn2d8WDsrlVjwuQybBYUo/90/Mw6VmOeDfzLFUR8kCP/MFYu4yhswa Ek4BQ0PepbcKNsn6RFdZWL1rO8J6IiY= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=sent.com header.s=fm3 header.b="C70tT3/h"; dkim=pass header.d=messagingengine.com header.s=fm3 header.b=mfJ6oPkF; spf=pass (imf05.hostedemail.com: domain of zi.yan@sent.com designates 66.111.4.29 as permitted sender) smtp.mailfrom=zi.yan@sent.com; dmarc=pass (policy=none) header.from=sent.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707861350; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=w6VhDK8TXvu8VmS0cIwR/bVucmXbgvOXS24MFWRb9kQ=; b=GMTvXtgSIDUtCA9orZ1l1T0KPNPrPqivs9/lLwVnDLGZVe2fL1CDXvaiTF7S9uU8xqc8HE w6U2kuMcm0v7/w7dka674U60dy5Ql13qTPTG1NRo3DqgKYXiZZi0wKk/grMn7lSxE/F1n1 f8LqMZXUrtL78CzjjCBmDP4GEDkkojU= Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id 632325C0112; Tue, 13 Feb 2024 16:55:49 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Tue, 13 Feb 2024 16:55:49 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sent.com; h=cc :cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:reply-to:subject:subject:to:to; s=fm3; t= 1707861349; x=1707947749; bh=w6VhDK8TXvu8VmS0cIwR/bVucmXbgvOXS24 MFWRb9kQ=; b=C70tT3/hxvmwRWrVgxnS8fozz4YHtS6gPhAjMZn75BqWt0l64Kq 6NAknIY8hodeTZXxf1TcFW+hmSrY8Ez6UcvgHwAYCo/PzX/kaod9FkQg4YxM6Qap +Q0U0w8f96uywhMHVijq7849z79hzfhu9xT1WBbNjbnqePwm5/ZmuWlXZzd9dWG1 Ihah9K6AUWgSgv9aAkOqam/jPngyvV2GhLW2LtwWP+KQJ+smHMCekknDEyUOxKUI uL233jsmWJ9skW3QUzLrpOgUlN4+wsNmJGn6/f3rdboztQfhMVpqShelgfvJGMBK BzByecW+/ekBdo0qS4Pd0bLg+VuomGNJegA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:reply-to:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1707861349; x=1707947749; bh=w6VhDK8TXvu8VmS0cIwR/bVucmXbgvOXS24 MFWRb9kQ=; b=mfJ6oPkFyNA+mLkOP/AUEVBP9KImpo/pDaBA8WA4QMCAq03CiTz 492X3jwKiuTbKwuWwNH62NYygt2WBIlP2hxakQ6u0PuV2KIigxiRUrBfckunC0MP nt/aNZDy4MAzjFvlZ6uLK75/N92HY+cpE2wE0m34hVBxGSzd/XcVGP8Fya3eleTG OdN/SgRo6balkm91Wog9MxEYiVA742kmaYLsnDsEPH9WryD4QW9km77C9HyraNOY ktQRHTwI//dgaj4iVwiDumZjJirsDYev9o0Uv1zHeLkNIc7VjvRc0XXR/UwtChiu Z5/e6Y2a0o5yXwC0zyZf0TbF28RyZw1gxnQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrudehgdduheegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgjfhhrgggtgfesthekredtredtjeenucfhrhhomhepkghi ucgjrghnuceoiihirdihrghnsehsvghnthdrtghomheqnecuggftrfgrthhtvghrnhepje ekteekffelleekudfftdefvddtjeejuedtuedtteegjefgvedtfedujeekieevnecuvehl uhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepiihirdihrghnse hsvghnthdrtghomh X-ME-Proxy: Feedback-ID: iccd040f4:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 13 Feb 2024 16:55:48 -0500 (EST) From: Zi Yan To: "Pankaj Raghav (Samsung)" , linux-mm@kvack.org Cc: Zi Yan , "Matthew Wilcox (Oracle)" , David Hildenbrand , Yang Shi , Yu Zhao , "Kirill A . Shutemov" , Ryan Roberts , =?utf-8?q?Michal_Koutn=C3=BD?= , Roman Gushchin , "Zach O'Keefe" , Hugh Dickins , Mcgrof Chamberlain , Andrew Morton , linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v4 3/7] mm: memcg: make memcg huge page split support any order split. Date: Tue, 13 Feb 2024 16:55:16 -0500 Message-ID: <20240213215520.1048625-4-zi.yan@sent.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240213215520.1048625-1-zi.yan@sent.com> References: <20240213215520.1048625-1-zi.yan@sent.com> Reply-To: Zi Yan MIME-Version: 1.0 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 21C8F100016 X-Stat-Signature: aiwd8nn53h6g4dhrxb9tu7e8spfmfx8r X-Rspam-User: X-HE-Tag: 1707861349-978463 X-HE-Meta: U2F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ZB1HuWsTlpgun88I9i7JTg2RXfWbecQ6BxJZx6DsokBbJrckLoZhkIpf2Y7cyuOcGcGc6PAEwqhjtDLRj2QVuBDviQNib9UjhnBSIS+1yKCdIKr4mT3aBXxLINZ5eWxT9sVKeYcRYdnXJMg3r0us4lBtblhEKAm+fjzXGYiFgFuChSR/qiJb30xW8qe55vNvj7JI+2y4qgxpPYD2sdLx6QF05voIX3x8/y54r6Fr/vpIz1ZRyCWwnAIy2zRjKSBl4tgqiS/ZXrOQsZbrP40/Y8vY1NILwhJyIp1S51EGXUErsG6/ekUrbDXOh/eJ54aj7qsNUB+KLsrCCCHCIsYwXgBNtO9cNiZPFBKxLVM X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Zi Yan It sets memcg information for the pages after the split. A new parameter new_order is added to tell the order of subpages in the new page, always 0 for now. It prepares for upcoming changes to support split huge page to any lower order. Signed-off-by: Zi Yan Acked-by: David Hildenbrand --- include/linux/memcontrol.h | 4 ++-- mm/huge_memory.c | 2 +- mm/memcontrol.c | 11 ++++++----- mm/page_alloc.c | 4 ++-- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 173bbb53c1ec..9a2dea92be0e 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -1163,7 +1163,7 @@ static inline void memcg_memory_event_mm(struct mm_struct *mm, rcu_read_unlock(); } -void split_page_memcg(struct page *head, int order); +void split_page_memcg(struct page *head, int old_order, int new_order); unsigned long mem_cgroup_soft_limit_reclaim(pg_data_t *pgdat, int order, gfp_t gfp_mask, @@ -1621,7 +1621,7 @@ void count_memcg_event_mm(struct mm_struct *mm, enum vm_event_item idx) { } -static inline void split_page_memcg(struct page *head, int order) +static inline void split_page_memcg(struct page *head, int old_order, int new_order) { } diff --git a/mm/huge_memory.c b/mm/huge_memory.c index f079b02f1f59..3d30eccd3a7f 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2880,7 +2880,7 @@ static void __split_huge_page(struct page *page, struct list_head *list, int order = folio_order(folio); /* complete memcg works before add pages to LRU */ - split_page_memcg(head, order); + split_page_memcg(head, order, 0); if (folio_test_anon(folio) && folio_test_swapcache(folio)) { offset = swp_offset(folio->swap); diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 404e529644c0..27d53715d8dc 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -3608,23 +3608,24 @@ void obj_cgroup_uncharge(struct obj_cgroup *objcg, size_t size) /* * Because page_memcg(head) is not set on tails, set it now. */ -void split_page_memcg(struct page *head, int order) +void split_page_memcg(struct page *head, int old_order, int new_order) { struct folio *folio = page_folio(head); struct mem_cgroup *memcg = folio_memcg(folio); int i; - unsigned int nr = 1 << order; + unsigned int old_nr = 1 << old_order; + unsigned int new_nr = 1 << new_order; if (mem_cgroup_disabled() || !memcg) return; - for (i = 1; i < nr; i++) + for (i = new_nr; i < old_nr; i += new_nr) folio_page(folio, i)->memcg_data = folio->memcg_data; if (folio_memcg_kmem(folio)) - obj_cgroup_get_many(__folio_objcg(folio), nr - 1); + obj_cgroup_get_many(__folio_objcg(folio), old_nr / new_nr - 1); else - css_get_many(&memcg->css, nr - 1); + css_get_many(&memcg->css, old_nr / new_nr - 1); } #ifdef CONFIG_SWAP diff --git a/mm/page_alloc.c b/mm/page_alloc.c index b6e8fe6fed67..9d4dd41d0647 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -2653,7 +2653,7 @@ void split_page(struct page *page, unsigned int order) for (i = 1; i < (1 << order); i++) set_page_refcounted(page + i); split_page_owner(page, order); - split_page_memcg(page, order); + split_page_memcg(page, order, 0); } EXPORT_SYMBOL_GPL(split_page); @@ -4838,7 +4838,7 @@ static void *make_alloc_exact(unsigned long addr, unsigned int order, struct page *last = page + nr; split_page_owner(page, order); - split_page_memcg(page, order); + split_page_memcg(page, order, 0); while (page < --last) set_page_refcounted(last);