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=-3.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 630F2C43467 for ; Wed, 14 Oct 2020 18:39:51 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B55552222C for ; Wed, 14 Oct 2020 18:39:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ljjUBHvD" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B55552222C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id D37D16B005C; Wed, 14 Oct 2020 14:39:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CE9D16B005D; Wed, 14 Oct 2020 14:39:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BD69B6B0062; Wed, 14 Oct 2020 14:39:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0193.hostedemail.com [216.40.44.193]) by kanga.kvack.org (Postfix) with ESMTP id 8921D6B005C for ; Wed, 14 Oct 2020 14:39:49 -0400 (EDT) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 2A67E1EE6 for ; Wed, 14 Oct 2020 18:39:49 +0000 (UTC) X-FDA: 77371394898.23.rat44_041471f2720e Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin23.hostedemail.com (Postfix) with ESMTP id 08DAA37609 for ; Wed, 14 Oct 2020 18:39:49 +0000 (UTC) X-HE-Tag: rat44_041471f2720e X-Filterd-Recvd-Size: 8041 Received: from mail-pj1-f65.google.com (mail-pj1-f65.google.com [209.85.216.65]) by imf21.hostedemail.com (Postfix) with ESMTP for ; Wed, 14 Oct 2020 18:39:48 +0000 (UTC) Received: by mail-pj1-f65.google.com with SMTP id g16so220378pjv.3 for ; Wed, 14 Oct 2020 11:39:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=NH5urOcy6c6c7U4nE2ctki4Ov521XyxV+9elVLTe53k=; b=ljjUBHvD9onxp1gRCJrEBhb0tdHVp8S71mYcEA5XYCz4Rhycv80d2h0TNWdFnZIIoL fTq+20VgUsTeou8V8x/eRwjfy1Z4ZgUEti0xXp+hqBDKTuIwfJvXf1ilf6gpPrTX+/5z bxnNYkQEr3EmDy7DbGRsK2+h/bf2blPJSsaIRE6CXM83dqKfkEftHUtyb63cZ5gd+BiB TMGaeDgrKgSNkVtzuh06CPpV2IdsQy3mZWKFj+vQPQ0EVkbi2htUZ2cpRfbQAVKgr7pA cjyLOY2ie7XcjfJFC+baHNO/TCCXnrCpLeDGRvcFW9ty4iOO1AfLotqQDHRnupTYTOtU QJ8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to; bh=NH5urOcy6c6c7U4nE2ctki4Ov521XyxV+9elVLTe53k=; b=AVYKZXBGwJ4L6nh4wmKye8dQ6L/JdOWWzy+c7f30P9hGi2w+hyrVqmTLlP4xSi5YB2 MXXPReSZzvykcsC58FcptHVQClvo/2fJk99LVZlGxBkQ/hpAjMJauFjGomhFRvKicgVR eJsjG8gCzaaLM0axE8XMPJG/eyR6KWW/FacgMg+9CECDAwdrZ1tpkuYv1TgNKCbR+69P aLAij5lJ8IFhhflklHThQiM3BhbTEF9AIShCWTWFLuYSYFFjR+KI3p43CGQideM2vc5L x7NKGabD0ugVobPTmglnPcIyvlw2MO/IMlOexeXxGdxCCdEA0/oMsoXLAr8s/1Npiwzc tA1Q== X-Gm-Message-State: AOAM531O+Xv9WeZf7JEAkmwK8cHWoObuQDtf31BkW6b3ILNpaZXaCyZi CPGGo3x+ylZUCRUxrdQEUsc= X-Google-Smtp-Source: ABdhPJwJRebcnF/K6rXv4Pvhn7mjLRUX1W19rCgciAw9z+AVgh4JoWoSHdM40MH8mmAfl3iv8UEsPA== X-Received: by 2002:a17:90a:474c:: with SMTP id y12mr502073pjg.150.1602700787366; Wed, 14 Oct 2020 11:39:47 -0700 (PDT) Received: from google.com ([2620:15c:211:1:7220:84ff:fe09:5e58]) by smtp.gmail.com with ESMTPSA id q24sm371251pfn.72.2020.10.14.11.39.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Oct 2020 11:39:46 -0700 (PDT) Date: Wed, 14 Oct 2020 11:39:43 -0700 From: minchan@kernel.org To: Suren Baghdasaryan Cc: Michal Hocko , linux-api@vger.kernel.org, linux-mm , Andrew Morton , David Rientjes , Matthew Wilcox , Johannes Weiner , Roman Gushchin , Rik van Riel , Christian Brauner , Oleg Nesterov , Tim Murray , kernel-team , LKML , Mel Gorman Subject: Re: [RFC]: userspace memory reaping Message-ID: <20201014183943.GA1489464@google.com> References: <20201014120937.GC4440@dhcp22.suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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, Oct 14, 2020 at 09:57:20AM -0700, Suren Baghdasaryan wrote: > On Wed, Oct 14, 2020 at 5:09 AM Michal Hocko wrote: > > > > [Sorry for a late reply] > > > > On Mon 14-09-20 17:45:44, Suren Baghdasaryan wrote: > > > + linux-kernel@vger.kernel.org > > > > > > On Mon, Sep 14, 2020 at 5:43 PM Suren Baghdasaryan wrote: > > > > > > > > Last year I sent an RFC about using oom-reaper while killing a > > > > process: https://patchwork.kernel.org/cover/10894999. During LSFMM2019 > > > > discussion https://lwn.net/Articles/787217 a couple of alternative > > > > options were discussed with the most promising one (outlined in the > > > > last paragraph of https://lwn.net/Articles/787217) suggesting to use a > > > > remote version of madvise(MADV_DONTNEED) operation to force memory > > > > reclaim of a killed process. With process_madvise() making its way > > > > through reviews (https://patchwork.kernel.org/patch/11747133/), I > > > > would like to revive this discussion and get feedback on several > > > > possible options, their pros and cons. > > > > Thanks for reviving this! > > Thanks for your feedback! > > > > > > > The need is similar to why oom-reaper was introduced - when a process > > > > is being killed to free memory we want to make sure memory is freed > > > > even if the victim is in uninterruptible sleep or is busy and reaction > > > > to SIGKILL is delayed by an unpredictable amount of time. I > > > > experimented with enabling process_madvise(MADV_DONTNEED) operation > > > > and using it to force memory reclaim of the target process after > > > > sending SIGKILL. Unfortunately this approach requires the caller to > > > > read proc/pid/maps to extract the list of VMAs to pass as an input to > > > > process_madvise(). > > > > Well I would argue that this is not really necessary. You can simply > > call process_madvise with the full address range and let the kernel > > operated only on ranges which are safe to tear down asynchronously. > > Sure that would require some changes to the existing code to not fail > > on those ranges if they contain incompatible vmas but that should be > > possible. If we are worried about backward compatibility then a > > dedicated flag could override. > > > > IIUC this is very similar to the last option I proposed. I think this > is doable if we treat it as a special case. process_madvise() return > value not being able to handle a large range would still be a problem. > Maybe we can return MAX_INT in those cases? Or, maybe we could just return 0 if the operation succeeds without any error. > > > [...] > > > > > > While the objective is to guarantee forward progress even when the > > > > victim cannot terminate, we still want this mechanism to be efficient > > > > because we perform these operations to relieve memory pressure before > > > > it affects user experience. > > > > > > > > Alternative options I would like your feedback are: > > > > 1. Introduce a dedicated process_madvise(MADV_DONTNEED_MM) > > > > specifically for this case to indicate that the whole mm can be freed. > > > > This shouldn't be any different from madvise on the full address range, > > right? > > > > Yep, just a matter of choosing the most appropriate API. I agree full range or just NULL passing to indicate entire address space would be better than introducing a new advise in that we could avoid MADV_PAGEOUT_MM, MADV_COLD_MM. > > > > > 2. A new syscall to efficiently obtain a vector of VMAs (start, > > > > length, flags) of the process instead of reading /proc/pid/maps. The > > > > size of the vector is still limited by UIO_MAXIOV (1024), so several > > > > calls might be needed to query larger number of VMAs, however it will > > > > still be an order of magnitude more efficient than reading > > > > /proc/pid/maps file in 4K or smaller chunks. > > > > While this might be interesting for other usecases - userspace memory > > management in general - I do not think it is directly related to this > > particular feature. > > > > True but such a syscall would be useful for other use cases, like > MADV_COLD/MADV_PAGEOUT that Minchan was working on. Maybe we can kill > more than one bird here? Minchan, any thought? Generally, it could be helpful but I don't see it as desperate at this moment.