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 7A8E7C43334 for ; Thu, 23 Jun 2022 00:25:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F0C3F8E0100; Wed, 22 Jun 2022 20:25:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E938D8E00FA; Wed, 22 Jun 2022 20:25:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D35728E0100; Wed, 22 Jun 2022 20:25:33 -0400 (EDT) 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 BDB528E00FA for ; Wed, 22 Jun 2022 20:25:33 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id 918B480763 for ; Thu, 23 Jun 2022 00:25:33 +0000 (UTC) X-FDA: 79607606946.15.55B929F Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) by imf27.hostedemail.com (Postfix) with ESMTP id 3940D40015 for ; Thu, 23 Jun 2022 00:25:33 +0000 (UTC) Received: by mail-wm1-f53.google.com with SMTP id m32-20020a05600c3b2000b0039756bb41f2so524424wms.3 for ; Wed, 22 Jun 2022 17:25:32 -0700 (PDT) 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=aGc760CUzqfAXiBkGN4MiPEho4dLgNkLq+hTF2lwnHA=; b=gQuswyeZ2unJsJtQNdmDZ13sMjSqQo1RWSPOiC/NK2N6itjLR5J+1pYFpBUaOk6nGg z+eBGxEETPfbh6+Q/63zwgCuErxr1n5GlLO2m24RI9cwyao/BcBdP5QxFZb4hbKT5u9S 5ZWz9nJuRU6vErz7/qraQ8ex4nAKDzu/I6waUlkUe/Dymw127vM04k6MDKa8JQQVJNRp MEM20FVHD7SEBwGul5ytxZpGM2ExN8pkl9+MfLjZOGxUCQK6nCy5A5DDHQGfFFkEUd7s twcRMDz8TGTNcaoADcabM6Q7zjLE+6dLSgcXdTT+XOe04JLMDh6byVctoHADa4HYUVNS GfKg== 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=aGc760CUzqfAXiBkGN4MiPEho4dLgNkLq+hTF2lwnHA=; b=DaNT/x3BWQUuwBWvZJ6tHJ+vfSo9vbFCoXBdKWCd3Br5ef02C3qaPCZLpkUVh5nV4N YeX0X9R3/J8w/RMisn/AC7q4WfJN6oX6UNibZCf7YsATzxjMk03/iSaDGdFOGKIgXow6 2Yt5Zv71RY6NzxLwTGEEt4/twWQM0jboyF7ULG+AwtIGQiUCll6uIy+N+HNSTSTHrMk5 J8ifJtGaMJWtQR33GGhL6Z6/Sp8hrl6Hu9rLgWMqv1TtZGsRWq+antuG5/B51a9563lY gMKaVew6gqfo7/V02+rDACf2xsZNM6vvhu2ABDuS9Dg04xuAqzXpeJdqUVE0znxPLUla b4+A== X-Gm-Message-State: AJIora/1w0fkv2Z1xbBwDc05fJde87bQQPDicSn8C8mxOha6/W4KTtsQ 5JgAe5b2D0Abq5FoSEOB1ih4FdknrPTxhDxy5NNygw== X-Google-Smtp-Source: AGRyM1uhhmG98sWEyp+Tt/TaRm3zA+KfVhcjnxuRunOrr071IyYR489kEobIjYMc0JTmKOgMrzlUlKJIg0kh6lv6qh0= X-Received: by 2002:a05:600c:34cc:b0:39c:832c:bd92 with SMTP id d12-20020a05600c34cc00b0039c832cbd92mr991182wmq.24.1655943931730; Wed, 22 Jun 2022 17:25:31 -0700 (PDT) MIME-Version: 1.0 References: <20220623000530.1194226-1-yosryahmed@google.com> <20220622171624.fc7de8d0ab18a5cf663f8ab8@linux-foundation.org> In-Reply-To: <20220622171624.fc7de8d0ab18a5cf663f8ab8@linux-foundation.org> From: Yosry Ahmed Date: Wed, 22 Jun 2022 17:24:55 -0700 Message-ID: Subject: Re: [PATCH] mm: vmpressure: don't count userspace-induced reclaim as memory pressure To: Andrew Morton Cc: Johannes Weiner , Michal Hocko , Roman Gushchin , Shakeel Butt , Muchun Song , Matthew Wilcox , Vlastimil Babka , David Hildenbrand , Miaohe Lin , NeilBrown , Alistair Popple , Suren Baghdasaryan , Peter Xu , Linux Kernel Mailing List , Cgroups , Linux-MM Content-Type: text/plain; charset="UTF-8" ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655943933; a=rsa-sha256; cv=none; b=IFRwsGt0Yq9fXXvH6U++1yS1W9G+pKkR7OD91PzmIUfYaE5TGrhuuqduc1dTDPXqOVX/2E R5DIXe1hQBQneJvmoRHc16I+tmWKbF95HK0R3WH25O+li0LIoMM3vh5f/kihpBa0Tw77xE QGGANyNOkFd0Y9+QOzo3jqavXGtAYIY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655943933; 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=aGc760CUzqfAXiBkGN4MiPEho4dLgNkLq+hTF2lwnHA=; b=CuxiHe66QkLeJDXGht1UajDAUYw1dlNjqz8rVjZHrk7xvF99H8ad0Y5a8+YIo27JZASf2+ rMF03kICGJR8u+Ttq1Lmn/7bM20wYFFqRXvKhnzpEcZUC9wLd6XqAHCAh2GG4nf0dVsrjP m+qojbE90DLf2IwH6kOIXpUz460vI1k= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=gQuswyeZ; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf27.hostedemail.com: domain of yosryahmed@google.com designates 209.85.128.53 as permitted sender) smtp.mailfrom=yosryahmed@google.com X-Rspam-User: X-Rspamd-Queue-Id: 3940D40015 Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=gQuswyeZ; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf27.hostedemail.com: domain of yosryahmed@google.com designates 209.85.128.53 as permitted sender) smtp.mailfrom=yosryahmed@google.com X-Stat-Signature: mmsburaaazd6cri7a6zmwkq1phhnp6bo X-Rspamd-Server: rspam09 X-HE-Tag: 1655943933-493135 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 Wed, Jun 22, 2022 at 5:16 PM Andrew Morton wrote: > > On Thu, 23 Jun 2022 00:05:30 +0000 Yosry Ahmed wrote: > > > Commit e22c6ed90aa9 ("mm: memcontrol: don't count limit-setting reclaim > > as memory pressure") made sure that memory reclaim that is induced by > > userspace (limit-setting, proactive reclaim, ..) is not counted as > > memory pressure for the purposes of psi. > > > > Instead of counting psi inside try_to_free_mem_cgroup_pages(), callers > > from try_charge() and reclaim_high() wrap the call to > > try_to_free_mem_cgroup_pages() with psi handlers. > > > > However, vmpressure is still counted in these cases where reclaim is > > directly induced by userspace. This patch makes sure vmpressure is not > > counted in those operations, in the same way as psi. Since vmpressure > > calls need to happen deeper within the reclaim path, the same approach > > could not be followed. Hence, a new "controlled" flag is added to struct > > scan_control to flag a reclaim operation that is controlled by > > userspace. This flag is set by limit-setting and proactive reclaim > > operations, and is used to count vmpressure correctly. > > > > To prevent future divergence of psi and vmpressure, commit e22c6ed90aa9 > > ("mm: memcontrol: don't count limit-setting reclaim as memory pressure") > > is effectively reverted and the same flag is used to control psi as > > well. > > I'll await reviewer input on this, but I can always do trivia! Thanks for taking a look so quickly, will address and send v2 soon! > > > @@ -3502,6 +3497,8 @@ unsigned long mem_cgroup_soft_limit_reclaim(pg_data_t *pgdat, int order, > > static int mem_cgroup_force_empty(struct mem_cgroup *memcg) > > { > > int nr_retries = MAX_RECLAIM_RETRIES; > > + unsigned int reclaim_options = MEMCG_RECLAIM_CONTROLLED | > > + MEMCG_RECLAIM_MAY_SWAP; > > If it doesn't fit, it's nicer to do > > unsigned int reclaim_options; > ... > > reclaim_options = MEMCG_RECLAIM_CONTROLLED | MEMCG_RECLAIM_MAY_SWAP; > > (several places) > > > @@ -3751,6 +3757,7 @@ unsigned long try_to_free_pages(struct zonelist *zonelist, int order, > > .may_writepage = !laptop_mode, > > .may_unmap = 1, > > .may_swap = 1, > > + .controlled = 0, > > }; > > Let's just skip all these initializations to zero, let the compiler take > care of it. > > > @@ -4095,6 +4112,7 @@ static int balance_pgdat(pg_data_t *pgdat, int order, int highest_zoneidx) > > .gfp_mask = GFP_KERNEL, > > .order = order, > > .may_unmap = 1, > > + .controlled = 0, > > }; > > > > set_task_reclaim_state(current, &sc.reclaim_state); > > @@ -4555,6 +4573,7 @@ unsigned long shrink_all_memory(unsigned long nr_to_reclaim) > > .may_unmap = 1, > > .may_swap = 1, > > .hibernation_mode = 1, > > + .controlled = 0, > > }; > > struct zonelist *zonelist = node_zonelist(numa_node_id(), sc.gfp_mask); > > unsigned long nr_reclaimed; > > @@ -4707,6 +4726,7 @@ static int __node_reclaim(struct pglist_data *pgdat, gfp_t gfp_mask, unsigned in > > .may_unmap = !!(node_reclaim_mode & RECLAIM_UNMAP), > > .may_swap = 1, > > .reclaim_idx = gfp_zone(gfp_mask), > > + .controlled = 0, > > }; > > unsigned long pflags; > >