Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp927105yba; Thu, 4 Apr 2019 00:16:39 -0700 (PDT) X-Google-Smtp-Source: APXvYqznFHCMVyCKu5QnT+qC4aRICdBAR+h+IgsZg3MKsvLV1ZRJ+BnSODFSQlANMZBRhPYQUAOM X-Received: by 2002:a65:410a:: with SMTP id w10mr4299716pgp.206.1554362199885; Thu, 04 Apr 2019 00:16:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554362199; cv=none; d=google.com; s=arc-20160816; b=ATD9QJryi131JRTXBsjkM93lSMdX8CaYiX+6LuzetFXv8Nx6gMqVLb2fY7VgcQ/SAf jgvPWAeb77b1DwXy7TkxgyEb4pnM0v8Fq3UeN7JPfjSccoNnTQOIGes/AAxl+rEQQx1R GQC1Fofbrv3sMKQUCfktZUxnliYdkITl5bwL1YPDt37yr+ehMMsjjazYowns8xAG0u8E FwdlRqJoic5s3kjIIgv19w1gxGVBuoBd8HQiEMLHSpsrCJ7xYkKp/7o/SgeLHZToRk/e WCqUhYEmYqcrTb8fyXnnpxF7aTpS3ea6g8nszhgkUw3pBdaMxjayqKWiynOnzHtDpA3N eMrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=71TPOxvlZ/WVFmxXgszLnCi/Vd26Rjr4Pz+pf4db6RM=; b=t1UkpSkT/dq+iRpb7My7XUZhcHRFpcSwKSpAG94sA1AN1mk7MbBzTpVuUo4cfcRbtx ry9Kd3hQKl2QFARr7c8wjt0mW0SrDWK7cStjgvbveJVn2N9nLOOOQmWAqkV0PN3Qecvb HnDQUtaQM/wlYFqujU5VGmLWV7SSc6qAWrcp7pNBlgl1rYl1/V5b5Xw+/lgo0y3Wngo9 ny4l1BI7G3PVTihg8yQx22Nqa6XQ7+iS1XsYZODztEDTluXoRFOqzADwvap7dFFsqTic U0yyNAaDQj8OK45WIBAU9xc2/0Z16yfOAMp3HtwTkNX/DyLSgBSdDWlQJrQUdXvqg26Q +FWQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l1si16628353pld.210.2019.04.04.00.16.24; Thu, 04 Apr 2019 00:16:39 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727171AbfDDHPR (ORCPT + 99 others); Thu, 4 Apr 2019 03:15:17 -0400 Received: from mx2.suse.de ([195.135.220.15]:44194 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726855AbfDDHPR (ORCPT ); Thu, 4 Apr 2019 03:15:17 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 06844AD2B; Thu, 4 Apr 2019 07:15:14 +0000 (UTC) Date: Thu, 4 Apr 2019 09:15:12 +0200 From: Michal Hocko To: Zhaoyang Huang Cc: Andrew Morton , Vlastimil Babka , Joonsoo Kim , David Rientjes , Zhaoyang Huang , Roman Gushchin , Jeff Layton , Matthew Wilcox , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Pavel Tatashin , Johannes Weiner Subject: Re: [PATCH] mm:workingset use real time to judge activity of the file page Message-ID: <20190404071512.GE12864@dhcp22.suse.cz> References: <1554348617-12897-1-git-send-email-huangzhaoyang@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1554348617-12897-1-git-send-email-huangzhaoyang@gmail.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [Fixup email for Pavel and add Johannes] On Thu 04-04-19 11:30:17, Zhaoyang Huang wrote: > From: Zhaoyang Huang > > In previous implementation, the number of refault pages is used > for judging the refault period of each page, which is not precised as > eviction of other files will be affect a lot on current cache. > We introduce the timestamp into the workingset's entry and refault ratio > to measure the file page's activity. It helps to decrease the affection > of other files(average refault ratio can reflect the view of whole system > 's memory). > The patch is tested on an Android system, which can be described as > comparing the launch time of an application between a huge memory > consumption. The result is launch time decrease 50% and the page fault > during the test decrease 80%. > > Signed-off-by: Zhaoyang Huang > --- > include/linux/mmzone.h | 2 ++ > mm/workingset.c | 24 +++++++++++++++++------- > 2 files changed, 19 insertions(+), 7 deletions(-) > > diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h > index 32699b2..c38ba0a 100644 > --- a/include/linux/mmzone.h > +++ b/include/linux/mmzone.h > @@ -240,6 +240,8 @@ struct lruvec { > atomic_long_t inactive_age; > /* Refaults at the time of last reclaim cycle */ > unsigned long refaults; > + atomic_long_t refaults_ratio; > + atomic_long_t prev_fault; > #ifdef CONFIG_MEMCG > struct pglist_data *pgdat; > #endif > diff --git a/mm/workingset.c b/mm/workingset.c > index 40ee02c..6361853 100644 > --- a/mm/workingset.c > +++ b/mm/workingset.c > @@ -159,7 +159,7 @@ > NODES_SHIFT + \ > MEM_CGROUP_ID_SHIFT) > #define EVICTION_MASK (~0UL >> EVICTION_SHIFT) > - > +#define EVICTION_JIFFIES (BITS_PER_LONG >> 3) > /* > * Eviction timestamps need to be able to cover the full range of > * actionable refaults. However, bits are tight in the radix tree > @@ -175,18 +175,22 @@ static void *pack_shadow(int memcgid, pg_data_t *pgdat, unsigned long eviction) > eviction >>= bucket_order; > eviction = (eviction << MEM_CGROUP_ID_SHIFT) | memcgid; > eviction = (eviction << NODES_SHIFT) | pgdat->node_id; > + eviction = (eviction << EVICTION_JIFFIES) | (jiffies >> EVICTION_JIFFIES); > eviction = (eviction << RADIX_TREE_EXCEPTIONAL_SHIFT); > > return (void *)(eviction | RADIX_TREE_EXCEPTIONAL_ENTRY); > } > > static void unpack_shadow(void *shadow, int *memcgidp, pg_data_t **pgdat, > - unsigned long *evictionp) > + unsigned long *evictionp, unsigned long *prev_jiffp) > { > unsigned long entry = (unsigned long)shadow; > int memcgid, nid; > + unsigned long prev_jiff; > > entry >>= RADIX_TREE_EXCEPTIONAL_SHIFT; > + entry >>= EVICTION_JIFFIES; > + prev_jiff = (entry & ((1UL << EVICTION_JIFFIES) - 1)) << EVICTION_JIFFIES; > nid = entry & ((1UL << NODES_SHIFT) - 1); > entry >>= NODES_SHIFT; > memcgid = entry & ((1UL << MEM_CGROUP_ID_SHIFT) - 1); > @@ -195,6 +199,7 @@ static void unpack_shadow(void *shadow, int *memcgidp, pg_data_t **pgdat, > *memcgidp = memcgid; > *pgdat = NODE_DATA(nid); > *evictionp = entry << bucket_order; > + *prev_jiffp = prev_jiff; > } > > /** > @@ -242,8 +247,12 @@ bool workingset_refault(void *shadow) > unsigned long refault; > struct pglist_data *pgdat; > int memcgid; > + unsigned long refault_ratio; > + unsigned long prev_jiff; > + unsigned long avg_refault_time; > + unsigned long refault_time; > > - unpack_shadow(shadow, &memcgid, &pgdat, &eviction); > + unpack_shadow(shadow, &memcgid, &pgdat, &eviction, &prev_jiff); > > rcu_read_lock(); > /* > @@ -288,10 +297,11 @@ bool workingset_refault(void *shadow) > * list is not a problem. > */ > refault_distance = (refault - eviction) & EVICTION_MASK; > - > inc_lruvec_state(lruvec, WORKINGSET_REFAULT); > - > - if (refault_distance <= active_file) { > + lruvec->refaults_ratio = atomic_long_read(&lruvec->inactive_age) / jiffies; > + refault_time = jiffies - prev_jiff; > + avg_refault_time = refault_distance / lruvec->refaults_ratio; > + if (refault_time <= avg_refault_time) { > inc_lruvec_state(lruvec, WORKINGSET_ACTIVATE); > rcu_read_unlock(); > return true; > @@ -521,7 +531,7 @@ static int __init workingset_init(void) > * some more pages at runtime, so keep working with up to > * double the initial memory by using totalram_pages as-is. > */ > - timestamp_bits = BITS_PER_LONG - EVICTION_SHIFT; > + timestamp_bits = BITS_PER_LONG - EVICTION_SHIFT - EVICTION_JIFFIES; > max_order = fls_long(totalram_pages - 1); > if (max_order > timestamp_bits) > bucket_order = max_order - timestamp_bits; > -- > 1.9.1 -- Michal Hocko SUSE Labs