Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1205009pxj; Fri, 18 Jun 2021 01:47:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyu/olVfrGIh6GBrpP1JCG7xIib5TgQsdyQ2ch1scOZwzOI8MttSgIRgZgjGT5g7hsmSLo2 X-Received: by 2002:a05:6e02:5d1:: with SMTP id l17mr6491362ils.162.1624006050506; Fri, 18 Jun 2021 01:47:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624006050; cv=none; d=google.com; s=arc-20160816; b=ZVyKQorCs85d2JqqbewOyKAbZdPp6TnSsBT45j4EV8khxWIlRHgezvHqSTNUwdUD9r rdAA9Kt54E1nnSJaA0V13LVT/G85oNeC5jxITFJPF+UvUB72riaEPC39CIoJUzXx88dP ykolS81oESecshpdmfKPVMWGTS8BrWaz6fPrOGTOLWVlgil3naq+PYk4EgBlKXeeXwTJ nctSkVTKkqd9Bowj/c1iHxrlnvZthBuQZEqDT8urIUC0LUA1fDWL+eUBGbNciY2zb31J /1PnxwwlpJy0mEl24rMZ4TQPnr+o3hA4EEThIszClgKnuULsfrUVsmmMPZ+BLCfaGTYd Bm6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-sdr:ironport-sdr; bh=I5+yw/IUljGV2ANnLyYWb9B60ooixZdUHuOguVJ21Fk=; b=HopTkNsduG0gX+zFHd9cX6rIc+CX7w8V2PULnqIysi2MZkFzFHmj5Vj4lOv+PwdNdE JuQYByXo4na2x68YJqX//Qm6IVe+IdpJM9I5tP1UGyNoC0mGArcfFAzYTYffOJNZW4Ak HRbbK6dppHeQNJZFl2oIRRODwIDCUTxkcf1k/WojehREfpc/Gj8WJ2ME/tKITcARj0M8 ph568vWKGkfZOw34RJqG6O8gzEpumZgNQMVyOyb/clDHZpwMNDUY0QmUGyQRaGtRYh/5 So9/AdA2hV+0B3hGlHa2jVT8LSJRWxyzM2v8Vws3C57htuOddaHaCMzMZ1V1xik871Uq g0ZA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l11si9388674iow.13.2021.06.18.01.47.18; Fri, 18 Jun 2021 01:47:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232650AbhFRGW7 (ORCPT + 99 others); Fri, 18 Jun 2021 02:22:59 -0400 Received: from mga18.intel.com ([134.134.136.126]:4823 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232394AbhFRGU6 (ORCPT ); Fri, 18 Jun 2021 02:20:58 -0400 IronPort-SDR: Er3bHynbi9kGG7/Qin4BPa2cDQZqsPxiAt5a3bPpqEiU/BZFLpYYU9J53XiaUL5SsJsi9AUEPD Sl7YdCo+G+wA== X-IronPort-AV: E=McAfee;i="6200,9189,10018"; a="193815273" X-IronPort-AV: E=Sophos;i="5.83,283,1616482800"; d="scan'208";a="193815273" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Jun 2021 23:16:30 -0700 IronPort-SDR: mrsrbjnulGResonwwRAnorHqJvjiY+JLvv3kupci1kC/8rUC8uavMvKXythzg0Q+B3ODTUMlpC 4xdFSkDDd8YA== X-IronPort-AV: E=Sophos;i="5.83,283,1616482800"; d="scan'208";a="485573705" Received: from mzhou6-mobl1.ccr.corp.intel.com (HELO yhuang6-mobl1.ccr.corp.intel.com) ([10.254.212.155]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Jun 2021 23:16:27 -0700 From: Huang Ying To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, Keith Busch , Dave Hansen , "Huang, Ying" , Yang Shi , Michal Hocko , Wei Xu , David Rientjes , Dan Williams , David Hildenbrand , osalvador Subject: [PATCH -V8 08/10] mm/vmscan: Consider anonymous pages without swap Date: Fri, 18 Jun 2021 14:15:35 +0800 Message-Id: <20210618061537.434999-9-ying.huang@intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210618061537.434999-1-ying.huang@intel.com> References: <20210618061537.434999-1-ying.huang@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Keith Busch Reclaim anonymous pages if a migration path is available now that demotion provides a non-swap recourse for reclaiming anon pages. Note that this check is subtly different from the anon_should_be_aged() checks. This mechanism checks whether a specific page in a specific context *can* actually be reclaimed, given current swap space and cgroup limits anon_should_be_aged() is a much simpler and more preliminary check which just says whether there is a possibility of future reclaim. Cc: Keith Busch Signed-off-by: Dave Hansen Signed-off-by: "Huang, Ying" Reviewed-by: Yang Shi Cc: Michal Hocko Cc: Wei Xu Cc: David Rientjes Cc: Dan Williams Cc: David Hildenbrand Cc: osalvador -- Changes from Dave 10/2020: * remove 'total_swap_pages' modification Changes from Dave 06/2020: * rename reclaim_anon_pages()->can_reclaim_anon_pages() Note: Keith's Intel SoB is commented out because he is no longer at Intel and his @intel.com mail will bounce. --- mm/vmscan.c | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 8654cec65522..bf52329f29dd 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -516,6 +516,34 @@ static long add_nr_deferred(long nr, struct shrinker *shrinker, return atomic_long_add_return(nr, &shrinker->nr_deferred[nid]); } +static inline bool can_reclaim_anon_pages(struct mem_cgroup *memcg, + int node_id) +{ + if (memcg == NULL) { + /* + * For non-memcg reclaim, is there + * space in any swap device? + */ + if (get_nr_swap_pages() > 0) + return true; + } else { + /* Is the memcg below its swap limit? */ + if (mem_cgroup_get_nr_swap_pages(memcg) > 0) + return true; + } + + /* + * The page can not be swapped. + * + * Can it be reclaimed from this node via demotion? + */ + if (next_demotion_node(node_id) >= 0) + return true; + + /* No way to reclaim anon pages */ + return false; +} + /* * This misses isolated pages which are not accounted for to save counters. * As the data only determines if reclaim or compaction continues, it is @@ -527,7 +555,7 @@ unsigned long zone_reclaimable_pages(struct zone *zone) nr = zone_page_state_snapshot(zone, NR_ZONE_INACTIVE_FILE) + zone_page_state_snapshot(zone, NR_ZONE_ACTIVE_FILE); - if (get_nr_swap_pages() > 0) + if (can_reclaim_anon_pages(NULL, zone_to_nid(zone))) nr += zone_page_state_snapshot(zone, NR_ZONE_INACTIVE_ANON) + zone_page_state_snapshot(zone, NR_ZONE_ACTIVE_ANON); @@ -2521,6 +2549,7 @@ enum scan_balance { static void get_scan_count(struct lruvec *lruvec, struct scan_control *sc, unsigned long *nr) { + struct pglist_data *pgdat = lruvec_pgdat(lruvec); struct mem_cgroup *memcg = lruvec_memcg(lruvec); unsigned long anon_cost, file_cost, total_cost; int swappiness = mem_cgroup_swappiness(memcg); @@ -2531,7 +2560,7 @@ static void get_scan_count(struct lruvec *lruvec, struct scan_control *sc, enum lru_list lru; /* If we have no swap space, do not bother scanning anon pages. */ - if (!sc->may_swap || mem_cgroup_get_nr_swap_pages(memcg) <= 0) { + if (!sc->may_swap || !can_reclaim_anon_pages(memcg, pgdat->node_id)) { scan_balance = SCAN_FILE; goto out; } @@ -2906,7 +2935,7 @@ static inline bool should_continue_reclaim(struct pglist_data *pgdat, */ pages_for_compaction = compact_gap(sc->order); inactive_lru_pages = node_page_state(pgdat, NR_INACTIVE_FILE); - if (get_nr_swap_pages() > 0) + if (can_reclaim_anon_pages(NULL, pgdat->node_id)) inactive_lru_pages += node_page_state(pgdat, NR_INACTIVE_ANON); return inactive_lru_pages > pages_for_compaction; -- 2.30.2