Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp2202254ybk; Mon, 11 May 2020 14:46:48 -0700 (PDT) X-Google-Smtp-Source: APiQypLQq6aAB8UfdFjNSbt+B6q9Vem+5GD2jQTz6icoEG6XijK0eIw3olPRLpYOq6NnwTKGNnfv X-Received: by 2002:a17:906:687:: with SMTP id u7mr14474425ejb.149.1589233607875; Mon, 11 May 2020 14:46:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589233607; cv=none; d=google.com; s=arc-20160816; b=wFCPBEjPR5DhRHBOPPfu9LvbjOpsgDWNtzdOS42XUVqoCkyJPGQy8sx5nM9ICGKSBl G07Rl9H75mxHFvsN0HpKrf3NWlWQegSp6Au3c5hp98bI6RCM2PHNQMekDazHsMCHZB7k v/CjCSiKjknb0JUx3JPY5nTdgZQTI5aX/E7Vz0UOCclv9hWRACTyQ3JNmZO8hMCX5YkR Nk+WumNzSNqRUvCXx3pfVVZ63HHfuqqXOQdjdj+qYHyL5e05fPILeLUBkzLOJTPdy/Oj MOQPEPc3YuMloSimlXTl04jhgNn5l4Ul3YNFbsXFs76dOXdiL3xgHpu0vk/sz+M/RZG5 GxJQ== 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=Qi8QFxJcn8ospcUaTTL/msn/H2PnYlfa7gEDxoqIEDk=; b=hElsIv+Ux1d0Z9JUbe2mg9qSa31RSwyVHQKMW4xoAYSAkyvSIo44d1Dc/Aq+473nqN v+o+K/45SRt3Yr+D7bmfiO2Bez3bvBjXBWhVI/sPA/wq73P+kPnzjMJCNUW7NcWPlucJ yIl7vGYL42yl7irOV79yHKQFodVhyvDBSB6OlJQjJ55ApX1J0FciGCFVyG4PZUj0wZmv rHLlvRnJV2yQfeMYsluIFxr6E7zZcrbyKbUyVXZfBbkKdCMoRzJ6Q+1VcBNrtavHkaos oFdUIPdd5QKGvjAiXsb+WpDUT9+c7YBRUlLvMF9YD/JxFseWVlWihncO0Cv1Hq/Qq2Ux A1Lg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="Xde/V+Am"; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cy5si6465461edb.327.2020.05.11.14.46.23; Mon, 11 May 2020 14:46:47 -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=@google.com header.s=20161025 header.b="Xde/V+Am"; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727836AbgEKVol (ORCPT + 99 others); Mon, 11 May 2020 17:44:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51132 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1725860AbgEKVok (ORCPT ); Mon, 11 May 2020 17:44:40 -0400 Received: from mail-lj1-x241.google.com (mail-lj1-x241.google.com [IPv6:2a00:1450:4864:20::241]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17E54C061A0E for ; Mon, 11 May 2020 14:44:40 -0700 (PDT) Received: by mail-lj1-x241.google.com with SMTP id w10so536237ljo.0 for ; Mon, 11 May 2020 14:44:40 -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=Qi8QFxJcn8ospcUaTTL/msn/H2PnYlfa7gEDxoqIEDk=; b=Xde/V+AmEr9RhRI0OF3eoEMOlc1isYqe7VOjexZ9+yvqXUITqDMjYykWWvmO4V34Mf JOKkt+8ipvHoG6K6EnRJr+X4BE5BAeOIwVncM8mZiP+p8lL6D28UrUf9zrcUO4HYJ7Li /D0qRklBhVjc7H/pRd3r6sLDxIMmGPBdiSdMvnDuECFum3YPjKLEReOjRUX1lEMISjPa UxRo1lcjtjDBeAqBK9a6l4tU/5RJrH/CC/Tv8dqgB7LOsv/2hUPnh1rhH6QKtsylPMHk BdDMHIPOaPWBeuE+Acy+5O+YHoJMjaQHW8cBtfuVR6w/jN0CQ0EMrdo5tDVPzgaOXoPu HV7A== 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=Qi8QFxJcn8ospcUaTTL/msn/H2PnYlfa7gEDxoqIEDk=; b=aAH7qjFbGShTJCjA++kIEFaILpE3zSzGTmScdeUrseiLNQWr6MxVxmDs1gyScf7BNq 3vnzp4TsXSuI1kvJjr56DwCTQtqaw3N1htm+3+VBBgwG4N/dUMM9BwsJXQ+MNjfKv6jh J3tAnvGuDHSffoLF3np78kWORBvSueqlHbkPNWV+gY+oEBxV5pb9nqOAqP9svxlU8GcB yM4ncwU+Y8EUVaasQNzOE/0OS0lz/sxj5pXGdvvWK6e76C3/xEJn0XQ8hPc2WnZJyQAR woVsA95ALHukR5ZubMGwaj3oqQiapbY/zeaPIPAaQUTynOfigyA8b8HsJOfNLltAD9kV KYqw== X-Gm-Message-State: AOAM531YUAZ+ibUdxlMPlzaOqRPvnoglYF63RdFrhSUmYprBjzCK46po riGCUHtWCYhkcEUhHo0SJOdKkDpdB2j7UH3Nbja7Dw== X-Received: by 2002:a2e:9a54:: with SMTP id k20mr12277759ljj.265.1589233477493; Mon, 11 May 2020 14:44:37 -0700 (PDT) MIME-Version: 1.0 References: <20200507163301.229070-1-shakeelb@google.com> <20200507164653.GM6345@dhcp22.suse.cz> <20200511155646.GB306292@cmpxchg.org> In-Reply-To: <20200511155646.GB306292@cmpxchg.org> From: Shakeel Butt Date: Mon, 11 May 2020 14:44:26 -0700 Message-ID: Subject: Re: [PATCH] memcg: effective memory.high reclaim for remote charging To: Johannes Weiner Cc: Michal Hocko , Roman Gushchin , Greg Thelen , Andrew Morton , Linux MM , Cgroups , LKML 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 11, 2020 at 8:57 AM Johannes Weiner wrote: > > On Thu, May 07, 2020 at 10:00:07AM -0700, Shakeel Butt wrote: > > On Thu, May 7, 2020 at 9:47 AM Michal Hocko wrote: > > > > > > On Thu 07-05-20 09:33:01, Shakeel Butt wrote: > > > [...] > > > > @@ -2600,8 +2596,23 @@ static int try_charge(struct mem_cgroup *memcg, gfp_t gfp_mask, > > > > schedule_work(&memcg->high_work); > > > > break; > > > > } > > > > - current->memcg_nr_pages_over_high += batch; > > > > - set_notify_resume(current); > > > > + > > > > + if (gfpflags_allow_blocking(gfp_mask)) > > > > + reclaim_over_high(memcg, gfp_mask, batch); > > > > + > > > > + if (page_counter_read(&memcg->memory) <= > > > > + READ_ONCE(memcg->high)) > > > > + break; > > > > > > I am half way to a long weekend so bear with me. Shouldn't this be continue? The > > > parent memcg might be still in excess even the child got reclaimed, > > > right? > > > > > > > The reclaim_high() actually already does this walk up to the root and > > reclaim from ones who are still over their high limit. Though having > > 'continue' here is correct too. > > If reclaim was weak and failed to bring the child back in line, we > still do set_notify_resume(). We should do that for ancestors too. > > But it seems we keep adding hierarchy walks and it's getting somewhat > convoluted: page_counter does it, then we check high overage > recursively, and now we add the call to reclaim which itself is a walk > up the ancestor line. > > Can we hitchhike on the page_counter_try_charge() walk, which already > has the concept of identifying counters with overage? Rename the @fail > to @limited and return the first counter that is in excess of its high > as well, even when the function succeeds? > > Then we could ditch the entire high checking loop here and simply > replace it with > > done_restock: > ... > > if (*limited) { > if (gfpflags_allow_blocking()) > reclaim_over_high(memcg_from_counter(limited)); > /* Reclaim may not be able to do much, ... */ > set_notify_resume(); // or schedule_work() > }; > I will try to code the above and will give a shot to the following long-term suggestion as well. > In the long-term, the best thing might be to integrate memory.high > reclaim with the regular reclaim that try_charge() is already > doing. Especially the part where it retries several times - we > currently give up on memory.high unnecessarily early. Make > page_counter_try_charge() fail on high and max equally, and after > several reclaim cycles, instead of invoking the OOM killer, inject the > penalty sleep and force the charges. OOM killing and throttling is > supposed to be the only difference between the two, anyway, and yet > the code diverges far more than that for no apparent reason. > > But I also appreciate that this is a cleanup beyond the scope of this > patch here, so it's up to you how far you want to take it. Thanks, Shakeel