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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id EA7A2C67861 for ; Wed, 10 Apr 2024 02:17:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 510666B0083; Tue, 9 Apr 2024 22:17:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4995F6B0088; Tue, 9 Apr 2024 22:17:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 339BF6B0089; Tue, 9 Apr 2024 22:17:13 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 14D4E6B0083 for ; Tue, 9 Apr 2024 22:17:13 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 9AC3A1A05A2 for ; Wed, 10 Apr 2024 02:17:12 +0000 (UTC) X-FDA: 81992009904.09.6447B27 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.17]) by imf23.hostedemail.com (Postfix) with ESMTP id 2331514000C for ; Wed, 10 Apr 2024 02:17:09 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=BCgDwykm; spf=none (imf23.hostedemail.com: domain of tim.c.chen@linux.intel.com has no SPF policy when checking 198.175.65.17) smtp.mailfrom=tim.c.chen@linux.intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712715430; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=0lzs+qPY7BUZt3XXSWZ0lLk+fJmux2RYy+140ZGLMD4=; b=GBlmHoUFfDxeV0gcPEybA7WyDhQ9J0zZjQJvhLU3V4aX9C9r9xhqkEB1VxdQVUdv00dGM+ U6OM7ItB3KXoHrB7yNbvhF+9S75bil8Y9Docy5YegnxJw1yfWKrp6Wk09cdyaOxa3F0xCD AgsXk9P9PC/lQUcAAKd0MyJhjo5jBgs= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712715430; a=rsa-sha256; cv=none; b=A1zTtyUCIzIGGul/sWB6tIHR3HRXLfP/3kGkE1O7bXON6812a53Ok8bgCAt6w8cJ/BLHNG nbdmfiCgoJnvLMjn6120x5wNr/kecbX6qIPgcmrLqJh83UJnaaGssySY0TGrYRnSWQZnTQ Wqdf0jaOr29UCf+UkxFKfOXjalw5a1Q= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=BCgDwykm; spf=none (imf23.hostedemail.com: domain of tim.c.chen@linux.intel.com has no SPF policy when checking 198.175.65.17) smtp.mailfrom=tim.c.chen@linux.intel.com; dmarc=pass (policy=none) header.from=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1712715431; x=1744251431; h=message-id:subject:from:to:cc:date:in-reply-to: references:content-transfer-encoding:mime-version; bh=O6C6n9pybJTJLPJy1c8WzpgKVw+uUnnwKizzYQ7blj4=; b=BCgDwykmfcV03ny5/IP9BBC9uDDqCY0G5zrg9WrrdLEy8AdZIDlNIXww U5DwdYPr26zvCqQzyWMbHLqHjV2kr8OiMqbF+LvQFLxkJ4voKfpF/U8Gf Zg6+wBdO08tLNGCLMVrqKZaAg4X3CMMz1OO4A/vXMOmaWN0XQO2RzJJfH LjuvOSV5hk7efOsNymFmsud189QEsxLP00mPw6ahbS7pkwsQ6mTAGx4oM Hudvqv+/dJt6k0TcNWZDJpifvCXBJ+S/ZDz6yTaP/MkALD+l4mOTNmocx y+t363x8AkwQmK8UqnM9lExNFHzmqlLw37Y70ZZyGFJbwESLOcgct5rIb A==; X-CSE-ConnectionGUID: apPA2hSGQVySW5pFwuqdTg== X-CSE-MsgGUID: BRcYFyl5QGa+z1329Sd1eg== X-IronPort-AV: E=McAfee;i="6600,9927,11039"; a="8161291" X-IronPort-AV: E=Sophos;i="6.07,190,1708416000"; d="scan'208";a="8161291" Received: from fmviesa003.fm.intel.com ([10.60.135.143]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Apr 2024 19:17:09 -0700 X-CSE-ConnectionGUID: TXOFrYDjTyiFtmhcOf1iKQ== X-CSE-MsgGUID: PGZlSwBjSt+v7vtpIZ8YWA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,190,1708416000"; d="scan'208";a="24908586" Received: from amatsuba-mobl2.amr.corp.intel.com (HELO [10.209.3.203]) ([10.209.3.203]) by fmviesa003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Apr 2024 19:17:10 -0700 Message-ID: <19a3c2890b18ce230a9e147c0eeee27caf0c4137.camel@linux.intel.com> Subject: Re: [RFC] mm: get_mm_counter() get the total memory usage of the process From: Tim Chen To: Chen Taotao , akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org Date: Tue, 09 Apr 2024 19:17:08 -0700 In-Reply-To: <20240322151139.7417-1-chentt10@chinatelecom.cn> References: <20240322151139.7417-1-chentt10@chinatelecom.cn> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.44.4 (3.44.4-2.fc36) MIME-Version: 1.0 X-Stat-Signature: h6mgqrgd5graqztd6pbjwwnmhfkuzx59 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 2331514000C X-Rspam-User: X-H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v9enBx3FFLSn52bq5j1udtPFguxixpsrRJqngsfrwcXsJ6EZKcSjGvIdhPiBG2MJkuExn1N/pc4pZHr+lAFsqRu9S8JUIqTqdF2sdU+CnPstaU= 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: List-Subscribe: List-Unsubscribe: On Fri, 2024-03-22 at 23:11 +0800, Chen Taotao wrote: > Currently, the get_mm_counter() function returns only the value of > the process memory counter percpu_counter ->count record, ignoring > the memory usage count maintained by each CPU in the > percpu_counter->counters array, which leads to an error in obtaining > the memory usage count of a process, especially when there are many > CPU cores. counts, especially when there are many CPU cores. >=20 > It is now possible to have get_mm_counter() get the memory count of a > process by adding the memory counts maintained by each cpu, thus getting > an accurate memory count of the process. >=20 > This patch is an unofficial version that simply fixes the above problem, > as I'm not sure if it makes sense to do so. Summing up the mm counts maintained in every cpu is expensive, especially if we are doing the read often. More so when there are a large number of cores on large servers or newer CPU with high core counts. For mm counters,the count in fbc->count is good enough we don't need to correct fbc->count with the the small counts update (< percpu_counter_batch) cached in per cpu counts. So do you have a mm count use case where you really need the precise count with get_mm_counter? I do not think we should make the change you suggested. Tim >=20 > Signed-off-by: Chen Taotao > --- > include/linux/mm.h | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) >=20 > diff --git a/include/linux/mm.h b/include/linux/mm.h > index f5a97dec5..5cf6443aa 100644 > --- a/include/linux/mm.h > +++ b/include/linux/mm.h > @@ -2569,7 +2569,7 @@ static inline bool get_user_page_fast_only(unsigned= long addr, > */ > static inline unsigned long get_mm_counter(struct mm_struct *mm, int mem= ber) > { > - return percpu_counter_read_positive(&mm->rss_stat[member]); > + return percpu_counter_sum_positive(&mm->rss_stat[member]); > } > =20 > void mm_trace_rss_stat(struct mm_struct *mm, int member);