Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp1509126ybx; Thu, 7 Nov 2019 12:54:46 -0800 (PST) X-Google-Smtp-Source: APXvYqxcj3wEqSD6N6oeeoUb868FXkX4vRa63NSHlhL6DjhjHRjL96oY+3KkGVZNDIVIVHXYsAaZ X-Received: by 2002:a17:906:1611:: with SMTP id m17mr5347109ejd.281.1573160086132; Thu, 07 Nov 2019 12:54:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573160086; cv=none; d=google.com; s=arc-20160816; b=f8/NKp348eL+lpa1nLM/QeMtOJIPYCXDVlvn0pBUYIwi0CkCQz7MKu3s6qLBRcZk/r 45AmmBitlJ1FF7Cu6NVqyGnHH4v1rYvcTrnO54g5SmeeggoCuBte5sb7V/mvitE6Kq2M +JvK7zXeXFz3dsHn0gfM56Mwpr1Q7hBniGprPRpIDxp4BwO7Wj89lUhroNGt3WlailZ6 M6v3k6Rdlz5q0OklYIYSV0AJq5b79BSWXUYMYMsTJtQMux5TU9v3JwUkBykcgwL1bDX5 KHy+SvfPYRhd9oABBPEX9S2+PeAy9QJ36RsQr0vXTd37P5Mt0xj6qAPYjR/5TnGojavP evXg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=GnXcKvw24Mkpxrnsn9Jk/2NsGqvskVrKtfbs3H323nA=; b=h94kFx6gVNesLEr0sKjXzQO0YIwsU1th1xyZenYwqYWCbOAuxKcB/1hex/l5hhALEB Q6Lmf1/jdyLArH9sBtZ3gmKQnceNXDNmdTpz9RZloe9h4MzoTg2VnzTqaTQcdTdOCMsI Yr4pRJO9NIoeLTES0QKO4OefA4GE0vH6p+s0HIvFpD+jUfK35vRUFMYPYi2alkYAFlLg x0dCLSKqHJqqwaCiYiy2zwYTseNTQrxiXLs22cxRlJRINIOTUMDgl585en/x9kt0aSVJ +uTcfd0mroGSonrwIB+U7n/r1KlmcXF5rQeCac4Oc3jLzy1tN0PDUA0/qnFkG7v7s/ad kNag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=OzWbKP3Q; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c11si2363756ejr.176.2019.11.07.12.54.21; Thu, 07 Nov 2019 12:54:46 -0800 (PST) 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=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=OzWbKP3Q; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727437AbfKGUxn (ORCPT + 99 others); Thu, 7 Nov 2019 15:53:43 -0500 Received: from mail-pg1-f196.google.com ([209.85.215.196]:37694 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727401AbfKGUxm (ORCPT ); Thu, 7 Nov 2019 15:53:42 -0500 Received: by mail-pg1-f196.google.com with SMTP id z24so2763790pgu.4 for ; Thu, 07 Nov 2019 12:53:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=GnXcKvw24Mkpxrnsn9Jk/2NsGqvskVrKtfbs3H323nA=; b=OzWbKP3QiAn5Cn8rqW3do83+lh2GNKnq0FS6MLFOgzuNg9dowb58c23NoQzbB4lOdp W/UmmwJIvWubOW8e8AJP+Ab0S8N1ndrzXmVCVkPfewcm1xbU9rkvqPvwCOU8QjJ0TCz1 2XA8J6K9+5TBaC2uSnBomFE2jescOZki3s/+b7Zs8yd34ZfQTpzAi0FICpNiOTlz2+iG aepA0Eqnm1gTv2wpj5IcSHjnJhNPZMhqlHSPShHOjL5/j8blN+6ibf/WtsHncdXvrzo1 XbshrsG+fEWB6/dMhCk8in4SmLpDYy0wWZ0Rcw2WEvEW4Pno2tVgkBqADGtysU6hrNC2 1Ngg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=GnXcKvw24Mkpxrnsn9Jk/2NsGqvskVrKtfbs3H323nA=; b=IDX65EqOUKfM08kcJqf9zuWsC9fy+gC8OdrfGGwHod6H/P8lpVgrKhLHSO4WLksyX/ DGXyog5pz/I+0sud/Re0oD6VJEruUo86eSYz7wi0YUU8YTG9cyL6vEqZWmFYWLctSNM6 JfnNQfkXL+ihmVzSCyAQjwfRVMY8A1WZFEesEQlNM+HhzmBP6iBJTlDBSwP2KJCH3J5l EbKCW5+iCOkilHolM3Q++gGUY5YT9459URstYQn1sEZJzQz50ZDisqu2dFu/RQB/pKKH t3GMKWy/U1/J8z9cArlChsyoUjYCq9cIGm/LRQt3B2LAhZ1ZKcXOK2Lrh/v2GCNrUkF9 clkw== X-Gm-Message-State: APjAAAUkGGlh+RPgmy4AyQ21SC47evKAKOo7ZImVdfHk9459+SFlbLmH cGPhXu7RGKmSB0m1VdYH0YNFzQ== X-Received: by 2002:a62:53:: with SMTP id 80mr7030693pfa.192.1573160020255; Thu, 07 Nov 2019 12:53:40 -0800 (PST) Received: from localhost ([2620:10d:c090:200::3:3792]) by smtp.gmail.com with ESMTPSA id r11sm2952834pjp.14.2019.11.07.12.53.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Nov 2019 12:53:39 -0800 (PST) From: Johannes Weiner To: Andrew Morton Cc: Andrey Ryabinin , Suren Baghdasaryan , Shakeel Butt , Rik van Riel , Michal Hocko , linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 1/3] mm: vmscan: move file exhaustion detection to the node level Date: Thu, 7 Nov 2019 12:53:32 -0800 Message-Id: <20191107205334.158354-2-hannes@cmpxchg.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191107205334.158354-1-hannes@cmpxchg.org> References: <20191107205334.158354-1-hannes@cmpxchg.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When file pages are lower than the watermark on a node, we try to force scan anonymous pages to counter-act the balancing algorithms preference for new file pages when they are likely thrashing. This is a node-level decision, but it's currently made each time we look at an lruvec. This is unnecessarily expensive and also a layering violation that makes the code harder to understand. Clean this up by making the check once per node and setting a flag in the scan_control. Signed-off-by: Johannes Weiner Reviewed-by: Shakeel Butt --- mm/vmscan.c | 80 ++++++++++++++++++++++++++++------------------------- 1 file changed, 42 insertions(+), 38 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index d97985262dda..e8dd601e1fad 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -101,6 +101,9 @@ struct scan_control { /* One of the zones is ready for compaction */ unsigned int compaction_ready:1; + /* The file pages on the current node are dangerously low */ + unsigned int file_is_tiny:1; + /* Allocation order */ s8 order; @@ -2289,45 +2292,16 @@ static void get_scan_count(struct lruvec *lruvec, struct scan_control *sc, } /* - * Prevent the reclaimer from falling into the cache trap: as - * cache pages start out inactive, every cache fault will tip - * the scan balance towards the file LRU. And as the file LRU - * shrinks, so does the window for rotation from references. - * This means we have a runaway feedback loop where a tiny - * thrashing file LRU becomes infinitely more attractive than - * anon pages. Try to detect this based on file LRU size. + * If the system is almost out of file pages, force-scan anon. + * But only if there are enough inactive anonymous pages on + * the LRU. Otherwise, the small LRU gets thrashed. */ - if (!cgroup_reclaim(sc)) { - unsigned long pgdatfile; - unsigned long pgdatfree; - int z; - unsigned long total_high_wmark = 0; - - pgdatfree = sum_zone_node_page_state(pgdat->node_id, NR_FREE_PAGES); - pgdatfile = node_page_state(pgdat, NR_ACTIVE_FILE) + - node_page_state(pgdat, NR_INACTIVE_FILE); - - for (z = 0; z < MAX_NR_ZONES; z++) { - struct zone *zone = &pgdat->node_zones[z]; - if (!managed_zone(zone)) - continue; - - total_high_wmark += high_wmark_pages(zone); - } - - if (unlikely(pgdatfile + pgdatfree <= total_high_wmark)) { - /* - * Force SCAN_ANON if there are enough inactive - * anonymous pages on the LRU in eligible zones. - * Otherwise, the small LRU gets thrashed. - */ - if (!inactive_list_is_low(lruvec, false, sc, false) && - lruvec_lru_size(lruvec, LRU_INACTIVE_ANON, sc->reclaim_idx) - >> sc->priority) { - scan_balance = SCAN_ANON; - goto out; - } - } + if (sc->file_is_tiny && + !inactive_list_is_low(lruvec, false, sc, false) && + lruvec_lru_size(lruvec, LRU_INACTIVE_ANON, + sc->reclaim_idx) >> sc->priority) { + scan_balance = SCAN_ANON; + goto out; } /* @@ -2754,6 +2728,36 @@ static bool shrink_node(pg_data_t *pgdat, struct scan_control *sc) nr_reclaimed = sc->nr_reclaimed; nr_scanned = sc->nr_scanned; + /* + * Prevent the reclaimer from falling into the cache trap: as + * cache pages start out inactive, every cache fault will tip + * the scan balance towards the file LRU. And as the file LRU + * shrinks, so does the window for rotation from references. + * This means we have a runaway feedback loop where a tiny + * thrashing file LRU becomes infinitely more attractive than + * anon pages. Try to detect this based on file LRU size. + */ + if (!cgroup_reclaim(sc)) { + unsigned long file; + unsigned long free; + int z; + unsigned long total_high_wmark = 0; + + free = sum_zone_node_page_state(pgdat->node_id, NR_FREE_PAGES); + file = node_page_state(pgdat, NR_ACTIVE_FILE) + + node_page_state(pgdat, NR_INACTIVE_FILE); + + for (z = 0; z < MAX_NR_ZONES; z++) { + struct zone *zone = &pgdat->node_zones[z]; + if (!managed_zone(zone)) + continue; + + total_high_wmark += high_wmark_pages(zone); + } + + sc->file_is_tiny = file + free <= total_high_wmark; + } + shrink_node_memcgs(pgdat, sc); if (reclaim_state) { -- 2.24.0