From patchwork Mon Dec 11 16:22:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13487536 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 03923C4167B for ; Mon, 11 Dec 2023 16:22:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 491246B015E; Mon, 11 Dec 2023 11:22:38 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 418C86B0160; Mon, 11 Dec 2023 11:22:38 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2BBA76B0161; Mon, 11 Dec 2023 11:22:38 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 1B3F06B015E for ; Mon, 11 Dec 2023 11:22:38 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id DB21A1207F3 for ; Mon, 11 Dec 2023 16:22:37 +0000 (UTC) X-FDA: 81555055554.27.2AB9DB4 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf01.hostedemail.com (Postfix) with ESMTP id 3188C40006 for ; Mon, 11 Dec 2023 16:22:35 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=Dk0qLtEY; spf=none (imf01.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1702311756; 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=lv5/QlpFBGfTPKEhLKk7D9FZb8fAcEsAJO+HR3ZfBi8=; b=HEuQzNyk9YGhKRvooxpEkbTZ06PE4rD5spp5tooe2gvqFIEVVz9Lc3kDUhKbvwF0qAAXlh baRuRmN66SIOlxGnkWiDcHWQDjKYsMqP7mNieEczdMBWNjRe5Qqpyx0pKywga5WKKbl7a2 BocP7XsA3UyVn3mbiaPayCcq3fLQlvM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702311756; a=rsa-sha256; cv=none; b=iw+TrxrlamjCCDfwvUVmyRmQUTRvFGCgafhvL9uDZPwBFPMl09/VFZ8MMlI0Ggl7ls9STt RW8PW33qMfIt5hxQMptNDV7SZdBHvMe9PQRZxjxuWYZq/rUN0aBRJTGkQbwANP9KiI6e0a d7l3b+9DcbBnWsqPJTM42f5iokxluJg= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=Dk0qLtEY; spf=none (imf01.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=lv5/QlpFBGfTPKEhLKk7D9FZb8fAcEsAJO+HR3ZfBi8=; b=Dk0qLtEYD8I4szbGges29A2qv1 hRNfLUGhR/JjyKFFmwSd0G8I8SvurxwaYIB7ALTc8MJqqg5OF6EKdnYaeAC3XLwLgL+W4VroTgIVQ 1JD6rAFTbDqRe6xKcN5s2/cTqbsQctrv1THorzPCuqDuCS6SfQ4lkkZctdN0L+8b1MYLqZiX2sxUA f/VgG8JM7FR0QEHdK/CgFhteUvAnt87TIdmbNJolYo3F9yYhuhTvDVJUM9F71R3uGarRJom3RtG9/ saOLk8coQKSde/hl8p1MpgB2lQubT0jv5MvMnSierftxiB66z9LO+j3uV050dXj47wLlO7ghOK0fE dgJkzlag==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1rCj2u-0090JN-6i; Mon, 11 Dec 2023 16:22:16 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org Subject: [PATCH 3/9] mm: Convert unuse_pte() to use a folio throughout Date: Mon, 11 Dec 2023 16:22:08 +0000 Message-Id: <20231211162214.2146080-4-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20231211162214.2146080-1-willy@infradead.org> References: <20231211162214.2146080-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 3188C40006 X-Rspam-User: X-Stat-Signature: 7aoooije77ghs6oe1kk11nwtwnum9ccq X-Rspamd-Server: rspam03 X-HE-Tag: 1702311755-365113 X-HE-Meta: U2FsdGVkX1+AvKPH+18QaYJ8QUngvz/fA8n2bq4vDNVL3qFOnlycr5RlbJ2LJZKK/yoLQF+7xInCjY/4NKPs6eI3mD+0bdUKQPyl1EoICLuStYNW7BO2t2rkgsRhmhVnlmQs6ORq315tuVnSRj9Bv8QYDpnuIjLPogHUoXxoT3Qzx78ODakSSV7hURU9c1TbE2+1yrSA/Nzw1zKalIjrpB7fhDNVhVo1f7XDb9918XWuvhMmCPdvNmdqCiDUnPjGUrAwlE37QvPiVl1wtq8aYHt19CGKK6LFCm3UdJKETF3dwwcND9P4BDirNHf/eAoZy14IkYb+6+pU3g1jz5Y4g04qk3oxR8uiHYYgEC7xTuMerzkBAWeubV5dEYumqGKB3hby4vA7QCyz17TW2na8P8T9qARuzlWfo7fhW5E8+WSW1rex5HNm6oxzXFykrCLPUrP++YoCLivXyIk9S6wlxnJ1nCiC97UhZGtfTBFwS/0jE+dJLl9ih5J3RIMCG2XkHiHlzFpatLDBYBIcdNGEzHYpNC+5BtHI25z06rVkbgCbvE2tzUDo8eFxx8uQMMqb2AETW5piEPfovsl3wnYiSD4PAJbItjAFxZweVjH6vmaLi41/szly5YGkIH37jKyjwIn4poOfEo/q5PQ6icnWLdOc2JC/gN5rv5XAEHDHkQ2bP+kHb/lcmxnvCRQ1eykZ6eWvg9DqLzuoXdty30xJEaAsDMG2knR67+JWg9TNmJpPh5OzB5W3VSpQm+vTyiazM9FeEZP3gZE0eKyjwAup+nyCz1NbnE8t4NbQm9aVWCYEQx/DoSoqGWJ4xqU1qQ3RcuGV699OklzBc3q3KML42wUeLNwVsbXgN0GgTpZNTuixBaJtJm9ixOf9IVpnp4TCVsxLqjloaFOhHmcQOlk3TJFmnGnWGt3YsbROrcmwtZKJ3kSZfCvM0B5besBMXSRnXD5S2NcYYoKxYT3NB6Q xEdNNzRA qUbcAR+DtQtyuFB9mNs9/NiJhhRycVx8CNYHyCQGs8Qhu9V7KurXBhxo0yoUYInh2wrK+Uu12dms/6zSPiHrYfR26zEv8H48fO7HmVwJly+3FlUYfCy9pA8rM9nICi9ZJltb00OwPIXGVwz9ZpHHA6xeKxY8R5PKnmtwKoWWpB482n5Lx2zR93z5jHSQtourVMJ+xDnzY5NJmCnGAnwbx0ES4vPaAicxabKUR 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: List-Subscribe: List-Unsubscribe: Saves about eight calls to compound_head(). Signed-off-by: Matthew Wilcox (Oracle) --- mm/swapfile.c | 47 +++++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/mm/swapfile.c b/mm/swapfile.c index 88842c6fb8fe..21eced2d1f80 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -1741,21 +1741,25 @@ static inline int pte_same_as_swp(pte_t pte, pte_t swp_pte) static int unuse_pte(struct vm_area_struct *vma, pmd_t *pmd, unsigned long addr, swp_entry_t entry, struct folio *folio) { - struct page *page = folio_file_page(folio, swp_offset(entry)); - struct page *swapcache; + struct page *page; + struct folio *swapcache; spinlock_t *ptl; pte_t *pte, new_pte, old_pte; - bool hwpoisoned = PageHWPoison(page); + bool hwpoisoned = false; int ret = 1; - swapcache = page; + swapcache = folio; folio = ksm_might_need_to_copy(folio, vma, addr); if (unlikely(!folio)) return -ENOMEM; - else if (unlikely(folio == ERR_PTR(-EHWPOISON))) + else if (unlikely(folio == ERR_PTR(-EHWPOISON))) { + hwpoisoned = true; + folio = swapcache; + } + + page = folio_file_page(folio, swp_offset(entry)); + if (PageHWPoison(page)) hwpoisoned = true; - else - page = folio_file_page(folio, swp_offset(entry)); pte = pte_offset_map_lock(vma->vm_mm, pmd, addr, &ptl); if (unlikely(!pte || !pte_same_as_swp(ptep_get(pte), @@ -1766,13 +1770,12 @@ static int unuse_pte(struct vm_area_struct *vma, pmd_t *pmd, old_pte = ptep_get(pte); - if (unlikely(hwpoisoned || !PageUptodate(page))) { + if (unlikely(hwpoisoned || !folio_test_uptodate(folio))) { swp_entry_t swp_entry; dec_mm_counter(vma->vm_mm, MM_SWAPENTS); if (hwpoisoned) { - swp_entry = make_hwpoison_entry(swapcache); - page = swapcache; + swp_entry = make_hwpoison_entry(page); } else { swp_entry = make_poisoned_swp_entry(); } @@ -1786,7 +1789,7 @@ static int unuse_pte(struct vm_area_struct *vma, pmd_t *pmd, * when reading from swap. This metadata may be indexed by swap entry * so this must be called before swap_free(). */ - arch_swap_restore(entry, page_folio(page)); + arch_swap_restore(entry, folio); /* See do_swap_page() */ VM_BUG_ON_FOLIO(!folio_test_anon(folio), folio); @@ -1794,23 +1797,23 @@ static int unuse_pte(struct vm_area_struct *vma, pmd_t *pmd, dec_mm_counter(vma->vm_mm, MM_SWAPENTS); inc_mm_counter(vma->vm_mm, MM_ANONPAGES); - get_page(page); - if (page == swapcache) { + folio_get(folio); + if (folio == swapcache) { rmap_t rmap_flags = RMAP_NONE; /* - * See do_swap_page(): PageWriteback() would be problematic. - * However, we do a wait_on_page_writeback() just before this - * call and have the page locked. + * See do_swap_page(): writeback would be problematic. + * However, we do a folio_wait_writeback() just before this + * call and have the folio locked. */ - VM_BUG_ON_PAGE(PageWriteback(page), page); + VM_BUG_ON_FOLIO(folio_test_writeback(folio), folio); if (pte_swp_exclusive(old_pte)) rmap_flags |= RMAP_EXCLUSIVE; page_add_anon_rmap(page, vma, addr, rmap_flags); } else { /* ksm created a completely new copy */ - page_add_new_anon_rmap(page, vma, addr); - lru_cache_add_inactive_or_unevictable(page, vma); + folio_add_new_anon_rmap(folio, vma, addr); + folio_add_lru_vma(folio, vma); } new_pte = pte_mkold(mk_pte(page, vma->vm_page_prot)); if (pte_swp_soft_dirty(old_pte)) @@ -1823,9 +1826,9 @@ static int unuse_pte(struct vm_area_struct *vma, pmd_t *pmd, out: if (pte) pte_unmap_unlock(pte, ptl); - if (page != swapcache) { - unlock_page(page); - put_page(page); + if (folio != swapcache) { + folio_unlock(folio); + folio_put(folio); } return ret; }