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 22434EB64D9 for ; Tue, 11 Jul 2023 00:44:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8F4C48E0001; Mon, 10 Jul 2023 20:44:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8A2F68D0001; Mon, 10 Jul 2023 20:44:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 792B58E0001; Mon, 10 Jul 2023 20:44:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 675B28D0001 for ; Mon, 10 Jul 2023 20:44:23 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 4662F402AE for ; Tue, 11 Jul 2023 00:44:23 +0000 (UTC) X-FDA: 80997484806.13.79DFE48 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf12.hostedemail.com (Postfix) with ESMTP id 4B7D340004 for ; Tue, 11 Jul 2023 00:44:21 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=BR1zNz1Z; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf12.hostedemail.com: domain of longman@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=longman@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689036261; 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=xh89EtaamRoEiOvIq1NF8NCe+vpDYxFReDkvfE9D/uk=; b=KAi+LzWrdmeD9KPIAIW03N1HPRJXoRiqYG2F3fDjqlwZm22+uRDyHmZgWs773d3n4THRls TIGbf6d2yGXFf2ZvxqjHcKSH5Alw5iikyQnh2ysy7g16FOAwy0g9F5roYU7fl3rPUYI/sc ebWviN4gOmjDgRTEVBGCJcBddfLJQ0I= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=BR1zNz1Z; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf12.hostedemail.com: domain of longman@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=longman@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689036261; a=rsa-sha256; cv=none; b=21EnHl8grgykesX1a0fp6icNgdi/1O/CIc93yH0sGs5xqpr2A+TvnNVE3DR9cRJiaDNUCk VXnHafKiEPckQEywSmCGFOrF9Sno8rIg5Jji0GmnNfBa4sP8VRay5EfEg/zolZdkzMCPUy O54PoqAJkRdguIfd3crkpE43cJd8ijA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689036260; h=from:from: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; bh=xh89EtaamRoEiOvIq1NF8NCe+vpDYxFReDkvfE9D/uk=; b=BR1zNz1ZCVZwH2AxbQQsRswWHGFuyDPDNM4kWJB2/QMt5vKMi03944gMtpbOHiONaRYNcO 4Vkh+INgiDQfzEn4E+GrNYQSvu5fx7H5BnOf3+XJ4YwdJ/tVRiv8vgavW95jbaFQgjv1hL H6u6OOkFwlD4pC6ZA3wvZyzreeQRx5w= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-619-CLDbuslQOtGEC9Jy_DLEQw-1; Mon, 10 Jul 2023 20:44:17 -0400 X-MC-Unique: CLDbuslQOtGEC9Jy_DLEQw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 52C6A3844FA0; Tue, 11 Jul 2023 00:44:16 +0000 (UTC) Received: from [10.22.18.171] (unknown [10.22.18.171]) by smtp.corp.redhat.com (Postfix) with ESMTP id A7112145414E; Tue, 11 Jul 2023 00:44:15 +0000 (UTC) Message-ID: Date: Mon, 10 Jul 2023 20:44:15 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.1 Subject: Re: Expensive memory.stat + cpu.stat reads Content-Language: en-US To: Ivan Babrou , Shakeel Butt Cc: cgroups@vger.kernel.org, Linux MM , kernel-team , Johannes Weiner , Michal Hocko , Roman Gushchin , Muchun Song , Andrew Morton , linux-kernel References: <20230706062045.xwmwns7cm4fxd7iu@google.com> From: Waiman Long In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Rspam-User: X-Stat-Signature: tc4qemp811zyj13bguz9nsgfwpqp5f5x X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 4B7D340004 X-HE-Tag: 1689036261-79247 X-HE-Meta: U2FsdGVkX18iv24lpsGPxZliO2CNPYXskCG/KLm6A+v8oYql4ieS5uHVQpb/H27AJKOGdZwNm4CdZY9QK3RPCJSMw//9SCUwS8eWbakeyryjfYKAmofpQB+EkA5K1y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=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 7/10/23 19:21, Ivan Babrou wrote: > On Wed, Jul 5, 2023 at 11:20 PM Shakeel Butt wrote: >> On Fri, Jun 30, 2023 at 04:22:28PM -0700, Ivan Babrou wrote: >>> Hello, >>> >>> We're seeing CPU load issues with cgroup stats retrieval. I made a >>> public gist with all the details, including the repro code (which >>> unfortunately requires heavily loaded hardware) and some flamegraphs: >>> >>> * https://gist.github.com/bobrik/5ba58fb75a48620a1965026ad30a0a13 >>> >>> I'll repeat the gist of that gist here. Our repro has the following >>> output after a warm-up run: >>> >>> completed: 5.17s [manual / mem-stat + cpu-stat] >>> completed: 5.59s [manual / cpu-stat + mem-stat] >>> completed: 0.52s [manual / mem-stat] >>> completed: 0.04s [manual / cpu-stat] >>> >>> The first two lines do effectively the following: >>> >>> for _ in $(seq 1 1000); do cat /sys/fs/cgroup/system.slice/memory.stat >>> /sys/fs/cgroup/system.slice/cpu.stat > /dev/null >>> >>> The latter two are the same thing, but via two loops: >>> >>> for _ in $(seq 1 1000); do cat /sys/fs/cgroup/system.slice/cpu.stat > >>> /dev/null; done >>> for _ in $(seq 1 1000); do cat /sys/fs/cgroup/system.slice/memory.stat >>>> /dev/null; done >>> As you might've noticed from the output, splitting the loop into two >>> makes the code run 10x faster. This isn't great, because most >>> monitoring software likes to get all stats for one service before >>> reading the stats for the next one, which maps to the slow and >>> expensive way of doing this. >>> >>> We're running Linux v6.1 (the output is from v6.1.25) with no patches >>> that touch the cgroup or mm subsystems, so you can assume vanilla >>> kernel. >>> >>> From the flamegraph it just looks like rstat flushing takes longer. I >>> used the following flags on an AMD EPYC 7642 system (our usual pick >>> cpu-clock was blaming spinlock irqrestore, which was questionable): >>> >>> perf -e cycles -g --call-graph fp -F 999 -- /tmp/repro >>> >>> Naturally, there are two questions that arise: >>> >>> * Is this expected (I guess not, but good to be sure)? >>> * What can we do to make this better? >>> >>> I am happy to try out patches or to do some tracing to help understand >>> this better. >> Hi Ivan, >> >> Thanks a lot, as always, for reporting this. This is not expected and >> should be fixed. Is the issue easy to repro or some specific workload or >> high load/traffic is required? Can you repro this with the latest linus >> tree? Also do you see any difference of root's cgroup.stat where this >> issue happens vs good state? > I'm afraid there's no easy way to reproduce. We see it from time to > time in different locations. The one that I was looking at for the > initial email does not reproduce it anymore: My understanding of mem-stat and cpu-stat is that they are independent of each other. In theory, reading one shouldn't affect the performance of reading the others. Since you are doing mem-stat and cpu-stat reading repetitively in a loop, it is likely that all the data are in the cache most of the time resulting in very fast processing time. If it happens that the specific memory location of mem-stat and cpu-stat data are such that reading one will cause the other data to be flushed out of the cache and have to be re-read from memory again, you could see significant performance regression. It is one of the possible causes, but I may be wrong. Cheers, Longman