From patchwork Mon Aug 14 06:34:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Zhang X-Patchwork-Id: 13352429 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 88415C04A94 for ; Mon, 14 Aug 2023 06:34:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C7BE38D0001; Mon, 14 Aug 2023 02:34:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C2BAC8E0001; Mon, 14 Aug 2023 02:34:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B41128D0001; Mon, 14 Aug 2023 02:34:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 9A3888D0003 for ; Mon, 14 Aug 2023 02:34:44 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 3FE5BA058C for ; Mon, 14 Aug 2023 06:34:44 +0000 (UTC) X-FDA: 81121746888.12.0B41270 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf14.hostedemail.com (Postfix) with ESMTP id BFD05100002 for ; Mon, 14 Aug 2023 06:34:41 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf14.hostedemail.com: domain of zhangpeng362@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=zhangpeng362@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1691994882; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FoHoajp7+eOaJ3gYgN0J7R+rWMFqVIAG2CrqNrcPCAw=; b=8GwxMXeNp3+FVGZLa95MUVZU61qLkjNZV6n/wdKy7oDfCFLoIPqTSHUpEqDY24mr0i+wSE f22+h6pi+b/vJCY39Vd7xsbAjbUkQd8m9/ojBsOC5IeRxIAC+EM9f5rP4hzyAE14stqkaX tIY4NvDsVfy0zRRBRqAxS+DOIVPYrsE= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf14.hostedemail.com: domain of zhangpeng362@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=zhangpeng362@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1691994882; a=rsa-sha256; cv=none; b=M5zcUkqjvGEPg2wJJ5CSGFmbATsF9X7gOGONM81aeNNbUqBLYx5yTiTGyHQg1eSXO5PfiP cgX5nPIss530cC4Od85ex30+4sfDZxjOzb4YjJ6G85GexatSdeFzkIAa+b3672ZIEgOitS zL6BnMBFdxTU/LTSl6DO9KV/uYbTzok= Received: from kwepemm600020.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4RPPfy0mPTzNmxm; Mon, 14 Aug 2023 14:31:06 +0800 (CST) Received: from localhost.localdomain (10.175.112.125) by kwepemm600020.china.huawei.com (7.193.23.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Mon, 14 Aug 2023 14:34:36 +0800 From: Peng Zhang To: CC: , , , , , ZhangPeng Subject: [PATCH 2/2] mm: oom: terminate the oom_evaluate_task() loop early Date: Mon, 14 Aug 2023 14:34:28 +0800 Message-ID: <20230814063428.4111206-3-zhangpeng362@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230814063428.4111206-1-zhangpeng362@huawei.com> References: <20230814063428.4111206-1-zhangpeng362@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To kwepemm600020.china.huawei.com (7.193.23.147) X-CFilter-Loop: Reflected X-Rspam-User: X-Stat-Signature: o66aztg96ficaq75eggskpertmjx76u5 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: BFD05100002 X-HE-Tag: 1691994881-910551 X-HE-Meta: U2FsdGVkX1/3SuSn0soIj1nak3fe5QRp0yQY4DJfD6rk8IpUMNksApuoS6kxr/wH0RfUFOdrbjmWWu05Kz9MEhpbQnDt0V+XXZXah95XG5pidQK22/YnUzOk4dcbDY9X7+08jyWQ8E3Dg8rSafWLKBsSxgdvqVWcpS0lD8KTDxBBDP5AGm1XIz5hPOHNTQuMME4ikYQGUdaHOH1Q9xaw0utG8ktlrirPuBT9yH0imn7GmQI3wh3/WLnYDZLuTX5NYzeW0OrsEmX4C/hN3i0Goy+NbiFqE6ErjcrUY2arhYVhuubTt7neVhcwf3IF87l+96xmSuW5JiawA0lW5bveuKNCHXCnBzyLc1xofaSwYuLmgmccQvkOCXT0sIHnLWiuYTbTsQfohyCla62fFbxKIV9Uv54zRsPneifwJlsuLikWMA2U7fIwe1T4CxF3ql2XwABU0VTGDdbCkAYPqr4pJRiDFLUc18ykdBL0VdAlV8znQ8t7m/PZztcn6jZmBj6AYem0IrCKr2nvlqENoqXmUFPT2YfiPyva82vK+Nm+wIhwQ51Q2bl/8ylgkCpTTR5DlngNR5toDFcxAD0NvYzU1eTrRmO1bf7mW7Vxiz/wqrmCMGlHnLVpaDPtWGOccxW6QiAARTv8yyxpaBwjx0630CgM5TX43XDcE9ys/Ih/Ws5ls/+u0ygUSE0ZSJklniiLx/q6oP6Q767RMekwritIp3jM2lnaBS2kEVx0Iiiqaouwu+7+nKKjCsbRL5ii2pkysAWjiHEAST/48+ZlEWwe4OIIpbDkhbkCbyIk2pONr1tuAl/GL5PTAuaQN5dDLUx6pR3T1sKKOZdmwqrueYNYIw7bSeJOZiVOyNdvb47xJfwBnj6D5C3BxXzqO7aUZZNkCYmb8/qwGJi9Xe97VS75nH/yZqshNXVFLjjVGpWBgjjugWbb9q8Bwhx+cKBLHW8GKfc5xy0miBolQ2IGBJX wkaGsyUn eCtQWcby9p373jsMzpJLP0wyDFtWCs1lH3QNr/TvogyO2tGYnBCICmoilDBcZr1epILe1kIPBlNGLQWD5PfkX1YNrkWjAhG3w8hiNFZPOYocSdOqendkj9IR9PJPtiChZrL8OXOdYDtju6ngQoRBujpUbJi8N0tVMHYPiLlp0UldBYR3RpTD9JTbLxWe7PCTTUmdW 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: From: ZhangPeng If task is allocating a lot of memory and has been marked to be killed first, then it gets the highest score (LONG_MAX). Therefore, there is no need to continue to calculate the points of other tasks. Just terminate the oom_evaluate_task() loop early, when the task with the highest score is found. By doing this, we can get some performance gains in select_bad_process(). To implement it, the return value of oom_evaluate_task() is modified. When the task with the highest score is found (points == LONG_MAX), oom_evaluate_task() will return 1 and the loop will terminate early. Signed-off-by: ZhangPeng --- mm/oom_kill.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mm/oom_kill.c b/mm/oom_kill.c index 10f7826c4035..02d11ae043aa 100644 --- a/mm/oom_kill.c +++ b/mm/oom_kill.c @@ -346,6 +346,8 @@ static int oom_evaluate_task(struct task_struct *task, void *arg) get_task_struct(task); oc->chosen = task; oc->chosen_points = points; + if (points == LONG_MAX) + return 1; next: return 0; abort: