Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp54738pxm; Tue, 22 Feb 2022 16:31:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJx31EGy/bPoweJB1vLkqp4AA2sL6js+z/AVmXBCgQtKMvqWe/rB5VytI8K4k0o6r04AIu5C X-Received: by 2002:a63:1719:0:b0:373:9a4a:368d with SMTP id x25-20020a631719000000b003739a4a368dmr21521814pgl.134.1645576315419; Tue, 22 Feb 2022 16:31:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645576315; cv=none; d=google.com; s=arc-20160816; b=SknyuN8b83jI5rYJZ8BlEZDRwtZU0yzLRWcmghQv1RwNrG9z9rVhCYtG2sl20x+XEE 4+mjOaouYe2yByEcI9iHkHKTzFFUt/hkoR8J/0s0/jnRXth/Kzx0A7LNAVsWpUKZpBE6 zDbkSx93JZDNbkQcpDVbKYc3+5InUa7e60Cu2SyDbA9qHKlwbQOGzMzq4MJCfxeeiFRi 7g/ajbeimgKLrAXz0paDkOEVk/fwRjDN9uPffXAE9dgQLjAQWFO4tgGT58NrYdwjZhl1 4tcnbYWLLDmq3DeMmxXrdOHh6TaOPDUzAHCFQOjgTvhjckx7kcTIwriwHi68IqyHXfpJ xonw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=3OXelgpgEN6TKz3C8orHccpNYtVFASdQJguRZzrhCw4=; b=GYdenySr/PGTx/MISd7K4jypbYscn50n2K9VWqK8quc4nmNmcbj7sPCoEMDGP2BHan 4nuw2oeIsEJzd/cgjrFWvYpXbAHVCYv7mnHr14ANh/qDRq1u8McWm6C1WF6Wo4EO4L+a Gg1wpzY1BLsFprvK35i/MqcUqGv/426RDt0jvPrBVI05u77kWlz1zl8vCsPsJgHEH2kS 21zUj3YH2mlVbg0fAhm5PP8EXvKExuybEUWpE08dK5t0x4WBR9TBSeqJOLXNr+2l7N5S 1A/Sjj2tMml+sm8ApHj7/TKGVt8jZ/YXrcEZtYfBQropvrNekwxeYvRh8Oumz0If+vu9 87og== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="Xmb1/NVt"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x2si14100169pln.591.2022.02.22.16.31.39; Tue, 22 Feb 2022 16:31:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="Xmb1/NVt"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S235261AbiBVTrk (ORCPT + 99 others); Tue, 22 Feb 2022 14:47:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233551AbiBVTrj (ORCPT ); Tue, 22 Feb 2022 14:47:39 -0500 Received: from mail-vs1-xe35.google.com (mail-vs1-xe35.google.com [IPv6:2607:f8b0:4864:20::e35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A59E2B1AA6 for ; Tue, 22 Feb 2022 11:47:13 -0800 (PST) Received: by mail-vs1-xe35.google.com with SMTP id w4so787579vsq.1 for ; Tue, 22 Feb 2022 11:47:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=3OXelgpgEN6TKz3C8orHccpNYtVFASdQJguRZzrhCw4=; b=Xmb1/NVtOZZnlcQeIzmTv9K64XnBoxbqbhWtBF7HzEM5ReTl05OlN0NkhauKMalSnD aVKmB0bz0+Gm1d3Wc9HQB9+0NIvnz4G3jNeKcig1d+zYIAtoxhZ+Ag/E6GDdwghDQ2NH uikMNsfl5lxInO6zpZzoiOeCJirM2uoXoJ6p458HO1h8EsiscBZSdGH7J5BOrbC0USmI C7TO8fuKHE/u7veRNHsg7PHeFcKvCD6Kg56dj4YnoC74VeWPUoi+KkxFzPxedCLzpUBC 0xFYUuklqWaXFGBGN6wbTYEnF6MVofR++Ux3oERR5TARRSgCfAZZ4CsLVRb+ceVle3dU oiuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=3OXelgpgEN6TKz3C8orHccpNYtVFASdQJguRZzrhCw4=; b=L6Xc3SUZdCKLeUnQ4kDJDprQvLySQA6RSA09wDjcFv4JCffRK+klQZL2eKEITGDATM WC9dN344PhY4SaBplV5kRmkQb1O+/jivaBJt4zkwHkk8W3ipVK4fvzp1V4yCouwMN6CP 05b7o3LaTCcZYj4Iacn10JTgWGF+P4CvYPUeydSjqH6pE5828+vrtlJzPnUSL2u3TrBR LeDMH9pjaZPTqLl/4mC2OnBQBcRxb/hjSZX3Z6X8UjlsUwj9M2s+A23wpZQwfn369Gor qpJY/QaZ0y3QWEmabK3GivoKHeolYblpUzlMlFOdWV4BobUs+xjCTVey1HYB/J8OTxQ6 RbUA== X-Gm-Message-State: AOAM531Qxm3TJE4VXySj7bDaU2LghYV/Q6i2iUpHq/8aaaLV/zrgABQh HM5lt5sAT3XZJ/1ZM6EQzqjj79ikq5ZyRxHDOFeQwA== X-Received: by 2002:a05:6102:53b:b0:31c:d:8d8b with SMTP id m27-20020a056102053b00b0031c000d8d8bmr8321517vsa.22.1645559232490; Tue, 22 Feb 2022 11:47:12 -0800 (PST) MIME-Version: 1.0 References: <20220219174940.2570901-1-surenb@google.com> In-Reply-To: From: Tim Murray Date: Tue, 22 Feb 2022 11:47:01 -0800 Message-ID: Subject: Re: [PATCH 1/1] mm: count time in drain_all_pages during direct reclaim as memory pressure To: Michal Hocko Cc: Suren Baghdasaryan , Andrew Morton , Johannes Weiner , Peter Zijlstra , guro@fb.com, Shakeel Butt , Minchan Kim , Linux-MM , LKML , Android Kernel Team Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Feb 21, 2022 at 12:55 AM Michal Hocko wrote: > It would be cool to have some numbers here. Are there any numbers beyond what Suren mentioned that would be useful? As one example, in a trace of a camera workload that I opened at random to check for drain_local_pages stalls, I saw the kworker that ran drain_local_pages stay at runnable for 68ms before getting any CPU time. I could try to query our trace corpus to find more examples, but they're not hard to find in individual traces already. > If the draining is too slow and dependent on the current CPU/WQ > contention then we should address that. The original intention was that > having a dedicated WQ with WQ_MEM_RECLAIM would help to isolate the > operation from the rest of WQ activity. Maybe we need to fine tune > mm_percpu_wq. If that doesn't help then we should revise the WQ model > and use something else. Memory reclaim shouldn't really get stuck behind > other unrelated work. In my experience, workqueues are easy to misuse and should be approached with a lot of care. For many workloads, they work fine 99%+ of the time, but once you run into problems with scheduling delays for that workqueue, the only option is to stop using workqueues. If you have work that is system-initiated with minimal latency requirements (eg, some driver heartbeat every so often, devfreq governors, things like that), workqueues are great. If you have userspace-initiated work that should respect priority (eg, GPU command buffer submission in the critical path of UI) or latency-critical system-initiated work (eg, display synchronization around panel refresh), workqueues are the wrong choice because there is no RT capability. WQ_HIGHPRI has a minor impact, but it won't solve the fundamental problem if the system is under heavy enough load or if RT threads are involved. As Petr mentioned, the best solution for those cases seems to be "convert the workqueue to an RT kthread_worker." I've done that many times on many different Android devices over the years for latency-critical work, especially around GPU, display, and camera. In the drain_local_pages case, I think it is triggered by userspace work and should respect priority; I don't think a prio 50 RT task should be blocked waiting on a prio 120 (or prio 100 if WQ_HIGHPRI) kworker to be scheduled so it can run drain_local_pages. If that's a reasonable claim, then I think moving drain_local_pages away from workqueues is the best choice.