Re: [PATCH 7/8] vrange: Add method to purge volatile ranges

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello John,

I am rewriting purging path and found a bug from this patch.
I might forget it so I will send this comment for recording.

On Tue, Jun 11, 2013 at 09:22:50PM -0700, John Stultz wrote:
> From: Minchan Kim <minchan@xxxxxxxxxx>
> 
> This patch adds discarding function to purge volatile ranges under
> memory pressure. Logic is as following:
> 
> 1. Memory pressure happens
> 2. VM start to reclaim pages
> 3. Check the page is in volatile range.
> 4. If so, zap the page from the process's page table.
>    (By semantic vrange(2), we should mark it with another one to
>     make page fault when you try to access the address. It will
>     be introduced later patch)
> 5. If page is unmapped from all processes, discard it instead of swapping.
> 
> This patch does not address the case where there is no swap, which
> keeps anonymous pages from being aged off the LRUs. Minchan has
> additional patches that add support for purging anonymous pages
> 
> XXX: First pass at file purging. Seems to work, but is likely broken
> and needs close review.
> 
> Cc: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
> Cc: Android Kernel Team <kernel-team@xxxxxxxxxxx>
> Cc: Robert Love <rlove@xxxxxxxxxx>
> Cc: Mel Gorman <mel@xxxxxxxxx>
> Cc: Hugh Dickins <hughd@xxxxxxxxxx>
> Cc: Dave Hansen <dave@xxxxxxxxxxxxxxxxxx>
> Cc: Rik van Riel <riel@xxxxxxxxxx>
> Cc: Dmitry Adamushko <dmitry.adamushko@xxxxxxxxx>
> Cc: Dave Chinner <david@xxxxxxxxxxxxx>
> Cc: Neil Brown <neilb@xxxxxxx>
> Cc: Andrea Righi <andrea@xxxxxxxxxxxxxxx>
> Cc: Andrea Arcangeli <aarcange@xxxxxxxxxx>
> Cc: Aneesh Kumar K.V <aneesh.kumar@xxxxxxxxxxxxxxxxxx>
> Cc: Mike Hommey <mh@xxxxxxxxxxxx>
> Cc: Taras Glek <tglek@xxxxxxxxxxx>
> Cc: Dhaval Giani <dgiani@xxxxxxxxxxx>
> Cc: Jan Kara <jack@xxxxxxx>
> Cc: KOSAKI Motohiro <kosaki.motohiro@xxxxxxxxx>
> Cc: Michel Lespinasse <walken@xxxxxxxxxx>
> Cc: Minchan Kim <minchan@xxxxxxxxxx>
> Cc: linux-mm@xxxxxxxxx <linux-mm@xxxxxxxxx>
> Signed-off-by: Minchan Kim <minchan@xxxxxxxxxx>
> [jstultz: Reworked to add purging of file pages, commit log tweaks]
> Signed-off-by: John Stultz <john.stultz@xxxxxxxxxx>
> ---
>  include/linux/rmap.h   |  12 +-
>  include/linux/swap.h   |   1 +
>  include/linux/vrange.h |   7 ++
>  mm/ksm.c               |   2 +-
>  mm/rmap.c              |  30 +++--
>  mm/swapfile.c          |  36 ++++++
>  mm/vmscan.c            |  16 ++-
>  mm/vrange.c            | 332 +++++++++++++++++++++++++++++++++++++++++++++++++
>  8 files changed, 420 insertions(+), 16 deletions(-)
> 
> diff --git a/include/linux/rmap.h b/include/linux/rmap.h
> index 6dacb93..6432dfb 100644
> --- a/include/linux/rmap.h
> +++ b/include/linux/rmap.h
> @@ -83,6 +83,8 @@ enum ttu_flags {
>  };
>  

< snip >

> @@ -662,7 +663,7 @@ int page_mapped_in_vma(struct page *page, struct vm_area_struct *vma)
>   */
>  int page_referenced_one(struct page *page, struct vm_area_struct *vma,
>  			unsigned long address, unsigned int *mapcount,
> -			unsigned long *vm_flags)
> +			unsigned long *vm_flags, int *is_vrange)
>  {
>  	struct mm_struct *mm = vma->vm_mm;
>  	int referenced = 0;
> @@ -724,6 +725,9 @@ int page_referenced_one(struct page *page, struct vm_area_struct *vma,
>  				referenced++;
>  		}
>  		pte_unmap_unlock(pte, ptl);
> +		if (is_vrange &&
> +			vrange_address(mm, address, address + PAGE_SIZE - 1))
> +			*is_vrange = 1;

< snip >

> +static bool __vrange_address(struct vrange_root *vroot,
> +			unsigned long start, unsigned long end)
> +{
> +	struct interval_tree_node *node;
> +
> +	node = interval_tree_iter_first(&vroot->v_rb, start, end);
> +	return node ? true : false;
> +}
> +
> +bool vrange_address(struct mm_struct *mm,
> +			unsigned long start, unsigned long end)
> +{
> +	struct vrange_root *vroot;
> +	unsigned long vstart_idx, vend_idx;
> +	struct vm_area_struct *vma;
> +	bool ret;
> +
> +	vma = find_vma(mm, start);

It seems to be tweaked by you while you are refactoring with file-vrange
The problem of the code is that you couldn't use vma without holding
the lock of mmap_sem and you couldn't use the lock in purging path
because you couldn't know other tasks's state so it might be a dealock
if you try to hold a lock.

> +	if (vma->vm_file && (vma->vm_flags & VM_SHARED)) {
> +		vroot = &vma->vm_file->f_mapping->vroot;
> +		vstart_idx = vma->vm_pgoff + start - vma->vm_start;
> +		vend_idx = vma->vm_pgoff + end - vma->vm_start;
> +	} else {
> +		vroot = &mm->vroot;
> +		vstart_idx = start;
> +		vend_idx = end;
> +	}
> +
> +	vrange_lock(vroot);
> +	ret = __vrange_address(vroot, vstart_idx, vend_idx);
> +	vrange_unlock(vroot);
> +	return ret;
> +}
> +
-- 
Kind regards,
Minchan Kim

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@xxxxxxxxx.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@xxxxxxxxx";> email@xxxxxxxxx </a>




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]