From patchwork Sun Oct 23 08:04:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 13016142 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id F38B4ECAAA1 for ; Sun, 23 Oct 2022 08:04:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2CB5E900003; Sun, 23 Oct 2022 04:04:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 27A01900002; Sun, 23 Oct 2022 04:04:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 141AC900003; Sun, 23 Oct 2022 04:04:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 040AE900002 for ; Sun, 23 Oct 2022 04:04:50 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id C6B9B1207C6 for ; Sun, 23 Oct 2022 08:04:49 +0000 (UTC) X-FDA: 80051477898.13.7C54172 Received: from mail-ed1-f54.google.com (mail-ed1-f54.google.com [209.85.208.54]) by imf27.hostedemail.com (Postfix) with ESMTP id 58BB640007 for ; Sun, 23 Oct 2022 08:04:49 +0000 (UTC) Received: by mail-ed1-f54.google.com with SMTP id m16so20679809edc.4 for ; Sun, 23 Oct 2022 01:04:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=gi7NfuP6YrbO9KnChE3CTeHiwM/FZZFAHtTEuT2w744=; b=h403PvAX0ilKW5FyNEZpH/WjDFoJqbs1GbTxL21CNw3/vrYiGVw+BxoCNo9iPOJau7 OcVvVjGAcDswiQ+ps8tkrnNRYLMdpDCwsgsJZDcsEVVGk5lqR/OzCSi2YkBTa8Oxes37 7vbJIlfPeeJ6MnUqA0gxQId7usHnPcqeb8ZYu8irEMjeXn86vj67639ysA1kySgHRO/v Pe457fOyOrMx8cl311nKP24F5+Yh/QEFaqwrSFbzyx5C6eClTrQqZfCx1WGwfYV+VQlT Lq4MUcrmKds+FXUIPR0MfHowshlK6nsMUqxbXLTIAAJqKsekfc2J3ND4U649WgAxYNQv 7Kxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gi7NfuP6YrbO9KnChE3CTeHiwM/FZZFAHtTEuT2w744=; b=Vle/Wr3we1WSX29OePryl1g3jWLnI52onHxab96Pjiwyv6svDjjehqM/43HE9Bi5qa rEThw6YoLsorf2+PLGEHdVgz3JRFVfeu/Bcq0fPSSpWHISrTJLOkWdsn4sgK9fOUnETP tagQTQi8YIdUDopUCz4kQXyOmlkO29WSLTUobdVjUyxkj3ZSmF9fC89lTCLRtEjgiS1T 2D2Qg40i57Yy2h0W4unISP/FJ3BT6hoBc/K+g/oeo2s+2pIkze9oi8KjwXViyoAHG/lB o8iXiKXTbyNp6zzVQn7lYT9Sw5iKI8A9Q3lmGvJz6eB9hRygG9yOn/jEthXWPk5I9+si Yqnw== X-Gm-Message-State: ACrzQf3UsEGJ/rOE+HivdQe/gK4CxTjrwCOyxyIkviCRqdF/kZPvX9nu poEVL/zyLTQHn4Ue82ngLqE= X-Google-Smtp-Source: AMsMyM5/O3t5idjryVeTnrucCzxIh8sAaUiVx/yVLrXiJX6rtIaA/+S2VsjoG6l2AEP9TISdQLuKXw== X-Received: by 2002:a17:907:7e9e:b0:78d:f3b0:fc78 with SMTP id qb30-20020a1709077e9e00b0078df3b0fc78mr23139231ejc.478.1666512287828; Sun, 23 Oct 2022 01:04:47 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id p22-20020a056402045600b0044e01e2533asm16293049edw.43.2022.10.23.01.04.46 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 23 Oct 2022 01:04:47 -0700 (PDT) From: Wei Yang To: akpm@linux-foundation.org Cc: linux-mm@kvack.org, Wei Yang , Mel Gorman , Daero Lee Subject: [PATCH] mm/vmscan: reduce double-check if kswapd is not able to sleep Date: Sun, 23 Oct 2022 08:04:31 +0000 Message-Id: <20221023080431.30893-1-richard.weiyang@gmail.com> X-Mailer: git-send-email 2.11.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1666512289; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references:dkim-signature; bh=gi7NfuP6YrbO9KnChE3CTeHiwM/FZZFAHtTEuT2w744=; b=n/0psk48efshGQyGarU0AifalAFzDmzgRX2nxA4d6+dUm8ZnMrZZs9iMh99qOp/UJBepay sYUBOGcQN4QcKaAT4JmSnpmP2hhPO+GRNrswgJMlCN2vNsm3WWDcIYE1WTmPURTYtiIRb7 zytxklPowjlu8mPTgTSUDPwbM45QRUE= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=h403PvAX; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf27.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.208.54 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666512289; a=rsa-sha256; cv=none; b=duic/Gt7Gr1uWuWeSt2WAjhv6NODRZK8Sp/44I5UcGKMUG/j3a+rKAsylciyVmBVInEOn4 6WKh36KeE5L4gmgIR19tdX8jq+RvuZt5/Pb+xVODG9qPQ9yYL7+UvsvXXCrSHP9zCJ+QVk ymigJvtiNzmK+FzBdp2bBx15IJC6mDQ= X-Rspam-User: X-Rspamd-Queue-Id: 58BB640007 X-Stat-Signature: bajh75q74of6khbgbwg5a8yj5xdqj1ex Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=h403PvAX; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf27.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.208.54 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com X-Rspamd-Server: rspam07 X-HE-Tag: 1666512289-752485 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: In function kswapd_try_to_sleep, there are two phases for kswapd to sleep: * premature sleep * fully sleep For each phase we need to check whether kswapd is fine to sleep. While if it doesn't pass the check for first phase, it is not necessary to do the check again. Signed-off-by: Wei Yang CC: Mel Gorman CC: Daero Lee --- The original thread is https://lkml.kernel.org/lkml/20220106094650.GX3366@techsingularity.net/T/, but seems no further following up. So I pick it up. Mel, I just see your mail, sorry for the late reply :-( --- mm/vmscan.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 04d8b88e5216..5a50b5908c4c 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -7179,7 +7179,8 @@ static enum zone_type kswapd_highest_zoneidx(pg_data_t *pgdat, static void kswapd_try_to_sleep(pg_data_t *pgdat, int alloc_order, int reclaim_order, unsigned int highest_zoneidx) { - long remaining = 0; + long remaining; + bool can_sleep; DEFINE_WAIT(wait); if (freezing(current) || kthread_should_stop()) @@ -7194,7 +7195,8 @@ static void kswapd_try_to_sleep(pg_data_t *pgdat, int alloc_order, int reclaim_o * eligible zone balanced that it's also unlikely that compaction will * succeed. */ - if (prepare_kswapd_sleep(pgdat, reclaim_order, highest_zoneidx)) { + can_sleep = prepare_kswapd_sleep(pgdat, reclaim_order, highest_zoneidx); + if (can_sleep) { /* * Compaction records what page blocks it recently failed to * isolate pages from and skips them in the future scanning. @@ -7223,6 +7225,10 @@ static void kswapd_try_to_sleep(pg_data_t *pgdat, int alloc_order, int reclaim_o if (READ_ONCE(pgdat->kswapd_order) < reclaim_order) WRITE_ONCE(pgdat->kswapd_order, reclaim_order); + can_sleep = false; + } else { + can_sleep = prepare_kswapd_sleep(pgdat, reclaim_order, + highest_zoneidx); } finish_wait(&pgdat->kswapd_wait, &wait); @@ -7230,11 +7236,11 @@ static void kswapd_try_to_sleep(pg_data_t *pgdat, int alloc_order, int reclaim_o } /* - * After a short sleep, check if it was a premature sleep. If not, then - * go fully to sleep until explicitly woken up. + * If kswapd is fine to sleep, restore vmstat thresholds and kswapd + * goes to sleep. + * If not, account whether the low or high watermark was hit quickly. */ - if (!remaining && - prepare_kswapd_sleep(pgdat, reclaim_order, highest_zoneidx)) { + if (can_sleep) { trace_mm_vmscan_kswapd_sleep(pgdat->node_id); /*