Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2139976rwb; Thu, 15 Dec 2022 20:32:25 -0800 (PST) X-Google-Smtp-Source: AA0mqf5vNZIH/7GtpHpIGRvqaYKTtEAaWaGNMqmq1r5P2IhslVala6Rzz2rVe3QN9ompOytkOZZb X-Received: by 2002:a62:1a8a:0:b0:56e:9a2c:152b with SMTP id a132-20020a621a8a000000b0056e9a2c152bmr30882920pfa.24.1671165145410; Thu, 15 Dec 2022 20:32:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671165145; cv=none; d=google.com; s=arc-20160816; b=kQ84QgR+pQMBVeEzkKI/NkjxtB2ohgthPQ2B5WhOL0qBhzSFffwGVWHacFHZUI9F5F 4YxvuVBJQG6qyaz1/3S06ZzsHueVYgJQDHHmkVVgp1s0h2ZOagmumA01zsLPtQy35ivA c0plCcExWNbnJja2v4Z3esGpftvvc7woTR0RWHcXxxN9KVAzPo7kXoeLbKIZ4DLbnNyv nh2MpsWaAAqlYFWkdz06QDu/88x+lunLWN57/gGfpIERX7WWYQe6jpinam7xdLOdoA8w aTsFFhUWiyO/+S2P1wRNo/vMu/kSZPsOvxbi8xmQ1kNup81G0Cz9I6eEpBRE0X979tLz DGTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:message-id:in-reply-to :date:references:subject:cc:to:from:dkim-signature; bh=zSkqLmK/5Sk8AcqKWBGC54VAk+z9QFGQXJOxdxJiJzg=; b=C0bWYa9Tg6rN16F2KjOm8Xh46o8xGR6Rh/7lQLG9GImr1HHsHkuBxzeIQT436EAmcN XrqK5fnfnPECZFea3QBusTblJifhWDDR7Cn8OccF2CAS1C5ELEg42N+VqSNb0jB2LLso uPqhV8UGz1osDkZSjhVxE7ewaWyCArYzOkB4ueuCF5SOnNur2HjlpCLyIzSolL/aqCJx 4LJ3lQVu/eE4yI+hANO9pFVzDh4ZmGR7bkKljeFypttM17Xv5veG730dYfZH1UUaT847 ma5HRNfOVzZKvIQ4OKzFc3DCf0WgJSRCJLmRk3A5pfyeVn3Ci1OktcHC7K6/aihST9lQ dwIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=LH0DTbnh; 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=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k79-20020a628452000000b00577552eff0bsi1268805pfd.27.2022.12.15.20.32.16; Thu, 15 Dec 2022 20:32:25 -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=@intel.com header.s=Intel header.b=LH0DTbnh; 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=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229950AbiLPDS0 (ORCPT + 68 others); Thu, 15 Dec 2022 22:18:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47702 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230125AbiLPDSI (ORCPT ); Thu, 15 Dec 2022 22:18:08 -0500 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74D945FB93 for ; Thu, 15 Dec 2022 19:17:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1671160637; x=1702696637; h=from:to:cc:subject:references:date:in-reply-to: message-id:mime-version; bh=V7nMACfvQKW9NVbyjcAlrDxmwIs/5qIqkQZBaVPjfTQ=; b=LH0DTbnhIGesmPMNYGB7xKH/WOAs5N1HpL4LCAkw67S69n8VwKB6JZmW sy8cI0Y//XupcIVyqUGb9CNd5cJFGLyATlBa1Dfx++ctZWFmlcEYcT9/D TbZTIkYpPv4q6fEwWTYOAls1g/ptNVD1MsnUoOn0oNUaMOxchmzRghJp6 DsJzPx+QE/SHl0MIz1I1t79/Mtl5rStHHNCbgBihcWTmc67OhTjQzuzll FTQsRa5EhmOnAZ5d357+zgyj6CRLCUTJm5yrk02pSPjiWkYTOGNW+iOeq CIfyM8/fN70PF7xgEa0/Y58Uv9kRfr+4UUg4tbzhQ5KKPCuhm5t2ImM9y Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10562"; a="299209615" X-IronPort-AV: E=Sophos;i="5.96,248,1665471600"; d="scan'208";a="299209615" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Dec 2022 19:17:16 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10562"; a="713147851" X-IronPort-AV: E=Sophos;i="5.96,248,1665471600"; d="scan'208";a="713147851" Received: from yhuang6-desk2.sh.intel.com (HELO yhuang6-desk2.ccr.corp.intel.com) ([10.238.208.55]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Dec 2022 19:17:14 -0800 From: "Huang, Ying" To: Johannes Weiner Cc: Michal Hocko , Dave Hansen , Yang Shi , Wei Xu , Andrew Morton , linux-mm@kvack.org, LKML Subject: Re: memcg reclaim demotion wrt. isolation References: <87edt1dwd2.fsf@yhuang6-desk2.ccr.corp.intel.com> Date: Fri, 16 Dec 2022 11:16:26 +0800 In-Reply-To: (Johannes Weiner's message of "Thu, 15 Dec 2022 09:22:33 +0100") Message-ID: <877cys9gxh.fsf@yhuang6-desk2.ccr.corp.intel.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=ascii X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE 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 Johannes Weiner writes: > On Thu, Dec 15, 2022 at 02:17:13PM +0800, Huang, Ying wrote: >> Michal Hocko writes: >> >> > On Tue 13-12-22 17:14:48, Johannes Weiner wrote: >> >> On Tue, Dec 13, 2022 at 04:41:10PM +0100, Michal Hocko wrote: >> >> > Hi, >> >> > I have just noticed that that pages allocated for demotion targets >> >> > includes __GFP_KSWAPD_RECLAIM (through GFP_NOWAIT). This is the case >> >> > since the code has been introduced by 26aa2d199d6f ("mm/migrate: demote >> >> > pages during reclaim"). I suspect the intention is to trigger the aging >> >> > on the fallback node and either drop or further demote oldest pages. >> >> > >> >> > This makes sense but I suspect that this wasn't intended also for >> >> > memcg triggered reclaim. This would mean that a memory pressure in one >> >> > hierarchy could trigger paging out pages of a different hierarchy if the >> >> > demotion target is close to full. >> >> >> >> This is also true if you don't do demotion. If a cgroup tries to >> >> allocate memory on a full node (i.e. mbind()), it may wake kswapd or >> >> enter global reclaim directly which may push out the memory of other >> >> cgroups, regardless of the respective cgroup limits. >> > >> > You are right on this. But this is describing a slightly different >> > situaton IMO. >> > >> >> The demotion allocations don't strike me as any different. They're >> >> just allocations on behalf of a cgroup. I would expect them to wake >> >> kswapd and reclaim physical memory as needed. >> > >> > I am not sure this is an expected behavior. Consider the currently >> > discussed memory.demote interface when the userspace can trigger >> > (almost) arbitrary demotions. This can deplete fallback nodes without >> > over-committing the memory overall yet push out demoted memory from >> > other workloads. From the user POV it would look like a reclaim while >> > the overall memory is far from depleted so it would be considered as >> > premature and a warrant a bug report. >> > >> > The reclaim behavior would make more sense to me if it was constrained >> > to the allocating memcg hierarchy so unrelated lruvecs wouldn't be >> > disrupted. >> >> When we reclaim/demote some pages from a memcg proactively, what is our >> goal? To free up some memory in this memcg for other memcgs to use? If >> so, it sounds reasonable to keep the pages of other memcgs as many as >> possible. > > The goal of proactive aging is to free up any resources that aren't > needed to meet the SLAs (e.g. end-to-end response time of webserver). > Meaning, to run things as leanly as possible within spec. Into that > free space, another container can then be co-located. > > This means that the goal is to free up as many resources as possible, > starting with the coveted hightier. If a container has been using > all-hightier memory but is able demote to lowtier, there are 3 options > for existing memory in the lower tier: > > 1) Colder/stale memory - should be displaced > > 2) Memory that can be promoted once the hightier is free - > reclaim/demotion of the coldest pages needs to happen at least > temporarily, or the tierswap is in stale mate. > > 3) Equally hot memory - if this exceeds capacity of the lower tier, > the hottest overall pages should stay, the excess demoted/reclaimed. > > You can't know what scenario you're in until you put the demoted pages > in direct LRU competition with what's already there. And in all three > scenarios, direct LRU competition also produces the optimal outcome. If my understanding were correct, your preferred semantics is to be memcg specific in the higher tier, and global in the lower tier. Another choice is to add another global "memory.reclaim" knob, for example, as /sys/devices/virtual/memory_tiering/memory_tier/memory.reclaim ? Then we can trigger global memory reclaim in lower tiers firstly. Then trigger memcg specific memory reclaim in higher tier for the specified memcg. The cons of this choice is that you need 2 steps to finish the work. The pros is that you don't need to combine memcg-specific and global behavior in one interface. Best Regards, Huang, Ying