From patchwork Wed Sep 2 18:06:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 11751487 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7374814E3 for ; Wed, 2 Sep 2020 18:06:50 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3F521206EB for ; Wed, 2 Sep 2020 18:06:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=sent.com header.i=@sent.com header.b="KyXUVz3o"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Soqx4+uH" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3F521206EB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=sent.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 7712890001A; Wed, 2 Sep 2020 14:06:35 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 55BBB900012; Wed, 2 Sep 2020 14:06:35 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2EA71900012; Wed, 2 Sep 2020 14:06:34 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0185.hostedemail.com [216.40.44.185]) by kanga.kvack.org (Postfix) with ESMTP id 9C8E5900012 for ; Wed, 2 Sep 2020 14:06:34 -0400 (EDT) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 58D5F3633 for ; Wed, 2 Sep 2020 18:06:34 +0000 (UTC) X-FDA: 77218901508.26.alley55_3918661270a2 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin26.hostedemail.com (Postfix) with ESMTP id 263A21804B66E for ; Wed, 2 Sep 2020 18:06:34 +0000 (UTC) X-Spam-Summary: 1,0,0,6d54c49fd11787b1,d41d8cd98f00b204,zi.yan@sent.com,,RULES_HIT:41:355:379:541:800:960:973:988:989:1260:1261:1311:1314:1345:1359:1437:1515:1535:1543:1711:1730:1747:1777:1792:2393:2559:2562:2693:3138:3139:3140:3141:3142:3355:3865:3868:3874:4041:4118:4321:4605:5007:6119:6120:6261:6653:7576:7903:8603:8957:10004:11026:11473:11658:11914:12043:12291:12296:12438:12555:12679:12683:12895:13894:14096:14110:14181:14721:21080:21450:21627:21796:21990:30036:30054:30064,0,RBL:66.111.4.25:@sent.com:.lbl8.mailshell.net-66.100.201.100 62.18.0.100;04ygwnbn7m45k9a7cyn4pbf1or1hiyptkaqbpc437ymwdokz1kxkxm3y6tqef3p.q7yp7jg8pudc8gfet39as73thhyc6iyuiuz66k3bh3aureeef97n61ff7fniixx.k-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: alley55_3918661270a2 X-Filterd-Recvd-Size: 7233 Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) by imf21.hostedemail.com (Postfix) with ESMTP for ; Wed, 2 Sep 2020 18:06:33 +0000 (UTC) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 5A0DF5C01B7; Wed, 2 Sep 2020 14:06:33 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Wed, 02 Sep 2020 14:06:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sent.com; h=from :to:cc:subject:date:message-id:in-reply-to:references:reply-to :mime-version:content-transfer-encoding; s=fm1; bh=uV0fK8A8kyNXU 7VUiy/PxZphd7Odkhk2JVfsAnagHMA=; b=KyXUVz3o8pbUikkX3gIY6OzDUrVdo lJZPkDDssk92G83YzNS6IudfjKbKwektFnszCCSdcOL3QPzd6Ripk0pa+okmTBJS 9YutRA/C57/UZyWE2neOW1jmWfWpw/tSUKGGwBCzCrJg3QWaDdtz14BTyIreDlQD Y767g4Tthf9MM5uzf4BCcrZXmM7dB9P/RB8Blil0Z92zfZQf9unYNM1aBhCq+cr4 SsZ/oVPyxZUsgurQjkKR3Ei68wjp5+sUXo9eZLn45WIE3c3C6B9tiJLXhFk3sYsS KGHbApaOLdL6qh4SqZVF0suQZkPs9EGla7uypGM7hDmE4SJEbkzW9pLAw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:reply-to:subject :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=uV0fK8A8kyNXU7VUiy/PxZphd7Odkhk2JVfsAnagHMA=; b=Soqx4+uH CG+o25MOr/QSIRCN3hrUPo6jC71tJuT4TYMcPJcaSW8LPYAU9ZsbE0YaLrGgk6uN WmZDVhqOCQDLFuaEFU6xYjyD9i42lq3EkpAK3uPqYHqSwsGQAl5OgVnsAhlL7AFe eFIz1as9E9UUovorMa8QaFh4ldY2oHqJ69/VmsvljpvRSqd+xieYvVrbGtrLGhe+ Q8nCMvNKK25MOjC/WWhgyUAAF66y7zj0AN7CFO3VgNIpj+j6c031TFdJZjWs3cB/ 3zL7p35gv7gMDaVoqvNcWsonCzI3O51j+cl50SMKZ9RaBEIdzOZ+jU3+26uB6e5p UUcmwjbcSKnQUw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduiedrudefledguddvudcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefhvffufffkofgjfhhrggfgsedtkeertdertddtnecuhfhrohhmpegkihcu jggrnhcuoeiiihdrhigrnhesshgvnhhtrdgtohhmqeenucggtffrrghtthgvrhhnpeduhf ffveektdduhfdutdfgtdekkedvhfetuedufedtgffgvdevleehheevjefgtdenucfkphep uddvrdegiedruddtiedrudeigeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmh epmhgrihhlfhhrohhmpeiiihdrhigrnhesshgvnhhtrdgtohhm X-ME-Proxy: Received: from nvrsysarch6.NVidia.COM (unknown [12.46.106.164]) by mail.messagingengine.com (Postfix) with ESMTPA id 6C61D30600A9; Wed, 2 Sep 2020 14:06:32 -0400 (EDT) From: Zi Yan To: linux-mm@kvack.org, Roman Gushchin Cc: Rik van Riel , "Kirill A . Shutemov" , Matthew Wilcox , Shakeel Butt , Yang Shi , David Nellans , linux-kernel@vger.kernel.org, Zi Yan Subject: [RFC PATCH 07/16] mm: stats: make smap stats understand PUD THPs. Date: Wed, 2 Sep 2020 14:06:19 -0400 Message-Id: <20200902180628.4052244-8-zi.yan@sent.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200902180628.4052244-1-zi.yan@sent.com> References: <20200902180628.4052244-1-zi.yan@sent.com> Reply-To: Zi Yan MIME-Version: 1.0 X-Rspamd-Queue-Id: 263A21804B66E X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam01 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: From: Zi Yan Signed-off-by: Zi Yan --- fs/proc/task_mmu.c | 63 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 58 insertions(+), 5 deletions(-) diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index 7fc9b3cc48d3..2ff80a9c8b57 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -430,10 +430,9 @@ static void smaps_page_accumulate(struct mem_size_stats *mss, } static void smaps_account(struct mem_size_stats *mss, struct page *page, - bool compound, bool young, bool dirty, bool locked) + unsigned long size, bool young, bool dirty, bool locked) { - int i, nr = compound ? compound_nr(page) : 1; - unsigned long size = nr * PAGE_SIZE; + int i, nr = size / PAGE_SIZE; /* * First accumulate quantities that depend only on |size| and the type @@ -536,7 +535,7 @@ static void smaps_pte_entry(pte_t *pte, unsigned long addr, if (!page) return; - smaps_account(mss, page, false, pte_young(*pte), pte_dirty(*pte), locked); + smaps_account(mss, page, PAGE_SIZE, pte_young(*pte), pte_dirty(*pte), locked); } #ifdef CONFIG_TRANSPARENT_HUGEPAGE @@ -567,8 +566,44 @@ static void smaps_pmd_entry(pmd_t *pmd, unsigned long addr, /* pass */; else mss->file_thp += HPAGE_PMD_SIZE; - smaps_account(mss, page, true, pmd_young(*pmd), pmd_dirty(*pmd), locked); + smaps_account(mss, page, HPAGE_PMD_SIZE, pmd_young(*pmd), + pmd_dirty(*pmd), locked); } + +#ifdef CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD +static void smaps_pud_entry(pud_t *pud, unsigned long addr, + struct mm_walk *walk) +{ + 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 (pud_present(*pud)) { + /* FOLL_DUMP will return -EFAULT on huge zero page */ + page = follow_trans_huge_pud(vma, addr, pud, FOLL_DUMP); + } + if (IS_ERR_OR_NULL(page)) + return; + if (PageAnon(page)) + mss->anonymous_thp += HPAGE_PUD_SIZE; + else if (PageSwapBacked(page)) + mss->shmem_thp += HPAGE_PUD_SIZE; + else if (is_zone_device_page(page)) + /* pass */; + else + mss->file_thp += HPAGE_PUD_SIZE; + smaps_account(mss, page, HPAGE_PUD_SIZE, pud_young(*pud), + pud_dirty(*pud), locked); +} +#else +static void smaps_pud_entry(pud_t *pud, unsigned long addr, + struct mm_walk *walk) +{ +} +#endif + + #else static void smaps_pmd_entry(pmd_t *pmd, unsigned long addr, struct mm_walk *walk) @@ -576,6 +611,23 @@ static void smaps_pmd_entry(pmd_t *pmd, unsigned long addr, } #endif +static int smaps_pud_range(pud_t *pud, unsigned long addr, unsigned long end, + struct mm_walk *walk) +{ + struct vm_area_struct *vma = walk->vma; + spinlock_t *ptl; + + ptl = pud_trans_huge_lock(pud, vma); + if (ptl) { + smaps_pud_entry(pud, addr, walk); + spin_unlock(ptl); + walk->action = ACTION_CONTINUE; + } + + cond_resched(); + return 0; +} + static int smaps_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end, struct mm_walk *walk) { @@ -713,6 +765,7 @@ static int smaps_hugetlb_range(pte_t *pte, unsigned long hmask, #endif /* HUGETLB_PAGE */ static const struct mm_walk_ops smaps_walk_ops = { + .pud_entry = smaps_pud_range, .pmd_entry = smaps_pte_range, .hugetlb_entry = smaps_hugetlb_range, };