From patchwork Mon Sep 28 17:54:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 11804477 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 819226CA for ; Mon, 28 Sep 2020 17:56:11 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3340D21D41 for ; Mon, 28 Sep 2020 17:56:10 +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="Q+wV/JzL"; dkim=temperror (0-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="PYYNaM47" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3340D21D41 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 1FBC8900016; Mon, 28 Sep 2020 13:55:29 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 1D622900015; Mon, 28 Sep 2020 13:55:29 -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 F393A900016; Mon, 28 Sep 2020 13:55:28 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0131.hostedemail.com [216.40.44.131]) by kanga.kvack.org (Postfix) with ESMTP id D1C22900015 for ; Mon, 28 Sep 2020 13:55:28 -0400 (EDT) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 9123C180AD802 for ; Mon, 28 Sep 2020 17:55:28 +0000 (UTC) X-FDA: 77313222336.08.basin08_0a11b0827183 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin08.hostedemail.com (Postfix) with ESMTP id 7699E1819E773 for ; Mon, 28 Sep 2020 17:55:28 +0000 (UTC) X-Spam-Summary: 1,0,0,54a64ae709cd223e,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:6742:7576:7903:8603:8957:10004:11026:11473:11658:11914:12043:12291:12296:12438:12555:12679:12683:12895:12986:13894:14096:14110:14181:14721:21080:21450:21627:21796:21990:30036:30054:30064,0,RBL:64.147.123.17:@sent.com:.lbl8.mailshell.net-62.18.0.100 64.100.201.100;04yfyh1monq6ozh919y66dqmqu7n6ypoc84tt5ob7ymwdokz1kxkxm3y6tqkztw.3qdd4b5qtharyqckt39as73th7e8d8frhcj5cppk4yg5dmmir1rc6hif7fniixx.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:26,LUA_SUMMARY:none X-HE-Tag: basin08_0a11b0827183 X-Filterd-Recvd-Size: 7665 Received: from wnew3-smtp.messagingengine.com (wnew3-smtp.messagingengine.com [64.147.123.17]) by imf26.hostedemail.com (Postfix) with ESMTP for ; Mon, 28 Sep 2020 17:55:27 +0000 (UTC) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailnew.west.internal (Postfix) with ESMTP id B2291E89; Mon, 28 Sep 2020 13:55:25 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Mon, 28 Sep 2020 13:55:26 -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=+Ag2KegvStddb FvKA1aftsfAEt1esGFTwgcceSEwVTE=; b=Q+wV/JzLi/GVQYAkHGoDt99oT6+cl GVYZQnorxiSP0T5OVC/u6BAy7DuyFrlyCxeWC80/C+6EvSuvCidfq+hoCz2DthP7 W49p2Y9LC6W+VM/X5g3+WnIh91BlyZthXT7/ahA7yLYDNXyZfeldfAEz6NSl4pwo zMaPb3hssAJ9xMJ1gZz0Ycm6fPyAx5Vg02YzWsi5Z3ZkerGR0Ch73rXxa5hrFIjl l8S2b/QiNBjEJUlSVbdeq9adboFVDjx+ADO+0F4ascZsjli5QhxHy0xhYoW9j+OA 394bwxfpf9Y64bzqpcc/VhyiSfVNq7W/3BXEzP7IMMSIEcUL7H7E6sHjA== 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=+Ag2KegvStddbFvKA1aftsfAEt1esGFTwgcceSEwVTE=; b=PYYNaM47 1SA6hG7pzXIwayd5OpM+ea3rDYKYEOOVD+IQLxRhmJC90dkkLY4wZMHCM+QNTsA4 yjGyLGnYFzj+H+RLt16wBb0KULdoJquhc8hfjW6CSMFvGc4/xtbtsw6DGS11giAW XCxd9n6ZbzIOX8GnXXISgPg/DzLHD1MDlxuTKsdiLvi1/yWRZ0wHFUqwLS/SrRlK ojFiqulMf5zAUZHBhr3kVpGw/bq/BQBXRa2cgAcKWion2e3HrjsP5oni2Mc3/duc pxX7T5nKzupgFP9J47GcB2o5LCwBDzaLZdArjmAbIwA5FnriGGs4K8aYV6eq5AMN KMBJ4lisrf+QeA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrvdeigdeliecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvffufffkofgjfhhrggfgsedtkeertdertddtnecuhfhrohhmpegkihcujggr nhcuoeiiihdrhigrnhesshgvnhhtrdgtohhmqeenucggtffrrghtthgvrhhnpeduhfffve ektdduhfdutdfgtdekkedvhfetuedufedtgffgvdevleehheevjefgtdenucfkphepuddv rdegiedruddtiedrudeigeenucevlhhushhtvghrufhiiigvpeduvdenucfrrghrrghmpe hmrghilhhfrhhomhepiihirdihrghnsehsvghnthdrtghomh X-ME-Proxy: Received: from nvrsysarch6.NVidia.COM (unknown [12.46.106.164]) by mail.messagingengine.com (Postfix) with ESMTPA id CD5B1306468B; Mon, 28 Sep 2020 13:55:24 -0400 (EDT) From: Zi Yan To: linux-mm@kvack.org Cc: "Kirill A . Shutemov" , Roman Gushchin , Rik van Riel , Matthew Wilcox , Shakeel Butt , Yang Shi , Jason Gunthorpe , Mike Kravetz , Michal Hocko , David Hildenbrand , William Kucharski , Andrea Arcangeli , John Hubbard , David Nellans , linux-kernel@vger.kernel.org, Zi Yan Subject: [RFC PATCH v2 19/30] mm: stats: make smap stats understand PUD THPs. Date: Mon, 28 Sep 2020 13:54:17 -0400 Message-Id: <20200928175428.4110504-20-zi.yan@sent.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200928175428.4110504-1-zi.yan@sent.com> References: <20200928175428.4110504-1-zi.yan@sent.com> Reply-To: Zi Yan MIME-Version: 1.0 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 | 68 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 63 insertions(+), 5 deletions(-) diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index a21484b1414d..077196182288 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 @@ -530,7 +529,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 @@ -561,8 +560,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) @@ -570,6 +605,28 @@ static void smaps_pmd_entry(pmd_t *pmd, unsigned long addr, } #endif +static int smaps_pud_range(pud_t pud, pud_t *pudp, 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(pudp, vma); + if (ptl) { + if (memcmp(pudp, &pud, sizeof(pud)) != 0) { + walk->action = ACTION_AGAIN; + spin_unlock(ptl); + return 0; + } + smaps_pud_entry(pudp, addr, walk); + spin_unlock(ptl); + walk->action = ACTION_CONTINUE; + } + + cond_resched(); + return 0; +} + static int smaps_pte_range(pmd_t pmd, pmd_t *pmdp, unsigned long addr, unsigned long end, struct mm_walk *walk) { @@ -712,6 +769,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, };