Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp919629ybm; Tue, 21 May 2019 06:00:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqwCx3tguSLUGFJlIC1K1YY8E7BDXe+J5s1hDU4v2ofSFdezJK6Zhlg8apmm1ZqqjnW1LiPh X-Received: by 2002:a17:902:4324:: with SMTP id i33mr1562770pld.75.1558443607361; Tue, 21 May 2019 06:00:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558443607; cv=none; d=google.com; s=arc-20160816; b=ORAZS7uJ6nkxlgu4saya+FPRjoWQWFEANhMLeiRIN4PsNRlmaxEEKP6lulBqLSgC/l wkJOMkegQVtA4QvwN9pAcvnC/beyFGXwhkdz9Ao2s1TgAwGobFn2fB+7ycDXm2rXQf01 OQ/KattDjCSm6R50JrPTdiUvGghm69VNMpLndQKhuAanpSkxNmqOqKPXpGaBvMrKizLJ tdffdFR9VZC6zzDE5FFeqnPlrsFqmQa6eMpSo4VxY3V+NeIgpE+yO0vKWi2/OO1Ln1uV nEgUcLOxCrRbftqoQjKzbuX0UbAs4ORZzQHmY5KG7lglcb45NeZKjHvFf5+jeBGm5xD0 baBg== 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=T/AHbGrbWFUhevOXCGpUGCgyop6Di8UfE0ud1RTG1ps=; b=NKFFT5vo+ScCxgftkTFVofa/ulxhHaprmQnt8kOSd0gEDDjnc+Fkq/XivaB7u/e4Er 7FZO7JAUWk1ewhn+LpOS6zgzAyPUxzIIBePUyeKgva9X+fqad7hjOqaoiweyrmEFK55h TFMiMwtZM/TSG6dBky8Fpf7E17u4226M/2ojnjoFZMbfXrEHw5viigye9oEmY+NDtyIT 0qioJ3xMC6pNPBE87CayDGGKmbzO5/Dh8QsanpajME/9S7PRDb5ztdKOY0oX2LMJ4ycO GZaR1Kx/HqZNElBJKG1kT/qR4b7kDqxiWdPCAekpd5VUcjYJ04c0wI9hSZGJnFSkE1Q8 NoRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=akTuLbwy; 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 3si20695778pgt.305.2019.05.21.05.59.51; Tue, 21 May 2019 06:00:07 -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=akTuLbwy; 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 S1728237AbfEUM5N (ORCPT + 99 others); Tue, 21 May 2019 08:57:13 -0400 Received: from mail-yw1-f67.google.com ([209.85.161.67]:33945 "EHLO mail-yw1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726692AbfEUM5M (ORCPT ); Tue, 21 May 2019 08:57:12 -0400 Received: by mail-yw1-f67.google.com with SMTP id n76so7267577ywd.1 for ; Tue, 21 May 2019 05:57:11 -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=T/AHbGrbWFUhevOXCGpUGCgyop6Di8UfE0ud1RTG1ps=; b=akTuLbwyJU5RN+ZX+1XrhOSjd4MciXH7phKiqrpcWAfdgPdU7zImpJSRTClYg+LnD8 f72NWpwZAcJEJWW1W6buISDdzYyEyDIrp3SR3YVvwuoBzzqiLJ9PEwNNgqHybiKQNlMJ 2iG330vUDmL9jD5pERSkZpkiDcA8RywSlF0+wux3E+aw+YbeSJtlt4GB0itIQzksJcGg Ox4p2HDQsBtjjFQFbP2hmcPMJ6riI3suMWoQIGSBSXyT4sy107pII8ukRM5RFzlrR0H7 IR44iZACqmT/AbXbIN0ZY4HXhfvGYsyfHLNXmBvTIPjUwP/LNaI4afQeK3TCCWZpsHCl 1cnQ== 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=T/AHbGrbWFUhevOXCGpUGCgyop6Di8UfE0ud1RTG1ps=; b=DvJTyVZgDs8rxmGcJcFJiQVjRcZRMMKlY3kf1IZ9wVrPlG5rBq2nV3708OHyu9RSFh SDivwV0HwbdPdfSnjPCTjFtObnRcwP78Kb4mTmG9HwrfzyEz2PRbBkt6pZl6zkue3y+t AH/peuuOY90bAx9yW9Sxngd8QAJEOPDv8NuNyHqI/VrpLFUYOJWdu0tcEstfeL6vvwJM bAFHsC3m8vjZHdqAu/1AZe/UOoVxrpKcsUTBV/yH1U+kU4zhh+zQLJR65BOaMoDu88DW YfJV7VVMC8aypA7ak6xNrvSvymFmfzDZSLuDsp5QUegiohF/3ua8L7Pm1eDkTtKXpmXm wXiQ== X-Gm-Message-State: APjAAAXLPI365JNrDeyt6XnBlyzUx95naL1Rdz7DL/LRrO6BnKOVmp/j XluCifAYzMkqdM4fD966SdnkngR3HpwNeZ5oXdZP8w== X-Received: by 2002:a81:5ec3:: with SMTP id s186mr39737429ywb.308.1558443430631; Tue, 21 May 2019 05:57:10 -0700 (PDT) MIME-Version: 1.0 References: <20190520035254.57579-1-minchan@kernel.org> <1754d0ef-6756-d88b-f728-17b1fe5d5b07@arm.com> In-Reply-To: <1754d0ef-6756-d88b-f728-17b1fe5d5b07@arm.com> From: Shakeel Butt Date: Tue, 21 May 2019 05:56:59 -0700 Message-ID: Subject: Re: [RFC 0/7] introduce memory hinting API for external process To: Anshuman Khandual Cc: Tim Murray , Minchan Kim , Andrew Morton , LKML , linux-mm , Michal Hocko , Johannes Weiner , Joel Fernandes , Suren Baghdasaryan , Daniel Colascione , Sonny Rao , Brian Geffon , linux-api@vger.kernel.org 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 Mon, May 20, 2019 at 7:55 PM Anshuman Khandual wrote: > > > > On 05/20/2019 10:29 PM, Tim Murray wrote: > > On Sun, May 19, 2019 at 11:37 PM Anshuman Khandual > > wrote: > >> > >> Or Is the objective here is reduce the number of processes which get killed by > >> lmkd by triggering swapping for the unused memory (user hinted) sooner so that > >> they dont get picked by lmkd. Under utilization for zram hardware is a concern > >> here as well ? > > > > The objective is to avoid some instances of memory pressure by > > proactively swapping pages that userspace knows to be cold before > > those pages reach the end of the LRUs, which in turn can prevent some > > apps from being killed by lmk/lmkd. As soon as Android userspace knows > > that an application is not being used and is only resident to improve > > performance if the user returns to that app, we can kick off > > process_madvise on that process's pages (or some portion of those > > pages) in a power-efficient way to reduce memory pressure long before > > the system hits the free page watermark. This allows the system more > > time to put pages into zram versus waiting for the watermark to > > trigger kswapd, which decreases the likelihood that later memory > > allocations will cause enough pressure to trigger a kill of one of > > these apps. > > So this opens up bit of LRU management to user space hints. Also because the app > in itself wont know about the memory situation of the entire system, new system > call needs to be called from an external process. > > > > >> Swapping out memory into zram wont increase the latency for a hot start ? Or > >> is it because as it will prevent a fresh cold start which anyway will be slower > >> than a slow hot start. Just being curious. > > > > First, not all swapped pages will be reloaded immediately once an app > > is resumed. We've found that an app's working set post-process_madvise > > is significantly smaller than what an app allocates when it first > > launches (see the delta between pswpin and pswpout in Minchan's > > results). Presumably because of this, faulting to fetch from zram does > > pswpin 417613 1392647 975034 233.00 > pswpout 1274224 2661731 1387507 108.00 > > IIUC the swap-in ratio is way higher in comparison to that of swap out. Is that > always the case ? Or it tend to swap out from an active area of the working set > which faulted back again. > > > not seem to introduce a noticeable hot start penalty, not does it > > cause an increase in performance problems later in the app's > > lifecycle. I've measured with and without process_madvise, and the > > differences are within our noise bounds. Second, because we're not > > That is assuming that post process_madvise() working set for the application is > always smaller. There is another challenge. The external process should ideally > have the knowledge of active areas of the working set for an application in > question for it to invoke process_madvise() correctly to prevent such scenarios. > > > preemptively evicting file pages and only making them more likely to > > be evicted when there's already memory pressure, we avoid the case > > where we process_madvise an app then immediately return to the app and > > reload all file pages in the working set even though there was no > > intervening memory pressure. Our initial version of this work evicted > > That would be the worst case scenario which should be avoided. Memory pressure > must be a parameter before actually doing the swap out. But pages if know to be > inactive/cold can be marked high priority to be swapped out. > > > file pages preemptively and did cause a noticeable slowdown (~15%) for > > that case; this patch set avoids that slowdown. Finally, the benefit > > from avoiding cold starts is huge. The performance improvement from > > having a hot start instead of a cold start ranges from 3x for very > > small apps to 50x+ for larger apps like high-fidelity games. > > Is there any other real world scenario apart from this app based ecosystem where > user hinted LRU management might be helpful ? Just being curious. Thanks for the > detailed explanation. I will continue looking into this series. Chrome OS is another real world use-case for this user hinted LRU management approach by proactively reclaiming reclaim from tabs not accessed by the user for some time.