Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp4171094imm; Mon, 11 Jun 2018 08:05:25 -0700 (PDT) X-Google-Smtp-Source: ADUXVKItKUDn6qKT+akNYzCrlmFGsUIJJsB6oTMR4qY28mbtDOcJ9Kul0ewSfb7gryHNPV9keGXd X-Received: by 2002:aa7:8254:: with SMTP id e20-v6mr18131174pfn.140.1528729525652; Mon, 11 Jun 2018 08:05:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528729525; cv=none; d=google.com; s=arc-20160816; b=gglMBUND2KTZjKM511EBrlXDdqyASWs2IftGFeGHlLGJs/iN+gGNbIc2oUfSQOyMzg gbvqw1jPbv5AdDvdfGpEpQTKnkxVImqqMfWqKTc5CjizWWUo1+HpDlWtzDKw3V1JEWSa rPAPor1HN48LQuh5fKA3QvpFo2EV/ga3PBPHSqdkjCx19fd9wgQlXnwngdu/wgccXjdM oitNKarjrVTA5rloZMEtDpM7aMznyephvbU20aMEM7pFd7eQNvLfqzXp1z5H6n9eWhl+ yhNf660p8C7Z6xE2hzkIzPhO+OSMiFdou7RIWBsRL+j71Fzw0s35vUqWDG94FXhp16m3 vFDA== 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=XKL8Z4D44Sr7l+Fu3hB5en/n/Q8AtJiXHYADjHC0ILI=; b=NSuNu2XzIuK8iDTZWzoNGlkruHFDxRxgMafdXHsk8Rv6LEnm/mt6EbW2HCUuIQfdNX KepEfa1NDKMBpYhnVtHYH5xmvakujlzTXGMsNPnD86lwSilOMvYUctRdnl2NNcHMOZkZ FAhNltL6fbtRzPGD1MdmDiVzOsix424pb6SjerpEdvNlfeKCLSuPxFVCuW3j+5SCPz1r fkiLR4W1CHTIcfYBv8xZuKacVrYQSsN7WzpeWqFZw3ma/xxD59Id+5uikOt0y21nYRM6 wWCc6pYZ1I6hDmTbrZGlPEH/dNdedSQzijqNlZOHwOQ1FBten/iypwsdBBMcffC8l9SJ HZxg== 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 s9-v6si16183641pfm.257.2018.06.11.08.05.10; Mon, 11 Jun 2018 08:05:25 -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 S1754060AbeFKPDe (ORCPT + 99 others); Mon, 11 Jun 2018 11:03:34 -0400 Received: from mx2.suse.de ([195.135.220.15]:39601 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754019AbeFKPDd (ORCPT ); Mon, 11 Jun 2018 11:03:33 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext-too.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id B376BAE92; Mon, 11 Jun 2018 15:03:31 +0000 (UTC) Date: Mon, 11 Jun 2018 17:03:30 +0200 From: Michal Hocko To: Jason Baron Cc: akpm@linux-foundation.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Vlastimil Babka , 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: <20180611150330.GQ13364@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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4c4de46d-c55a-99a8-469f-e1e634fb8525@akamai.com> 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 Mon 11-06-18 10:51:44, Jason Baron wrote: > On 06/11/2018 03:20 AM, Michal Hocko wrote: > > [CCing linux-api - please make sure to CC this mailing list anytime you > > are touching user visible apis] > > > > On Fri 08-06-18 14:56:52, Jason Baron wrote: > >> In order to free memory that is marked MLOCK_ONFAULT, the memory region > >> needs to be first unlocked, before calling MADV_DONTNEED. And if the region > >> is to be reused as MLOCK_ONFAULT, we require another call to mlock2() with > >> the MLOCK_ONFAULT flag. > >> > >> Let's simplify freeing memory that is set MLOCK_ONFAULT, by allowing > >> MADV_DONTNEED to work directly for memory that is set MLOCK_ONFAULT. > > > > I do not understand the point here. How is MLOCK_ONFAULT any different > > from the regular mlock here? If you want to free mlocked memory then > > fine but the behavior should be consistent. MLOCK_ONFAULT is just a way > > to say that we do not want to pre-populate the mlocked area and do that > > lazily on the page fault time. madvise should make any difference here. > > > > The difference for me is after the page has been freed, MLOCK_ONFAULT > will re-populate the range if its accessed again. Whereas with regular > mlock I don't think it will because its normally done at mlock() or > mmap() time. The vma would still be locked so we would effectively turn it into ONFAULT IIRC. > In any case, the state of a region being locked with > regular mlock and pages not present does not currently exist, whereas it > does for MLOCK_ONFAULT, so it seems more natural to do it only for > MLOCK_ONFAULT. Finally, the use-case we had for this, didn't need > regular mlock(). 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? -- Michal Hocko SUSE Labs