From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id ABE20C63777 for ; Tue, 24 Nov 2020 05:45:41 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 12BA32080A for ; Tue, 24 Nov 2020 05:45:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="pHVSEjjg" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 12BA32080A Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 597426B005D; Tue, 24 Nov 2020 00:45:40 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 51FE76B0070; Tue, 24 Nov 2020 00:45:40 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3E6C66B0071; Tue, 24 Nov 2020 00:45:40 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0031.hostedemail.com [216.40.44.31]) by kanga.kvack.org (Postfix) with ESMTP id 0DF576B005D for ; Tue, 24 Nov 2020 00:45:40 -0500 (EST) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id AF5E98249980 for ; Tue, 24 Nov 2020 05:45:39 +0000 (UTC) X-FDA: 77518224798.16.mouth10_35015782736b Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin16.hostedemail.com (Postfix) with ESMTP id 903B9100E690C for ; Tue, 24 Nov 2020 05:45:39 +0000 (UTC) X-HE-Tag: mouth10_35015782736b X-Filterd-Recvd-Size: 8132 Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by imf46.hostedemail.com (Postfix) with ESMTP for ; Tue, 24 Nov 2020 05:45:38 +0000 (UTC) Received: by mail-wr1-f67.google.com with SMTP id z7so5197985wrn.3 for ; Mon, 23 Nov 2020 21:45:38 -0800 (PST) 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=rFs/RObUOd+On4EQgVH9l81JcWrm5Ewwy7I/EnEZpRc=; b=pHVSEjjgKCPj8u1WeC6H1FiX781gs+9vslN4mIY0bI7J2Sx2Op0HBNitySKWudQiEn gPYVmik42GHdvJhKRFEj3WNt+1P2H0t1Npsu7BXIhBR1g6E33S58c+i6bGRW0aSHDZuq HhNaWJDjo7QaJCo+nGCwBZC9luRQ/42c+LbqGBiUWrtqwZ/+29p5nVf1M9s0ZqJX0eXi 4RHYmMBLesird3OdOSDKLe2K6ElGTmhooNWSrFcJvOQTHONKSQ0Q24Fcsz49fkhnANlB ted1e00qJnyYjb9Tsq7X3WaXKTpmFDMkxJA8JjW5s4VDdEEqPU8X9jDM3mlbFQwpy+H0 d+LA== 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=rFs/RObUOd+On4EQgVH9l81JcWrm5Ewwy7I/EnEZpRc=; b=e+qiIQcfiWUjwB0ztt61K3YL9Cm9zD6IBGnDktrBKqN+iCMXPKmVjvecZro/fCs+mQ 2TkHGgMAjX3Nn0hWeAiK0M4uEpP24qq6Sz9dRPMVDlxmaF6Zjoyi1iB/L3GsONe7A7N9 ap8A9T5VXrMiMUIwWp4bovhdFpY/a0G7rmfxJC58+zUGnPlFxa0xOftehkP8rnqaRbWr pkYS5jHLtdfRO6RJI5R/jKrxnJr2EQUJ88xBNk0JMswM0XBIldOSifXhNTIM6cOtPAgQ Mbi73gqmLIeF7OuhBBpww+68Cd67zfncKN3ZqNNLBL+ILIJ793c19KN4FPZCl9brgNKJ k7cQ== X-Gm-Message-State: AOAM530LzgDOxcfOYPmcnLb2wk4b/YI8o1eLOolqywSVU8QKcsDjaAeK /WTY9vaUcVi6tpMBNfujL0AdkZZLKdQy+dFxEbDl8w== X-Google-Smtp-Source: ABdhPJxODaedfDJcEn/GE5PN1Gls3pL9/CyBaXh1Z/70lssTc6UFzgcH6nyYo0mbPkXC8ZbpEnvWxvwAfV18Muv+sz8= X-Received: by 2002:adf:fd47:: with SMTP id h7mr3271659wrs.106.1606196737273; Mon, 23 Nov 2020 21:45:37 -0800 (PST) MIME-Version: 1.0 References: <20201113173448.1863419-1-surenb@google.com> <20201113155539.64e0af5b60ad3145b018ab0d@linux-foundation.org> <20201113170032.7aa56ea273c900f97e6ccbdc@linux-foundation.org> <20201113171810.bebf66608b145cced85bf54c@linux-foundation.org> <20201113181632.6d98489465430a987c96568d@linux-foundation.org> <20201118154334.GT12284@dhcp22.suse.cz> <20201118193233.GV12284@dhcp22.suse.cz> In-Reply-To: From: Suren Baghdasaryan Date: Mon, 23 Nov 2020 21:45:26 -0800 Message-ID: Subject: Re: [PATCH 1/1] RFC: add pidfd_send_signal flag to reclaim mm while killing a process To: Michal Hocko Cc: Andrew Morton , David Rientjes , Matthew Wilcox , Johannes Weiner , Roman Gushchin , Rik van Riel , Christian Brauner , Oleg Nesterov , Tim Murray , linux-api@vger.kernel.org, linux-mm , LKML , kernel-team , Minchan Kim Content-Type: text/plain; charset="UTF-8" X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Wed, Nov 18, 2020 at 4:13 PM Suren Baghdasaryan wrote: > > On Wed, Nov 18, 2020 at 11:55 AM Suren Baghdasaryan wrote: > > > > On Wed, Nov 18, 2020 at 11:51 AM Suren Baghdasaryan wrote: > > > > > > On Wed, Nov 18, 2020 at 11:32 AM Michal Hocko wrote: > > > > > > > > On Wed 18-11-20 11:22:21, Suren Baghdasaryan wrote: > > > > > On Wed, Nov 18, 2020 at 11:10 AM Michal Hocko wrote: > > > > > > > > > > > > On Fri 13-11-20 18:16:32, Andrew Morton wrote: > > > > > > [...] > > > > > > > It's all sounding a bit painful (but not *too* painful). But to > > > > > > > reiterate, I do think that adding the ability for a process to shoot > > > > > > > down a large amount of another process's memory is a lot more generally > > > > > > > useful than tying it to SIGKILL, agree? > > I was looking into how to work around the limitation of MAX_RW_COUNT > and the conceptual issue there is the "struct iovec" which has its > iov_len as size_t that lacks capacity for expressing ranges like > "entire process memory". I would like to check your reaction to the > following idea which can be implemented without painful surgeries to > the import_iovec and its friends. > > process_madvise(pidfd, iovec = [ { range_start_addr, 0 }, { > range_end_addr, 0 } ], vlen = 2, behavior=MADV_xxx, flags = > PMADV_FLAG_RANGE) > > So, to represent a range we pass a new PMADV_FLAG_RANGE flag and > construct a 2-element vector to express range start and range end > using iovec.iov_base members. iov_len member of the iovec elements is > ignored in this mode. I know it sounds hacky but I think it's the > simplest way if we want the ability to express an arbitrarily large > range. > Another option is to do what Andrew described as "madvise((void *)0, > (void *)-1, MADV_PAGEOUT)" which means this mode works only with the > entire mm of the process. > WDYT? > To follow up on this discussion, I posted a patchset to implement process_madvise(MADV_DONTNEED) supporting the entire mm range at https://lkml.org/lkml/2020/11/24/21. > > > > > > > > > > > > I am not sure TBH. Is there any reasonable usecase where uncoordinated > > > > > > memory tear down is OK and a target process which is able to see the > > > > > > unmapped memory? > > > > > > > > > > I think uncoordinated memory tear down is a special case which makes > > > > > sense only when the target process is being killed (and we can enforce > > > > > that by allowing MADV_DONTNEED to be used only if the target process > > > > > has pending SIGKILL). > > > > > > > > That would be safe but then I am wondering whether it makes sense to > > > > implement as a madvise call. It is quite strange to expect somebody call > > > > a syscall on a killed process. But this is more a detail. I am not a > > > > great fan of a more generic MADV_DONTNEED on a remote process. This is > > > > just too dangerous IMHO. > > > > > > Agree 100% > > > > I assumed here that by "a more generic MADV_DONTNEED on a remote > > process" you meant "process_madvise(MADV_DONTNEED) applied to a > > process that is not being killed". Re-reading your comment I realized > > that you might have meant "process_madvice() with generic support to > > large memory areas". I hope I understood you correctly. > > > > > > > > > > > > > > However, the ability to apply other flavors of > > > > > process_madvise() to large memory areas spanning multiple VMAs can be > > > > > useful in more cases. > > > > > > > > Yes I do agree with that. The error reporting would be more tricky but > > > > I am not really sure that the exact reporting is really necessary for > > > > advice like interface. > > > > > > Andrew's suggestion for this special mode to change return semantics > > > to the usual "0 or error code" seems to me like the most reasonable > > > way to deal with the return value limitation. > > > > > > > > > > > > For example in Android we will use > > > > > process_madvise(MADV_PAGEOUT) to "shrink" an inactive background > > > > > process. > > > > > > > > That makes sense to me. > > > > -- > > > > Michal Hocko > > > > SUSE Labs