From patchwork Tue Jun 13 16:09:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Roberts X-Patchwork-Id: 13279023 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id EA77EEB64D8 for ; Tue, 13 Jun 2023 16:10:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5A53D6B007E; Tue, 13 Jun 2023 12:10:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 555CD6B0080; Tue, 13 Jun 2023 12:10:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 41E388E0002; Tue, 13 Jun 2023 12:10:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 2E06A6B007E for ; Tue, 13 Jun 2023 12:10:07 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id B2FAFA0547 for ; Tue, 13 Jun 2023 16:10:06 +0000 (UTC) X-FDA: 80898211212.16.4E69CC4 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf28.hostedemail.com (Postfix) with ESMTP id EEF01C002D for ; Tue, 13 Jun 2023 16:10:04 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=none; spf=pass (imf28.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1686672605; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=u/oFTsAx0DFe844cGbRZyJYSHBhvZgEMygWOmwDfxmw=; b=4pSw9TJZlFxacFvLgqjMeYmVEJvxQoEIQnbHCSs4LDtF5KyG5AeWeIqNxetLKChLn2rKUN VP07+qvc6mBRtdm/9aAOqA0FDjvRodp4UAv36uj+7MVZevxT4xNU1H+T3opB6F59avMfhw t2oJaqQVQGPDmV06U9YCYcDOJ8wVxaI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1686672605; a=rsa-sha256; cv=none; b=NgIIqsK/WC2wAuQIP+opwmLBclF6yCMUi2FWSHd4iTRizTPImP1ok09V3o9s+rnQcAZtsi k1EsflskLIC5Npq8/A+iNHoHTShTvj/sgiPOIAdVWiYOrb2Ks1g6bmCABbYLB+E2thOlFq c2ZkO5uU7FXXF5i9xpZFYoCns/8W44s= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=none; spf=pass (imf28.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com; dmarc=pass (policy=none) header.from=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 9AE202F4; Tue, 13 Jun 2023 09:10:48 -0700 (PDT) Received: from e125769.cambridge.arm.com (e125769.cambridge.arm.com [10.1.196.26]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 4AB803F5A1; Tue, 13 Jun 2023 09:10:02 -0700 (PDT) From: Ryan Roberts To: Jonathan Corbet , Andrew Morton , "Matthew Wilcox (Oracle)" , Yu Zhao Cc: Ryan Roberts , linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-doc@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v1 1/2] mm: /proc/pid/smaps: Report large folio mappings Date: Tue, 13 Jun 2023 17:09:49 +0100 Message-Id: <20230613160950.3554675-2-ryan.roberts@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230613160950.3554675-1-ryan.roberts@arm.com> References: <20230613160950.3554675-1-ryan.roberts@arm.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: EEF01C002D X-Rspam-User: X-Stat-Signature: e5bz8dm3titq1ofrce6qdx9ypzehbmni X-Rspamd-Server: rspam03 X-HE-Tag: 1686672604-615874 X-HE-Meta: U2FsdGVkX1/Lq7/9zV9Q1vYDJ8HU9N0UvlZdYzT4h/qCtLUWFhQz8qvI0cyGJE5RPH5SrNgQXkwNljEM1UqpLJjHpgOwO++sYjJKrvVJqekwGYkOm6Jz1GLs0fcUe8tY6aGe8m9CRcCqIcom9haxjkRzoVqQGFeopYrNrVL3lzBcYzH9O8yy9zSx1IjBbe2B57lgR08JqSLyAKzhvo0Gy7ppz+hgkdzZOCRnJ9P+r+DFPD78zf0v97HOJujqR0tjp5kx9RzCn6GqD844hRffM/bK6aP0x1nHERuZzb4pidAR2J+Zx/GxaJQQXdM92o7ySrfu0b2ERri1Ss1/bs7p9QtTmf/TRbpRbFieyq6g+IDxAxCQ4lyrpG9RcAzWYjKyVyPpUdi07Yg78PLZMO49/begcQZp005FmFIGP6OyYInyB/4olWoHkagzZig4sw+ZJvz6ywqnVbvcyc4eA5/vj4yTamDP+RPiCky5Xi9cuAm7Crbq8tKRnFtfwFFVTjgJXNAIUhus49xFQhMgkx9OOtLod7XGhl7O/sRhjRqXwqrtFKpEb2Ugv7Btw8TmMYDyibKxeJgGNfBIOIMmC4XhoWWpoquiTOFAbMwT0TNRW9eLBGyugiMjdnHwmWP2vcekcMi7lcNPa9GQ2NC7ajMuVNJuyVIu5A/SC2dPoC88Hh8U3o4s/STuadr2RYrJ55YLTwUsrQNenb2aNJAl0I604Ei6tQ4gm1Urzm58DmHPZ57uNhMIYGS5LKMfRi5ruaz7Du0jSSDV8pBbaeq2XWYFq5AhWHjhGyy1BWo4AQDthJb04ZNqsHJNHmKrHsrgCOT9EjW5DJ2y0/HZ2ISe3h2u1eaiuuZW3acvXe8hesdApuqEWf4gko4AFSi4dnIFr7PASE43PF+q0jSetBEZtk8bxTIk/JLX9AnLSKI18qmdV+5P9mynZVPNUS7+a2c+KSokZS3ZKSmUrvKroEyRwKK vxIsp6GO 842TM9YRgaUn0ic4K5ktV4pa4CqmWkzYdeAuXFNGd9pwSYliRCi0PQt1TuDTSg38MHtTVMoYDy6K2CLJLC9nk7Wln8h+M+Un9bdV2Yh6du1n081HJdUBln8n2LwuqCnbQJ53lRwhiNEERKfzFxE9Dxj4Z9SlYtFQP2xuM 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: With the addition of large folios for page cache pages, it is useful to see which orders of folios are being mapped into a process. Additionally, with planned future improvements to allocate large folios for anonymous memory this will become even more useful. Visibility will help to tune performance. New fields "AnonContXXX" and "FileContXXX" indicate physically contiguous runs of memory, binned into power-of-2 sizes starting with the page size and ending with the pmd size. Therefore the exact set of keys will vary by platform. It only includes pte-mapped memory and reports on anonymous and file-backed memory separately. Rollup Example: aaaac9960000-ffffddfdd000 ---p 00000000 00:00 0 [rollup] Rss: 10852 kB ... AnonCont4K: 3480 kB AnonCont8K: 0 kB AnonCont16K: 0 kB AnonCont32K: 0 kB AnonCont64K: 0 kB AnonCont128K: 0 kB AnonCont256K: 0 kB AnonCont512K: 0 kB AnonCont1M: 0 kB AnonCont2M: 0 kB FileCont4K: 3060 kB FileCont8K: 40 kB FileCont16K: 3792 kB FileCont32K: 160 kB FileCont64K: 320 kB FileCont128K: 0 kB FileCont256K: 0 kB FileCont512K: 0 kB FileCont1M: 0 kB FileCont2M: 0 kB Signed-off-by: Ryan Roberts --- Documentation/filesystems/proc.rst | 26 +++++++ fs/proc/task_mmu.c | 115 +++++++++++++++++++++++++++++ 2 files changed, 141 insertions(+) diff --git a/Documentation/filesystems/proc.rst b/Documentation/filesystems/proc.rst index 7897a7dafcbc..5fa3f638848d 100644 --- a/Documentation/filesystems/proc.rst +++ b/Documentation/filesystems/proc.rst @@ -471,6 +471,26 @@ Memory Area, or VMA) there is a series of lines such as the following:: KernelPageSize: 4 kB MMUPageSize: 4 kB Locked: 0 kB + AnonCont4K: 0 kB + AnonCont8K: 0 kB + AnonCont16K: 0 kB + AnonCont32K: 0 kB + AnonCont64K: 0 kB + AnonCont128K: 0 kB + AnonCont256K: 0 kB + AnonCont512K: 0 kB + AnonCont1M: 0 kB + AnonCont2M: 0 kB + FileCont4K: 348 kB + FileCont8K: 0 kB + FileCont16K: 32 kB + FileCont32K: 0 kB + FileCont64K: 512 kB + FileCont128K: 0 kB + FileCont256K: 0 kB + FileCont512K: 0 kB + FileCont1M: 0 kB + FileCont2M: 0 kB THPeligible: 0 VmFlags: rd ex mr mw me dw @@ -524,6 +544,12 @@ replaced by copy-on-write) part of the underlying shmem object out on swap. does not take into account swapped out page of underlying shmem objects. "Locked" indicates whether the mapping is locked in memory or not. +"AnonContXXX" and "FileContXXX" indicate physically contiguous runs of memory, +binned into power-of-2 sizes starting with the page size and ending with the +pmd size. Therefore the exact set of keys will vary by platform. It only +includes pte-mapped memory and reports on anonymous and file-backed memory +separately. + "THPeligible" indicates whether the mapping is eligible for allocating THP pages as well as the THP is PMD mappable or not - 1 if true, 0 otherwise. It just shows the current status. diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index 507cd4e59d07..29fee5b7b00b 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -397,6 +397,49 @@ const struct file_operations proc_pid_maps_operations = { #define PSS_SHIFT 12 #ifdef CONFIG_PROC_PAGE_MONITOR + +#define CONT_ORDER_MAX (PMD_SHIFT-PAGE_SHIFT) +#define CONT_LABEL_FIELD_SIZE 8 +#define CONT_LABEL_BUF_SIZE 32 + +static char *cont_label(int order, char buf[CONT_LABEL_BUF_SIZE]) +{ + unsigned long size = ((1UL << order) * PAGE_SIZE) >> 10; + char suffix = 'K'; + int count; + + if (size >= SZ_1K) { + size >>= 10; + suffix = 'M'; + } + + if (size >= SZ_1K) { + size >>= 10; + suffix = 'G'; + } + + count = snprintf(buf, CONT_LABEL_BUF_SIZE, "%lu%c:", size, suffix); + + /* + * If the string is less than the field size, pad it with spaces so that + * the values line up in smaps. + */ + if (count < CONT_LABEL_FIELD_SIZE) { + memset(&buf[count], ' ', CONT_LABEL_FIELD_SIZE - count); + buf[CONT_LABEL_FIELD_SIZE] = '\0'; + } + + return buf; +} + +struct cont_accumulator { + bool anon; + unsigned long folio_start_pfn; + unsigned long folio_end_pfn; + unsigned long next_pfn; + unsigned long nrpages; +}; + struct mem_size_stats { unsigned long resident; unsigned long shared_clean; @@ -419,8 +462,60 @@ struct mem_size_stats { u64 pss_dirty; u64 pss_locked; u64 swap_pss; + unsigned long anon_cont[CONT_ORDER_MAX + 1]; + unsigned long file_cont[CONT_ORDER_MAX + 1]; + struct cont_accumulator cacc; }; +static void cacc_init(struct mem_size_stats *mss) +{ + struct cont_accumulator *cacc = &mss->cacc; + + cacc->next_pfn = -1; + cacc->nrpages = 0; +} + +static void cacc_drain(struct mem_size_stats *mss) +{ + struct cont_accumulator *cacc = &mss->cacc; + unsigned long *cont = cacc->anon ? mss->anon_cont : mss->file_cont; + unsigned long order; + unsigned long nrpages; + + while (cacc->nrpages > 0) { + order = ilog2(cacc->nrpages); + nrpages = 1UL << order; + cacc->nrpages -= nrpages; + cont[order] += nrpages * PAGE_SIZE; + } +} + +static void cacc_accumulate(struct mem_size_stats *mss, struct page *page) +{ + struct cont_accumulator *cacc = &mss->cacc; + unsigned long pfn = page_to_pfn(page); + bool anon = PageAnon(page); + struct folio *folio; + unsigned long start_pfn; + + if (cacc->next_pfn == pfn && cacc->anon == anon && + pfn >= cacc->folio_start_pfn && pfn < cacc->folio_end_pfn) { + cacc->next_pfn++; + cacc->nrpages++; + } else { + cacc_drain(mss); + + folio = page_folio(page); + start_pfn = page_to_pfn(&folio->page); + + cacc->anon = anon; + cacc->folio_start_pfn = start_pfn; + cacc->folio_end_pfn = start_pfn + folio_nr_pages(folio); + cacc->next_pfn = pfn + 1; + cacc->nrpages = 1; + } +} + static void smaps_page_accumulate(struct mem_size_stats *mss, struct page *page, unsigned long size, unsigned long pss, bool dirty, bool locked, bool private) @@ -473,6 +568,10 @@ static void smaps_account(struct mem_size_stats *mss, struct page *page, if (young || page_is_young(page) || PageReferenced(page)) mss->referenced += size; + /* Accumulate physically contiguous map size information. */ + if (!compound) + cacc_accumulate(mss, page); + /* * Then accumulate quantities that may depend on sharing, or that may * differ page-by-page. @@ -622,6 +721,7 @@ static int smaps_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end, struct mm_walk *walk) { struct vm_area_struct *vma = walk->vma; + struct mem_size_stats *mss = walk->private; pte_t *pte; spinlock_t *ptl; @@ -632,6 +732,7 @@ static int smaps_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end, goto out; } + cacc_init(mss); pte = pte_offset_map_lock(vma->vm_mm, pmd, addr, &ptl); if (!pte) { walk->action = ACTION_AGAIN; @@ -640,6 +741,7 @@ static int smaps_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end, for (; addr != end; pte++, addr += PAGE_SIZE) smaps_pte_entry(pte, addr, walk); pte_unmap_unlock(pte - 1, ptl); + cacc_drain(mss); out: cond_resched(); return 0; @@ -816,6 +918,9 @@ static void smap_gather_stats(struct vm_area_struct *vma, static void __show_smap(struct seq_file *m, const struct mem_size_stats *mss, bool rollup_mode) { + int i; + char label[CONT_LABEL_BUF_SIZE]; + 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); @@ -849,6 +954,16 @@ static void __show_smap(struct seq_file *m, const struct mem_size_stats *mss, mss->swap_pss >> PSS_SHIFT); SEQ_PUT_DEC(" kB\nLocked: ", mss->pss_locked >> PSS_SHIFT); + for (i = 0; i <= CONT_ORDER_MAX; i++) { + seq_printf(m, " kB\nAnonCont%s%8lu", + cont_label(i, label), + mss->anon_cont[i] >> 10); + } + for (i = 0; i <= CONT_ORDER_MAX; i++) { + seq_printf(m, " kB\nFileCont%s%8lu", + cont_label(i, label), + mss->file_cont[i] >> 10); + } seq_puts(m, " kB\n"); } From patchwork Tue Jun 13 16:09:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Roberts X-Patchwork-Id: 13279024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6297AEB64D9 for ; Tue, 13 Jun 2023 16:10:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B234D6B0080; Tue, 13 Jun 2023 12:10:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AD44B6B0081; Tue, 13 Jun 2023 12:10:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 99EA58E0002; Tue, 13 Jun 2023 12:10:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 8540D6B0080 for ; Tue, 13 Jun 2023 12:10:08 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 4A9F1AFB5A for ; Tue, 13 Jun 2023 16:10:08 +0000 (UTC) X-FDA: 80898211296.28.551A5D2 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf07.hostedemail.com (Postfix) with ESMTP id 7B50C4003B for ; Tue, 13 Jun 2023 16:10:06 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=none; spf=pass (imf07.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1686672606; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/LrWKGbrKOZ8XZhunsfnuO9D+E/u1un+phE47f0SpRU=; b=3ULTUgegX0vC8Xh0u4NvwpZSQ2UgJYraxNTvAKd+oTwLhF9tblE9UCQiJg7aQtf5d3rief ps9Ytb8GizXJf5TxJWoN8XgpcagAWEB3FGCqg/k9YkJW5l8cpywIpJyqf0aRkzIf3PCNvV DSw/6iKWjUbVubvWic/8CG0vGghPcxo= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1686672606; a=rsa-sha256; cv=none; b=X5+g70T9rcIEYhbpjnpfLefQXRvp/zPaGMkwpXrOt21iqZsamJC2+NU2dyfrAh2Tnb7hoA lOhzDFNLZhl0GmOuN7YD1IOr5uZpcQ4zn5l5maPlBJ+k4uRom/M1WaE8ha7WHtmZdLzNE3 mr6v8/b0M4Eagu0mllIi0MBrjxIUMNQ= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=none; spf=pass (imf07.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com; dmarc=pass (policy=none) header.from=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 2B482143D; Tue, 13 Jun 2023 09:10:50 -0700 (PDT) Received: from e125769.cambridge.arm.com (e125769.cambridge.arm.com [10.1.196.26]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E80413F5A1; Tue, 13 Jun 2023 09:10:03 -0700 (PDT) From: Ryan Roberts To: Jonathan Corbet , Andrew Morton , "Matthew Wilcox (Oracle)" , Yu Zhao Cc: Ryan Roberts , linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-doc@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v1 2/2] mm: /proc/pid/smaps: Report contpte mappings Date: Tue, 13 Jun 2023 17:09:50 +0100 Message-Id: <20230613160950.3554675-3-ryan.roberts@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230613160950.3554675-1-ryan.roberts@arm.com> References: <20230613160950.3554675-1-ryan.roberts@arm.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 7B50C4003B X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: cf91c86oxzsorgmhspp595y19ntrrn6k X-HE-Tag: 1686672606-951674 X-HE-Meta: U2FsdGVkX19idNFkhz7Nfnvzm+OMyOUd9cPR9Qk6eunrroV2ybsUeGeXwZljpI1/mFl9wloHT/sUX+nCy75XCyrAznUBvgWoYKp2f0v6g3C1LH9RCMARvvaOLDvw0kn6TIvtjqkku8MqGMKGJJfQDFQqXOrDVyElbUdMj2+DJAkzD/4GBxDqdPRil64tVXUYhfbonrGCGZCAzTmsiHGfMd4x6vbVOkg3Nfm5UqUCuvReKWnfUm9w8hwcooj+nUayo01GUSe+9XutNzLnNeJ7/94x2dBVpu+ZsFl08ioOk44pKU8RAZKywl/ooFjQj0lLC+tBjkYddKPJdBCpnnG2XeLlQpfMRBtgpsnajaUoQPMvTUnqit6utgQcPvlUdYAGty8FoSq/rtbK9/EpTPm6eL8bmH34pSnC5K9tE29cvyofb6urOgFUFKLbawIgy1o6AL5HRN5Pp+nH/sF9hBFYVAhNlzrBLAK+VhbhKWZl7bfMe63ZDQ/tug2taIXiMyzatFt6Ca9z5Komh4/xLYyFchKnoESIY/k+lneOav9Yia7uPalOw0hubL2Vp8COG0sLWt5pu346pq4Ev+DaKU6KW9QfOHo1hroPcZlfBekbqVExKrLvoWBkMrpvG86PP0BmEv5bCxHnm84VbPAQ0f2OVkKwFL1zzu1dR54BUSfe0tk88rx+ojo33eBAcnKQkaCJEVw3uIkJvKJtTN9NWzt+EEEqbCjovCeaque4QuRumRjO5MQojF+tLmL6c0101kk96zF/J/oO+yldokET1W2qSidwNtP3sDqBcIBnInGwmEuWOZAiKMfVC2HnZ5FUwlTFs7Nn8OdIX33XU5MMeF1wpZm+MsoPEIqto1mr76aVzhIX5XqbIfM2Z73iW1L2W6Oy0CXh5eU6ovZAkd+Tz78wMPcsy5fVX/7N7OuT35i6PV8+EFy/X4Cr5EN7GrYv/qAuVBiObw3ODdGb8JYbDSC 1SyGCGpz X65W5hwqWPkU4pY3zWuQZGY06ZDntkVP0Nq6BQva3u7UpyvoH49Ivt0jcpmmzf0rn+crngN+qVRwzsvbuT2HA8Cw26n3tNvZxZKDuZNaxa8trW4ynNqtUlRaywdCSl6nZ7qNN6kdkO843R0/IWB3qGstdX6Or5FHi11qq 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: arm64 intends to start using its "contpte" bit in pgtables more frequently, and therefore it would be useful to know how well utilised it is in order to help diagnose and fix performance issues. Add "ContPTEMapped" field, which shows how much of the rss is mapped using contptes. For architectures that do not support contpte mappings (as determined by pte_cont() not being defined) the field will be suppressed. Rollup Example: aaaac5150000-ffffccf07000 ---p 00000000 00:00 0 [rollup] Rss: 11504 kB ... ContPTEMapped: 6848 kB Signed-off-by: Ryan Roberts --- Documentation/filesystems/proc.rst | 5 +++++ fs/proc/task_mmu.c | 19 +++++++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/Documentation/filesystems/proc.rst b/Documentation/filesystems/proc.rst index 5fa3f638848d..726951374c57 100644 --- a/Documentation/filesystems/proc.rst +++ b/Documentation/filesystems/proc.rst @@ -491,6 +491,7 @@ Memory Area, or VMA) there is a series of lines such as the following:: FileCont512K: 0 kB FileCont1M: 0 kB FileCont2M: 0 kB + ContPTEMapped: 0 kB THPeligible: 0 VmFlags: rd ex mr mw me dw @@ -550,6 +551,10 @@ pmd size. Therefore the exact set of keys will vary by platform. It only includes pte-mapped memory and reports on anonymous and file-backed memory separately. +"ContPTEMapped" is only present for architectures that support indicating a set +of contiguously mapped ptes in their page tables. In this case, it indicates +how much of the memory is currently mapped using contpte mappings. + "THPeligible" indicates whether the mapping is eligible for allocating THP pages as well as the THP is PMD mappable or not - 1 if true, 0 otherwise. It just shows the current status. diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index 29fee5b7b00b..0ebd6eb7efd4 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -465,6 +465,7 @@ struct mem_size_stats { unsigned long anon_cont[CONT_ORDER_MAX + 1]; unsigned long file_cont[CONT_ORDER_MAX + 1]; struct cont_accumulator cacc; + unsigned long contpte_mapped; }; static void cacc_init(struct mem_size_stats *mss) @@ -548,7 +549,7 @@ 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, - bool migration) + bool migration, bool contpte) { int i, nr = compound ? compound_nr(page) : 1; unsigned long size = nr * PAGE_SIZE; @@ -572,6 +573,10 @@ static void smaps_account(struct mem_size_stats *mss, struct page *page, if (!compound) cacc_accumulate(mss, page); + /* Accumulate all the pages that are part of a contpte. */ + if (contpte) + mss->contpte_mapped += size; + /* * Then accumulate quantities that may depend on sharing, or that may * differ page-by-page. @@ -636,13 +641,16 @@ static void smaps_pte_entry(pte_t *pte, unsigned long addr, struct vm_area_struct *vma = walk->vma; bool locked = !!(vma->vm_flags & VM_LOCKED); struct page *page = NULL; - bool migration = false, young = false, dirty = false; + bool migration = false, young = false, dirty = false, cont = false; pte_t ptent = ptep_get(pte); if (pte_present(ptent)) { page = vm_normal_page(vma, addr, ptent); young = pte_young(ptent); dirty = pte_dirty(ptent); +#ifdef pte_cont + cont = pte_cont(ptent); +#endif } else if (is_swap_pte(ptent)) { swp_entry_t swpent = pte_to_swp_entry(ptent); @@ -672,7 +680,7 @@ static void smaps_pte_entry(pte_t *pte, unsigned long addr, if (!page) return; - smaps_account(mss, page, false, young, dirty, locked, migration); + smaps_account(mss, page, false, young, dirty, locked, migration, cont); } #ifdef CONFIG_TRANSPARENT_HUGEPAGE @@ -708,7 +716,7 @@ static void smaps_pmd_entry(pmd_t *pmd, unsigned long addr, mss->file_thp += HPAGE_PMD_SIZE; smaps_account(mss, page, true, pmd_young(*pmd), pmd_dirty(*pmd), - locked, migration); + locked, migration, false); } #else static void smaps_pmd_entry(pmd_t *pmd, unsigned long addr, @@ -964,6 +972,9 @@ static void __show_smap(struct seq_file *m, const struct mem_size_stats *mss, cont_label(i, label), mss->file_cont[i] >> 10); } +#ifdef pte_cont + SEQ_PUT_DEC(" kB\nContPTEMapped: ", mss->contpte_mapped); +#endif seq_puts(m, " kB\n"); }