From patchwork Thu Aug 15 05:04:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shakeel Butt X-Patchwork-Id: 13764398 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 CC4A3C52D7F for ; Thu, 15 Aug 2024 05:05:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6371C6B008A; Thu, 15 Aug 2024 01:05:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5BF6C6B008C; Thu, 15 Aug 2024 01:05:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4600A6B0092; Thu, 15 Aug 2024 01:05:28 -0400 (EDT) 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 221E66B008A for ; Thu, 15 Aug 2024 01:05:28 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id BBF9D120DBB for ; Thu, 15 Aug 2024 05:05:27 +0000 (UTC) X-FDA: 82453291494.11.1B085A1 Received: from out-187.mta1.migadu.com (out-187.mta1.migadu.com [95.215.58.187]) by imf29.hostedemail.com (Postfix) with ESMTP id 143BE12001F for ; Thu, 15 Aug 2024 05:05:25 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=X0EawjGD; spf=pass (imf29.hostedemail.com: domain of shakeel.butt@linux.dev designates 95.215.58.187 as permitted sender) smtp.mailfrom=shakeel.butt@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1723698254; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=3kd/o0yNhsTl6XgkxdFjWyNP+hd5ZpFtgpy4OdScm7c=; b=3Ymq8AyEqMWke8pHWCUbV8puVk+7KfXiEGFwv94rvzWst1fgE29LtEtDDrbUDjZW6hScph XZk1l2c7fq3PdMMCqfB5nO5Q6eU0bvTWeMBm4YUOLg6mVQjpb9TpHRQGOErDL3Wcq2uZoY SPoA+x8TK+j3n/ml04ff0ymJDcnc0J8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723698254; a=rsa-sha256; cv=none; b=3PPl6jct/syMFESriP/3oBXok1ZRs56qWQIvtxm549ahbub1KwiaKjgmO6WODSB5InsUeT z5tI7QWr3HS7cnmhlXs9M2ldKIg3hTc/qQjsmO+fKyJsRRG9f0euUAsVDO/wkf93cbXOSa MxICxEOrjduA+qZB+EytoyaLtQtXhM8= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=X0EawjGD; spf=pass (imf29.hostedemail.com: domain of shakeel.butt@linux.dev designates 95.215.58.187 as permitted sender) smtp.mailfrom=shakeel.butt@linux.dev; dmarc=pass (policy=none) header.from=linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1723698324; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3kd/o0yNhsTl6XgkxdFjWyNP+hd5ZpFtgpy4OdScm7c=; b=X0EawjGDGBt0x9QlW3FR9g3CeR2jLvJN8b92rhYl0C8WSp8MKMgYF8pjXvM+UazgUhT92s 7sLOcrK9t6peoDGdE7HiOQtlxG83UkRbwLpUgeCDl9mkGc0cWuKmJtSd96jllCUoH5ISwe 0Vf/bgMX7pYM3B6MiFwezeZns1BD21c= From: Shakeel Butt To: Andrew Morton Cc: Johannes Weiner , Michal Hocko , Roman Gushchin , Muchun Song , "T . J . Mercier" , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Meta kernel team , cgroups@vger.kernel.org Subject: [PATCH 2/7] memcg: move mem_cgroup_event_ratelimit to v1 code Date: Wed, 14 Aug 2024 22:04:48 -0700 Message-ID: <20240815050453.1298138-3-shakeel.butt@linux.dev> In-Reply-To: <20240815050453.1298138-1-shakeel.butt@linux.dev> References: <20240815050453.1298138-1-shakeel.butt@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Queue-Id: 143BE12001F X-Stat-Signature: cku93w4h5e6o7uk3nfr5uhfnn7i8fc6u X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1723698325-789250 X-HE-Meta: U2FsdGVkX18uO3avTzPfoTeD8j2Kyv938MEdanrljFxNJDww8ogBH1bXj2bNtPv8feTaHJMmq4aHMvXhc4oKhW2mD8XlrBtRi//HAO0Sk3SxUGhIot6MA8of13uNiBLrDp6Xo7ZBpvgHfQH5QkleulUOusz0DRlAmyUZjcG+XIDjH1HfA4mECDRVgijfJ68x+tgx0ALd0B3LGTXi9kg5hS1ifSEB1+CAdK/rsb8eJ+fd5pWQYvI94+PGY68ULi1a0nsM4eWCZBVhUktq8xJ8SPNq7Sft0n4/Gg4ciLKYsYJ/GGLaIeg5EaL9918eRu79/+R+kh8uxHLtGNlCdHAQxtJxV6zujtN3t9ZXpz2Qo7DiP6FJ9A2YWfXdvKCIOwxnwYH45ieEYsdK496uxwsJIOqR/2dyO16yMHiB4imipa8Hd27sCv86bKf9MA4c2wDFuxi38p359bJcWumXFWWgqlgCh0ufYgMz/3RjxDDwIG6YBuUrN98WnZXK6WxaAHRvTM+mHw0b8KCDnGCxw9xnFTkLU5EfSipF/8Vkbhh+6hFvXLDR+zw4AhnkEM6MIIXSS+gjUo9kwcqnmEBb/xll1RoWDB1gmnvJtu445OX0dL0iagWUnhbK5H3heBw4KhJd0/OQ1NeePyE9fIDEhzwej51RIAg+ugqRX5rsOl1SZEhBpIDN9Y94jehz+q8jeLTpQo/Acu1ihvOcsUjYT+3YvR/g3R3i1Qpos/8/wDhJ/4Nq2tf570zNBSwuSr9ga4tA7A4NyIMDH+EAT/B2c1mC/j+lvXGVICtn7qjByy8vTrtMmx8yuFHbaPSwrFgE68zYIi26/yC9SzDDngMe8pRKBhoDtfOdUf+GikNEU6XSRADjx1nqg8P381RzaE9kE0Xp/CQwEKNc290KXae7GYgdYSTobG3fX6IFKbDUaXXyUljRUuFv0u4MFBv2KlI+Btimrd2b4E3whszZQdLAMqT 4oShLgRy rgtfSas7JhOZnpVa3h+5xUK7lnLOh07sAg/zKWxXuJiU0DyG5JBzwtmxLozHpJgLEaZRn6J00d6+0JvVcIPGASd/sv9TLz+qg6G/mWZrCloicnDNNprbxkehTRr0jQhUfyMriTo0bDq0GReJSqO9kt2mHgg== 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: There are no callers of mem_cgroup_event_ratelimit() in the v2 code. Move it to v1 only code and rename it to memcg1_event_ratelimit(). Signed-off-by: Shakeel Butt --- mm/memcontrol-v1.c | 32 ++++++++++++++++++++++++++++++-- mm/memcontrol-v1.h | 2 -- mm/memcontrol.c | 28 ---------------------------- 3 files changed, 30 insertions(+), 32 deletions(-) diff --git a/mm/memcontrol-v1.c b/mm/memcontrol-v1.c index 52aecdae2c28..0ce1807ba468 100644 --- a/mm/memcontrol-v1.c +++ b/mm/memcontrol-v1.c @@ -1439,6 +1439,34 @@ static void mem_cgroup_threshold(struct mem_cgroup *memcg) } } +#define THRESHOLDS_EVENTS_TARGET 128 +#define SOFTLIMIT_EVENTS_TARGET 1024 + +static bool memcg1_event_ratelimit(struct mem_cgroup *memcg, + enum mem_cgroup_events_target target) +{ + unsigned long val, next; + + val = __this_cpu_read(memcg->events_percpu->nr_page_events); + next = __this_cpu_read(memcg->events_percpu->targets[target]); + /* from time_after() in jiffies.h */ + if ((long)(next - val) < 0) { + switch (target) { + case MEM_CGROUP_TARGET_THRESH: + next = val + THRESHOLDS_EVENTS_TARGET; + break; + case MEM_CGROUP_TARGET_SOFTLIMIT: + next = val + SOFTLIMIT_EVENTS_TARGET; + break; + default: + break; + } + __this_cpu_write(memcg->events_percpu->targets[target], next); + return true; + } + return false; +} + /* * Check events in order. * @@ -1449,11 +1477,11 @@ void memcg1_check_events(struct mem_cgroup *memcg, int nid) return; /* threshold event is triggered in finer grain than soft limit */ - if (unlikely(mem_cgroup_event_ratelimit(memcg, + if (unlikely(memcg1_event_ratelimit(memcg, MEM_CGROUP_TARGET_THRESH))) { bool do_softlimit; - do_softlimit = mem_cgroup_event_ratelimit(memcg, + do_softlimit = memcg1_event_ratelimit(memcg, MEM_CGROUP_TARGET_SOFTLIMIT); mem_cgroup_threshold(memcg); if (unlikely(do_softlimit)) diff --git a/mm/memcontrol-v1.h b/mm/memcontrol-v1.h index 8feccecf8e2a..fb7d439f19de 100644 --- a/mm/memcontrol-v1.h +++ b/mm/memcontrol-v1.h @@ -62,8 +62,6 @@ struct memcg1_events_percpu { unsigned long targets[MEM_CGROUP_NTARGETS]; }; -bool mem_cgroup_event_ratelimit(struct mem_cgroup *memcg, - enum mem_cgroup_events_target target); unsigned long mem_cgroup_usage(struct mem_cgroup *memcg, bool swap); void drain_all_stock(struct mem_cgroup *root_memcg); diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 66d60bb56f91..7ea511119567 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -95,9 +95,6 @@ static bool cgroup_memory_nobpf __ro_after_init; static DECLARE_WAIT_QUEUE_HEAD(memcg_cgwb_frn_waitq); #endif -#define THRESHOLDS_EVENTS_TARGET 128 -#define SOFTLIMIT_EVENTS_TARGET 1024 - static inline bool task_is_dying(void) { return tsk_is_oom_victim(current) || fatal_signal_pending(current) || @@ -864,31 +861,6 @@ void mem_cgroup_charge_statistics(struct mem_cgroup *memcg, int nr_pages) __this_cpu_add(memcg->events_percpu->nr_page_events, nr_pages); } -bool mem_cgroup_event_ratelimit(struct mem_cgroup *memcg, - enum mem_cgroup_events_target target) -{ - unsigned long val, next; - - val = __this_cpu_read(memcg->events_percpu->nr_page_events); - next = __this_cpu_read(memcg->events_percpu->targets[target]); - /* from time_after() in jiffies.h */ - if ((long)(next - val) < 0) { - switch (target) { - case MEM_CGROUP_TARGET_THRESH: - next = val + THRESHOLDS_EVENTS_TARGET; - break; - case MEM_CGROUP_TARGET_SOFTLIMIT: - next = val + SOFTLIMIT_EVENTS_TARGET; - break; - default: - break; - } - __this_cpu_write(memcg->events_percpu->targets[target], next); - return true; - } - return false; -} - struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p) { /*