Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1200217

Re: [PATCH] smaps: fill missing fields for vma(VM_HUGETLB)

From Jörn Engel <joern@purestorage.com>
Newsgroups linux.kernel
Subject Re: [PATCH] smaps: fill missing fields for vma(VM_HUGETLB)
Date 2015-08-04 20:30 +0200
Message-ID <pTP8l-1Gf-3@gated-at.bofh.it> (permalink)
References (5 earlier) <pRnSV-Ns-1@gated-at.bofh.it> <pRETL-dU-13@gated-at.bofh.it> <pRIXn-5Vv-5@gated-at.bofh.it> <pTACl-5Ra-3@gated-at.bofh.it> <pTCNQ-Kb-7@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Tue, Aug 04, 2015 at 05:13:39AM +0000, Naoya Horiguchi wrote:
> On Tue, Aug 04, 2015 at 02:55:30AM +0000, Naoya Horiguchi wrote:
> > 
> > One possible way to get hugetlb metric in per-task basis is to walk page
> > table via /proc/pid/pagemap, and counting page flags for each mapped page
> > (we can easily do this with tools/vm/page-types.c like "page-types -p <PID>
> > -b huge"). This is obviously slower than just storing the counter as
> > in-kernel data and just exporting it, but might be useful in some situation.

Maybe.  The current situation is a mess and I don't know the best way
out of it yet.

> BTW, currently smaps doesn't report any meaningful info for vma(VM_HUGETLB).
> I wrote the following patch, which hopefully is helpful for your purpose.
> 
> Thanks,
> Naoya Horiguchi
> 
> ---
> From: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>
> Subject: [PATCH] smaps: fill missing fields for vma(VM_HUGETLB)
> 
> Currently smaps reports many zero fields for vma(VM_HUGETLB), which is
> inconvenient when we want to know per-task or per-vma base hugetlb usage.
> This patch enables these fields by introducing smaps_hugetlb_range().
> 
> before patch:
> 
>   Size:              20480 kB
>   Rss:                   0 kB
>   Pss:                   0 kB
>   Shared_Clean:          0 kB
>   Shared_Dirty:          0 kB
>   Private_Clean:         0 kB
>   Private_Dirty:         0 kB
>   Referenced:            0 kB
>   Anonymous:             0 kB
>   AnonHugePages:         0 kB
>   Swap:                  0 kB
>   KernelPageSize:     2048 kB
>   MMUPageSize:        2048 kB
>   Locked:                0 kB
>   VmFlags: rd wr mr mw me de ht
> 
> after patch:
> 
>   Size:              20480 kB
>   Rss:               18432 kB
>   Pss:               18432 kB
>   Shared_Clean:          0 kB
>   Shared_Dirty:          0 kB
>   Private_Clean:         0 kB
>   Private_Dirty:     18432 kB
>   Referenced:        18432 kB
>   Anonymous:         18432 kB
>   AnonHugePages:         0 kB
>   Swap:                  0 kB
>   KernelPageSize:     2048 kB
>   MMUPageSize:        2048 kB
>   Locked:                0 kB
>   VmFlags: rd wr mr mw me de ht

Nice!

> Signed-off-by: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>
> ---
>  fs/proc/task_mmu.c | 27 +++++++++++++++++++++++++++
>  1 file changed, 27 insertions(+)
> 
> diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
> index ca1e091881d4..c7218603306d 100644
> --- a/fs/proc/task_mmu.c
> +++ b/fs/proc/task_mmu.c
> @@ -610,12 +610,39 @@ static void show_smap_vma_flags(struct seq_file *m, struct vm_area_struct *vma)
>  	seq_putc(m, '\n');
>  }
>  
> +#ifdef CONFIG_HUGETLB_PAGE
> +static int smaps_hugetlb_range(pte_t *pte, unsigned long hmask,
> +				 unsigned long addr, unsigned long end,
> +				 struct mm_walk *walk)
> +{
> +	struct mem_size_stats *mss = walk->private;
> +	struct vm_area_struct *vma = walk->vma;
> +	struct page *page = NULL;
> +
> +	if (pte_present(*pte)) {
> +		page = vm_normal_page(vma, addr, *pte);
> +	} else if (is_swap_pte(*pte)) {
> +		swp_entry_t swpent = pte_to_swp_entry(*pte);
> +
> +		if (is_migration_entry(swpent))
> +			page = migration_entry_to_page(swpent);
> +	}
> +	if (page)
> +		smaps_account(mss, page, huge_page_size(hstate_vma(vma)),
> +			      pte_young(*pte), pte_dirty(*pte));
> +	return 0;
> +}
> +#endif /* HUGETLB_PAGE */
> +
>  static int show_smap(struct seq_file *m, void *v, int is_pid)
>  {
>  	struct vm_area_struct *vma = v;
>  	struct mem_size_stats mss;
>  	struct mm_walk smaps_walk = {
>  		.pmd_entry = smaps_pte_range,
> +#ifdef CONFIG_HUGETLB_PAGE
> +		.hugetlb_entry = smaps_hugetlb_range,
> +#endif

Not too fond of the #ifdef.  But I won't blame you, as there already is
an example of the same and - worse - a contradicting example that
unconditionally assigns and moved the #ifdef elsewhere.

Hugetlb is the unloved stepchild with 13 years of neglect and
half-measures.  It shows.

Patch looks good to me.

Acked-by: Jörn Engel <joern@logfs.org>

Jörn

--
Functionality is an asset, but code is a liability.
--Ted Dziuba
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

hugetlb pages not accounted for in rss Mike Kravetz <mike.kravetz@oracle.com> - 2015-07-28 01:30 +0200
  Re: hugetlb pages not accounted for in rss Mike Kravetz <mike.kravetz@oracle.com> - 2015-07-28 23:20 +0200
    Re: hugetlb pages not accounted for in rss Jörn Engel <joern@purestorage.com> - 2015-07-29 03:00 +0200
      Re: hugetlb pages not accounted for in rss Naoya Horiguchi <n-horiguchi@ah.jp.nec.com> - 2015-08-04 05:00 +0200
        [PATCH] smaps: fill missing fields for vma(VM_HUGETLB) Naoya Horiguchi <n-horiguchi@ah.jp.nec.com> - 2015-08-04 07:20 +0200
          Re: [PATCH] smaps: fill missing fields for vma(VM_HUGETLB) Jörn Engel <joern@purestorage.com> - 2015-08-04 20:30 +0200
            Re: [PATCH] smaps: fill missing fields for vma(VM_HUGETLB) David Rientjes <rientjes@google.com> - 2015-08-06 04:20 +0200
              Re: [PATCH] smaps: fill missing fields for vma(VM_HUGETLB) Naoya Horiguchi <n-horiguchi@ah.jp.nec.com> - 2015-08-06 09:50 +0200
                [PATCH v2 0/2] hugetlb: display per-process/per-vma usage Naoya Horiguchi <n-horiguchi@ah.jp.nec.com> - 2015-08-07 09:30 +0200
                [PATCH v2 2/2] mm: hugetlb: add VmHugetlbRSS: field in  /proc/pid/status Naoya Horiguchi <n-horiguchi@ah.jp.nec.com> - 2015-08-07 09:30 +0200
                Re: [PATCH v2 2/2] mm: hugetlb: add VmHugetlbRSS: field in  /proc/pid/status Andrew Morton <akpm@linux-foundation.org> - 2015-08-08 01:00 +0200
                [PATCH v3 3/3] Documentation/filesystems/proc.txt: document hugetlb  RSS Naoya Horiguchi <n-horiguchi@ah.jp.nec.com> - 2015-08-10 02:50 +0200
                Re: [PATCH v3 3/3] Documentation/filesystems/proc.txt: document  hugetlb RSS David Rientjes <rientjes@google.com> - 2015-08-11 02:50 +0200
                Re: [PATCH v3 3/3] Documentation/filesystems/proc.txt: document  hugetlb RSS Naoya Horiguchi <n-horiguchi@ah.jp.nec.com> - 2015-08-12 02:10 +0200
                [PATCH v4 2/2] mm: hugetlb: proc: add HugetlbPages field to  /proc/PID/status Naoya Horiguchi <n-horiguchi@ah.jp.nec.com> - 2015-08-12 09:50 +0200
                Re: [PATCH v4 2/2] mm: hugetlb: proc: add HugetlbPages field to  /proc/PID/status David Rientjes <rientjes@google.com> - 2015-08-12 22:40 +0200
                Re: [PATCH v4 2/2] mm: hugetlb: proc: add HugetlbPages field to  /proc/PID/status Naoya Horiguchi <n-horiguchi@ah.jp.nec.com> - 2015-08-13 02:50 +0200
                Re: [PATCH v4 2/2] mm: hugetlb: proc: add HugetlbPages field to  /proc/PID/status Jörn Engel <joern@purestorage.com> - 2015-08-13 23:20 +0200
                Re: [PATCH v4 2/2] mm: hugetlb: proc: add HugetlbPages field to  /proc/PID/status Jörn Engel <joern@purestorage.com> - 2015-08-13 23:20 +0200
                Re: [PATCH v4 2/2] mm: hugetlb: proc: add HugetlbPages field to  /proc/PID/status David Rientjes <rientjes@google.com> - 2015-08-17 23:30 +0200
                [PATCH v4 1/2] mm: hugetlb: proc: add HugetlbPages field to  /proc/PID/smaps Naoya Horiguchi <n-horiguchi@ah.jp.nec.com> - 2015-08-12 09:50 +0200
                Re: [PATCH v4 1/2] mm: hugetlb: proc: add HugetlbPages field to  /proc/PID/smaps David Rientjes <rientjes@google.com> - 2015-08-12 22:30 +0200
                Re: [PATCH v4 1/2] mm: hugetlb: proc: add HugetlbPages field to  /proc/PID/smaps Jörn Engel <joern@purestorage.com> - 2015-08-13 23:20 +0200
                [PATCH v3 2/3] mm: hugetlb: add VmHugetlbRSS: field in  /proc/pid/status Naoya Horiguchi <n-horiguchi@ah.jp.nec.com> - 2015-08-10 02:50 +0200
                Re: [PATCH v3 2/3] mm: hugetlb: add VmHugetlbRSS: field in  /proc/pid/status Naoya Horiguchi <n-horiguchi@ah.jp.nec.com> - 2015-08-10 03:20 +0200
                [PATCH v3 1/3] smaps: fill missing fields for vma(VM_HUGETLB) Naoya Horiguchi <n-horiguchi@ah.jp.nec.com> - 2015-08-10 02:50 +0200
                Re: [PATCH v2 2/2] mm: hugetlb: add VmHugetlbRSS: field in  /proc/pid/status Naoya Horiguchi <n-horiguchi@ah.jp.nec.com> - 2015-08-10 02:50 +0200
                [PATCH v2 1/2] smaps: fill missing fields for vma(VM_HUGETLB) Naoya Horiguchi <n-horiguchi@ah.jp.nec.com> - 2015-08-07 09:30 +0200
                Re: [PATCH v2 1/2] smaps: fill missing fields for vma(VM_HUGETLB) Andrew Morton <akpm@linux-foundation.org> - 2015-08-08 01:00 +0200
                Re: [PATCH v2 1/2] smaps: fill missing fields for vma(VM_HUGETLB) David Rientjes <rientjes@google.com> - 2015-08-11 02:40 +0200
                Re: [PATCH v2 1/2] smaps: fill missing fields for vma(VM_HUGETLB) Naoya Horiguchi <n-horiguchi@ah.jp.nec.com> - 2015-08-12 01:40 +0200
                Re: [PATCH v2 1/2] smaps: fill missing fields for vma(VM_HUGETLB) David Rientjes <rientjes@google.com> - 2015-08-12 01:50 +0200

csiph-web