From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754381AbdIZJOQ (ORCPT ); Tue, 26 Sep 2017 05:14:16 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:7021 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751548AbdIZJOM (ORCPT ); Tue, 26 Sep 2017 05:14:12 -0400 Message-ID: <59CA1A57.5000905@huawei.com> Date: Tue, 26 Sep 2017 17:13:59 +0800 From: Xishi Qiu User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:12.0) Gecko/20120428 Thunderbird/12.0.1 MIME-Version: 1.0 To: Michal Hocko CC: Joonsoo Kim , Vlastimil Babka , Mel Gorman , Linux MM , LKML , zhong jiang , yeyunfeng , , "Zhoukang (A)" Subject: Re: [RFC] a question about mlockall() and mprotect() References: <59CA0847.8000508@huawei.com> <20170926081716.xo375arjoyu5ytcb@dhcp22.suse.cz> <59CA125C.8000801@huawei.com> <20170926090255.jmocezs6s3lpd6p4@dhcp22.suse.cz> In-Reply-To: <20170926090255.jmocezs6s3lpd6p4@dhcp22.suse.cz> Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.177.25.179] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A090204.59CA1A61.0063,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0, ip=0.0.0.0, so=2014-11-16 11:51:01, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 680568639d747f2a0e3590340e04255b Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2017/9/26 17:02, Michal Hocko wrote: > On Tue 26-09-17 16:39:56, Xishi Qiu wrote: >> On 2017/9/26 16:17, Michal Hocko wrote: >> >>> On Tue 26-09-17 15:56:55, Xishi Qiu wrote: >>>> When we call mlockall(), we will add VM_LOCKED to the vma, >>>> if the vma prot is ---p, >>> >>> not sure what you mean here. apply_mlockall_flags will set the flag on >>> all vmas except for special mappings (mlock_fixup). This phase will >>> cause that memory reclaim will not free already mapped pages in those >>> vmas (see page_check_references and the lazy mlock pages move to >>> unevictable LRUs). >>> >>>> then mm_populate -> get_user_pages will not alloc memory. >>> >>> mm_populate all the vmas with pages. Well there are certainly some >>> constrains - e.g. memory cgroup hard limit might be hit and so the >>> faulting might fail. >>> >>>> I find it said "ignore errors" in mm_populate() >>>> static inline void mm_populate(unsigned long addr, unsigned long len) >>>> { >>>> /* Ignore errors */ >>>> (void) __mm_populate(addr, len, 1); >>>> } >>> >>> But we do not report the failure because any failure past >>> apply_mlockall_flags would be tricky to handle. We have already dropped >>> the mmap_sem lock so some other address space operations could have >>> interfered. >>> >>>> And later we call mprotect() to change the prot, then it is >>>> still not alloc memory for the mlocked vma. >>>> >>>> My question is that, shall we alloc memory if the prot changed, >>>> and who(kernel, glibc, user) should alloc the memory? >>> >>> I do not understand your question but if you are asking how to get pages >>> to map your vmas then touching that area will fault the memory in. >> >> Hi Michal, >> >> syscall mlockall() will first apply the VM_LOCKED to the vma, then >> call mm_populate() to map the vmas. >> >> mm_populate >> populate_vma_page_range >> __get_user_pages >> check_vma_flags >> And the above path maybe return -EFAULT in some case, right? >> >> If we call mprotect() to change the prot of vma, just let >> check_vma_flags() return 0, then we will get the mlocked pages >> in following page-fault, right? > > Any future page fault to the existing vma will result in the mlocked > page. That is what VM_LOCKED guarantess. > >> My question is that, shall we map the vmas immediately when >> the prot changed? If we should map it immediately, who(kernel, glibc, user) >> do this step? > > This is still very fuzzy. What are you actually trying to achieve? I don't expect page fault any more after mlock.