From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail190.messagelabs.com (mail190.messagelabs.com [216.82.249.51]) by kanga.kvack.org (Postfix) with SMTP id 59C2D5F0001 for ; Fri, 17 Apr 2009 03:02:14 -0400 (EDT) Received: by rv-out-0708.google.com with SMTP id f25so613253rvb.26 for ; Fri, 17 Apr 2009 00:02:15 -0700 (PDT) Message-ID: <49E8292D.7050904@gmail.com> Date: Fri, 17 Apr 2009 15:01:01 +0800 From: Huang Shijie MIME-Version: 1.0 Subject: Does get_user_pages_fast lock the user pages in memory in my case? Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Sender: owner-linux-mm@kvack.org To: linux-mm@kvack.org List-ID: I'm writting a driver for a video card with the V4L2 interface . V4L2 interface supports the USER-POINTER method for the video frame handling. VLC player supports the USER-POINTER method,while MPALYER does not. In the USER-POINTER method, VLC will call the posix_memalign() to allocate 203 pages in certain PAL mode (that is 720*576*2) for a single frame. In my driver , I call the get_user_pages_fast() to obtain the pages array,and then call the vmap() to map the pages to VMALLOC space for the memcpy().The code shows below: .................... get_user_pages_fast(); ... f->data = vmap(); ....................... In comments, it said : " +/** + * get_user_pages_fast() - pin user pages in memory + * @start: starting user address + * @nr_pages: number of pages from start to pin + * @write: whether pages will be written to + * @pages: array that receives pointers to the pages pinned. + * Should be at least nr_pages long. " But after I digged the code of kswap and the get_user_pages(called by get_user_pages_fast), I did not find how the pages pinned in memory.I really need the pages pinned in memory. Assume page A is one of the pages obtained by get_user_pages_fast() during page-fault. [1] page A will on the LRU_ACTIVE_ANON list; the _count of page A increment by one; PTE for page A will be set ACCESSED. [2] kswapd will scan the lru list,and move page A from LRU_ACTIVE_ANON to LRU_INACTIVE_ANON. In the shrink_page_list(), there is nothing can stop page A been swapped out. I don't think the page_reference() can move page A back to LRU_ACTIVE_ANON.In my driver, I am not sure if the VLC can access the page A. Is this a bug? or I miss something? Thanks . -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail202.messagelabs.com (mail202.messagelabs.com [216.82.254.227]) by kanga.kvack.org (Postfix) with SMTP id 3A4585F0001 for ; Sat, 18 Apr 2009 02:18:46 -0400 (EDT) Received: from m5.gw.fujitsu.co.jp ([10.0.50.75]) by fgwmail7.fujitsu.co.jp (Fujitsu Gateway) with ESMTP id n3I6J040021636 for (envelope-from kosaki.motohiro@jp.fujitsu.com); Sat, 18 Apr 2009 15:19:01 +0900 Received: from smail (m5 [127.0.0.1]) by outgoing.m5.gw.fujitsu.co.jp (Postfix) with ESMTP id BF9F845DE53 for ; Sat, 18 Apr 2009 15:19:00 +0900 (JST) Received: from s5.gw.fujitsu.co.jp (s5.gw.fujitsu.co.jp [10.0.50.95]) by m5.gw.fujitsu.co.jp (Postfix) with ESMTP id 9A76B45DE4F for ; Sat, 18 Apr 2009 15:19:00 +0900 (JST) Received: from s5.gw.fujitsu.co.jp (localhost.localdomain [127.0.0.1]) by s5.gw.fujitsu.co.jp (Postfix) with ESMTP id 7C52C1DB803F for ; Sat, 18 Apr 2009 15:19:00 +0900 (JST) Received: from m106.s.css.fujitsu.com (m106.s.css.fujitsu.com [10.249.87.106]) by s5.gw.fujitsu.co.jp (Postfix) with ESMTP id 380B61DB8038 for ; Sat, 18 Apr 2009 15:19:00 +0900 (JST) From: KOSAKI Motohiro Subject: Re: Does get_user_pages_fast lock the user pages in memory in my case? In-Reply-To: <49E8292D.7050904@gmail.com> References: <49E8292D.7050904@gmail.com> Message-Id: <20090418151620.1258.A69D9226@jp.fujitsu.com> MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Date: Sat, 18 Apr 2009 15:18:59 +0900 (JST) Sender: owner-linux-mm@kvack.org To: Huang Shijie Cc: kosaki.motohiro@jp.fujitsu.com, linux-mm@kvack.org List-ID: Hi > " > +/** > + * get_user_pages_fast() - pin user pages in memory > + * @start: starting user address > + * @nr_pages: number of pages from start to pin > + * @write: whether pages will be written to > + * @pages: array that receives pointers to the pages pinned. > + * Should be at least nr_pages long. > " > > But after I digged the code of kswap and the get_user_pages(called by > get_user_pages_fast), > I did not find how the pages pinned in memory.I really need the pages > pinned in memory. > > Assume page A is one of the pages obtained by get_user_pages_fast() > during page-fault. > > [1] page A will on the LRU_ACTIVE_ANON list; > the _count of page A increment by one; > PTE for page A will be set ACCESSED. > > [2] kswapd will scan the lru list,and move page A from LRU_ACTIVE_ANON > to LRU_INACTIVE_ANON. > In the shrink_page_list(), there is nothing can stop page A been > swapped out. > I don't think the page_reference() can move page A back to > LRU_ACTIVE_ANON.In my driver, > I am not sure if the VLC can access the page A. > > Is this a bug? or I miss something? > Thanks . BUG. We are talking about it just now. see the following thread in lkml "[RFC][PATCH 0/6] IO pinning(get_user_pages()) vs fork race fix" but unfortunately, we don't have no painful fix. perhaps you need change your code... -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail190.messagelabs.com (mail190.messagelabs.com [216.82.249.51]) by kanga.kvack.org (Postfix) with SMTP id C11265F0001 for ; Sun, 19 Apr 2009 19:44:59 -0400 (EDT) Received: by ti-out-0910.google.com with SMTP id a21so1115624tia.8 for ; Sun, 19 Apr 2009 16:45:40 -0700 (PDT) Date: Mon, 20 Apr 2009 08:45:33 +0900 From: Minchan Kim Subject: Re: Does get_user_pages_fast lock the user pages in memory in my case? Message-Id: <20090420084533.7f701e16.minchan.kim@barrios-desktop> In-Reply-To: <49E8292D.7050904@gmail.com> References: <49E8292D.7050904@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-linux-mm@kvack.org To: Huang Shijie Cc: linux-mm@kvack.org List-ID: On Fri, 17 Apr 2009 15:01:01 +0800 Huang Shijie wrote: > > I'm writting a driver for a video card with the V4L2 interface . > V4L2 interface supports the USER-POINTER method for the video frame > handling. > > VLC player supports the USER-POINTER method,while MPALYER does not. > > In the USER-POINTER method, VLC will call the posix_memalign() to > allocate > 203 pages in certain PAL mode (that is 720*576*2) for a single frame. > In my driver , I call the get_user_pages_fast() to obtain the pages > array,and then call > the vmap() to map the pages to VMALLOC space for the memcpy().The code > shows below: > .................... > get_user_pages_fast(); > ... > f->data = vmap(); > ....................... What I understand is that you get the pages of posix_memalign by get_user_pages_fast and then that pages are mapped at kernel vmalloc space by vmap. Is it for removing copy overhead from kernel to user ? > In comments, it said : > " > +/** > + * get_user_pages_fast() - pin user pages in memory > + * @start: starting user address > + * @nr_pages: number of pages from start to pin > + * @write: whether pages will be written to > + * @pages: array that receives pointers to the pages pinned. > + * Should be at least nr_pages long. > " > > But after I digged the code of kswap and the get_user_pages(called by > get_user_pages_fast), > I did not find how the pages pinned in memory.I really need the pages > pinned in memory. > > Assume page A is one of the pages obtained by get_user_pages_fast() > during page-fault. > > [1] page A will on the LRU_ACTIVE_ANON list; > the _count of page A increment by one; > PTE for page A will be set ACCESSED. > > [2] kswapd will scan the lru list,and move page A from LRU_ACTIVE_ANON > to LRU_INACTIVE_ANON. > In the shrink_page_list(), there is nothing can stop page A been > swapped out. > I don't think the page_reference() can move page A back to > LRU_ACTIVE_ANON.In my driver, > I am not sure if the VLC can access the page A. > > Is this a bug? or I miss something? > Thanks . If above my assumption is right, It's not a BUG. You get the application's pages by get_user_pages_fast. 'Page pinning' means it shouldn't be freed. Application's pages always can be swapped out. If you don't want to swap out the page, you should use mlock. If you use mlock, kernel won't insert the page to lru [in]active list. So the page never can be swapped out. > > > > > > > > > > > > -- > To unsubscribe, send a message with 'unsubscribe linux-mm' in > the body to majordomo@kvack.org. For more info on Linux MM, > see: http://www.linux-mm.org/ . > Don't email: email@kvack.org -- Kinds Regards Minchan Kim -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail190.messagelabs.com (mail190.messagelabs.com [216.82.249.51]) by kanga.kvack.org (Postfix) with SMTP id 1B6265F0001 for ; Sun, 19 Apr 2009 22:16:58 -0400 (EDT) Received: by wa-out-1112.google.com with SMTP id v27so823511wah.22 for ; Sun, 19 Apr 2009 19:17:12 -0700 (PDT) Message-ID: <49EBDADB.4040307@gmail.com> Date: Mon, 20 Apr 2009 10:15:55 +0800 From: Huang Shijie MIME-Version: 1.0 Subject: Re: Does get_user_pages_fast lock the user pages in memory in my case? References: <49E8292D.7050904@gmail.com> <20090420084533.7f701e16.minchan.kim@barrios-desktop> In-Reply-To: <20090420084533.7f701e16.minchan.kim@barrios-desktop> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Sender: owner-linux-mm@kvack.org To: Minchan Kim Cc: linux-mm@kvack.org List-ID: Minchan Kim a??e??: > On Fri, 17 Apr 2009 15:01:01 +0800 > Huang Shijie wrote: > > >> I'm writting a driver for a video card with the V4L2 interface . >> V4L2 interface supports the USER-POINTER method for the video frame >> handling. >> >> VLC player supports the USER-POINTER method,while MPALYER does not. >> >> In the USER-POINTER method, VLC will call the posix_memalign() to >> allocate >> 203 pages in certain PAL mode (that is 720*576*2) for a single frame. >> In my driver , I call the get_user_pages_fast() to obtain the pages >> array,and then call >> the vmap() to map the pages to VMALLOC space for the memcpy().The code >> shows below: >> .................... >> get_user_pages_fast(); >> ... >> f->data = vmap(); >> ....................... >> > > > What I understand is that you get the pages of posix_memalign by get_user_pages_fast > and then that pages are mapped at kernel vmalloc space by vmap. > > Is it for removing copy overhead from kernel to user ? > > I need a large range of virtual contigous memory to store my video frame(about 203 pages). When I received a full frame ,I will queue the buffer in a VIDIOC queue,which will be remove by the VIDIOC_DQBUF. >> In comments, it said : >> " >> +/** >> + * get_user_pages_fast() - pin user pages in memory >> + * @start: starting user address >> + * @nr_pages: number of pages from start to pin >> + * @write: whether pages will be written to >> + * @pages: array that receives pointers to the pages pinned. >> + * Should be at least nr_pages long. >> " >> >> But after I digged the code of kswap and the get_user_pages(called by >> get_user_pages_fast), >> I did not find how the pages pinned in memory.I really need the pages >> pinned in memory. >> >> Assume page A is one of the pages obtained by get_user_pages_fast() >> during page-fault. >> >> [1] page A will on the LRU_ACTIVE_ANON list; >> the _count of page A increment by one; >> PTE for page A will be set ACCESSED. >> >> [2] kswapd will scan the lru list,and move page A from LRU_ACTIVE_ANON >> to LRU_INACTIVE_ANON. >> In the shrink_page_list(), there is nothing can stop page A been >> swapped out. >> I don't think the page_reference() can move page A back to >> LRU_ACTIVE_ANON.In my driver, >> I am not sure if the VLC can access the page A. >> >> Is this a bug? or I miss something? >> Thanks . >> > > If above my assumption is right, It's not a BUG. > You get the application's pages by get_user_pages_fast. > 'Page pinning' means it shouldn't be freed. > Application's pages always can be swapped out. > If you don't want to swap out the page, you should use mlock. > If you use mlock, kernel won't insert the page to lru [in]active list. > So the page never can be swapped out. > > Yes, it not a bug . I read the kernel code again. In my case ,the kernel will pin the pages in memory. I missed function is_page_cache_freeable() in the pageout(). In my case, is_page_cache_freeable()will return false ,for page_count(page) is 3 now: <1> one is from alloc_page_* in page fault. <2> one is from get_usr_pages() <3> one is from add_to_swap() in shrink_page_list() So ,there is no need to use the mlock, it will mess my driver. is_page_cache_freeable()will return PAGE_KEEP, and page is locked in swap cache. Unfortunately, the page is unmaped, and the PTE of the page has been replaced by a swp_entry_t . When the process read the page ,it will raise a page fault again, the kernel will find the page in the swap cache, and requeue the page in LRU_ACTIVE_ANON, ---I think it is a vicious circle for the kernel. I think there two places to put back the gup() pages. <1> isolate_page_glable() <2> in the shrink_page_list(), before called the try_to_unmap(). KOSAKI Motohiro 's patch takes effect in the second place. I think the first place is better. -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail191.messagelabs.com (mail191.messagelabs.com [216.82.242.19]) by kanga.kvack.org (Postfix) with SMTP id C3EF95F0001 for ; Sun, 19 Apr 2009 22:23:46 -0400 (EDT) Received: by rv-out-0708.google.com with SMTP id f25so1288969rvb.26 for ; Sun, 19 Apr 2009 19:23:47 -0700 (PDT) Message-ID: <49EBDC67.2060204@gmail.com> Date: Mon, 20 Apr 2009 10:22:31 +0800 From: Huang Shijie MIME-Version: 1.0 Subject: Re: Does get_user_pages_fast lock the user pages in memory in my case? References: <49E8292D.7050904@gmail.com> <20090418151620.1258.A69D9226@jp.fujitsu.com> In-Reply-To: <20090418151620.1258.A69D9226@jp.fujitsu.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Sender: owner-linux-mm@kvack.org To: KOSAKI Motohiro Cc: linux-mm@kvack.org List-ID: KOSAKI Motohiro a??e??: > Hi > > >> " >> +/** >> + * get_user_pages_fast() - pin user pages in memory >> + * @start: starting user address >> + * @nr_pages: number of pages from start to pin >> + * @write: whether pages will be written to >> + * @pages: array that receives pointers to the pages pinned. >> + * Should be at least nr_pages long. >> " >> >> But after I digged the code of kswap and the get_user_pages(called by >> get_user_pages_fast), >> I did not find how the pages pinned in memory.I really need the pages >> pinned in memory. >> >> Assume page A is one of the pages obtained by get_user_pages_fast() >> during page-fault. >> >> [1] page A will on the LRU_ACTIVE_ANON list; >> the _count of page A increment by one; >> PTE for page A will be set ACCESSED. >> >> [2] kswapd will scan the lru list,and move page A from LRU_ACTIVE_ANON >> to LRU_INACTIVE_ANON. >> In the shrink_page_list(), there is nothing can stop page A been >> swapped out. >> I don't think the page_reference() can move page A back to >> LRU_ACTIVE_ANON.In my driver, >> I am not sure if the VLC can access the page A. >> >> Is this a bug? or I miss something? >> Thanks . >> > > BUG. > > We are talking about it just now. > > see the following thread in lkml > "[RFC][PATCH 0/6] IO pinning(get_user_pages()) vs fork race fix" > > thanks, I read the thread as well as your patch. What about to put the gup() page back in the isolate_pages_global()? > but unfortunately, we don't have no painful fix. perhaps you need change > your code... > > -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail138.messagelabs.com (mail138.messagelabs.com [216.82.249.35]) by kanga.kvack.org (Postfix) with SMTP id D1C075F0001 for ; Sun, 19 Apr 2009 22:42:06 -0400 (EDT) Received: by ti-out-0910.google.com with SMTP id a21so1154273tia.8 for ; Sun, 19 Apr 2009 19:42:44 -0700 (PDT) Date: Mon, 20 Apr 2009 11:42:36 +0900 From: Minchan Kim Subject: Re: Does get_user_pages_fast lock the user pages in memory in my case? Message-Id: <20090420114236.dda3de34.minchan.kim@barrios-desktop> In-Reply-To: <49EBDADB.4040307@gmail.com> References: <49E8292D.7050904@gmail.com> <20090420084533.7f701e16.minchan.kim@barrios-desktop> <49EBDADB.4040307@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: owner-linux-mm@kvack.org To: Huang Shijie Cc: Minchan Kim , linux-mm@kvack.org List-ID: On Mon, 20 Apr 2009 10:15:55 +0800 Huang Shijie wrote: > Minchan Kim a??e??: > > On Fri, 17 Apr 2009 15:01:01 +0800 > > Huang Shijie wrote: > > > > > >> I'm writting a driver for a video card with the V4L2 interface . > >> V4L2 interface supports the USER-POINTER method for the video frame > >> handling. > >> > >> VLC player supports the USER-POINTER method,while MPALYER does not. > >> > >> In the USER-POINTER method, VLC will call the posix_memalign() to > >> allocate > >> 203 pages in certain PAL mode (that is 720*576*2) for a single frame. > >> In my driver , I call the get_user_pages_fast() to obtain the pages > >> array,and then call > >> the vmap() to map the pages to VMALLOC space for the memcpy().The code > >> shows below: > >> .................... > >> get_user_pages_fast(); > >> ... > >> f->data = vmap(); > >> ....................... > >> > > > > > > What I understand is that you get the pages of posix_memalign by get_user_pages_fast > > and then that pages are mapped at kernel vmalloc space by vmap. > > > > Is it for removing copy overhead from kernel to user ? > > > > > I need a large range of virtual contigous memory to store my video > frame(about 203 pages). When I received a full frame ,I will queue the > buffer in > a VIDIOC queue,which will be remove by the VIDIOC_DQBUF.' I can't understand your point. Sorry for that. Could you explain more detail relation (user buffer which is allocated by posix_memalign) and (kernel buffer which is mapped by vmap) ? > >> In comments, it said : > >> " > >> +/** > >> + * get_user_pages_fast() - pin user pages in memory > >> + * @start: starting user address > >> + * @nr_pages: number of pages from start to pin > >> + * @write: whether pages will be written to > >> + * @pages: array that receives pointers to the pages pinned. > >> + * Should be at least nr_pages long. > >> " > >> > >> But after I digged the code of kswap and the get_user_pages(called by > >> get_user_pages_fast), > >> I did not find how the pages pinned in memory.I really need the pages > >> pinned in memory. > >> > >> Assume page A is one of the pages obtained by get_user_pages_fast() > >> during page-fault. > >> > >> [1] page A will on the LRU_ACTIVE_ANON list; > >> the _count of page A increment by one; > >> PTE for page A will be set ACCESSED. > >> > >> [2] kswapd will scan the lru list,and move page A from LRU_ACTIVE_ANON > >> to LRU_INACTIVE_ANON. > >> In the shrink_page_list(), there is nothing can stop page A been > >> swapped out. > >> I don't think the page_reference() can move page A back to > >> LRU_ACTIVE_ANON.In my driver, > >> I am not sure if the VLC can access the page A. > >> > >> Is this a bug? or I miss something? > >> Thanks . > >> > > > > If above my assumption is right, It's not a BUG. > > You get the application's pages by get_user_pages_fast. > > 'Page pinning' means it shouldn't be freed. > > Application's pages always can be swapped out. > > If you don't want to swap out the page, you should use mlock. > > If you use mlock, kernel won't insert the page to lru [in]active list. > > So the page never can be swapped out. > > > > > Yes, it not a bug . > > I read the kernel code again. In my case ,the kernel will pin the pages > in memory. > I missed function is_page_cache_freeable() in the pageout(). > > In my case, is_page_cache_freeable()will return false ,for > page_count(page) is 3 now: > <1> one is from alloc_page_* in page fault. > <2> one is from get_usr_pages() > <3> one is from add_to_swap() in shrink_page_list() One more, try_to_unmap will call page_cache_release. So, count is 2. > So ,there is no need to use the mlock, it will mess my driver. > is_page_cache_freeable()will return PAGE_KEEP, and page is locked in > swap cache. > I can't understand your point exactly yet. But what I mean is following as in user mode posix_memalignq(&buffer); mlock(buffer, buffer_len); I will not dirty your driver. Do I miss something ? > Unfortunately, the page is unmaped, and the PTE of the page has been > replaced by a swp_entry_t . > When the process read the page ,it will raise a page fault again, the > kernel will find the page in the > swap cache, and requeue the page in LRU_ACTIVE_ANON, ---I think it is a > vicious circle for the kernel. > > I think there two places to put back the gup() pages. > <1> isolate_page_glable() > <2> in the shrink_page_list(), before called the try_to_unmap(). > KOSAKI Motohiro 's patch takes effect in the second place. > I think the first place is better. > > > > > > > > -- Kinds Regards Minchan Kim -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail190.messagelabs.com (mail190.messagelabs.com [216.82.249.51]) by kanga.kvack.org (Postfix) with SMTP id D32945F0001 for ; Sun, 19 Apr 2009 23:18:30 -0400 (EDT) Received: from m6.gw.fujitsu.co.jp ([10.0.50.76]) by fgwmail6.fujitsu.co.jp (Fujitsu Gateway) with ESMTP id n3K3IjGF026510 for (envelope-from kosaki.motohiro@jp.fujitsu.com); Mon, 20 Apr 2009 12:18:45 +0900 Received: from smail (m6 [127.0.0.1]) by outgoing.m6.gw.fujitsu.co.jp (Postfix) with ESMTP id 7B22F45DE53 for ; Mon, 20 Apr 2009 12:18:45 +0900 (JST) Received: from s6.gw.fujitsu.co.jp (s6.gw.fujitsu.co.jp [10.0.50.96]) by m6.gw.fujitsu.co.jp (Postfix) with ESMTP id 5B37A45DE51 for ; Mon, 20 Apr 2009 12:18:45 +0900 (JST) Received: from s6.gw.fujitsu.co.jp (localhost.localdomain [127.0.0.1]) by s6.gw.fujitsu.co.jp (Postfix) with ESMTP id 412E5E1800B for ; Mon, 20 Apr 2009 12:18:45 +0900 (JST) Received: from m107.s.css.fujitsu.com (m107.s.css.fujitsu.com [10.249.87.107]) by s6.gw.fujitsu.co.jp (Postfix) with ESMTP id DE92FE18005 for ; Mon, 20 Apr 2009 12:18:44 +0900 (JST) From: KOSAKI Motohiro Subject: Re: Does get_user_pages_fast lock the user pages in memory in my case? In-Reply-To: <49EBDADB.4040307@gmail.com> References: <20090420084533.7f701e16.minchan.kim@barrios-desktop> <49EBDADB.4040307@gmail.com> Message-Id: <20090420121401.4B60.A69D9226@jp.fujitsu.com> MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Date: Mon, 20 Apr 2009 12:18:44 +0900 (JST) Sender: owner-linux-mm@kvack.org To: Huang Shijie Cc: kosaki.motohiro@jp.fujitsu.com, Minchan Kim , linux-mm@kvack.org List-ID: > I think there two places to put back the gup() pages. > <1> isolate_page_glable() > <2> in the shrink_page_list(), before called the try_to_unmap(). > KOSAKI Motohiro 's patch takes effect in the second place. > I think the first place is better. It seems don't works it. Andrea pointed out mmu_notifier issue. kvm pinned various page for shadow pte. it is unmapped by mmu_notifier_invalidate_page() in try_to_unmap_one(). Thus, we can only check page_count after mmu_notifier_invalidate_page. -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail190.messagelabs.com (mail190.messagelabs.com [216.82.249.51]) by kanga.kvack.org (Postfix) with SMTP id 62F865F0001 for ; Sun, 19 Apr 2009 23:28:51 -0400 (EDT) Received: by wa-out-1112.google.com with SMTP id v27so833688wah.22 for ; Sun, 19 Apr 2009 20:29:17 -0700 (PDT) Message-ID: <49EBEBC0.8090102@gmail.com> Date: Mon, 20 Apr 2009 11:28:00 +0800 From: Huang Shijie MIME-Version: 1.0 Subject: Re: Does get_user_pages_fast lock the user pages in memory in my case? References: <49E8292D.7050904@gmail.com> <20090420084533.7f701e16.minchan.kim@barrios-desktop> <49EBDADB.4040307@gmail.com> <20090420114236.dda3de34.minchan.kim@barrios-desktop> In-Reply-To: <20090420114236.dda3de34.minchan.kim@barrios-desktop> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Sender: owner-linux-mm@kvack.org To: Minchan Kim Cc: linux-mm@kvack.org List-ID: Minchan Kim a??e??: > On Mon, 20 Apr 2009 10:15:55 +0800 > Huang Shijie wrote: > > >> Minchan Kim a??e??: >> >>> On Fri, 17 Apr 2009 15:01:01 +0800 >>> Huang Shijie wrote: >>> >>> >>> >>>> I'm writting a driver for a video card with the V4L2 interface . >>>> V4L2 interface supports the USER-POINTER method for the video frame >>>> handling. >>>> >>>> VLC player supports the USER-POINTER method,while MPALYER does not. >>>> >>>> In the USER-POINTER method, VLC will call the posix_memalign() to >>>> allocate >>>> 203 pages in certain PAL mode (that is 720*576*2) for a single frame. >>>> In my driver , I call the get_user_pages_fast() to obtain the pages >>>> array,and then call >>>> the vmap() to map the pages to VMALLOC space for the memcpy().The code >>>> shows below: >>>> .................... >>>> get_user_pages_fast(); >>>> ... >>>> f->data = vmap(); >>>> ....................... >>>> >>>> >>> What I understand is that you get the pages of posix_memalign by get_user_pages_fast >>> and then that pages are mapped at kernel vmalloc space by vmap. >>> >>> Is it for removing copy overhead from kernel to user ? >>> >>> >>> >> I need a large range of virtual contigous memory to store my video >> frame(about 203 pages). When I received a full frame ,I will queue the >> buffer in >> a VIDIOC queue,which will be remove by the VIDIOC_DQBUF.' >> > > I can't understand your point. > Sorry for that. > > Could you explain more detail relation (user buffer which is allocated by posix_memalign) and (kernel buffer which is mapped by vmap) ? > > :) sorry for my poor english. [1] VLC uses the posix_memalign to allocate a big buffer for a single frame(203 pages). [2] vmap sets up the mapping of virtual contigous address for gup()'s pages array(the pages are not consecutive). memcpy() needs a contiguous address to copy in kernel mode. [3] my driver do some specail operations to received data, then memcopy the data to the buffer get in step [2]. [4] when the buffer is full ,I will give the the user process (VLC). That's all. >>>> In comments, it said : >>>> " >>>> +/** >>>> + * get_user_pages_fast() - pin user pages in memory >>>> + * @start: starting user address >>>> + * @nr_pages: number of pages from start to pin >>>> + * @write: whether pages will be written to >>>> + * @pages: array that receives pointers to the pages pinned. >>>> + * Should be at least nr_pages long. >>>> " >>>> >>>> But after I digged the code of kswap and the get_user_pages(called by >>>> get_user_pages_fast), >>>> I did not find how the pages pinned in memory.I really need the pages >>>> pinned in memory. >>>> >>>> Assume page A is one of the pages obtained by get_user_pages_fast() >>>> during page-fault. >>>> >>>> [1] page A will on the LRU_ACTIVE_ANON list; >>>> the _count of page A increment by one; >>>> PTE for page A will be set ACCESSED. >>>> >>>> [2] kswapd will scan the lru list,and move page A from LRU_ACTIVE_ANON >>>> to LRU_INACTIVE_ANON. >>>> In the shrink_page_list(), there is nothing can stop page A been >>>> swapped out. >>>> I don't think the page_reference() can move page A back to >>>> LRU_ACTIVE_ANON.In my driver, >>>> I am not sure if the VLC can access the page A. >>>> >>>> Is this a bug? or I miss something? >>>> Thanks . >>>> >>>> >>> If above my assumption is right, It's not a BUG. >>> You get the application's pages by get_user_pages_fast. >>> 'Page pinning' means it shouldn't be freed. >>> Application's pages always can be swapped out. >>> If you don't want to swap out the page, you should use mlock. >>> If you use mlock, kernel won't insert the page to lru [in]active list. >>> So the page never can be swapped out. >>> >>> >>> >> Yes, it not a bug . >> >> I read the kernel code again. In my case ,the kernel will pin the pages >> in memory. >> I missed function is_page_cache_freeable() in the pageout(). >> >> In my case, is_page_cache_freeable()will return false ,for >> page_count(page) is 3 now: >> <1> one is from alloc_page_* in page fault. >> <2> one is from get_usr_pages() >> <3> one is from add_to_swap() in shrink_page_list() >> > > One more, try_to_unmap will call page_cache_release. > So, count is 2. > > Yes, you are right. I missed the page_cache_release() in try_to_unmap(). :( >> So ,there is no need to use the mlock, it will mess my driver. >> is_page_cache_freeable()will return PAGE_KEEP, and page is locked in >> swap cache. >> >> > > I can't understand your point exactly yet. > But what I mean is following as in user mode > > posix_memalignq(&buffer); > mlock(buffer, buffer_len); > > I also wish the VLC use the mlock,but it does not.If it uses mlock(), the pages will be put in LRU_UNEVICETABL LIST. Maybe the programmer of VLC thinks: Why i add mlock, for the kernel has the gup() which could pin the pages in memory? > I will not dirty your driver. > Do I miss something ? > > I did add the Mlock bit to the VMA->vm_flags in my driver before,but I think that's ugly. >> Unfortunately, the page is unmaped, and the PTE of the page has been >> replaced by a swp_entry_t . >> When the process read the page ,it will raise a page fault again, the >> kernel will find the page in the >> swap cache, and requeue the page in LRU_ACTIVE_ANON, ---I think it is a >> vicious circle for the kernel. >> >> I think there two places to put back the gup() pages. >> <1> isolate_page_glable() >> <2> in the shrink_page_list(), before called the try_to_unmap(). >> KOSAKI Motohiro 's patch takes effect in the second place. >> I think the first place is better. >> >> >> >> >> >> >> >> >> > > > -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail138.messagelabs.com (mail138.messagelabs.com [216.82.249.35]) by kanga.kvack.org (Postfix) with SMTP id 4B7765F0001 for ; Sun, 19 Apr 2009 23:41:26 -0400 (EDT) Received: from m6.gw.fujitsu.co.jp ([10.0.50.76]) by fgwmail6.fujitsu.co.jp (Fujitsu Gateway) with ESMTP id n3K3g3na003329 for (envelope-from kosaki.motohiro@jp.fujitsu.com); Mon, 20 Apr 2009 12:42:03 +0900 Received: from smail (m6 [127.0.0.1]) by outgoing.m6.gw.fujitsu.co.jp (Postfix) with ESMTP id 29B9C45DE53 for ; Mon, 20 Apr 2009 12:42:03 +0900 (JST) Received: from s6.gw.fujitsu.co.jp (s6.gw.fujitsu.co.jp [10.0.50.96]) by m6.gw.fujitsu.co.jp (Postfix) with ESMTP id 0D64D45DE52 for ; Mon, 20 Apr 2009 12:42:03 +0900 (JST) Received: from s6.gw.fujitsu.co.jp (localhost.localdomain [127.0.0.1]) by s6.gw.fujitsu.co.jp (Postfix) with ESMTP id 035CF1DB8038 for ; Mon, 20 Apr 2009 12:42:03 +0900 (JST) Received: from m108.s.css.fujitsu.com (m108.s.css.fujitsu.com [10.249.87.108]) by s6.gw.fujitsu.co.jp (Postfix) with ESMTP id B2F391DB803A for ; Mon, 20 Apr 2009 12:42:02 +0900 (JST) From: KOSAKI Motohiro Subject: Re: Does get_user_pages_fast lock the user pages in memory in my case? In-Reply-To: <49EBEBC0.8090102@gmail.com> References: <20090420114236.dda3de34.minchan.kim@barrios-desktop> <49EBEBC0.8090102@gmail.com> Message-Id: <20090420123510.2503.A69D9226@jp.fujitsu.com> MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Date: Mon, 20 Apr 2009 12:42:01 +0900 (JST) Sender: owner-linux-mm@kvack.org To: Huang Shijie Cc: kosaki.motohiro@jp.fujitsu.com, Minchan Kim , linux-mm@kvack.org List-ID: > > I can't understand your point exactly yet. > > But what I mean is following as in user mode > > > > posix_memalignq(&buffer); > > mlock(buffer, buffer_len); > > > > > I also wish the VLC use the mlock,but it does not.If it uses mlock(), > the pages will be put in LRU_UNEVICETABL LIST. > > Maybe the programmer of VLC thinks: Why i add mlock, for the kernel has the > gup() which could pin the pages in memory? more weakness. mlock() only gurantee the address range is memory-resident, not gurantee to no change virtual-physical mappings. There are different operation. example, gup() prevent page migration but mlock doesn't. > > I will not dirty your driver. > > Do I miss something ? > > > I did add the Mlock bit to the VMA->vm_flags in my driver before,but I > think that's ugly. -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail191.messagelabs.com (mail191.messagelabs.com [216.82.242.19]) by kanga.kvack.org (Postfix) with SMTP id E4B115F0001 for ; Sun, 19 Apr 2009 23:58:12 -0400 (EDT) Received: by wa-out-1112.google.com with SMTP id v27so837969wah.22 for ; Sun, 19 Apr 2009 20:59:06 -0700 (PDT) Message-ID: <49EBF2BE.2030908@gmail.com> Date: Mon, 20 Apr 2009 11:57:50 +0800 From: Huang Shijie MIME-Version: 1.0 Subject: Re: Does get_user_pages_fast lock the user pages in memory in my case? References: <49E8292D.7050904@gmail.com> <20090420084533.7f701e16.minchan.kim@barrios-desktop> <49EBDADB.4040307@gmail.com> <20090420114236.dda3de34.minchan.kim@barrios-desktop> In-Reply-To: <20090420114236.dda3de34.minchan.kim@barrios-desktop> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Sender: owner-linux-mm@kvack.org To: Minchan Kim Cc: linux-mm@kvack.org List-ID: Minchan Kim a??e??: > On Mon, 20 Apr 2009 10:15:55 +0800 > Huang Shijie wrote: > > >> Minchan Kim a??e??: >> >>> On Fri, 17 Apr 2009 15:01:01 +0800 >>> Huang Shijie wrote: >>> >>> >>> >>>> I'm writting a driver for a video card with the V4L2 interface . >>>> V4L2 interface supports the USER-POINTER method for the video frame >>>> handling. >>>> >>>> VLC player supports the USER-POINTER method,while MPALYER does not. >>>> >>>> In the USER-POINTER method, VLC will call the posix_memalign() to >>>> allocate >>>> 203 pages in certain PAL mode (that is 720*576*2) for a single frame. >>>> In my driver , I call the get_user_pages_fast() to obtain the pages >>>> array,and then call >>>> the vmap() to map the pages to VMALLOC space for the memcpy().The code >>>> shows below: >>>> .................... >>>> get_user_pages_fast(); >>>> ... >>>> f->data = vmap(); >>>> ....................... >>>> >>>> >>> What I understand is that you get the pages of posix_memalign by get_user_pages_fast >>> and then that pages are mapped at kernel vmalloc space by vmap. >>> >>> Is it for removing copy overhead from kernel to user ? >>> >>> >>> >> I need a large range of virtual contigous memory to store my video >> frame(about 203 pages). When I received a full frame ,I will queue the >> buffer in >> a VIDIOC queue,which will be remove by the VIDIOC_DQBUF.' >> > > I can't understand your point. > Sorry for that. > > Could you explain more detail relation (user buffer which is allocated by posix_memalign) and (kernel buffer which is mapped by vmap) ? > > [1] fork() will copy the range of 768-1024 index of swapper_pg_dir to mm->pgd. [2] vmap setup mapping in the swapper_pg_dir. [3] my driver will use the mm->pgd in the ioctl context.for the reason of [1],driver could see the address setup by vmap. >>>> In comments, it said : >>>> " >>>> +/** >>>> + * get_user_pages_fast() - pin user pages in memory >>>> + * @start: starting user address >>>> + * @nr_pages: number of pages from start to pin >>>> + * @write: whether pages will be written to >>>> + * @pages: array that receives pointers to the pages pinned. >>>> + * Should be at least nr_pages long. >>>> " >>>> >>>> But after I digged the code of kswap and the get_user_pages(called by >>>> get_user_pages_fast), >>>> I did not find how the pages pinned in memory.I really need the pages >>>> pinned in memory. >>>> >>>> Assume page A is one of the pages obtained by get_user_pages_fast() >>>> during page-fault. >>>> >>>> [1] page A will on the LRU_ACTIVE_ANON list; >>>> the _count of page A increment by one; >>>> PTE for page A will be set ACCESSED. >>>> >>>> [2] kswapd will scan the lru list,and move page A from LRU_ACTIVE_ANON >>>> to LRU_INACTIVE_ANON. >>>> In the shrink_page_list(), there is nothing can stop page A been >>>> swapped out. >>>> I don't think the page_reference() can move page A back to >>>> LRU_ACTIVE_ANON.In my driver, >>>> I am not sure if the VLC can access the page A. >>>> >>>> Is this a bug? or I miss something? >>>> Thanks . >>>> >>>> >>> If above my assumption is right, It's not a BUG. >>> You get the application's pages by get_user_pages_fast. >>> 'Page pinning' means it shouldn't be freed. >>> Application's pages always can be swapped out. >>> If you don't want to swap out the page, you should use mlock. >>> If you use mlock, kernel won't insert the page to lru [in]active list. >>> So the page never can be swapped out. >>> >>> >>> >> Yes, it not a bug . >> >> I read the kernel code again. In my case ,the kernel will pin the pages >> in memory. >> I missed function is_page_cache_freeable() in the pageout(). >> >> In my case, is_page_cache_freeable()will return false ,for >> page_count(page) is 3 now: >> <1> one is from alloc_page_* in page fault. >> <2> one is from get_usr_pages() >> <3> one is from add_to_swap() in shrink_page_list() >> > > One more, try_to_unmap will call page_cache_release. > So, count is 2. > > >> So ,there is no need to use the mlock, it will mess my driver. >> is_page_cache_freeable()will return PAGE_KEEP, and page is locked in >> swap cache. >> >> > > I can't understand your point exactly yet. > But what I mean is following as in user mode > > posix_memalignq(&buffer); > mlock(buffer, buffer_len); > > I will not dirty your driver. > Do I miss something ? > > >> Unfortunately, the page is unmaped, and the PTE of the page has been >> replaced by a swp_entry_t . >> When the process read the page ,it will raise a page fault again, the >> kernel will find the page in the >> swap cache, and requeue the page in LRU_ACTIVE_ANON, ---I think it is a >> vicious circle for the kernel. >> >> I think there two places to put back the gup() pages. >> <1> isolate_page_glable() >> <2> in the shrink_page_list(), before called the try_to_unmap(). >> KOSAKI Motohiro 's patch takes effect in the second place. >> I think the first place is better. >> >> >> >> >> >> >> >> >> > > > -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail143.messagelabs.com (mail143.messagelabs.com [216.82.254.35]) by kanga.kvack.org (Postfix) with SMTP id 1FF345F0001 for ; Mon, 20 Apr 2009 00:52:46 -0400 (EDT) Received: by ti-out-0910.google.com with SMTP id a21so1188209tia.8 for ; Sun, 19 Apr 2009 21:53:33 -0700 (PDT) Date: Mon, 20 Apr 2009 13:53:23 +0900 From: Minchan Kim Subject: Re: Does get_user_pages_fast lock the user pages in memory in my case? Message-Id: <20090420135323.08015e32.minchan.kim@barrios-desktop> In-Reply-To: <49EBEBC0.8090102@gmail.com> References: <49E8292D.7050904@gmail.com> <20090420084533.7f701e16.minchan.kim@barrios-desktop> <49EBDADB.4040307@gmail.com> <20090420114236.dda3de34.minchan.kim@barrios-desktop> <49EBEBC0.8090102@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: owner-linux-mm@kvack.org To: Huang Shijie Cc: Minchan Kim , linux-mm@kvack.org List-ID: On Mon, 20 Apr 2009 11:28:00 +0800 Huang Shijie wrote: I will summarize your method. Is right ? kernel(driver) application posix_memalign(buffer) ioctl(buffer) ioctl handler get_user_pages(pages); /* This pages are mapped at user's vma' address space */ vaddr = vmap(pages); /* This pages are mapped at vmalloc space */ . . . . interrupt handler in your driver memcpy(vaddr, src, len); notify_user(); processing(buffer); It's rather awkward use case of get_user_pages. If you want to share one big buffer between kernel and user, You can vmalloc and remap_pfn_range. You can refer cpia_mmap in drivers/media/video/cpia.c > Minchan Kim a??e??: > > On Mon, 20 Apr 2009 10:15:55 +0800 > > Huang Shijie wrote: > > > > > >> Minchan Kim a??e??: > >> > >>> On Fri, 17 Apr 2009 15:01:01 +0800 > >>> Huang Shijie wrote: > >>> > >>> > >>> > >>>> I'm writting a driver for a video card with the V4L2 interface . > >>>> V4L2 interface supports the USER-POINTER method for the video frame > >>>> handling. > >>>> > >>>> VLC player supports the USER-POINTER method,while MPALYER does not. > >>>> > >>>> In the USER-POINTER method, VLC will call the posix_memalign() to > >>>> allocate > >>>> 203 pages in certain PAL mode (that is 720*576*2) for a single frame. > >>>> In my driver , I call the get_user_pages_fast() to obtain the pages > >>>> array,and then call > >>>> the vmap() to map the pages to VMALLOC space for the memcpy().The code > >>>> shows below: > >>>> .................... > >>>> get_user_pages_fast(); > >>>> ... > >>>> f->data = vmap(); > >>>> ....................... > >>>> > >>>> > >>> What I understand is that you get the pages of posix_memalign by get_user_pages_fast > >>> and then that pages are mapped at kernel vmalloc space by vmap. > >>> > >>> Is it for removing copy overhead from kernel to user ? > >>> > >>> > >>> > >> I need a large range of virtual contigous memory to store my video > >> frame(about 203 pages). When I received a full frame ,I will queue the > >> buffer in > >> a VIDIOC queue,which will be remove by the VIDIOC_DQBUF.' > >> > > > > I can't understand your point. > > Sorry for that. > > > > Could you explain more detail relation (user buffer which is allocated by posix_memalign) and (kernel buffer which is mapped by vmap) ? > > > > > :) sorry for my poor english. > [1] VLC uses the posix_memalign to allocate a big buffer for a single > frame(203 pages). > [2] vmap sets up the mapping of virtual contigous address for gup()'s > pages array(the pages are not consecutive). > memcpy() needs a contiguous address to copy in kernel mode. > [3] my driver do some specail operations to received data, then > memcopy the data to the buffer get in step [2]. > [4] when the buffer is full ,I will give the the user process (VLC). > > That's all. -- Kinds Regards Minchan Kim -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail203.messagelabs.com (mail203.messagelabs.com [216.82.254.243]) by kanga.kvack.org (Postfix) with SMTP id 57C8E5F0001 for ; Mon, 20 Apr 2009 01:05:01 -0400 (EDT) Received: from m1.gw.fujitsu.co.jp ([10.0.50.71]) by fgwmail7.fujitsu.co.jp (Fujitsu Gateway) with ESMTP id n3K553n0019372 for (envelope-from kosaki.motohiro@jp.fujitsu.com); Mon, 20 Apr 2009 14:05:03 +0900 Received: from smail (m1 [127.0.0.1]) by outgoing.m1.gw.fujitsu.co.jp (Postfix) with ESMTP id 9941B45DD76 for ; Mon, 20 Apr 2009 14:05:03 +0900 (JST) Received: from s1.gw.fujitsu.co.jp (s1.gw.fujitsu.co.jp [10.0.50.91]) by m1.gw.fujitsu.co.jp (Postfix) with ESMTP id 78FE145DD74 for ; Mon, 20 Apr 2009 14:05:03 +0900 (JST) Received: from s1.gw.fujitsu.co.jp (localhost.localdomain [127.0.0.1]) by s1.gw.fujitsu.co.jp (Postfix) with ESMTP id 77D701DB8018 for ; Mon, 20 Apr 2009 14:05:03 +0900 (JST) Received: from m106.s.css.fujitsu.com (m106.s.css.fujitsu.com [10.249.87.106]) by s1.gw.fujitsu.co.jp (Postfix) with ESMTP id 35D3F1DB8016 for ; Mon, 20 Apr 2009 14:05:03 +0900 (JST) From: KOSAKI Motohiro Subject: Re: Does get_user_pages_fast lock the user pages in memory in my case? In-Reply-To: <20090420135323.08015e32.minchan.kim@barrios-desktop> References: <49EBEBC0.8090102@gmail.com> <20090420135323.08015e32.minchan.kim@barrios-desktop> Message-Id: <20090420135748.2506.A69D9226@jp.fujitsu.com> MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Date: Mon, 20 Apr 2009 14:05:02 +0900 (JST) Sender: owner-linux-mm@kvack.org To: Minchan Kim Cc: kosaki.motohiro@jp.fujitsu.com, Huang Shijie , linux-mm@kvack.org List-ID: > It's rather awkward use case of get_user_pages. > > If you want to share one big buffer between kernel and user, > You can vmalloc and remap_pfn_range. > You can refer cpia_mmap in drivers/media/video/cpia.c Hm, good opinion. gup()ed page stay in lru, but remap_pfn_range() page doesn't. it cause gup() pinning: merit - Can processing any user process patch (DirectIO need it) demerit - introduce reclaim slowdown remap merit - Don't cause any slowdown demerit - can be used on some special situation only. Then, driver can use special memory and need long time pinning. remap_pfn_range() is better. but, DirectIO liked general pinning need gup() pinning. I think. but I'm not remap_pfn_range() specialist. perhaps I can talk about incorrect thing ... -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail138.messagelabs.com (mail138.messagelabs.com [216.82.249.35]) by kanga.kvack.org (Postfix) with SMTP id 1E9E15F0001 for ; Mon, 20 Apr 2009 01:06:49 -0400 (EDT) Received: by rv-out-0708.google.com with SMTP id f25so1326150rvb.26 for ; Sun, 19 Apr 2009 22:06:54 -0700 (PDT) Message-ID: <49EC029D.1060807@gmail.com> Date: Mon, 20 Apr 2009 13:05:33 +0800 From: Huang Shijie MIME-Version: 1.0 Subject: Re: Does get_user_pages_fast lock the user pages in memory in my case? References: <49E8292D.7050904@gmail.com> <20090420084533.7f701e16.minchan.kim@barrios-desktop> <49EBDADB.4040307@gmail.com> <20090420114236.dda3de34.minchan.kim@barrios-desktop> <49EBEBC0.8090102@gmail.com> <20090420135323.08015e32.minchan.kim@barrios-desktop> In-Reply-To: <20090420135323.08015e32.minchan.kim@barrios-desktop> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Sender: owner-linux-mm@kvack.org To: Minchan Kim Cc: linux-mm@kvack.org List-ID: Minchan Kim a??e??: > On Mon, 20 Apr 2009 11:28:00 +0800 > Huang Shijie wrote: > > I will summarize your method. > Is right ? > > > kernel(driver) application > > posix_memalign(buffer) > ioctl(buffer) > > ioctl handler > get_user_pages(pages); > /* This pages are mapped at user's vma' > address space */ > vaddr = vmap(pages); > /* This pages are mapped at vmalloc space */ > . > . > It may change to other process context> > . > . > interrupt handler in your driver > memcpy(vaddr, src, len); > notify_user(); > > processing(buffer); > > It's rather awkward use case of get_user_pages. > > If you want to share one big buffer between kernel and user, > You can vmalloc and remap_pfn_range. > The v4l2 method IO_METHOD_MMAP does use the vmaloc() method you told above , our driver also support this method,we user vmalloc /remap_vmalloc_range(). But the v4l2 method IO_METHOD_USERPTR must use the method I told above. > You can refer cpia_mmap in drivers/media/video/cpia.c > > > > >> Minchan Kim a??e??: >> >>> On Mon, 20 Apr 2009 10:15:55 +0800 >>> Huang Shijie wrote: >>> >>> >>> >>>> Minchan Kim a??e??: >>>> >>>> >>>>> On Fri, 17 Apr 2009 15:01:01 +0800 >>>>> Huang Shijie wrote: >>>>> >>>>> >>>>> >>>>> >>>>>> I'm writting a driver for a video card with the V4L2 interface . >>>>>> V4L2 interface supports the USER-POINTER method for the video frame >>>>>> handling. >>>>>> >>>>>> VLC player supports the USER-POINTER method,while MPALYER does not. >>>>>> >>>>>> In the USER-POINTER method, VLC will call the posix_memalign() to >>>>>> allocate >>>>>> 203 pages in certain PAL mode (that is 720*576*2) for a single frame. >>>>>> In my driver , I call the get_user_pages_fast() to obtain the pages >>>>>> array,and then call >>>>>> the vmap() to map the pages to VMALLOC space for the memcpy().The code >>>>>> shows below: >>>>>> .................... >>>>>> get_user_pages_fast(); >>>>>> ... >>>>>> f->data = vmap(); >>>>>> ....................... >>>>>> >>>>>> >>>>>> >>>>> What I understand is that you get the pages of posix_memalign by get_user_pages_fast >>>>> and then that pages are mapped at kernel vmalloc space by vmap. >>>>> >>>>> Is it for removing copy overhead from kernel to user ? >>>>> >>>>> >>>>> >>>>> >>>> I need a large range of virtual contigous memory to store my video >>>> frame(about 203 pages). When I received a full frame ,I will queue the >>>> buffer in >>>> a VIDIOC queue,which will be remove by the VIDIOC_DQBUF.' >>>> >>>> >>> I can't understand your point. >>> Sorry for that. >>> >>> Could you explain more detail relation (user buffer which is allocated by posix_memalign) and (kernel buffer which is mapped by vmap) ? >>> >>> >>> >> :) sorry for my poor english. >> [1] VLC uses the posix_memalign to allocate a big buffer for a single >> frame(203 pages). >> [2] vmap sets up the mapping of virtual contigous address for gup()'s >> pages array(the pages are not consecutive). >> memcpy() needs a contiguous address to copy in kernel mode. >> [3] my driver do some specail operations to received data, then >> memcopy the data to the buffer get in step [2]. >> [4] when the buffer is full ,I will give the the user process (VLC). >> >> That's all. >> > > > -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail172.messagelabs.com (mail172.messagelabs.com [216.82.254.3]) by kanga.kvack.org (Postfix) with SMTP id 429F05F0001 for ; Mon, 20 Apr 2009 01:19:35 -0400 (EDT) Received: from m5.gw.fujitsu.co.jp ([10.0.50.75]) by fgwmail6.fujitsu.co.jp (Fujitsu Gateway) with ESMTP id n3K5Jolq011283 for (envelope-from kosaki.motohiro@jp.fujitsu.com); Mon, 20 Apr 2009 14:19:50 +0900 Received: from smail (m5 [127.0.0.1]) by outgoing.m5.gw.fujitsu.co.jp (Postfix) with ESMTP id 61CC445DE52 for ; Mon, 20 Apr 2009 14:19:50 +0900 (JST) Received: from s5.gw.fujitsu.co.jp (s5.gw.fujitsu.co.jp [10.0.50.95]) by m5.gw.fujitsu.co.jp (Postfix) with ESMTP id 4363845DE4E for ; Mon, 20 Apr 2009 14:19:50 +0900 (JST) Received: from s5.gw.fujitsu.co.jp (localhost.localdomain [127.0.0.1]) by s5.gw.fujitsu.co.jp (Postfix) with ESMTP id 26E2D1DB8040 for ; Mon, 20 Apr 2009 14:19:50 +0900 (JST) Received: from ml13.s.css.fujitsu.com (ml13.s.css.fujitsu.com [10.249.87.103]) by s5.gw.fujitsu.co.jp (Postfix) with ESMTP id DAB351DB8038 for ; Mon, 20 Apr 2009 14:19:49 +0900 (JST) From: KOSAKI Motohiro Subject: Re: Does get_user_pages_fast lock the user pages in memory in my case? In-Reply-To: <49EC029D.1060807@gmail.com> References: <20090420135323.08015e32.minchan.kim@barrios-desktop> <49EC029D.1060807@gmail.com> Message-Id: <20090420141710.2509.A69D9226@jp.fujitsu.com> MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Date: Mon, 20 Apr 2009 14:19:49 +0900 (JST) Sender: owner-linux-mm@kvack.org To: Huang Shijie Cc: kosaki.motohiro@jp.fujitsu.com, Minchan Kim , linux-mm@kvack.org List-ID: > The v4l2 method IO_METHOD_MMAP does use the vmaloc() method you told above , > our driver also support this method,we user vmalloc /remap_vmalloc_range(). > > But the v4l2 method IO_METHOD_USERPTR must use the method I told above. I guess you mean IO_METHOD_USERPTR can't use remap_vmalloc_range, right? we need explanation of v4l2 requirement. Can you explain why v4l2 use two different way? Why application developer need two way? -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail143.messagelabs.com (mail143.messagelabs.com [216.82.254.35]) by kanga.kvack.org (Postfix) with SMTP id 0EE8B5F0001 for ; Mon, 20 Apr 2009 01:24:12 -0400 (EDT) Received: by ti-out-0910.google.com with SMTP id a21so1195540tia.8 for ; Sun, 19 Apr 2009 22:24:33 -0700 (PDT) Date: Mon, 20 Apr 2009 14:24:22 +0900 From: Minchan Kim Subject: Re: Does get_user_pages_fast lock the user pages in memory in my case? Message-Id: <20090420142422.ff1a2a66.minchan.kim@barrios-desktop> In-Reply-To: <49EC029D.1060807@gmail.com> References: <49E8292D.7050904@gmail.com> <20090420084533.7f701e16.minchan.kim@barrios-desktop> <49EBDADB.4040307@gmail.com> <20090420114236.dda3de34.minchan.kim@barrios-desktop> <49EBEBC0.8090102@gmail.com> <20090420135323.08015e32.minchan.kim@barrios-desktop> <49EC029D.1060807@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: owner-linux-mm@kvack.org To: Huang Shijie Cc: Minchan Kim , linux-mm@kvack.org List-ID: On Mon, 20 Apr 2009 13:05:33 +0800 Huang Shijie wrote: > Minchan Kim a??e??: > > On Mon, 20 Apr 2009 11:28:00 +0800 > > Huang Shijie wrote: > > > > I will summarize your method. > > Is right ? > > > > > > kernel(driver) application > > > > posix_memalign(buffer) > > ioctl(buffer) > > > > ioctl handler > > get_user_pages(pages); > > /* This pages are mapped at user's vma' > > address space */ > > vaddr = vmap(pages); > > /* This pages are mapped at vmalloc space */ > > . > > . > > > It may change to other process context> > > . > > . > > interrupt handler in your driver > > memcpy(vaddr, src, len); > > notify_user(); > > > > processing(buffer); > > > > It's rather awkward use case of get_user_pages. > > > > If you want to share one big buffer between kernel and user, > > You can vmalloc and remap_pfn_range. > > > The v4l2 method IO_METHOD_MMAP does use the vmaloc() method you told above , > our driver also support this method,we user vmalloc /remap_vmalloc_range(). > > But the v4l2 method IO_METHOD_USERPTR must use the method I told above. I can't understand IO_METHOD_USERPTR's benefit compared with IO_METHOD_MMAP. I think both solution can support that application programmer can handle buffer as like pointer and kernel can reduce copy overhead from kernel to user. Why do you have to support IO_METHOD_USERPTR? If you can justify your goal, we can add locked GUP. -- Kinds Regards Minchan Kim -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail203.messagelabs.com (mail203.messagelabs.com [216.82.254.243]) by kanga.kvack.org (Postfix) with SMTP id 1930C5F0001 for ; Mon, 20 Apr 2009 01:38:21 -0400 (EDT) Received: by wa-out-1112.google.com with SMTP id v27so852946wah.22 for ; Sun, 19 Apr 2009 22:38:56 -0700 (PDT) Message-ID: <49EC0A24.6060307@gmail.com> Date: Mon, 20 Apr 2009 13:37:40 +0800 From: Huang Shijie MIME-Version: 1.0 Subject: Re: Does get_user_pages_fast lock the user pages in memory in my case? References: <20090420135323.08015e32.minchan.kim@barrios-desktop> <49EC029D.1060807@gmail.com> <20090420141710.2509.A69D9226@jp.fujitsu.com> In-Reply-To: <20090420141710.2509.A69D9226@jp.fujitsu.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Sender: owner-linux-mm@kvack.org To: KOSAKI Motohiro Cc: Minchan Kim , linux-mm@kvack.org List-ID: KOSAKI Motohiro a??e??: >> The v4l2 method IO_METHOD_MMAP does use the vmaloc() method you told above , >> our driver also support this method,we user vmalloc /remap_vmalloc_range(). >> >> But the v4l2 method IO_METHOD_USERPTR must use the method I told above. >> > > I guess you mean IO_METHOD_USERPTR can't use remap_vmalloc_range, right? > Yes. IO_METHOD_USERPTR method uses the anonymous pages allocated by posix_memalign(), while the remap_vmalloc_range() use the pages alloced by vmalloc(). > we need explanation of v4l2 requirement. > > Can you explain why v4l2 use two different way? Why application developer > need two way? > > > pleasure :) http://v4l2spec.bytesex.org/spec/r13696.htm shows the vidioc_reqbufs(). It determines the method of IO : "Memory Mapping or User Pointer I/O" The application developers can support any methodes of the Two, there is no mandatory request to realize both methods. For example, the Mplayer only support the "memory maping" method ,and it does't support the "user pointer", while the VLC supports both. The full spec is below. http://v4l2spec.bytesex.org/spec/ > > > -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail143.messagelabs.com (mail143.messagelabs.com [216.82.254.35]) by kanga.kvack.org (Postfix) with SMTP id 7B8D95F0001 for ; Mon, 20 Apr 2009 01:42:38 -0400 (EDT) Received: by wa-out-1112.google.com with SMTP id v27so853567wah.22 for ; Sun, 19 Apr 2009 22:43:17 -0700 (PDT) Message-ID: <49EC0B2A.5080600@gmail.com> Date: Mon, 20 Apr 2009 13:42:02 +0800 From: Huang Shijie MIME-Version: 1.0 Subject: Re: Does get_user_pages_fast lock the user pages in memory in my case? References: <49E8292D.7050904@gmail.com> <20090420084533.7f701e16.minchan.kim@barrios-desktop> <49EBDADB.4040307@gmail.com> <20090420114236.dda3de34.minchan.kim@barrios-desktop> <49EBEBC0.8090102@gmail.com> <20090420135323.08015e32.minchan.kim@barrios-desktop> <49EC029D.1060807@gmail.com> <20090420142422.ff1a2a66.minchan.kim@barrios-desktop> In-Reply-To: <20090420142422.ff1a2a66.minchan.kim@barrios-desktop> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Sender: owner-linux-mm@kvack.org To: Minchan Kim Cc: linux-mm@kvack.org List-ID: Minchan Kim a??e??: > On Mon, 20 Apr 2009 13:05:33 +0800 > Huang Shijie wrote: > > >> Minchan Kim a??e??: >> >>> On Mon, 20 Apr 2009 11:28:00 +0800 >>> Huang Shijie wrote: >>> >>> I will summarize your method. >>> Is right ? >>> >>> >>> kernel(driver) application >>> >>> posix_memalign(buffer) >>> ioctl(buffer) >>> >>> ioctl handler >>> get_user_pages(pages); >>> /* This pages are mapped at user's vma' >>> address space */ >>> vaddr = vmap(pages); >>> /* This pages are mapped at vmalloc space */ >>> . >>> . >>> >> It may change to other process context> >>> . >>> . >>> interrupt handler in your driver >>> memcpy(vaddr, src, len); >>> notify_user(); >>> >>> processing(buffer); >>> >>> It's rather awkward use case of get_user_pages. >>> >>> If you want to share one big buffer between kernel and user, >>> You can vmalloc and remap_pfn_range. >>> >>> >> The v4l2 method IO_METHOD_MMAP does use the vmaloc() method you told above , >> our driver also support this method,we user vmalloc /remap_vmalloc_range(). >> >> But the v4l2 method IO_METHOD_USERPTR must use the method I told above. >> > > I can't understand IO_METHOD_USERPTR's benefit compared with IO_METHOD_MMAP. > I think both solution can support that application programmer can handle buffer as like pointer and kernel can reduce copy overhead from kernel to user. > > yes ,I agree with you . But the application programmers do not know which method is more efficient. > Why do you have to support IO_METHOD_USERPTR? > just for fun. For the v4l2 spec has the method ,why I don't realize it? > If you can justify your goal, we can add locked GUP. > > I can't . -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail137.messagelabs.com (mail137.messagelabs.com [216.82.249.19]) by kanga.kvack.org (Postfix) with SMTP id 9CC8C5F0001 for ; Mon, 20 Apr 2009 03:58:20 -0400 (EDT) Received: from mt1.gw.fujitsu.co.jp ([10.0.50.74]) by fgwmail5.fujitsu.co.jp (Fujitsu Gateway) with ESMTP id n3K7xDG8013169 for (envelope-from kosaki.motohiro@jp.fujitsu.com); Mon, 20 Apr 2009 16:59:14 +0900 Received: from smail (m4 [127.0.0.1]) by outgoing.m4.gw.fujitsu.co.jp (Postfix) with ESMTP id C28EE45DE4E for ; Mon, 20 Apr 2009 16:59:13 +0900 (JST) Received: from s4.gw.fujitsu.co.jp (s4.gw.fujitsu.co.jp [10.0.50.94]) by m4.gw.fujitsu.co.jp (Postfix) with ESMTP id A188745DE4F for ; Mon, 20 Apr 2009 16:59:13 +0900 (JST) Received: from s4.gw.fujitsu.co.jp (localhost.localdomain [127.0.0.1]) by s4.gw.fujitsu.co.jp (Postfix) with ESMTP id 6960FE08007 for ; Mon, 20 Apr 2009 16:59:13 +0900 (JST) Received: from ml13.s.css.fujitsu.com (ml13.s.css.fujitsu.com [10.249.87.103]) by s4.gw.fujitsu.co.jp (Postfix) with ESMTP id 18425E08003 for ; Mon, 20 Apr 2009 16:59:13 +0900 (JST) From: KOSAKI Motohiro Subject: Re: Does get_user_pages_fast lock the user pages in memory in my case? In-Reply-To: <49EC0A24.6060307@gmail.com> References: <20090420141710.2509.A69D9226@jp.fujitsu.com> <49EC0A24.6060307@gmail.com> Message-Id: <20090420165529.61AB.A69D9226@jp.fujitsu.com> MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Date: Mon, 20 Apr 2009 16:59:12 +0900 (JST) Sender: owner-linux-mm@kvack.org To: Huang Shijie Cc: kosaki.motohiro@jp.fujitsu.com, Minchan Kim , linux-mm@kvack.org List-ID: > http://v4l2spec.bytesex.org/spec/r13696.htm > shows the vidioc_reqbufs(). It determines the method of IO : "Memory > Mapping or User Pointer I/O" > > The application developers can support any methodes of the Two, there is > no mandatory request to realize > both methods. For example, the Mplayer only support the "memory > maping" method ,and it does't support the "user pointer", > while the VLC supports both. I greped VIDIOC_REQBUFS on current tree. Almost driver has following check. if (rb->memory != V4L2_MEMORY_MMAP) return -EINVAL; IOW, almost one don't provide V4L2_MEMORY_USERPTR method. Thus, I think any userland application don't want use V4L2_MEMORY_USERPTR. I recommend you also return -EINVAL. I think we can't implement V4L2_MEMORY_USERPTR properly. it is mistake by specification. -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail138.messagelabs.com (mail138.messagelabs.com [216.82.249.35]) by kanga.kvack.org (Postfix) with SMTP id F0CAA5F0001 for ; Mon, 20 Apr 2009 04:24:51 -0400 (EDT) Received: by wa-out-1112.google.com with SMTP id v27so878834wah.22 for ; Mon, 20 Apr 2009 01:25:14 -0700 (PDT) Message-ID: <49EC311D.4090605@gmail.com> Date: Mon, 20 Apr 2009 16:23:57 +0800 From: Huang Shijie MIME-Version: 1.0 Subject: Re: Does get_user_pages_fast lock the user pages in memory in my case? References: <20090420141710.2509.A69D9226@jp.fujitsu.com> <49EC0A24.6060307@gmail.com> <20090420165529.61AB.A69D9226@jp.fujitsu.com> In-Reply-To: <20090420165529.61AB.A69D9226@jp.fujitsu.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Sender: owner-linux-mm@kvack.org To: KOSAKI Motohiro Cc: Minchan Kim , linux-mm@kvack.org, Huang Shijie List-ID: KOSAKI Motohiro a??e??: >> http://v4l2spec.bytesex.org/spec/r13696.htm >> shows the vidioc_reqbufs(). It determines the method of IO : "Memory >> Mapping or User Pointer I/O" >> >> The application developers can support any methodes of the Two, there is >> no mandatory request to realize >> both methods. For example, the Mplayer only support the "memory >> maping" method ,and it does't support the "user pointer", >> while the VLC supports both. >> > > I greped VIDIOC_REQBUFS on current tree. > Almost driver has following check. > > if (rb->memory != V4L2_MEMORY_MMAP) > return -EINVAL; > > IOW, almost one don't provide V4L2_MEMORY_USERPTR method. > Thus, I think any userland application don't want use V4L2_MEMORY_USERPTR. > I recommend you also return -EINVAL. > > Thanks. In the V4L2_MEMORY_USERPTR method, what I want to do is pin the anonymous pages in memory. I used to add the VM_LOCKED to vma associated with the pages.In my opinion, the pages will: LRU_ACTIVE_ANON ---> LRU_INACTIVE_ANON---> LRU_UNEVICTABLE so the pages are pinned in memory.It was ugly, but it works I think. Do you have any suggestions about this method? > I think we can't implement V4L2_MEMORY_USERPTR properly. > it is mistake by specification. > > > > > > -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail138.messagelabs.com (mail138.messagelabs.com [216.82.249.35]) by kanga.kvack.org (Postfix) with SMTP id D641E5F0001 for ; Mon, 20 Apr 2009 05:24:11 -0400 (EDT) Received: from m3.gw.fujitsu.co.jp ([10.0.50.73]) by fgwmail7.fujitsu.co.jp (Fujitsu Gateway) with ESMTP id n3K9OWKn030035 for (envelope-from kosaki.motohiro@jp.fujitsu.com); Mon, 20 Apr 2009 18:24:33 +0900 Received: from smail (m3 [127.0.0.1]) by outgoing.m3.gw.fujitsu.co.jp (Postfix) with ESMTP id C0ADB45DD7F for ; Mon, 20 Apr 2009 18:24:32 +0900 (JST) Received: from s3.gw.fujitsu.co.jp (s3.gw.fujitsu.co.jp [10.0.50.93]) by m3.gw.fujitsu.co.jp (Postfix) with ESMTP id 8B4D745DD75 for ; Mon, 20 Apr 2009 18:24:32 +0900 (JST) Received: from s3.gw.fujitsu.co.jp (localhost.localdomain [127.0.0.1]) by s3.gw.fujitsu.co.jp (Postfix) with ESMTP id 4719B1DB803C for ; Mon, 20 Apr 2009 18:24:32 +0900 (JST) Received: from m105.s.css.fujitsu.com (m105.s.css.fujitsu.com [10.249.87.105]) by s3.gw.fujitsu.co.jp (Postfix) with ESMTP id D70D2E08005 for ; Mon, 20 Apr 2009 18:24:31 +0900 (JST) From: KOSAKI Motohiro Subject: Re: Does get_user_pages_fast lock the user pages in memory in my case? In-Reply-To: <49EC311D.4090605@gmail.com> References: <20090420165529.61AB.A69D9226@jp.fujitsu.com> <49EC311D.4090605@gmail.com> Message-Id: <20090420181436.61AE.A69D9226@jp.fujitsu.com> MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Date: Mon, 20 Apr 2009 18:24:31 +0900 (JST) Sender: owner-linux-mm@kvack.org To: Huang Shijie Cc: kosaki.motohiro@jp.fujitsu.com, Minchan Kim , linux-mm@kvack.org List-ID: > In the V4L2_MEMORY_USERPTR method, what I want to do is pin the > anonymous pages in memory. > > I used to add the VM_LOCKED to vma associated with the pages.In my > opinion, the pages will: > LRU_ACTIVE_ANON ---> LRU_INACTIVE_ANON---> LRU_UNEVICTABLE > > so the pages are pinned in memory.It was ugly, but it works I think. > Do you have any suggestions about this method? page migration (e.g. move_pages) ignore MLOCK. maybe, VM_LOCKED + gut()ed solved it partially :) but, user process still can call munlock. it cause disaster. I still think -EINVAL is better. -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail143.messagelabs.com (mail143.messagelabs.com [216.82.254.35]) by kanga.kvack.org (Postfix) with SMTP id B2C385F0001 for ; Mon, 20 Apr 2009 05:48:21 -0400 (EDT) Received: by rv-out-0708.google.com with SMTP id f25so1395903rvb.26 for ; Mon, 20 Apr 2009 02:49:06 -0700 (PDT) Message-ID: <49EC44C6.1010603@gmail.com> Date: Mon, 20 Apr 2009 17:47:50 +0800 From: Huang Shijie MIME-Version: 1.0 Subject: Re: Does get_user_pages_fast lock the user pages in memory in my case? References: <20090420165529.61AB.A69D9226@jp.fujitsu.com> <49EC311D.4090605@gmail.com> <20090420181436.61AE.A69D9226@jp.fujitsu.com> In-Reply-To: <20090420181436.61AE.A69D9226@jp.fujitsu.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Sender: owner-linux-mm@kvack.org To: KOSAKI Motohiro Cc: Minchan Kim , linux-mm@kvack.org, Huang Shijie List-ID: KOSAKI Motohiro a??e??: >> In the V4L2_MEMORY_USERPTR method, what I want to do is pin the >> anonymous pages in memory. >> >> I used to add the VM_LOCKED to vma associated with the pages.In my >> opinion, the pages will: >> LRU_ACTIVE_ANON ---> LRU_INACTIVE_ANON---> LRU_UNEVICTABLE >> >> so the pages are pinned in memory.It was ugly, but it works I think. >> Do you have any suggestions about this method? >> > > page migration (e.g. move_pages) ignore MLOCK. > maybe, VM_LOCKED + gut()ed solved it partially :) > > My old codes used the get_user_pages()/VM_LOCKED just as you said. I will read the migration code, I am not clear about why the gup() can stop the migraion. > but, user process still can call munlock. it cause disaster. > I still think -EINVAL is better. > > > Why the user process call munlock? VLC or Mplayer do not call it, so I don't worry about that. Our video card is still not on sale.So I can wait until the bug is fixed. :) If there is no method to bypass the problem in future,I will return -EINVAL. thanks > > -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail143.messagelabs.com (mail143.messagelabs.com [216.82.254.35]) by kanga.kvack.org (Postfix) with SMTP id 99D836B003D for ; Mon, 20 Apr 2009 21:42:39 -0400 (EDT) Received: from m2.gw.fujitsu.co.jp ([10.0.50.72]) by fgwmail6.fujitsu.co.jp (Fujitsu Gateway) with ESMTP id n3L1hHoE012432 for (envelope-from kosaki.motohiro@jp.fujitsu.com); Tue, 21 Apr 2009 10:43:17 +0900 Received: from smail (m2 [127.0.0.1]) by outgoing.m2.gw.fujitsu.co.jp (Postfix) with ESMTP id 7D7F245DE51 for ; Tue, 21 Apr 2009 10:43:17 +0900 (JST) Received: from s2.gw.fujitsu.co.jp (s2.gw.fujitsu.co.jp [10.0.50.92]) by m2.gw.fujitsu.co.jp (Postfix) with ESMTP id 5CA6845DD79 for ; Tue, 21 Apr 2009 10:43:17 +0900 (JST) Received: from s2.gw.fujitsu.co.jp (localhost.localdomain [127.0.0.1]) by s2.gw.fujitsu.co.jp (Postfix) with ESMTP id 4863B1DB8038 for ; Tue, 21 Apr 2009 10:43:17 +0900 (JST) Received: from m108.s.css.fujitsu.com (m108.s.css.fujitsu.com [10.249.87.108]) by s2.gw.fujitsu.co.jp (Postfix) with ESMTP id EE01E1DB803B for ; Tue, 21 Apr 2009 10:43:13 +0900 (JST) From: KOSAKI Motohiro Subject: Re: Does get_user_pages_fast lock the user pages in memory in my case? In-Reply-To: <49EC44C6.1010603@gmail.com> References: <20090420181436.61AE.A69D9226@jp.fujitsu.com> <49EC44C6.1010603@gmail.com> Message-Id: <20090421104225.F116.A69D9226@jp.fujitsu.com> MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Date: Tue, 21 Apr 2009 10:43:13 +0900 (JST) Sender: owner-linux-mm@kvack.org To: Huang Shijie Cc: kosaki.motohiro@jp.fujitsu.com, Minchan Kim , linux-mm@kvack.org List-ID: > > but, user process still can call munlock. it cause disaster. > > I still think -EINVAL is better. > > > Why the user process call munlock? VLC or Mplayer do not call it, so I > don't worry about that. > > Our video card is still not on sale.So I can wait until the bug is fixed. :) > If there is no method to bypass the problem in future,I will return -EINVAL. We don't assume any userspace behavior in kernel. but you can ignore our recommendation, of cource :) -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail190.messagelabs.com (mail190.messagelabs.com [216.82.249.51]) by kanga.kvack.org (Postfix) with SMTP id 0897C6B003D for ; Tue, 21 Apr 2009 15:54:46 -0400 (EDT) Received: from localhost (smtp.ultrahosting.com [127.0.0.1]) by smtp.ultrahosting.com (Postfix) with ESMTP id 82C5982C703 for ; Tue, 21 Apr 2009 16:06:02 -0400 (EDT) Received: from smtp.ultrahosting.com ([74.213.174.254]) by localhost (smtp.ultrahosting.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id fJoOGggPfQ7m for ; Tue, 21 Apr 2009 16:06:02 -0400 (EDT) Received: from qirst.com (unknown [74.213.171.31]) by smtp.ultrahosting.com (Postfix) with ESMTP id C6E8982C709 for ; Tue, 21 Apr 2009 16:05:57 -0400 (EDT) Date: Tue, 21 Apr 2009 15:47:35 -0400 (EDT) From: Christoph Lameter Subject: Re: Does get_user_pages_fast lock the user pages in memory in my case? In-Reply-To: <49EC44C6.1010603@gmail.com> Message-ID: References: <20090420165529.61AB.A69D9226@jp.fujitsu.com> <49EC311D.4090605@gmail.com> <20090420181436.61AE.A69D9226@jp.fujitsu.com> <49EC44C6.1010603@gmail.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-linux-mm@kvack.org To: Huang Shijie Cc: KOSAKI Motohiro , Minchan Kim , linux-mm@kvack.org List-ID: On Mon, 20 Apr 2009, Huang Shijie wrote: > I will read the migration code, I am not clear about why the gup() can stop > the migraion. Because it increases the refcount of the page. Page migration is then unable to account for all the references to a page and therefore the page cannot be migrated. -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail137.messagelabs.com (mail137.messagelabs.com [216.82.249.19]) by kanga.kvack.org (Postfix) with SMTP id 111CB6B009F for ; Wed, 22 Apr 2009 02:09:56 -0400 (EDT) Received: by wa-out-1112.google.com with SMTP id v27so1316628wah.22 for ; Tue, 21 Apr 2009 23:10:05 -0700 (PDT) Message-ID: <49EEB46D.90802@gmail.com> Date: Wed, 22 Apr 2009 14:08:45 +0800 From: Huang Shijie MIME-Version: 1.0 Subject: Re: Does get_user_pages_fast lock the user pages in memory in my case? References: <49E8292D.7050904@gmail.com> <20090420084533.7f701e16.minchan.kim@barrios-desktop> <49EBDADB.4040307@gmail.com> <20090420114236.dda3de34.minchan.kim@barrios-desktop> In-Reply-To: <20090420114236.dda3de34.minchan.kim@barrios-desktop> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Sender: owner-linux-mm@kvack.org To: Minchan Kim Cc: linux-mm@kvack.org, KOSAKI Motohiro List-ID: >> I read the kernel code again. In my case ,the kernel will pin the pages >> in memory. >> I missed function is_page_cache_freeable() in the pageout(). >> >> In my case, is_page_cache_freeable()will return false ,for >> page_count(page) is 3 now: >> <1> one is from alloc_page_* in page fault. >> <2> one is from get_usr_pages() >> <3> one is from add_to_swap() in shrink_page_list() >> > > One more, try_to_unmap will call page_cache_release. > So, count is 2. > > I found I missed something.When code reachs is_page_cache_freeable(). page_count(page) is 3: <1> alloc_page_* in page fault . [page count is 1] <2> get_usr_pages(). [page count is 2] <3> isolate_pages_global() [page count is 3] <4> add_to_swap() [page count is 4] <5> try_to_unmap() [page count is 3] so it not a bug, just a vicious circle. Do i miss something? -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail202.messagelabs.com (mail202.messagelabs.com [216.82.254.227]) by kanga.kvack.org (Postfix) with SMTP id C0C656B00A7 for ; Wed, 22 Apr 2009 05:46:10 -0400 (EDT) Received: by rv-out-0708.google.com with SMTP id f25so2144668rvb.26 for ; Wed, 22 Apr 2009 02:46:53 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <49EEB46D.90802@gmail.com> References: <49E8292D.7050904@gmail.com> <20090420084533.7f701e16.minchan.kim@barrios-desktop> <49EBDADB.4040307@gmail.com> <20090420114236.dda3de34.minchan.kim@barrios-desktop> <49EEB46D.90802@gmail.com> Date: Wed, 22 Apr 2009 18:46:52 +0900 Message-ID: <28c262360904220246q6be8167fxd44fa21936070e4b@mail.gmail.com> Subject: Re: Does get_user_pages_fast lock the user pages in memory in my case? From: Minchan Kim Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Sender: owner-linux-mm@kvack.org To: Huang Shijie Cc: linux-mm@kvack.org, KOSAKI Motohiro List-ID: On Wed, Apr 22, 2009 at 3:08 PM, Huang Shijie wrote: > >>> I read the kernel code again. In my case ,the kernel will pin the pages >>> in memory. >>> I missed function is_page_cache_freeable() in the pageout(). >>> >>> In my case, is_page_cache_freeable()will return false ,for >>> page_count(page) is 3 now: >>> <1> one is from alloc_page_* in page fault. >>> <2> one is from get_usr_pages() >>> <3> one is from add_to_swap() in shrink_page_list() >>> >> >> One more, try_to_unmap will call page_cache_release. So, count is 2. >> > > I found I missed something.When code reachs is_page_cache_freeable(). > page_count(page) is 3: > > <1> alloc_page_* in page fault . [page count is 1] > <2> get_usr_pages(). =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 [page coun= t is 2] > <3> isolate_pages_global() =C2=A0 =C2=A0 =C2=A0 [page count is 3] > <4> add_to_swap() =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= [page count is 4] > <5> try_to_unmap() =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 [page= count is 3] > Yes. It seems you're right. I missed isolate. ;-; Thanks for fixing me. > so it not a bug, just a vicious circle. > > Do i miss something? > > > --=20 Kinds regards, Minchan Kim -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org