Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp1473492ybj; Fri, 8 May 2020 02:05:29 -0700 (PDT) X-Google-Smtp-Source: APiQypJFxL9TDnVUuuAHuOlp/5XNYAkW2M0eaPBFc3FAwd/QWIZVXWm0bpkkd4HgCVw0FTvNP0YH X-Received: by 2002:a05:6402:711:: with SMTP id w17mr1296743edx.228.1588928729628; Fri, 08 May 2020 02:05:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588928729; cv=none; d=google.com; s=arc-20160816; b=yqsR5aVJbiBwwUQ1eOd5fjVYvFYXxTxwZzlqxhG/TxnhNVXneM9kYG9sd0a5/JsWoz VUrBkkmDAoMnFA/eaCVDUx8Zp4+eO51xP6sxQLhCZ0Go64P52ZT4SB6tKSIUMd0vAAQz fj07ZrmfW+rlcRofFAgJXMzqwa4I0lakioAr0N96sDg/7xKvhkt850w/Xi2R60+VcNz1 A0JP9+vn5v+p2NTHOY3N1eEdTC3UdnK2tA20VxAVZowD30RCHjLUsaLowmyDXcTHbfK8 dalieLAVEPHplzFFvNkWVQO5/3ZBb1Vigl6Fb/WTzV2KP3c+QNPeYq7Pc1Y9/bKvwO4v KRVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=r+zeM+Wm8gT9suLhtNmZ+zjqd6JgenBIv4L8SdDYscU=; b=NsnYE3q6prsWRikriDwodb898onkWXQxyv75I5v+/IXR0trlmawCn5eoRXxtkEOA40 0HG5CUlgVAzBLvJSKd8S4QPsEDN7c/Tfq1R0jIkTswmLARWKjLr5D/H9P79vnFnJcesm CFxRCQCxiGZxVqwHsoy5FyAHrSlPs7VXjQZLyQQb1l9ZY+cO7bW5wKEMRBz1phnwCE22 up9SYLGQVGVjTL0INqHcqoEp9LxwujQW4AfRzoosbTQwVsu+wGQ+4N8g/fZ1g5vbelOW tgClS1k2aW07LetMV12Na4NBCTjI3MMCvS0PdegmuQIL8zaZcO5RAOO1bdyvOjOiZxbF rkpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yandex-team.ru header.s=default header.b=azk8NOL8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=yandex-team.ru Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z6si608093ejb.147.2020.05.08.02.05.06; Fri, 08 May 2020 02:05:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@yandex-team.ru header.s=default header.b=azk8NOL8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=yandex-team.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726843AbgEHJAm (ORCPT + 99 others); Fri, 8 May 2020 05:00:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726325AbgEHJAm (ORCPT ); Fri, 8 May 2020 05:00:42 -0400 Received: from forwardcorp1o.mail.yandex.net (forwardcorp1o.mail.yandex.net [IPv6:2a02:6b8:0:1a2d::193]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 22543C05BD43 for ; Fri, 8 May 2020 02:00:41 -0700 (PDT) Received: from mxbackcorp1g.mail.yandex.net (mxbackcorp1g.mail.yandex.net [IPv6:2a02:6b8:0:1402::301]) by forwardcorp1o.mail.yandex.net (Yandex) with ESMTP id 42A922E1559; Fri, 8 May 2020 12:00:36 +0300 (MSK) Received: from myt4-18a966dbd9be.qloud-c.yandex.net (myt4-18a966dbd9be.qloud-c.yandex.net [2a02:6b8:c00:12ad:0:640:18a9:66db]) by mxbackcorp1g.mail.yandex.net (mxbackcorp/Yandex) with ESMTP id 1URGeionvE-0TAWUM7G; Fri, 08 May 2020 12:00:36 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1588928436; bh=r+zeM+Wm8gT9suLhtNmZ+zjqd6JgenBIv4L8SdDYscU=; h=In-Reply-To:Message-ID:From:Date:References:To:Subject:Cc; b=azk8NOL81jymru/vZxoV+bzrrvA6I5G4zkfWfzFWHSRZ1McJCqM88uh9aXpIble7/ TpnXYQULgWd03fNIb3595uZr173EEDiWgUBVC4IdYFJrsk7m+CInAJ8QRe47eHmbP9 32yZvcvC3Y4jkhfiZj4XLHtUAPG44+JQWEJjAM5k= Authentication-Results: mxbackcorp1g.mail.yandex.net; dkim=pass header.i=@yandex-team.ru Received: from dynamic-vpn.dhcp.yndx.net (dynamic-vpn.dhcp.yndx.net [2a02:6b8:b080:7008::1:4]) by myt4-18a966dbd9be.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 833o3SHgni-0SWKjeuC; Fri, 08 May 2020 12:00:29 +0300 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client certificate not present) Subject: Re: [PATCH RFC tip/core/rcu] Add shrinker to shift to fast/inefficient GP mode To: paulmck@kernel.org, Johannes Weiner Cc: Andrew Morton , rcu@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@fb.com, mingo@kernel.org, jiangshanlai@gmail.com, dipankar@in.ibm.com, mathieu.desnoyers@efficios.com, josh@joshtriplett.org, tglx@linutronix.de, peterz@infradead.org, rostedt@goodmis.org, dhowells@redhat.com, edumazet@google.com, fweisbec@gmail.com, oleg@redhat.com, joel@joelfernandes.org, viro@zeniv.linux.org.uk, Dave Chinner References: <20200507004240.GA9156@paulmck-ThinkPad-P72> <20200506175535.d4986a4d497071a410b69765@linux-foundation.org> <20200507170006.GA155220@cmpxchg.org> <20200507170903.GR2869@paulmck-ThinkPad-P72> <20200507183102.GB155220@cmpxchg.org> <20200507190905.GX2869@paulmck-ThinkPad-P72> From: Konstantin Khlebnikov Message-ID: <6d93affb-6505-1bf3-58a0-c67c34a18a9e@yandex-team.ru> Date: Fri, 8 May 2020 12:00:28 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: <20200507190905.GX2869@paulmck-ThinkPad-P72> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-CA Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 07/05/2020 22.09, Paul E. McKenney wrote: > On Thu, May 07, 2020 at 02:31:02PM -0400, Johannes Weiner wrote: >> On Thu, May 07, 2020 at 10:09:03AM -0700, Paul E. McKenney wrote: >>> On Thu, May 07, 2020 at 01:00:06PM -0400, Johannes Weiner wrote: >>>> On Wed, May 06, 2020 at 05:55:35PM -0700, Andrew Morton wrote: >>>>> On Wed, 6 May 2020 17:42:40 -0700 "Paul E. McKenney" wrote: >>>>> >>>>>> This commit adds a shrinker so as to inform RCU when memory is scarce. >>>>>> RCU responds by shifting into the same fast and inefficient mode that is >>>>>> used in the presence of excessive numbers of RCU callbacks. RCU remains >>>>>> in this state for one-tenth of a second, though this time window can be >>>>>> extended by another call to the shrinker. >>>> >>>> We may be able to use shrinkers here, but merely being invoked does >>>> not carry a reliable distress signal. >>>> >>>> Shrinkers get invoked whenever vmscan runs. It's a useful indicator >>>> for when to age an auxiliary LRU list - test references, clear and >>>> rotate or reclaim stale entries. The urgency, and what can and cannot >>>> be considered "stale", is encoded in the callback frequency and scan >>>> counts, and meant to be relative to the VM's own rate of aging: "I've >>>> tested X percent of mine for recent use, now you go and test the same >>>> share of your pool." It doesn't translate well to other >>>> interpretations of the callbacks, although people have tried. >>> >>> Would it make sense for RCU to interpret two invocations within (say) >>> 100ms of each other as indicating urgency? (Hey, I had to ask!) >> >> It's the perfect number for one combination of CPU, storage device, >> and shrinker implementation :-) > > Woo-hoo!!! > > But is that one combination actually in use anywhere? ;-) > >>>>>> If it proves feasible, a later commit might add a function call directly >>>>>> indicating the end of the period of scarce memory. >>>>> >>>>> (Cc David Chinner, who often has opinions on shrinkers ;)) >>>>> >>>>> It's a bit abusive of the intent of the slab shrinkers, but I don't >>>>> immediately see a problem with it. Always returning 0 from >>>>> ->scan_objects might cause a problem in some situations(?). >>>>> >>>>> Perhaps we should have a formal "system getting low on memory, please >>>>> do something" notification API. >>>> >>>> It's tricky to find a useful definition of what low on memory >>>> means. In the past we've used sc->priority cutoffs, the vmpressure >>>> interface (reclaimed/scanned - reclaim efficiency cutoffs), oom >>>> notifiers (another reclaim efficiency cutoff). But none of these >>>> reliably capture "distress", and they vary highly between different >>>> hardware setups. It can be hard to trigger OOM itself on fast IO >>>> devices, even when the machine is way past useful (where useful is >>>> somewhat subjective to the user). Userspace OOM implementations that >>>> consider userspace health (also subjective) are getting more common. >>>> >>>>> How significant is this? How much memory can RCU consume? >>>> >>>> I think if rcu can end up consuming a significant share of memory, one >>>> way that may work would be to do proper shrinker integration and track >>>> the age of its objects relative to the age of other allocations in the >>>> system. I.e. toss them all on a clock list with "new" bits and shrink >>>> them at VM velocity. If the shrinker sees objects with new bit set, >>>> clear and rotate. If it sees objects without them, we know rcu_heads >>>> outlive cache pages etc. and should probably cycle faster too. >>> >>> It would be easy for RCU to pass back (or otherwise use) the age of the >>> current grace period, if that would help. >>> >>> Tracking the age of individual callbacks is out of the question due to >>> memory overhead, but RCU could approximate this via statistical sampling. >>> Comparing this to grace-period durations could give information as to >>> whether making grace periods go faster would be helpful. >> >> That makes sense. >> >> So RCU knows the time and the VM knows the amount of memory. Either >> RCU needs to figure out its memory component to be able to translate >> shrinker input to age, or the VM needs to learn about time to be able >> to say: I'm currently scanning memory older than timestamp X. >> >> The latter would also require sampling in the VM. Nose goes. :-) > > Sounds about right. ;-) > > Does reclaim have any notion of having continuously scanned for > longer than some amount of time? Or could RCU reasonably deduce this? > For example, if RCU noticed that reclaim had been scanning for longer than > (say) five grace periods, RCU might decide to speed things up. > > But on the other hand, with slow disks, reclaim might go on for tens of > seconds even without much in the way of memory pressure, mightn't it? > > I suppose that another indicator would be recent NULL returns from > allocators. But that indicator flashes a bit later than one would like, > doesn't it? And has false positives when allocators are invoked from > atomic contexts, no doubt. And no doubt similar for sleeping more than > a certain length of time in an allocator. > >> There actually is prior art for teaching reclaim about time: >> https://lore.kernel.org/linux-mm/20130430110214.22179.26139.stgit@zurg/ >> >> CCing Konstantin. I'm curious how widely this ended up being used and >> how reliably it worked. > > Looking forward to hearing of any results! Well, that was some experiment about automatic steering memory pressure between containers. LRU timings from milestones itself worked pretty well. Remaining engine were more robust than mainline cgroups these days. Memory becomes much cheaper - I hope nobody want's overcommit it that badly anymore. It seems modern MM has plenty signals about memory pressure. Kswapsd should have enough knowledge to switch gears in RCU. > >>> But, yes, it would be better to have an elusive unambiguous indication >>> of distress. ;-) >> >> I agree. Preferably something more practical than a dialogue box >> asking the user on how well things are going for them :-) > > Indeed, that dialog box should be especially useful for things like > light bulbs running Linux. ;-) > > Thanx, Paul >