From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752160AbdBJRbb (ORCPT ); Fri, 10 Feb 2017 12:31:31 -0500 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:42743 "EHLO mx0b-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751519AbdBJRb1 (ORCPT ); Fri, 10 Feb 2017 12:31:27 -0500 Date: Fri, 10 Feb 2017 09:30:09 -0800 From: Shaohua Li To: Minchan Kim CC: , , , , , , , , , Subject: Re: [PATCH V2 2/7] mm: move MADV_FREE pages into LRU_INACTIVE_FILE list Message-ID: <20170210173008.GA86050@shli-mbp.local> References: <3914c9f53c343357c39cb891210da31aa30ad3a9.1486163864.git.shli@fb.com> <20170210065022.GC25078@bbox> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <20170210065022.GC25078@bbox> User-Agent: Mutt/1.6.1 (2016-04-27) X-Originating-IP: [2620:10d:c090:200::d:7cca] X-ClientProxiedBy: BN6PR1401CA0023.namprd14.prod.outlook.com (10.174.237.161) To CY4PR15MB1637.namprd15.prod.outlook.com (10.175.119.149) X-MS-Office365-Filtering-Correlation-Id: cb959513-bf0a-45a5-592b-08d451da7ca8 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001);SRVR:CY4PR15MB1637; X-Microsoft-Exchange-Diagnostics: 1;CY4PR15MB1637;3:nDPQy79WlHY9HuWx4lfmnZDBt3PsDvE1R9DR6ngIP6xMBExu/O6AHp+mOjOz0+S6IMdJDzgfpNIL6WB6sICY+E9Ly2U15PQyj0CWVJg6+127Dam8Pu8ONa1cr8Mv6/bBMnnOIAo8I8sZJlFjRpSgJbwA8iTykJG2r+Am7H0OsaR0DNiOCgX82xkuRP1FxGmiCyTzcxwEOhF6z8xeAW6NSw9vRspKohY4GLie+5U80Eavd5WeIugHBa2hPmxYtVlaCtGsg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KqT04HhaWfuc+R3f4sUiAzZdrDm/rLsrgAFa1LzCoYCuCPb34cRMBgit5DGZa6CFcVN0CnXNf/6AyDSHhBWyLjtU+YoDN8y9cQBMFg/lhTzbNg2nG+6c0KbydRrbOalM6XBsctnp5GrfbVsZM30SM98LURmXLD/ibKvppr/eFARRd0riaD7TtZO59VtXIHETAPlRo2WRRFgZ+MUC5UiraRl+RhBM X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(67672495146484)(211936372134217); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040375)(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046)(6041248)(20161123555025)(20161123560025)(20161123564025)(20161123562025)(20161123558025)(6072148);SRVR:CY4PR15MB1637;BCL:0;PCL:0;RULEID:;SRVR:CY4PR15MB1637; X-Microsoft-Exchange-Diagnostics: 1;CY4PR15MB1637;4:df8JTCKrsNdpwYpn8jZ8m+rxPcEgP2pVqLsXCeq1L9amgeeivJXkJw7mqiKurOOk6hQKMXzEAfTieQ30H+6XqN25qXV1CgPtE9lNrMf8z+cIUlbSHouEzqH4bSuI7bC3GCzoETQGGMhM9YwB9Ibhj5qckLTvK8ZSaWL3de71Y6Qfq1eEgBlagXCO+QupDqoD8V0jDcz6vTajo2Z9vapUoUBbWmtF/6GX7xdToPC74/zfk5sTo0SZR6cwEEjX6/XDOn2wfSy92t7mLp/O8ex/MY9Dr7+oQoJfnjOCbiV5uTHiCh5Z8ikOC8bn375uiR1LhRDSJwxzCEed7vvA3hpQKH5kSJmuptmVmMOTE+kq3bUVuXMTVw5Yk46nySPtxHRiQJru6RUnHN4TCs+9rPOktcIdpTRw9eAWpMsTAM6+ntI2NQ5FQmimKbMbRy4tcegxP6grABxm8jYon19U9WaHOwB/xE1Nliz5h0xlwkrBOCvHTIhkxtpDMXzppufb9VAz/RM1LGtZxn3NZzs7n0DUFC32Vitf85gpYKyHvdlJZW7eTlJXefjlyiBLZt0EO2DHKyUCl/OtYPEfJh1Id65/qZKkdXEDHITlP+rJhXWse3A64bobtfhOrrIF/cIVfTIpx/UvzbYYQGZyQ+C/02VN38GzJtfT+0EwthEivvhDiwa9QraZyeZj1DKyQHPcEaZQ X-Forefront-PRVS: 0214EB3F68 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(4630300001)(6009001)(7916002)(39830400002)(39410400002)(39450400003)(199003)(189002)(24454002)(33656002)(54356999)(97756001)(23726003)(46406003)(1076002)(105586002)(76176999)(50986999)(101416001)(92566002)(6916009)(6246003)(189998001)(53936002)(6116002)(47776003)(6666003)(2950100002)(98436002)(42186005)(5660300001)(50466002)(8676002)(305945005)(39060400001)(4001350100001)(106356001)(7416002)(81156014)(86362001)(4326007)(97736004)(6506006)(229853002)(81166006)(9686003)(2906002)(7736002)(54906002)(55016002)(110136004)(83506001)(25786008)(38730400002)(68736007)(18370500001);DIR:OUT;SFP:1102;SCL:1;SRVR:CY4PR15MB1637;H:shli-mbp.local;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;CY4PR15MB1637;23:9gd4w4bJchPtT0P+LZohQcMlfeybaFrFwN7Mh0Rw/?= =?us-ascii?Q?p2vHVOJ4BSMsG32a9AK6t2jddC9RkfKcYdrDs5osRyyJQEmHYOZMvKDN2V58?= =?us-ascii?Q?wmxB3FqCzOFZ01NR8Q/3RaMxNpbJmfwyYCmkNPc/+5EEurIf7qDENF4hFHyb?= =?us-ascii?Q?ipA2wL/pirxDMPGFgXU7eZk2v+XndfgyCzpIu0QbEr+1FFeFRivGodgdakFV?= =?us-ascii?Q?GR0UUt4XlH9T460EQFW70fxiaYTi/XDm/kSrVfKAJc0qTT7E+zkL7qcDKGYH?= =?us-ascii?Q?VkIn6yyjOTlSS475VUxCQFY2yqF/nt2b6U0LTOYZo4GMTN4149Xgb6mv0nKR?= =?us-ascii?Q?hfPNMVUTIPAnOalv8XfKR6W9lSC+JFLMEri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1SD+3GdXxoKd82Xjs+2ju3Qabf/KGG0M3wW+yuNp2v4rhoBrONbi8K6lcFr6fDXWibk8j/0XvbRet9lX5kQ83anvWL8yqKAplRp8qW1qpXrTv5ahcjua9ZkI5nqH7/dqVSrJoysZOo5BT3OpycopWfWAtEB8iIeGHgPH9dEB8liOdLd31GIFfg5Rske1WIyoWxZwHPFnvjJdLU4vX2/VS135poqlNeuFvgaN54h9xDb6Nn6SKHY09fI4xqcLln/cN7e2qMeCAHkqMb93vMHE3L3JDiFyojPrhCKaahKmbBlYyZEqEzAZrLp4+vaUOzOXQL+3/WvA1lrArZ01e90tam51uZgoMa/4CP+PAn0fyzgAFpRkkBo1EtVjw39dPmg4Vb2QV84Bezn/yZ+nQtzgb61HcA==;20:vniQgIcj9lajoqCtbPdMQq1wKIZNsCBkw0XIRS7h80UunnxosQ0aIFQq+RfnrBv0NA98cEyhf/megKTqi3Zd97wRXU7fTsqUDya/QJ78YhdWdGe+LNfUgE0WyrOqkQPQvUXmu9/+6ocYwaTiBTfcBpx4BCGti63Xs815In8/AR4= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Feb 2017 17:30:18.3985 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR15MB1637 X-OriginatorOrg: fb.com X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-02-10_07:,, signatures=0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Feb 10, 2017 at 03:50:22PM +0900, Minchan Kim wrote: > Hi Shaohua, Thanks for your time! > On Fri, Feb 03, 2017 at 03:33:18PM -0800, Shaohua Li wrote: > > Userspace indicates MADV_FREE pages could be freed without pageout, so > > it pretty much likes used once file pages. For such pages, we'd like to > > reclaim them once there is memory pressure. Also it might be unfair > > reclaiming MADV_FREE pages always before used once file pages and we > > definitively want to reclaim the pages before other anonymous and file > > pages. > > > > To speed up MADV_FREE pages reclaim, we put the pages into > > LRU_INACTIVE_FILE list. The rationale is LRU_INACTIVE_FILE list is tiny > > nowadays and should be full of used once file pages. Reclaiming > > MADV_FREE pages will not have much interfere of anonymous and active > > file pages. And the inactive file pages and MADV_FREE pages will be > > reclaimed according to their age, so we don't reclaim too many MADV_FREE > > pages too. Putting the MADV_FREE pages into LRU_INACTIVE_FILE_LIST also > > means we can reclaim the pages without swap support. This idea is > > suggested by Johannes. > > > > We also clear the pages SwapBacked flag to indicate they are MADV_FREE > > pages. > > I think this patch should be merged with 3/7. Otherwise, MADV_FREE will > be broken during the bisect. Maybe I should move the patch 3 ahead, then we won't break bisect and still make the patches clear. > > Cc: Michal Hocko > > Cc: Minchan Kim > > Cc: Hugh Dickins > > Cc: Johannes Weiner > > Cc: Rik van Riel > > Cc: Mel Gorman > > Cc: Andrew Morton > > Signed-off-by: Shaohua Li > > --- > > include/linux/mm_inline.h | 5 +++++ > > include/linux/swap.h | 2 +- > > include/linux/vm_event_item.h | 2 +- > > mm/huge_memory.c | 5 ++--- > > mm/madvise.c | 3 +-- > > mm/swap.c | 50 ++++++++++++++++++++++++------------------- > > mm/vmstat.c | 1 + > > 7 files changed, 39 insertions(+), 29 deletions(-) > > > > diff --git a/include/linux/mm_inline.h b/include/linux/mm_inline.h > > index e030a68..fdded06 100644 > > --- a/include/linux/mm_inline.h > > +++ b/include/linux/mm_inline.h > > @@ -22,6 +22,11 @@ static inline int page_is_file_cache(struct page *page) > > return !PageSwapBacked(page); > > } > > > > +static inline bool page_is_lazyfree(struct page *page) > > +{ > > + return PageAnon(page) && !PageSwapBacked(page); > > +} > > + > > trivial: > > How about using PageLazyFree for consistency with other PageXXX? > As well, use SetPageLazyFree/ClearPageLazyFree rather than using > raw {Set,Clear}PageSwapBacked. So SetPageLazyFree == ClearPageSwapBacked, that would be weird. I personally prefer directly using {Set, Clear}PageSwapBacked, because reader can immediately know what's happening. If using the PageLazyFree, people always need to refer the code and check the relationship between PageLazyFree and PageSwapBacked. > > static __always_inline void __update_lru_size(struct lruvec *lruvec, > > enum lru_list lru, enum zone_type zid, > > int nr_pages) > > diff --git a/include/linux/swap.h b/include/linux/swap.h > > index 45e91dd..486494e 100644 > > --- a/include/linux/swap.h > > +++ b/include/linux/swap.h > > @@ -279,7 +279,7 @@ extern void lru_add_drain_cpu(int cpu); > > extern void lru_add_drain_all(void); > > extern void rotate_reclaimable_page(struct page *page); > > extern void deactivate_file_page(struct page *page); > > -extern void deactivate_page(struct page *page); > > +extern void mark_page_lazyfree(struct page *page); > > trivial: > > How about "deactivate_lazyfree_page"? IMO, it would show intention > clear that move the lazy free page to inactive list. > > It's just matter of preference so I'm not strong against. Yes, I thought about the name a little bit. Don't think we should use deactivate, because it sounds that only works for active page, while the function works for both active/inactive pages. I'm open to any suggestions. > > extern void swap_setup(void); > > > > extern void add_page_to_unevictable_list(struct page *page); > > diff --git a/include/linux/vm_event_item.h b/include/linux/vm_event_item.h > > index 6aa1b6c..94e58da 100644 > > --- a/include/linux/vm_event_item.h > > +++ b/include/linux/vm_event_item.h > > @@ -25,7 +25,7 @@ enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT, > > FOR_ALL_ZONES(PGALLOC), > > FOR_ALL_ZONES(ALLOCSTALL), > > FOR_ALL_ZONES(PGSCAN_SKIP), > > - PGFREE, PGACTIVATE, PGDEACTIVATE, > > + PGFREE, PGACTIVATE, PGDEACTIVATE, PGLAZYFREE, > > PGFAULT, PGMAJFAULT, > > PGLAZYFREED, > > PGREFILL, > > diff --git a/mm/huge_memory.c b/mm/huge_memory.c > > index ecf569d..ddb9a94 100644 > > --- a/mm/huge_memory.c > > +++ b/mm/huge_memory.c > > @@ -1391,9 +1391,6 @@ bool madvise_free_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma, > > ClearPageDirty(page); > > unlock_page(page); > > > > - if (PageActive(page)) > > - deactivate_page(page); > > - > > if (pmd_young(orig_pmd) || pmd_dirty(orig_pmd)) { > > orig_pmd = pmdp_huge_get_and_clear_full(tlb->mm, addr, pmd, > > tlb->fullmm); > > @@ -1404,6 +1401,8 @@ bool madvise_free_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma, > > set_pmd_at(mm, addr, pmd, orig_pmd); > > tlb_remove_pmd_tlb_entry(tlb, pmd, addr); > > } > > + > > + mark_page_lazyfree(page); > > ret = true; > > out: > > spin_unlock(ptl); > > diff --git a/mm/madvise.c b/mm/madvise.c > > index c867d88..c24549e 100644 > > --- a/mm/madvise.c > > +++ b/mm/madvise.c > > @@ -378,10 +378,9 @@ static int madvise_free_pte_range(pmd_t *pmd, unsigned long addr, > > ptent = pte_mkclean(ptent); > > ptent = pte_wrprotect(ptent); > > set_pte_at(mm, addr, pte, ptent); > > - if (PageActive(page)) > > - deactivate_page(page); > > tlb_remove_tlb_entry(tlb, pte, addr); > > } > > + mark_page_lazyfree(page); > > } > > out: > > if (nr_swap) { > > diff --git a/mm/swap.c b/mm/swap.c > > index c4910f1..69a7e9d 100644 > > --- a/mm/swap.c > > +++ b/mm/swap.c > > @@ -46,7 +46,7 @@ int page_cluster; > > static DEFINE_PER_CPU(struct pagevec, lru_add_pvec); > > static DEFINE_PER_CPU(struct pagevec, lru_rotate_pvecs); > > static DEFINE_PER_CPU(struct pagevec, lru_deactivate_file_pvecs); > > -static DEFINE_PER_CPU(struct pagevec, lru_deactivate_pvecs); > > +static DEFINE_PER_CPU(struct pagevec, lru_lazyfree_pvecs); > > #ifdef CONFIG_SMP > > static DEFINE_PER_CPU(struct pagevec, activate_page_pvecs); > > #endif > > @@ -268,6 +268,11 @@ static void __activate_page(struct page *page, struct lruvec *lruvec, > > int lru = page_lru_base_type(page); > > > > del_page_from_lru_list(page, lruvec, lru); > > + if (page_is_lazyfree(page)) { > > + SetPageSwapBacked(page); > > + file = 0; > > I don't see why you set file with 0. Could you explain the rationale? We are moving the page back to active anonymous list, so I'd like to charge the recent_scanned and recent_rotated to anonymous. Thanks, Shaohua From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ua0-f197.google.com (mail-ua0-f197.google.com [209.85.217.197]) by kanga.kvack.org (Postfix) with ESMTP id 930E76B0038 for ; Fri, 10 Feb 2017 12:30:32 -0500 (EST) Received: by mail-ua0-f197.google.com with SMTP id j94so25550897uad.0 for ; Fri, 10 Feb 2017 09:30:32 -0800 (PST) Received: from mx0b-00082601.pphosted.com (mx0b-00082601.pphosted.com. [67.231.153.30]) by mx.google.com with ESMTPS id h23si711455vkc.174.2017.02.10.09.30.31 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 Feb 2017 09:30:31 -0800 (PST) Date: Fri, 10 Feb 2017 09:30:09 -0800 From: Shaohua Li Subject: Re: [PATCH V2 2/7] mm: move MADV_FREE pages into LRU_INACTIVE_FILE list Message-ID: <20170210173008.GA86050@shli-mbp.local> References: <3914c9f53c343357c39cb891210da31aa30ad3a9.1486163864.git.shli@fb.com> <20170210065022.GC25078@bbox> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <20170210065022.GC25078@bbox> Sender: owner-linux-mm@kvack.org List-ID: To: Minchan Kim Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Kernel-team@fb.com, danielmicay@gmail.com, mhocko@suse.com, hughd@google.com, hannes@cmpxchg.org, riel@redhat.com, mgorman@techsingularity.net, akpm@linux-foundation.org On Fri, Feb 10, 2017 at 03:50:22PM +0900, Minchan Kim wrote: > Hi Shaohua, Thanks for your time! > On Fri, Feb 03, 2017 at 03:33:18PM -0800, Shaohua Li wrote: > > Userspace indicates MADV_FREE pages could be freed without pageout, so > > it pretty much likes used once file pages. For such pages, we'd like to > > reclaim them once there is memory pressure. Also it might be unfair > > reclaiming MADV_FREE pages always before used once file pages and we > > definitively want to reclaim the pages before other anonymous and file > > pages. > > > > To speed up MADV_FREE pages reclaim, we put the pages into > > LRU_INACTIVE_FILE list. The rationale is LRU_INACTIVE_FILE list is tiny > > nowadays and should be full of used once file pages. Reclaiming > > MADV_FREE pages will not have much interfere of anonymous and active > > file pages. And the inactive file pages and MADV_FREE pages will be > > reclaimed according to their age, so we don't reclaim too many MADV_FREE > > pages too. Putting the MADV_FREE pages into LRU_INACTIVE_FILE_LIST also > > means we can reclaim the pages without swap support. This idea is > > suggested by Johannes. > > > > We also clear the pages SwapBacked flag to indicate they are MADV_FREE > > pages. > > I think this patch should be merged with 3/7. Otherwise, MADV_FREE will > be broken during the bisect. Maybe I should move the patch 3 ahead, then we won't break bisect and still make the patches clear. > > Cc: Michal Hocko > > Cc: Minchan Kim > > Cc: Hugh Dickins > > Cc: Johannes Weiner > > Cc: Rik van Riel > > Cc: Mel Gorman > > Cc: Andrew Morton > > Signed-off-by: Shaohua Li > > --- > > include/linux/mm_inline.h | 5 +++++ > > include/linux/swap.h | 2 +- > > include/linux/vm_event_item.h | 2 +- > > mm/huge_memory.c | 5 ++--- > > mm/madvise.c | 3 +-- > > mm/swap.c | 50 ++++++++++++++++++++++++------------------- > > mm/vmstat.c | 1 + > > 7 files changed, 39 insertions(+), 29 deletions(-) > > > > diff --git a/include/linux/mm_inline.h b/include/linux/mm_inline.h > > index e030a68..fdded06 100644 > > --- a/include/linux/mm_inline.h > > +++ b/include/linux/mm_inline.h > > @@ -22,6 +22,11 @@ static inline int page_is_file_cache(struct page *page) > > return !PageSwapBacked(page); > > } > > > > +static inline bool page_is_lazyfree(struct page *page) > > +{ > > + return PageAnon(page) && !PageSwapBacked(page); > > +} > > + > > trivial: > > How about using PageLazyFree for consistency with other PageXXX? > As well, use SetPageLazyFree/ClearPageLazyFree rather than using > raw {Set,Clear}PageSwapBacked. So SetPageLazyFree == ClearPageSwapBacked, that would be weird. I personally prefer directly using {Set, Clear}PageSwapBacked, because reader can immediately know what's happening. If using the PageLazyFree, people always need to refer the code and check the relationship between PageLazyFree and PageSwapBacked. > > static __always_inline void __update_lru_size(struct lruvec *lruvec, > > enum lru_list lru, enum zone_type zid, > > int nr_pages) > > diff --git a/include/linux/swap.h b/include/linux/swap.h > > index 45e91dd..486494e 100644 > > --- a/include/linux/swap.h > > +++ b/include/linux/swap.h > > @@ -279,7 +279,7 @@ extern void lru_add_drain_cpu(int cpu); > > extern void lru_add_drain_all(void); > > extern void rotate_reclaimable_page(struct page *page); > > extern void deactivate_file_page(struct page *page); > > -extern void deactivate_page(struct page *page); > > +extern void mark_page_lazyfree(struct page *page); > > trivial: > > How about "deactivate_lazyfree_page"? IMO, it would show intention > clear that move the lazy free page to inactive list. > > It's just matter of preference so I'm not strong against. Yes, I thought about the name a little bit. Don't think we should use deactivate, because it sounds that only works for active page, while the function works for both active/inactive pages. I'm open to any suggestions. > > extern void swap_setup(void); > > > > extern void add_page_to_unevictable_list(struct page *page); > > diff --git a/include/linux/vm_event_item.h b/include/linux/vm_event_item.h > > index 6aa1b6c..94e58da 100644 > > --- a/include/linux/vm_event_item.h > > +++ b/include/linux/vm_event_item.h > > @@ -25,7 +25,7 @@ enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT, > > FOR_ALL_ZONES(PGALLOC), > > FOR_ALL_ZONES(ALLOCSTALL), > > FOR_ALL_ZONES(PGSCAN_SKIP), > > - PGFREE, PGACTIVATE, PGDEACTIVATE, > > + PGFREE, PGACTIVATE, PGDEACTIVATE, PGLAZYFREE, > > PGFAULT, PGMAJFAULT, > > PGLAZYFREED, > > PGREFILL, > > diff --git a/mm/huge_memory.c b/mm/huge_memory.c > > index ecf569d..ddb9a94 100644 > > --- a/mm/huge_memory.c > > +++ b/mm/huge_memory.c > > @@ -1391,9 +1391,6 @@ bool madvise_free_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma, > > ClearPageDirty(page); > > unlock_page(page); > > > > - if (PageActive(page)) > > - deactivate_page(page); > > - > > if (pmd_young(orig_pmd) || pmd_dirty(orig_pmd)) { > > orig_pmd = pmdp_huge_get_and_clear_full(tlb->mm, addr, pmd, > > tlb->fullmm); > > @@ -1404,6 +1401,8 @@ bool madvise_free_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma, > > set_pmd_at(mm, addr, pmd, orig_pmd); > > tlb_remove_pmd_tlb_entry(tlb, pmd, addr); > > } > > + > > + mark_page_lazyfree(page); > > ret = true; > > out: > > spin_unlock(ptl); > > diff --git a/mm/madvise.c b/mm/madvise.c > > index c867d88..c24549e 100644 > > --- a/mm/madvise.c > > +++ b/mm/madvise.c > > @@ -378,10 +378,9 @@ static int madvise_free_pte_range(pmd_t *pmd, unsigned long addr, > > ptent = pte_mkclean(ptent); > > ptent = pte_wrprotect(ptent); > > set_pte_at(mm, addr, pte, ptent); > > - if (PageActive(page)) > > - deactivate_page(page); > > tlb_remove_tlb_entry(tlb, pte, addr); > > } > > + mark_page_lazyfree(page); > > } > > out: > > if (nr_swap) { > > diff --git a/mm/swap.c b/mm/swap.c > > index c4910f1..69a7e9d 100644 > > --- a/mm/swap.c > > +++ b/mm/swap.c > > @@ -46,7 +46,7 @@ int page_cluster; > > static DEFINE_PER_CPU(struct pagevec, lru_add_pvec); > > static DEFINE_PER_CPU(struct pagevec, lru_rotate_pvecs); > > static DEFINE_PER_CPU(struct pagevec, lru_deactivate_file_pvecs); > > -static DEFINE_PER_CPU(struct pagevec, lru_deactivate_pvecs); > > +static DEFINE_PER_CPU(struct pagevec, lru_lazyfree_pvecs); > > #ifdef CONFIG_SMP > > static DEFINE_PER_CPU(struct pagevec, activate_page_pvecs); > > #endif > > @@ -268,6 +268,11 @@ static void __activate_page(struct page *page, struct lruvec *lruvec, > > int lru = page_lru_base_type(page); > > > > del_page_from_lru_list(page, lruvec, lru); > > + if (page_is_lazyfree(page)) { > > + SetPageSwapBacked(page); > > + file = 0; > > I don't see why you set file with 0. Could you explain the rationale? We are moving the page back to active anonymous list, so I'd like to charge the recent_scanned and recent_rotated to anonymous. Thanks, Shaohua -- 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