Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp2982498ybk; Tue, 12 May 2020 12:58:34 -0700 (PDT) X-Google-Smtp-Source: APiQypJyNinC+aTfycUmrOPwEaWdgZt1t4DlOHADQGfhJwOCmLeIZYRhHiWdCw2rzfB1m+NjQNtK X-Received: by 2002:aa7:c744:: with SMTP id c4mr14787073eds.241.1589313514229; Tue, 12 May 2020 12:58:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589313514; cv=none; d=google.com; s=arc-20160816; b=BhBjUxT21jIzdLeVbqZB7QA+MfeWmKsas+y131fNMvurIx8H6h9Mh/WUMo1WuBjQd9 qnNFIWvO8gHuGY/7woJRt1C73ulHBtK2+0O/WPodi/65RD7pL/cWxCslg2XPVEFL67JC hFBUezWLEMtLvy+sDJGP4cEWeIdt7gH6A2mWG8AUXiRrTOu/5Poh2BrgmQwHO3NgHsLr O2jFFL9edhQwVNG39FWQUHM1G+0c7m5Shd+VY4QQyht/Iqgd1oeeZKoG4t3tBjW+PlVM RqEVNmwNOlxt7DTQfbM2GRAxyduU1kMj3zG8UteB0R6jpCgq/ZN7HCX7QgbTK4HE79l0 x8gQ== 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=souGqEVdFUGfbVs6klo3kTV/o0WFTA0pV6SMGDZE5jU=; b=ADBPxoJxRQWSA4Ubg6LhNYTVeN5hS/kdk20Fb6o6OggcOe60EPGrscqDK/kL2s7DuY jhHBp9c2JsiK8lD8v7WttNQ+km63y/1G5TdYm1xT8Nyx6bqjgWGd9Ntjhm9B85HvsNA1 GDprNJznzdiq9xELvnopgeOzxTn9eBSKSvtm0kamAsAEpnbbDgt2rtSLlWCbEhhcYQhb 6Zf0iSx9IStfKvM4zSQ9S4Kysl+qOyIHWpxH0sS10RWEodxyromaEO1kVh24MrTg2tSX Gd0mYxMGJiMEbHHWr1Vbxd6e+DPwQ4hC5B5JS54YJ3Qe3d9ves1Dq2RpjdhGlFXq958G Tw4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="BGByk4t/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id dt12si5603734ejc.99.2020.05.12.12.58.08; Tue, 12 May 2020 12:58:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="BGByk4t/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1730889AbgELTzq (ORCPT + 99 others); Tue, 12 May 2020 15:55:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60676 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725950AbgELTzp (ORCPT ); Tue, 12 May 2020 15:55:45 -0400 Received: from mail-vs1-xe42.google.com (mail-vs1-xe42.google.com [IPv6:2607:f8b0:4864:20::e42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1073EC061A0C for ; Tue, 12 May 2020 12:55:44 -0700 (PDT) Received: by mail-vs1-xe42.google.com with SMTP id a5so8663976vsm.7 for ; Tue, 12 May 2020 12:55:44 -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=souGqEVdFUGfbVs6klo3kTV/o0WFTA0pV6SMGDZE5jU=; b=BGByk4t/lgEtRVy7AtXqVevMTDz90sCHvuLDrt76134g9D/XItf0Ktm7vUPpyEWdwi 64DApzPuvJouI1yo+2vRRdSKpZdFDmGG2oTRKHPbFbZyBiJLkDrFaj/fzoyYXcNETbmG q3eEQXEDH2DKbwb5Xffuev5oBuFRf934QYOjhcke0Mi5oyne/vHEpY5Ks7qT0Lg7zcMT b0e1tttnIX3fK3KgNQ9DFs3S1FB2Gkehy1pqFjtJ6ekv0TzPSS2WGT6Xx+vIUb7lXKH0 Qo4rs067MNBl/CbM4MzosrXxY4CrZAn/jO3iycnbI4WFbyEYQnBQnaZ389icQNz0QWt5 Z38A== 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=souGqEVdFUGfbVs6klo3kTV/o0WFTA0pV6SMGDZE5jU=; b=Jyux/WacjfOzFuFxWkgiymJl1ZFjDCyQABVwq5P/4gZUxbd2WNWYyKred2D1VyQxJm 8aH5cOff0alWWDzFSW0wEeH4qDwqGMUSdNNImatCwujnPv+ErPU23vHHjDa4l/kSd226 lHosGwySUgyq4YaEXxWUCtO4d2F51IHEWakjunl3mFdMFf3SFkCrVDJeGPp3gWNnbKXi yMD/VymBBLaNf7d6nJ0GyKF0i6NtQHbqCoeuem3wy1fInkNsOjm8ueiFNkOATyYsubiH SujWXdh0bkDLCE2nocJxSnw8qWRDC04GeH8k6xIkbqf6WmdfBvsAs0l6bPrGT4/bfiuV FLNg== X-Gm-Message-State: AGi0PuYejQbKfzNW12qr49bVpYRILg+CzO8WXFzvT4t6A8k20eiymlyU PnFJgZ9fStQGD/CRIr5lUDDBL4ddTL6TRZMsoJD6Kw== X-Received: by 2002:a67:dd98:: with SMTP id i24mr18420597vsk.239.1589313342705; Tue, 12 May 2020 12:55:42 -0700 (PDT) MIME-Version: 1.0 References: <20200302193630.68771-1-minchan@kernel.org> <20200302193630.68771-6-minchan@kernel.org> <14089609-5fb1-b082-716f-c2e129d27c48@suse.cz> <20200311004251.GB87930@google.com> <20200508183653.GB125527@google.com> <20200508160415.65ff359a9e312c613336587b@linux-foundation.org> <20200509124817.xmrvsrq3mla6b76k@wittgenstein> <20200509231441.GC61301@google.com> In-Reply-To: <20200509231441.GC61301@google.com> From: Suren Baghdasaryan Date: Tue, 12 May 2020 12:55:30 -0700 Message-ID: Subject: Re: [PATCH v7 5/7] mm: support both pid and pidfd for process_madvise To: Minchan Kim Cc: Christian Brauner , Andrew Morton , Vlastimil Babka , LKML , linux-mm , linux-api@vger.kernel.org, Oleksandr Natalenko , Tim Murray , Daniel Colascione , Sandeep Patil , Sonny Rao , Brian Geffon , Michal Hocko , Johannes Weiner , Shakeel Butt , John Dias , Joel Fernandes , Jann Horn , alexander.h.duyck@linux.intel.com, sj38.park@gmail.com, Christian Brauner , Kirill Tkhai 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 Sat, May 9, 2020 at 4:14 PM Minchan Kim wrote: > > Hi Christian, > > On Sat, May 09, 2020 at 02:48:17PM +0200, Christian Brauner wrote: > > On Fri, May 08, 2020 at 04:04:15PM -0700, Andrew Morton wrote: > > > On Fri, 8 May 2020 11:36:53 -0700 Minchan Kim wrote: > > > > > > > > > > > ... > > > > > > > > Per Vlastimil's request, I changed "which and advise" with "idtype and > > > > advice" in function prototype of description. > > > > Could you replace the part in the description? Code is never changed. > > > > > > > > > > Done, but... > > > > > > > > > > > ... > > > > > > > > There is a demand[1] to support pid as well pidfd for process_madvise to > > > > reduce unnecessary syscall to get pidfd if the user has control of the > > > > target process(ie, they could guarantee the process is not gone or pid is > > > > not reused). > > > > > > > > This patch aims for supporting both options like waitid(2). So, the > > > > syscall is currently, > > > > > > > > int process_madvise(idtype_t idtype, id_t id, void *addr, > > > > size_t length, int advice, unsigned long flags); > > > > > > > > @which is actually idtype_t for userspace libray and currently, it > > > > supports P_PID and P_PIDFD. > > > > > > What does "@which is actually idtype_t for userspace libray" mean? Can > > > you clarify and expand? > > > > If I may clarify, the only case where we've supported both pidfd and pid > > in the same system call is waitid() to avoid adding a dedicated system > > call for waiting and because waitid() already had this (imho insane) > > argument type switching. The idtype_t thing comes from waitid() and is > > located int sys/wait.h and is defined as > > > > "The type idtype_t is defined as an enumeration type whose possible > > values include at least the following: > > > > P_ALL > > P_PID > > P_PGID > > " > > > > int waitid(idtype_t idtype, id_t id, siginfo_t *infop, int options); > > If idtype is P_PID, waitid() shall wait for the child with a process ID equal to (pid_t)id. > > If idtype is P_PGID, waitid() shall wait for any child with a process group ID equal to (pid_t)id. > > If idtype is P_ALL, waitid() shall wait for any children and id is ignored. > > > > I'm personally not a fan of this idtype_t thing and think this should > > just have been > > > > int pidfd_madvise(int pidfd, void *addr, > > > > size_t length, int advice, unsigned long flags); > > and call it a day. > > That was the argument at that time, Daniel and I didn't want to have > pid along with pidfd even though Kirill strongly wanted to have it. > However you said " Overall, I don't particularly care how or if you > integrate pidfd here." at that time. > > https://lore.kernel.org/linux-mm/20200113104256.5ujbplyec2sk4onn@wittgenstein/ > > I asked a question to Kirll at that time. > > " > > Sounds like that you want to support both options for every upcoming API > > which deals with pid. I'm not sure how it's critical for process_madvise > > API this case. In general, we sacrifice some performance for the nicer one > > and later, once it's reported as hurdle for some workload, we could fix it > > via introducing new flag. What I don't like at this moment is to make > > syscall complicated with potential scenarios without real workload. > > Yes, I suggest allowing both options for every new process api > " > https://lore.kernel.org/linux-mm/9d849087-3359-c4ab-fbec-859e8186c509@virtuozzo.com/ > > You didn't give the opinion at that time, either(I expected you will > make some voice then). What I could do to proceed work was separate it > as different patch like this one to get more attention in future. > And now it works. > > Let me clarify my side: I still don't like to introduce pid for new API > since we have pidfd. Since you just brought this issue again, I want to > hear *opinions* from others, again. IIRC Kirill's main complaint was that if we support only pidfds and userspace has a pid of the process then it would have to convert that pid into pidfd before calling process_madvise, which involves additional syscall(s). The overhead would be more tangible if there are multiple processes needing to be madvised. I'm not sure how often such a need arises to madvise multiple processes in a bulk like that and how critical is the overhead of obtaining pidfd. With pid reuse possibility pid-based API will still have the issue of possibly sending the request to a wrong process, so this pidfd obtaining overhead arguably makes the usage more robust and therefore is not a pure loss. I don't have a real strong opinion against supporting pid in this syscall but I think API maintainers should decide going forward whether new APIs should support pid along with pidfd or switch to pidfd only. Thanks! > > > > > Also, if I may ask, why is the flag argument "unsigned long"? > > That's pretty unorthodox. The expectation is that flag arguments are > > not word-size dependent and should usually use "unsigned int". All new > > system calls follow this pattern too. > > Nothing special in this flag: Let me change it as "unsigned int". > I will send the change once we have an agreement on "pidfd" argument. > > Thanks for the review, Christian!