Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp2646162iog; Mon, 20 Jun 2022 01:23:26 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vs+owHELzMRrXgn2ZuldMe+syWijghhAkeXcYEQSx/SI8A95gfF/MMShWX9Z1D6E0Ma0xu X-Received: by 2002:a17:90a:5104:b0:1ea:e86b:6aed with SMTP id t4-20020a17090a510400b001eae86b6aedmr25046175pjh.69.1655713406595; Mon, 20 Jun 2022 01:23:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655713406; cv=none; d=google.com; s=arc-20160816; b=bkRyQJDJKEtoiQW7US2I/7CCMFA8t1ED5T9HydF99o0kTxtwvK6O/pnGLYW/TnUUVt SKABm04KvDfsbDMx1JaLUQCnTbTLTeeYnVHLgg3jYFdES5E1ykihtYWA0XBkDUskvm9n FPcRZs7lKCIjj6YeNzm+vLXUsLd51JrqLDKuhirsJklcXpS4fcdhmLD2mVEHUIY08tmn JurYR6DaVfuiV9Dcf8ljC8Vw7wDe51YdvZsh8bRp1FbIZc7SndY3Z+7pLPNEF+dSIqif nZ6iFYRl/VS/Im7gOX85DOeAPRHz6ZTFPtkzwIa/z3lhNv6C2DdtL7SRoIK6Fg7ZK16w Lcsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=gZFTepVCVuUiqVxMVdZ46Oj4Iz+xt4uwly/OdoZth3I=; b=DPAqj9dcyI0pzjFs5Xro4JniDumI8B/A9bjL+mmxhuO6GAzaI0kbm3EWqLPisr1j2Z 1XFy+6GYenesGDvCQD/yg7OxdJlLzarq7qZDCADoUM6BMKdBX+onBWJdSgUQe8P8ragF QWFLDAeSbDan5wtSuTzvq46HZOqT4pbKVaBtKcDGzeLgCVHsSb0ei+AmniP6XJsJnF7+ Dp0GTbIZWO86E3sOYSRSf95p7GGfa+PlLLGesVONQEXN+eJBs5WellFw3c5Ypr6/kJCW lsF9dNAiouSHzvvE0UdXDwWz68iSdV0TyXjoZ/elCBrTBHjMm3e+EXPDZlvEa0TFbtFN 9Y0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@axis.com header.s=axis-central1 header.b=ejM5C1dT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=axis.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 189-20020a6302c6000000b003c1977e2008si14720248pgc.821.2022.06.20.01.23.13; Mon, 20 Jun 2022 01:23:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@axis.com header.s=axis-central1 header.b=ejM5C1dT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=axis.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232762AbiFTINH (ORCPT + 99 others); Mon, 20 Jun 2022 04:13:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60892 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233274AbiFTIND (ORCPT ); Mon, 20 Jun 2022 04:13:03 -0400 Received: from smtp1.axis.com (smtp1.axis.com [195.60.68.17]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B5618625C; Mon, 20 Jun 2022 01:12:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axis.com; q=dns/txt; s=axis-central1; t=1655712780; x=1687248780; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=gZFTepVCVuUiqVxMVdZ46Oj4Iz+xt4uwly/OdoZth3I=; b=ejM5C1dTXUQXl0PyF0zSPtptwseGwwUEExKTkagu51codOB5xGEuGiLP rNac9fNUKlX3AUMHvYk84+2LnaTvtrnkbenkYwwghzNW4FK/klfaYqYZp tphOQ4x+w2WSd3Kuh6W07BHhiRzLHMQjzJFpV+TfPwc3YgBU0kN0SPVZi bYxBElXDIfGxb+NHvXsUerwS9bGcJ4laYShEL83hjdrgkYweyBte6V0Kd SPhzSVj6WeQzC79VI5Uh6yfkMmbR5WqK/1dXEYrzT4251Z04vYI4stGjS RzvUvIILVJukpqNh95TAJeGS948CshA8b9B3wsPsROMuRDrcBqh1tR6By g==; From: Vincent Whitchurch To: , Jonathan Corbet CC: , , Vincent Whitchurch , , , Subject: [PATCH v2] mm/smaps: add Pss_Dirty Date: Mon, 20 Jun 2022 10:12:50 +0200 Message-ID: <20220620081251.2928103-1-vincent.whitchurch@axis.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Pss is the sum of the sizes of clean and dirty private pages, and the proportional sizes of clean and dirty shared pages: Private = Private_Dirty + Private_Clean Shared_Proportional = Shared_Dirty_Proportional + Shared_Clean_Proportional Pss = Private + Shared_Proportional The Shared*Proportional fields are not present in smaps, so it is not always possible to determine how much of the Pss is from dirty pages and how much is from clean pages. This information can be useful for measuring memory usage for the purpose of optimisation, since clean pages can usually be discarded by the kernel immediately while dirty pages cannot. The smaps routines in the kernel already have access to this data, so add a Pss_Dirty to show it to userspace. Pss_Clean is not added since it can be calculated from Pss and Pss_Dirty. Signed-off-by: Vincent Whitchurch --- Documentation/ABI/testing/procfs-smaps_rollup | 1 + Documentation/filesystems/proc.rst | 5 ++++- fs/proc/task_mmu.c | 3 +++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Documentation/ABI/testing/procfs-smaps_rollup b/Documentation/ABI/testing/procfs-smaps_rollup index a4e31c465194..b446a7154a1b 100644 --- a/Documentation/ABI/testing/procfs-smaps_rollup +++ b/Documentation/ABI/testing/procfs-smaps_rollup @@ -22,6 +22,7 @@ Description: MMUPageSize: 4 kB Rss: 884 kB Pss: 385 kB + Pss_Dirty: 68 kB Pss_Anon: 301 kB Pss_File: 80 kB Pss_Shmem: 4 kB diff --git a/Documentation/filesystems/proc.rst b/Documentation/filesystems/proc.rst index 1bc91fb8c321..f7dce062548f 100644 --- a/Documentation/filesystems/proc.rst +++ b/Documentation/filesystems/proc.rst @@ -448,6 +448,7 @@ Memory Area, or VMA) there is a series of lines such as the following:: MMUPageSize: 4 kB Rss: 892 kB Pss: 374 kB + Pss_Dirty: 0 kB Shared_Clean: 892 kB Shared_Dirty: 0 kB Private_Clean: 0 kB @@ -479,7 +480,9 @@ dirty shared and private pages in the mapping. The "proportional set size" (PSS) of a process is the count of pages it has in memory, where each page is divided by the number of processes sharing it. So if a process has 1000 pages all to itself, and 1000 shared with one other -process, its PSS will be 1500. +process, its PSS will be 1500. "Pss_Dirty" is the portion of PSS which +consists of dirty pages. ("Pss_Clean" is not included, but it can be +calculated by subtracting "Pss_Dirty" from "Pss".) Note that even a page which is part of a MAP_SHARED mapping, but has only a single pte mapped, i.e. is currently used by only one process, is accounted diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index 2d04e3470d4c..751c19d5bfdd 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -406,6 +406,7 @@ struct mem_size_stats { u64 pss_anon; u64 pss_file; u64 pss_shmem; + u64 pss_dirty; u64 pss_locked; u64 swap_pss; }; @@ -427,6 +428,7 @@ static void smaps_page_accumulate(struct mem_size_stats *mss, mss->pss_locked += pss; if (dirty || PageDirty(page)) { + mss->pss_dirty += pss; if (private) mss->private_dirty += size; else @@ -808,6 +810,7 @@ static void __show_smap(struct seq_file *m, const struct mem_size_stats *mss, { SEQ_PUT_DEC("Rss: ", mss->resident); SEQ_PUT_DEC(" kB\nPss: ", mss->pss >> PSS_SHIFT); + SEQ_PUT_DEC(" kB\nPss_Dirty: ", mss->pss_dirty >> PSS_SHIFT); if (rollup_mode) { /* * These are meaningful only for smaps_rollup, otherwise two of -- 2.34.1