From patchwork Wed Dec 7 23:01:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vishal Moola X-Patchwork-Id: 13067736 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 A5C4FC63705 for ; Wed, 7 Dec 2022 23:02:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 330BC8E0005; Wed, 7 Dec 2022 18:02:01 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 26CC78E0001; Wed, 7 Dec 2022 18:02:01 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 06EA18E0005; Wed, 7 Dec 2022 18:02:00 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id E79E88E0001 for ; Wed, 7 Dec 2022 18:02:00 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 9A7BCAB49E for ; Wed, 7 Dec 2022 23:02:00 +0000 (UTC) X-FDA: 80217034800.06.A42908E Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) by imf17.hostedemail.com (Postfix) with ESMTP id 1F6EC4001A for ; Wed, 7 Dec 2022 23:01:57 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b="HiV/oY75"; spf=pass (imf17.hostedemail.com: domain of vishal.moola@gmail.com designates 209.85.216.44 as permitted sender) smtp.mailfrom=vishal.moola@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1670454118; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=mYZlpNMA+Acznxg5e3x9zZ+EdiKxFlZgSChFwOm2lRk=; b=Fyx1RsTseqLj2hYg2/K6SEuD2FF8XLTaC3YdapAjUPnvkkrD76bnlE3bUOUffkEXO5zagU XSNJrkLr7eEOdDZBYlya8bx8kkkraC4mx+kTaiYl82OiISs16qgguo7rCELDhNAMqFl3AP oLrJGdJifBGBfRI6a8JBnknmU+rk3h0= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b="HiV/oY75"; spf=pass (imf17.hostedemail.com: domain of vishal.moola@gmail.com designates 209.85.216.44 as permitted sender) smtp.mailfrom=vishal.moola@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1670454118; a=rsa-sha256; cv=none; b=LMfTOKhx6mhUpFIod7pPW1DsD9rmTQK5TyfiPc+t3j69oGvAkEQogePLDL6m2HUn6Kp/QN Ser9g3tsNBpZvbPmlQucE2i1DTyxS9UNQECJ/IfPCw7+QOoiC3PerPBj0vPSdXagOHlbqS 1JdoVI0WWhs6W330/mQmZB6hSYZC8Zs= Received: by mail-pj1-f44.google.com with SMTP id u15-20020a17090a3fcf00b002191825cf02so3188323pjm.2 for ; Wed, 07 Dec 2022 15:01:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=mYZlpNMA+Acznxg5e3x9zZ+EdiKxFlZgSChFwOm2lRk=; b=HiV/oY75y2SgvXSPgyC4fy1/yI+dEmaKpwJP9rcT9dvAgK7E9TPad3a0idSitkerjT Rrx0RTHSsmtv3oYd5pfyIkV0y4GmO+Ls1xkjiaFCRuEDjWgdtfBwXFaxlF5rV4ac7dhC CTZ+IdatW3dUUDP49usWcGXfNyH1/cFNk/xhDASziYsASDFEEJQN1T4Qz8o2+HDwFMZQ n4bL6G0h7Mv4SDokh1Hd/WE4OycJFvigMqFcBjH3A6gGRp/2gfMSNyIay1/n3CcbXFu0 JYMWAnXquC8dwcR+vBFJiWJXrY4ZOi92H5zeUQj/dJopHjbdAk622Ttf2+x+Y1B265qB 6RrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mYZlpNMA+Acznxg5e3x9zZ+EdiKxFlZgSChFwOm2lRk=; b=6q8lro7gvOPo1GiTzMWhDA3l+JZh4t0AOgEA5nWZISeAlkDqEAf2gzGfiJQV0fI6r5 XeENPcQJ2aHVEmQpSKyHAYY5yB0yotOCkhnUDlvHAnOWy6VchOeaaRS7OSMxv1cLe3qt eCMxfbTZ75BYjP/NGKVOdBEePosmsKcFvyAwZisZMN/oED9gnQ43CFI2/jAQZ4ih4QBb UQ7s9yQX98kkRNNDMXKPZoRpRuX8hHys65/7dpPE+XfkMvmL9t/iPICbd95AgoFHZFcf bKSEUhwW7dGCkIziTpZmyIv9kN7q13BqA5RIhFY8i/W0sdSxjqP4Z1DydSAutST2rCpL JYcg== X-Gm-Message-State: ANoB5pmDU21W6SFcuMi6qsZTdVHCzap7M35Id5NN9Y3aiHz7Ln3VERWB 0IhHY5gj0P2jmA4zNQhRebOV+ERRTfrDOQ== X-Google-Smtp-Source: AA0mqf4uIlwwTywDq7pnmSssjoqZm8uc2lM/w6x1j1eyco1kE6LT4+WStL0ZREb8lSZ3UNkCCMIzPA== X-Received: by 2002:a17:90b:1913:b0:219:396c:9e30 with SMTP id mp19-20020a17090b191300b00219396c9e30mr1056216pjb.20.1670454117492; Wed, 07 Dec 2022 15:01:57 -0800 (PST) Received: from fedora.hsd1.ca.comcast.net ([2601:644:8002:1c20::2c6b]) by smtp.googlemail.com with ESMTPSA id pc16-20020a17090b3b9000b00212cf2fe8c3sm5411033pjb.1.2022.12.07.15.01.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Dec 2022 15:01:57 -0800 (PST) From: "Vishal Moola (Oracle)" To: linux-mm@kvack.org Cc: damon@lists.linux.dev, linux-kernel@vger.kernel.org, akpm@linux-foundation.org, sj@kernel.org, "Vishal Moola (Oracle)" Subject: [PATCH v2 1/3] madvise: Convert madvise_cold_or_pageout_pte_range() to use folios Date: Wed, 7 Dec 2022 15:01:50 -0800 Message-Id: <20221207230152.22938-2-vishal.moola@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221207230152.22938-1-vishal.moola@gmail.com> References: <20221207230152.22938-1-vishal.moola@gmail.com> MIME-Version: 1.0 X-Stat-Signature: c4w3tsposrk96k1pabbq49y8w54zjmrc X-Rspam-User: X-Rspamd-Queue-Id: 1F6EC4001A X-Rspamd-Server: rspam06 X-HE-Tag: 1670454117-413357 X-HE-Meta: U2FsdGVkX1+YsYh0LXn8KIPej2yZVcrdPLvUyepKTnEkLxuGd2Z3RKA9QjTcL6s3235K15UY22BNcLAQkHF/lgLpcMvFN49HRTCZQa9hX+cyo8smnFSKPzu4ygv1P9jaUK1apvN8LflSfYD6RgHtxIyUjGCf6SMsBeCPmCNK8EBMAx89tRkik8pX1UaYocxo6oB7xyvcXmtJ77GA6pLdhwN0t3fl/r66On6/+ssJgQAU6YMYP26UnDjxZDIi031PoGD7CvAuMZ2fuh39Iqd3BsVkhnJ0R9lMpVpvdsNF/Vx8D5yB6snN6zCOgkcp4iq9pCLcddMKdQsETkRwhGsEGYVY7D0YE8I6FoXeajHbO2Ir7YuoUX4sYaTnOokt7W7xa0Znhi9GaDpW/JF9arjmecS6uDk3EY2cSGoAFAjlr7YBKp23VDMtCsavBKrUK8BZiqgeNndvLtxrNAJNK8nlRQFWcjuvvvlqvWs80uz6JCVL1vCGphLks48ekl/yvSNw8tNACoJ5OGuNjwyH9kICcWbpfrMrz19IqX6HZstazGNCMvFQvm2UdzqanwPfegYFWZCeuGxMh3DkoROTYay0oaALnb4PbDC6eEV749jmf3TPkSvK59BPj3+aIGagG6jztAVE/Nv4IAPPUXiOKnxsJHTEM/YxcJw7B0CCSEX74J4P/HdskyecdnPej/+Cd8U1k0GqVU+9+HAQuila6m8ekL792uj8cCttKsnyzOJd+0aKqiu4R0jHePdiO07j7uvYc72hRy8KMGh04GMt4xQzh0iTO0qFgGMcuq5bCkvwYbLtwhFXQ4VF2UkVdXeXWQFQoL9tFgu/UcRR2INzPOzlpj5OE6MWzMxzd6LvzPPNRDn5S6ZSskg8OvESmBSttKPHvtM9YfzFujX15bZgsb8NCC3H7gY9yIMf8mU4bP/S/IvYsEcGXPwyOadjEPT56JAjGlDKtboUC717lkdhSOB pcQn8ZCK gltDflzIjpKFByTk7TI8pMF1SsGA1hxcpOqXa5WgM25C5Siw8SfM5+3NNjQk43qexvDAozlMvHxyL5hSJOStaZbSDKHlHzo7jMOcnFU3la1UiYnqnE3T5Rs14reYznPX0IGJBtugemyLnFOmpnifvUiT5EOrlx8JAF8NSrZAXUfK39p3u081jbL6K7xE8cVkUQ0acqccHd3MtSzaeKXGwDefQ1rFZpq1Vy608eLbosdj8SzQWPUiucIa2+8cYenGJc5hAGSaYtN1Z5cifYqCggUjQqg== 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: This change removes a number of calls to compound_head(), and saves 1319 bytes of kernel text. Signed-off-by: Vishal Moola (Oracle) --- mm/madvise.c | 88 +++++++++++++++++++++++++++------------------------- 1 file changed, 45 insertions(+), 43 deletions(-) diff --git a/mm/madvise.c b/mm/madvise.c index 2baa93ca2310..b323672c969d 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -332,8 +332,9 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd, struct vm_area_struct *vma = walk->vma; pte_t *orig_pte, *pte, ptent; spinlock_t *ptl; + struct folio *folio = NULL; struct page *page = NULL; - LIST_HEAD(page_list); + LIST_HEAD(folio_list); if (fatal_signal_pending(current)) return -EINTR; @@ -358,23 +359,23 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd, goto huge_unlock; } - page = pmd_page(orig_pmd); + folio = pfn_folio(pmd_pfn(orig_pmd)); - /* Do not interfere with other mappings of this page */ - if (page_mapcount(page) != 1) + /* Do not interfere with other mappings of this folio */ + if (folio_mapcount(folio) != 1) goto huge_unlock; if (next - addr != HPAGE_PMD_SIZE) { int err; - get_page(page); + folio_get(folio); spin_unlock(ptl); - lock_page(page); - err = split_huge_page(page); - unlock_page(page); - put_page(page); + folio_lock(folio); + err = split_folio(folio); + folio_unlock(folio); + folio_put(folio); if (!err) - goto regular_page; + goto regular_folio; return 0; } @@ -386,25 +387,25 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd, tlb_remove_pmd_tlb_entry(tlb, pmd, addr); } - ClearPageReferenced(page); - test_and_clear_page_young(page); + folio_clear_referenced(folio); + folio_test_clear_young(folio); if (pageout) { - if (!isolate_lru_page(page)) { - if (PageUnevictable(page)) - putback_lru_page(page); + if (!folio_isolate_lru(folio)) { + if (folio_test_unevictable(folio)) + folio_putback_lru(folio); else - list_add(&page->lru, &page_list); + list_add(&folio->lru, &folio_list); } } else - deactivate_page(page); + deactivate_page(&folio->page); huge_unlock: spin_unlock(ptl); if (pageout) - reclaim_pages(&page_list); + reclaim_pages(&folio_list); return 0; } -regular_page: +regular_folio: if (pmd_trans_unstable(pmd)) return 0; #endif @@ -424,28 +425,29 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd, page = vm_normal_page(vma, addr, ptent); if (!page || is_zone_device_page(page)) continue; + folio = page_folio(page); /* * Creating a THP page is expensive so split it only if we * are sure it's worth. Split it if we are only owner. */ - if (PageTransCompound(page)) { - if (page_mapcount(page) != 1) + if (folio_test_large(folio)) { + if (folio_mapcount(folio) != 1) break; - get_page(page); - if (!trylock_page(page)) { - put_page(page); + folio_get(folio); + if (!folio_trylock(folio)) { + folio_put(folio); break; } pte_unmap_unlock(orig_pte, ptl); - if (split_huge_page(page)) { - unlock_page(page); - put_page(page); + if (split_folio(folio)) { + folio_unlock(folio); + folio_put(folio); orig_pte = pte_offset_map_lock(mm, pmd, addr, &ptl); break; } - unlock_page(page); - put_page(page); + folio_unlock(folio); + folio_put(folio); orig_pte = pte = pte_offset_map_lock(mm, pmd, addr, &ptl); pte--; addr -= PAGE_SIZE; @@ -453,13 +455,13 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd, } /* - * Do not interfere with other mappings of this page and - * non-LRU page. + * Do not interfere with other mappings of this folio and + * non-LRU folio. */ - if (!PageLRU(page) || page_mapcount(page) != 1) + if (!folio_test_lru(folio)) continue; - VM_BUG_ON_PAGE(PageTransCompound(page), page); + VM_BUG_ON_FOLIO(folio_test_large(folio), folio); if (pte_young(ptent)) { ptent = ptep_get_and_clear_full(mm, addr, pte, @@ -470,28 +472,28 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd, } /* - * We are deactivating a page for accelerating reclaiming. - * VM couldn't reclaim the page unless we clear PG_young. + * We are deactivating a folio for accelerating reclaiming. + * VM couldn't reclaim the folio unless we clear PG_young. * As a side effect, it makes confuse idle-page tracking * because they will miss recent referenced history. */ - ClearPageReferenced(page); - test_and_clear_page_young(page); + folio_clear_referenced(folio); + folio_test_clear_young(folio); if (pageout) { - if (!isolate_lru_page(page)) { - if (PageUnevictable(page)) - putback_lru_page(page); + if (!folio_isolate_lru(folio)) { + if (folio_test_unevictable(folio)) + folio_putback_lru(folio); else - list_add(&page->lru, &page_list); + list_add(&folio->lru, &folio_list); } } else - deactivate_page(page); + deactivate_page(&folio->page); } arch_leave_lazy_mmu_mode(); pte_unmap_unlock(orig_pte, ptl); if (pageout) - reclaim_pages(&page_list); + reclaim_pages(&folio_list); cond_resched(); return 0;