Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp9101429rwi; Tue, 25 Oct 2022 15:19:34 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4qytXlnj/XZq3jYSHNw0gzeaq96cmOwFRhwoWOuRYxX6KIM5GGsMbMukgNKAkButn5j5zM X-Received: by 2002:a17:907:7214:b0:791:a4cf:5bb7 with SMTP id dr20-20020a170907721400b00791a4cf5bb7mr30321100ejc.576.1666736374145; Tue, 25 Oct 2022 15:19:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666736374; cv=none; d=google.com; s=arc-20160816; b=YzG5Hvsl5ZtvG/jaFAzvzwRKLjH7B/KdbwLIvZsbZkGn6Mam9JX0sHFQqYnuFaGiQJ aXRLf07taoXxMIvWSIwJsej2Q8Qp9s+rkJ7nGyWU08Ea5iKE2i+FLlZD2YSFqXmamnPr f46cHJOVHa9F7KmYRU1MYG1maAI2tOtYfrtXvMizKOmdYqJxzZ0Yr2JXJlloeHBQ08Ev QnMKr804S1xrRKk9ceWqFVamkeZRdilBL9oXNYlT+LYL+rJfdTuHS9KB3dWXEGOtd8Fj /vFRK6VskImnjQzm9pGjVb9l2WabXlj65uIu3pYAj8C4N5YFTBzJeLz86Yvc5BoBUqo8 /cHg== 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=j1ebPB11JE5IFAkyV0hTUtb8iYF2G4QeJkAHbSonpqM=; b=yuIiS5nJcMmB+fzYhb/yVgumC+KyFEX7bTDqpl+oa5tLg5/glatr7RqrhPhRzxJslo mYR3mWx6Ke5Lsy6PFPQzfwa5Ofyl/tms7SMzipO/HP3akjzVmf2mirsH63/4LQnkmy8w D6B7+i4igRucfbHdtfM9IFCe18haj5MKv4u+DUQSbp3UN4OWT/lt+bO4+ibEzXbDbtC4 fGgRifjIWzqqh/Nb8/Ys3RN7Yugt0DqWvgSmbg63tXkeNUjROn4X4C8Rx/g6o0wxtv82 zUJThwG+1JPXZtHM+i+sqyfD6q3HTCFn6DL9maShYvcQsxUQ56btxQzjo1XpJ613PKpw YKFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Cy3SpsXH; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q12-20020a17090676cc00b0078d9d67841fsi3534293ejn.400.2022.10.25.15.18.49; Tue, 25 Oct 2022 15:19:34 -0700 (PDT) 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=@gmail.com header.s=20210112 header.b=Cy3SpsXH; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232388AbiJYVxR (ORCPT + 99 others); Tue, 25 Oct 2022 17:53:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232226AbiJYVxO (ORCPT ); Tue, 25 Oct 2022 17:53:14 -0400 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 459EEDBE5E for ; Tue, 25 Oct 2022 14:53:14 -0700 (PDT) Received: by mail-pl1-x62f.google.com with SMTP id jo13so8566964plb.13 for ; Tue, 25 Oct 2022 14:53:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=j1ebPB11JE5IFAkyV0hTUtb8iYF2G4QeJkAHbSonpqM=; b=Cy3SpsXHe4MYa7NALkJnN09vXeQems4AxsMMSNLXl04rex0tmvbZd4o6vXJqcAhaEY ukaT3ldu/vkOXILPa6oGq9DP3NY8fEWLZ2YkILfpSgvd7+quYDG5IOpNwKCopIlpmrSr jeEtbEaiF24gAwBoeYAKgWCkn8KcQM+bkpv/yaYrnPIOcYK8i/MzXvOF3dhqec6xpEA+ rtTS6Au+z3Os+jW/JhVhvyOr7UOUXyNTkzMpkFaHEa0O8B4rALJ7yJ23YZPd+twEXEQT tcFiCKDE/O0zC5j9nm5xnbA05I9UciPI/03KW5pIiXvb29r6b62UKvaDiCMdrhJe/1hD vNaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=j1ebPB11JE5IFAkyV0hTUtb8iYF2G4QeJkAHbSonpqM=; b=2JwYJ9+xpG4LVJQqNEzb/j9FIdKgXQw3R2PheJqwSRrAa/w40PPA4Fu21vWvHpn7oz UBMssBf/wZEZCYFdcHlD3ZFOpAO2pWtx2nbGcwmkCFQYev/DZC09TGvouEbjPXA4170i 04fg3V8ljvVEyDbEwC6G7fzV26sDP989w21OEBGpw88EgQOoAnY8rUpm81tuSDXPea7o COctyS6vkXRvH/fmkGQb6Ky7aCngwDPTd4usgo74CRFbdKruCycQwwKVh/emfT/ApOL5 7vVCJqCxL42TtVMq7FSml57k3N4i0bxfdPpD3ctdylLilFpXHJkCzrLoQtn1HSjEeuWt vXXA== X-Gm-Message-State: ACrzQf2NjtqItDIuEFmavWwhsy8Xvs/+pykugtbSpMse4bI904JA6jqo CE4LLRRX8WtOtd7A5KCXJCLxv5Lf1SIP5rCCx8E= X-Received: by 2002:a17:90b:1c87:b0:20a:e485:4e21 with SMTP id oo7-20020a17090b1c8700b0020ae4854e21mr442378pjb.194.1666734793686; Tue, 25 Oct 2022 14:53:13 -0700 (PDT) MIME-Version: 1.0 References: <20221025170519.314511-1-hannes@cmpxchg.org> In-Reply-To: From: Yang Shi Date: Tue, 25 Oct 2022 14:53:01 -0700 Message-ID: Subject: Re: [PATCH] mm: vmscan: split khugepaged stats from direct reclaim stats To: Johannes Weiner Cc: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Eric Bergen Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS 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 Tue, Oct 25, 2022 at 1:54 PM Johannes Weiner wrote: > > On Tue, Oct 25, 2022 at 12:40:15PM -0700, Yang Shi wrote: > > On Tue, Oct 25, 2022 at 10:05 AM Johannes Weiner wrote: > > > > > > Direct reclaim stats are useful for identifying a potential source for > > > application latency, as well as spotting issues with kswapd. However, > > > khugepaged currently distorts the picture: as a kernel thread it > > > doesn't impose allocation latencies on userspace, and it explicitly > > > opts out of kswapd reclaim. Its activity showing up in the direct > > > reclaim stats is misleading. Counting it as kswapd reclaim could also > > > cause confusion when trying to understand actual kswapd behavior. > > > > > > Break out khugepaged from the direct reclaim counters into new > > > pgsteal_khugepaged, pgdemote_khugepaged, pgscan_khugepaged counters. > > > > > > Test with a huge executable (CONFIG_READ_ONLY_THP_FOR_FS): > > > > > > pgsteal_kswapd 1342185 > > > pgsteal_direct 0 > > > pgsteal_khugepaged 3623 > > > pgscan_kswapd 1345025 > > > pgscan_direct 0 > > > pgscan_khugepaged 3623 > > > > There are other kernel threads or works may allocate memory then > > trigger memory reclaim, there may be similar problems for them and > > someone may try to add a new stat. So how's about we make the stats > > more general, for example, call it "pg{steal|scan}_kthread"? > > I'm not convinved that's a good idea. > > Can you generally say that userspace isn't indirectly waiting for one > of those allocating threads? With khugepaged, we know. AFAIK, ksm may do slab allocation with __GFP_DIRECT_RECLAIM. Some device mapper drivers may do heavy lift in the work queue, for example, dm-crypt, particularly for writing. > > And those other allocations are usually ___GFP_KSWAPD_RECLAIM, so if > they do direct reclaim, we'd probably want to know that kswapd is > failing to keep up (doubly so if userspace is waiting). In a shared > kthread counter, khugepaged would again muddy the waters.