Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp1620106lqp; Sat, 23 Mar 2024 01:57:53 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX1OOX+IPhAXOBpq1PqA/RyIMn4XNj0SOB5d60dsrv0PrgJ3SeC71ZD51iIp/StmjGbCdoBfYhPlw7d5FtqZs4y1elLw6HEAVkMK8cNrw== X-Google-Smtp-Source: AGHT+IEIBu9ZFHeOxQFfZ7xJaBUbvm2YVWPFR8y2JgvSGQgnWGOzFt75wt2dHivtCzWUcbDUryD8 X-Received: by 2002:a05:6358:d03:b0:17c:1b9b:bf46 with SMTP id v3-20020a0563580d0300b0017c1b9bbf46mr2126091rwj.13.1711184272945; Sat, 23 Mar 2024 01:57:52 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711184272; cv=pass; d=google.com; s=arc-20160816; b=lfN+oB65cQUpQxjz28/FCyJWLlxn2ZEt973FzRXRf6wwJ3IXNpzb9SU9nsv+sX9pdc tHYXxxFufr73moE9+oAO7O7LxNOFHU2D9vncEk1hG2a1NS6M2saA1nXm30m4TLZ/w5yz FGdn50RT9jOzTeKhUGOmKVzOqFW9wSAsMqsbGL/C+Ms/imZGbRdXP9a28H9W/9GoNvlM bPgGJu+O0cliLgAdVbLcA/tdm8uEdOgItOCzfOIVD4myGLSmSJ2ie41tpCmWQurvToQa ZH0P/vBb7QNfjQENOmZYVKQjlf4tn5jEeWOzG8jtwslj3IgiN0lW645XM3MI7Ivu2QqR 8JgQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:sender:hmm_source_type:hmm_attache_num:hmm_source_ip; bh=/bF7L3LdHQTGLmX6dO/mi7Q27FrbhvYtOl6ChhnWopY=; fh=YxaQX7GTjfBsN7A2Jl+A9yP6mmGOQanoqU6QROKhVaA=; b=WfqeTO0qCq0wgbkS1Rei16tC0hA9wNWt2QJRKtnYYR+7MVyDY74FyEaYNPO5yz41Et SMVNmc5e8QWRgpqGdu9+m13LxKp1LFwxCr37YnEstwxmd/fTIcNYtJO/whZseR9SSp1Y AveY7j2cXSyOGH2ZVvU9S/knS5/ev9Q3f9vg8DBiI4pNoU5gXzN0hZwu1lhNMoYcwjfP fqaDoDoFydlf3TzE5PWX8DSygvSMYDtv/8bKkeOLYRUAAaGG1VwuCRXxz7ga6O3npstf XPbOVQPL3NKNj7jZD8WjMkXDG+S+35bLt03X/TmWS5rkP5goR90soP6tNi671jAk5k7a ZglA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=chinatelecom.cn); spf=pass (google.com: domain of linux-kernel+bounces-112266-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-112266-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id g22-20020a63dd56000000b005dc528be9acsi3683935pgj.475.2024.03.23.01.57.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Mar 2024 01:57:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-112266-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=chinatelecom.cn); spf=pass (google.com: domain of linux-kernel+bounces-112266-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-112266-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 204B32812A4 for ; Sat, 23 Mar 2024 08:57:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 696EFDDB7; Sat, 23 Mar 2024 08:57:47 +0000 (UTC) Received: from chinatelecom.cn (smtpnm6-05.21cn.com [182.42.157.213]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 58331D535 for ; Sat, 23 Mar 2024 08:57:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=182.42.157.213 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711184266; cv=none; b=suVlr08LZP/eYLUqUCQ5iRVbs5E0hH0VzUvTw5/iw00nOB261FeIcYE/XicRL2/Yk0mkiyF64o1Ej6V7vWrgDOcHQ5Y8uipos0oGv5MNwILat4oePikvR/oRLpgqjnpivhTP8xW9GhKf5da5RWTbm+8ACcFsgwEAefP/ug4bWtw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711184266; c=relaxed/simple; bh=YR9Icjn4E0WLpXvgUHdNENF0Q30VS6zm01rlmVJ+EX8=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=michQtWn408dD2PCVNuXcQ+eqSsWVmqk1kc9O3XN7RpIy32oX9MpGXTCail6LJXY4ntiUTZ6r5yrelP/wytLukSbUwesdPORM7Xm4iV1awDcwviahi1CP8/7Nty7hTIhyShNFMqm5aGv9UL/1M8oH9SGGsDUvlwDqvjsqlawZRk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=chinatelecom.cn; spf=pass smtp.mailfrom=chinatelecom.cn; arc=none smtp.client-ip=182.42.157.213 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=chinatelecom.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chinatelecom.cn HMM_SOURCE_IP:192.168.137.232:3649.1797840252 HMM_ATTACHE_NUM:0000 HMM_SOURCE_TYPE:SMTP Received: from clientip-36.111.64.84 (unknown [192.168.137.232]) by chinatelecom.cn (HERMES) with SMTP id 368419BD0A; Sat, 23 Mar 2024 16:46:08 +0800 (CST) X-189-SAVE-TO-SEND: chentt10@chinatelecom.cn Received: from ([36.111.64.84]) by gateway-ssl-dep-77bc75f6c8-jgbgh with ESMTP id 093e69577b2144e3b8c2a8bd28ab5af2 for akpm@linux-foundation.org; Sat, 23 Mar 2024 16:46:12 CST X-Transaction-ID: 093e69577b2144e3b8c2a8bd28ab5af2 X-Real-From: chentt10@chinatelecom.cn X-Receive-IP: 36.111.64.84 X-MEDUSA-Status: 0 Sender: chentt10@chinatelecom.cn From: Chen Taotao To: akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [RFC] mm: get_mm_counter() get the total memory usage of the process Date: Fri, 22 Mar 2024 23:11:39 +0800 Message-Id: <20240322151139.7417-1-chentt10@chinatelecom.cn> X-Mailer: git-send-email 2.27.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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. 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. This patch is an unofficial version that simply fixes the above problem, as I'm not sure if it makes sense to do so. Signed-off-by: Chen Taotao --- include/linux/mm.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 member) { - return percpu_counter_read_positive(&mm->rss_stat[member]); + return percpu_counter_sum_positive(&mm->rss_stat[member]); } void mm_trace_rss_stat(struct mm_struct *mm, int member); -- 2.27.0