From mboxrd@z Thu Jan 1 00:00:00 1970 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 DC261D149CD for ; Fri, 25 Oct 2024 18:27:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 55E3B6B008C; Fri, 25 Oct 2024 14:27:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 50EA46B0092; Fri, 25 Oct 2024 14:27:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3D60E6B0095; Fri, 25 Oct 2024 14:27:00 -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 1F0C86B008C for ; Fri, 25 Oct 2024 14:27:00 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 1D9BB40E74 for ; Fri, 25 Oct 2024 18:26:49 +0000 (UTC) X-FDA: 82712955192.13.52948F9 Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) by imf27.hostedemail.com (Postfix) with ESMTP id A22E44000A for ; Fri, 25 Oct 2024 18:26:37 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=EDCRHAiz; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf27.hostedemail.com: domain of inwardvessel@gmail.com designates 209.85.216.41 as permitted sender) smtp.mailfrom=inwardvessel@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729880692; a=rsa-sha256; cv=none; b=1IfTm4Osq6MFgqDP455FSl32KvQnuHWAdB1/VSw5/F3H0IxVodhvd8oCVICyyv/y6Mf3H5 L0amkSl2Ky/v3KJoNIIgnQG2UZdEM9j5BZ5VdezVEyDn/M+iIMqW5XrO3fDhdQ84GiaNCg qhV3LziqGrTSEm6z7WyiyboTqUADiS0= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=EDCRHAiz; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf27.hostedemail.com: domain of inwardvessel@gmail.com designates 209.85.216.41 as permitted sender) smtp.mailfrom=inwardvessel@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729880692; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ql2NdbXSkfYGipdoKTi487hWlak8rqljNeSnzCYiOXo=; b=wLt4G07AE6LFTJGcUh5bpqfKZ4vRof0ZKxTSC2OXTliHvQp5MIoaXIHHtG2F+rtcFCvbHD bBDMSkDgnsjH00mxglCsoDND2764CBfyG/1xF23/tgGxbytvLbExOJSU+Y1GbzqJT16B/s b46joJ+yyv0KlVO+NGv7NtFnGj5H4wM= Received: by mail-pj1-f41.google.com with SMTP id 98e67ed59e1d1-2e2ed2230d8so1805994a91.0 for ; Fri, 25 Oct 2024 11:26:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729880816; x=1730485616; darn=kvack.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=ql2NdbXSkfYGipdoKTi487hWlak8rqljNeSnzCYiOXo=; b=EDCRHAiztj7hwBog/+8Ww7zVH6g1lwyJOxtJpJ9FGFuZO2Q+Jg9kGhgVZL1GBFF4fm y5tk69k6og1a42BGJmo8w3RgUSzVLHhkI87OVPDh6rjFaWOO9zuV4Lt/IR83ShEbfG8g W2CeaDewPzki0Dxu8e74gzRFlAUk+hqxgNXV+ceLdF00+EALzBmHxYVrdi4P2wn3ng4w L644yy6jrZ/i+WwqkPSnsDvCzWkPysBh7uHZcirJMA1Cv97hKJWAZXOP8YEMzE/p1MmA faAIXoSIv6Let/87NKNqiOfPeZxVvBGXmguW/nx7OON7xH8+p0CVw+cNpbvfg6AFzrJC 9Pxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729880816; x=1730485616; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ql2NdbXSkfYGipdoKTi487hWlak8rqljNeSnzCYiOXo=; b=Tgd2FpvOKc23LCR5Aq1wnPDF1VY5vMjbhBb8C0QWPs8BlwEvpo2RRzugarP0kP2MLG GoNJ9D0ldxueLadHg6KoloaFLYF7r/6KAb5vi775+FiDKSUb8dplcvIzXEHjyF3j25aL gO6vbwgI8hhwAN3JpGz3paQaT/2NX6grATZsQjb63bLyvknqAoRlIojrfRdKL5aFy0nV 2Dr6aIwV4p7lw4/oPkaVp6z2Jr2CqTdAKITm0jKhLQW7kipAXoTWMkU9gtowFrr0BuV4 gPCB+XxaD3WzD1pH8kb79SIr0rhTnKoHFtYVbHxgy0VDNTRdvnV+PXMMU50kxymDvXD3 R4fA== X-Forwarded-Encrypted: i=1; AJvYcCXFHRGG2gRZQTjqB+sYmGAKlkpP1c9fomt0aN6LG6/AnoWu2Gr7TYZ5jKp231MdE0VWi56zI9y0Uw==@kvack.org X-Gm-Message-State: AOJu0YzYVqEaT/0ZRfOKxlY5OnrFU+YKJNtAKP+kkXXCUQgR2KravR1z s07/eErEr5meQGYytI8/BoyMK/KMLnQplyJDr9VpQklgWoOVl9ai X-Google-Smtp-Source: AGHT+IGdR8TauvJA45i/zjGNl+kwwL0J3f5JdBGSaQPwA75prD8dLqXC+NHSwV4EUnVAkKXgwdFsBA== X-Received: by 2002:a17:90a:ca83:b0:2e2:e769:dffe with SMTP id 98e67ed59e1d1-2e8f11ac9b4mr318810a91.30.1729880816403; Fri, 25 Oct 2024 11:26:56 -0700 (PDT) Received: from [192.168.2.10] (c-67-188-127-15.hsd1.ca.comcast.net. [67.188.127.15]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e8e3572cadsm1812413a91.14.2024.10.25.11.26.54 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 25 Oct 2024 11:26:55 -0700 (PDT) Message-ID: <8c44b4d3-0083-42b6-8006-adcfaee04e19@gmail.com> Date: Fri, 25 Oct 2024 11:26:54 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 2/2] memcg: use memcg flush tracepoint To: Yosry Ahmed Cc: Shakeel Butt , hannes@cmpxchg.org, akpm@linux-foundation.org, rostedt@goodmis.org, linux-mm@kvack.org, cgroups@vger.kernel.org References: <20241025002511.129899-1-inwardvessel@gmail.com> <20241025002511.129899-3-inwardvessel@gmail.com> <3da0f38a-51f1-43fa-a625-6bb1fe992920@gmail.com> Content-Language: en-US From: JP Kobryn In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: A22E44000A X-Stat-Signature: h6jkfioxqofuqapwp8t5wkr1r8c5gqt5 X-Rspam-User: X-HE-Tag: 1729880797-998712 X-HE-Meta: U2FsdGVkX19LdGwahM479zeh8vgFVFL+YDU0vNiw/qPEH6mCSDLGlRu/kgTSw6sdQqhl7maL++pjB4YzTT0oFCYM5p76yFy8i/wBVxpz0YL7BS8WIRfoNBFLy3ElBNWdXpsl/E3NV6xbh//sfVlwDtQRke/sRTj7WJEqmEUj2fBaZoNKvU4vJPW28UabosTKxwjz23SQHP2zbQkaJ4ZsRHqLnKVEtK8XJJoICTngZFOgwq8fmUj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nVXQ+UiTlTtkw8Vl58eixrFvxO7pFutV0JwfZdKx5ySULCy1WCLOzFlZxsK8Jgspt39mmNxkpY9R71yCkw5ORFbeH1GR3ixr8JqynUdBaQce2YHTp3Jb 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: On 10/25/24 10:53 AM, Yosry Ahmed wrote: > On Fri, Oct 25, 2024 at 10:05 AM JP Kobryn wrote: >> >> On 10/25/24 12:40 AM, Yosry Ahmed wrote: >>> On Thu, Oct 24, 2024 at 6:16 PM Shakeel Butt wrote: >>>> On Thu, Oct 24, 2024 at 05:57:25PM GMT, Yosry Ahmed wrote: >>>>> On Thu, Oct 24, 2024 at 5:26 PM JP Kobryn wrote: >>>>>> Make use of the flush tracepoint within memcontrol. >>>>>> >>>>>> Signed-off-by: JP Kobryn >>>>> Is the intention to use tools like bpftrace to analyze where we flush >>>>> the most? In this case, why can't we just attach to the fentry of >>>>> do_flush_stats() and use the stack trace to find the path? >>>>> >>>>> We can also attach to mem_cgroup_flush_stats(), and the difference in >>>>> counts between the two will be the number of skipped flushes. >>>>> >>>> All these functions can get inlined and then we can not really attach >>>> easily. We can somehow find the offset in the inlined places and try to >>>> use kprobe but it is prohibitive when have to do for multiple kernels >>>> built with fdo/bolt. >>>> >>>> Please note that tracepoints are not really API, so we can remove them >>>> in future if we see no usage for them. >>> That's fair, but can we just add two tracepoints? This seems enough to >>> collect necessary data, and prevent proliferation of tracepoints and >>> the addition of the enum. >>> >>> I am thinking one in mem_cgroup_flush_stats() and one in >>> do_flush_stats(), e.g. trace_mem_cgroup_flush_stats() and >>> trace_do_flush_stats(). Although the name of the latter is too >>> generic, maybe we should rename the function first to add mem_cgroup_* >>> or memcg_*. >>> >>> WDYT? >> Hmmm, I think if we did that we wouldn't get accurate info on when the >> flush was skipped. Comparing the number of hits between >> mem_cgroup_flush_stats() and do_flush_stats() to determine the number of >> skips doesn't seem reliable because of the places where do_flush_stats() >> is called outside of mem_cgroup_flush_stats(). There would be situations >> where a skip occurs, but meanwhile each call to do_flush_stats() outside >> of mem_cgroup_flush_stats() would effectively subtract that skip, making >> it appear that a skip did not occur. > You're underestimating the power of BPF, my friend :) We can count the > number of flushes in task local storages, in which case we can get a > very accurate representation because the counters are per-task, so we > know exactly when we skipped, but.. Interesting. Thanks for explaining. > >> Maybe as a middle ground we could remove the trace calls for the zswap >> and periodic cases, since no skips can occur there. We could then just >> leave one trace call in mem_cgroup_flush_stats() and instead of an enum >> we can pass a bool saying skipped or not. Something like this: >> >> mem_cgroup_flush_stats() >> >> { >> >> bool needs_flush = memcg_vmstats_needs_flush(...); >> >> trace_memcg_flush_stats(memcg, needs_flush); >> >> if (needs_flush) >> >> do_flush_stats(...); >> >> } >> >> >> Yosry/Shakeel, do you have any thoughts on whether we should keep the >> trace calls for obj_cgroup_may_zswap() and periodic workqueue cases? > ..with that being said, I do like having a single tracepoint. I think > with some refactoring we can end up with a single tracepoint and more > data. We can even capture the cases where we force a flush but we > don't really need to flush. We can even add vmstats->stats_updates to > the tracepoint to know exactly how many updates we have when we flush. > > What about the following: > > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > index 7845c64a2c570..be0e7f52ad11a 100644 > --- a/mm/memcontrol.c > +++ b/mm/memcontrol.c > @@ -584,8 +584,14 @@ static inline void memcg_rstat_updated(struct > mem_cgroup *memcg, int val) > } > } > > -static void do_flush_stats(struct mem_cgroup *memcg) > +static void __mem_cgroup_flush_stats(struct mem_cgroup *memcg, bool force) > { > + bool needs_flush = memcg_vmstats_needs_flush(memcg->vmstats); > + > + trace_memcg_flush_stats(memcg, needs_flush, force, ...); > + if (!force && !needs_flush) > + return; > + > if (mem_cgroup_is_root(memcg)) > WRITE_ONCE(flush_last_time, jiffies_64); > > @@ -609,8 +615,7 @@ void mem_cgroup_flush_stats(struct mem_cgroup *memcg) > if (!memcg) > memcg = root_mem_cgroup; > > - if (memcg_vmstats_needs_flush(memcg->vmstats)) > - do_flush_stats(memcg); > + __mem_cgroup_flush_stats(memcg, false); > } > > void mem_cgroup_flush_stats_ratelimited(struct mem_cgroup *memcg) > @@ -626,7 +631,7 @@ static void flush_memcg_stats_dwork(struct work_struct *w) > * Deliberately ignore memcg_vmstats_needs_flush() here so that flushing > * in latency-sensitive paths is as cheap as possible. > */ > - do_flush_stats(root_mem_cgroup); > + __mem_cgroup_flush_stats(root_mem_cgroup, true); > queue_delayed_work(system_unbound_wq, &stats_flush_dwork, FLUSH_TIME); > } > > @@ -5272,11 +5277,8 @@ bool obj_cgroup_may_zswap(struct obj_cgroup *objcg) > break; > } > > - /* > - * mem_cgroup_flush_stats() ignores small changes. Use > - * do_flush_stats() directly to get accurate stats for charging. > - */ > - do_flush_stats(memcg); > + /* Force a flush to get accurate stats for charging */ > + __mem_cgroup_flush_stats(memcg, true); > pages = memcg_page_state(memcg, MEMCG_ZSWAP_B) / PAGE_SIZE; > if (pages < max) > continue; I like the additional info. I'll incorporate this into v2.