mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Robert Foss <robert.foss@collabora.com>
To: Jann Horn <jann@thejh.net>, Sonny Rao <sonnyrao@chromium.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Kees Cook <keescook@chromium.org>,
	Al Viro <viro@zeniv.linux.org.uk>,
	Cyrill Gorcunov <gorcunov@openvz.org>,
	John Stultz <john.stultz@linaro.org>,
	Robin Humble <plaguedbypenguins@gmail.com>,
	Mateusz Guzik <mguzik@redhat.com>,
	Alexey Dobriyan <adobriyan@gmail.com>,
	Janis Danisevskis <jdanis@google.com>,
	calvinowens@fb.com, Michal Hocko <mhocko@suse.com>,
	Konstantin Khlebnikov <koct9i@gmail.com>,
	Vlastimil Babka <vbabka@suse.cz>,
	Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>,
	"Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>,
	ldufour@linux.vnet.ibm.com, Johannes Weiner <hannes@cmpxchg.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Ben Zhang <benzh@chromium.org>, Bryan Freed <bfreed@chromium.org>,
	Filipe Brandenburger <filbranden@chromium.org>
Subject: Re: [PACTH v1] mm, proc: Implement /proc/<pid>/totmaps
Date: Fri, 12 Aug 2016 12:28:11 -0400	[thread overview]
Message-ID: <c4e93e1f-5438-f38a-5fff-c8a48b963d4e@collabora.com> (raw)
In-Reply-To: <20160810180546.GA486@pc.thejh.net>



