Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp5322935iog; Wed, 22 Jun 2022 17:28:17 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vIlsnOk9reuIBR01CsT/v3LwilLTx//gtZMGsmYIDvis7hyKAgK17Il140m2qp+dxsvsno X-Received: by 2002:aa7:d294:0:b0:435:5d12:867f with SMTP id w20-20020aa7d294000000b004355d12867fmr7192776edq.147.1655944097332; Wed, 22 Jun 2022 17:28:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655944097; cv=none; d=google.com; s=arc-20160816; b=TZIZARcsZiO4kfgVkeJXCL//ybKUoNdU14krWd2c0NwlSk9bl5LFggZQta+Izef4CD kMYgMHvVo+Jpgb9ykVsKvRT2UeGXncjknoVEkTU5GOh/q9P+zDB0VmlxTBJEtCNyZ+9I KihcNR1MTGl8MlAkEXej+kPuN7ncHm5rfCA5IXFjJXNpLkiJFXITqtGLsDWBQOS0ojWX SgZRFYsjnB1h0lxoOXBjJXQU3k5tDBpFqKqVuiInJ6x4ildEpD1n0z6Xwx4ZucKldYUd x8czUfk7DVqc3yWJ6ng5+9D5FOSs3VMo/HoAjSGh5GNYcaU9xKCIFOZruGM1GaOkyGwY FYrw== 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=aGc760CUzqfAXiBkGN4MiPEho4dLgNkLq+hTF2lwnHA=; b=MGzXIYEolJGkxXkLdtzcoasXV+Z/Vzv81wPJBN6lu5h6YWovh/X+ncrTtohwHT43Hh ggSTAuPUZtMXvmf4l0H3XbBSUc8yPxCbhmAJryFfPP61NEhuAbY+TomeCDNKITEY0XRX fpjSaYpw+L2Ymje/H/31YkbORY/k2oGBpXK0su9IyRPCLHsaPY7LXJypF1Yafjztebt4 7KXiLID7mtNi2Xs79cySRY9Eo6V4SUZGWEnFZOKu5p3Hvs5Mj4a14+k1Q/7uC4bTmeEG CyAEnctbUUNkQzOIxgABxBulHCw4og/QuVcMT59tXDniT5pQu1eVKku5Vf94gFP7tFgc oHpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=gQuswyeZ; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t6-20020a056402524600b00435964535aasi4010835edd.322.2022.06.22.17.27.44; Wed, 22 Jun 2022 17:28:17 -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=@google.com header.s=20210112 header.b=gQuswyeZ; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354836AbiFWAZg (ORCPT + 99 others); Wed, 22 Jun 2022 20:25:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351013AbiFWAZe (ORCPT ); Wed, 22 Jun 2022 20:25:34 -0400 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4BC996580 for ; Wed, 22 Jun 2022 17:25:33 -0700 (PDT) Received: by mail-wm1-x331.google.com with SMTP id n185so10103213wmn.4 for ; Wed, 22 Jun 2022 17:25:33 -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=AsCHLsR0X509w4nFi6V2GhZ3Y2RfxrtwjRubttCsexiwjAmcsvNXpgEEP4O/KXAbuz miOUu1dLcARYFC7mRaStyFBxGyjjuZwQBvXhWKVG9RylBrqLoAt7ePVbOgmnJJpdF4km fBWolWwj9MQ5QLU1QJcUmpdJhVE094/84c1ZVrqRHxNM5yx4SOE68sVvcnegOyp5NwB2 FRMd1QuBs+JSsfRvE7Aq6dzambqq+Gt1D4SCfBAkYTbH2BluysPXawPfFbtxZf2V4FrS Ihma153fNhtcyVCk6Brzij5iQmGnt0UkTGM4dn5M0Zt1ZRocwgkNASriEpukqzSrQOGA 2GMA== X-Gm-Message-State: AJIora9pPSeU7+Z9QfbC/evNYwNP2lBt5t6xWMiDUMO0/GjwkFn/GXqy H9ClN14E2mJNBtG0U1/LfObQJEhtkaenwm7DOD0Bkw== 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" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=unavailable 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, 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; > >