From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965764AbbKDUzU (ORCPT ); Wed, 4 Nov 2015 15:55:20 -0500 Received: from gum.cmpxchg.org ([85.214.110.215]:41558 "EHLO gum.cmpxchg.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965730AbbKDUzS (ORCPT ); Wed, 4 Nov 2015 15:55:18 -0500 Date: Wed, 4 Nov 2015 15:55:04 -0500 From: Johannes Weiner To: Minchan Kim Cc: Andrew Morton , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Michael Kerrisk , linux-api@vger.kernel.org, Hugh Dickins , zhangyanfei@cn.fujitsu.com, Rik van Riel , Mel Gorman , KOSAKI Motohiro , Jason Evans , Daniel Micay , "Kirill A. Shutemov" , Michal Hocko , yalin.wang2010@gmail.com, Shaohua Li , "Wang, Yalin" Subject: Re: [PATCH 5/8] mm: move lazily freed pages to inactive list Message-ID: <20151104205504.GA9927@cmpxchg.org> References: <1446188504-28023-1-git-send-email-minchan@kernel.org> <1446188504-28023-6-git-send-email-minchan@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1446188504-28023-6-git-send-email-minchan@kernel.org> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Oct 30, 2015 at 04:01:41PM +0900, Minchan Kim wrote: > MADV_FREE is a hint that it's okay to discard pages if there is memory > pressure and we use reclaimers(ie, kswapd and direct reclaim) to free them > so there is no value keeping them in the active anonymous LRU so this > patch moves them to inactive LRU list's head. > > This means that MADV_FREE-ed pages which were living on the inactive list > are reclaimed first because they are more likely to be cold rather than > recently active pages. > > An arguable issue for the approach would be whether we should put the page > to the head or tail of the inactive list. I chose head because the kernel > cannot make sure it's really cold or warm for every MADV_FREE usecase but > at least we know it's not *hot*, so landing of inactive head would be a > comprimise for various usecases. Even if we're wrong about the aging of those MADV_FREE pages, their contents are invalidated; they can be discarded freely, and restoring them is a mere GFP_ZERO allocation. All other anonymous pages have to be written to disk, and potentially be read back. [ Arguably, MADV_FREE pages should even be reclaimed before inactive page cache. It's the same cost to discard both types of pages, but restoring page cache involves IO. ] It probably makes sense to stop thinking about them as anonymous pages entirely at this point when it comes to aging. They're really not. The LRU lists are split to differentiate access patterns and cost of page stealing (and restoring). From that angle, MADV_FREE pages really have nothing in common with in-use anonymous pages, and so they shouldn't be on the same LRU list. That would also fix the very unfortunate and unexpected consequence of tying the lazy free optimization to the availability of swap space. I would prefer to see this addressed before the code goes upstream. From mboxrd@z Thu Jan 1 00:00:00 1970 From: Johannes Weiner Subject: Re: [PATCH 5/8] mm: move lazily freed pages to inactive list Date: Wed, 4 Nov 2015 15:55:04 -0500 Message-ID: <20151104205504.GA9927@cmpxchg.org> References: <1446188504-28023-1-git-send-email-minchan@kernel.org> <1446188504-28023-6-git-send-email-minchan@kernel.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Content-Disposition: inline In-Reply-To: <1446188504-28023-6-git-send-email-minchan-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> Sender: linux-api-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org To: Minchan Kim Cc: Andrew Morton , linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-mm-Bw31MaZKKs3YtjvyW6yDsg@public.gmane.org, Michael Kerrisk , linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, Hugh Dickins , zhangyanfei-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org, Rik van Riel , Mel Gorman , KOSAKI Motohiro , Jason Evans , Daniel Micay , "Kirill A. Shutemov" , Michal Hocko , yalin.wang2010-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org, Shaohua Li , "Wang, Yalin" List-Id: linux-api@vger.kernel.org On Fri, Oct 30, 2015 at 04:01:41PM +0900, Minchan Kim wrote: > MADV_FREE is a hint that it's okay to discard pages if there is memory > pressure and we use reclaimers(ie, kswapd and direct reclaim) to free them > so there is no value keeping them in the active anonymous LRU so this > patch moves them to inactive LRU list's head. > > This means that MADV_FREE-ed pages which were living on the inactive list > are reclaimed first because they are more likely to be cold rather than > recently active pages. > > An arguable issue for the approach would be whether we should put the page > to the head or tail of the inactive list. I chose head because the kernel > cannot make sure it's really cold or warm for every MADV_FREE usecase but > at least we know it's not *hot*, so landing of inactive head would be a > comprimise for various usecases. Even if we're wrong about the aging of those MADV_FREE pages, their contents are invalidated; they can be discarded freely, and restoring them is a mere GFP_ZERO allocation. All other anonymous pages have to be written to disk, and potentially be read back. [ Arguably, MADV_FREE pages should even be reclaimed before inactive page cache. It's the same cost to discard both types of pages, but restoring page cache involves IO. ] It probably makes sense to stop thinking about them as anonymous pages entirely at this point when it comes to aging. They're really not. The LRU lists are split to differentiate access patterns and cost of page stealing (and restoring). From that angle, MADV_FREE pages really have nothing in common with in-use anonymous pages, and so they shouldn't be on the same LRU list. That would also fix the very unfortunate and unexpected consequence of tying the lazy free optimization to the availability of swap space. I would prefer to see this addressed before the code goes upstream. From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wi0-f180.google.com (mail-wi0-f180.google.com [209.85.212.180]) by kanga.kvack.org (Postfix) with ESMTP id 1BCEB82F64 for ; Wed, 4 Nov 2015 15:55:20 -0500 (EST) Received: by wicll6 with SMTP id ll6so97952879wic.0 for ; Wed, 04 Nov 2015 12:55:19 -0800 (PST) Received: from gum.cmpxchg.org (gum.cmpxchg.org. [85.214.110.215]) by mx.google.com with ESMTPS id b66si5424254wmf.33.2015.11.04.12.55.18 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 04 Nov 2015 12:55:19 -0800 (PST) Date: Wed, 4 Nov 2015 15:55:04 -0500 From: Johannes Weiner Subject: Re: [PATCH 5/8] mm: move lazily freed pages to inactive list Message-ID: <20151104205504.GA9927@cmpxchg.org> References: <1446188504-28023-1-git-send-email-minchan@kernel.org> <1446188504-28023-6-git-send-email-minchan@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1446188504-28023-6-git-send-email-minchan@kernel.org> Sender: owner-linux-mm@kvack.org List-ID: To: Minchan Kim Cc: Andrew Morton , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Michael Kerrisk , linux-api@vger.kernel.org, Hugh Dickins , zhangyanfei@cn.fujitsu.com, Rik van Riel , Mel Gorman , KOSAKI Motohiro , Jason Evans , Daniel Micay , "Kirill A. Shutemov" , Michal Hocko , yalin.wang2010@gmail.com, Shaohua Li , "Wang, Yalin" On Fri, Oct 30, 2015 at 04:01:41PM +0900, Minchan Kim wrote: > MADV_FREE is a hint that it's okay to discard pages if there is memory > pressure and we use reclaimers(ie, kswapd and direct reclaim) to free them > so there is no value keeping them in the active anonymous LRU so this > patch moves them to inactive LRU list's head. > > This means that MADV_FREE-ed pages which were living on the inactive list > are reclaimed first because they are more likely to be cold rather than > recently active pages. > > An arguable issue for the approach would be whether we should put the page > to the head or tail of the inactive list. I chose head because the kernel > cannot make sure it's really cold or warm for every MADV_FREE usecase but > at least we know it's not *hot*, so landing of inactive head would be a > comprimise for various usecases. Even if we're wrong about the aging of those MADV_FREE pages, their contents are invalidated; they can be discarded freely, and restoring them is a mere GFP_ZERO allocation. All other anonymous pages have to be written to disk, and potentially be read back. [ Arguably, MADV_FREE pages should even be reclaimed before inactive page cache. It's the same cost to discard both types of pages, but restoring page cache involves IO. ] It probably makes sense to stop thinking about them as anonymous pages entirely at this point when it comes to aging. They're really not. The LRU lists are split to differentiate access patterns and cost of page stealing (and restoring). From that angle, MADV_FREE pages really have nothing in common with in-use anonymous pages, and so they shouldn't be on the same LRU list. That would also fix the very unfortunate and unexpected consequence of tying the lazy free optimization to the availability of swap space. I would prefer to see this addressed before the code goes upstream. -- 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