Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp4665886ybi; Tue, 30 Jul 2019 06:08:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqyikmKVDHJMIynzryVm9YqlyeUKDRH7RLaxM+E5VXo6sKfZimgqAdzKAdehca6/oVEi+0ge X-Received: by 2002:a63:2685:: with SMTP id m127mr10058708pgm.6.1564492080138; Tue, 30 Jul 2019 06:08:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564492080; cv=none; d=google.com; s=arc-20160816; b=yenBoFQCRUyLmnC54BY7VUlD55goz8tz1FU5ymmhMZoiIJR9FNnteC2A+lggjyX9gI nBXd29zdSq57DnrjGiClQxD7f+S/dY9J5RJZX4dzr6/sjgGbbO6jTO5/MWpxU1uyyz/N R/BZYPjnOcRLjISntXe45anIHrLxGSt9Q6i3FdcSPr7+CVfkLF3uA3xD3H9VugP/pcAH HuKFcePMbpCtckwf5Kri3oTo33MTha6lNyLYefh23Knvc5coIQoN+Ew1PSEXAjac7DDU /9eZqk0j81UzpQf3ND5LENg0679J0F3kmVTjs3Ep31K83cn6Bf9knPs6Q5Wa7Hs1+Fln 80pA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=+w66kByWBg6FjYrxXcGd5uPmMwPtO1bhVxzbFathPzI=; b=rNeEE+FtQC/RYQ3qtytpYDnvYtoKkc2dVkQKJy+/DiQH/6DymQhQZmVyfvZE2ju1vV rjl+x816GYKtoY4nMSqS53vKnwUiSklw4f312dihhQlYzfPuLjQX97nxdx7jUMy3ZC7K kHGCgdR8GmynUlCUXjs2xM2yso1kcim3xvZuFMZaI54fcwPhaV0CRqoIUByAbUp8dzqc zAFUEGVvHp3EcSjPUulcko+1XSrIqZBLrN1L+8GjnrgSHC/AMr3/sDTpuFMiqJSUJELm CIuNEW70TRkr6LU+W9NZeKqJs5+sjpn9bTitmJZ5lERmjECt1mqMLSALKAUFhv5g6dC+ ZyCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=rlvbtrIt; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y10si26584391plp.117.2019.07.30.06.07.43; Tue, 30 Jul 2019 06:08:00 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=rlvbtrIt; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729348AbfG3NGu (ORCPT + 99 others); Tue, 30 Jul 2019 09:06:50 -0400 Received: from mail-lf1-f65.google.com ([209.85.167.65]:38838 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728331AbfG3NGt (ORCPT ); Tue, 30 Jul 2019 09:06:49 -0400 Received: by mail-lf1-f65.google.com with SMTP id h28so44632098lfj.5 for ; Tue, 30 Jul 2019 06:06:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=+w66kByWBg6FjYrxXcGd5uPmMwPtO1bhVxzbFathPzI=; b=rlvbtrIt21GU4iIJZ5r9dzLKvzu4zMCj4l8RKBDeA0o2mYiR3UKN0mPszMjSSAhX6X 3OVtDWT+La05tWgdt87ZEAWGPkMfChkvs3/3jpFIqx88JiCdQhRyg5Hp1suRYIE7B9ff MncOgoeiv7F+vEZfGTVRnoNhuPuHjjFqr7im4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=+w66kByWBg6FjYrxXcGd5uPmMwPtO1bhVxzbFathPzI=; b=bAHlJH4+UNwQ/JJgcTFzydNb97RTSgdYkxnRgjLedPpjunhDpgXKNLe+QxTSfnA9uX AkoWmrH50lxJNHJlXFg3Y2ugjCRspSOxJsDk2Tu2nCdOGoo5IWPzeeyW0WcngP1KVbTO YoiupqoKbk20FIIZMePPCFDB5sIRmSCbxVSGmoQR3we+qXqznJ0BR+ICLZVwRkeSaDh8 0rTfP2Lohi61B9af0wEPUkQU3exJv/QR0vQTGyvMb2VnXbLeESTSlCVjsdNsyul7ZZaU JwRRINSoZt2A0Tciouy4vC27I6aML0LOxBeSeiGrxwVeFA2LBk2he4MxCZqxKAxtK7De CueQ== X-Gm-Message-State: APjAAAX99VPjuD7vasPTaLlGUnrqw4GwP3LWmqOY2dinv6sVIIeV8+Vr 9Vyl3cywTt2qMVIsSr+yYsDSyZDQzWT4qQ4YfE9QQg== X-Received: by 2002:ac2:53a7:: with SMTP id j7mr23078118lfh.112.1564492007737; Tue, 30 Jul 2019 06:06:47 -0700 (PDT) MIME-Version: 1.0 References: <20190726152319.134152-1-joel@joelfernandes.org> In-Reply-To: <20190726152319.134152-1-joel@joelfernandes.org> From: Joel Fernandes Date: Tue, 30 Jul 2019 09:06:36 -0400 Message-ID: Subject: Re: [PATCH v3 1/2] mm/page_idle: Add per-pid idle page tracking using virtual indexing To: LKML Cc: Alexey Dobriyan , Andrew Morton , Brendan Gregg , Christian Hansen , Daniel Colascione , Florian Mayer , John Dias , Joel Fernandes , Jonathan Corbet , Kees Cook , kernel-team , Linux API , "open list:DOCUMENTATION" , Linux FS Devel , linux-mm , Michal Hocko , Mike Rapoport , Minchan Kim , Namhyung Kim , Roman Gushchin , Stephen Rothwell , Suren Baghdasaryan , Todd Kjos , Vladimir Davydov , Vlastimil Babka , Wei Wang Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jul 26, 2019 at 11:23 AM Joel Fernandes (Google) wrote: > > The page_idle tracking feature currently requires looking up the pagemap > for a process followed by interacting with /sys/kernel/mm/page_idle. > Looking up PFN from pagemap in Android devices is not supported by > unprivileged process and requires SYS_ADMIN and gives 0 for the PFN. > > This patch adds support to directly interact with page_idle tracking at > the PID level by introducing a /proc//page_idle file. It follows > the exact same semantics as the global /sys/kernel/mm/page_idle, but now > looking up PFN through pagemap is not needed since the interface uses > virtual frame numbers, and at the same time also does not require > SYS_ADMIN. > > In Android, we are using this for the heap profiler (heapprofd) which > profiles and pin points code paths which allocates and leaves memory > idle for long periods of time. This method solves the security issue > with userspace learning the PFN, and while at it is also shown to yield > better results than the pagemap lookup, the theory being that the window > where the address space can change is reduced by eliminating the > intermediate pagemap look up stage. In virtual address indexing, the > process's mmap_sem is held for the duration of the access. > > Signed-off-by: Joel Fernandes (Google) > > --- > v2->v3: > Fixed a bug where I was doing a kfree that is not needed due to not > needing to do GFP_ATOMIC allocations. > > v1->v2: > Mark swap ptes as idle (Minchan) > Avoid need for GFP_ATOMIC (Andrew) > Get rid of idle_page_list lock by moving list to stack I believe all suggestions have been addressed. Do these look good now? thanks, - Joel > Internal review -> v1: > Fixes from Suren. > Corrections to change log, docs (Florian, Sandeep) > > fs/proc/base.c | 3 + > fs/proc/internal.h | 1 + > fs/proc/task_mmu.c | 57 +++++++ > include/linux/page_idle.h | 4 + > mm/page_idle.c | 340 +++++++++++++++++++++++++++++++++----- > 5 files changed, 360 insertions(+), 45 deletions(-) > > diff --git a/fs/proc/base.c b/fs/proc/base.c > index 77eb628ecc7f..a58dd74606e9 100644 > --- a/fs/proc/base.c > +++ b/fs/proc/base.c > @@ -3021,6 +3021,9 @@ static const struct pid_entry tgid_base_stuff[] = { > REG("smaps", S_IRUGO, proc_pid_smaps_operations), > REG("smaps_rollup", S_IRUGO, proc_pid_smaps_rollup_operations),