Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp4636996ybh; Tue, 6 Aug 2019 15:20:19 -0700 (PDT) X-Google-Smtp-Source: APXvYqwdC4z7Vr4mJXaSxj05i9L7qOOhnPTyKIDxlAdsyZVs2ERcIhxjdYH8Ty3T6vTqSkJtj6m4 X-Received: by 2002:a63:2157:: with SMTP id s23mr1405253pgm.167.1565130018881; Tue, 06 Aug 2019 15:20:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565130018; cv=none; d=google.com; s=arc-20160816; b=qXd/XaL8htPRxgK4HT1i17bAnkenGS8B3EYFvZOxCB9+Z+7byt37RuiobCZvp01UA1 pUubvRpEcn+/ENhJWejSLnoF42Gdjm3srRXUek+9yA0AHhQ+r/XksdKQZgLu/QBpwyoi +xmQ8RUk0XUu1yVMwDvyckTGZTN/8ZqWWYt/2aRTLMPE6zkIRNQQcqvRk/Q0vP+04Egp n69Aj/pybqXlcIIJvaeeiDJY30ejHMhCnu+b2aNqY4RC3MWQWT6q5qc7CJue3NqvcRSm Gc33WFvdixCmuj8A7WXeFnuvZ1C86zk64V7JqeSQwWUbp0TvV1aJK67qh1oZQ35W9eMA TcrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=cLMFtcOvaClrMbvdwLd+qf/TT0K3oNYe27UnDzPlpx0=; b=lif2zzKvccgkDhCLYHrfxIl3+s9cLcml3nvf8uCqpoN+LqN4AzS/L6oJ/bvS3WPu7o muGq73XciJ4Pwd878OewuVz2rOavBlAovzGE+CuhV61A/Q2+ttqwXbQMAba3F3I8Yh14 AL4MCPag8ZeXkSDaqLDZ1wiUvWR9cdAWTZKG/KOEJ30DLcQw1iRqwglCBi1Rm92Z5DDh YD2TZWiZFH8xguy81VI4GovwfflSWlGxbJ5V8Iuy7H8cJ/U6YPKGC+Jb4FwMHRq+pLx/ ctZrsku6Q59Ncq+lW6+M9jis0TheTgJkt4xHGUbkLtmEBtAkUtpVDYA52ekbn7tCImRu r7KA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=meFIABtu; 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 132si46335449pgc.134.2019.08.06.15.20.01; Tue, 06 Aug 2019 15:20:18 -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=@kernel.org header.s=default header.b=meFIABtu; 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 S1727116AbfHFWTY (ORCPT + 99 others); Tue, 6 Aug 2019 18:19:24 -0400 Received: from mail.kernel.org ([198.145.29.99]:37640 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726419AbfHFWTY (ORCPT ); Tue, 6 Aug 2019 18:19:24 -0400 Received: from localhost.localdomain (c-73-223-200-170.hsd1.ca.comcast.net [73.223.200.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id AB7B121874; Tue, 6 Aug 2019 22:19:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1565129963; bh=uggloegaAwke9A4UP4qBuMyVFR/d5SRDz42VgcGIwio=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=meFIABtuhORcSvMNLD1Hv0nThWvFZI0Qr53BkMiWwh6sZaACsB8AxS19EWRhOD245 XPjeM7EQeanIE0mnWrDAF2RVaT5KRg5MyslBzowrxK7IAG3AckB1mYjDZTe7CHOPId 5LjvjYRK0qyrzcwOxuFdWnbt8prbQySEv0+MClOM= Date: Tue, 6 Aug 2019 15:19:21 -0700 From: Andrew Morton To: "Joel Fernandes (Google)" 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 , joelaf@google.com, 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: <20190806151921.edec128271caccb5214fc1bd@linux-foundation.org> In-Reply-To: <20190805170451.26009-1-joel@joelfernandes.org> References: <20190805170451.26009-1-joel@joelfernandes.org> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org (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. > 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? > > ... > > +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? > + mmdrop(mm); > + return 0; > +} > > ... >