Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932739Ab2EVAIe (ORCPT ); Mon, 21 May 2012 20:08:34 -0400 Received: from mail-we0-f174.google.com ([74.125.82.174]:34915 "EHLO mail-we0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932253Ab2EVAIc convert rfc822-to-8bit (ORCPT ); Mon, 21 May 2012 20:08:32 -0400 MIME-Version: 1.0 In-Reply-To: References: Date: Mon, 21 May 2012 17:08:29 -0700 X-Google-Sender-Auth: QNXI5dNPEA2hExzCV4LQhnB2Kdc Message-ID: Subject: Re: [PATCH 5/10] mm/fs: route MADV_REMOVE to FALLOC_FL_PUNCH_HOLE From: john stultz To: Hugh Dickins , =?ISO-8859-1?Q?Arve_Hj=F8nnev=E5g?= Cc: Andrew Morton , Christoph Hellwig , Cong Wang , Al Viro , Colin Cross , John Stulz , Greg Kroah-Hartman , "Theodore Ts'o" , Andreas Dilger , Mark Fasheh , Joel Becker , Dave Chinner , Ben Myers , Michael Kerrisk , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4610 Lines: 111 On Sat, May 12, 2012 at 5:13 AM, Hugh Dickins wrote: > Now tmpfs supports hole-punching via fallocate(), switch madvise_remove() > to use do_fallocate() instead of vmtruncate_range(): which extends > madvise(,,MADV_REMOVE) support from tmpfs to ext4, ocfs2 and xfs. > > There is one more user of vmtruncate_range() in our tree, staging/android's > ashmem_shrink(): convert it to use do_fallocate() too (but if its unpinned > areas are already unmapped - I don't know - then it would do better to use > shmem_truncate_range() directly). I suspect shmem_truncate_range directly would be the right approach, but am not totally sure. Arve: Any thoughts? Hugh: Do you have a git tree with this set available somewhere? I was working on my own tmpfs support for FALLOC_FL_PUNCH_HOLE, along with my volatile range work, so I'd like to rebase on top of your work here. thanks -john > > Based-on-patch-by: Cong Wang > Signed-off-by: Hugh Dickins > --- > ?drivers/staging/android/ashmem.c | ? ?8 +++++--- > ?mm/madvise.c ? ? ? ? ? ? ? ? ? ? | ? 15 +++++++-------- > ?2 files changed, 12 insertions(+), 11 deletions(-) > > --- 3045N.orig/drivers/staging/android/ashmem.c 2012-05-05 10:42:33.564056626 -0700 > +++ 3045N/drivers/staging/android/ashmem.c ? ? ?2012-05-05 10:46:25.692062478 -0700 > @@ -19,6 +19,7 @@ > ?#include > ?#include > ?#include > +#include > ?#include > ?#include > ?#include > @@ -363,11 +364,12 @@ static int ashmem_shrink(struct shrinker > > ? ? ? ?mutex_lock(&ashmem_mutex); > ? ? ? ?list_for_each_entry_safe(range, next, &ashmem_lru_list, lru) { > - ? ? ? ? ? ? ? struct inode *inode = range->asma->file->f_dentry->d_inode; > ? ? ? ? ? ? ? ?loff_t start = range->pgstart * PAGE_SIZE; > - ? ? ? ? ? ? ? loff_t end = (range->pgend + 1) * PAGE_SIZE - 1; > + ? ? ? ? ? ? ? loff_t end = (range->pgend + 1) * PAGE_SIZE; > > - ? ? ? ? ? ? ? vmtruncate_range(inode, start, end); > + ? ? ? ? ? ? ? do_fallocate(range->asma->file, > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? start, end - start); > ? ? ? ? ? ? ? ?range->purged = ASHMEM_WAS_PURGED; > ? ? ? ? ? ? ? ?lru_del(range); > > --- 3045N.orig/mm/madvise.c ? ? 2012-05-05 10:42:33.572056784 -0700 > +++ 3045N/mm/madvise.c ?2012-05-05 10:46:25.692062478 -0700 > @@ -11,8 +11,10 @@ > ?#include > ?#include > ?#include > +#include > ?#include > ?#include > +#include > > ?/* > ?* Any behaviour which results in changes to the vma->vm_flags needs to > @@ -200,8 +202,7 @@ static long madvise_remove(struct vm_are > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?struct vm_area_struct **prev, > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?unsigned long start, unsigned long end) > ?{ > - ? ? ? struct address_space *mapping; > - ? ? ? loff_t offset, endoff; > + ? ? ? loff_t offset; > ? ? ? ?int error; > > ? ? ? ?*prev = NULL; ? /* tell sys_madvise we drop mmap_sem */ > @@ -217,16 +218,14 @@ static long madvise_remove(struct vm_are > ? ? ? ?if ((vma->vm_flags & (VM_SHARED|VM_WRITE)) != (VM_SHARED|VM_WRITE)) > ? ? ? ? ? ? ? ?return -EACCES; > > - ? ? ? mapping = vma->vm_file->f_mapping; > - > ? ? ? ?offset = (loff_t)(start - vma->vm_start) > ? ? ? ? ? ? ? ? ? ? ? ?+ ((loff_t)vma->vm_pgoff << PAGE_SHIFT); > - ? ? ? endoff = (loff_t)(end - vma->vm_start - 1) > - ? ? ? ? ? ? ? ? ? ? ? + ((loff_t)vma->vm_pgoff << PAGE_SHIFT); > > - ? ? ? /* vmtruncate_range needs to take i_mutex */ > + ? ? ? /* filesystem's fallocate may need to take i_mutex */ > ? ? ? ?up_read(¤t->mm->mmap_sem); > - ? ? ? error = vmtruncate_range(mapping->host, offset, endoff); > + ? ? ? error = do_fallocate(vma->vm_file, > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? offset, end - start); > ? ? ? ?down_read(¤t->mm->mmap_sem); > ? ? ? ?return error; > ?} > -- > To unsubscribe from this list: send the line "unsubscribe linux-kernel" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at ?http://vger.kernel.org/majordomo-info.html > Please read the FAQ at ?http://www.tux.org/lkml/ -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/