From patchwork Thu Dec 8 20:35:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vishal Moola X-Patchwork-Id: 13068866 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 C49ADC001B2 for ; Thu, 8 Dec 2022 20:35:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 50EED8E0007; Thu, 8 Dec 2022 15:35:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 448A78E0001; Thu, 8 Dec 2022 15:35:12 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2C39C8E0007; Thu, 8 Dec 2022 15:35:12 -0500 (EST) 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 1E6F78E0001 for ; Thu, 8 Dec 2022 15:35:12 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id E54E5120F97 for ; Thu, 8 Dec 2022 20:35:11 +0000 (UTC) X-FDA: 80220293622.12.1C1963B Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) by imf18.hostedemail.com (Postfix) with ESMTP id 3A74C1C0016 for ; Thu, 8 Dec 2022 20:35:10 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=NEepa2sC; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf18.hostedemail.com: domain of vishal.moola@gmail.com designates 209.85.214.178 as permitted sender) smtp.mailfrom=vishal.moola@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1670531710; 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=wHUznzZJR/+2eFOYGxPgX5SObHA9uL1BQ/OTB3xHgrA=; b=ZhJiXYkk/bYm93ry0kPu8GMNPN+p+MIkkwbdw5/0LDVt7OrDWCWsNkly/Sr9xmQ20C3Kuh BsCdgm9zjUqqeFknzBQN0cU+ILg8RURdIE/iiEXCDqHeijKMDhIZV0Nw1+lh70SNA0lXdz jOSuMoWEaOcUS6/WnK0TSbpX9iGXOpo= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=NEepa2sC; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf18.hostedemail.com: domain of vishal.moola@gmail.com designates 209.85.214.178 as permitted sender) smtp.mailfrom=vishal.moola@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1670531710; a=rsa-sha256; cv=none; b=hyrZYImuhvKR0zzljlihz5wvrtvl1mHKCktCNBkw4RL5WRTkAIrOI/qJSFXPJDxwePwPLe YhGNPG9O5+642342IzfJ1DmWe4CgH7WOL4qGBV9r5usmVXtsQ1N7cq3+94IEBEuO2o+sOr c170f+Ujn4U7v3JmYhQ7/7sJDqziM/g= Received: by mail-pl1-f178.google.com with SMTP id s7so2680595plk.5 for ; Thu, 08 Dec 2022 12:35:09 -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=wHUznzZJR/+2eFOYGxPgX5SObHA9uL1BQ/OTB3xHgrA=; b=NEepa2sCfJJvgnX3ejRFOGPrjMYmgXnKRjN5unAOsJ/tE/BFewdxSNeEpPh1ad1sGm sIvarvzBcw9Q3fQ8zNawaQb5T7z+NwATAYhUr1/Zzfia5k8LSv8jP7nLAWj12z2ly+ZT f1GUI5W5sCMhxUsXXmc3IaXRX1EDRvErMLIqll3a5CVIKNBy+z+Ps/lbk08QQ9KaT7Xk XnMYibTX66/3+am1vVR/kGAVRT7Ww4h9duW2iIIY993dThq5e7aPSkAMZ/4u08o/kpj9 hMuvayRPzWZ61DFZfjIkSk7CofF4B5i1NolYOU2OWLJeiOsFr0kMvqfSPwlc83/zYe2K Aagw== 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=wHUznzZJR/+2eFOYGxPgX5SObHA9uL1BQ/OTB3xHgrA=; b=QpPuF2jsLXwVQyh3ecQHSxXqfS63x6hv00j8ELsFNOrCaSdgJGB5W08k6pFBKHHyR5 u1qdt5WT5vYsEL4QG0pibtVusOnRa+2Xk5v6R/ieYYJSa6iSqdxLV/YrGqDxS3pjHNAQ qT72mFU7zWrQOWb98LDixdt4yfFUcrnnbkTgohvTXop8m59ZeBuTceuSzq7nH4v3fnU3 BK9muRJ9jUM7IG+YSZoKHGHO4teJGQADIlVsgy1DmDUqb5nRFNSkWsVA8m1fNy/B9vUh smaR4LD6frTDuHdKEmDJRxKSTk0Y+XQlh1POe07SK89X/GMNGrok51/2j4whwAzE1sAY Gv7A== X-Gm-Message-State: ANoB5pm8/VQRgZ59E/9hCGCOT5ifJTDoMxeZRY29Ge3dOFJ9ylzm+RT6 U0LJrFt4xvdhd6to85X8QL4wRM55tac= X-Google-Smtp-Source: AA0mqf5+O1BZXrE1YEC4dz/Cxj4pggZ4XHVB3Kve73sA6I4CTYSn6JfKCq6XbOm2qlu7J9B/7TW1zQ== X-Received: by 2002:a17:902:d58a:b0:189:a11e:9995 with SMTP id k10-20020a170902d58a00b00189a11e9995mr3527512plh.13.1670531708818; Thu, 08 Dec 2022 12:35:08 -0800 (PST) Received: from fedora.hsd1.ca.comcast.net ([2601:644:8002:1c20::2c6b]) by smtp.googlemail.com with ESMTPSA id f5-20020a170902860500b00189951514c4sm16954349plo.206.2022.12.08.12.35.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Dec 2022 12:35:08 -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 v3 2/4] madvise: Convert madvise_cold_or_pageout_pte_range() to use folios Date: Thu, 8 Dec 2022 12:35:01 -0800 Message-Id: <20221208203503.20665-3-vishal.moola@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221208203503.20665-1-vishal.moola@gmail.com> References: <20221208203503.20665-1-vishal.moola@gmail.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 3A74C1C0016 X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: iio7y77rehp1q6zcuo4kxm7bcdktgfu4 X-HE-Tag: 1670531710-766526 X-HE-Meta: U2FsdGVkX1/P1laHjfSzD148d5gG/JERtsAztoCU9VZkLIKRDVFy1sOJHy/UgWnY2Sce+p9Kwzb9kwf+FnrslN6nYRbAKp1vCJaoE9S8Ri/TvmPyDWW12QJ3SwLMgNb4ArEVHC2oKnXmk9Ma3nEp/tx8oFpcD87xgY3HXNfElknBKkCChAw/CaaS9DTzZsVVXSe5qX9H7Dj8pr6mwVO1cw0d6U6LMHh3AWl7U12vfA1uPHwL6YlyvYE63uOY+HQ2Fc16lGaIH/QXmRNZV6i9ilcCPqtaHZMH5oTJtEsLq7lO2rFrO6xM8+g86hpA34FYQ355k9PaRN9VQ+j8SyqUbOztPRcXQzT3YLnLaiO2bao+fs+kJGbiyLV8MA+0Xa+jadZUAQYwcdm0XeZqICpKZ0eP6/22exoX5ceNZsovbyb866KxA6SC64h3gmsqECnOphlj3CWtzwm95fpE/np1GXVIXkxyZzddHywNxMfyzr1KPUhwqnL/az1AAezzhXX8LkZbETkkbkbL0EeRHV8DM6Y/VZGORFVI9DWMkL1oybSnQ5gUf18Z6vBFUqa3jYh9i1vOd4Qw0F675Jjlf7NwVrwAsK72c5WNBVkWDpaHwgzOKL1Cq55GVytOvyyNBQ+rnnzBCZmbiiyKE4pL0Y9GqT28vwhFfe0rx4snltBHIePdp0dZ9hM/KAxoXducfKdErFQaJcFu9+VlaSa1dnx0wekewaLwHkMM7b6ZSvY1KGq0Op75N25LFK8AC7NFAwEQ7N+DQUpWRXmUdbdM4nIrtGnO3HQZvHln3QnchIpfuQxmruu50ldYnt8xuiZg98WrBWNRmmWWJYLM0GnbwMsuRBqvUz1gbXNOLF1JPSr6VfgYPEQR2pvTpNv1Z11bwk7hp5/EBn1ODa6YpErGeV/g8ISS3gGM0k/tSNVkP0Tt+bBypL2VVbUN7Wv594XQs2FQJd8bb8PBDgtSnwJ56Pz Th6tp7j7 t02k9LbpM9BO4VRhel04sYLxw1aEaPT1vulaxJn15uJN+CWmzC+Q5oii0duNcPew7f0eeOiyc6RFn2cPgb3PNEOTQTbfuGL/iuwdhdCp8ReTHD+hM8rR8OLm/gI5CuoYRT4RDlP3/g5f7f/zP24yEwBXd8U2AnAHiKlVTumXed3vV5JKEZi71xBni4NzMrXWRzIkkrLeEYV+AgnFT+p0FMzLQQBfXKrXJC4eaHD0v6h5prDID/+Xi7QCgnAO4U9xL/8dWizhmhSj7ATvt44G3UFgh7A== 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) Reviewed-by: Matthew Wilcox (Oracle) --- mm/madvise.c | 92 ++++++++++++++++++++++++++-------------------------- 1 file changed, 46 insertions(+), 46 deletions(-) diff --git a/mm/madvise.c b/mm/madvise.c index 2baa93ca2310..2a84b5dfbb4c 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -332,8 +332,8 @@ 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 page *page = NULL; - LIST_HEAD(page_list); + struct folio *folio = NULL; + LIST_HEAD(folio_list); if (fatal_signal_pending(current)) return -EINTR; @@ -358,23 +358,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 +386,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 @@ -421,31 +421,31 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd, if (!pte_present(ptent)) continue; - page = vm_normal_page(vma, addr, ptent); - if (!page || is_zone_device_page(page)) + folio = vm_normal_folio(vma, addr, ptent); + if (!folio || folio_is_zone_device(folio)) continue; /* * 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 +453,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) || folio_mapcount(folio) != 1) 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 +470,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;