From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.3 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 69F04C31E40 for ; Tue, 6 Aug 2019 10:45:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3EEAF20818 for ; Tue, 6 Aug 2019 10:45:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=joelfernandes.org header.i=@joelfernandes.org header.b="BK0x5edz" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732650AbfHFKp5 (ORCPT ); Tue, 6 Aug 2019 06:45:57 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:46892 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730844AbfHFKp4 (ORCPT ); Tue, 6 Aug 2019 06:45:56 -0400 Received: by mail-pg1-f196.google.com with SMTP id w3so4175820pgt.13 for ; Tue, 06 Aug 2019 03:45:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=ABKgADdiGa23iy+5xy09f6OBQqR3I/07f0qdbQrp2Ug=; b=BK0x5edz5Iheer/fK6xR02+EYpWEe73+fBNaVu3psDyEfFgQR4iTDEjMX3llLyVbBQ oo5c2wtKKMdHq+s0dbGvvCrA28tZJ7WgRbNvmF9B9TCPhzQEMI365I16VRvzSe8CiyqZ ulIdft17U/LPUUnWy2+R0724GxrzxbZjJPUj8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=ABKgADdiGa23iy+5xy09f6OBQqR3I/07f0qdbQrp2Ug=; b=ZN03eDvIdXCg+JbgGO4GvUl268LNLd71ikiPOryX/pK9a339isnczUJeJv3z3KARQw hNkpdFHluL+8ir8SrqjL4lJDCM6pwKGLcR95l6v2CRcfsjxUp52WU+4HH6cb5GM9txJv TwWWx3PrHOyju13e2RMZ0QUSnccp/t1caQQy/jeaUwXSwuRdQrqPyoTw9WM7tI8Uo+GJ 4RuYZ50ThF/HKb2TiSPwPVpQitl3enGbfAvGVmiboczx0DDVIuXywDM7pRhKut0Mf2U0 RDg94hwZjC2o+D444Q3WZAY3ZvVzujzvxNVb7lgps6eFqOoFI+8r6iXQktR88MWgzb0H HVUg== X-Gm-Message-State: APjAAAXJWr8LxCoegUTBlJPVrk4u5gREVpOoJlmaGVKmDRzmPNVyrG1i gELKD4kB0RvOCOnqAl4Ob+pKLA== X-Google-Smtp-Source: APXvYqyKhAOOvSnRzmdX9OiAK7Cu7h4b/c73qpWbsn3JUV5APW6ELiBP2MjwevD8QijB6PWnNqvwJA== X-Received: by 2002:aa7:90d4:: with SMTP id k20mr2919746pfk.78.1565088356112; Tue, 06 Aug 2019 03:45:56 -0700 (PDT) Received: from localhost ([2620:15c:6:12:9c46:e0da:efbf:69cc]) by smtp.gmail.com with ESMTPSA id b126sm126571952pfa.126.2019.08.06.03.45.54 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 06 Aug 2019 03:45:55 -0700 (PDT) Date: Tue, 6 Aug 2019 06:45:54 -0400 From: Joel Fernandes To: Michal Hocko Cc: linux-kernel@vger.kernel.org, Alexey Dobriyan , Andrew Morton , Borislav Petkov , Brendan Gregg , Catalin Marinas , Christian Hansen , dancol@google.com, fmayer@google.com, "H. Peter Anvin" , Ingo Molnar , Jonathan Corbet , Kees Cook , kernel-team@android.com, linux-api@vger.kernel.org, linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, Mike Rapoport , minchan@kernel.org, namhyung@google.com, paulmck@linux.ibm.com, Robin Murphy , Roman Gushchin , Stephen Rothwell , surenb@google.com, Thomas Gleixner , tkjos@google.com, Vladimir Davydov , Vlastimil Babka , Will Deacon Subject: Re: [PATCH v4 4/5] page_idle: Drain all LRU pagevec before idle tracking Message-ID: <20190806104554.GB218260@google.com> References: <20190805170451.26009-1-joel@joelfernandes.org> <20190805170451.26009-4-joel@joelfernandes.org> <20190806084357.GK11812@dhcp22.suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190806084357.GK11812@dhcp22.suse.cz> 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 On Tue, Aug 06, 2019 at 10:43:57AM +0200, Michal Hocko wrote: > On Mon 05-08-19 13:04:50, Joel Fernandes (Google) wrote: > > During idle tracking, we see that sometimes faulted anon pages are in > > pagevec but are not drained to LRU. Idle tracking considers pages only > > on LRU. Drain all CPU's LRU before starting idle tracking. > > Please expand on why does this matter enough to introduce a potentially > expensinve draining which has to schedule a work on each CPU and wait > for them to finish. Sure, I can expand. I am able to find multiple issues involving this. One issue looks like idle tracking is completely broken. It shows up in my testing as if a page that is marked as idle is always "accessed" -- because it was never marked as idle (due to not draining of pagevec). The other issue shows up as a failure in my "swap test", with the following sequence: 1. Allocate some pages 2. Write to them 3. Mark them as idle <--- fails 4. Introduce some memory pressure to induce swapping. 5. Check the swap bit I introduced in this series. <--- fails to set idle bit in swap PTE. Draining the pagevec in advance fixes both of these issues. This operation even if expensive is only done once during the access of the page_idle file. Did you have a better fix in mind? thanks, - Joel > > Signed-off-by: Joel Fernandes (Google) > > --- > > mm/page_idle.c | 6 ++++++ > > 1 file changed, 6 insertions(+) > > > > diff --git a/mm/page_idle.c b/mm/page_idle.c > > index a5b00d63216c..2972367a599f 100644 > > --- a/mm/page_idle.c > > +++ b/mm/page_idle.c > > @@ -180,6 +180,8 @@ static ssize_t page_idle_bitmap_read(struct file *file, struct kobject *kobj, > > unsigned long pfn, end_pfn; > > int bit, ret; > > > > + lru_add_drain_all(); > > + > > ret = page_idle_get_frames(pos, count, NULL, &pfn, &end_pfn); > > if (ret == -ENXIO) > > return 0; /* Reads beyond max_pfn do nothing */ > > @@ -211,6 +213,8 @@ static ssize_t page_idle_bitmap_write(struct file *file, struct kobject *kobj, > > unsigned long pfn, end_pfn; > > int bit, ret; > > > > + lru_add_drain_all(); > > + > > ret = page_idle_get_frames(pos, count, NULL, &pfn, &end_pfn); > > if (ret) > > return ret; > > @@ -428,6 +432,8 @@ ssize_t page_idle_proc_generic(struct file *file, char __user *ubuff, > > walk.private = &priv; > > walk.mm = mm; > > > > + lru_add_drain_all(); > > + > > down_read(&mm->mmap_sem); > > > > /* > > -- > > 2.22.0.770.g0f2c4a37fd-goog > > -- > Michal Hocko > SUSE Labs