Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp3993627ybh; Tue, 6 Aug 2019 04:45:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqz6AqT9qWK4VbB1jdItjMeVNzLeUF1YZjHKYN+QYNgAdG3Cn84tR0Wvgn8KITLTzjm+NA5W X-Received: by 2002:a17:90b:d8b:: with SMTP id bg11mr2824164pjb.30.1565091899964; Tue, 06 Aug 2019 04:44:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565091899; cv=none; d=google.com; s=arc-20160816; b=Ro3Mv0K58AFLNMsfEZ1CTPIkiQFgBLmz+K8odLs/m57kB37i61YyyppQzD5lz1Wqmi elO5dgsn9ky645L3pYhbEFaNgqsT0ZFPel2J73loO3f6GrUEtJ1LWFLlAqAAqWNU0Q/F dc2M5Gzcv8FiHxZzSGRipTFuRVlPe3iGbLxvGQbiepzZgx3oYjx46V+WAAQMAkgt/G0f 9Du+JsfG7GRef4zVSiGGuEVLC5hKzSVS3bFtXxfB4OpvMYrA1acDPsOX5g3HSSJSDedi XKKzUodbLwA3ucJOuyLCsYRMQ1gPOxJuEjbZqj0abFskCcUDnaKehlP7B6Nw+f3wsXqL ln+A== 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=M7xwBBk2ijoFEX0YRfTFXOfgVxiJM6mtXulCPGec2C0=; b=MMrTDZmSCO+s0f5RSjgTFnY3YV7Xp3aXfrfKS868FVHwhc8jIoR7pjYbxkhSdHL556 kkCu0Y7aArfUKQ6POZgSElwg4n743SReyl8wHsnLImvlfgKHIFNmszFCkoa7zMRLMm60 NOMk2IZv+wCAVceI04WrmAhSHSKW1+5oV9IU5WSkFKcOpsA9XShfyE42sz/FFhJzlhYN 8LUJiFewDdOD9E+YsnVU9+o1DOpk+wTxpfs1VLem8SG7SR9Y3rKce7Z27fe3uX2v7aPU e8IFqMIhih1hRCYVHKJbfcNb01umh6ocr07+u4MTko/f5WTaLgsA3W7Js83rUwZaDtPn Hl0Q== 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 bj5si41912419plb.227.2019.08.06.04.44.43; Tue, 06 Aug 2019 04:44:59 -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 S1730472AbfHFLoH (ORCPT + 99 others); Tue, 6 Aug 2019 07:44:07 -0400 Received: from mx2.suse.de ([195.135.220.15]:58590 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726783AbfHFLoH (ORCPT ); Tue, 6 Aug 2019 07:44:07 -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 0656EAF59; Tue, 6 Aug 2019 11:44:04 +0000 (UTC) Date: Tue, 6 Aug 2019 13:44:02 +0200 From: Michal Hocko To: Joel Fernandes 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: <20190806114402.GX11812@dhcp22.suse.cz> References: <20190805170451.26009-1-joel@joelfernandes.org> <20190805170451.26009-4-joel@joelfernandes.org> <20190806084357.GK11812@dhcp22.suse.cz> <20190806104554.GB218260@google.com> <20190806105149.GT11812@dhcp22.suse.cz> <20190806111921.GB117316@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190806111921.GB117316@google.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 On Tue 06-08-19 07:19:21, Joel Fernandes wrote: > On Tue, Aug 06, 2019 at 12:51:49PM +0200, Michal Hocko wrote: > > On Tue 06-08-19 06:45:54, Joel Fernandes wrote: > > > 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 belongs to the changelog. > > Sure, will add. > > > > > 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? > > > > Can we set the idle bit also for non-lru pages as long as they are > > reachable via pte? > > Not at the moment with the current page idle tracking code. PageLRU(page) > flag is checked in page_idle_get_page(). yes, I am aware of the current code. I strongly suspect that the PageLRU check was there to not mark arbitrary page looked up by pfn with the idle bit because that would be unexpected. But I might be easily wrong here. > Even if we could set it for non-LRU, the idle bit (page flag) would not be > cleared if page is not on LRU because page-reclaim code (page_referenced() I > believe) would not clear it. Yes, it is either reclaim when checking references as you say but also mark_page_accessed. I believe the later might still have the page on the pcp LRU add cache. Maybe I am missing something something but it seems that there is nothing fundamentally requiring the user mapped page to be on the LRU list when seting the idle bit. That being said, your big hammer approach will work more reliable but if you do not feel like changing the underlying PageLRU assumption then document that draining should be removed longterm. -- Michal Hocko SUSE Labs