Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp7149711ybi; Mon, 8 Jul 2019 15:38:39 -0700 (PDT) X-Google-Smtp-Source: APXvYqz1Ti+/Lf00I34Vp6g/ErwjJk64R0488tZ7CbxHtGBklK+VUjFzcc6zhtMinTH7p4KsQSaO X-Received: by 2002:a63:5202:: with SMTP id g2mr26373188pgb.386.1562625519132; Mon, 08 Jul 2019 15:38:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562625519; cv=none; d=google.com; s=arc-20160816; b=c/+BL9HgaT32KrS1cbfODmpeuM/FLn8goLjxeRRWKZXKGLw5XSFCqCnBr6+gorklGX 69dwF4ggEXX0thI/hzyvEGwR/PwhGVz+if4kNlp3pR+lIz9TnvD1l75N5BPlZ7W1PLVF ds54INglixRkYQH5QytaZSpJ/plV5xv7wJn2V7KZeFUH09udcVgU8hA/4CrP2rRNvMOY LI8UR965LX88z1JwDxxo8hKCFZG3gI8JgJD8eOGBqxRMiCJlPdmxK0Ib/6Z+G7lNJv7T BzgfT7S+TT1Pz+fFuLRrtcvyVO0KvW2psMKMkOaOgUgHZFdEBce9NEODdfvtG/S+Dydo k0qw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=6Nlp0jM7oO+JBfKFgfGa5eidGxt1kplNU9eHElE3jks=; b=Gi3SwMfg0/6dinUnJerP7Z5OVeM7wzwpwp4nbgOVd7ktWiIg80G0/WJvMKsbPYI/tY TciuVwHZva8jGmv3nMwSA/TKYHTvI7BsNcAMj33BD1ssuZqdxnaE3krGaQwlfFF5jiWD oicCjE9YkYrjH/kWolTHR3ZSQZvg2nXhAr2Y5lKCtXQEP9Tt1JD8I+6YPCUsbrvAfh6x axh4yf9nYyq5NPjv+p1yFwZXYUcCNmxVNXPkMYpCUXTd3GH32GnN7GmDAMi17D6tuWIR 114iR+V2J3TnkVwNVvuABtTRSfE2BelmlANzrxhLgbR/XVSig6F1JdEqH4Sg6gLcAosN uQdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=MhIE2QPG; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t4si19314947plq.93.2019.07.08.15.38.24; Mon, 08 Jul 2019 15:38:39 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=MhIE2QPG; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389414AbfGHP3B (ORCPT + 99 others); Mon, 8 Jul 2019 11:29:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:57624 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389399AbfGHP26 (ORCPT ); Mon, 8 Jul 2019 11:28:58 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2B6E021537; Mon, 8 Jul 2019 15:28:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1562599737; bh=v3p0s9VV7bGgXKLIwcoxYndAsqwbD/So0jRgwNwg3So=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MhIE2QPGgWHQ0aBbotWu0/zIyF3zGS9AatglNebAj++X/6WPy+TzqyAoBFe63bi8S 5zPJnpN0fY0q3CG2fCHh4qd8Gtd/tjWtEiwdgpCj2c7bLumoJjR4rQD/sokB3Df/AJ mvRfSmT9kzfUcZrHT2OdzYf4duoI+/01oLkhWtP8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Shakeel Butt , Yang Shi , Mel Gorman , Johannes Weiner , Michal Hocko , Vlastimil Babka , Hillf Danton , Roman Gushchin , Andrew Morton , Linus Torvalds Subject: [PATCH 4.19 61/90] mm/vmscan.c: prevent useless kswapd loops Date: Mon, 8 Jul 2019 17:13:28 +0200 Message-Id: <20190708150525.495665322@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190708150521.829733162@linuxfoundation.org> References: <20190708150521.829733162@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Shakeel Butt commit dffcac2cb88e4ec5906235d64a83d802580b119e upstream. In production we have noticed hard lockups on large machines running large jobs due to kswaps hoarding lru lock within isolate_lru_pages when sc->reclaim_idx is 0 which is a small zone. The lru was couple hundred GiBs and the condition (page_zonenum(page) > sc->reclaim_idx) in isolate_lru_pages() was basically skipping GiBs of pages while holding the LRU spinlock with interrupt disabled. On further inspection, it seems like there are two issues: (1) If kswapd on the return from balance_pgdat() could not sleep (i.e. node is still unbalanced), the classzone_idx is unintentionally set to 0 and the whole reclaim cycle of kswapd will try to reclaim only the lowest and smallest zone while traversing the whole memory. (2) Fundamentally isolate_lru_pages() is really bad when the allocation has woken kswapd for a smaller zone on a very large machine running very large jobs. It can hoard the LRU spinlock while skipping over 100s of GiBs of pages. This patch only fixes (1). (2) needs a more fundamental solution. To fix (1), in the kswapd context, if pgdat->kswapd_classzone_idx is invalid use the classzone_idx of the previous kswapd loop otherwise use the one the waker has requested. Link: http://lkml.kernel.org/r/20190701201847.251028-1-shakeelb@google.com Fixes: e716f2eb24de ("mm, vmscan: prevent kswapd sleeping prematurely due to mismatched classzone_idx") Signed-off-by: Shakeel Butt Reviewed-by: Yang Shi Acked-by: Mel Gorman Cc: Johannes Weiner Cc: Michal Hocko Cc: Vlastimil Babka Cc: Hillf Danton Cc: Roman Gushchin Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- mm/vmscan.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -3599,19 +3599,18 @@ out: } /* - * pgdat->kswapd_classzone_idx is the highest zone index that a recent - * allocation request woke kswapd for. When kswapd has not woken recently, - * the value is MAX_NR_ZONES which is not a valid index. This compares a - * given classzone and returns it or the highest classzone index kswapd - * was recently woke for. + * The pgdat->kswapd_classzone_idx is used to pass the highest zone index to be + * reclaimed by kswapd from the waker. If the value is MAX_NR_ZONES which is not + * a valid index then either kswapd runs for first time or kswapd couldn't sleep + * after previous reclaim attempt (node is still unbalanced). In that case + * return the zone index of the previous kswapd reclaim cycle. */ static enum zone_type kswapd_classzone_idx(pg_data_t *pgdat, - enum zone_type classzone_idx) + enum zone_type prev_classzone_idx) { if (pgdat->kswapd_classzone_idx == MAX_NR_ZONES) - return classzone_idx; - - return max(pgdat->kswapd_classzone_idx, classzone_idx); + return prev_classzone_idx; + return pgdat->kswapd_classzone_idx; } static void kswapd_try_to_sleep(pg_data_t *pgdat, int alloc_order, int reclaim_order, @@ -3752,7 +3751,7 @@ kswapd_try_sleep: /* Read the new order and classzone_idx */ alloc_order = reclaim_order = pgdat->kswapd_order; - classzone_idx = kswapd_classzone_idx(pgdat, 0); + classzone_idx = kswapd_classzone_idx(pgdat, classzone_idx); pgdat->kswapd_order = 0; pgdat->kswapd_classzone_idx = MAX_NR_ZONES; @@ -3806,8 +3805,12 @@ void wakeup_kswapd(struct zone *zone, gf if (!cpuset_zone_allowed(zone, gfp_flags)) return; pgdat = zone->zone_pgdat; - pgdat->kswapd_classzone_idx = kswapd_classzone_idx(pgdat, - classzone_idx); + + if (pgdat->kswapd_classzone_idx == MAX_NR_ZONES) + pgdat->kswapd_classzone_idx = classzone_idx; + else + pgdat->kswapd_classzone_idx = max(pgdat->kswapd_classzone_idx, + classzone_idx); pgdat->kswapd_order = max(pgdat->kswapd_order, order); if (!waitqueue_active(&pgdat->kswapd_wait)) return;