Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp1070248pxm; Wed, 23 Feb 2022 17:20:04 -0800 (PST) X-Google-Smtp-Source: ABdhPJxl4QcbYbmloF9LazQzX+zKmOU/Nl0UFTgG0225Jhjo30qrOZSRZqdcLH1B4nJOja65Rt+7 X-Received: by 2002:a62:586:0:b0:4e1:dc81:8543 with SMTP id 128-20020a620586000000b004e1dc818543mr251354pff.0.1645665604306; Wed, 23 Feb 2022 17:20:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645665604; cv=none; d=google.com; s=arc-20160816; b=n7bMRWNqjW4d1z+4wMPKd/hVUubIFNv+YjFN2bTaadna0K2ib+Bsc3t7Leuqe0Y39h bJclhfTbg0NM4XtgXCr+zJ0EkRfqmJZ488l1lZhoExL1CWBnN9f/59TYV5UOU/JCepJ4 +8cDNHhc2J4wPjK2iqQcHMd1C8yasTKhzvHmp6k4SElwZSB6mi63QRyT+fyDcGevPHLN ACqr6GYrYj83By/wzRxbZSL+Rr9k7ZU/8FwimrQaZ4ijpJhV+6cPI9+U7i80i2J2GqZ9 JG1rbvUkUrSXTJPrAXX2kdl2CMAc1vjB47nQsKidlxE6fj9h2Dq53NCNYsVQl1IV3X9+ wCLg== 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=54/HvN726MqlsO96lMqmuncnL9Vx07+xIyR2b+fR3E4=; b=GlGWFspLxMgmWNZaGlHb7RwB3ruEwpDbjxOtJLSn7kae9JU1DFBjAXLSjcqCxF6Nla PjIMNAKIX8moJj1vo9hVIiqlvry6kv0/sV6jXehCTQCdfoik8tPwUEy/e5piBR1ar+Zg 8KFKn9zwZsVMeGwV+H3YId/50aMbivxdrOXTVsbECrn4SNpTpaMzHMl0z7Cvz1TGbUcH w2MLRw1svhfB2FD2abTKfaKJB7QSyzbdVQigO72DJuH2pvSbF/6iD8upKGjq0zuhtdCh iI5KfZpWJNU/bfFv689SMOXLfAVlb+57p2ExArZkrH1I/l9XAXOWrf5mS2Jlm46lPa+r Q5GQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="idFqy/xi"; 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 j3si1358223plr.339.2022.02.23.17.20.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Feb 2022 17:20:04 -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="idFqy/xi"; 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 59049189AB9; Wed, 23 Feb 2022 17:04:22 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244130AbiBWTnv (ORCPT + 99 others); Wed, 23 Feb 2022 14:43:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232716AbiBWTnu (ORCPT ); Wed, 23 Feb 2022 14:43:50 -0500 Received: from mail-yb1-xb33.google.com (mail-yb1-xb33.google.com [IPv6:2607:f8b0:4864:20::b33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9CB34B1EC for ; Wed, 23 Feb 2022 11:43:22 -0800 (PST) Received: by mail-yb1-xb33.google.com with SMTP id v186so50267464ybg.1 for ; Wed, 23 Feb 2022 11:43:22 -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=54/HvN726MqlsO96lMqmuncnL9Vx07+xIyR2b+fR3E4=; b=idFqy/xi+TvmjfT97O7inoduMChq7SC1fgF33ncJ50t98jHo5FawhJS6mMzdk2uynV xttWSREB3IWif7VVM95t1+Ydu4dO8MRhBdilJBDbsY2oIaUWT9iVd/b6wLcpdDrhq+ms AM0CKs9Nh1aSSTjOPL0fU7zOJW/O+7jIU0bMrG7mcl62ydAIfNRGGrNka/V3Jqg9IEKs m4B3uQHRDs846Y469RIZkV/6kaV+3DuYC5qCUFLnQy3Dy6KdC/r54DYX0W63lstgu3xz suOfMrBlcm1T1QARcV1X1atZecFuJCRSVU38+OLR7bdzzwVYeHsFOkpp9nsafE7R4cQF d33g== 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=54/HvN726MqlsO96lMqmuncnL9Vx07+xIyR2b+fR3E4=; b=8GuV3fjewDsFx48nNes7B4ROV6tH/2YjlhGXOlHyN1Ixap8QbFEBw/EMH2ksg4gWBP PLQ9ar4tOoRtdaq3cN7FWZkKg9GDtczsOEz7h/JUuYUE/9YPsl5MV8OF+ye/yPFjIOqe PBlnC/+a6QFds3GKOF0ThibLpz0kJxEtTLACwYyYEs/rF3+EymZpAEb95oXkYfb//G9t wbrHacJcXGuH3nxJ73hIiRMlez5t42XzCkgr3QiyEm1g7H4GOZsmilZAYy7ZFpjscsoV YWN1G0P6tDNqb/+Pf3BADYaF24KYwyFGDbAwmrUBsWNXjFx1VAmhYdtkP8p6j1m/S7Ay quWQ== X-Gm-Message-State: AOAM5329e+wyMPWPK76pwZfFHscXdgDWhwxuKb59ITfDyKglTnFj3jkB KQdsGX5Xn9L7s7QXXknEzFXql0kAUoU82cABbvHDxQ== X-Received: by 2002:a25:d986:0:b0:624:ddc:ff9 with SMTP id q128-20020a25d986000000b006240ddc0ff9mr1103775ybg.509.1645645401836; Wed, 23 Feb 2022 11:43:21 -0800 (PST) MIME-Version: 1.0 References: <20220223194018.1296629-1-surenb@google.com> In-Reply-To: <20220223194018.1296629-1-surenb@google.com> From: Suren Baghdasaryan Date: Wed, 23 Feb 2022 11:43:10 -0800 Message-ID: Subject: Re: [PATCH v2 1/1] mm: count time in drain_all_pages during direct reclaim as memory pressure To: akpm@linux-foundation.org Cc: hannes@cmpxchg.org, mhocko@suse.com, 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 Wed, Feb 23, 2022 at 11:40 AM 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%) > > 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 > --- > changes in v2: > - Added captured sample case to show the delay numbers, per Michal Hocko > - Moved annotation from __perform_reclaim into __alloc_pages_direct_reclaim, > per Minchan Kim > > mm/page_alloc.c | 11 ++++++----- > 1 file changed, 6 insertions(+), 5 deletions(-) > > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > index 3589febc6d31..2e9fbf28938f 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,7 +4644,8 @@ __alloc_pages_direct_reclaim(gfp_t gfp_mask, unsigned int order, > drained = true; > goto retry; > } > - > + psi_memstall_leave(&pflags); Oh, psi_memstall_leave should have been *after* the "out" label. Will fix and repost. > +out: > return page; > } > > -- > 2.35.1.473.g83b2b277ed-goog >