Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1459161
| From | Jann Horn <jann@thejh.net> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: [PACTH v1] mm, proc: Implement /proc/<pid>/totmaps |
| Date | 2016-08-10 00:40 +0200 |
| Message-ID | <s4nQJ-585-9@gated-at.bofh.it> (permalink) |
| References | <s4hLk-1pO-27@gated-at.bofh.it> <s4kSS-3iq-13@gated-at.bofh.it> <s4mrD-4nc-5@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
[Multipart message — attachments visible in raw view] - view raw
On Tue, Aug 09, 2016 at 05:01:44PM -0400, Robert Foss wrote:
> On 2016-08-09 03:24 PM, Jann Horn wrote:
> >On Tue, Aug 09, 2016 at 12:05:43PM -0400, robert.foss@collabora.com wrote:
> >>+ down_read(&mm->mmap_sem);
> >>+ hold_task_mempolicy(priv);
> >>+
> >>+ for (vma = mm->mmap; vma != priv->tail_vma; vma = vma->vm_next) {
> >>+ struct mem_size_stats mss;
> >>+ struct mm_walk smaps_walk = {
> >>+ .pmd_entry = smaps_pte_range,
> >>+ .mm = vma->vm_mm,
> >>+ .private = &mss,
> >>+ };
> >>+
> >>+ if (vma->vm_mm && !is_vm_hugetlb_page(vma)) {
> >>+ memset(&mss, 0, sizeof(mss));
> >>+ walk_page_vma(vma, &smaps_walk);
> >>+ add_smaps_sum(&mss, mss_sum);
> >>+ }
> >>+ }
> >
> >Errrr... what? You accumulate values from mem_size_stats items into a
> >struct mss_sum that is associated with the struct file? So when you
> >read the file the second time, you get the old values plus the new ones?
> >And when you read the file in parallel, you get inconsistent values?
> >
> >For most files in procfs, the behavior is that you can just call
> >pread(fd, buf, sizeof(buf), 0) on the same fd again and again, giving
> >you the current values every time, without mutating state. I strongly
> >recommend that you get rid of priv->mss and just accumulate the state
> >in a local variable (maybe one on the stack).
>
> So a simple "static struct mem_size_stats" in totmaps_proc_show() would be a
> better solution?
Er, why "static"? Are you trying to create shared state between different
readers for some reason?
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PACTH v1] mm, proc: Implement /proc/<pid>/totmaps robert.foss@collabora.com - 2016-08-09 18:10 +0200
Re: [PACTH v1] mm, proc: Implement /proc/<pid>/totmaps Mateusz Guzik <mguzik@redhat.com> - 2016-08-09 18:40 +0200
Re: [PACTH v1] mm, proc: Implement /proc/<pid>/totmaps Sonny Rao <sonnyrao@chromium.org> - 2016-08-09 19:00 +0200
Re: [PACTH v1] mm, proc: Implement /proc/<pid>/totmaps Robert Foss <robert.foss@collabora.com> - 2016-08-09 22:20 +0200
Re: [PACTH v1] mm, proc: Implement /proc/<pid>/totmaps Robert Foss <robert.foss@collabora.com> - 2016-08-10 20:10 +0200
Re: [PACTH v1] mm, proc: Implement /proc/<pid>/totmaps Robert Foss <robert.foss@collabora.com> - 2016-08-10 20:30 +0200
Re: [PACTH v1] mm, proc: Implement /proc/<pid>/totmaps Mateusz Guzik <mguzik@redhat.com> - 2016-08-10 23:00 +0200
Re: [PACTH v1] mm, proc: Implement /proc/<pid>/totmaps Alexey Dobriyan <adobriyan@gmail.com> - 2016-08-09 19:00 +0200
Re: [PACTH v1] mm, proc: Implement /proc/<pid>/totmaps Sonny Rao <sonnyrao@chromium.org> - 2016-08-09 20:30 +0200
Re: [PACTH v1] mm, proc: Implement /proc/<pid>/totmaps Konstantin Khlebnikov <koct9i@gmail.com> - 2016-08-09 21:20 +0200
Re: [PACTH v1] mm, proc: Implement /proc/<pid>/totmaps Sonny Rao <sonnyrao@chromium.org> - 2016-08-10 02:40 +0200
Re: [PACTH v1] mm, proc: Implement /proc/<pid>/totmaps Jann Horn <jann@thejh.net> - 2016-08-09 21:30 +0200
Re: [PACTH v1] mm, proc: Implement /proc/<pid>/totmaps Robert Foss <robert.foss@collabora.com> - 2016-08-09 23:10 +0200
Re: [PACTH v1] mm, proc: Implement /proc/<pid>/totmaps Jann Horn <jann@thejh.net> - 2016-08-10 00:40 +0200
Re: [PACTH v1] mm, proc: Implement /proc/<pid>/totmaps Jann Horn <jann@thejh.net> - 2016-08-10 20:40 +0200
Re: [PACTH v1] mm, proc: Implement /proc/<pid>/totmaps Robert Foss <robert.foss@collabora.com> - 2016-08-10 21:50 +0200
Re: [PACTH v1] mm, proc: Implement /proc/<pid>/totmaps Robert Foss <robert.foss@collabora.com> - 2016-08-10 21:00 +0200
Re: [PACTH v1] mm, proc: Implement /proc/<pid>/totmaps Jann Horn <jann@thejh.net> - 2016-08-10 20:10 +0200
Re: [PACTH v1] mm, proc: Implement /proc/<pid>/totmaps Jann Horn <jann@thejh.net> - 2016-08-10 20:20 +0200
Re: [PACTH v1] mm, proc: Implement /proc/<pid>/totmaps Sonny Rao <sonnyrao@chromium.org> - 2016-08-10 20:50 +0200
Re: [PACTH v1] mm, proc: Implement /proc/<pid>/totmaps Sonny Rao <sonnyrao@chromium.org> - 2016-08-10 20:30 +0200
csiph-web