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 3EC1CC433EF for ; Wed, 23 Feb 2022 18:55:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5C30B8D0041; Wed, 23 Feb 2022 13:55:00 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 572738D0011; Wed, 23 Feb 2022 13:55:00 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4143E8D0041; Wed, 23 Feb 2022 13:55:00 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0135.hostedemail.com [216.40.44.135]) by kanga.kvack.org (Postfix) with ESMTP id 1A7A18D0011 for ; Wed, 23 Feb 2022 13:55:00 -0500 (EST) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 9BC5A92ED7 for ; Wed, 23 Feb 2022 18:54:59 +0000 (UTC) X-FDA: 79174946718.17.201D923 Received: from mail-qv1-f43.google.com (mail-qv1-f43.google.com [209.85.219.43]) by imf02.hostedemail.com (Postfix) with ESMTP id F19318000D for ; Wed, 23 Feb 2022 18:54:58 +0000 (UTC) Received: by mail-qv1-f43.google.com with SMTP id d3so10208671qvb.5 for ; Wed, 23 Feb 2022 10:54:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=fK7FpqspG7jF5jtxh0YvYWB/hUstBu9iQdJkK5fSXHU=; b=YhQ1GZV818HFnqsC6KhMrbhbpSiJ/BaWSfoeVKso9Ev25O2AsceHCn4UhtrQQJpKdc O3/GQq7cM0tHeud+hWzJvxAMc8C0Jxavyt4AGrUfCfLhHxkBJuolMHDMF+O3hpCYo79p kCf6jPXR76CyYhhWOMBWxiV+ArjmpVhYge2P9lWDKPLwpD6EqGrYkiGRPzBmXDg/LRv+ l/VRqcDFWSK9vBoB6/ta+iBnaoZ2KJuvbQa8sCCnng0e1Hq3Cy3ZX4CdUZQ9HKIcNsTq 24KMf/1fIH4O7/aNNSt4jXdHlRqS4FprN/fq+hb34YMku8fKuVC0GWiQjDsJUvbZNWPp UyRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=fK7FpqspG7jF5jtxh0YvYWB/hUstBu9iQdJkK5fSXHU=; b=TTuE/YngJOPyxaSgGHycjFnJL8gnW3zROhKXZInucjgVuUeo3iIHIy1LuIe0JOhjNf kQnrOj408uzZH8jSx1tsySmIfiL7LOyxTZn+lgXLiZLp8dkvOz/Jle9NqwZ6Btlc679M O8KUO0gmrvqceyJyftzCup22l9P1yL6abgsHhkqFATBwYufUMRPok7UPhile0Ud1p6JJ mgIzyKNS6hxD2TtAF05RK2POXTzK54RdAYN5oSWYj7BCwkAdr0TavAjnNABKw+b0v6nT 93bovSzTbOvaOGbj3dUMvRvdjlMreL/d/aMbSd0VRW3l2irt49SMuoVvtgW0Bn18DDfH IWZA== X-Gm-Message-State: AOAM532R1gzceZS76nJEQvYcU61PXwZ8XvtVKzFA6r0S+q9i7iAmkMxC m0OhU5ZhyZTHsVf+iQC6hLyshw== X-Google-Smtp-Source: ABdhPJxyd9gKcjqoaOsHR6RiSIBFfJnWIU2vuUHflml0HohXhfTyCB+A//GMBsJpUMADcZqbN1XOHA== X-Received: by 2002:a05:622a:1305:b0:2de:7054:2649 with SMTP id v5-20020a05622a130500b002de70542649mr1090584qtk.244.1645642497975; Wed, 23 Feb 2022 10:54:57 -0800 (PST) Received: from localhost (cpe-98-15-154-102.hvc.res.rr.com. [98.15.154.102]) by smtp.gmail.com with ESMTPSA id f207sm210953qke.22.2022.02.23.10.54.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Feb 2022 10:54:57 -0800 (PST) Date: Wed, 23 Feb 2022 13:54:56 -0500 From: Johannes Weiner To: Suren Baghdasaryan Cc: Minchan Kim , akpm@linux-foundation.org, mhocko@suse.com, peterz@infradead.org, guro@fb.com, shakeelb@google.com, timmurray@google.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@android.com Subject: Re: [PATCH 1/1] mm: count time in drain_all_pages during direct reclaim as memory pressure Message-ID: References: <20220219174940.2570901-1-surenb@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Queue-Id: F19318000D X-Stat-Signature: brhoerti69q4n59qi948ewbrhbj91gyg Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=cmpxchg-org.20210112.gappssmtp.com header.s=20210112 header.b=YhQ1GZV8; dmarc=pass (policy=none) header.from=cmpxchg.org; spf=pass (imf02.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.219.43 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org X-Rspam-User: X-Rspamd-Server: rspam11 X-HE-Tag: 1645642498-216598 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 Sun, Feb 20, 2022 at 08:52:38AM -0800, Suren Baghdasaryan wrote: > On Sat, Feb 19, 2022 at 4:40 PM Minchan Kim wrote: > > > > On Sat, Feb 19, 2022 at 09:49:40AM -0800, 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 > > > > Yes, drain_all_pages is serious slow(100ms - 150ms on Android) > > especially when CPUs are fully packed. It was also spotted in CMA > > allocation even when there was on no memory pressure. > > Thanks for the input, Minchan! > In my tests I've seen 50-60ms delays in a single drain_all_pages but I > can imagine there are cases worse than these. > > > > > > proceeding. Currently this time is not accounted as psi memory stall. > > > > Good spot. > > > > > > > > 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. > > > > > > Annotate drain_all_pages and unreserve_highatomic_pageblock during > > > page allocation failure in the direct reclaim path so that delays > > > caused by these calls are accounted as memory stall. > > > > > > Reported-by: Tim Murray > > > Signed-off-by: Suren Baghdasaryan > > > --- > > > mm/page_alloc.c | 4 ++++ > > > 1 file changed, 4 insertions(+) > > > > > > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > > > index 3589febc6d31..7fd0d392b39b 100644 > > > --- a/mm/page_alloc.c > > > +++ b/mm/page_alloc.c > > > @@ -4639,8 +4639,12 @@ __alloc_pages_direct_reclaim(gfp_t gfp_mask, unsigned int order, > > > * Shrink them and try again > > > */ > > > if (!page && !drained) { > > > + unsigned long pflags; > > > + > > > + psi_memstall_enter(&pflags); > > > unreserve_highatomic_pageblock(ac, false); > > > drain_all_pages(NULL); > > > + psi_memstall_leave(&pflags); > > > > Instead of annotating the specific drain_all_pages, how about > > moving the annotation from __perform_reclaim to > > __alloc_pages_direct_reclaim? > > I'm fine with that approach too. Let's wait for Johannes' input before > I make any changes. I think the change makes sense, even if the workqueue fix speeds up the drain. I agree with Minchan about moving the annotation upward. With it moved, please feel free to add Acked-by: Johannes Weiner