Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754098AbbKLL00 (ORCPT ); Thu, 12 Nov 2015 06:26:26 -0500 Received: from mail-wm0-f50.google.com ([74.125.82.50]:36460 "EHLO mail-wm0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752679AbbKLL0Y (ORCPT ); Thu, 12 Nov 2015 06:26:24 -0500 Date: Thu, 12 Nov 2015 13:26:20 +0200 From: "Kirill A. Shutemov" To: Minchan Kim Cc: Andrew Morton , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Michael Kerrisk , linux-api@vger.kernel.org, Hugh Dickins , Johannes Weiner , Rik van Riel , Mel Gorman , KOSAKI Motohiro , Jason Evans , Daniel Micay , Shaohua Li , Michal Hocko , yalin.wang2010@gmail.com Subject: Re: [PATCH v3 01/17] mm: support madvise(MADV_FREE) Message-ID: <20151112112620.GB22481@node.shutemov.name> References: <1447302793-5376-1-git-send-email-minchan@kernel.org> <1447302793-5376-2-git-send-email-minchan@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1447302793-5376-2-git-send-email-minchan@kernel.org> User-Agent: Mutt/1.5.23.1 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2179 Lines: 84 On Thu, Nov 12, 2015 at 01:32:57PM +0900, Minchan Kim wrote: > @@ -256,6 +260,125 @@ static long madvise_willneed(struct vm_area_struct *vma, > return 0; > } > > +static int madvise_free_pte_range(pmd_t *pmd, unsigned long addr, > + unsigned long end, struct mm_walk *walk) > + > +{ > + struct mmu_gather *tlb = walk->private; > + struct mm_struct *mm = tlb->mm; > + struct vm_area_struct *vma = walk->vma; > + spinlock_t *ptl; > + pte_t *pte, ptent; > + struct page *page; > + > + split_huge_page_pmd(vma, addr, pmd); > + if (pmd_trans_unstable(pmd)) > + return 0; > + > + pte = pte_offset_map_lock(mm, pmd, addr, &ptl); > + arch_enter_lazy_mmu_mode(); > + for (; addr != end; pte++, addr += PAGE_SIZE) { > + ptent = *pte; > + > + if (!pte_present(ptent)) > + continue; > + > + page = vm_normal_page(vma, addr, ptent); > + if (!page) > + continue; > + > + if (PageSwapCache(page)) { Could you put VM_BUG_ON_PAGE(PageTransCompound(page), page) here? Just in case. > + if (!trylock_page(page)) > + continue; > + > + if (!try_to_free_swap(page)) { > + unlock_page(page); > + continue; > + } > + > + ClearPageDirty(page); > + unlock_page(page); Hm. Do we handle pages shared over fork() here? Souldn't we ignore pages with mapcount > 0? > + } > + > + if (pte_young(ptent) || pte_dirty(ptent)) { > + /* > + * Some of architecture(ex, PPC) don't update TLB > + * with set_pte_at and tlb_remove_tlb_entry so for > + * the portability, remap the pte with old|clean > + * after pte clearing. > + */ > + ptent = ptep_get_and_clear_full(mm, addr, pte, > + tlb->fullmm); > + > + ptent = pte_mkold(ptent); > + ptent = pte_mkclean(ptent); > + set_pte_at(mm, addr, pte, ptent); > + tlb_remove_tlb_entry(tlb, pte, addr); > + } > + } > + > + arch_leave_lazy_mmu_mode(); > + pte_unmap_unlock(pte - 1, ptl); > + cond_resched(); > + return 0; > +} > -- Kirill A. Shutemov -- 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/