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 03B5BC4332F for ; Wed, 23 Feb 2022 19:43:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 898728D0051; Wed, 23 Feb 2022 14:43:25 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 847798D0011; Wed, 23 Feb 2022 14:43:25 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 70F298D0051; Wed, 23 Feb 2022 14:43:25 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.25]) by kanga.kvack.org (Postfix) with ESMTP id 4CBC68D0011 for ; Wed, 23 Feb 2022 14:43:25 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id CF8148087D for ; Wed, 23 Feb 2022 19:43:24 +0000 (UTC) X-FDA: 79175068728.01.A76DFE4 Received: from mail-yb1-f172.google.com (mail-yb1-f172.google.com [209.85.219.172]) by imf11.hostedemail.com (Postfix) with ESMTP id 3861F4000C for ; Wed, 23 Feb 2022 19:43:22 +0000 (UTC) Received: by mail-yb1-f172.google.com with SMTP id g6so28848240ybe.12 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=VYxdyjcqNbLtjCVLfWV63jusTOHKs5RlxIMCPoT7Bi4j0+jSWzvg9i+oAf4nT9tXwv NXLWo6bS+Nav/FQ23ia2AuZPLbZZjGLnM0c6aLtJCpBWTrhOFdxXWCRB/L4VJjopUDn2 PE3BjSW6weKjFmG/einzt6CWKByhuLc9MnMJvmeKNVtm7ioAHlW7P0TpjP9nY8/Zc1Va o6zyXS6cy+oeB+J12+Z8r311TsBLVUtvHTHW0/RuNoTKFO4UUcEN0WxuLvyIqXTG9/UP 9SYiU5Zsk8J6wz7gn32ED5zyfa0qrqATVOudr7Dr67OHimOTHCrzO3qZ5qe0IylQZ0ud 1v1g== X-Gm-Message-State: AOAM531/5YrViGxjXXoSgIkOS7eAfc4VbQk63/YxHVIsGhxSQi417W/k 9uoMAqYnqAkRnM0J18zXRpaZ0KtL/LVphYNe3b8JyQ== X-Google-Smtp-Source: ABdhPJxXoRWS8X+v/OApN513fsdXy5xIoRE2m6FSI7EuUKMpgwxXNlDcmngcr37rxM4DzMMuBTydk7yfJInMTgWbo2E= 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-Rspamd-Queue-Id: 3861F4000C X-Stat-Signature: jutaxuqw8ziyre5p8qzo4mhuec9n4z85 Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b="idFqy/xi"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf11.hostedemail.com: domain of surenb@google.com designates 209.85.219.172 as permitted sender) smtp.mailfrom=surenb@google.com X-Rspam-User: X-Rspamd-Server: rspam11 X-HE-Tag: 1645645402-522601 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, 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 >