From patchwork Fri Feb 9 18:34:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philip Cox X-Patchwork-Id: 1897184 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TWjHx10WWz23h4 for ; Sat, 10 Feb 2024 05:37:00 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1rYVk1-0004bo-CZ; Fri, 09 Feb 2024 18:36:49 +0000 Received: from smtp-relay-internal-0.internal ([10.131.114.225] helo=smtp-relay-internal-0.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1rYVju-0004Zz-Kc for kernel-team@lists.ubuntu.com; Fri, 09 Feb 2024 18:36:43 +0000 Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id D725840590 for ; Fri, 9 Feb 2024 18:36:41 +0000 (UTC) Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-785863ca8c4so153909685a.0 for ; Fri, 09 Feb 2024 10:36:41 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707503800; x=1708108600; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ctnnAiVjGm9h+dtceh69iHB5u5IyfTLoAr607X0PQVI=; b=FqY8YgZmi3JGE5Fq5nMgqgRz1/HXK0XMpw//4vSv4vu0TBdPEzMxDZtiOc/gxq3aUK g/vF5vxXLB82/0mX7Epp2d5JbjrsPvbMhqpsQik0RWYWttLnKI93NZ2vb48XTa0auloj UKmiK5depGy7c5lTK4HozKfqIm4JM84DKsE3WxHAeBdNeWdCCDmdM3YP+pxiSWP66lBf YzLC53B9RUqVAzJkB+eYiI1PmcNj8gm5E19iekKOKiUFgZuhLWess+318mBZVxwx38AV vDmRwNloU/kgXyx+btrHZ2csxj18piA/7HgpcNzR1mGAvKlqVLITsFFsR+XJGCnyfh4V EYtQ== X-Gm-Message-State: AOJu0YwBq91XDLOYYFOh2tbM6NPd1siXLuhQViL/+9o7n6SnT6ZaM7sh gAAxxOaY+pnBIPuBaxq1PVWI7jMvI/lXTOXbk0Db8zB4q6yXJtfpW78OKu4GvbEUGMbQBMQpEgp wtfXH/yhJrlOcQwZ1Sgzh/DCtgGa4KyDajv3le+skytexRLuCd83oKCs9YCTxFGWxq2i7pzsT+j PPTs1rjgoZvg== X-Received: by 2002:a05:620a:414a:b0:785:3da4:58a5 with SMTP id k10-20020a05620a414a00b007853da458a5mr3222867qko.37.1707503799919; Fri, 09 Feb 2024 10:36:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IHq1GQpTaBnY5AWXi3134AGyTd5RZbU9ET4thAgUH1z9kz2yZslPxIaCfvLGjMKY7UibHn23g== X-Received: by 2002:a05:620a:414a:b0:785:3da4:58a5 with SMTP id k10-20020a05620a414a00b007853da458a5mr3222846qko.37.1707503799640; Fri, 09 Feb 2024 10:36:39 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCV6as7Z0IAicBiAuoWyDWhJdcYf4OWSApn3N7gkqOo2nQVsm45NyfyE/ONdKAYQWBGYCuKXnmhRvQG77SBKIEqXvuAgloQWmfQ= Received: from cox.home.arpa ([108.175.227.176]) by smtp.gmail.com with ESMTPSA id wa4-20020a05620a4d0400b00785bd0f5e0csm72qkn.47.2024.02.09.10.36.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Feb 2024 10:36:38 -0800 (PST) From: Philip Cox To: kernel-team@lists.ubuntu.com, philip.cox@canonical.com Subject: [SRU][jammy:linux][PATCH] mm/memcontrol.c: remove the redundant updating of stats_flush_threshold Date: Fri, 9 Feb 2024 13:34:35 -0500 Message-Id: <20240209183435.328126-1-philip.cox@canonical.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Jiebin Sun BugLink: https://bugs.launchpad.net/bugs/2052827 Remove the redundant updating of stats_flush_threshold. If the global var stats_flush_threshold has exceeded the trigger value for __mem_cgroup_flush_stats, further increment is unnecessary. Apply the patch and test the pts/hackbench-1.0.0 Count:4 (160 threads). Score gain: 1.95x Reduce CPU cycles in __mod_memcg_lruvec_state (44.88% -> 0.12%) CPU: ICX 8380 x 2 sockets Core number: 40 x 2 physical cores Benchmark: pts/hackbench-1.0.0 Count:4 (160 threads) Link: https://lkml.kernel.org/r/20220722164949.47760-1-jiebin.sun@intel.com Signed-off-by: Jiebin Sun Acked-by: Shakeel Butt Reviewed-by: Roman Gushchin Reviewed-by: Tim Chen Acked-by: Muchun Song Cc: Johannes Weiner Cc: Michal Hocko Cc: "Huang, Ying" Cc: Amadeusz Sawiski Signed-off-by: Andrew Morton (cherry picked from commit 873f64b791a2b43c246e78b7d9fdd64ce909685b) Signed-off-by: Philip Cox Acked-by: Andrei Gherzan Acked-by: Thibault Ferrante --- mm/memcontrol.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 6f969ba0d688..f922613ddf8c 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -662,7 +662,14 @@ static inline void memcg_rstat_updated(struct mem_cgroup *memcg, int val) x = __this_cpu_add_return(stats_updates, abs(val)); if (x > MEMCG_CHARGE_BATCH) { - atomic_add(x / MEMCG_CHARGE_BATCH, &stats_flush_threshold); + /* + * If stats_flush_threshold exceeds the threshold + * (>num_online_cpus()), cgroup stats update will be triggered + * in __mem_cgroup_flush_stats(). Increasing this var further + * is redundant and simply adds overhead in atomic update. + */ + if (atomic_read(&stats_flush_threshold) <= num_online_cpus()) + atomic_add(x / MEMCG_CHARGE_BATCH, &stats_flush_threshold); __this_cpu_write(stats_updates, 0); } }