From patchwork Tue Feb 13 21:55:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 13555736 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 D6766C48260 for ; Tue, 13 Feb 2024 21:55:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 68C3B8D0019; Tue, 13 Feb 2024 16:55:51 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 63E048D0012; Tue, 13 Feb 2024 16:55:51 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 48F058D0019; Tue, 13 Feb 2024 16:55:51 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 33FFE8D0012 for ; Tue, 13 Feb 2024 16:55:51 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id A22F9A0842 for ; Tue, 13 Feb 2024 21:55:50 +0000 (UTC) X-FDA: 81788138460.14.3A357BE Received: from out5-smtp.messagingengine.com (out5-smtp.messagingengine.com [66.111.4.29]) by imf01.hostedemail.com (Postfix) with ESMTP id 96E8340015 for ; Tue, 13 Feb 2024 21:55:48 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=sent.com header.s=fm3 header.b=LTPl4PvC; dkim=pass header.d=messagingengine.com header.s=fm3 header.b=NS1rZYqI; dmarc=pass (policy=none) header.from=sent.com; spf=pass (imf01.hostedemail.com: domain of zi.yan@sent.com designates 66.111.4.29 as permitted sender) smtp.mailfrom=zi.yan@sent.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707861348; 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=43KUO5pZ3osjy6nQRy6LW8cIMJ14A3p6oz8yC6ceQKk=; b=GSo0SuQutA3RaFBHRtxwTX0Qt9oiGzqpqxuew2Fk62h9O0qPV0blmnI5XLH34tXCSkwQtK Nak1iz10t8i9ExMq9bjOatqbR4OdnyB9lJOohVnllKUULob0tMKzs6A3+iLwdDCg6NFo7B UDgURunyC1SbU8fMA9LCib/k/BxHdpE= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=sent.com header.s=fm3 header.b=LTPl4PvC; dkim=pass header.d=messagingengine.com header.s=fm3 header.b=NS1rZYqI; dmarc=pass (policy=none) header.from=sent.com; spf=pass (imf01.hostedemail.com: domain of zi.yan@sent.com designates 66.111.4.29 as permitted sender) smtp.mailfrom=zi.yan@sent.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707861348; a=rsa-sha256; cv=none; b=iAhMYkTxE8E3X1Z/vW82RnVQx7J1qTlywnwFITCTIrXmlh99Usm3a2lh8HLCCG1hIojSQC 2sMkuSZYpG2ls8sKLIGaxPYy28QQZNlBkfZ2TTSBkqHO5VQKZDRhOMNAZUCQExTGTbOchs hbEP8B442ivvpgX0s3ZBQSppDrmdSms= Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id D43925C00CA; Tue, 13 Feb 2024 16:55:47 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Tue, 13 Feb 2024 16:55:47 -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= 1707861347; x=1707947747; bh=43KUO5pZ3osjy6nQRy6LW8cIMJ14A3p6oz8 yC6ceQKk=; b=LTPl4PvCEFNUWDJZquJqdFcLG0owwHI9iL4COQiteBUhernnnNq LH6fO88G1V9ARLPVrpl41dw2Mvmbe7Dms1ZpgNKVpUx87Aw9LUnOSgvBw4+bcsbg Qts6nhxjVNsTFvJweIWEM8CzHPQin02SRUS+uxKYa8DO4jig+rm6zQMQSmM1gEmt JsRgaojL5wKkQqVb27ss0mEt3a+AdAxzleU7U+eGn6OrZMm3jMkUh7cmxMyzseoC UUG/n1QCRbZVEaCZEfaxkshdDkPg+XubSSDrDsUYGTbBl6axSRhmQBh9o6uW9Gi5 RBJ31EzlPhh4FML7qpweqDqojd6i9V4NVYA== 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= 1707861347; x=1707947747; bh=43KUO5pZ3osjy6nQRy6LW8cIMJ14A3p6oz8 yC6ceQKk=; b=NS1rZYqIDbBEaDSWg1X5bjk05SdO55tD+MgK8/KdvNjyX8L853q F9BmuErnawsM7nwDrkc7O3CFyEdZ6NkLWoNMUhlDOlWsbXuvOZl0MXQUdG4767R3 YN+egUo2h0XSD/tneJAwXP1569DVxKjnBpm1uCubpskQ4od7IPdHexduhByAfv9y a+JtAMDrL5trG/bCgFoqqGWga0eeMUDDEHdQAqfQnMdf2IUh0wJaq/kMBZ7PSgxW N/tZhT2zmPU1YsfUei38gjBePrKNQQH0Q2n4N4SX1FjCUUDajeiT11CuFsFk1yM8 50BlGNcQjabvDCvofI5zW4XvuKdaFuoV20w== 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:46 -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 1/7] mm/memcg: use order instead of nr in split_page_memcg() Date: Tue, 13 Feb 2024 16:55:14 -0500 Message-ID: <20240213215520.1048625-2-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: rspam09 X-Rspamd-Queue-Id: 96E8340015 X-Stat-Signature: u4oz4yy59z78ww1bsr19efssxxetz956 X-Rspam-User: X-HE-Tag: 1707861348-845942 X-HE-Meta: U2FsdGVkX19UKF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jgYAqTHkvrbabYyFsRrLApplQkbaKw8ZNQww0xy45YDS8ZCcIwNlqu23+K5xgh4CN6omJccS9FEl3USnm1EqbSeySX/tQRUpYTRf5tUbXkTDtEriqWajXhZWk2FTktsoogO8hGncd474HZU2vj20pR71LO0i0LHzXgnig/hfrfaTiTQql6nkY1TTtbdSdBntH71S/jstVrI8H/AqrRGBHdg+GoNxj7T6ZCRJUUBztOfRXx+xzqis9P4xU0rfy6rGOXydfg2BxGkpqnSl8B4eDWJjXy7IV9IzkMVTX8H3qAba2DXx4bj/0yoKp/0AQAQAvJ+UptkcKyyQo4wZ8V4MkHRaIbvgCtk7ULoQpSDxTCfU3Z6JhbQZZlko2fvWMrheXjuDvaDFCqzNSg== 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 We do not have non power of two pages, using nr is error prone if nr is not power-of-two. Use page order instead. Signed-off-by: Zi Yan Acked-by: David Hildenbrand --- include/linux/memcontrol.h | 4 ++-- mm/huge_memory.c | 3 ++- mm/memcontrol.c | 3 ++- mm/page_alloc.c | 4 ++-- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 4e4caeaea404..173bbb53c1ec 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, unsigned int nr); +void split_page_memcg(struct page *head, int 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, unsigned int nr) +static inline void split_page_memcg(struct page *head, int order) { } diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 016e20bd813e..0cd5fba0923c 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2877,9 +2877,10 @@ static void __split_huge_page(struct page *page, struct list_head *list, unsigned long offset = 0; unsigned int nr = thp_nr_pages(head); int i, nr_dropped = 0; + int order = folio_order(folio); /* complete memcg works before add pages to LRU */ - split_page_memcg(head, nr); + split_page_memcg(head, order); 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 93ad8640b741..404e529644c0 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -3608,11 +3608,12 @@ 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, unsigned int nr) +void split_page_memcg(struct page *head, int order) { struct folio *folio = page_folio(head); struct mem_cgroup *memcg = folio_memcg(folio); int i; + unsigned int nr = 1 << order; if (mem_cgroup_disabled() || !memcg) return; diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 7ae4b74c9e5c..7c927b84e16c 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, 1 << order); - split_page_memcg(page, 1 << order); + split_page_memcg(page, order); } 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, 1 << order); - split_page_memcg(page, 1 << order); + split_page_memcg(page, order); while (page < --last) set_page_refcounted(last);