Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1608213yba; Sat, 6 Apr 2019 17:46:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqyftK8GF5BhUYoMgPAaz+u82ufbOT99bSIaiTfjE8eLPEXDUv4OUPZ0X95iucLmjT+Gm9t5 X-Received: by 2002:a63:494f:: with SMTP id y15mr20673868pgk.56.1554597980633; Sat, 06 Apr 2019 17:46:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554597980; cv=none; d=google.com; s=arc-20160816; b=enJUADTat+MX5ttcu+UmJCgXtscYybinZzvk+7tBZAhxxvdVHkxTnLWL41PW1i/FDe /J7cHNJArx7sNBqtVCmW9DTItQNdRkcp2RVNLWxEdK1i3YM+fy0r8fLhc20aCprpYOFH dYx1hrnrG3SbHgWkWx221GEdJXhcSUvnGs+0fI8fgds1SQBUT0+Lm9L2zJfdMf3av7tu I/Da0JhXMeracE9MkibSAfLdM5jEMhQUYsV3f3PsAAR8KyGbCNherzUA5uyvr9ZhH+gn Z8xpf8EnsSKazZU9fTS6CuhRwc4gOcKfLBM0wBz591Ahf8is0CQiJxiQ9FpaYPYORUA2 +mYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=bNsqfdQNBfHjyXIGV8C12WgnaMuuVXlb2SSFxsHHfG8=; b=DrhBLCitxNP7Ng5kLQWIzP+W1ZW4QpGas9rr9qy1clNgsaV3IyryrtNQ3pZHKrxNwU IyBbo8D0bfCcv41BG8F6WAv3xCw6c+zkJgVuET9Fz7Noh4lfStEroVhWOHEXdiWr+uRY BcPqYrYAusiDp5GJsERNarDXi8YhCkkSeT+LfX0n/5Prz+rOJ4F1/1Bw5DE7UOeQZPQi WnsvT2h6n5pK4sq/7ym4sEPU5DqivqJjZ/PW6iNUakJjf8QQvqwuhPOqBMkGwFDvOr23 o2sCEF63bMoeXz2b88G7DxeXb4qLSAnyefBsrBrLfz0uaSFK6wOh2JlKcwkpxOfdWzK3 asjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=mN0D6qW7; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a7si21429565pgt.496.2019.04.06.17.46.04; Sat, 06 Apr 2019 17:46:20 -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; dkim=pass header.i=@google.com header.s=20161025 header.b=mN0D6qW7; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726411AbfDGAnk (ORCPT + 99 others); Sat, 6 Apr 2019 20:43:40 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:52189 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726144AbfDGAnk (ORCPT ); Sat, 6 Apr 2019 20:43:40 -0400 Received: by mail-wm1-f67.google.com with SMTP id 4so10391180wmf.1 for ; Sat, 06 Apr 2019 17:43:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=bNsqfdQNBfHjyXIGV8C12WgnaMuuVXlb2SSFxsHHfG8=; b=mN0D6qW7g35is4a2WGB+jmFlKNC88Q6qdutNQHtkLf+TX5BIJWXmt4AbJLRxYybMlS EV+KP1TA2u8rlXQcwYk5K7ngg3HP3aVWgp0XY03oenL020WfomGRMzGV29YPol6cyUjR zPdcU9ystDG8p07xEtyWPir26zzORUFjGIaIvSIoPoxL4Ec+ibUo9HSZdq+ko8MihD6D Lx4PTDpDKmaq1gkJwtMkrgLqdBigGU450vfFKiI9KPLmzrKdEqzBL36EkLOeq0aG+l9g SMqKY4wJpBGU9azGiDF/DRVkLjSAVccK2B/55DRxmDDDLMUgiShCzTY/8s8Ao6ny9My7 ScTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=bNsqfdQNBfHjyXIGV8C12WgnaMuuVXlb2SSFxsHHfG8=; b=MCNt4yZCpQZJGhkSaImjal0rIGTrbTC2yfzD0UqN/XQp1W8fYdwhubLZU9zHFvY5TH 1uP325hOBNwcuNu61wS6oZ6FRsuytg9yJtflRbalwaRWlP5yNUrmmsD35gc6eQypCnLU fZFubO19Bpv3mm36I5piaLzV9MVZoKnrNiPjzGb0rwO1aXfhaPO1kG89k9JA1Wf2I2MR AOz9acsC0xy0WvdmA6ikP+o/9vm1F/LA4mFQtkSLnAfFCGErHTstxmNk6NVpjNvF//uf vGIfbQsBOftwvsMDMbA5isRgZrn/cpfCIPut2ufYONesKhRITwoaxLqIuBykxAtGFYZR ctVg== X-Gm-Message-State: APjAAAWnK5qckpgt1TqduHcZVTj/U1sBHjlvOlXMeawrlOH2yBJg5lEB DdO2Sr3wJSNvDc2OSVHq9DFrsUtvL7qhg1FICu+emQ== X-Received: by 2002:a05:600c:2118:: with SMTP id u24mr12728182wml.24.1554597817349; Sat, 06 Apr 2019 17:43:37 -0700 (PDT) MIME-Version: 1.0 References: <1554343303-11880-1-git-send-email-huangzhaoyang@gmail.com> In-Reply-To: <1554343303-11880-1-git-send-email-huangzhaoyang@gmail.com> From: Suren Baghdasaryan Date: Sat, 6 Apr 2019 17:43:26 -0700 Message-ID: Subject: Re: [PATCH] mm:workingset use real time to judge activity of the file page To: Zhaoyang Huang Cc: Andrew Morton , Vlastimil Babka , Pavel Tatashin , Joonsoo Kim , David Rientjes , Roman Gushchin , Jeff Layton , Matthew Wilcox , linux-mm , LKML Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Apr 3, 2019 at 7:03 PM 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. > We introduce the timestamp into the workingset's entry to measure > the file page's activity. > > 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; I also wonder how many times the division above yields a 0... > + refault_time = jiffies - prev_jiff; > + avg_refault_time = refault_distance / lruvec->refaults_ratio; and then used here as a denominator. > + 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 >