From patchwork Sun Sep 19 15:24:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xie Yongmei X-Patchwork-Id: 12504357 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=-14.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FORGED_HOTMAIL_RCVD2,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham 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 48599C433F5 for ; Sun, 19 Sep 2021 15:24:47 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A8F18610A3 for ; Sun, 19 Sep 2021 15:24:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org A8F18610A3 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=hotmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id E79226B006C; Sun, 19 Sep 2021 11:24:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E28AD6B0073; Sun, 19 Sep 2021 11:24:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CF0136B0074; Sun, 19 Sep 2021 11:24:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0179.hostedemail.com [216.40.44.179]) by kanga.kvack.org (Postfix) with ESMTP id BBC6E6B006C for ; Sun, 19 Sep 2021 11:24:45 -0400 (EDT) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 77E348249980 for ; Sun, 19 Sep 2021 15:24:45 +0000 (UTC) X-FDA: 78604695330.12.AB39BEC Received: from JPN01-OS2-obe.outbound.protection.outlook.com (mail-os2jpn01olkn0151.outbound.protection.outlook.com [104.47.92.151]) by imf29.hostedemail.com (Postfix) with ESMTP id E5B5F9000257 for ; Sun, 19 Sep 2021 15:24:44 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cKq/s4fp9meWsZQEFUPJVbyXFLb7hXPnzZgKa4dDfs4DYC2axQ0hb6sHaQvsr137EvZgDuKXuwdXTou1s58Yj1lTJ+vZnL/AD8F0apijoYc7dyP26zCEn6NhcS+LNrDT4IwWfFSLomZD8JtX4u/fuhExJdLtVPiJgwlj9KMjBcgngz+cQMuzM7uNVGGlge3wNK0hxrH0+KS57qWhS6scv5fVBSxiHPPel+h1h3mc4JneULRKOYOcCWaQqLBc7B7r6Dmznoj2YgGwoJY4kppraLbAuK4ude0V+gppcSp5clQYc7Tr9F+IZ+cQ5q/0505BG0ArgpEX5HFIHd95/U8kEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=wTHl2Ik6OvgqgPmuc0/BK4YyKeBBBoYkFAMHXCZFyqM=; b=jvi+3fkzOTC3nADmsCX+4SX3fIWlvn2+lFcdahX945+p+fIXxkolMcYTBeFRqubCcrPWgB1ChFCvrvEkcAySlG6czNsKq2YPUdwpclezp3XyOQ6RDcylRMMOeydIyAfOkNuNz7S+cU/1zgg3Y3K3H0P+xVWukqfkzyMmqssfVbRhi8xORPjdd7S8bMA5ptD1QRUMvXM+HniCgLhOLSTkICF6H0EAkPEtOiN6SxtAOldU6l9lRJ0Kij4ZGbS+uhsHE2D6p1VMQyG0s/kNanPvCw5yltuJL2XoYbI/U8iEl2tJGbEFoPAQyn+tKGbtrJlQOBY2otHdYLYJ63UBjB0Yyg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hotmail.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=wTHl2Ik6OvgqgPmuc0/BK4YyKeBBBoYkFAMHXCZFyqM=; b=cDCc5hKRD4fjL04HkzsYCcS0jPegjtVweiFXHg1bKN5R2m61A3mNIYOdKyt9syERFhnR92BHCFw+N8mztsdPsIlgj/FCe8Y0lB3tatbaVkdVs+rCVIVFNlCiTB5KOmGKiO+hYI0iwMiFPu2pXqTX/0YSbBohZQpaFU9qvfLbfDkOBr3yc+VkdypFzPlffi1DWOpd0hBIiSiNhrsVocZIEMpEvO2wQyw8/cuNbgOkG+ri1Eex3MzikoI4Sr6wTrp0bAZlnm8zh/vRIjjlsJYl8AQXJErQ2vf/eRK2Ipu2qUl+FdospDbFUiNwobmECg4Cg7kILN2yRfMjyFfHNPhOfA== Received: from TYCP286MB1108.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:b3::8) by TYAP286MB0683.JPNP286.PROD.OUTLOOK.COM (2603:1096:402:3b::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.16; Sun, 19 Sep 2021 15:24:40 +0000 Received: from TYCP286MB1108.JPNP286.PROD.OUTLOOK.COM ([fe80::38ca:ae4a:679a:fed4]) by TYCP286MB1108.JPNP286.PROD.OUTLOOK.COM ([fe80::38ca:ae4a:679a:fed4%9]) with mapi id 15.20.4523.018; Sun, 19 Sep 2021 15:24:40 +0000 From: Yongmei Xie To: akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: yongmeixie@hotmail.com Subject: [PATCH] mm:vmscan remove unnecessary lru lock unlock/lock pair Date: Sun, 19 Sep 2021 23:24:30 +0800 Message-ID: X-Mailer: git-send-email 2.18.2 X-TMN: [d8XQvneyVakXXsZlEXy3ryDixN9TgPzL] X-ClientProxiedBy: HK2PR0302CA0005.apcprd03.prod.outlook.com (2603:1096:202::15) To TYCP286MB1108.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:b3::8) X-Microsoft-Original-Message-ID: <20210919152430.653243-1-yongmeixie@hotmail.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from 192.168.3.12 (111.202.144.35) by HK2PR0302CA0005.apcprd03.prod.outlook.com (2603:1096:202::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4544.6 via Frontend Transport; Sun, 19 Sep 2021 15:24:39 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 7d48a90d-a9e7-4a8a-33f7-08d97b819925 X-MS-Exchange-SLBlob-MailProps: f36zkjAOy3WAm9Vmetkc9UBOgmTaMK76vZuyBuFwDgxQu3c5Epbt6n9JmYaprk9iZGrhS1rIB3zZPNIv0JxaT6ClA/xO6ebCoFRqWlKbK41DMnNN248nJsdnKo0b45qW/w967YdtSM+oKJs1yjfYk+avlbzPCBB9qvK4enXbYVjuKl142e194Bc2/7fyowLVVpE0/E4yEUSahPgQyZVCpwQWnLFNTrHNjfuayAA6cbqEakgAoDbCdTLKu4vWWjo/4suG5LsAQtIomKc4Lm8iTLSF3CC67xclz5v6oenH1lAwCmtJHlzYWanXi5q/m7Vrop3OZJx8EdAP8gBGBLVDTfq50pscjZ3IXTEHV3D4zzmdYhaCEDQo7YWDUMHkkfGBsnTfmW3iSLQgzcvAJqRLihe0W9SsFUR3UDSvMFV69lvVV+NXR7tCY5m8r08kZvYMyKBhwhgL9ICDus3FVFk4Rz06NbQKa4IEZJ8HnAbWOyRQV7i5zb5qgCbUJPPaUBAKCLzzmOgMqMJ3wVdrBi2tTvJvOE4743/xIUzI+keM1yM+P0/k+ltIbmlMVSflXfigeMeV8anJXAzotR9aKHtVWVslKeBV+vJQjrQcJ1wZIe61QB0EGRqfqPu5epccWcEhTe5T9qDuD3mN21LWLeoif2jBPoWpU6IFSTz9oucWZZaXoMMnInHiDPRWdVBIhi7oEeh8smJrFQ7U9DV/ElMfZC52FnhVri4IQKrTvPWjiZ8= X-MS-TrafficTypeDiagnostic: TYAP286MB0683: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: r61+T+PKLv1ikoxMqQLGl2uMfJrck1KJTERAdkCY8pT1OX/UL0WbP0t5dxeP8wzVx1j+Php00bi9lOteZgtiwg3p52BJI3QzPn89M0ikFikqElp3tAqjoIZWV2Mpprn0hgKbTW0wDiQZRFlCb8QWdKB9nixwmjIoRvbLd7FQ7qNu2sHzTc5cQr5DvrhWbiAOW90SgHY1hWNi6/pxNMqN/8VuZgTDH6wzsVY9ECGsTxrCKgvBjebf8NUgQYWmKJJdRO4UxzZiwfZZ1wKdsfXDqf68ei3IdDuleXRXy3dJ4bqiw4ctIMtZKKTR8LeY0KB3pbeZHILLA95a9ziprGYIChU77+45dc27E2jfm8DOYmtW2RfCW6A8l2ve7s1tj1UrAlRtwIW8ZPfk8MlLXX72CvqtJTK4CkrHjRbTfOND39OJmbsLq+R8lCDATM080xYe X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Uu2DIAoWXaumpJy4ArL25fu01cto786LOWbOAa6w5CuH0Hd95JRnyabwl6CWJQHFqmzq+hrR1ZBR9z3OoGDC1EFeYew6JM93TW+aoe3iXepFwUeSZICyUnPI6PRwMYofMGV+lViG6uqixJ4uHkXZqQ== X-OriginatorOrg: sct-15-20-3174-20-msonline-outlook-18f16.templateTenant X-MS-Exchange-CrossTenant-Network-Message-Id: 7d48a90d-a9e7-4a8a-33f7-08d97b819925 X-MS-Exchange-CrossTenant-AuthSource: TYCP286MB1108.JPNP286.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Sep 2021 15:24:40.1608 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYAP286MB0683 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: E5B5F9000257 X-Stat-Signature: 5151oc1of6ckdtcny5cqzkitrddp13gj Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=hotmail.com header.s=selector1 header.b=cDCc5hKR; spf=pass (imf29.hostedemail.com: domain of yongmeixie@hotmail.com designates 104.47.92.151 as permitted sender) smtp.mailfrom=yongmeixie@hotmail.com; dmarc=pass (policy=none) header.from=hotmail.com X-HE-Tag: 1632065084-708731 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: There's code redundant in move_pages_to_lru. When there're multiple of mlocked pages or compound pages, the original implementation tries to unlock and then lock to handle some exceptional case. Signed-off-by: Yongmei Xie --- mm/vmscan.c | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 74296c2d1fed..c19c6c572ba3 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -2156,6 +2156,8 @@ static unsigned int move_pages_to_lru(struct lruvec *lruvec, { int nr_pages, nr_moved = 0; LIST_HEAD(pages_to_free); + LIST_HEAD(pages_to_putback); + LIST_HEAD(compound_pages_to_free); struct page *page; while (!list_empty(list)) { @@ -2163,9 +2165,7 @@ static unsigned int move_pages_to_lru(struct lruvec *lruvec, VM_BUG_ON_PAGE(PageLRU(page), page); list_del(&page->lru); if (unlikely(!page_evictable(page))) { - spin_unlock_irq(&lruvec->lru_lock); - putback_lru_page(page); - spin_lock_irq(&lruvec->lru_lock); + list_move(&page->lru, &pages_to_putback); continue; } @@ -2185,11 +2185,9 @@ static unsigned int move_pages_to_lru(struct lruvec *lruvec, if (unlikely(put_page_testzero(page))) { __clear_page_lru_flags(page); - if (unlikely(PageCompound(page))) { - spin_unlock_irq(&lruvec->lru_lock); - destroy_compound_page(page); - spin_lock_irq(&lruvec->lru_lock); - } else + if (unlikely(PageCompound(page))) + list_move(&page->lru, &compound_pages_to_free); + else list_add(&page->lru, &pages_to_free); continue; @@ -2207,6 +2205,24 @@ static unsigned int move_pages_to_lru(struct lruvec *lruvec, workingset_age_nonresident(lruvec, nr_pages); } + /* + * Putback as a batch to reduce unlock/lock pair for unevictable pages + */ + spin_unlock_irq(&lruvec->lru_lock); + while (!list_empty(&pages_to_putback)) { + page = lru_to_page(&pages_to_putback); + putback_lru_page(page); + } + + /* + * Free compound page as a batch to reduce unnecessary unlock/lock + */ + while (!list_empty(&compound_pages_to_free)) { + page = lru_to_page(&compound_pages_to_free); + destroy_compound_page(page); + } + spin_lock_irq(&lruvec->lru_lock); + /* * To save our caller's stack, now use input list for pages to free. */