From patchwork Wed Feb 23 19:48:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 12757471 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 C04A1C433EF for ; Wed, 23 Feb 2022 19:48:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 279928D0052; Wed, 23 Feb 2022 14:48:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 200C98D0011; Wed, 23 Feb 2022 14:48:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 07A818D0052; Wed, 23 Feb 2022 14:48:17 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.a.hostedemail.com [64.99.140.24]) by kanga.kvack.org (Postfix) with ESMTP id D18538D0011 for ; Wed, 23 Feb 2022 14:48:17 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 8152C212C4 for ; Wed, 23 Feb 2022 19:48:17 +0000 (UTC) X-FDA: 79175081034.10.5C49FA7 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf22.hostedemail.com (Postfix) with ESMTP id EC938C000C for ; Wed, 23 Feb 2022 19:48:16 +0000 (UTC) Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-2d11b6259adso400507b3.19 for ; Wed, 23 Feb 2022 11:48:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:message-id:mime-version:subject:from:to:cc; bh=MM6VpwEuHyZ5v5v0jkqjjMY1tkkmV3hr/n/VQS94jks=; b=lkZO2GjNLpY1p8wRTYMQKCURny9OLBoayJa+FZ5zbPz4LDZBvHCV06L73NHFu0MIMQ HszNdU6gZ84ueetyuYOMK9iZV4Qt2rHE0DRYDYunAcDMevcqAYdOuKRQcA7vEUyxT0ut 7iXcnr6wxHDVbUA6H7XMhS6qFii6FoVrP3V/rdcGkfwACofFURhVkxkPYKR2FEOTXszY 2j8jLTCyQeMpEBdkXgjM5p+Dqc5WPFuKFxi20BM2YbI981ObaFLYYEThPGfMuDLx/mPs QkKqjSo3yYluG9yStCtfgBj6VbLorXXj+4rsOhkgD5EnJwS3N4w0Cb1QoAf/0efvPuL9 9Ocw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=MM6VpwEuHyZ5v5v0jkqjjMY1tkkmV3hr/n/VQS94jks=; b=UykPh7fEWjngWWs/A8gnRW6pY7GSByoxkvkEqdV7D5+6PBHlmJZEh2v4WTIXLQniTd OY0GXfLOqbAwXiIybkAwwYDxPDiHeVt+7BOAFOMUP7d5DxUmNd2tFqW/NGRZbs/ZT+GP 8ppDRfa4X5bASHTMOa7keDCcdmV0Bb/bIoqhPpLbDG4Af2Kvg6mkVaQ6Wdb6yASMMEV3 PuFXKaQitpIAJNWPoSGIgHORSNgaPhtCWGPIVZF5MkzutmiMr/Qsyye4PaSKc2syA0mm +RlumHhndRrxNdCtK71IajScmfQfVoIGFcXlyzzgsR8XoDmw7yOJreqIQDiRz4RNnYdb si4w== X-Gm-Message-State: AOAM530I/zSTR2uuiDl/TfrmyPirDLVXHC9fCcqPpym+fOpJSZ7IFq/F p+8QszHR9xDwwjCp+5lkJ4KIel0HNpY= X-Google-Smtp-Source: ABdhPJzOMSgn9uDD/a4pJaJMz6d/iPAqkjY23/RUpGkAAjMqcefD2ddyVi/6WU6MFC3BPviettcstjqE6tU= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:200:5093:9fb5:d0ba:a5f]) (user=surenb job=sendgmr) by 2002:a25:b18e:0:b0:624:62c1:be56 with SMTP id h14-20020a25b18e000000b0062462c1be56mr1167372ybj.624.1645645695981; Wed, 23 Feb 2022 11:48:15 -0800 (PST) Date: Wed, 23 Feb 2022 11:48:12 -0800 Message-Id: <20220223194812.1299646-1-surenb@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.35.1.473.g83b2b277ed-goog Subject: [PATCH v3 1/1] mm: count time in drain_all_pages during direct reclaim as memory pressure From: Suren Baghdasaryan 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, surenb@google.com X-Rspamd-Queue-Id: EC938C000C X-Stat-Signature: sk8nwp4nx4wqsu8b5mww3t6953awpj7j X-Rspam-User: Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=lkZO2GjN; spf=pass (imf22.hostedemail.com: domain of 3f48WYgYKCBA8A7u3rw44w1u.s421y3AD-220Bqs0.47w@flex--surenb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3f48WYgYKCBA8A7u3rw44w1u.s421y3AD-220Bqs0.47w@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspamd-Server: rspam05 X-HE-Tag: 1645645696-15316 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: 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 Reviewed-by: Shakeel Butt Acked-by: Michal Hocko --- 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; }