From patchwork Mon Aug 14 06:34:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Zhang X-Patchwork-Id: 13352428 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 3931FC001B0 for ; Mon, 14 Aug 2023 06:34:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 883C58D0002; Mon, 14 Aug 2023 02:34:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 834B68D0001; 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 724E68D0002; Mon, 14 Aug 2023 02:34:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 5FFC68D0001 for ; Mon, 14 Aug 2023 02:34:44 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 3D1E740AB1 for ; Mon, 14 Aug 2023 06:34:44 +0000 (UTC) X-FDA: 81121746888.12.BDC78E3 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf29.hostedemail.com (Postfix) with ESMTP id B09F512000E for ; Mon, 14 Aug 2023 06:34:41 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf29.hostedemail.com: domain of zhangpeng362@huawei.com designates 45.249.212.255 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=pmFcbTknQ3HLiO/EH7lo0/s0iOkl8xDKF/Y/+3CYvrY=; b=fAIKgZ6A1LbyxhlKT4r8cVoz+uU83tQq4WPc9+1DF/SGkdTtEI1sRP670oT9FIAmYWQp+1 +OzUZuIjUG1HZKCt4fwtqpO0HzPEtTiQiJ/W1ydNb5KAP97ZTFynbfB25smhOEX1UNMIpY oV+9HgdfxGjot/AmZoP/pDm5btPVUPE= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf29.hostedemail.com: domain of zhangpeng362@huawei.com designates 45.249.212.255 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=NYq8CstSRM/4VD8aGkH6VC6JhB0ZJicXBiTAE0D27AF8pXqmH0QQ5s1EzADy61C+R+l2z+ qpv/e106MDB01lE6tgzx/wKdlGsQwQkwMXZJsND4DAB9vXBa7E8rl9I8PpuWX7VlhQZHry UFgP7GIwjqQ+I2LjhAM4rnRe8jWaWAI= Received: from kwepemm600020.china.huawei.com (unknown [172.30.72.56]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4RPPjV5ddvz1GDG0; Mon, 14 Aug 2023 14:33:18 +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:35 +0800 From: Peng Zhang To: CC: , , , , , ZhangPeng Subject: [PATCH 1/2] mm: oom: remove unnecessary goto in oom_evaluate_task() Date: Mon, 14 Aug 2023 14:34:27 +0800 Message-ID: <20230814063428.4111206-2-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-Rspamd-Queue-Id: B09F512000E X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: dqwcbmitpkrcuxa1jikcwz8esi1oxabh X-HE-Tag: 1691994881-794902 X-HE-Meta: U2FsdGVkX1+R/U/nmMMAiO3VI0np3Rhw8qfC2fCR+4xruR5sDRNbEuAvx706WIG1IQmhVWvnKLHGh1r85w/ZCAWvoodb9DgDo1cko2nDnCvqsX8moFEebJ8e//qXL7D3h7jIpdlGKzM4B9zJu0wFLsjSabQpChp8WdM0OIPAgulewtN2tUYmNG8GFmfOue8IDvirJiMQZQQ7YHEPlQ27tdWF+SLShAyb00JLWQvnXChQudo7OYgri4PzTua5J7ChpPYkVrPW5S/wriZvQGA7mUTW+t6+6Lcz/CMqIsTziWUHdt9Dd7+3FfszVhtEc7LewPkIIO1HQVALWyZfmMeYkH+nRXc0b7uRXzK0qTlqP+5QlLZys5uYjmrpWfNJnvaxU38Ql2HMXsJE8l8y+iBLeq68O6ZY/m5onYunHMx+J8CDS5lecIhsusqPxarvtC//cVB+PfV94XyWzDUjF5xPlZ1S6xrX42Ot7IdtwhL8AkrhgBCQPsznsN0dAOjPHWSTXXSHFXuw6g4mxP4iuBHzBO2RUrM6G2l5v/lHblG8uXalnjSIOPYv7F6HqqNNPOQHIYkt2c151pCHukPUXv5T4FkSvq3NL8mMTlThnhVMWYdsm2CW4CTtuQW9BGU1eYDLHaIM+MaxDiMFpKN5wc05oFYSplR+gff1Tk/k29bNA1RpQfB6WAw4Krfw3U2QqZq+6qpFnSDxMcuAnsy9XzwaEYxVYoAWnhJN/vRTKbdlkIQtWvnw0EQYqGYiHB7Wn/GyGCbmO0SSV3Im0AT3X7aLXV4iB06m5uKGQL8T7VYRKY/PNKYEmdgggNj5BQzBQLFO3Il8uyHeqw82gwaCZDKMj3GTfoRT+0nYrbGJ6+G2HiMbQ0Jfy3iJlTEmC+e2t7C7YjoJ31zWhAYQEl/tn6qJ3iTa7f868PgdnIKd6UmILFIanV5ZGBlYgdKM4OxwZFGQ9ShbnBh43e/WF+Hpwc9 uhxefnzd YnPuNzg25wZ5HeehLRn9SJskrKOR2amgaXy2upViv4WHk6250kvgdtaAarigUJb8QMpP+XJ9t66EdMlk+qdB3CMmUUCggsZfnq8sMk44EDcaKyqC/jcUj2ioU04x8zcob1q6EnDoJBz63KPF7oeRyrSsw4qi8tME0xOCuoCBKxgdC841uF2Gru6En+ia9mvgtDogo 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 Remove redundant goto statement in oom_evaluate_task() to simplify the code a bit. No functional modification involved. Signed-off-by: ZhangPeng --- mm/oom_kill.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/mm/oom_kill.c b/mm/oom_kill.c index 44bde56ecd02..10f7826c4035 100644 --- a/mm/oom_kill.c +++ b/mm/oom_kill.c @@ -335,14 +335,12 @@ static int oom_evaluate_task(struct task_struct *task, void *arg) */ if (oom_task_origin(task)) { points = LONG_MAX; - goto select; + } else { + points = oom_badness(task, oc->totalpages); + if (points == LONG_MIN || points < oc->chosen_points) + goto next; } - points = oom_badness(task, oc->totalpages); - if (points == LONG_MIN || points < oc->chosen_points) - goto next; - -select: if (oc->chosen) put_task_struct(oc->chosen); get_task_struct(task); 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: