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=-13.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL 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 09D84C07E95 for ; Tue, 13 Jul 2021 20:27:17 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A7DB461175 for ; Tue, 13 Jul 2021 20:27:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A7DB461175 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id C5DD96B0036; Tue, 13 Jul 2021 16:27:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BE7236B008A; Tue, 13 Jul 2021 16:27:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A38A98D0001; Tue, 13 Jul 2021 16:27:16 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0200.hostedemail.com [216.40.44.200]) by kanga.kvack.org (Postfix) with ESMTP id 793076B0036 for ; Tue, 13 Jul 2021 16:27:16 -0400 (EDT) Received: from smtpin37.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 744452CBDC for ; Tue, 13 Jul 2021 20:27:15 +0000 (UTC) X-FDA: 78358699230.37.1C7559E Received: from mail-lf1-f43.google.com (mail-lf1-f43.google.com [209.85.167.43]) by imf02.hostedemail.com (Postfix) with ESMTP id 2DD257001A24 for ; Tue, 13 Jul 2021 20:27:15 +0000 (UTC) Received: by mail-lf1-f43.google.com with SMTP id q16so16349872lfa.5 for ; Tue, 13 Jul 2021 13:27:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=vDVcnWUCmKFgFt42Z0BstCmPPXwwhSiEhiVvSxMjimA=; b=gGWUKJ1/QgenvRKNsFA/kuTLwkZmnjUbKvkHw6Hb9aeF/y3rC4CapuK/JdpFMuw1Sf XwIJHgrRUcz4hL+muJYuC3WCP0VSU+GXiTlRPCy5233n4lTzBS3lJlade5HnVy8531og 6Xi/Rol5DVgx2NaHFulwZjPFeEg0g3fYptl7fVMy3GOodBuVsSiHGD/dkf8T4whLLNYp D36hGi7QmxKTb2QbtBHjvrSKG80CZ5YDP0gEMBEpfHn0DoSxKXmOrVtm9RlojlL13t+v 16SMl0zfZLA5lkfGEOFqPlgfe6R1pe5k2jYAqVXM0YwJiEIDPfNuLt3mLwmIIMxRQ8IE QB4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=vDVcnWUCmKFgFt42Z0BstCmPPXwwhSiEhiVvSxMjimA=; b=AEGJq6FpYxq7Fn+39ul5ZN/k6TBX2c2WcW5/f9dVdS3g+2HALyqhDghxJCCvOuNQbs 0dOvvo0rB4Sme3VWSoK1+Z/oTZR1gR5NTjXQPB4nxA0dATuYtM+oCvSfRR8JJbb/YAh8 7vTmDnqy64HIY8l7c6MAw7ca1hzLFbXUHLD/2CskVGiMmKDKKrJpq6vkDZiLjstJBoXo 7LPc0Zstfc+3+40M/1JklQ0mmC3OTRjxlp5YaV3pSZqjEPg9EgVtFdDo50WgFSp0bkI7 sD6eBEdo+IVqx7OZj4jSoD+2rc6++oZPd/CJzRPt9KCImkEXSv+cUZte8f1vwMHMUy3L xt0Q== X-Gm-Message-State: AOAM530InwJHTCl7Lex9uvhHH4OucpdyseH6VILF3M7ErHm/eAYrOmNV FZyYRk8qQTXEqZ6YtHFZ0g31IIDXgxB/8oXwnxyZ5Q== X-Google-Smtp-Source: ABdhPJypAoGStqdoyPRQutNsnNe7ghH2ya92MNaOYt9mzbNtnwlCrOwGl9PbRkXmq4Ck30R0BdGl4VZ0c/9O4luKWmE= X-Received: by 2002:a05:6512:687:: with SMTP id t7mr4852056lfe.347.1626208033194; Tue, 13 Jul 2021 13:27:13 -0700 (PDT) MIME-Version: 1.0 References: <20210713202412.248252-1-shakeelb@google.com> <20210713202412.248252-2-shakeelb@google.com> In-Reply-To: <20210713202412.248252-2-shakeelb@google.com> From: Shakeel Butt Date: Tue, 13 Jul 2021 13:27:02 -0700 Message-ID: Subject: Re: [PATCH 2/2] memcg: infrastructure to flush memcg stats To: Tejun Heo , Johannes Weiner , Muchun Song Cc: Michal Hocko , Roman Gushchin , =?UTF-8?Q?Michal_Koutn=C3=BD?= , Huang Ying , Hillf Danton , Andrew Morton , Cgroups , Linux MM , LKML Content-Type: text/plain; charset="UTF-8" X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 2DD257001A24 X-Stat-Signature: iq64d4wb16thefhdg4x75bxs3ctpm3ph Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20161025 header.b="gGWUKJ1/"; spf=pass (imf02.hostedemail.com: domain of shakeelb@google.com designates 209.85.167.43 as permitted sender) smtp.mailfrom=shakeelb@google.com; dmarc=pass (policy=reject) header.from=google.com X-HE-Tag: 1626208035-36756 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000022, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Tue, Jul 13, 2021 at 1:24 PM 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. > > This patch uses following mechanisms to solve these challenges: > > 1. Periodically flush the stats from root memcg every 2 seconds. This > will time limit the out of sync stats. > > 2. Asynchronously flush the stats after fixed number of stat updates. > In the worst case the stat can be out of sync by O(nr_cpus * BATCH) for > 2 seconds. > > 3. For avoiding thundering herd to flush the stats particularly from the > memory reclaim context, introduce memcg local spinlock and let only one > flusher active at a time. This could have been done through > cgroup_rstat_lock lock but that lock is used by other subsystem and for > userspace reading memcg stats. So, it is better to keep flushers > introduced by this patch decoupled from cgroup_rstat_lock. > --- > Changes since v2: > - Changed the subject of the patch > - Added mechanism to bound errors to nr_cpus instead of nr_cgroups > - memcg local lock to let one active flusher > > Changes since v1: > - use system_unbound_wq for flushing the memcg stats > Forgot to add v3 in the subject for this patch.