Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp7151349ybi; Mon, 8 Jul 2019 15:40:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqyDa+0yelHXHPZKFROllPFtugmpEyuYIyDXkol8eNW+ykObBow2GMuk2rh0TZ9qEiTsZl+4 X-Received: by 2002:a63:a35c:: with SMTP id v28mr26628419pgn.144.1562625650396; Mon, 08 Jul 2019 15:40:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562625650; cv=none; d=google.com; s=arc-20160816; b=PfPozdifWXBa4EuDMxe9RS+QvNojiMxQO09KO8ifVflOcdzIHQ9CmTPGeaK4qJ3ebW blg1UasK2wDvJQNhgMCVRD48FTwdsTAOQEwd5knFGdBT3O3qh/y0JqSVwpqoWJQiyuBb eeaQJ8l8bB8dDTaEVRoLVqH1HZib7HaMhIJB6heXCKVOsCRniqK/r6OXD3d+uzYsGVMa navt6rIMg3bjt4bNY5VGp1zf7UgYlYeYlQAWeASTpfEkvWvxToeaqv2/UjaZ1yuRO5MB JDGgfr+WNFHD9Et4gZ7uoxxHf7i1AL2wZMI6Qnxc+Ht1pkhCljQ2hOXkWUrtQjwEpmLH dsIQ== 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=5X5rBrdyqFzlcBdW3NfVjZoUAUgeBJeQO95kn3uLgc8=; b=VAgZYjtlClvD6c200w+M2P7AugkaJBculH4wNT1XRW3hU62VgwJMr4Q14e2mR+tnVE 5vQCCtKdjtFfjo736WZz5jG5Tss3tUoZTeSTLpRBLks0ltt9vbpQhxtZdxLnKXLkNVXl HC/tWYMymEAURw0MmbDxlQiSqM787i04D+5yOyU4NQdztKsRkcMVvSe2SS73v1FCdZDF BVJNvd2jOJyYRZ7ErFObgr5sw7Ea52jmT2ahxbk2nlIa/O4iDnaeLbSenaD2ehTTksU4 vQD/ejbZFiIYg4lGYm66bT6qOH/mLX4rdNXZ3BqM7xajlcWgw++RnjvLto6wginNwFjY qb1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=EIJkxila; 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 j18si22247760pfe.235.2019.07.08.15.40.35; Mon, 08 Jul 2019 15:40:50 -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=EIJkxila; 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 S2390546AbfGHPe2 (ORCPT + 99 others); Mon, 8 Jul 2019 11:34:28 -0400 Received: from mail.kernel.org ([198.145.29.99]:36604 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390524AbfGHPeX (ORCPT ); Mon, 8 Jul 2019 11:34:23 -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 51D35204EC; Mon, 8 Jul 2019 15:34:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1562600061; bh=LAw8ROyevx5HxY16X/9v0fGtkIyqotvJSRgnPKReu1k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EIJkxilaFxLv2cfjTzNrf0sy5LVRJKSCFSwkW4q9KWHbKntHT4yU9L1yKSF9EAGH4 1HrMApOTscPNx3SZ852luv79mpghnD4UFRZAb3iQmeilCWCaGHtXRHe2mQSEPvyGlx p31gQ42ybimVH7kdX9jBBYgoHv7emDL8F6ozKYDg= 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 5.1 81/96] mm/vmscan.c: prevent useless kswapd loops Date: Mon, 8 Jul 2019 17:13:53 +0200 Message-Id: <20190708150530.838326773@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190708150526.234572443@linuxfoundation.org> References: <20190708150526.234572443@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 @@ -3703,19 +3703,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, @@ -3856,7 +3855,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; @@ -3910,8 +3909,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;