Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp564648ybf; Wed, 26 Feb 2020 18:37:34 -0800 (PST) X-Google-Smtp-Source: APXvYqz/JV+ShR0DZhOgHMPQqk/FJYWZZl09ut/br4vRdTmgyT/ar67/uybcq7y8KtXJX1tvMvVt X-Received: by 2002:aca:1101:: with SMTP id 1mr1705980oir.30.1582771054076; Wed, 26 Feb 2020 18:37:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582771054; cv=none; d=google.com; s=arc-20160816; b=ijfz1X5m6FBkmoFyQF6ioyg3G0b9Kc3EvNcd+QQjsnFKMIPDsB4O0HBv/TA1nLgqzu bQiOobm4fN/hSWqxabON3kl2na2kILiDPjt1SxSlJWUHYf1O1bJkkUvVbemQNN9onmUf 9sh+G0b1DnEH5c7321E4fn1QupluHvmRKeMDfUMh9xf54aWkAIpw1mI8lclvH7TZXlqF dapBiMHZQ0CaUQ2dhHHRZKRmc9iyiEbrVnR4RjfoY6zcowz/b4XREGi4Yxn0HmsnkK1m j0rAljApoz1fZjuOAWONRw6csBw0iUYHHaQeqLxu1ZxBDRt/280Nf5gF8eXbkpfVjDrI cFnA== 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=FgDRP53fhRc849hJWqV/+PwhPD91i+668jgIHMCfsLU=; b=0VKDoAeEGpx+I2EcEMLxpcyhbDtHKySa1PzcwZVkwYJHgHqFtcyIc3EEMqzja0/hOi KXEM9knuvMX3nkYRaaUxZKv5pMy6rfsUiWFSf2WWOouUUfUYWeKtY8ZIgHey9GsgtCDG bB6ZWYtjNQxLLdKAKm7zKnS6vjRBMHROsjjtl+TTWoo7WEbC3pb4cTOpoJFQawILyrGP 017+hlsus9m1F5u3w5Pj+h/etb8Ltg4IpaDCBiBnCJ6QGW/p4ZMfH9WmwtGgicWsDmEd ONFQmbH9Q/dQztTPvpHi99+qShhG110bZS/W6HlXe8i8tRZ1pgaJGIqYLCBBLcDrAam6 Qj/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=NxVZZMPH; 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 f62si540850oib.131.2020.02.26.18.37.21; Wed, 26 Feb 2020 18:37:34 -0800 (PST) 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=NxVZZMPH; 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 S1728238AbgB0Cgr (ORCPT + 99 others); Wed, 26 Feb 2020 21:36:47 -0500 Received: from mail-oi1-f194.google.com ([209.85.167.194]:35964 "EHLO mail-oi1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728211AbgB0Cgr (ORCPT ); Wed, 26 Feb 2020 21:36:47 -0500 Received: by mail-oi1-f194.google.com with SMTP id c16so1799794oic.3 for ; Wed, 26 Feb 2020 18:36:46 -0800 (PST) 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=FgDRP53fhRc849hJWqV/+PwhPD91i+668jgIHMCfsLU=; b=NxVZZMPHkldyISQkt/j9q46fqdC/fTHYg2D8rxmu3JQ5FQTpEWAnsrfAW1INOGxpeL 7h/DwX4EseSXzq8DPxsx7tT89LiU3NA/LHAN4Sx7xeCJY7jLlWu2wlI7PxFLojwfUju3 XCXCv0GNC9Xz5gwwW7M6ZQvAHCRuijZey00McNQxQ9NVe7aC2WLqdpYWQ76fRU+M2TSD fCSLoyGAnvdSsxpdtTUIC1FBt0jEnZJWNiN/eJ1V1HI2R4d3LlFZziKBBFNxThGx34jE FKNM7vbPt25+yqO0LpSs/FWkruIUFSvFAow7Xv2uEwRevRGyVVEdbZ3TS4R6adpOe9Q4 7e2Q== 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=FgDRP53fhRc849hJWqV/+PwhPD91i+668jgIHMCfsLU=; b=n3eR2ESyBVjr+x9eU5eepm0FRqJLkUUw0IWScuKqLjd/bxVDyRuyBczAnQpxQAU8U+ zRKwBaJMTwSK14RnmPKukECX82eezAu3l4xZ9lvmxWPp1I0sztpZIvV6E5aOBX+78IPH 4zYDPwTy2/RCRDMqT5VrUPUmQwmRnGe1SulPgAOAFNVKSpmzE3oWxY2MW5ssILYyeepk gYGxcev5npQE4/sKkBQxT+w6HECjZ4lu/U0OpKSQhS4wN9312o9L5YOrEENKBAEgT52d 36I6VInHv6h6+98bfNyafHgIuaBlvK5rdeNRlwHjiuTXIAyRW+CWdB8umjfo/4NhAOH/ +HMw== X-Gm-Message-State: APjAAAWJQ1SvjRyN9TE3YojqaGB4+FaTF00hO8X3egS47F4mKwdUTrmt MYZyaKh0F8bVyzljqoYRcrQZNAVLcJJKgp5sHyBmb1W6 X-Received: by 2002:a05:6808:30d:: with SMTP id i13mr1610873oie.144.1582771005560; Wed, 26 Feb 2020 18:36:45 -0800 (PST) MIME-Version: 1.0 References: <20200219181219.54356-1-hannes@cmpxchg.org> <1bfd6ea4-f012-5778-64c6-36731e69b5ba@linux.alibaba.com> In-Reply-To: <1bfd6ea4-f012-5778-64c6-36731e69b5ba@linux.alibaba.com> From: Shakeel Butt Date: Wed, 26 Feb 2020 18:36:34 -0800 Message-ID: Subject: Re: [PATCH] mm: memcontrol: asynchronous reclaim for memory.high To: Yang Shi Cc: Johannes Weiner , Andrew Morton , Michal Hocko , Tejun Heo , Roman Gushchin , Linux MM , Cgroups , LKML , Kernel Team 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, Feb 26, 2020 at 3:59 PM Yang Shi wrote: > > > > On 2/26/20 12:25 PM, Shakeel Butt wrote: > > On Wed, Feb 19, 2020 at 10:12 AM Johannes Weiner wrote: > >> We have received regression reports from users whose workloads moved > >> into containers and subsequently encountered new latencies. For some > >> users these were a nuisance, but for some it meant missing their SLA > >> response times. We tracked those delays down to cgroup limits, which > >> inject direct reclaim stalls into the workload where previously all > >> reclaim was handled my kswapd. > >> > >> This patch adds asynchronous reclaim to the memory.high cgroup limit > >> while keeping direct reclaim as a fallback. In our testing, this > >> eliminated all direct reclaim from the affected workload. > >> > >> memory.high has a grace buffer of about 4% between when it becomes > >> exceeded and when allocating threads get throttled. We can use the > >> same buffer for the async reclaimer to operate in. If the worker > >> cannot keep up and the grace buffer is exceeded, allocating threads > >> will fall back to direct reclaim before getting throttled. > >> > >> For irq-context, there's already async memory.high enforcement. Re-use > >> that work item for all allocating contexts, but switch it to the > >> unbound workqueue so reclaim work doesn't compete with the workload. > >> The work item is per cgroup, which means the workqueue infrastructure > >> will create at maximum one worker thread per reclaiming cgroup. > >> > >> Signed-off-by: Johannes Weiner > >> --- > >> mm/memcontrol.c | 60 +++++++++++++++++++++++++++++++++++++------------ > >> mm/vmscan.c | 10 +++++++-- > > This reminds me of the per-memcg kswapd proposal from LSFMM 2018 > > (https://lwn.net/Articles/753162/). > > Thanks for bringing this up. > > > > > If I understand this correctly, the use-case is that the job instead > > of direct reclaiming (potentially in latency sensitive tasks), prefers > > a background non-latency sensitive task to do the reclaim. I am > > wondering if we can use the memory.high notification along with a new > > memcg interface (like memory.try_to_free_pages) to implement a user > > space background reclaimer. That would resolve the cpu accounting > > concerns as the user space background reclaimer can share the cpu cost > > with the task. > > Actually I'm interested how you implement userspace reclaimer. Via a new > syscall or a variant of existing syscall? > We have a per-memcg interface memory.try_to_free_pages on which user space can echo two numbers i.e. number of bytes to reclaim and a byte representing flags (I/O allowed or just reclaim zombies e.t.c). However nowadays we are just using it for zombie cleanup. Shakeel