Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp909874ybi; Fri, 31 May 2019 10:36:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqwloxWdvQDRADodB4ja8GiGVkaZ058JiY1+t2WvBxpOumj/fKH0ydVTFV9wwbWiTpgzrN3O X-Received: by 2002:a63:1106:: with SMTP id g6mr10030050pgl.83.1559324219846; Fri, 31 May 2019 10:36:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559324219; cv=none; d=google.com; s=arc-20160816; b=yiBvz7LaWxnjAHGEziL4iOiaCY9E7HKc5WIFLGCLoZf0oP6zRzmspjxZ5HjqeHU35N 2bKiDNcfsvqyjfbz1AG5cnu7/Cw0ef4TJbnAsZTg2O7KCC8fp92Rs1Md6UNdgoDt/smQ di0gocsWEABZxvAzgzDtsI3GtHP/DqQ4uA3XWIBot7ndUHNkZJxVgwLNKxRlZhVHU13T pW9sZTcUuqXOuQlkOvgrMzwvw6x6I0IVg8DJrWATWMZTqN/LE4vw/TCnKg8JV86HQcnK vBIwjucTYjgSi/phje1PS1Gikgmvfa6PqHfnqwKLkmIuDDtMSBbBtygbffrqJsYYGoM7 qWEw== 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=UT95TGe8i+iSc4Mrslq2c6bgkkgpf7MqKUVEvywS9rQ=; b=fKlyxQm1nnQUGGddcczFESdPeLeF8OuDXBJGR+5p7nme9H93xrSQhW+J1W2V8H3Bq8 pIzbqBf7AwTaNvyM8ibPcK7QAr0xa3YntHdzR+afGgdPGWUIoAk0E9jA8BWqSqndff8H NdoSLp7Nx0qcJcQCzsmLpLN4NMQTB4JYRtSjx1uUq2ZDcNPMkhzizOH9j45EPOltPjCy rV/+2O4Mi5/WlJAhBifQZUlZzGVUOw0wwvk5igzz2UEN9PvrUq2MLjwuJzEDmwvTsLVE kPXrZZmvClPfAC2A9ENXqFm6PZhUwhzlJlIxU2LKW26pqfi+4x05hyIaMwXoAbgHjItv pWIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=XkRXGO8r; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p19si6720567pgm.175.2019.05.31.10.36.44; Fri, 31 May 2019 10:36:59 -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=@google.com header.s=20161025 header.b=XkRXGO8r; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726896AbfEaRfd (ORCPT + 99 others); Fri, 31 May 2019 13:35:33 -0400 Received: from mail-vs1-f65.google.com ([209.85.217.65]:38528 "EHLO mail-vs1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726862AbfEaRfd (ORCPT ); Fri, 31 May 2019 13:35:33 -0400 Received: by mail-vs1-f65.google.com with SMTP id b10so7220042vsp.5 for ; Fri, 31 May 2019 10:35:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=UT95TGe8i+iSc4Mrslq2c6bgkkgpf7MqKUVEvywS9rQ=; b=XkRXGO8rGh8TZ4EUzxfokC5808K1dz1UcgRHXk5nSZXjzX7ByJ9OOS3VUfLxIGGAe4 tBJOQ41tQiTrAGL8Vqh+uDVv6x0PoGvSasP0vc6fBcPf9wEekZyVRoXaNo1xuJ2Fn5wJ Mdw2jJZ25WDo6I4uz8vJmqlZY84v/5BJKw6tSscV26kE59k4+mPTnBO54Ga2JiQ3fF49 9f36MMHIrDv6UDicgzKbwCc4KmUky3yRfA6nB2SCVng6BOkS7L2+dNFKBJmEgZK6JRI0 aOaHXvY0eVS+UnHvlhi71Ao0kSR18YVuOC0awHBXNUVnRpG6nJezGgjBM5MLoZEwisfe er5A== 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=UT95TGe8i+iSc4Mrslq2c6bgkkgpf7MqKUVEvywS9rQ=; b=gMyhVM4OOOF24+h8/4vL7DXeS5Mvq77/yIY5yiiCNqm1u5f3j7xlvttzsNJg9dU+BL oJQ0JuS5jALkuTkxBYbdFcbifxGpEV2qMkRcdSIhRCuzSV6IFUqwE5kBZwVFqFZHLTgn NqvBN+x+YvmGOyu9RgshHuneW4coqMwA3DHCA5fFy6qoy+xnlhz8ARlWQiB3dMeFY4XG Ecqx5b8pR8mb05dYwiDVDdEsQRPxNMy1dZtR3IyG6MkPF97CRzoAeIEOlhsuUwLV23Z3 VAYsWEWqbMdSg2Gg/6KBWdBqn9crihCOre0b+dgiAuL+QYLRqUszZeAoW6EhFAf8eD2S B52Q== X-Gm-Message-State: APjAAAVjkAmkMt5NfzlRAXP2BF9o1XrLrMtLUjqSdF/StWofHzhrNPbY MGwf51h1EqZW7gJCvMDOg7MTzOVH6yzhka6szeMhMg== X-Received: by 2002:a67:2084:: with SMTP id g126mr6137960vsg.114.1559324131824; Fri, 31 May 2019 10:35:31 -0700 (PDT) MIME-Version: 1.0 References: <20190531064313.193437-1-minchan@kernel.org> <20190531064313.193437-6-minchan@kernel.org> In-Reply-To: <20190531064313.193437-6-minchan@kernel.org> From: Daniel Colascione Date: Fri, 31 May 2019 10:35:20 -0700 Message-ID: Subject: Re: [RFCv2 5/6] mm: introduce external memory hinting API To: Minchan Kim Cc: Andrew Morton , linux-mm , LKML , Linux API , Michal Hocko , Johannes Weiner , Tim Murray , Joel Fernandes , Suren Baghdasaryan , Shakeel Butt , Sonny Rao , Brian Geffon , Jann Horn , Oleg Nesterov , Christian Brauner , oleksandr@redhat.com, hdanton@sina.com 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 Thu, May 30, 2019 at 11:43 PM Minchan Kim wrote: > > There is some usecase that centralized userspace daemon want to give > a memory hint like MADV_[COLD|PAGEEOUT] to other process. Android's > ActivityManagerService is one of them. > > It's similar in spirit to madvise(MADV_WONTNEED), but the information > required to make the reclaim decision is not known to the app. Instead, > it is known to the centralized userspace daemon(ActivityManagerService), > and that daemon must be able to initiate reclaim on its own without > any app involvement. > > To solve the issue, this patch introduces new syscall process_madvise(2). > It could give a hint to the exeternal process of pidfd. > > int process_madvise(int pidfd, void *addr, size_t length, int advise, > unsigned long cookie, unsigned long flag); > > Since it could affect other process's address range, only privileged > process(CAP_SYS_PTRACE) or something else(e.g., being the same UID) > gives it the right to ptrace the process could use it successfully. > > The syscall has a cookie argument to privode atomicity(i.e., detect > target process's address space change since monitor process has parsed > the address range of target process so the operaion could fail in case > of happening race). Although there is no interface to get a cookie > at this moment, it could be useful to consider it as argument to avoid > introducing another new syscall in future. It could support *atomicity* > for disruptive hint(e.g., MADV_DONTNEED|FREE). > flag argument is reserved for future use if we need to extend the API. How about a compromise? Let's allow all madvise hints if the process is calling process_madvise *on itself* (which will be useful once we wire up the atomicity cookie) and restrict the cross-process case to the hints you've mentioned. This way, the restriction on madvise hints isn't tied to the specific API, but to the relationship between hinter and hintee.