Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp4330588imm; Mon, 11 Jun 2018 10:28:14 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKZHdm7tNqM7DiDtcd16O/AwGKp5FPq3ySVI+cc/pD5hpKY40JMvgDcGw9fye89o1Rs2mZM X-Received: by 2002:a62:c16:: with SMTP id u22-v6mr66812pfi.177.1528738093894; Mon, 11 Jun 2018 10:28:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528738093; cv=none; d=google.com; s=arc-20160816; b=we8v3/yvNiYwTTMirlreClQu2HrSq49yeMj3r//x7Bv3/87ZIiDUWxXsU+WUz4xXzc IBG1vgR/4mUSzQTWpBvv/IURKhLGEUVAaFeW4IPczw5bB3RbRuWG/6wgO3NU7Db7m14G 5q0vHkz6YlnIs0PxO6W4POKEMKr1GFPgkBHqyfWpL8/hwWHcgtcUi6/MkqYAv9PuWsFv rJCD0Jnw92L7G2BFFnpmyaDd5rKl4tuglbXnRHbVDiz+ADPAx73iB6k60fouDZ4l0jAd TBKybfje/fOvcnM6y8dxEqfrCWcwDKZSGrFiQ9GknwjoqyY6ZM2NfBUr3BxCv6vmkpds BaWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature :arc-authentication-results; bh=AmJHJ1ujGBOT2mGYqN2O2LNXDRTTfyilRK8kKBzwvG8=; b=kkcUZTwQBoZpiyM0tw1W1iRqxxut3yx+U/FDl0SZsBaG8Iluw7NeGL1X93S4gbUfzC b3ZRjAt6j3P8PtaPv7aUIXaMNijZm1BTbRSfyaBTobM+Hm+6sMWOVmOPJYNKwFj9M83v MD5x7A5QVE5g35Dp/FhTUZ8Tl5GbNYfIG/W/KWowVqxcSvOr+zihtDGDfD5ItLp7VqwE QQxQ6bTQmU0tOT0ic3lslQ4Kbsvf+ePSmqMv+pStJaQQcQr1nYkt98UqZGJOSYSkXnF/ JpQX/dN6cBRGz1mcNHi0hlAuQ18EHm6yngqcyHGtjRy4NQZ0MLgbv0+2qzm6Mj1SL/3M c2Fw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@akamai.com header.s=jan2016.eng header.b=gaLubl+R; 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=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=akamai.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s26-v6si24975516pgo.298.2018.06.11.10.27.29; Mon, 11 Jun 2018 10:28:13 -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; dkim=pass header.i=@akamai.com header.s=jan2016.eng header.b=gaLubl+R; 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=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=akamai.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933452AbeFKQYQ (ORCPT + 99 others); Mon, 11 Jun 2018 12:24:16 -0400 Received: from mx0b-00190b01.pphosted.com ([67.231.157.127]:54648 "EHLO mx0b-00190b01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933136AbeFKQYO (ORCPT ); Mon, 11 Jun 2018 12:24:14 -0400 Received: from pps.filterd (m0050102.ppops.net [127.0.0.1]) by m0050102.ppops.net-00190b01. (8.16.0.22/8.16.0.22) with SMTP id w5BGGqHZ030820; Mon, 11 Jun 2018 17:24:01 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=akamai.com; h=subject : to : cc : references : from : message-id : date : mime-version : in-reply-to : content-type : content-transfer-encoding; s=jan2016.eng; bh=AmJHJ1ujGBOT2mGYqN2O2LNXDRTTfyilRK8kKBzwvG8=; b=gaLubl+RxtfAQqPYsBloULcFFm6RZKqTqQ8VplKJhiKIeudcw033Bu5o2Idf9a9d4cH6 LXhvFTrE70731tbj694cJOcidgUXMl6uQKZW+y1p1FBDR1AOfqeJ9WYHshJSjgk3OLYb mPiRROQHqgVqEKpn4HtZBUKSv81Cqfs+VfcR25PQuVt6cNhB6wcBN05jh1VBSFHvITiZ +IiyVEn40IwXM/996DyI9ulaAuJkkYbJQo3Ctd9TYMyzB/X5mCN+RiEZQlNX+GizKrBF /VKtUyaczREs4wfZXmhvQxTPG629dWjKQJ/H96E6WbPUK0mAwqN0YS14csLtZ83A2hiN +w== Received: from prod-mail-ppoint4 (a96-6-114-87.deploy.static.akamaitechnologies.com [96.6.114.87] (may be forged)) by m0050102.ppops.net-00190b01. with ESMTP id 2jg3ycy7hf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 11 Jun 2018 17:24:00 +0100 Received: from pps.filterd (prod-mail-ppoint4.akamai.com [127.0.0.1]) by prod-mail-ppoint4.akamai.com (8.16.0.21/8.16.0.21) with SMTP id w5BGGX88005934; Mon, 11 Jun 2018 12:23:59 -0400 Received: from prod-mail-relay14.akamai.com ([172.27.17.39]) by prod-mail-ppoint4.akamai.com with ESMTP id 2jga7ve721-1; Mon, 11 Jun 2018 12:23:59 -0400 Received: from [172.28.13.175] (bos-lpjec.kendall.corp.akamai.com [172.28.13.175]) by prod-mail-relay14.akamai.com (Postfix) with ESMTP id D53EB811D9; Mon, 11 Jun 2018 16:23:58 +0000 (GMT) Subject: Re: [PATCH] mm/madvise: allow MADV_DONTNEED to free memory that is MLOCK_ONFAULT To: Michal Hocko 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 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> From: Jason Baron Message-ID: <775adf2d-140c-1460-857f-2de7b24bafe7@akamai.com> Date: Mon, 11 Jun 2018 12:23:58 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <20180611150330.GQ13364@dhcp22.suse.cz> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-06-11_07:,, signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=2 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1805220000 definitions=main-1806110187 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-06-11_07:,, signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=2 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1805220000 definitions=main-1806110187 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 06/11/2018 11:03 AM, Michal Hocko wrote: > 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. > Indeed. I just tried allowing MADV_DONTNEED against regular mlock() and in my brief testing it seemed to work as expected against both anonymous and file back pages. I am certainly not against allowing it for regular mlock() as well, if you think that makes it more consistent. >> 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? > 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? Thanks, -Jason