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 X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B2F5FC48BDF for ; Tue, 15 Jun 2021 19:29:59 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 31929610EA for ; Tue, 15 Jun 2021 19:29:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 31929610EA Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=cmpxchg.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id AC22C6B006C; Tue, 15 Jun 2021 15:29:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A4A436B006E; Tue, 15 Jun 2021 15:29:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 89C5D6B0070; Tue, 15 Jun 2021 15:29:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0203.hostedemail.com [216.40.44.203]) by kanga.kvack.org (Postfix) with ESMTP id 540546B006C for ; Tue, 15 Jun 2021 15:29:58 -0400 (EDT) Received: from smtpin40.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id EA18CBEF3 for ; Tue, 15 Jun 2021 19:29:57 +0000 (UTC) X-FDA: 78256948434.40.ADA7D1C Received: from mail-qk1-f179.google.com (mail-qk1-f179.google.com [209.85.222.179]) by imf05.hostedemail.com (Postfix) with ESMTP id 07994E000204 for ; Tue, 15 Jun 2021 19:29:44 +0000 (UTC) Received: by mail-qk1-f179.google.com with SMTP id f70so12947qke.13 for ; Tue, 15 Jun 2021 12:29:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=b1NdNJmbQ9vufxbdq46R0yQ5rOWLcgcQTrxTuRLsRs4=; b=kZmQdCqtAe6i6mcTzPE2G1TnxW5S3b3u7NHWwpD/z6z+rVhlqxQofe38Zav7pYflCb 6TjmJhRoa0BXLTlDnKddSVw7zM/k74Plwu1Q4dNQn5RRpBWMyBbKtApXtgOUdOW+PsP2 i3+fbThoD6+KVR8g8QPHi6Rkizkxw2FQpC0R7pXdyz7mIH5K5spJvHcPMeVOQv8JENu0 tYtQFQ9eyCT9WqDme2JdoLd9kwKp2xnWipBrKHag4G8AY6i7Cz/mf2UVWkvHpmHgVEtg bgGU4fEzFlzDrN8NXje4+5ygkO87UjYU+B58pIvX82JJ5I3InE44LSHwHZfL9L+L8YdK bNBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=b1NdNJmbQ9vufxbdq46R0yQ5rOWLcgcQTrxTuRLsRs4=; b=YWJ2ljz2Dx7EwqBvhjm7eQM94GEz6R6yA2srOsjj8J1qVFq6rLqqQtK0qjFCCuLqP4 HBtBSUInIIRbCYcm+6izn2kEYA02cIFF1iGuGfPPXD3M/sNUZJ+KFfDOhpb19LQ2EVCu Ku2qIFF16DrfTMSMwnDjPaUbJalMZLCp3Z9p2/JFphNPPGvlyFffplnYrh4kfkZUzCkd pG91p45s1HuAJz0Q1gH3u2pkAehe5ayay7M5H1Fo7w+Isx27kR4CtsghLBqvnZ4srXwy VxqkPHNIZkbI2++0evZONuDCyotZp9FZ1UlCLkBxTUryNOKyEwPcdd/Bt9C2vwBvzCxH OU1g== X-Gm-Message-State: AOAM530FzXVcWNgaXq6FkpYMkbS8T1XzrjVPSkuJ2WC+UBqyxjJb+yIY 0F1fWcX8cxVcZuytgvIijqAApp7l8TYdbA== X-Google-Smtp-Source: ABdhPJxP3yHeFpozEvcuka46Iijje/SKXPkiGMZdItJHdDhI9CQNqB/bOJ9eNYsjEGTObmJeG86+cA== X-Received: by 2002:ae9:d608:: with SMTP id r8mr1245226qkk.279.1623785396646; Tue, 15 Jun 2021 12:29:56 -0700 (PDT) Received: from localhost (70.44.39.90.res-cmts.bus.ptd.net. [70.44.39.90]) by smtp.gmail.com with ESMTPSA id y128sm10310870qke.113.2021.06.15.12.29.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Jun 2021 12:29:55 -0700 (PDT) Date: Tue, 15 Jun 2021 15:29:55 -0400 From: Johannes Weiner To: Shakeel Butt Cc: Tejun Heo , Muchun Song , Michal Hocko , Roman Gushchin , Michal =?iso-8859-1?Q?Koutn=FD?= , Huang Ying , Andrew Morton , cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 2/2] memcg: periodically flush the memcg stats Message-ID: References: <20210615174435.4174364-1-shakeelb@google.com> <20210615174435.4174364-2-shakeelb@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210615174435.4174364-2-shakeelb@google.com> Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=kZmQdCqt; spf=pass (imf05.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.222.179 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org; dmarc=pass (policy=none) header.from=cmpxchg.org X-Stat-Signature: zmya3skb34w5bgbprf4p4wqyrghq3yhr X-Rspamd-Queue-Id: 07994E000204 X-Rspamd-Server: rspam06 X-HE-Tag: 1623785384-259754 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: Hey Shakeel, On Tue, Jun 15, 2021 at 10:44:35AM -0700, Shakeel Butt wrote: > At the moment memcg stats are read in four contexts: > > 1. memcg stat user interfaces > 2. dirty throttling > 3. page fault > 4. memory reclaim > > Currently the kernel flushes the stats for first two cases. Flushing the > stats for remaining two casese may have performance impact. Always > flushing the memcg stats on the page fault code path may negatively > impacts the performance of the applications. In addition flushing in the > memory reclaim code path, though treated as slowpath, can become the > source of contention for the global lock taken for stat flushing because > when system or memcg is under memory pressure, many tasks may enter the > reclaim path. > > Instead of synchronously flushing the stats, this patch adds support of > asynchronous periodic flushing of the memcg stats. For now the flushing > period is hardcoded to 2*HZ but that can be changed later through maybe > sysctl if need arise. I'm concerned that quite a lot can happen in terms of reclaim and page faults in 2 seconds. It's conceivable that the error of a fixed 2s flush can actually exceed the error of a fixed percpu batch size. The way the global vmstat implementation manages error is doing both: ratelimiting and timelimiting. It uses percpu batching to limit the error when it gets busy, and periodic flushing to limit the length of time consumers of those stats could be stuck trying to reach a state that the batching would otherwise prevent from being reflected. Maybe we can use a combination of ratelimiting and timelimiting too? We shouldn't flush on every fault, but what about a percpu ratelimit that would at least bound the error to NR_CPU instead of nr_cgroups? For thundering herds during reclaim: as long as they all tried to flush from the root, only one of them would actually need to do the work, and we could use trylock. If the lock is already taken, you can move on knowing that somebody is already doing the shared flush work.