From patchwork Sat Aug 26 09:22:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinjiang Tu X-Patchwork-Id: 13366539 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 B3F23C83F01 for ; Sat, 26 Aug 2023 08:28:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0158F2800EF; Sat, 26 Aug 2023 04:28:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F07B02800EE; Sat, 26 Aug 2023 04:28:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DF56F2800EF; Sat, 26 Aug 2023 04:28:14 -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 D211A2800EE for ; Sat, 26 Aug 2023 04:28:14 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 199FAC015D for ; Sat, 26 Aug 2023 08:28:14 +0000 (UTC) X-FDA: 81165578508.22.5B9DC8F Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf24.hostedemail.com (Postfix) with ESMTP id 7AEF5180014 for ; Sat, 26 Aug 2023 08:28:10 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf24.hostedemail.com: domain of tujinjiang@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=tujinjiang@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1693038492; 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=fEsmjFLd2tRL9ydHAgTYr9Tswf5k/ls+Jfu0AzJPGHo=; b=519cMje7iqfF5cP1cltAbSZ3d7/kBGtNkHw88WqVcfz4qFO3/c4DVZc/fh9/NncrKF49kG o2TsgdykBxG4QIjH5+/8mtrGphBdm0v7ND7agQ02yaXdPPDHCwIpetPNDLDax1dyRj0rQQ p87v+/NtP/oYVTO7WXQZ3emEPpyycx8= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf24.hostedemail.com: domain of tujinjiang@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=tujinjiang@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1693038492; a=rsa-sha256; cv=none; b=HqZWYCNpfNOsrlaO7zpOC1+LK5jzKr1vukK2QXMu2YEQrzycqi9N88aZAnO0aFVefcAY8U oDOMqTZUM09LmeSIGUFEZiOWQeNhgqZBuxp4cHRnvPXuSdwYFjpQPkZ2f7ijbNgLoAVfKn tG4pSRgTk6Qjs4KZAnTOAIhQqbrdwrc= Received: from dggpeml500011.china.huawei.com (unknown [172.30.72.57]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4RXqfc5cLqz1L8V9; Sat, 26 Aug 2023 16:26:32 +0800 (CST) Received: from huawei.com (10.175.113.32) by dggpeml500011.china.huawei.com (7.185.36.84) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Sat, 26 Aug 2023 16:28:05 +0800 From: Jinjiang Tu To: , , CC: Subject: [RFC PATCH 1/2] mm/gup: move pinned pages to unevictable list to avoid meaningless scan Date: Sat, 26 Aug 2023 17:22:39 +0800 Message-ID: <20230826092240.713105-2-tujinjiang@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230826092240.713105-1-tujinjiang@huawei.com> References: <20230826092240.713105-1-tujinjiang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.32] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpeml500011.china.huawei.com (7.185.36.84) X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: 7AEF5180014 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: ice99hp55znrypy6hreqwm1kag93s6t5 X-HE-Tag: 1693038490-626511 X-HE-Meta: U2FsdGVkX1/s0RJGy52a0Z4mcTG7YWC0jsA+YqK+t2iknRotpMOR8KsyS0NvvFwf3P+wCZjUJI4V2mhAhZa4IxK4CkPqfqBCKsp3udNa4Y68MV/ClUknH9sNKHHdRsLeRnh+Rl6G/raHbjBDG+rMsTu7wVS4cB2w8ydVtJK7QirwH3QhhN8XyDeoi4BRdVQayn4zu2tyqcxiO/8Z4WKjthe7HIRrqs8NdNWTXk/qmBMLMJ6y10B6XPYjoNNsHIc2lL2c4JCkyBlQFlWHiEittYyUB6DHVg5bk5p2qNtjKNsGXUIDsMNL/9Z526rudwOyQSPVRMqWNofVU26adfP1qLKVI9UM/mQwksFp+xN4AhUQfchyLizsVcNY6zB8IdCLvXuf3YLofy1DGblVUFR8TzWRqKm7JoTgkQ7FqTKgfEVaCT2X+bz/UgZnQrtTifKngIOGrc6LyWqS2rbwj0TCn7ebmRBA9LPr5gbuRdXdvO5ZxtqH7qHkvfxoXKMuArBM9pS8qvALgUw0/kwxKKXwXEegWxKaqgAefVllJCmlVQaOHOrDzR98QsAklwiARCg8yHXbrv2HzK00nW2ucUTM2K0WPN6FEcRhBAQmGax7cG3le72syzMVmMlTjvczrW9kooAqFoSTL82ZJzuoIJaffO1dHeIFHNaYdeaWwnVW0FvGUluXeHqXOQ3EubT1wRFVvkNpvpU9+I965kP9VihVKKbDzRt8U+R4rl0W1seNjY5fi5fvQGfJ/6l8/PQa2bzGzbliEhDhwUrBloindRFqG+MdqzFjoXStjYsEv41gBWcfQ6UzgOGFC9atUTw515BRsVGzIgrvgmAOgNgsxLVzOKpMGdMpv2DwHmTzh2x/zNMabxcwOfHP3BRq7sTP7dsC4UOQsHIavAPEKkQyf3pAnjMFihtlJpnMflnO2dwSsYfbNxtHSOxQQ5fVTg7F44v/PzGmbXtPFZ8JAe+CiYZ D4cdTVIr BlpV8LBwrj+uPWhI8tQhhzZxdLl1tyyYexKtRtZ5CpX9hLZzI4Zx3PFIsDHbhnMsCgMUP6nIACVndl7ReE1eMjWdHYGLBKHEm2fWR0xSCllIM0pUUdm8L1u2dqKgjWDTB0/OK+wHjpmVf4SA= 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: To avoid meaningless scan during memory reclaim, this patch moves pinned pages to unevictable list to avoid meaningless scan during memory reclaim. Update folio_evictable() to check if the folio is pinned. If the folio is pinned, the function returns false. The vmscan code will put the folio to inevictable list when scanning the folio, so each pinned page will be scanned at most once. When the folio is unpinned, check if the folio can be put back to inactive/active list by calling folio_evictable(). Signed-off-by: Jinjiang Tu --- mm/gup.c | 13 +++++++++++++ mm/internal.h | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/mm/gup.c b/mm/gup.c index 6e2f9e9d6537..ca82e1bc6826 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -200,6 +200,19 @@ static void gup_put_folio(struct folio *folio, int refs, unsigned int flags) if (!put_devmap_managed_page_refs(&folio->page, refs)) folio_put_refs(folio, refs); + + if (folio_test_unevictable(folio) && folio_evictable(folio)) { + struct lruvec *lruvec = folio_lruvec_lock_irq(folio); + + lruvec_del_folio(lruvec, folio); + folio_clear_unevictable(folio); + lruvec_add_folio(lruvec, folio); + folio_set_lru(folio); + __count_vm_events(UNEVICTABLE_PGRESCUED, + folio_nr_pages(folio)); + + unlock_page_lruvec_irq(lruvec); + } } /** diff --git a/mm/internal.h b/mm/internal.h index 8ed127c1c808..9ce158de40cf 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -154,7 +154,7 @@ static inline bool folio_evictable(struct folio *folio) /* Prevent address_space of inode and swap cache from being freed */ rcu_read_lock(); ret = !mapping_unevictable(folio_mapping(folio)) && - !folio_test_mlocked(folio); + !folio_test_mlocked(folio) && !folio_maybe_dma_pinned(folio); rcu_read_unlock(); return ret; } From patchwork Sat Aug 26 09:22:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinjiang Tu X-Patchwork-Id: 13366540 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 DF8CDC83F16 for ; Sat, 26 Aug 2023 08:28:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7DDCF2800F0; Sat, 26 Aug 2023 04:28:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 78EE62800EE; Sat, 26 Aug 2023 04:28:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5E0DF2800F0; Sat, 26 Aug 2023 04:28:16 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 523B42800EE for ; Sat, 26 Aug 2023 04:28:16 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 22AB312015E for ; Sat, 26 Aug 2023 08:28:16 +0000 (UTC) X-FDA: 81165578592.11.E10B7D2 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf09.hostedemail.com (Postfix) with ESMTP id A6535140010 for ; Sat, 26 Aug 2023 08:28:13 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=none; spf=pass (imf09.hostedemail.com: domain of tujinjiang@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=tujinjiang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1693038494; 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=QuyBgHit9PHzHFB77zJ1j41runvAieSvfr+traiMSq0=; b=Yx8xA82ScdoAY6OiO0UkHEm7kfUwYnB6N9K7aOT8qu8B7QwMoBfZgD2/7XfyGdqCjz6IKA n+jlmu9fN5vBTK8Wa5CxGUPeH5+7zOqbmKW/bioDRFXqegKv62/sU1SJveJXNg8CG0CLuP lVMr8a8Wkro0bWnbjr6vJzlJywjJ6OE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1693038494; a=rsa-sha256; cv=none; b=ef2yCAhMRS8IukFWCAxVaMiZp6basomHmpQ0ss6NXYJgMdveO9cEJlX4uEaig815CKnAut Ka4OwdKY8Gomn1QDeJjO1lEeXkPxVqCfHllYRTl9ySJJTMp43Iw2/vhO9mpzedbdz1fpH9 1DyDaxRXPfoC9KX/F7C4+m6ZfSGDyKI= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=none; spf=pass (imf09.hostedemail.com: domain of tujinjiang@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=tujinjiang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com Received: from dggpeml500011.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4RXqfc2nm2zfbxf; Sat, 26 Aug 2023 16:26:32 +0800 (CST) Received: from huawei.com (10.175.113.32) by dggpeml500011.china.huawei.com (7.185.36.84) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Sat, 26 Aug 2023 16:28:05 +0800 From: Jinjiang Tu To: , , CC: Subject: [RFC PATCH 2/2] mm/gup: remove folio_maybe_dma_pinned() calls in shrink_page_list() Date: Sat, 26 Aug 2023 17:22:40 +0800 Message-ID: <20230826092240.713105-3-tujinjiang@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230826092240.713105-1-tujinjiang@huawei.com> References: <20230826092240.713105-1-tujinjiang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.32] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpeml500011.china.huawei.com (7.185.36.84) X-CFilter-Loop: Reflected X-Stat-Signature: bs3jtc8xjkp33kxoztbe1dateznmhzf5 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: A6535140010 X-Rspam-User: X-HE-Tag: 1693038493-946187 X-HE-Meta: U2FsdGVkX18ma96QHKkGnQAWAU5zYs17qnnHkyl+uH1EYz/ofQVfTZQTdViemmNc+nz2bfXiOuarjIVCOKhnNn3vFTQl1I8/m5y158weqW/cJS4YmWg0LvZdiUaam+5TLdM1L1n1fqX+Ylh5taUaux/nhSR9hD45YiAJcGu7PpFzsUP6hlyFCTNC/4kXVDOYUZM/PE77kirTcnsnLwgcrt5n5xnhcIX7LxUPTks8phNPX8LxFL0+xYamn6LgFuZ+bGFY4GYYLHTB8SYqE8fIp93wKV92J69zTyoXTiqAOnWi504ZgrsHv9zDxHMFLyTIkvH8WjmsP/TP46TusqwvAx/aAJO+cnqV5Ny9+REkWM1jTCxZKeOmIltme3+aAFSpqdrAgx6hKQNB1bxtuBmI/9UmaeFkUrHSH75npbHQXU4FP8fSuuCdrwZ85wMrpFu5rR6uJ5Lus8JYtP1ta3WrwgxWe8+LDabFO9+cEve8crieQhNi+eojflhoZIDbSz1ANukIhW5GN+mkxZasw+/lISE3Mz4rXUktoEjcPvcxXIFvfUuBQTmC+mRCRx0rsaoUsrfCiG2mBp7eHpCLRC2GRDxNXveazWV+TRcofC0rbTmA+5gtyvCRVUYuClvq8JqQ7gghzpHnTWZbDJ2bp7knQOS79+w3yzPHaHfTKf9JzYyxtt9v1GM4B7M36PntgKaS8x2bMEDSot/2DiyXG9GthPa63LBiwx12r9db4DDzyIgsg85Wnz64y0mUKTu8M9KD17wuRfiuTQ292n3nxkgOMaUmraN8ErGjKytCM9Tu/lMd3QTwR2KrNzMS3qSVh/4M4ZmXM3s0N8R4vk/icVSSa98b3GHnO4jNtp0At5nYg5yxgMLYHhisYIGCQ3Uc0dp20gVpdom/XWJ5u45Ycop6LWrX01QkMC+Aq9uU2xYq1KdCUiX5833NgQ2skg5NGmc/L4iuuK2BSkmyY0iEBR1 ZJ6BsIGq wxO5wa77LRPaMRBGqjubZRSY2/bphhukROLrOcOwkdPG62MvYU14Dqfo1lCiZHn4y+M1GvY/fwgQJSo/e3ZskcDxHt2y6F46w3jNPLhCTOI7fwpnV9SHmZDJzSCwZ0ILqnW+D8/RRTwc4+EAd5awxRJ08OlXNG3hjBfC7hHbO0EjArpl+vYLenAOSphTdwZjEtWWo 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: Since the pinned pages have been put into inevictable list, folio_maybe_dma_pinned() calls in shrink_page_list() could be removed. Signed-off-by: Jinjiang Tu --- mm/vmscan.c | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 2fe4a11d63f4..590833c1fdbe 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -1891,8 +1891,6 @@ static unsigned int shrink_folio_list(struct list_head *folio_list, if (!folio_test_swapcache(folio)) { if (!(sc->gfp_mask & __GFP_IO)) goto keep_locked; - if (folio_maybe_dma_pinned(folio)) - goto keep_locked; if (folio_test_large(folio)) { /* cannot split folio, skip it */ if (!can_split_folio(folio, NULL)) @@ -1959,16 +1957,6 @@ static unsigned int shrink_folio_list(struct list_head *folio_list, } } - /* - * Folio is unmapped now so it cannot be newly pinned anymore. - * No point in trying to reclaim folio if it is pinned. - * Furthermore we don't want to reclaim underlying fs metadata - * if the folio is pinned and thus potentially modified by the - * pinning process as that may upset the filesystem. - */ - if (folio_maybe_dma_pinned(folio)) - goto activate_locked; - mapping = folio_mapping(folio); if (folio_test_dirty(folio)) { /*