Received: by 2002:ac0:da4c:0:0:0:0:0 with SMTP id a12csp2561416imi; Mon, 25 Jul 2022 01:51:21 -0700 (PDT) X-Google-Smtp-Source: AGRyM1u2aDVO0NTFMLZ42W8/OY8y671JCWJ05C+OZDoBpfh4+4xifewkPUmyNGVlF9rufRpdWvdj X-Received: by 2002:a17:907:3e86:b0:6f5:917:10cc with SMTP id hs6-20020a1709073e8600b006f5091710ccmr9430226ejc.53.1658739081500; Mon, 25 Jul 2022 01:51:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658739081; cv=none; d=google.com; s=arc-20160816; b=BCK7TUvsfMCt+q20Vt5eI6fiQ12RyGAhrxfuknQE+Yy73znsUsKlz4KPrgXLWYshEh CxbW+NzbDLQT4RtlmuZ+zQVULAz7TBP24Z9Fr5Ci0EVtuUebHefCnH1BvYDgdAmU1e8a wJShmMZo7tsAr1J+l+O+7XBDhtRbf8mGpPMsz52oEJWuEuWanuc5Wg78uxlafHJhtWzD HONimUy8KbhZMwXWSojFYgsrUEI3V5dFroBHFiQMMC3Lh/6T+ZrdpEa2iltnQUXOXk+B TGUFVbuVKXsXa5t9iAFgmR+jIwzg3A68UhfLMvFM0pMPBAgU1PgomAkAriGbGWmgZ3u3 Hlyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=ZzCqf5SO3G5XNE6TyYnaglEEdIMWG1eN6LeWnvG0iHs=; b=hVpIKr9UixV3JhmCFPGIsUhEpIjmFPeE3YNzfYQzNF6M4h65bSbFtKQ6X71peGt8l4 KBDCkQiCinv6zkXE48z8kwX4xcKUnYAcL/K7FX9gsVQKAOXJLCdB5ixEYSBQL4eHWepb m6mWCPUWRFuolkGG/PFXMOUYbL+0lq9vzPQUav1BQUFOMIWi4H5C93LaaB0ntfgGucVP Zp0rn4QEOzwl/HP5CJqVWlzcNisQsijmGuAYourqi4E+yrprmN6wfeXkdFZYdV5HwH9p D2RVhaBlCNISHQTegP+yYxL1yrehDKm91JWhj6flrjRt48Iht0JA+G+pKGYGsY60BXLw lTrg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g8-20020a1709065d0800b0072acbcfa511si13550837ejt.797.2022.07.25.01.50.56; Mon, 25 Jul 2022 01:51:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232478AbiGYImQ (ORCPT + 99 others); Mon, 25 Jul 2022 04:42:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231506AbiGYImP (ORCPT ); Mon, 25 Jul 2022 04:42:15 -0400 Received: from outbound-smtp63.blacknight.com (outbound-smtp63.blacknight.com [46.22.136.252]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C5C914036 for ; Mon, 25 Jul 2022 01:42:13 -0700 (PDT) Received: from mail.blacknight.com (pemlinmail05.blacknight.ie [81.17.254.26]) by outbound-smtp63.blacknight.com (Postfix) with ESMTPS id 0FE8BFAC5F for ; Mon, 25 Jul 2022 09:42:12 +0100 (IST) Received: (qmail 26044 invoked from network); 25 Jul 2022 08:42:11 -0000 Received: from unknown (HELO techsingularity.net) (mgorman@techsingularity.net@[84.203.198.246]) by 81.17.254.9 with ESMTPSA (AES256-SHA encrypted, authenticated); 25 Jul 2022 08:42:11 -0000 Date: Mon, 25 Jul 2022 09:42:04 +0100 From: Mel Gorman To: Jaewon Kim Cc: minchan@kernel.org, akpm@linux-foundation.org, bhe@redhat.com, vbabka@suse.cz, hannes@cmpxchg.org, mhocko@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, gh21.hong@samsung.com, ytk.lee@samsung.com, jaewon31.kim@gmail.com Subject: Re: [PATCH] page_alloc: fix invalid watemark check on a negative value Message-ID: <20220725084204.52kdi6jyjhytzudm@techsingularity.net> References: <20220725012843.17115-1-jaewon31.kim@samsung.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Disposition: inline In-Reply-To: <20220725012843.17115-1-jaewon31.kim@samsung.com> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS autolearn=ham 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 Mon, Jul 25, 2022 at 10:28:43AM +0900, Jaewon Kim wrote: > There was a report that a task is waiting at the > throttle_direct_reclaim. The pgscan_direct_throttle in vmstat was > increasing. > > This is a bug where zone_watermark_fast returns true even when the free > is very low. The commit f27ce0e14088 ("page_alloc: consider highatomic > reserve in watermark fast") changed the watermark fast to consider > highatomic reserve. But it did not handle a negative value case which > can be happened when reserved_highatomic pageblock is bigger than the > actual free. > > If watermark is considered as ok for the negative value, allocating > contexts for order-0 will consume all free pages without direct reclaim, > and finally free page may become depleted except highatomic free. > > Then allocating contexts may fall into throttle_direct_reclaim. This > symptom may easily happen in a system where wmark min is low and other > reclaimers like kswapd does not make free pages quickly. > > To handle the negative value, get the value as long type like > __zone_watermark_ok does. > > Reported-by: GyeongHwan Hong > Signed-off-by: Jaewon Kim Add Fixes: f27ce0e14088 ("page_alloc: consider highatomic reserve in watermark fast") The fix is fine as-is but it's not immediately obvious why this can wrap negative as it depends on an implementation detail of __zone_watermark_unusable_free. The variable copy just to change the sign could get accidentally "fixed" later as a micro-optimisation (same if the type of mark was changed) so maybe leave a comment like /* unusable may over-estimate high-atomic reserves */ Otherwise Acked-by: Mel Gorman The problem could also be made explicit with something like below. I know you are copying the logic of __zone_watermark_ok but I don't think min can go negative there. diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 934d1b5a5449..f8f50a2aa43e 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -4048,11 +4048,15 @@ static inline bool zone_watermark_fast(struct zone *z, unsigned int order, * need to be calculated. */ if (!order) { - long fast_free; + long usable_free; + long reserved; - fast_free = free_pages; - fast_free -= __zone_watermark_unusable_free(z, 0, alloc_flags); - if (fast_free > mark + z->lowmem_reserve[highest_zoneidx]) + usable_free = free_pages; + reserved = __zone_watermark_unusable_free(z, 0, alloc_flags); + + /* reserved may over estimate high-atomic reserves. */ + usable_free -= min(usable_free, reserved); + if (usable_free > mark + z->lowmem_reserve[highest_zoneidx]) return true; } -- Mel Gorman SUSE Labs