Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp307183imm; Wed, 13 Jun 2018 00:16:39 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKYh2L7oQEQQIOcUfaFMFxcYUJe1fa5Jhv8eUBGFru0L5eDaKpMl1ZVDe+LPF0uhpotGR5p X-Received: by 2002:a65:4bcd:: with SMTP id p13-v6mr3115883pgr.114.1528874199442; Wed, 13 Jun 2018 00:16:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528874199; cv=none; d=google.com; s=arc-20160816; b=ghoJEJGBSHQl/9Bqwdy3dNrRFEzd9AC20SlQn0XzXleu9yvsnErsSBj13/uRQq03gd t+cMYTpZb5KVK3RXT7VZ5Rjo4HXr/+/qYY4HVNdtYlM91muHAGlrAFV6PAWFz07vHoSz RHi37P2YljFg2tgAXN0H0gCWqS2rGqsWX7QSHgRGVxFR21fxSxXp29ZLgIqeGbV+ZoxN cLEdAMkIpA9DRKGByqjpMGgl80cNiojGIZMzO2ORROknygQXcHrlYMtYWUHOsZsq3EWV Jdfs9rK2TqQ9Zo24cLpaTqvg/nfaAVX18m8Plz4kAv5pKPU8ONiBdUgQ6sqJXENV7DOW T4Dg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=vx1yI8/QRRJ6zopbmz42m412Pq4K9lm1kD1GRoxB1NY=; b=ho/5Eecaydux1eeRUeSlXpTey71q70B8gQmijJI2pcbyojR6QcXRyp/8RDtZnAO8fM kxr+OgAm5+OSzKIi+aVzEg4N6wt661Ed6V8bovoK0JbAwGOXoycnq8ggTmN/Hz9GQsPZ hQLyvo7+8pbYTPOgPuUoICnRGRLWf3oB64at6c9CV/zmABO2/VhBH8Vgiejjf5t9HPnM OIbjUvSLV3k+f65JSPerRgp4ITz6EyKX7+MhBF9S80lF6mBw3pKuDmik68l0iGBYo//O Awc0eP9IpttzrzuThfqJ9jkqm/94HvZRIny6IhXhVEkxY+UCFTUg6hgRTUuz1sGJyyz3 7E5A== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i16-v6si2129660pfi.234.2018.06.13.00.16.25; Wed, 13 Jun 2018 00:16:39 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934480AbeFMHP7 (ORCPT + 99 others); Wed, 13 Jun 2018 03:15:59 -0400 Received: from mx2.suse.de ([195.135.220.15]:37499 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933999AbeFMHP6 (ORCPT ); Wed, 13 Jun 2018 03:15:58 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext-too.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 843F5AD08; Wed, 13 Jun 2018 07:15:56 +0000 (UTC) Date: Wed, 13 Jun 2018 09:15:52 +0200 From: Michal Hocko To: Vlastimil Babka Cc: Jason Baron , akpm@linux-foundation.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Joonsoo Kim , Mel Gorman , "Kirill A. Shutemov" , linux-api@vger.kernel.org, emunson@mgebm.net Subject: Re: [PATCH] mm/madvise: allow MADV_DONTNEED to free memory that is MLOCK_ONFAULT Message-ID: <20180613071552.GD13364@dhcp22.suse.cz> References: <1528484212-7199-1-git-send-email-jbaron@akamai.com> <20180611072005.GC13364@dhcp22.suse.cz> <4c4de46d-c55a-99a8-469f-e1e634fb8525@akamai.com> <20180611150330.GQ13364@dhcp22.suse.cz> <775adf2d-140c-1460-857f-2de7b24bafe7@akamai.com> <20180612074646.GS13364@dhcp22.suse.cz> <5a9398f4-453c-5cb5-6bbc-f20c3affc96a@akamai.com> <0daccb7c-f642-c5ce-ca7a-3b3e69025a1e@suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <0daccb7c-f642-c5ce-ca7a-3b3e69025a1e@suse.cz> User-Agent: Mutt/1.9.5 (2018-04-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed 13-06-18 08:32:19, Vlastimil Babka wrote: > On 06/12/2018 04:11 PM, Jason Baron wrote: > > > > > > On 06/12/2018 03:46 AM, Michal Hocko wrote: > >> On Mon 11-06-18 12:23:58, Jason Baron wrote: > >>> On 06/11/2018 11:03 AM, Michal Hocko wrote: > >>>> So can we start discussing whether we want to allow MADV_DONTNEED on > >>>> mlocked areas and what downsides it might have? Sure it would turn the > >>>> strong mlock guarantee to have the whole vma resident but is this > >>>> acceptable for something that is an explicit request from the owner of > >>>> the memory? > >>>> > >>> > >>> If its being explicity requested by the owner it makes sense to me. I > >>> guess there could be a concern about this breaking some userspace that > >>> relied on MADV_DONTNEED not freeing locked memory? > >> > >> Yes, this is always the fear when changing user visible behavior. I can > >> imagine that a userspace allocator calling MADV_DONTNEED on free could > >> break. The same would apply to MLOCK_ONFAULT/MCL_ONFAULT though. We > >> have the new flag much shorter so the probability is smaller but the > >> problem is very same. So I _think_ we should treat both the same because > >> semantically they are indistinguishable from the MADV_DONTNEED POV. Both > >> remove faulted and mlocked pages. Mlock, once applied, should guarantee > >> no later major fault and MADV_DONTNEED breaks that obviously. > > I think more concerning than guaranteeing no later major fault is > possible data loss, e.g. replacing data with zero-filled pages. But MADV_DONTNEED is an explicit call for data loss. Or do I miss your point? > The madvise manpage is also quite specific about not allowing > MADV_DONTNEED and MADV_FREE for locked pages. Yeah, but that seems to describe the state of the art rather than explain why. > So I don't think we should risk changing that for all mlocked pages. > Maybe we can risk MCL_ONFAULT, since it's relatively new and has few users? That is what Jason wanted but I argued that the two are the same from MADV_DONTNEED point of view. I do not see how treating them differently would be less confusing or error prone. It's new so we can make it behave differently is certainly not an argument. > >> So the more I think about it the more I am worried about this but I am > >> more and more convinced that making ONFAULT special is just a wrong way > >> around this. > >> > > > > Ok, I share the concern that there is a chance that userspace is relying > > on MADV_DONTNEED not free'ing locked memory. In that case, what if we > > introduce a MADV_DONTNEED_FORCE, which does everything that > > MADV_DONTNEED currently does but in addition will also free mlock areas. > > That way there is no concern about breaking something. > > A new niche case flag? Sad :( > > BTW I didn't get why we should allow this for MADV_DONTNEED but not > MADV_FREE. Can you expand on that? Well, I wanted to bring this up as well. I guess this would require some more hacks to handle the reclaim path correctly because we do rely on VM_LOCK at many places for the lazy mlock pages culling. -- Michal Hocko SUSE Labs