From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 02824C352A1 for ; Tue, 6 Dec 2022 12:20:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6FDA48E0002; Tue, 6 Dec 2022 07:20:41 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6AD9E8E0001; Tue, 6 Dec 2022 07:20:41 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 575CE8E0002; Tue, 6 Dec 2022 07:20:41 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 4959E8E0001 for ; Tue, 6 Dec 2022 07:20:41 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 16E5240978 for ; Tue, 6 Dec 2022 12:20:41 +0000 (UTC) X-FDA: 80211789882.02.FFAF59B Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by imf30.hostedemail.com (Postfix) with ESMTP id 7C4F280014 for ; Tue, 6 Dec 2022 12:20:39 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=fNE0Kyi7; spf=pass (imf30.hostedemail.com: domain of mhocko@suse.com designates 195.135.220.29 as permitted sender) smtp.mailfrom=mhocko@suse.com; dmarc=pass (policy=quarantine) header.from=suse.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1670329239; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ubehKMI13V7IpoDkqhnY7iW2vBl9bHhW3ygShDxfjZU=; b=FoL4bPVq1s5VEfJBNKP/YJ9wWiwUK0p6KX7KlwFpIrCfn76GZT3BgVVwpPxnf0UKlmTFSh z4zbzsXLG2pOU1U8C6ZnsoOLGcgKzCFwk5ZRgD0yweL5D++er2W234JwcWoRGz15HNpgJc 0QidMfZLO1wRai+Q8yrIMtDSBcv8gyA= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=fNE0Kyi7; spf=pass (imf30.hostedemail.com: domain of mhocko@suse.com designates 195.135.220.29 as permitted sender) smtp.mailfrom=mhocko@suse.com; dmarc=pass (policy=quarantine) header.from=suse.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1670329239; a=rsa-sha256; cv=none; b=KYDrGh/R4gw3fPeqOe4DgTkyik6Wc5qIvYkW1kzu5XLWChlV1Nt2cwuBu9Whkjmay31qvH f8IF33IQLtqsAx54nf9OHeRo9lo6dgnjIi07dO2+N5jnW1JQLOwdx5RieXMDOF9QY3Z7sf HlD6cN9N99rSjaEa3NYskrPl/zRE7j0= Received: from imap1.suse-dmz.suse.de (imap1.suse-dmz.suse.de [192.168.254.73]) (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-out2.suse.de (Postfix) with ESMTPS id E54991FE5A; Tue, 6 Dec 2022 12:20:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1670329237; 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=ubehKMI13V7IpoDkqhnY7iW2vBl9bHhW3ygShDxfjZU=; b=fNE0Kyi7oZSf7QU7bvg5Wd3bjmzSRo7dddFUZS7bf0M6Pvep5NmvE3cSuVk3ExVU9S8I1Z 9ysK78QuxkBeZ/tLa0co0Pxx+pWZutVmBiIxnIT5lM3MdNOa8pxSuKIqesIqj3aVwwShyV GGBwaXaACl3mgtb62ecUSiRl/sREQf0= Received: from imap1.suse-dmz.suse.de (imap1.suse-dmz.suse.de [192.168.254.73]) (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 imap1.suse-dmz.suse.de (Postfix) with ESMTPS id C3EDC132F3; Tue, 6 Dec 2022 12:20:37 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap1.suse-dmz.suse.de with ESMTPSA id 0dqjLZUzj2N6YgAAGKfGzw (envelope-from ); Tue, 06 Dec 2022 12:20:37 +0000 Date: Tue, 6 Dec 2022 13:20:37 +0100 From: Michal Hocko To: Mina Almasry Cc: Andrew Morton , Johannes Weiner , Roman Gushchin , Shakeel Butt , Muchun Song , Huang Ying , Yang Shi , Yosry Ahmed , weixugc@google.com, fvdl@google.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3] [mm-unstable] mm: Fix memcg reclaim on memory tiered systems Message-ID: References: <20221206023406.3182800-1-almasrymina@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221206023406.3182800-1-almasrymina@google.com> X-Spamd-Result: default: False [-0.96 / 9.00]; DMARC_POLICY_ALLOW(-0.50)[suse.com,quarantine]; R_SPF_ALLOW(-0.20)[+a:smtp-out2.suse.de]; R_DKIM_ALLOW(-0.20)[suse.com:s=susede1]; RCVD_NO_TLS_LAST(0.10)[]; MIME_GOOD(-0.10)[text/plain]; BAYES_HAM(-0.06)[56.61%]; RCPT_COUNT_TWELVE(0.00)[13]; FROM_EQ_ENVFROM(0.00)[]; DKIM_TRACE(0.00)[suse.com:+]; TO_MATCH_ENVRCPT_SOME(0.00)[]; RCVD_COUNT_THREE(0.00)[4]; ARC_SIGNED(0.00)[hostedemail.com:s=arc-20220608:i=1]; ARC_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[] X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 7C4F280014 X-Stat-Signature: ppbjm7ra1zxzakm48uz3h54eweptrrf4 X-HE-Tag: 1670329239-200274 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Mon 05-12-22 18:34:05, Mina Almasry wrote: > commit 3f1509c57b1b ("Revert "mm/vmscan: never demote for memcg > reclaim"") enabled demotion in memcg reclaim, which is the right thing > to do, however, it introduced a regression in the behavior of > try_to_free_mem_cgroup_pages(). > > The callers of try_to_free_mem_cgroup_pages() expect it to attempt to > reclaim - not demote - nr_pages from the cgroup. I.e. the memory usage > of the cgroup should reduce by nr_pages. The callers expect > try_to_free_mem_cgroup_pages() to also return the number of pages > reclaimed, not demoted. > > However, what try_to_free_mem_cgroup_pages() actually does is it > unconditionally counts demoted pages as reclaimed pages. So in practice > when it is called it will often demote nr_pages and return the number of > demoted pages to the caller. Demoted pages don't lower the memcg usage, > and so try_to_free_mem_cgroup_pages() is not actually doing what the > callers want it to do. > > Various things work suboptimally on memory tiered systems or don't work > at all due to this: > > - memory.high enforcement likely doesn't work (it just demotes nr_pages > instead of lowering the memcg usage by nr_pages). > - try_charge_memcg() will keep retrying the charge while > try_to_free_mem_cgroup_pages() is just demoting pages and not actually > making any room for the charge. This has been brought up during the review https://lore.kernel.org/all/YoYTEDD+c4GT0xYY@dhcp22.suse.cz/ > - memory.reclaim has a wonky interface. It advertises to the user it > reclaims the provided amount but it will actually often demote that > amount. > > There may be more effects to this issue. > > To fix these issues I propose shrink_folio_list() to only count pages > demoted from inside of sc->nodemask to outside of sc->nodemask as > 'reclaimed'. Could you expand on why the node mask matters? From the charge point of view it should be completely uninteresting as the charge remains. I suspect we really need to change to reclaim metrics for memcg reclaim. In the memory balancing reclaim we can indeed consider demotions as a reclaim because the memory is freed in the end but for the memcg reclaim we really should be counting discharges instead. No demotion/migration will free up charges. -- Michal Hocko SUSE Labs