Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1837139ybt; Sun, 21 Jun 2020 00:42:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxvPT0ceQcmrvXrLaiy82y8Eo8yUbOEuiLQy4Tfp2Nt/SgS5IFj9xfHjBJdvyxs1x+8MyOa X-Received: by 2002:aa7:c3d7:: with SMTP id l23mr11199891edr.264.1592725325563; Sun, 21 Jun 2020 00:42:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592725325; cv=none; d=google.com; s=arc-20160816; b=EWp4R3UzilRF7cwo8D2bV+yOUTBgto23K+L5noav0cpSFJJTgkpG/JadqVk2tQ25xX XUkIrrC7OeZSHCxLfwTGi+lCXH01BXZNfe5KYmwvCkrWQNCM1IlETbv692uyVN6eTwZh q2aT/p1QkYD/iCFvx4pVcVSvjOlcaK3Gphq5F7lAFgtEmxABiqz8syATJqwd0CbAqwEL U3mXorIxjwwlYAdtkk7/dJE99kAgCKd5glzRV7QKeML8nO8nSv/uryMZ/yq+/Le7Wt6s cmdHeHHkVgm5bYQRCRbBYGYdnom2giQ/mZHjwxUD7slZwsj+J2wU+yHtw2Guk7eLOwUG 6L/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:ironport-sdr:ironport-sdr; bh=QWk0hLyhWRy3ClZ9HBFzWJ9rYtJ4va0iyGBPVL3nLsA=; b=Uth49vYiVKajQXek6bF0gtvNCla4Qet4P5vU7svwLuO5K7+95arPUp5ed98ZB+CGe7 W4Nb0+0f1mES3wgMu/5UDRWPltKyE/zHmSOklOyKOVXofyBiJ6/NPjIaLSMCLyd6b8TT BlJKGnH/tv+w8xv8994iyXWZ9L23xrcHCqOB1VYGKQiebsqlBicsAcGBa2eTq8Dt0RA6 pWplliuL3q1agiuVcYZ6Rxj4fK5jUQqZQXJpHf//KD5D7DFgJt3DUNXPR7E1WBb5+tX3 Kabx8F1G7ihBhY08ZX398eeGZn2vbqFloBXL4BrqKiJtWiwsOTQVy9olpcg7EPKFk32I q74g== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id oj22si6987292ejb.115.2020.06.21.00.41.41; Sun, 21 Jun 2020 00:42:05 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729468AbgFUHgx (ORCPT + 99 others); Sun, 21 Jun 2020 03:36:53 -0400 Received: from mga06.intel.com ([134.134.136.31]:16490 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729423AbgFUHgw (ORCPT ); Sun, 21 Jun 2020 03:36:52 -0400 IronPort-SDR: 4g8fE2HOhrpAmPgP+yQkF7ZaobbxmUAOdDDTIPlNABUmHVnEWlOH8nKLoEhPIosAyCUnJ/UesX n0JVlrGBLnsA== X-IronPort-AV: E=McAfee;i="6000,8403,9658"; a="204986791" X-IronPort-AV: E=Sophos;i="5.75,262,1589266800"; d="scan'208";a="204986791" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Jun 2020 00:36:52 -0700 IronPort-SDR: Eoxe27Qgas/5AxcjOz+orM3yoyS4wCnzWFHVAf5HL3mtPx9gks+PcISKWPj172HZBsG/O9VbkT H9kkx+X0isFA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,262,1589266800"; d="scan'208";a="478102527" Received: from shbuild999.sh.intel.com ([10.239.146.107]) by fmsmga005.fm.intel.com with ESMTP; 21 Jun 2020 00:36:48 -0700 From: Feng Tang To: Andrew Morton , Michal Hocko , Johannes Weiner , Matthew Wilcox , Mel Gorman , Kees Cook , Luis Chamberlain , Iurii Zaikin , andi.kleen@intel.com, tim.c.chen@intel.com, dave.hansen@intel.com, ying.huang@intel.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Feng Tang , "K. Y. Srinivasan" , Haiyang Zhang Subject: [PATCH v5 2/3] mm/util.c: make vm_memory_committed() more accurate Date: Sun, 21 Jun 2020 15:36:39 +0800 Message-Id: <1592725000-73486-3-git-send-email-feng.tang@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1592725000-73486-1-git-send-email-feng.tang@intel.com> References: <1592725000-73486-1-git-send-email-feng.tang@intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org percpu_counter_sum_positive() will provide more accurate info. As with percpu_counter_read_positive(), in worst case the deviation could be 'batch * nr_cpus', which is totalram_pages/256 for now, and will be more when the batch gets enlarged. Its time cost is about 800 nanoseconds on a 2C/4T platform and 2~3 microseconds on a 2S/36C/72T Skylake server in normal case, and in worst case where vm_committed_as's spinlock is under severe contention, it costs 30~40 microseconds for the 2S/36C/72T Skylake sever, which should be fine for its only two users: /proc/meminfo and HyperV balloon driver's status trace per second. Signed-off-by: Feng Tang Acked-by: Michal Hocko # for /proc/meminfo Cc: "K. Y. Srinivasan" Cc: Haiyang Zhang Cc: Matthew Wilcox (Oracle) Cc: Johannes Weiner Cc: Mel Gorman Cc: Andi Kleen Cc: Tim Chen Cc: Dave Hansen Cc: Huang Ying --- mm/util.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mm/util.c b/mm/util.c index c63c8e4..1c9d097 100644 --- a/mm/util.c +++ b/mm/util.c @@ -787,10 +787,15 @@ struct percpu_counter vm_committed_as ____cacheline_aligned_in_smp; * balancing memory across competing virtual machines that are hosted. * Several metrics drive this policy engine including the guest reported * memory commitment. + * + * The time cost of this is very low for small platforms, and for big + * platform like a 2S/36C/72T Skylake server, in worst case where + * vm_committed_as's spinlock is under severe contention, the time cost + * could be about 30~40 microseconds. */ unsigned long vm_memory_committed(void) { - return percpu_counter_read_positive(&vm_committed_as); + return percpu_counter_sum_positive(&vm_committed_as); } EXPORT_SYMBOL_GPL(vm_memory_committed); -- 2.7.4