Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp4060011pxb; Mon, 4 Oct 2021 16:27:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxCexdX/JMs1LEMXwG3EsRr3AMzzxIdjyNdYq+7UBzCKzOLr2CSr7uckFy607aKaxo9D+Em X-Received: by 2002:a50:d944:: with SMTP id u4mr22138129edj.327.1633390055203; Mon, 04 Oct 2021 16:27:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633390055; cv=none; d=google.com; s=arc-20160816; b=eCPYQG4HUSYx48CEYJt6SFrmnYqaI27l2sd2gShZjdyu+8iWaoIsrtUspGUXN3JLMf K3XE1MCfI5i54pm9d+/oda30wEudpPUwXcC1uVn+osbe8F3IdLRdndfyaos/SgyRxbYh E5UcG+vAHN3KFPhmYBdUdhurTUlGNe3q4pSQRhNtG8PpyO2HhD36o5If2oDnfLYIYiTo 58rnjpsDZZaiquUd/ij91xlAPO60te8OChPd1aJlLbMIDC+yfieWjWb+XLXrHqimpdg6 v9wCK2MnO66HTm059BGUdJQU+JIiy+d2G7ajwg5DqM+Fr7tojbw8uaWv2yLoAoLA5HVt nh/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=wD6uuf3ru6YVNe7+4jEAmC2naccUsJPrRjEclRtsE7k=; b=McjrZ1qWWOLcoFYki4y8ZK5mwDSZgQFzJNYIYUNgXa9ROZJfje6Uzx3BElKOJ8ScIg CkJzFY9e/v3T8ldMQeF2P+bFLDAxgJdxdS6aKSMLzL4E7NuPeb2+gaHKB7sFrZmyxKd0 Dr+SzDt7b6XMJ0ES/KXKOB0+w9c5mCTdgLVWijO29Sj3FWIOB2rcZ2V7I5b6oeeIBxNH +gPru6IqrdUIlXiZLQcXXOCCuuN78efEQh9Cu5SVUGsp2TIuiKjOgiDBUgvaZA3DtfgJ XjqRoMMeuqwB/CCz7Rm5OmA8bU+eMnNDFkI+/QjCFqg4q6hQF9ZlRNZLJYfdyiLLdRiB wJJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=ay567YeX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q11si18349041edv.274.2021.10.04.16.27.12; Mon, 04 Oct 2021 16:27:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=ay567YeX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237433AbhJDSJx (ORCPT + 99 others); Mon, 4 Oct 2021 14:09:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45918 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237434AbhJDSJs (ORCPT ); Mon, 4 Oct 2021 14:09:48 -0400 Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [IPv6:2a00:1450:4864:20::136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BBA34C061746 for ; Mon, 4 Oct 2021 11:07:58 -0700 (PDT) Received: by mail-lf1-x136.google.com with SMTP id y23so35946817lfb.0 for ; Mon, 04 Oct 2021 11:07:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=wD6uuf3ru6YVNe7+4jEAmC2naccUsJPrRjEclRtsE7k=; b=ay567YeX+xvQosVRiRU+umrEP8Dfr/v0GOPuimkdV+SH13Kr5erX7ASGE7cibqmECp ey6exYQnFbUcRE1FQYpqaATUQPWZ8lOCy8w2kg2OznxoEVJUociUrntfZqHwTYXRjfk3 ztjnw7OKKSOhPVODNyjj6gwan7EqdlVeXHgBUwMiMIGhjI/jXl/ZV31Y8Xh5TMJDyTa4 eG7amjqFkoL3vGXo5P/UoueH7Mhhov2pn0NMg0MLjxEP8lAy98+ZjFJ/N9z2G7ytAKVL w/D48MG83NvxCGzXK6TtUUdXRDKy8ieLL/unqgmBFCFBVVG8LoKWdA9H1tXcEwOcQYQD ZPKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=wD6uuf3ru6YVNe7+4jEAmC2naccUsJPrRjEclRtsE7k=; b=oND167fZkPsVKvogQ8ckzgX02rRoN7z2NnCo/wm92Khjm5lJhayXvL+/hQDsFaH+rl iI/RYAKoObZeo7osD0OokV1FfEuqL4Nd1rcvFe5a1wCHB6uXu0LQ5E+XKmsgR3UOS1rC CPJxyVJ2EomhDs8GNotPD3bEsyE0yMpcJKlSr0xrfhMyrTAZN8rsrvt58CGyj8W23YDW AfMpbtIcDk2NZtMgIYxjLCkPtuvYmtdcrlwZtXgm2VuXtr69vq5Rv6u6HvTLqiehQ6ka yTiKz2Y8LV/RfEoU2SZCad0QZG+6W7G6yHlUZCfNPAuyfZls5DxSmvW9I88H/EjBUB1T 8ifQ== X-Gm-Message-State: AOAM530+iQH/3OKkivJ+t8ZR5I+MK4dXgrgWpwV3AsPrxZ4ffB2g1RIP xpWFHCcWAsyVpFhJl3eE8k1tC3OaXTsrc4atDtVJXg== X-Received: by 2002:a05:6512:2211:: with SMTP id h17mr15941482lfu.494.1633370876646; Mon, 04 Oct 2021 11:07:56 -0700 (PDT) MIME-Version: 1.0 References: <20210929235936.2859271-1-shakeelb@google.com> In-Reply-To: From: Shakeel Butt Date: Mon, 4 Oct 2021 11:07:45 -0700 Message-ID: Subject: Re: [PATCH] cgroup: rstat: optimize flush through speculative test To: Tejun Heo Cc: Johannes Weiner , =?UTF-8?Q?Michal_Koutn=C3=BD?= , Cgroups , LKML Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Oct 4, 2021 at 10:44 AM Tejun Heo wrote: > > On Mon, Oct 04, 2021 at 10:25:12AM -0700, Shakeel Butt wrote: > > > > To evaluate the impact of this patch, an 8 GiB tmpfs file is created on > > > > a system with swap-on-zram and the file was pushed to swap through > > > > memory.force_empty interface. On reading the whole file, the memcg stat > > > > flush in the refault code path is triggered. With this patch, we > > > > observed 38% reduction in the read time of 8 GiB file. > > > > > > The patch looks fine to me but that's a lot of reduction in read time. Can > > > you elaborate a bit on why this makes such a huge difference? Who's hitting > > > on that lock so hard? > > > > It was actually due to machine size. I ran a single threaded workload > > without any interference on a 112 cpus machine. So, most of the time > > the flush was acquiring and releasing the per-cpu rstat lock for empty > > trees. > > Sorry for being so slow but can you point to the exact call path which gets > slowed down so significantly? This is the mem_cgroup_flush_stats() inside workingset_refault() in mm/workingset.c. > I'm mostly wondering whether we need some sort > of time-batched flushes because even with lock avoidance the flush path > really isn't great when called frequently. We can mitigate it further if > necessary - e.g. by adding an "updated" bitmap so that the flusher doesn't > have to go around touching the cachelines for all the cpus. For the memcg stats, I already proposed a batched flush at [1]. I actually did perform the same experiment with the proposed patch along with [1] and it improves around just 1%. More specifically for memcg stats [1] is good enough but that is memcg specific and this patch has merits on its own. [1] https://lkml.kernel.org/r/20210930044711.2892660-1-shakeelb@google.com > > Thanks. > > -- > tejun