From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932625AbcHIWaJ (ORCPT ); Tue, 9 Aug 2016 18:30:09 -0400 Received: from thejh.net ([37.221.195.125]:39033 "EHLO thejh.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932360AbcHIWaI (ORCPT ); Tue, 9 Aug 2016 18:30:08 -0400 Date: Wed, 10 Aug 2016 00:30:04 +0200 From: Jann Horn To: Robert Foss Cc: Sonny Rao , akpm@linux-foundation.org, keescook@chromium.org, viro@zeniv.linux.org.uk, gorcunov@openvz.org, john.stultz@linaro.org, plaguedbypenguins@gmail.com, mguzik@redhat.com, adobriyan@gmail.com, jdanis@google.com, calvinowens@fb.com, mhocko@suse.com, koct9i@gmail.com, vbabka@suse.cz, n-horiguchi@ah.jp.nec.com, kirill.shutemov@linux.intel.com, ldufour@linux.vnet.ibm.com, hannes@cmpxchg.org, linux-kernel@vger.kernel.org, Ben Zhang , Bryan Freed , Filipe Brandenburger Subject: Re: [PACTH v1] mm, proc: Implement /proc//totmaps Message-ID: <20160809223004.GA7099@pc.thejh.net> References: <1470758743-17685-1-git-send-email-robert.foss@collabora.com> <20160809192414.GA19573@pc.thejh.net> <8ac1b493-e051-ea0e-3a71-c4476054bdb2@collabora.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="7JfCtLOvnd9MIVvH" Content-Disposition: inline In-Reply-To: <8ac1b493-e051-ea0e-3a71-c4476054bdb2@collabora.com> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --7JfCtLOvnd9MIVvH Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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 wrot= e: > >>+ down_read(&mm->mmap_sem); > >>+ hold_task_mempolicy(priv); > >>+ > >>+ for (vma =3D mm->mmap; vma !=3D priv->tail_vma; vma =3D vma->vm_next)= { > >>+ struct mem_size_stats mss; > >>+ struct mm_walk smaps_walk =3D { > >>+ .pmd_entry =3D smaps_pte_range, > >>+ .mm =3D vma->vm_mm, > >>+ .private =3D &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). >=20 > So a simple "static struct mem_size_stats" in totmaps_proc_show() would b= e a > better solution? Er, why "static"? Are you trying to create shared state between different readers for some reason? --7JfCtLOvnd9MIVvH Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBAgAGBQJXqllsAAoJED4KNFJOeCOoPF4P/jBz8AI1LffEDOkTAbfvShol 4h3SVACASiHWDPVySsjh0FKBhuzcQOGx8DVnuZCuZBF8DMPZTtuu1+UQrJ9Vh9DT SZyHYs+M7AT6PBb3BCVM2nD81cq7P1fCGfEWAJKGU6TX5zQqfjwpb5mS6WzTJtFi 0ukAhGRXDv4W0MX3akjbbuHUkv17zDjmuN7Maz27+tBTavyjr/MhEpDQDADUcWtI JfxZDkZCPgQKQcviHb9uj+MsCNygFwQpUdO87TV1fooxskyk0cvDttlI4hzgLnVK xedcq9TQlBxJpLLl+Kuab5C1XPnYAlO7UY4/F0bw3nO5tmriH25rmHyVlpnIkSoh xKYZZopCqa2DgFm0v+RwEUktCcU4FdFlDyYneZEhj8iw3Gsw0O/o9Ka6BfjVklOa iltyR9IvzwOG4ZaOoHtgePwGyGWA8eLOY/Eaj2IuROs/JJfCcCB7/RLu34FM48UU ixEvpxrM0Ena8Ax7pwWDw9GyGCDVShjtw99FG/Au/vEjoAoGrTnKu91KMsVSKblH 333DbVTdBr2iyyu7MHDHOLC0Wqb7MTl/eMCicwPYSOtcqlOlsiMa71e7rH6IJ05f yw9FQNMWygV9t/PzqbdA43uQdnaHtoBDAQu6nFvvam6MHUmrW9mDt7fXblfnBmtj 6g0h9nroc28B0ldzJFrX =VDX0 -----END PGP SIGNATURE----- --7JfCtLOvnd9MIVvH--