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 36BAFC19F32 for ; Thu, 6 Mar 2025 01:07:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4DBDF6B008C; Wed, 5 Mar 2025 20:07:11 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 48AEE6B0093; Wed, 5 Mar 2025 20:07:11 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 354D6280002; Wed, 5 Mar 2025 20:07:11 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 190B56B008C for ; Wed, 5 Mar 2025 20:07:11 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id D5585120DCE for ; Thu, 6 Mar 2025 01:07:10 +0000 (UTC) X-FDA: 83189337420.21.CC02F3B Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) by imf30.hostedemail.com (Postfix) with ESMTP id B0FEC8000C for ; Thu, 6 Mar 2025 01:07:08 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=MgAgkUee; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf30.hostedemail.com: domain of inwardvessel@gmail.com designates 209.85.214.169 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=1741223228; 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=3g5tO8cV38QyN61/JAPGKrpC1UagZdhR6CAA1Vj0Ft4=; b=wHL/FTvxVHNXoAwjSM/O03wJ6LAs8q3cR1nHt0Nk5LoAV1/GvqJXDJS03kbyIyDepDf8td L26cPeY+2gDGkCUmfAeogOSdejxI5SjwEQCjoZFodChLQ9ROr3iF5c+IN0jOOglGjmzFvK aofJcSxlVElBTsOwla9/EHi0o4bFgWg= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=MgAgkUee; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf30.hostedemail.com: domain of inwardvessel@gmail.com designates 209.85.214.169 as permitted sender) smtp.mailfrom=inwardvessel@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1741223228; a=rsa-sha256; cv=none; b=cH+8lRz9OhImuP02zmQwewnd2e0QXV5jrkb8n66InmuIfXDRIcM20Sb8jhybqlzNIMMJgn FOinp+LtOM1dMXMfVa7sU1YQvQ/pQ7VJXEa70RZ3JLbVGIsWGWkadPdllZJSjaTqNL+vPE LhQJMlA93S+glG5fUx7KmfYH0zx9shk= Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-223fd89d036so1178405ad.1 for ; Wed, 05 Mar 2025 17:07:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741223227; x=1741828027; darn=kvack.org; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:subject:from:user-agent:mime-version:date:message-id:from:to :cc:subject:date:message-id:reply-to; bh=3g5tO8cV38QyN61/JAPGKrpC1UagZdhR6CAA1Vj0Ft4=; b=MgAgkUee6siPVqnBVR+HlGaAr74LJ12ddQ/JlgHzSpWI8xvGtOSECWfFWG1G/JqMEb OFSpSXCJZX09K+232j/f66bWndy5oGKSwLxgIOKPdmqkqUBzx/AH/GwLwYQQIb470ZiK iKztjz3s8/gTXPs16Lzo9VLlX0asoIzhkVgd00qVfDqvh+ITuVgymwX32UlQ8YnLipSx IhlQD6zg6QEFR2LW1mapZmDRGxvFj5pdzKhT2lOI4HudArAEzwnV3ndzvGP6g1qUcqnC kMX3VvbjKPTPgm/OIaKs6QmRuKiELEP4xc2G+eSt1YsemvIFs03k2qYUri09Tv1wIaCO pOMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741223227; x=1741828027; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:subject:from:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=3g5tO8cV38QyN61/JAPGKrpC1UagZdhR6CAA1Vj0Ft4=; b=hmuKHhD3y+pvXso85Ayjebq3XU65uSTaRU7YPrHzvFtiJy+fVXT0o7U8tSDPsGqwLl CyxotZm+VJkovAYaVdo2J9ZZSlyu0tPbQM6pay0DERiQ/931GX4hR/k2w1FtFM85QFV+ 5oJmH4Aqj0bm9k4sUmJeYLl/KvOnqC1FZYviR6VSsyEt//ndDMDBuJE/huIS78kasoiY wIHGx8zO81pr2wehcY0usOdtq1h+1KJrCh19cgk/nDXadfbKkaS1l0nlcRtTbY/uWdJg HCenDTB+HJ4TozinxgElQYzzBGm1fOzJ4UX3v/I8EY2C/Xl7vTCKU3zy5Df60VVcZLU/ X2bA== X-Forwarded-Encrypted: i=1; AJvYcCXVDlSxHO5IeEH+gJK3AOGhJCm1VS9mnMcPP9pLYtF4JvWMmoX8bHchz70DYHrolPB1xXchsUTnyw==@kvack.org X-Gm-Message-State: AOJu0Yx4QhA8FooRGf71C+fgT7DpV7+UR/iPXDGhGG/o8HvZ+iAoBS3Q y0adVgeX3HKm3qSXinCcF+XL3NiN3cniwyrkqrmmMGnUJpYbrFjH X-Gm-Gg: ASbGncuQeu+FF+yt0ly5TRauZ6GTBNP0im6kEAM53ciJVgFCItH/CjA6GYVbowLr48b l20217ghMxO8lP/vRFGbx67XZR7H5vSGIV0WQJr1Dy4sX9DafuJGITggx/i7bXydvo68HVXqCfY J+EU3ZJVxMapOyHZl7auhIqKYYwBcd0tBVSFJas1xJv9p/whIgiG+g/z+7Ww4NEgxExRfyWKXoy ammqgPi2KWHl5St+7v+lwLp8KfquP1IxkP9vnYDLrGCeGaT3+2aIbpZlZEZsyLUCV1watdFrS/n ATZvTTjlSknWI0RftYxDmXRwm8EbfppPbm2CRGpfFQbC/YmTRdSC/aHicTtkNKoQS0YOg1CA1p3 JHw== X-Google-Smtp-Source: AGHT+IFI3/1Oy3hjhmvUKD4jzNMztsCiCuoTh6rFklQOBtUj+YMyniy9SIBkPT7jFyfc+tQ+hssUMA== X-Received: by 2002:a17:903:1c1:b0:224:93e:b5d7 with SMTP id d9443c01a7336-224093eb6afmr20756695ad.34.1741223227296; Wed, 05 Mar 2025 17:07:07 -0800 (PST) Received: from ?IPV6:2a03:83e0:1151:15:86f4:5731:1f28:6513? ([2620:10d:c090:500::5:58db]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-22410a7f700sm543275ad.144.2025.03.05.17.07.05 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 05 Mar 2025 17:07:06 -0800 (PST) Message-ID: Date: Wed, 5 Mar 2025 17:07:04 -0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird From: JP Kobryn Subject: Re: [PATCH 0/4 v2] cgroup: separate rstat trees To: =?UTF-8?Q?Michal_Koutn=C3=BD?= Cc: tj@kernel.org, shakeel.butt@linux.dev, yosryahmed@google.com, mhocko@kernel.org, hannes@cmpxchg.org, akpm@linux-foundation.org, linux-mm@kvack.org, cgroups@vger.kernel.org, kernel-team@meta.com References: <20250227215543.49928-1-inwardvessel@gmail.com> Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: B0FEC8000C X-Rspam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NdGgOl3sReANv/iScBNYx+oCNtJUzslaGdbMV6XKc5oGjdpKeCkWIEwl3GpN8XT5heVIItXV/+EzBN8+xyC3o4DVUdG5P1f6dSYg8cbIyXKJifHGS/FyodyHaclrNHAy+A4VHDc7TdjAplDJZ7VjzXN6BrJgzjFIO1v6BfO8MRvlpONjaFQR1NF/fBmd4kFH4oDgaqZszoSYkMWTMef5P0fAN3wv8I4LpUtxwjWHZX9LRGHcQlsc/h70V84RqJDFwyIbimvsMjLFRcsfThcfBmGuYn2bXQNEVJW71Qiv/S8YxICCJtqHsqT4zTD8WhmpbwBmAvQCzu1JJbeXC2T6GXQ8EyRi/DRJQXU6sLm0LCfuCcz/c1z6LRpCannXggOIJXpv/+wJvLE0xjnHeGkUPzNwZ+BcszKb21i3fvgzTT4VxrEz96kG21bbrTWn2gaMlFD4rnMQlIv50zkq/T2I= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000010, 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 3/3/25 7:19 AM, Michal Koutný wrote: > Hello JP. > > On Thu, Feb 27, 2025 at 01:55:39PM -0800, inwardvessel wrote: >> From: JP Kobryn >> >> The current design of rstat takes the approach that if one subsystem is >> to be flushed, all other subsystems with pending updates should also be >> flushed. It seems that over time, the stat-keeping of some subsystems >> has grown in size to the extent that they are noticeably slowing down >> others. This has been most observable in situations where the memory >> controller is enabled. One big area where the issue comes up is system >> telemetry, where programs periodically sample cpu stats. It would be a >> benefit for programs like this if the overhead of having to flush memory >> stats (and others) could be eliminated. It would save cpu cycles for >> existing cpu-based telemetry programs and improve scalability in terms >> of sampling frequency and volume of hosts. > >> This series changes the approach of "flush all subsystems" to "flush >> only the requested subsystem". > ... > >> before: >> sizeof(struct cgroup_rstat_cpu) =~ 176 bytes /* can vary based on config */ >> >> nr_cgroups * sizeof(struct cgroup_rstat_cpu) >> nr_cgroups * 176 bytes >> >> after: > ... >> nr_cgroups * (176 + 16 * 2) >> nr_cgroups * 208 bytes > > ~ 32B/cgroup/cpu Thanks. I'll make this clear in the cover letter next rev. > >> With regard to validation, there is a measurable benefit when reading >> stats with this series. A test program was made to loop 1M times while >> reading all four of the files cgroup.stat, cpu.stat, io.stat, >> memory.stat of a given parent cgroup each iteration. This test program >> has been run in the experiments that follow. > > Thanks for looking into this and running experiments on the behavior of > split rstat trees. And thank you for reviewing along with the good questions. > >> The first experiment consisted of a parent cgroup with memory.swap.max=0 >> and memory.max=1G. On a 52-cpu machine, 26 child cgroups were created >> and within each child cgroup a process was spawned to frequently update >> the memory cgroup stats by creating and then reading a file of size 1T >> (encouraging reclaim). The test program was run alongside these 26 tasks >> in parallel. The results showed a benefit in both time elapsed and perf >> data of the test program. >> >> time before: >> real 0m44.612s >> user 0m0.567s >> sys 0m43.887s >> >> perf before: >> 27.02% mem_cgroup_css_rstat_flush >> 6.35% __blkcg_rstat_flush >> 0.06% cgroup_base_stat_cputime_show >> >> time after: >> real 0m27.125s >> user 0m0.544s >> sys 0m26.491s > > So this shows that flushing rstat trees one by one (as the test program > reads *.stat) is quicker than flushing all at once (+idle reads of > *.stat). > Interesting, I'd not bet on that at first but that is convincing to > favor the separate trees approach. > >> perf after:mem_cgroup_css_rstat_flush >> 6.03% mem_cgroup_css_rstat_flush >> 0.37% blkcg_print_stat >> 0.11% cgroup_base_stat_cputime_show > > I'd understand why the series reduces time spent in > mem_cgroup_flush_stats() but what does the lower proportion of > mem_cgroup_css_rstat_flush() show? When the entry point for flushing is reading the file memory.stat, memory_stat_show() is called which leads to __mem_cgroup_flush_stats(). In this function, there is an early return when (!force && !needs_flush) is true. This opportunity to "skip" a flush is not reached when another subsystem has initiated the flush and entry point for flushing memory is css->css_rstat_flush(). To verify above, I made use of a tracepoint previously added [0] to get info info on the number of memcg flushes performed vs skipped. In a comparison between reading only the memory.stat file vs reading {memory,io,cpu}.stat files under the same test, the flush count increased by about the same value the skip count decreased. Reading memory.stat non-forced flushes: 5781 flushes skipped: 995826 Reading {memory,io.cpu}.stat non-forced flushes: 12047 flushes skipped: 990857 If the flushes were not skipped, I think we would see similar proportion of mem_cgroup_css_rstat_flush() when reading memory.stat. [0] https://lore.kernel.org/all/20241029021106.25587-1-inwardvessel@gmail.com/ > > >> Another experiment was setup on the same host using a parent cgroup with >> two child cgroups. The same swap and memory max were used as the >> previous experiment. In the two child cgroups, kernel builds were done >> in parallel, each using "-j 20". The perf comparison of the test program >> was very similar to the values in the previous experiment. The time >> comparison is shown below. >> >> before: >> real 1m2.077s >> user 0m0.784s >> sys 1m0.895s > > This is 1M loops of stats reading program like before? I.e. if this > should be analogous to 0m44.612s above why isn't it same? (I'm thinking > of more frequent updates in the latter test.) Yes. One notable difference on this test is there are more threads in the workload (40 vs 26) which are doing the updates. > >> after: >> real 0m32.216s >> user 0m0.709s >> sys 0m31.256s > > What was impact on the kernel build workloads (cgroup_rstat_updated)? You can now find some workload timing results further down. If you're asking specifically about time spent in cgroup_rstat_updated(), perf reports show fractional values on both sides. > > (Perhaps the saved 30s of CPU work (if potentially moved from readers to > writers) would be spread too thin in all of two 20-parallel kernel > builds, right?) Are you suggesting a workload with fewer threads? > > ... >> For the final experiment, perf events were recorded during a kernel >> build with the same host and cgroup setup. The builds took place in the >> child node. Control and experimental sides both showed similar in cycles >> spent on cgroup_rstat_updated() and appeard insignificant compared among >> the events recorded with the workload. > > What's the change between control vs experiment? Runnning in root cg vs > nested? Or running without *.stat readers vs with them against the > kernel build? > (This clarification would likely answer my question above.) > workload control with no readers: real 6m54.818s user 117m3.122s sys 5m4.996s workload experiment with no readers: real 6m54.862s user 117m12.812s sys 5m0.943s workload control with constant readers {memory,io,cpu,cgroup}.stat: real 6m59.468s user 118m26.981s sys 5m20.163s workload experiment with constant readers {memory,io,cpu,cgroup}.stat: real 6m57.031s user 118m13.833s sys 5m3.454s These tests were done in a child (nested) cgroup. Were you also asking for a root vs nested experiment or were you just needing clarification on the test details? > > Michal