Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp5236675ybh; Wed, 7 Aug 2019 03:01:06 -0700 (PDT) X-Google-Smtp-Source: APXvYqwnj80J/xGhBFuU9HODos7C5J9KTqVfC+7Xvs0lv0BjSI9kVcoWllqZeSn/xlYHNJ+a/Hec X-Received: by 2002:a17:90a:f488:: with SMTP id bx8mr7506634pjb.91.1565172065944; Wed, 07 Aug 2019 03:01:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565172065; cv=none; d=google.com; s=arc-20160816; b=kKyBatdEm8/f86Kkwj0BKvbEW1gHSxZ7FX7pz3/cn9a7njoeEiklbCWQs/rpEg8qUD lGZmQd7ziHRoj6NG0euWCTo2Mfii9GjA+KrYOOW3sCFG4DtVAjTvfm/SLkAAjR1jK5Bt z+M9Kg086mJQ1KmNguJQtLo57MdcnKYn9Omo088mbLmrj927wiQoy9pNd2DV16O/BQ0d HRm8dJo/EtvANqMzEZoU4GHMTTFos/9k1m0zIl6XpjKjbqStHjTfD77WJJ89D/joejN6 zdkMSJRrn624pjDy7o9twjnfrG73TiQB9a3+uHKY+m9QXfMnIL73CeRz7ofpjy9tmjVz gMmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=ZzlW9YyeiJ854Q1Ko1IPtbBbq0BYDBiTFOQHxFAcEc0=; b=I8oJIrPtOBKs3aYqM0SJZMiBkDegdZiVMvEwkSF5NCkKv80YB+QuAyF/OT8lbsiqz6 ozleFvi6LEhqFBbPDoUgawm7Qfhc1PW1U6OuhpCq+WUi9waB4xnLD7yNf0v9MLfZV/kz 52GJ4DgVwhIoFE71ujtQ+IvsjhKCSRc/Zba/Cmp9ppCsZ7d5qrMDN7sm2sgRppa4yhsx zFd6ang1S87BOzkRnc+BNaOpIZ3p0nSSoC/o6TIDPVss3bDcTi8jAoEQHlys+WJb0lI2 ryKKHQoxuHJ72B3Ig31YVxnqr82u9atkxfsNqaVmvY9nF9fa6k26JnEsDEm1zv9VfpfI jKhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=tCgJHesT; 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 cd17si47562895plb.210.2019.08.07.03.00.49; Wed, 07 Aug 2019 03:01:05 -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=tCgJHesT; 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 S1729344AbfHGKAQ (ORCPT + 99 others); Wed, 7 Aug 2019 06:00:16 -0400 Received: from mail-pl1-f196.google.com ([209.85.214.196]:43321 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729233AbfHGKAQ (ORCPT ); Wed, 7 Aug 2019 06:00:16 -0400 Received: by mail-pl1-f196.google.com with SMTP id 4so33025029pld.10 for ; Wed, 07 Aug 2019 03:00:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=ZzlW9YyeiJ854Q1Ko1IPtbBbq0BYDBiTFOQHxFAcEc0=; b=tCgJHesT9hyuTLNhA2JU2/UNk19RK2nU5AFtCBJaYk5S3w1NDvpmaFeth5Yo8wYH0s oM4Lnuq7N9b9hZ/RVsWSEyFtN0JZddKU9+yGb3onrTbH8MixdAzzdFWXDrrSZxkzHWDG kUybN6h9P7J8OPDKxwZ6UTFwzfLKIdRbmfvNc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=ZzlW9YyeiJ854Q1Ko1IPtbBbq0BYDBiTFOQHxFAcEc0=; b=VJ57l3dzSgG6QRsZ7ZTgabT7rjf6TcRR+KmE9h5RhRepn+ZOHK6uDzMv+mIlfWh021 Rzlu7zUaRKaEqSIBQxBMSbmX1qdX9OPRo9nANZQf4iHU7Vqkipgvp1ejKGL0MTnVPhnN FXeQbkpTTQbbIswqG42uNwQfpruXDmdMnSuFLsKPf5hAFibShoEuvCQv+kdHWW/g5e7u CHt7X1l1tFDc0o2RMgL7wfm2a25E5HPv1FcCjWNbjvjjmFZv74m8bhLKYgLYtH+tuFg3 Z5k4i9eneb1PzPOmJg26uA8FXWzCwIhlHLa1ASP4dm3aTbtjczZPb8ZRGAA9EMJEvl0m WWiw== X-Gm-Message-State: APjAAAV2dORtfMEt+ajyOz0Ko3NoYZd6rXaoKLGLsg4EQq1oFjFhVAgG L/5ACSgfS3IIwrMmvJhubGXWZA== X-Received: by 2002:aa7:9117:: with SMTP id 23mr8530297pfh.206.1565172015496; Wed, 07 Aug 2019 03:00:15 -0700 (PDT) Received: from localhost ([2620:15c:6:12:9c46:e0da:efbf:69cc]) by smtp.gmail.com with ESMTPSA id b136sm120273213pfb.73.2019.08.07.03.00.14 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 07 Aug 2019 03:00:14 -0700 (PDT) Date: Wed, 7 Aug 2019 06:00:13 -0400 From: Joel Fernandes To: Andrew Morton Cc: linux-kernel@vger.kernel.org, Alexey Dobriyan , Borislav Petkov , Brendan Gregg , Catalin Marinas , Christian Hansen , dancol@google.com, fmayer@google.com, "H. Peter Anvin" , Ingo Molnar , Jonathan Corbet , Kees Cook , kernel-team@android.com, linux-api@vger.kernel.org, linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, Michal Hocko , Mike Rapoport , minchan@kernel.org, namhyung@google.com, paulmck@linux.ibm.com, Robin Murphy , Roman Gushchin , Stephen Rothwell , surenb@google.com, Thomas Gleixner , tkjos@google.com, Vladimir Davydov , Vlastimil Babka , Will Deacon , Brendan Gregg Subject: Re: [PATCH v4 1/5] mm/page_idle: Add per-pid idle page tracking using virtual indexing Message-ID: <20190807100013.GC169551@google.com> References: <20190805170451.26009-1-joel@joelfernandes.org> <20190806151921.edec128271caccb5214fc1bd@linux-foundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190806151921.edec128271caccb5214fc1bd@linux-foundation.org> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Aug 06, 2019 at 03:19:21PM -0700, Andrew Morton wrote: > (cc Brendan's other email address, hoping for review input ;)) ;) > On Mon, 5 Aug 2019 13:04:47 -0400 "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. > > Quite a lot of changes to the page_idle code. Has this all been > runtime tested on architectures where > CONFIG_HAVE_ARCH_PTE_SWP_PGIDLE=n? That could be x86 with a little > Kconfig fiddle-for-testing-purposes. I will do this Kconfig fiddle test with CONFIG_HAVE_ARCH_PTE_SWP_PGIDLE=n and test the patch as well. In previous series, this flag was not there (which should have been equivalent to the above test), and things are working fine. > > 8 files changed, 376 insertions(+), 45 deletions(-) > > Quite a lot of new code unconditionally added to major architectures. > Are we confident that everyone will want this feature? I did not follow, could you clarify more? All of this diff stat is not to architecture code: arch/Kconfig | 3 ++ fs/proc/base.c | 3 ++ fs/proc/internal.h | 1 + fs/proc/task_mmu.c | 43 +++++++++++++++++++++ include/asm-generic/pgtable.h | 6 +++ include/linux/page_idle.h | 4 ++ mm/page_idle.c | 359 +++++++++++++++++++++++++++++.. mm/rmap.c | 2 + 8 files changed, 376 insertions(+), 45 deletions(-) The arcitecture change is in a later patch, and is not that many lines. Also, I am planning to split the swap functionality of the patch into a separate one for easier review. > > +static int proc_page_idle_open(struct inode *inode, struct file *file) > > +{ > > + struct mm_struct *mm; > > + > > + mm = proc_mem_open(inode, PTRACE_MODE_READ); > > + if (IS_ERR(mm)) > > + return PTR_ERR(mm); > > + file->private_data = mm; > > + return 0; > > +} > > + > > +static int proc_page_idle_release(struct inode *inode, struct file *file) > > +{ > > + struct mm_struct *mm = file->private_data; > > + > > + if (mm) > > I suspect the test isn't needed? proc_page_idle_release) won't be > called if proc_page_idle_open() failed? Yes you are right, will remove the test. thanks, - Joel