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; }