On 2016-08-10 02:05 PM, Jann Horn wrote:
> On Wed, Aug 10, 2016 at 10:45:51AM -0700, Sonny Rao wrote:
>> On Wed, Aug 10, 2016 at 10:37 AM, Jann Horn <jann@thejh.net> wrote:
>>> On Wed, Aug 10, 2016 at 10:23:53AM -0700, Sonny Rao wrote:
>>>> On Tue, Aug 9, 2016 at 2:01 PM, Robert Foss <robert.foss@collabora.com> 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:
>>>>>>>
>>>>>>> From: Sonny Rao <sonnyrao@chromium.org>
>>>>>>>
>>>>>>> This is based on earlier work by Thiago Goncales. It implements a new
>>>>>>> per process proc file which summarizes the contents of the smaps file
>>>>>>> but doesn't display any addresses.  It gives more detailed information
>>>>>>> than statm like the PSS (proprotional set size).  It differs from the
>>>>>>> original implementation in that it doesn't use the full blown set of
>>>>>>> seq operations, uses a different termination condition, and doesn't
>>>>>>> displayed "Locked" as that was broken on the original implemenation.
>>>>>>>
>>>>>>> This new proc file provides information faster than parsing the
>>>>>>> potentially
>>>>>>> huge smaps file.
>>>>>>>
>>>>>>> Signed-off-by: Sonny Rao <sonnyrao@chromium.org>
>>>>>>>
>>>>>>> Tested-by: Robert Foss <robert.foss@collabora.com>
>>>>>>> Signed-off-by: Robert Foss <robert.foss@collabora.com>
>>>>>>
>>>>>>
>>>>>>
>>>>>>> +static int totmaps_proc_show(struct seq_file *m, void *data)
>>>>>>> +{
>>>>>>> +       struct proc_maps_private *priv = m->private;
>>>>>>> +       struct mm_struct *mm;
>>>>>>> +       struct vm_area_struct *vma;
>>>>>>> +       struct mem_size_stats *mss_sum = priv->mss;
>>>>>>> +
>>>>>>> +       /* reference to priv->task already taken */
>>>>>>> +       /* but need to get the mm here because */
>>>>>>> +       /* task could be in the process of exiting */
>>>>>>
>>>>>>
>>>>>> Can you please elaborate on this? My understanding here is that you
>>>>>> intend for the caller to be able to repeatedly read the same totmaps
>>>>>> file with pread() and still see updated information after the target
>>>>>> process has called execve() and be able to detect process death
>>>>>> (instead of simply seeing stale values). Is that accurate?
>>>>>>
>>>>>> I would prefer it if you could grab a reference to the mm_struct
>>>>>> directly at open time.
>>>>>
>>>>>
>>>>> Sonny, do you know more about the above comment?
>>>>
>>>> I think right now the file gets re-opened every time, but the mode
>>>> where the file is opened once and repeatedly read is interesting
>>>> because it avoids having to open the file again and again.
>>>>
>>>> I guess you could end up with a wierd situation where you don't read
>>>> the entire contents of the file in open call to read() and you might
>>>> get inconsistent data across the different statistics?
>>>
>>> If the file is read in two chunks, totmaps_proc_show is only called
>>> once. The patch specifies seq_read as read handler. Have a look at its
>>> definition. As long as you don't read from the same seq file in
>>> parallel or seek around in it, simple sequential reads will not
>>> re-invoke the show() method for data that has already been formatted.
>>> For partially consumed data, the kernel buffers the rest until someone
>>> reads it or seeks to another offset.
>>
>> Ok that's good.  If the consumer were using pread() though, would that
>> look like a seek?
>
> Only if the consumer uses pread() with an offset that is not the same as
> the end offset of the previous read.
>
> So if you tried to use the same file from multiple threads in parallel,
> you might still have issues, but as long as you don't do that, it should
> be fine.
>
> I guess it might make sense to document this behavior somewhere - maybe
> the proc.5 manpage?
>

I'll add a note about limitations for parallel read. The overall 
documentation for this feature should live in the proc.5 manpage as well?

  reply	other threads:[~2016-08-12 16:28 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-09 16:05 robert.foss
2016-08-09 16:29 ` Mateusz Guzik
2016-08-09 16:56   ` Sonny Rao
2016-08-09 20:17   ` Robert Foss
2016-08-10 15:39     ` Robert Foss
2016-08-10 15:42       ` Mateusz Guzik
2016-08-10 15:50         ` Robert Foss
2016-08-09 16:58 ` Alexey Dobriyan
2016-08-09 18:28   ` Sonny Rao
2016-08-09 19:16 ` Konstantin Khlebnikov
2016-08-10  0:30   ` Sonny Rao
2016-08-09 19:24 ` Jann Horn
2016-08-09 21:01   ` Robert Foss
2016-08-09 22:30     ` Jann Horn
2016-08-10 14:16       ` Robert Foss
2016-08-10 15:02         ` Jann Horn
2016-08-10 16:24           ` Robert Foss
2016-08-10 17:23     ` Sonny Rao
2016-08-10 17:37       ` Jann Horn
2016-08-10 17:45         ` Sonny Rao
2016-08-10 18:05           ` Jann Horn
2016-08-12 16:28             ` Robert Foss [this message]
2016-08-13 12:39               ` Jann Horn

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c4e93e1f-5438-f38a-5fff-c8a48b963d4e@collabora.com \
    --to=robert.foss@collabora.com \
    --cc=adobriyan@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=benzh@chromium.org \
    --cc=bfreed@chromium.org \
    --cc=calvinowens@fb.com \
    --cc=filbranden@chromium.org \
    --cc=gorcunov@openvz.org \
    --cc=hannes@cmpxchg.org \
    --cc=jann@thejh.net \
    --cc=jdanis@google.com \
    --cc=john.stultz@linaro.org \
    --cc=keescook@chromium.org \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=koct9i@gmail.com \
    --cc=ldufour@linux.vnet.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mguzik@redhat.com \
    --cc=mhocko@suse.com \
    --cc=n-horiguchi@ah.jp.nec.com \
    --cc=plaguedbypenguins@gmail.com \
    --cc=sonnyrao@chromium.org \
    --cc=vbabka@suse.cz \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome