transfering pages from user space to user space
Hi: I am working on a project to copy (page aligned) the buffer content of one process to the buffer of other process. Now I resolved this issue using copy_page() but, analizing performance with different buffer sizes, the "copy_page" becames the critical time component and limiting factor. I read some articles about, COW, zero copy and page flipping and I wrote a kernel code to implement page "transfer" (only copy page references), but that code fail and hang. The kernel I use is 2.6.32. The pseudocode I think is: pte_t *src_pte, *dst_pte; src_pte = getpte(src_task); dst_pte = getpte(dst_task); free_pte(dst_pte); /*to free the page referenced by this PTE */ *dst_pte = *src_pte; /*copy source PTE to destination PTE */ And here is code added to the kernel: ------------------------------------------------------------------------------------------------------------- len = PAGE_SIZE; src_vma=find_vma_intersection(src_proc->p_task->mm,src_addr,src_addr+len); dst_vma=find_vma_intersection(dst_proc->p_task->mm,dst_addr,dst_addr+len); src_pgd=pgd_offset(src_proc->p_task->mm, (unsigned long) src_addr); src_pud=pud_offset(src_pgd,(unsigned long) src_addr); src_pmd=pmd_offset(src_pud,(unsigned long) src_addr); src_pte=pte_offset_map_lock(src_proc->p_task->mm, src_pmd,(unsigned long) src_addr, &src_ptl); dst_pgd=pgd_offset(dst_proc->p_task->mm, (unsigned long) dst_addr); dst_pud=pud_offset(dst_pgd,(unsigned long) dst_addr); dst_pmd=pmd_offset(dst_pud,(unsigned long) dst_addr); dst_pte=pte_offset_map_lock(dst_proc->p_task->mm, dst_pmd,(unsigned long) dst_addr, &dst_ptl); pte_free(dst_proc->p_task->mm, dst_pte); copy_pte_range(dst_proc->p_task->mm, src_proc->p_task->mm, dst_pmd, src_pmd, dst_vma, (unsigned long) dst_addr, ((unsigned long)dst_addr+PAGE_SIZE)); spin_unlock(src_ptl); spin_unlock(dst_ptl); ------------------------------------------------------------------------------------------------------------- There are a lots of kernel functions that are not well documented or they have been changed. Can anybody help me with this issue? Does COW (Copy On Write) will make the copy when the processes will modify their buffers? I am not suscribed to the mailing list, please CC: the answers to this email account. Thanks in Advance. I apologize for my basic English. Pablo Pessolani PD: once finishing with that code, some issues about page protection will be considered.
Hi, Le mercredi 05 décembre 2012 à 22:47 -0300, Pablo Pessolani a écrit :
Hi: I am working on a project to copy (page aligned) the buffer content of one process to the buffer of other process.
Now I resolved this issue using copy_page() but, analizing performance with different buffer sizes, the "copy_page" becames the critical time component and limiting factor.
This sounds a lot like "Cross Memory Support" (eg CROSS_MEMORY_ATTACH option) introduced in Linux 3.2: http://kernelnewbies.org/Linux_3.2#head-a5e26c6275e85a5c9c41873fbab96bd38d93... Cross Memory Support add two syscalls: - process_vm_readv() : read from a process memory - process_vm_writev() : write to a process memory Details can be found here: http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commitdif... And documentation here: http://www.man7.org/linux/man-pages/man2/process_vm_readv.2.html http://ozlabs.org/~cyeoh/cma/process_vm_readv.txt
[...] The kernel I use is 2.6.32.
BTW, why use a kernel released 3 years ago for such new development ? Kernel 2.6.32 was released the 3rd of december 2009. Even the -rt project switch to newer kernel (eg. no less than 3.0, and up to 3.4), see http://rt.wiki.kernel.org/ You should at least switch to a current long term support kernels, for example Linux 3.4. See http://www.kroah.com/log/linux/stable-status-08-2012.html Regards -- Yann Droneaud OPTEYA
Hi:
This sounds a lot like "Cross Memory Support" (eg CROSS_MEMORY_ATTACH option) introduced in Linux 3.2:
http://kernelnewbies.org/Linux_3.2#head-a5e26c6275e85a5c9c41873fbab96bd38d93...
Cross Memory Support add two syscalls: - process_vm_readv() : read from a process memory - process_vm_writev() : write to a process memory
Details can be found here:
http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commitdif...
And documentation here:
http://www.man7.org/linux/man-pages/man2/process_vm_readv.2.html http://ozlabs.org/~cyeoh/cma/process_vm_readv.txt
GREAT! I will study these documentation and source code.
[...] The kernel I use is 2.6.32.
BTW, why use a kernel released 3 years ago for such new development ? Kernel 2.6.32 was released the 3rd of december 2009. Even the -rt project switch to newer kernel (eg. no less than 3.0, and up to 3.4), see http://rt.wiki.kernel.org/
You should at least switch to a current long term support kernels, for example Linux 3.4. See http://www.kroah.com/log/linux/stable-status-08-2012.html
Because I use the stable distribution of Debian and all the packages for kernel modules and kernel building are for these version as you can see: Package kernel-image-2.6.32-5-486-di squeeze (stable) (debian-installer): Linux kernel binary image for the Debian installer 1.99+squeeze8: i386 Thanks Yann Droneaud PAP
Hi Yann: Reading the patch source code I find that the pages from one user space to other are "copied" 102 if (vm_write) 103 ret = copy_from_user(target_kaddr, 104 lvec[*lvec_current].iov_base 105 + *lvec_offset, 106 bytes_to_copy); 107 else 108 ret = copy_to_user(lvec[*lvec_current].iov_base 109 + *lvec_offset, 110 target_kaddr, bytes_to_copy); The code I wrote (very similar to this) also copies page contents. But my interest is transfering pages (zero-copy). Regards. PAP
Subject: Re: transfering pages from user space to user space From: ydroneaud@opteya.com To: ppessolani@hotmail.com Date: Thu, 6 Dec 2012 10:30:27 +0100 CC: kernelnewbies@kernelnewbies.org
Hi,
Le mercredi 05 décembre 2012 à 22:47 -0300, Pablo Pessolani a écrit :
Hi: I am working on a project to copy (page aligned) the buffer content of one process to the buffer of other process.
Now I resolved this issue using copy_page() but, analizing performance with different buffer sizes, the "copy_page" becames the critical time component and limiting factor.
This sounds a lot like "Cross Memory Support" (eg CROSS_MEMORY_ATTACH option) introduced in Linux 3.2:
http://kernelnewbies.org/Linux_3.2#head-a5e26c6275e85a5c9c41873fbab96bd38d93...
Cross Memory Support add two syscalls: - process_vm_readv() : read from a process memory - process_vm_writev() : write to a process memory
Details can be found here:
http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commitdif...
And documentation here:
http://www.man7.org/linux/man-pages/man2/process_vm_readv.2.html http://ozlabs.org/~cyeoh/cma/process_vm_readv.txt
[...] The kernel I use is 2.6.32.
BTW, why use a kernel released 3 years ago for such new development ? Kernel 2.6.32 was released the 3rd of december 2009. Even the -rt project switch to newer kernel (eg. no less than 3.0, and up to 3.4), see http://rt.wiki.kernel.org/
You should at least switch to a current long term support kernels, for example Linux 3.4. See http://www.kroah.com/log/linux/stable-status-08-2012.html
Regards
-- Yann Droneaud OPTEYA
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
participants (2)
-
Pablo Pessolani -
Yann Droneaud