Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp2469190imj; Mon, 18 Feb 2019 06:34:08 -0800 (PST) X-Google-Smtp-Source: AHgI3IagKLM2KswzvqcFDLaJl6XaE63sQNbqMTDGv7n8UMFulJHfQbMXeOwONJWkj5BkqwARTvzL X-Received: by 2002:a17:902:145:: with SMTP id 63mr25615879plb.256.1550500447989; Mon, 18 Feb 2019 06:34:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550500447; cv=none; d=google.com; s=arc-20160816; b=zchcLoHh4Fsejl8LiqdfJ1v2jCkkvlo85B7OL6/Jg/LPoz43DGgqJdY8jvwbOIesq9 wnI4WLryGaRpEk33C0FDN1F8CML/pY1nSlwTkQIRpE86vsgi0ftj2t4DclNRJWggbHwf XEjHXmNnSMMT2xks0LMEJAG7MKS/4f3UMQZzJiaIGfsqYzJTsJmhalQzaVkqWcJrWBVn VPsZs85pBKjRGaLa1HkdQB/DRfEHAjtKxYgXPPALFIht5mRRLGl3QG6KqjSL09kRlZZT 4nptNxJeLQbkFl/dy3u/i7kfJhYcM/qJaxL6XmSEtqjPMDQKibknmdtXlpQ5qVTXZqa8 LPHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=35sti+guds5jR2CnKB1zundGaO1UeYz00szJ7NA3Nqk=; b=eKrS0aqgqgC3S0Zk1SHG2VuM1qPDLnZQIUt4yLfKRzGqSLDz9Afbw5aQO22g8rF43G 1jifKzpswASiCVV56ky5JZIrYsiESKWEUbD5U9tzGAJCQxw2qJJ4KHNA2Ep5AsSLLBK2 B/VX9MaYamllVAHA3kQM0iP/HpNcCCarXspTEypBjQavBzQNJoAH06Wl5PgHQ4/MVJt2 TqYV4oHLc90S8FfSPvKKa3pHFGHy0nDEcoNX8rskZ0SRv2FdRofO9RHnwObfdCwWoK0y z6RiDP4pgpOmSiriuSmNaY0FAMAjFJ4+ExyW3qeC2X/BIxsA7tNykgtN24usJEQ1D3MS kqag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=uTP7bp2j; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t23si13749197plr.128.2019.02.18.06.33.52; Mon, 18 Feb 2019 06:34:07 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=uTP7bp2j; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387983AbfBRN5T (ORCPT + 99 others); Mon, 18 Feb 2019 08:57:19 -0500 Received: from mail.kernel.org ([198.145.29.99]:37598 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733067AbfBRN5O (ORCPT ); Mon, 18 Feb 2019 08:57:14 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4C210217D9; Mon, 18 Feb 2019 13:57:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1550498232; bh=yAeS96iylfWdmJ4tGBG9c3Mi38g3VUpkYo42rE46zHE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uTP7bp2jIyf4Rh2EpTwKrXI3Ks6GBQG/9WfqVrhTzN/rRv/sIBgprIPw9U6OE/TKz lwtVGZkXtDvGi1kweZCJM9ehcgQSW5G7XMif8oluXefr9clL7zVoDOdWnmg0bQjRnA 5O9ocYI1PSTjEVRdKrG4jz5S0PPwZ9PM/Jwo1D1c= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sandeep Patil , Vlastimil Babka , "Joel Fernandes (Google)" , Alexey Dobriyan , Daniel Colascione , Andrew Morton , Linus Torvalds Subject: [PATCH 4.14 49/62] mm: proc: smaps_rollup: fix pss_locked calculation Date: Mon, 18 Feb 2019 14:43:55 +0100 Message-Id: <20190218133510.004172041@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190218133505.801423074@linuxfoundation.org> References: <20190218133505.801423074@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Sandeep Patil commit 27dd768ed8db48beefc4d9e006c58e7a00342bde upstream. The 'pss_locked' field of smaps_rollup was being calculated incorrectly. It accumulated the current pss everytime a locked VMA was found. Fix that by adding to 'pss_locked' the same time as that of 'pss' if the vma being walked is locked. Link: http://lkml.kernel.org/r/20190203065425.14650-1-sspatil@android.com Fixes: 493b0e9d945f ("mm: add /proc/pid/smaps_rollup") Signed-off-by: Sandeep Patil Acked-by: Vlastimil Babka Reviewed-by: Joel Fernandes (Google) Cc: Alexey Dobriyan Cc: Daniel Colascione Cc: [4.14.x, 4.19.x] Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- fs/proc/task_mmu.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -459,7 +459,7 @@ struct mem_size_stats { }; static void smaps_account(struct mem_size_stats *mss, struct page *page, - bool compound, bool young, bool dirty) + bool compound, bool young, bool dirty, bool locked) { int i, nr = compound ? 1 << compound_order(page) : 1; unsigned long size = nr * PAGE_SIZE; @@ -486,24 +486,31 @@ static void smaps_account(struct mem_siz else mss->private_clean += size; mss->pss += (u64)size << PSS_SHIFT; + if (locked) + mss->pss_locked += (u64)size << PSS_SHIFT; return; } for (i = 0; i < nr; i++, page++) { int mapcount = page_mapcount(page); + unsigned long pss = (PAGE_SIZE << PSS_SHIFT); if (mapcount >= 2) { if (dirty || PageDirty(page)) mss->shared_dirty += PAGE_SIZE; else mss->shared_clean += PAGE_SIZE; - mss->pss += (PAGE_SIZE << PSS_SHIFT) / mapcount; + mss->pss += pss / mapcount; + if (locked) + mss->pss_locked += pss / mapcount; } else { if (dirty || PageDirty(page)) mss->private_dirty += PAGE_SIZE; else mss->private_clean += PAGE_SIZE; - mss->pss += PAGE_SIZE << PSS_SHIFT; + mss->pss += pss; + if (locked) + mss->pss_locked += pss; } } } @@ -526,6 +533,7 @@ static void smaps_pte_entry(pte_t *pte, { struct mem_size_stats *mss = walk->private; struct vm_area_struct *vma = walk->vma; + bool locked = !!(vma->vm_flags & VM_LOCKED); struct page *page = NULL; if (pte_present(*pte)) { @@ -568,7 +576,7 @@ static void smaps_pte_entry(pte_t *pte, if (!page) return; - smaps_account(mss, page, false, pte_young(*pte), pte_dirty(*pte)); + smaps_account(mss, page, false, pte_young(*pte), pte_dirty(*pte), locked); } #ifdef CONFIG_TRANSPARENT_HUGEPAGE @@ -577,6 +585,7 @@ static void smaps_pmd_entry(pmd_t *pmd, { struct mem_size_stats *mss = walk->private; struct vm_area_struct *vma = walk->vma; + bool locked = !!(vma->vm_flags & VM_LOCKED); struct page *page; /* FOLL_DUMP will return -EFAULT on huge zero page */ @@ -591,7 +600,7 @@ static void smaps_pmd_entry(pmd_t *pmd, /* pass */; else VM_BUG_ON_PAGE(1, page); - smaps_account(mss, page, true, pmd_young(*pmd), pmd_dirty(*pmd)); + smaps_account(mss, page, true, pmd_young(*pmd), pmd_dirty(*pmd), locked); } #else static void smaps_pmd_entry(pmd_t *pmd, unsigned long addr, @@ -792,11 +801,8 @@ static int show_smap(struct seq_file *m, } } #endif - /* mmap_sem is held in m_start */ walk_page_vma(vma, &smaps_walk); - if (vma->vm_flags & VM_LOCKED) - mss->pss_locked += mss->pss; if (!rollup_mode) { show_map_vma(m, vma, is_pid);