Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp948150rwi; Wed, 26 Oct 2022 09:02:16 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7c1/0232/Dts39Joy29VkdaPtuaQ1RRMeZ0jVtMdLbbJ1zyaVnaQZEFTuwrvojSorj53k6 X-Received: by 2002:a17:907:8a23:b0:78d:a24e:a9aa with SMTP id sc35-20020a1709078a2300b0078da24ea9aamr39194859ejc.404.1666800136494; Wed, 26 Oct 2022 09:02:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666800136; cv=none; d=google.com; s=arc-20160816; b=wWB9UdkIpeIL4eTj7/mkons7tWFBETMGghNXAxZLAi08SwsPRjzrJtcGqZF8KQD7P/ 8BpayWO+Ja3c9WRPIF0HELWSorNbPOflLlePzTpzymLyDYnDvguMwuqyQJXW2+dn0BWZ OeC0y+ErJ55/oPrESGgL9CrwK+FOC4gHqML6rFZk7IN1bkJDK8dj5XfPxUjST245BPad TQrnsA6SfL6DLn+znKgefdlaNGLtw9yohuuLGvgWBy4L1APbj0dXTz11vWFE+g/EBtF/ Nf+gduY+uJxsCUglf/X8OJnPvHDouSz+jnYnYno+A64mOILC9EBiQ8198FKvkNH603kR Y28w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=vpcNESwvh0jNYi8JKRjPbHDwFtWStBG7/bwwW7nzM+4=; b=fcvN6tBJuxXbHr7oU0y2KEpH3ksSmQSfQd16622dWJAyJ7nyn7b1psjhRYuKKFGcy1 TKfTiP/FhTZ/GdZqpBlSQWnPUwNyi7ZlMz2MIrSg8O0RpsLKdp7Hzew70qCUwT4n3Z/l usc4A4/KilndVWYK3YGZENObu/WkWmyjB+bcWhO6A2KhoBH+mYOZBW1YFnU4/bGmAkDa 57iYThrRGbeOXcoBtinoNSl3lgWReVp+Xh2megBuV7iceU9lYZPrf76Lm4I6P+iYsZsu juwfFZN38KJv0fHv6K/TV8z+7nKwa/Eq54hEbnm6EbcB92MLSDT2P4gdUZivY/iQ8iYh zu7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=BJvfGVSh; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cs13-20020a170906dc8d00b0078dad5e8d65si2247614ejc.68.2022.10.26.09.01.28; Wed, 26 Oct 2022 09:02:16 -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=@suse.com header.s=susede1 header.b=BJvfGVSh; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234320AbiJZP7k (ORCPT + 99 others); Wed, 26 Oct 2022 11:59:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234243AbiJZP7c (ORCPT ); Wed, 26 Oct 2022 11:59:32 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9864E4E5F; Wed, 26 Oct 2022 08:59:21 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 6FB3322007; Wed, 26 Oct 2022 15:59:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1666799960; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=vpcNESwvh0jNYi8JKRjPbHDwFtWStBG7/bwwW7nzM+4=; b=BJvfGVSh3MdOszpAO8QwQ4r7kh2M2m20+lHpatc8odP/4LmOpemYfq2byjwOFulcH3WrMN 5TDJSojDmoAYV8I2Qp/3iL9jvj05lBaEA1S5LTVeOc6Bmjcaem6/gvPDNzNE+t1zftP2KW 882Ix1/GY8wnRhgA3rxq6sGgqorhpD4= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 4703B13A6E; Wed, 26 Oct 2022 15:59:20 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id ihPyDlhZWWM9MwAAMHmgww (envelope-from ); Wed, 26 Oct 2022 15:59:20 +0000 Date: Wed, 26 Oct 2022 17:59:19 +0200 From: Michal Hocko To: Feng Tang Cc: Aneesh Kumar K V , Andrew Morton , Johannes Weiner , Tejun Heo , Zefan Li , Waiman Long , "Huang, Ying" , "linux-mm@kvack.org" , "cgroups@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "Hansen, Dave" , "Chen, Tim C" , "Yin, Fengwei" Subject: Re: [PATCH] mm/vmscan: respect cpuset policy during page demotion Message-ID: References: <20221026074343.6517-1-feng.tang@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED 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 Wed 26-10-22 20:20:01, Feng Tang wrote: > On Wed, Oct 26, 2022 at 05:19:50PM +0800, Michal Hocko wrote: > > On Wed 26-10-22 16:00:13, Feng Tang wrote: > > > On Wed, Oct 26, 2022 at 03:49:48PM +0800, Aneesh Kumar K V wrote: > > > > On 10/26/22 1:13 PM, Feng Tang wrote: > > > > > In page reclaim path, memory could be demoted from faster memory tier > > > > > to slower memory tier. Currently, there is no check about cpuset's > > > > > memory policy, that even if the target demotion node is not allowd > > > > > by cpuset, the demotion will still happen, which breaks the cpuset > > > > > semantics. > > > > > > > > > > So add cpuset policy check in the demotion path and skip demotion > > > > > if the demotion targets are not allowed by cpuset. > > > > > > > > > > > > > What about the vma policy or the task memory policy? Shouldn't we respect > > > > those memory policy restrictions while demoting the page? > > > > > > Good question! We have some basic patches to consider memory policy > > > in demotion path too, which are still under test, and will be posted > > > soon. And the basic idea is similar to this patch. > > > > For that you need to consult each vma and it's owning task(s) and that > > to me sounds like something to be done in folio_check_references. > > Relying on memcg to get a cpuset cgroup is really ugly and not really > > 100% correct. Memory controller might be disabled and then you do not > > have your association anymore. > > You are right, for cpuset case, the solution depends on 'CONFIG_MEMCG=y', > and the bright side is most of distribution have it on. CONFIG_MEMCG=y is not sufficient. You would need to enable memcg controller during the runtime as well. > > This all can get quite expensive so the primary question is, does the > > existing behavior generates any real issues or is this more of an > > correctness exercise? I mean it certainly is not great to demote to an > > incompatible numa node but are there any reasonable configurations when > > the demotion target node is explicitly excluded from memory > > policy/cpuset? > > We haven't got customer report on this, but there are quite some customers > use cpuset to bind some specific memory nodes to a docker (You've helped > us solve a OOM issue in such cases), so I think it's practical to respect > the cpuset semantics as much as we can. Yes, it is definitely better to respect cpusets and all local memory policies. There is no dispute there. The thing is whether this is really worth it. How often would cpusets (or policies in general) go actively against demotion nodes (i.e. exclude those nodes from their allowes node mask)? I can imagine workloads which wouldn't like to get their memory demoted for some reason but wouldn't it be more practical to tell that explicitly (e.g. via prctl) rather than configuring cpusets/memory policies explicitly? > Your concern about the expensive cost makes sense! Some raw ideas are: > * if the shrink_folio_list is called by kswapd, the folios come from > the same per-memcg lruvec, so only one check is enough > * if not from kswapd, like called form madvise or DAMON code, we can > save a memcg cache, and if the next folio's memcg is same as the > cache, we reuse its result. And due to the locality, the real > check is rarely performed. memcg is not the expensive part of the thing. You need to get from page -> all vmas::vm_policy -> mm -> task::mempolicy -- Michal Hocko SUSE Labs