From patchwork Wed Nov 18 03:22:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhaoyang Huang X-Patchwork-Id: 11913797 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 98E0DC56202 for ; Wed, 18 Nov 2020 03:23:10 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E115B24698 for ; Wed, 18 Nov 2020 03:23:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="tnHOdOJZ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E115B24698 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 220066B0036; Tue, 17 Nov 2020 22:23:09 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1A9CA6B005C; Tue, 17 Nov 2020 22:23:09 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 023F26B0068; Tue, 17 Nov 2020 22:23:08 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0122.hostedemail.com [216.40.44.122]) by kanga.kvack.org (Postfix) with ESMTP id C30E26B0036 for ; Tue, 17 Nov 2020 22:23:08 -0500 (EST) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 63C6F181AEF1D for ; Wed, 18 Nov 2020 03:23:08 +0000 (UTC) X-FDA: 77496092856.07.cent82_570f7f727336 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin07.hostedemail.com (Postfix) with ESMTP id 4F0B91803F9A7 for ; Wed, 18 Nov 2020 03:23:08 +0000 (UTC) X-HE-Tag: cent82_570f7f727336 X-Filterd-Recvd-Size: 5476 Received: from mail-pf1-f196.google.com (mail-pf1-f196.google.com [209.85.210.196]) by imf19.hostedemail.com (Postfix) with ESMTP for ; Wed, 18 Nov 2020 03:23:07 +0000 (UTC) Received: by mail-pf1-f196.google.com with SMTP id v12so500519pfm.13 for ; Tue, 17 Nov 2020 19:23:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=VbxZX7WZligZjkSjsPYjoIiLte2+7MW+ya6moaJXAZc=; b=tnHOdOJZRTbSZlzSiQyyUSf3QheUdLAMWcgI49dddOaT/IAJq1FZZpuNDWAAg+5ane IdyomdfrMjEJJfLNFpYy4DZcCyeCOw7fNX2/+rtNd/Z0OkPQEILhfU7fVhbDP2YOJCV5 Y00D6CLcgLtQCGBiyHIcvcaSjHnl0h5xpGzM1A6qwSynmj9RJDnfu3nWnJNqVAbgm/6n 4LopK7mNTzh2/V/mqPDNsepnS2LD/AcAL0gYf26VEfwDOeUgfpdsLGqV2KnOeHz+QuzX pWnA48BAqsVOwBvFZEZPZnkvBs6ngOTerJgDAx7VFA5sDgpj8D8aLJVW4kh80h342U2Z niZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=VbxZX7WZligZjkSjsPYjoIiLte2+7MW+ya6moaJXAZc=; b=MJlAc74eDQZtnfyCyfSlRrLClYgeX2Q08N1R7D4giiNomikAfVCAS6oNzpZ8LMrjzj eRlM/cqVNszvfJBpXGwC+uRmlc2aKawYafCQABtlXR9WyMPctEeen/IjfWXhPrEfFSro TK+Ufx1tpLYuKoxQHd6VNIHruj0uTf7ZbxL1eKy9KDwI3c3KoruX7F1PexX7v6bTn6MI VCC55La+e3Lq09U6XpljUUnJGdKcmCNs/P/sUkVSOR4iLbdIZK3CSrElifwxilmj3m8a cUO722LzsT+APVr59I1yUVHSWkvloQiMq0f50NKJ9sZrJeyB4QhF7DgeW2djE1spNhpe +JwQ== X-Gm-Message-State: AOAM530b/t/BXX4OEbqpsAfJPwlErQU5ZB9Za32q7XhvEuGi/al5sAoJ 8oryKXRAcbeKsSogSfFDRlA= X-Google-Smtp-Source: ABdhPJx9dLn+FwfoxB4sZt+nr8eOpIqAcpQQWlxMqtCwJxS/NyqIFlb0fmuUP7PhnfnReH70MSZXqw== X-Received: by 2002:a63:5853:: with SMTP id i19mr6529864pgm.333.1605669787037; Tue, 17 Nov 2020 19:23:07 -0800 (PST) Received: from bj03382pcu.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id f21sm20055197pga.32.2020.11.17.19.23.05 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Nov 2020 19:23:06 -0800 (PST) From: Zhaoyang Huang X-Google-Original-From: Zhaoyang Huang To: Zhaoyang Huang , Ingo Molnar , Peter Zijlstra , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH] mm: bail out from psi memstall when cond_resched Date: Wed, 18 Nov 2020 11:22:56 +0800 Message-Id: <1605669776-24242-1-git-send-email-zhaoyang.huang@unisoc.com> X-Mailer: git-send-email 1.7.9.5 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Memory reclaiming will run as several seconds in memory constraint system, which will be deemed as heavy memstall. Have the memory reclaim be more presiced by bailing out when cond_resched Signed-off-by: Zhaoyang Huang --- mm/vmscan.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index a815f73..a083c85 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -316,6 +316,15 @@ static inline bool memcg_congested(struct pglist_data *pgdat, } #endif +static inline void psi_cond_resched(void) +{ + unsigned long *flags; + + if (current->flags & PF_MEMSTALL) + psi_memstall_leave(&flags); + cond_resched(); + psi_memstall_enter(&flags); +} /* * This misses isolated pages which are not accounted for to save counters. * As the data only determines if reclaim or compaction continues, it is @@ -557,7 +566,7 @@ static unsigned long do_shrink_slab(struct shrink_control *shrinkctl, total_scan -= shrinkctl->nr_scanned; scanned += shrinkctl->nr_scanned; - cond_resched(); + psi_cond_resched(); } if (next_deferred >= scanned) @@ -714,7 +723,7 @@ static unsigned long shrink_slab(gfp_t gfp_mask, int nid, up_read(&shrinker_rwsem); out: - cond_resched(); + psi_cond_resched(); return freed; } @@ -1109,7 +1118,7 @@ static unsigned long shrink_page_list(struct list_head *page_list, unsigned nr_reclaimed = 0; memset(stat, 0, sizeof(*stat)); - cond_resched(); + psi_cond_resched(); while (!list_empty(page_list)) { struct address_space *mapping; @@ -1118,7 +1127,7 @@ static unsigned long shrink_page_list(struct list_head *page_list, enum page_references references = PAGEREF_RECLAIM_CLEAN; bool dirty, writeback; - cond_resched(); + psi_cond_resched(); page = lru_to_page(page_list); list_del(&page->lru); @@ -2084,7 +2093,7 @@ static void shrink_active_list(unsigned long nr_to_scan, spin_unlock_irq(&pgdat->lru_lock); while (!list_empty(&l_hold)) { - cond_resched(); + psi_cond_resched(); page = lru_to_page(&l_hold); list_del(&page->lru); @@ -2500,7 +2509,7 @@ static void shrink_node_memcg(struct pglist_data *pgdat, struct mem_cgroup *memc } } - cond_resched(); + psi_cond_resched(); if (nr_reclaimed < nr_to_reclaim || scan_adjusted) continue; @@ -4149,7 +4158,7 @@ static int __node_reclaim(struct pglist_data *pgdat, gfp_t gfp_mask, unsigned in .reclaim_idx = gfp_zone(gfp_mask), }; - cond_resched(); + psi_cond_resched(); fs_reclaim_acquire(sc.gfp_mask); /* * We need to be able to allocate from the reserves for RECLAIM_UNMAP