Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp1765088pxm; Thu, 24 Feb 2022 08:58:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJwEOMNWrk2p1YKfujHrzfORpZjvwKf/kSzeu2FJmFz6UDGrFAdWCJvU1v0v39RNF2xq6Wtd X-Received: by 2002:a17:90a:4fa1:b0:1bb:8ad8:581c with SMTP id q30-20020a17090a4fa100b001bb8ad8581cmr3764762pjh.105.1645721894827; Thu, 24 Feb 2022 08:58:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645721894; cv=none; d=google.com; s=arc-20160816; b=vi6GHjHgTY8DsNaKMMXVvY/5RSNKIDuMF7b9hsMkWRQexsk2d0ltatshHP6dv6Bnsh Nc5XY0B931qeRxpL9pUcxSLaxcEaKKayXsJKQdCbVN4uKrTBZT5lelYfGCngHWuCRPC+ E3mggvj/PkzJEQuqg+3VNREdoFM/6cIjD6DqDM2xKd5rZfu69fETgrUGkZz8+cXfxpRx yidd0ahW9k5yJs8hi9VzddURIpZWdOiSvgfsQMLG+mfgAa7TeDmDTikK1JdjV3pSRKYv qt7wv2EvagdvIgy/zBPQRI6DmRGEj2s/jvi6dBdjNk8CzlD08nXhelkk7h/GXYu34hwf A93A== 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=bluFR6fvvQhB6H6hwiDoTR3wKkQfMctdO4frcI1wEKA=; b=qixgNsJ/dGvII8QLBGTk5ClKZ4VPK2upKeNw0aXUT+PwSlGVg90CIIuwfTbv2Y2wm0 q8yn5uIzwMDrSnTMAjbpsCrVExPRhJWA1mKBxnVMdP9Gjk4z1+uQo5rZP0VX6ogz2uVV 3kq2317Mof7RGycECFWS1K2hIuS6/67qHuTgvQGg7+bIaL9qeo5SjMflLzYzjsQaNgae D8tNLdgKHsp1KO59ZZgKhs1MqGjXnEk/oIVzUtMop6IgIrnxx9LMxzaZquT6a+b43rJ2 J6iJv4JHISQXUboY+wYISiIoukyO/kQSLUGlpDtVU5VOoO+wONwDcelsmNgW+3UYHUrw E5HQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=c80cR3l+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id u21si3030708plq.218.2022.02.24.08.58.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Feb 2022 08:58:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=c80cR3l+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id EF98C1FE542; Thu, 24 Feb 2022 08:32:45 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229851AbiBXQ31 (ORCPT + 99 others); Thu, 24 Feb 2022 11:29:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229799AbiBXQ3W (ORCPT ); Thu, 24 Feb 2022 11:29:22 -0500 Received: from mail-yw1-x112a.google.com (mail-yw1-x112a.google.com [IPv6:2607:f8b0:4864:20::112a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0B66198EE1 for ; Thu, 24 Feb 2022 08:28:50 -0800 (PST) Received: by mail-yw1-x112a.google.com with SMTP id 00721157ae682-2d646fffcc2so3481407b3.4 for ; Thu, 24 Feb 2022 08:28:50 -0800 (PST) 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=bluFR6fvvQhB6H6hwiDoTR3wKkQfMctdO4frcI1wEKA=; b=c80cR3l+ItVFxWSro6ydAMDG+tMJYBXmM/LUuf54rg+irlLzimuC/kKw7/ykBgdLKe knqsI+x26Pn/N1J9OEKFvL6NkfCfAet72V1SJRwHaJAJguK5klQrhLBLqyGASmfweMSy KOSx6YIhi59ViHoOmmyVekYzvbMC7kC7Fhk445FnIihwur7uZ1gUaHnpbLmbYtRH/6hI ctxOWQnF829khBaWLNyr86qOUGRtJLeBUw40Q2fPBHbori3TGzG7sbOTBaRfKWclM55G MH9lRTxt7Ror5bE9nWBBHctuPTlttRVq/QMoK+jJWlf5VYmTF+j7XAN8N06E55SVJRVA aQpA== 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=bluFR6fvvQhB6H6hwiDoTR3wKkQfMctdO4frcI1wEKA=; b=hA41Pb8tpc3JfWl1Og1/KJZc/Sn4uUAMBPWOfvCHyJbMNFyEsCfXIdfWl65n35yNYD AjArnl5zhqld4XwnQffgah0r5SUxVJ2+1vy4dXqjaBZKKPH1Ov7+E957VwtvGjJ9tF/U /3zv0N0kkFldlMl5c1USnDbEOfkPkxmsBL9R6n86wxH40sO5a3/o84s2VqgjUV2lvtYy fAGoPqhH12JqKPEDRZVNwSCOqSXvDF3Jt/kxM/SaN8l73HQf3oYSTRhyQWgwZL5qGjB/ anB/t+6iCDVqjPIFo4YZdmgS7vTcmYoNGU/wPHBrR+AXtdMAjUzvXCVswvoXDC3xPtz5 z19A== X-Gm-Message-State: AOAM530dBoY9PmFr15Y4rwAHBinBmECEUJv4sIsEq0F+pN4CoS0XJxub 0mXb4GYVqm7V6s4qTjsEAIzg/ibq3Nom/k1znnx7d5JMYgL8XrHR X-Received: by 2002:a81:5fc3:0:b0:2d7:ab5d:1dd8 with SMTP id t186-20020a815fc3000000b002d7ab5d1dd8mr3201917ywb.514.1645720129543; Thu, 24 Feb 2022 08:28:49 -0800 (PST) MIME-Version: 1.0 References: <20220223194812.1299646-1-surenb@google.com> In-Reply-To: From: Suren Baghdasaryan Date: Thu, 24 Feb 2022 08:28:38 -0800 Message-ID: Subject: Re: [PATCH v3 1/1] mm: count time in drain_all_pages during direct reclaim as memory pressure To: Michal Hocko Cc: akpm@linux-foundation.org, hannes@cmpxchg.org, pmladek@suse.com, peterz@infradead.org, guro@fb.com, shakeelb@google.com, minchan@kernel.org, timmurray@google.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@android.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=no 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 Thu, Feb 24, 2022 at 12:53 AM 'Michal Hocko' via kernel-team wrote: > > On Wed 23-02-22 11:48:12, Suren Baghdasaryan wrote: > > When page allocation in direct reclaim path fails, the system will > > make one attempt to shrink per-cpu page lists and free pages from > > high alloc reserves. Draining per-cpu pages into buddy allocator can > > be a very slow operation because it's done using workqueues and the > > task in direct reclaim waits for all of them to finish before > > proceeding. Currently this time is not accounted as psi memory stall. > > > > While testing mobile devices under extreme memory pressure, when > > allocations are failing during direct reclaim, we notices that psi > > events which would be expected in such conditions were not triggered. > > After profiling these cases it was determined that the reason for > > missing psi events was that a big chunk of time spent in direct > > reclaim is not accounted as memory stall, therefore psi would not > > reach the levels at which an event is generated. Further investigation > > revealed that the bulk of that unaccounted time was spent inside > > drain_all_pages call. > > > > A typical captured case when drain_all_pages path gets activated: > > > > __alloc_pages_slowpath took 44.644.613ns > > __perform_reclaim took 751.668ns (1.7%) > > drain_all_pages took 43.887.167ns (98.3%) > > Although the draining is done in the slow path these numbers suggest > that we should really reconsider the use of WQ both for draining and > other purposes (like vmstats). Yep, I'm testing the kthread_create_worker_on_cpu approach suggested by Petr. Will post it later today if nothing regresses. > > > PSI in this case records the time spent in __perform_reclaim but > > ignores drain_all_pages, IOW it misses 98.3% of the time spent in > > __alloc_pages_slowpath. > > > > Annotate __alloc_pages_direct_reclaim in its entirety so that delays > > from handling page allocation failure in the direct reclaim path are > > accounted as memory stall. > > > > Reported-by: Tim Murray > > Signed-off-by: Suren Baghdasaryan > > Acked-by: Johannes Weiner > > Acked-by: Michal Hocko > > Thanks! > > > --- > > changes in v3: > > - Moved psi_memstall_leave after the "out" label > > > > mm/page_alloc.c | 10 ++++++---- > > 1 file changed, 6 insertions(+), 4 deletions(-) > > > > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > > index 3589febc6d31..029bceb79861 100644 > > --- a/mm/page_alloc.c > > +++ b/mm/page_alloc.c > > @@ -4595,13 +4595,12 @@ __perform_reclaim(gfp_t gfp_mask, unsigned int order, > > const struct alloc_context *ac) > > { > > unsigned int noreclaim_flag; > > - unsigned long pflags, progress; > > + unsigned long progress; > > > > cond_resched(); > > > > /* We now go into synchronous reclaim */ > > cpuset_memory_pressure_bump(); > > - psi_memstall_enter(&pflags); > > fs_reclaim_acquire(gfp_mask); > > noreclaim_flag = memalloc_noreclaim_save(); > > > > @@ -4610,7 +4609,6 @@ __perform_reclaim(gfp_t gfp_mask, unsigned int order, > > > > memalloc_noreclaim_restore(noreclaim_flag); > > fs_reclaim_release(gfp_mask); > > - psi_memstall_leave(&pflags); > > > > cond_resched(); > > > > @@ -4624,11 +4622,13 @@ __alloc_pages_direct_reclaim(gfp_t gfp_mask, unsigned int order, > > unsigned long *did_some_progress) > > { > > struct page *page = NULL; > > + unsigned long pflags; > > bool drained = false; > > > > + psi_memstall_enter(&pflags); > > *did_some_progress = __perform_reclaim(gfp_mask, order, ac); > > if (unlikely(!(*did_some_progress))) > > - return NULL; > > + goto out; > > > > retry: > > page = get_page_from_freelist(gfp_mask, order, alloc_flags, ac); > > @@ -4644,6 +4644,8 @@ __alloc_pages_direct_reclaim(gfp_t gfp_mask, unsigned int order, > > drained = true; > > goto retry; > > } > > +out: > > + psi_memstall_leave(&pflags); > > > > return page; > > } > > -- > > 2.35.1.473.g83b2b277ed-goog > > -- > Michal Hocko > SUSE Labs > > -- > To unsubscribe from this group and stop receiving emails from it, send an email to kernel-team+unsubscribe@android.com. >