From patchwork Mon Aug 21 16:08:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13359616 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 23107EE49AE for ; Mon, 21 Aug 2023 16:09:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A3B4C8E0005; Mon, 21 Aug 2023 12:09:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9C41A8E0002; Mon, 21 Aug 2023 12:09:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 72C6D8E0005; Mon, 21 Aug 2023 12:09:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 57E538E0002 for ; Mon, 21 Aug 2023 12:09:05 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 310C8B17E6 for ; Mon, 21 Aug 2023 16:09:05 +0000 (UTC) X-FDA: 81148595850.27.24DEEE0 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf25.hostedemail.com (Postfix) with ESMTP id 3F14CA0011 for ; Mon, 21 Aug 2023 16:09:03 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=MT2mNmXg; spf=pass (imf25.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1692634143; 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=JSFFh/KLUGTq+zDQ/y6zlFb70l3lmZmKgiSBR+NyjZY=; b=IrrXbbheqPnTFe2IxOivoAgVytCK5hMZr2HZX8Gc2k5AZLgLleu4QF4LA9Djr5v6WJBpiI 3J2cB79TDSoE7+AEKuN+pV3m3iT3dHnKHFI76ve0KM8jED5bNnA6YinvDE3PGooBetXAM5 QQocT3+8m8YB931yTX69d3dFTaS76D0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692634143; a=rsa-sha256; cv=none; b=3yybBut9T9cyC5H75g0uX2puz6vnaf+krZ3lhnyN+R3axLFP4CRaXiQuzVSjQa4YLegdmk XC5IqojcERuYuuIJ1VbcSAU0GIVJyOHJZlydjMjE5wfyd6FSLsB6oS2juD0u61CAB7/ly9 HWtgqFPq2HXUDLweG516CeWKVj7EspE= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=MT2mNmXg; spf=pass (imf25.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1692634142; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JSFFh/KLUGTq+zDQ/y6zlFb70l3lmZmKgiSBR+NyjZY=; b=MT2mNmXgc+vI20AhORo3Z/U/+lZIlvFiXxKuk/k+VoMSqkn0Le0qYfUZgp0TC0CHdEjVEn kcx2H6ct4qBwKv2cvbxn16WmQCwjX1ccdwQKL3S+FUjPcFRJvBb+BOFkW7Iz9Za2F8pbgm Mgw/yyPshAs6g+jq5HzH8YEdLMblF7c= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-520-GEYiNV70OW-yfFc5WKiRKg-1; Mon, 21 Aug 2023 12:08:59 -0400 X-MC-Unique: GEYiNV70OW-yfFc5WKiRKg-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E42CB187573F; Mon, 21 Aug 2023 16:08:55 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.39.192.184]) by smtp.corp.redhat.com (Postfix) with ESMTP id 56E2C492C14; Mon, 21 Aug 2023 16:08:53 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, David Hildenbrand , Andrew Morton , Matthew Wilcox , Peter Xu , Catalin Marinas , Will Deacon , Hugh Dickins , Seth Jennings , Dan Streetman , Vitaly Wool Subject: [PATCH mm-unstable v1 1/4] mm/swap: stop using page->private on tail pages for THP_SWAP Date: Mon, 21 Aug 2023 18:08:46 +0200 Message-ID: <20230821160849.531668-2-david@redhat.com> In-Reply-To: <20230821160849.531668-1-david@redhat.com> References: <20230821160849.531668-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Rspamd-Queue-Id: 3F14CA0011 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: psekonc47zbqi6mfxu4facprrwcfyt5q X-HE-Tag: 1692634143-215143 X-HE-Meta: U2FsdGVkX19RUuMzJvunkQ9sP0A+rdPq5WEXwUpt3xZYLVV46/j2hN5cLDG5KpBAoHUIPXvS5fL0YKuly8HIfw8SCsfqu/B4KSgOykhGtDyNqwDXyP8eYX4MQJ/9UbDNgb0oZPNa5IBYhHmkzaDoY8zj7ePtOzuyOXJW5V/B/PXNYjera+SqGKn4S0VjrV4zHvSq7x50qxIgbjq78Dl4E3Dxk62RzceCNkUGbv6+tT6cbxk2yngjrwpZEhgIgHmKjKeAi7ZkONMTfEwzRn4YZs86bB3O5tYuCljyGA5WIQwerHvrejEICsg3Qe32IU1RaeCyZf/EURbKH1KWzR7MACJkb0ZZ/TiSfpjkqRff2g1BRQ7zdAo3Zyfp1G5Egtp0Ty9dh+lrb9w92+bWYVHNQUUUZ6LN7/bPifwdpGdaAkFRf+l20fh5CrN27jRgXRYRccEre3hyHgaSeTOzWXpFRC6RjielUM3EhS2QqEG9gi8OhAi2z15af+3uaXZY1ifA7Oxl0H5uhL5gnTiyeWGvbP7AijZJqhotV2gESFMxd/awaqgkTkdQILCK2XNjvCJ9rMoFZiHRTbaRbqOt29GAGx64EM1FmcHEvs4gcLpg6CT73UMXZmIqi7iXClCG+6/RdfL1XNU45jM39NfAKfsYZTz2r+WToI5ojiQPmrLsF4JMl1PG7coJ4wMv1ouPW3mJZh4GAAj5zIIrXWslvlf8LDD4WWPCEJNwGn7url+9PWFZgx1EE+2jey546xTfKutQK3X1NuschmB6hi3M3Ljrk2QSQcllEB/LTuYyVDbSIwvShST5QjXa9hirLxv+fq7nq/ENUnizgXCDoe37NkAgV8rXJlJO8AExs3Kiygzxw2Eh7vfaokOTWF+/Sc1AS8BoweOCBzFIbXansQQMXDHoN9q1txvEshokzQec06lt8891bGEH4uHbOkbts6CIK5gfQnhkAk3RDXBujnwBBC8 IH1p/wK1 n0nFMRJdR3U2pdfyVACllJjDYtydoyfrXXDj/jtPbKR0PrrpnHjRnIcz5dfuQRjY2x9Yo2A0uzBdwcX2JbYEQKAZnORj4N/DEcysJOo+2tcyW/byztwZnoH0wHbmRTunEpT/k3LthWLR2TBEbDrjHP1l2/07e7X8qtNmr8o5g7wiH9UK0AjQY1QcNcNoyVnXICE266tRdqpOVksWm3+s6QBvX46FsDrB8I5KV7EjQPh2FgjY= 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: Let's stop using page->private on tail pages, making it possible to just unconditionally reuse that field in the tail pages of large folios. The remaining usage of the private field for THP_SWAP is in the THP splitting code (mm/huge_memory.c), that we'll handle separately later. Update the THP_SWAP documentation and sanity checks in mm_types.h and __split_huge_page_tail(). Signed-off-by: David Hildenbrand Acked-by: Catalin Marinas Signed-off-by: David Hildenbrand Reviewed-by: Yosry Ahmed --- arch/arm64/mm/mteswap.c | 5 +++-- include/linux/mm_types.h | 12 +----------- include/linux/swap.h | 9 +++++++++ mm/huge_memory.c | 15 ++++++--------- mm/memory.c | 2 +- mm/rmap.c | 2 +- mm/swap_state.c | 5 +++-- mm/swapfile.c | 4 ++-- 8 files changed, 26 insertions(+), 28 deletions(-) diff --git a/arch/arm64/mm/mteswap.c b/arch/arm64/mm/mteswap.c index cd508ba80ab1..a31833e3ddc5 100644 --- a/arch/arm64/mm/mteswap.c +++ b/arch/arm64/mm/mteswap.c @@ -33,8 +33,9 @@ int mte_save_tags(struct page *page) mte_save_page_tags(page_address(page), tag_storage); - /* page_private contains the swap entry.val set in do_swap_page */ - ret = xa_store(&mte_pages, page_private(page), tag_storage, GFP_KERNEL); + /* lookup the swap entry.val from the page */ + ret = xa_store(&mte_pages, page_swap_entry(page).val, tag_storage, + GFP_KERNEL); if (WARN(xa_is_err(ret), "Failed to store MTE tags")) { mte_free_tag_storage(tag_storage); return xa_err(ret); diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index b9b6c88875b9..61361f1750c3 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -333,11 +333,8 @@ struct folio { atomic_t _pincount; #ifdef CONFIG_64BIT unsigned int _folio_nr_pages; - /* 4 byte gap here */ - /* private: the union with struct page is transitional */ - /* Fix THP_SWAP to not use tail->private */ - unsigned long _private_1; #endif + /* private: the union with struct page is transitional */ }; struct page __page_1; }; @@ -358,9 +355,6 @@ struct folio { /* public: */ struct list_head _deferred_list; /* private: the union with struct page is transitional */ - unsigned long _avail_2a; - /* Fix THP_SWAP to not use tail->private */ - unsigned long _private_2a; }; struct page __page_2; }; @@ -385,9 +379,6 @@ FOLIO_MATCH(memcg_data, memcg_data); offsetof(struct page, pg) + sizeof(struct page)) FOLIO_MATCH(flags, _flags_1); FOLIO_MATCH(compound_head, _head_1); -#ifdef CONFIG_64BIT -FOLIO_MATCH(private, _private_1); -#endif #undef FOLIO_MATCH #define FOLIO_MATCH(pg, fl) \ static_assert(offsetof(struct folio, fl) == \ @@ -396,7 +387,6 @@ FOLIO_MATCH(flags, _flags_2); FOLIO_MATCH(compound_head, _head_2); FOLIO_MATCH(flags, _flags_2a); FOLIO_MATCH(compound_head, _head_2a); -FOLIO_MATCH(private, _private_2a); #undef FOLIO_MATCH /** diff --git a/include/linux/swap.h b/include/linux/swap.h index bb5adc604144..84fe0e94f5cd 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -339,6 +339,15 @@ static inline swp_entry_t folio_swap_entry(struct folio *folio) return entry; } +static inline swp_entry_t page_swap_entry(struct page *page) +{ + struct folio *folio = page_folio(page); + swp_entry_t entry = folio_swap_entry(folio); + + entry.val += page - &folio->page; + return entry; +} + static inline void folio_set_swap_entry(struct folio *folio, swp_entry_t entry) { folio->private = (void *)entry.val; diff --git a/mm/huge_memory.c b/mm/huge_memory.c index cc2f65f8cc62..c04702ae71d2 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2446,18 +2446,15 @@ static void __split_huge_page_tail(struct page *head, int tail, page_tail->index = head->index + tail; /* - * page->private should not be set in tail pages with the exception - * of swap cache pages that store the swp_entry_t in tail pages. - * Fix up and warn once if private is unexpectedly set. - * - * What of 32-bit systems, on which folio->_pincount overlays - * head[1].private? No problem: THP_SWAP is not enabled on 32-bit, and - * pincount must be 0 for folio_ref_freeze() to have succeeded. + * page->private should not be set in tail pages. Fix up and warn once + * if private is unexpectedly set. */ - if (!folio_test_swapcache(page_folio(head))) { - VM_WARN_ON_ONCE_PAGE(page_tail->private != 0, page_tail); + if (unlikely(page_tail->private)) { + VM_WARN_ON_ONCE_PAGE(true, page_tail); page_tail->private = 0; } + if (PageSwapCache(head)) + set_page_private(page_tail, (unsigned long)head->private + tail); /* Page flags must be visible before we make the page non-compound. */ smp_wmb(); diff --git a/mm/memory.c b/mm/memory.c index d003076b218d..ff13242c1589 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3882,7 +3882,7 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) * changed. */ if (unlikely(!folio_test_swapcache(folio) || - page_private(page) != entry.val)) + page_swap_entry(page).val != entry.val)) goto out_page; /* diff --git a/mm/rmap.c b/mm/rmap.c index 1f04debdc87a..ec7f8e6c9e48 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1647,7 +1647,7 @@ static bool try_to_unmap_one(struct folio *folio, struct vm_area_struct *vma, */ dec_mm_counter(mm, mm_counter(&folio->page)); } else if (folio_test_anon(folio)) { - swp_entry_t entry = { .val = page_private(subpage) }; + swp_entry_t entry = page_swap_entry(subpage); pte_t swp_pte; /* * Store the swap location in the pte. diff --git a/mm/swap_state.c b/mm/swap_state.c index 01f15139b7d9..2f2417810052 100644 --- a/mm/swap_state.c +++ b/mm/swap_state.c @@ -100,6 +100,7 @@ int add_to_swap_cache(struct folio *folio, swp_entry_t entry, folio_ref_add(folio, nr); folio_set_swapcache(folio); + folio_set_swap_entry(folio, entry); do { xas_lock_irq(&xas); @@ -113,7 +114,6 @@ int add_to_swap_cache(struct folio *folio, swp_entry_t entry, if (shadowp) *shadowp = old; } - set_page_private(folio_page(folio, i), entry.val + i); xas_store(&xas, folio); xas_next(&xas); } @@ -154,9 +154,10 @@ void __delete_from_swap_cache(struct folio *folio, for (i = 0; i < nr; i++) { void *entry = xas_store(&xas, shadow); VM_BUG_ON_PAGE(entry != folio, entry); - set_page_private(folio_page(folio, i), 0); xas_next(&xas); } + entry.val = 0; + folio_set_swap_entry(folio, entry); folio_clear_swapcache(folio); address_space->nrpages -= nr; __node_stat_mod_folio(folio, NR_FILE_PAGES, -nr); diff --git a/mm/swapfile.c b/mm/swapfile.c index d46933adf789..bd9d904671b9 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -3369,7 +3369,7 @@ struct swap_info_struct *swp_swap_info(swp_entry_t entry) struct swap_info_struct *page_swap_info(struct page *page) { - swp_entry_t entry = { .val = page_private(page) }; + swp_entry_t entry = page_swap_entry(page); return swp_swap_info(entry); } @@ -3384,7 +3384,7 @@ EXPORT_SYMBOL_GPL(swapcache_mapping); pgoff_t __page_file_index(struct page *page) { - swp_entry_t swap = { .val = page_private(page) }; + swp_entry_t swap = page_swap_entry(page); return swp_offset(swap); } EXPORT_SYMBOL_GPL(__page_file_index); From patchwork Mon Aug 21 16:08:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13359617 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 657BFEE4993 for ; Mon, 21 Aug 2023 16:09:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ECFA88E0006; Mon, 21 Aug 2023 12:09:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E7FA88E0002; Mon, 21 Aug 2023 12:09:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CF82F8E0006; Mon, 21 Aug 2023 12:09:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id B752E8E0002 for ; Mon, 21 Aug 2023 12:09:07 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 87DCFB19B7 for ; Mon, 21 Aug 2023 16:09:07 +0000 (UTC) X-FDA: 81148595934.23.F8A5009 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf01.hostedemail.com (Postfix) with ESMTP id 3675040028 for ; Mon, 21 Aug 2023 16:09:05 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=jC3lEYgi; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf01.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1692634145; 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=oXgxSUiHlACYEZ8/tewWc2FJCrUF3dBlQ9Skg2Bh23k=; b=8VPzAzVDhvS1AjWaYsdniit0ePGbYrG/gIWdklM0tbHidWaRp/w2HWqUrMM2oRASNx6q/T xlJQ2ipoHA44LOGEIOgfUqDwbMaBXDEzTvZMlyHIbSZ9/077pi9g0j2V6IsqoZbJjiQlhH tsSThsFizYpaPf0uavYYb6tiR8JsdsM= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=jC3lEYgi; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf01.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692634145; a=rsa-sha256; cv=none; b=p+7eLrhkvffzT/iXn4qNm4AHbMLlwwWmoVzRdx8c1P49GtktyUdy3MdKYquHowUuoclpC5 WMM1q28B4x+ORfrfBOaEZILd/2qqvOkMlKYYDX16T5TSXYvKWk89rNk11pUWBSaIIhd90F gd5xY95/tLX36b0om9f4rgghWuWNPyI= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1692634144; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oXgxSUiHlACYEZ8/tewWc2FJCrUF3dBlQ9Skg2Bh23k=; b=jC3lEYgidJpd+7Bhb6sAw7iUUGBKjzK6BePX3APWMLxaQ3+5+YspYU9t9ru8F5d+QpnQNB cs5kCjDv9xKLY5MSmOSVQAhHI9UUIv1u2kmSbwOu+TJsA8yNbi2E8pUJzTQHk6iBZGEXTp vIBcg4H6S8LwZkHBLAwAPt9bzppn+Ps= Received: from mimecast-mx02.redhat.com (66.187.233.73 [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-312-gUGvI0rJOSu3AbVA6NUL9A-1; Mon, 21 Aug 2023 12:09:01 -0400 X-MC-Unique: gUGvI0rJOSu3AbVA6NUL9A-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 807BE3C11A04; Mon, 21 Aug 2023 16:08:59 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.39.192.184]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5EBE9492C13; Mon, 21 Aug 2023 16:08:56 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, David Hildenbrand , Andrew Morton , Matthew Wilcox , Peter Xu , Catalin Marinas , Will Deacon , Hugh Dickins , Seth Jennings , Dan Streetman , Vitaly Wool Subject: [PATCH mm-unstable v1 2/4] mm/swap: use dedicated entry for swap in folio Date: Mon, 21 Aug 2023 18:08:47 +0200 Message-ID: <20230821160849.531668-3-david@redhat.com> In-Reply-To: <20230821160849.531668-1-david@redhat.com> References: <20230821160849.531668-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 3675040028 X-Stat-Signature: jbifaypxperfg3z8xje6gs37mkg359u7 X-HE-Tag: 1692634145-883988 X-HE-Meta: U2FsdGVkX19lktyIC/bL8NkYMAXNgNizNY1HDLUuHT4tD83MHykZiQwbqCwIdigWo/QzbsBnyAUG/dgRKM1p01g6JjQtQKEbm6+DIrnqsRWrmG/ZbF9G1FUPX152BpTptRZWiWt4MOPlzukIkD3SC1h1+8eD1G/ARGr4wgupk7q9Beceysko5NyvLEbfjwUbljD/5bFvQxA2dTmN0Y74GdG3z2ArUkaXNKUvxyg0jGqNNrmuHnQVeY7ZmmDjTQ3/HvjnmID4AM0f2e2RKLJPcpEmLCdXUQzkhDc3vqwRSFaAAq84KapMr4ZtJv1H5SToc9YtkjaB5lGPcdMJHPA86Z6vCggZVRTvwqz9nmcAY0E7Q6vzxR5G5HQWncdrOauuSH41K3+pO4IvIWOzh3s0ON6YSPFqpwEuSPhv5+CaKkpRdjkdgptX5ruRIaQAv56OJx885nEM7CMvRNu/e8V1YTbcmrSVzr3Q1ydk43jAqwndcIQQhP9kMmyIN3lgtIuJ6BPeb3Cn3vMkQnbHnMI2CpZzE03qQgRalgbVpUM3WK6ohiPfLRNZsp1w+MGMu4EintwzH4yjO9py1hEm9siLto5eOXjOkDD7RpoK0ScaxS3Bzq+RI671xbBid8X7i4bcDbM6RkzV1xN2zIqy6t/aHnp2AuvlzKGYC0Ys1H0xFy804rxcvezykK5j5E7kzJf5brHGLIG2WJ27Z+LC4Vx084EV12vRndoHzTkf/Nt4n5VDHkxfrRFwu7OgJRy9+e0f7lv4drJgYRl0mXD/6KtYJgZOMZ1akAVs17NE10LShRA6eqkrpDS6lidkXS0QWfQk8oSMWbOfRSAjNcES3drKn67zWAsiQedp2pXJb2kq6T6wptRnMDy8o/AodCsxieUx6VrfmCuBj7crAyUU2mpQzictQKXUNFyh3U1VLU/JaLYaW+CrYzpNDjVKkabvnTDcNPKXeHtG4Ae3n9AWKro J4oef73U VXdb6P+5S6wy/MhKFqlHEEZQBSG2MUrs/dULZUSt1LRbTBydkJYq1YXoumdVxHkltXgy9fbsCdi+LWgQi8+KCTBPQZxmWkGwNNYsILnO+gvlN007DxBNkg0mGrI8mdyWVun8dYS6PpqkT8mSNOe42fziPlNTDeVQ49SH5VkpU3fLpF+TE1oFUxqk1BcVxa8HxanR/cYiTdWUT0Nt7sQZGdwzwmGg1YH10H5FMKn3F7yO7oHM= 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: From: Matthew Wilcox Let's stop working on the private field and use an explicit swap field. We have to move the swp_entry_t typedef. Signed-off-by: Matthew Wilcox Signed-off-by: David Hildenbrand Reviewed-by: Chris Li --- include/linux/mm_types.h | 23 +++++++++++++---------- include/linux/swap.h | 5 ++--- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index 61361f1750c3..438a07854f8c 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -259,6 +259,14 @@ static inline struct page *encoded_page_ptr(struct encoded_page *page) */ #define TAIL_MAPPING_REUSED_MAX (2) +/* + * A swap entry has to fit into a "unsigned long", as the entry is hidden + * in the "index" field of the swapper address space. + */ +typedef struct { + unsigned long val; +} swp_entry_t; + /** * struct folio - Represents a contiguous set of bytes. * @flags: Identical to the page flags. @@ -269,7 +277,7 @@ static inline struct page *encoded_page_ptr(struct encoded_page *page) * @index: Offset within the file, in units of pages. For anonymous memory, * this is the index from the beginning of the mmap. * @private: Filesystem per-folio data (see folio_attach_private()). - * Used for swp_entry_t if folio_test_swapcache(). + * @swap: Used for swp_entry_t if folio_test_swapcache(). * @_mapcount: Do not access this member directly. Use folio_mapcount() to * find out how many times this folio is mapped by userspace. * @_refcount: Do not access this member directly. Use folio_ref_count() @@ -312,7 +320,10 @@ struct folio { }; struct address_space *mapping; pgoff_t index; - void *private; + union { + void *private; + swp_entry_t swap; + }; atomic_t _mapcount; atomic_t _refcount; #ifdef CONFIG_MEMCG @@ -1220,14 +1231,6 @@ enum tlb_flush_reason { NR_TLB_FLUSH_REASONS, }; - /* - * A swap entry has to fit into a "unsigned long", as the entry is hidden - * in the "index" field of the swapper address space. - */ -typedef struct { - unsigned long val; -} swp_entry_t; - /** * enum fault_flag - Fault flag definitions. * @FAULT_FLAG_WRITE: Fault was a write fault. diff --git a/include/linux/swap.h b/include/linux/swap.h index 84fe0e94f5cd..82859a1944f5 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -335,8 +335,7 @@ struct swap_info_struct { static inline swp_entry_t folio_swap_entry(struct folio *folio) { - swp_entry_t entry = { .val = page_private(&folio->page) }; - return entry; + return folio->swap; } static inline swp_entry_t page_swap_entry(struct page *page) @@ -350,7 +349,7 @@ static inline swp_entry_t page_swap_entry(struct page *page) static inline void folio_set_swap_entry(struct folio *folio, swp_entry_t entry) { - folio->private = (void *)entry.val; + folio->swap = entry; } /* linux/mm/workingset.c */ From patchwork Mon Aug 21 16:08:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13359618 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 36091EE49A6 for ; Mon, 21 Aug 2023 16:09:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D96F78E0007; Mon, 21 Aug 2023 12:09:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CFB008E0002; Mon, 21 Aug 2023 12:09:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B728F8E0007; Mon, 21 Aug 2023 12:09:08 -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 A28F38E0002 for ; Mon, 21 Aug 2023 12:09:08 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 81311A0825 for ; Mon, 21 Aug 2023 16:09:08 +0000 (UTC) X-FDA: 81148595976.13.F7DBF86 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf14.hostedemail.com (Postfix) with ESMTP id B52B7100029 for ; Mon, 21 Aug 2023 16:09:06 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=e3JNvKto; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf14.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1692634146; 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=GdnFUGqNF8uC/Mhnd72wov++fKDyb2cH73FrJqKy4cQ=; b=Srh1IHilYgEfTo6356QzpMVuXTKniE+Q5Ad0Mxbiq9z5gQF14W9zqg053ciLXd5AIubwLV rmjnW35xhxdNyd3ioUVIb9V7ViAatPNCiuwpCJlJ3AhiHLN+L3aIwt6v95u/jS/cE4dMtO W8yuzy3joPpcDkjOH3khcU4EKZyH+94= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=e3JNvKto; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf14.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692634146; a=rsa-sha256; cv=none; b=DdGCK/2jw9oO7PTGEybIYL6nlIJ1xISXLq7+ddBNV6CdeQzNjoywRR4tNTTT3983JPlVqm MRqiJn9VS8P7vR6l8oZkfp8e+g/j07HcI7s0L8h4hTssLLZ9Xed3vBvXqPK1vji3qu45lh P02x3S3d4Ds9Tw1X8cWziYxqwY+FJNU= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1692634146; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GdnFUGqNF8uC/Mhnd72wov++fKDyb2cH73FrJqKy4cQ=; b=e3JNvKtoQghdCsspwNPKLI95sboueYhn/r7/VOHRgcn7kQ3IaXGyiwAiPm9gM8Mj/WNs5U IzUuNNKvwEVrBKnnG+U8HXSRh40bvwzZS/TLmd5XmHRF/Hr+tSNg94Zg4XKnAREQHg4ZxV lxIS09ET667vXTzTTeNvM9yGYCjNixE= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-343-L421dwfjPouKmahmihEKAA-1; Mon, 21 Aug 2023 12:09:02 -0400 X-MC-Unique: L421dwfjPouKmahmihEKAA-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DBFE01875842; Mon, 21 Aug 2023 16:09:01 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.39.192.184]) by smtp.corp.redhat.com (Postfix) with ESMTP id B9873492C13; Mon, 21 Aug 2023 16:08:59 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, David Hildenbrand , Andrew Morton , Matthew Wilcox , Peter Xu , Catalin Marinas , Will Deacon , Hugh Dickins , Seth Jennings , Dan Streetman , Vitaly Wool Subject: [PATCH mm-unstable v1 3/4] mm/swap: inline folio_set_swap_entry() and folio_swap_entry() Date: Mon, 21 Aug 2023 18:08:48 +0200 Message-ID: <20230821160849.531668-4-david@redhat.com> In-Reply-To: <20230821160849.531668-1-david@redhat.com> References: <20230821160849.531668-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: B52B7100029 X-Stat-Signature: i6w9u7sxt9wxpdx9od8cdn4upuzfkxoe X-HE-Tag: 1692634146-613835 X-HE-Meta: U2FsdGVkX1/NBzaxSQnm/1IYMTEGQCWiUmrehAZgbWVm0siHE3cIp5Ch4ZlzFD7zwbcY8c+cDF83X+sY+zpQGGehVvAasmpQcwt+IVsc51ZvVGaTBSLZtRWQa7xZehQOLcfuHbu6+Ws1Xwg75swvqeWD7YEnRes4b81+MuThFQIBOOIdiXbo0mkbnOaYOOUBNg7wee9hqxUB5TYz/bMbyij0p7tk9cfzi97xjhIJxASnGM+ImDvX9jGa8FXCYd9rwlOQ/59HtdfjHG0EQ0zq7SdC58Z9n5BEcnj9cgZU+UWj8Nt7297mo2VqnRz45M8Hye4x848CJ5vWNzWwNNyaieykM3y7V04dd0xoXrA0NiUf3LrFR35nq5DL+pAkiOS961AtyuF1XDMvrDy1B7/v1f/jhrz5YYtafszoNr7RbCyia49gVyT+J1g+phPA8khltvCaNfhKbyJ7h2oMwczwTSBBDOim2QpRM0iL0upo/T7tKaRHfcL3k03VFE58TGXx1pd4JvzCuzmFBezDsHkxv2XEhMji5Ar0rPBFuh0ZyMdy08KMurVwfeafkfohSqkQsqoPht6YDtS0pbZdHTF24faEvRAhF5xjEPFij1qqN0M6kmcNr/gluzLhYtg8XL6pGay644KmlBP1SKUFcL/Jpgti07blGBWIP69wVvN7QZcCrB9gYSTlmRWX6o/q6NkX43J+LDmgP41ahDP6Cs/OaSXHykWcmU+YyX5fnpfL1UBu6l/AykS4U1tIbF/NUOY6pE4hukgb9o1NOJ/F+P0LBiYcAO58wnjRiL42aDErI4snuAwaO9HllAf6uylRvxxqcQ8Ix3R7Ek70IOrBs+exVfKwCzL8o9bxLBOCQ41PxKvD/cGg3QAkLaRMDbUs3BkTvUzcjruSnKZIyOp8MyBbPoehsyKrQ9lDjfyqDfYQfZdiaEqTNp9CUYUC8JbQcpOr+WEW4q6Bvay15/Y6WeM EqkTq1+O oPJRC9D5ZjX2W3a3GEK23LVMl+zC/59H8ZX3qsaFSiwh6YDRpreUGCzTjVHRCi482aCvhUD/ZFHhCwtXkKOoIDB4kfH1wJgEpaKtGhF+ujI674qEMxqYpOoESbSS4Rk5hZW6ljXOIJ0UibDH9COqZDvzZ0J+G2tBkKah/rArhqujsaHtwZawMX++xeQSSuwbf83GZk43ar0CiedDkU7PtGrVjDreCWZQYkQ2WZxvqtRSSqmAaexvv8cC7IIcQ/g70Qxv4hQ6Ewa3BKkOUg60mxu1cMg== 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: Let's simply work on the folio directly and remove the helpers. Suggested-by: Matthew Wilcox Signed-off-by: David Hildenbrand Reviewed-by: Chris Li --- include/linux/swap.h | 12 +----------- mm/memory.c | 2 +- mm/shmem.c | 6 +++--- mm/swap_state.c | 7 +++---- mm/swapfile.c | 2 +- mm/util.c | 2 +- mm/vmscan.c | 2 +- mm/zswap.c | 4 ++-- 8 files changed, 13 insertions(+), 24 deletions(-) diff --git a/include/linux/swap.h b/include/linux/swap.h index 82859a1944f5..603acf813873 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -333,25 +333,15 @@ struct swap_info_struct { */ }; -static inline swp_entry_t folio_swap_entry(struct folio *folio) -{ - return folio->swap; -} - static inline swp_entry_t page_swap_entry(struct page *page) { struct folio *folio = page_folio(page); - swp_entry_t entry = folio_swap_entry(folio); + swp_entry_t entry = folio->swap; entry.val += page - &folio->page; return entry; } -static inline void folio_set_swap_entry(struct folio *folio, swp_entry_t entry) -{ - folio->swap = entry; -} - /* linux/mm/workingset.c */ bool workingset_test_recent(void *shadow, bool file, bool *workingset); void workingset_age_nonresident(struct lruvec *lruvec, unsigned long nr_pages); diff --git a/mm/memory.c b/mm/memory.c index ff13242c1589..c51800dbfa9b 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3831,7 +3831,7 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) folio_add_lru(folio); /* To provide entry to swap_readpage() */ - folio_set_swap_entry(folio, entry); + folio->swap = entry; swap_readpage(page, true, NULL); folio->private = NULL; } diff --git a/mm/shmem.c b/mm/shmem.c index 7a0c1e19d9f8..fc1afe9dfcfe 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1657,7 +1657,7 @@ static int shmem_replace_folio(struct folio **foliop, gfp_t gfp, int error; old = *foliop; - entry = folio_swap_entry(old); + entry = old->swap; swap_index = swp_offset(entry); swap_mapping = swap_address_space(entry); @@ -1678,7 +1678,7 @@ static int shmem_replace_folio(struct folio **foliop, gfp_t gfp, __folio_set_locked(new); __folio_set_swapbacked(new); folio_mark_uptodate(new); - folio_set_swap_entry(new, entry); + new->swap = entry; folio_set_swapcache(new); /* @@ -1800,7 +1800,7 @@ static int shmem_swapin_folio(struct inode *inode, pgoff_t index, /* We have to do this with folio locked to prevent races */ folio_lock(folio); if (!folio_test_swapcache(folio) || - folio_swap_entry(folio).val != swap.val || + folio->swap.val != swap.val || !shmem_confirm_swap(mapping, index, swap)) { error = -EEXIST; goto unlock; diff --git a/mm/swap_state.c b/mm/swap_state.c index 2f2417810052..b3b14bd0dd64 100644 --- a/mm/swap_state.c +++ b/mm/swap_state.c @@ -100,7 +100,7 @@ int add_to_swap_cache(struct folio *folio, swp_entry_t entry, folio_ref_add(folio, nr); folio_set_swapcache(folio); - folio_set_swap_entry(folio, entry); + folio->swap = entry; do { xas_lock_irq(&xas); @@ -156,8 +156,7 @@ void __delete_from_swap_cache(struct folio *folio, VM_BUG_ON_PAGE(entry != folio, entry); xas_next(&xas); } - entry.val = 0; - folio_set_swap_entry(folio, entry); + folio->swap.val = 0; folio_clear_swapcache(folio); address_space->nrpages -= nr; __node_stat_mod_folio(folio, NR_FILE_PAGES, -nr); @@ -233,7 +232,7 @@ bool add_to_swap(struct folio *folio) */ void delete_from_swap_cache(struct folio *folio) { - swp_entry_t entry = folio_swap_entry(folio); + swp_entry_t entry = folio->swap; struct address_space *address_space = swap_address_space(entry); xa_lock_irq(&address_space->i_pages); diff --git a/mm/swapfile.c b/mm/swapfile.c index bd9d904671b9..e52f486834eb 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -1536,7 +1536,7 @@ static bool swap_page_trans_huge_swapped(struct swap_info_struct *si, static bool folio_swapped(struct folio *folio) { - swp_entry_t entry = folio_swap_entry(folio); + swp_entry_t entry = folio->swap; struct swap_info_struct *si = _swap_info_get(entry); if (!si) diff --git a/mm/util.c b/mm/util.c index cde229b05eb3..f31e2ca62cfa 100644 --- a/mm/util.c +++ b/mm/util.c @@ -764,7 +764,7 @@ struct address_space *folio_mapping(struct folio *folio) return NULL; if (unlikely(folio_test_swapcache(folio))) - return swap_address_space(folio_swap_entry(folio)); + return swap_address_space(folio->swap); mapping = folio->mapping; if ((unsigned long)mapping & PAGE_MAPPING_FLAGS) diff --git a/mm/vmscan.c b/mm/vmscan.c index c7c149cb8d66..6f13394b112e 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -1423,7 +1423,7 @@ static int __remove_mapping(struct address_space *mapping, struct folio *folio, } if (folio_test_swapcache(folio)) { - swp_entry_t swap = folio_swap_entry(folio); + swp_entry_t swap = folio->swap; if (reclaimed && !mapping_exiting(mapping)) shadow = workingset_eviction(folio, target_memcg); diff --git a/mm/zswap.c b/mm/zswap.c index 7300b98d4a03..412b1409a0d7 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -1190,7 +1190,7 @@ static void zswap_fill_page(void *ptr, unsigned long value) bool zswap_store(struct folio *folio) { - swp_entry_t swp = folio_swap_entry(folio); + swp_entry_t swp = folio->swap; int type = swp_type(swp); pgoff_t offset = swp_offset(swp); struct page *page = &folio->page; @@ -1370,7 +1370,7 @@ bool zswap_store(struct folio *folio) bool zswap_load(struct folio *folio) { - swp_entry_t swp = folio_swap_entry(folio); + swp_entry_t swp = folio->swap; int type = swp_type(swp); pgoff_t offset = swp_offset(swp); struct page *page = &folio->page; From patchwork Mon Aug 21 16:08:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13359619 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 DACBEEE49AB for ; Mon, 21 Aug 2023 16:09:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6430C8E0008; Mon, 21 Aug 2023 12:09:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5F2BA8E0002; Mon, 21 Aug 2023 12:09:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 494A98E0008; Mon, 21 Aug 2023 12:09:15 -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 353808E0002 for ; Mon, 21 Aug 2023 12:09:15 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 080F8B14D1 for ; Mon, 21 Aug 2023 16:09:15 +0000 (UTC) X-FDA: 81148596270.23.B4C9A99 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf11.hostedemail.com (Postfix) with ESMTP id 5614C4002B for ; Mon, 21 Aug 2023 16:09:13 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=gP6Ft9YJ; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf11.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692634153; a=rsa-sha256; cv=none; b=TabT5SWudv0GkqZ0T3jt8zVqNBur0uOafeMaX/IpdIxyiI7Z86xj/4ES7HL8RiAaRgL5dU lHhwH3XUMc9SGsuh07umkpIpsxs6xs+THCH4lUCkapriNtlIvYoGHSkKm/SOTx7EzjM5YA 3OPpUXkpzFE4BzqRWYetDaPablhNcPo= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=gP6Ft9YJ; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf11.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1692634153; 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=J/PlBgSOglEnVLTJqu2zbMYsJDvOn/SB34qHQ+lZyNk=; b=HlKrRyAgK0yAJu2xfNDQxmDDZ4aOcGdUg4/B4PFLVwf0iuduL43blJNz0LA2VutC91gYnO OT6oKLdoATaifzViW2tI6xdFMkffeaOkwLFVl9mEedP31Ls4n2FoCFen8s2bEivUkJhk1S UpE/xSGZL2Oo8KyQCvJ3lsHyRURYrPw= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1692634152; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=J/PlBgSOglEnVLTJqu2zbMYsJDvOn/SB34qHQ+lZyNk=; b=gP6Ft9YJ0vVj1169p7RdODEkACqQ6fb1lUmjqbzc5Bf6Uv+/gWA/2UU/NVwy/13yHenr2N to8ei6q5zAv9gItA8atSHTKNkrMYggDmY/OEtcj1UFY8jetnhJxoZQIkbz4leAR4B+KFaI emg2B5tFos25WPJFOJ3Dr/5JANFzz7U= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-211-Afa7N3q2MaOpDmVf2OHBqA-1; Mon, 21 Aug 2023 12:09:09 -0400 X-MC-Unique: Afa7N3q2MaOpDmVf2OHBqA-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 67DB9858EED; Mon, 21 Aug 2023 16:09:08 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.39.192.184]) by smtp.corp.redhat.com (Postfix) with ESMTP id 219E8492C13; Mon, 21 Aug 2023 16:09:02 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, David Hildenbrand , Andrew Morton , Matthew Wilcox , Peter Xu , Catalin Marinas , Will Deacon , Hugh Dickins , Seth Jennings , Dan Streetman , Vitaly Wool Subject: [PATCH mm-unstable v1 4/4] mm/huge_memory: work on folio->swap instead of page->private when splitting folio Date: Mon, 21 Aug 2023 18:08:49 +0200 Message-ID: <20230821160849.531668-5-david@redhat.com> In-Reply-To: <20230821160849.531668-1-david@redhat.com> References: <20230821160849.531668-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 5614C4002B X-Stat-Signature: 3a8ug3q7njqjzaj8g3feunt8pzc9apka X-HE-Tag: 1692634153-647751 X-HE-Meta: U2FsdGVkX1+PlJAN5vhnfZR920YFQAlNEUs7c8Qw1faR5/PDPaSC3i1EkdmsLPzY6e2wgUasrozMKpf3XeoiR6SaE0+xyaSxSnJHMxvaPBykNIkKXWWsEzi6sFkznJS8eVsv5wfhh3MeMFM7QDCgnYApmSmbINv5KQe7JD5gDCJeTFkKeYFU0NhpNEhY/asBlVDlP+NnKhNkcSPEQBMfltC3A1GkvTNHIVRgGs7bGVc+hBPlPBbdRq1KUwFx2pR5qrJrvBXIEqSxfylHMs8mkrVJumtUmeNH/KazUlnJI5p81TM4CKQa/mt4NsRTNMlydV0bALopRBAuSLxO/mJuXq+XJaxGVu3V86E6+uQI/YUD7TzMGify6IzmdkCsQOd7ensx+k4FpNKSB9ApGaRPHtRx1E1SNyd+y2ZuX++P2703rRHXmLugxv9vrZnJSvYe37YdioNuLRHKe2WuGROLetkxctEIQ+bBmEATa0k+MtReFnD53RI3ccgiPStrLhvS2R0+L6ork7XJ7+TJWtWLqNEnIJxy2+W7SrLOlb2R7mAzMBW9TW9mAwOpwOb3QjruoxosRG9njJe0iAeTGck5MnJ4oGODrE6xSdHmsVDXSrQr6eft7ZwM0b5hnVq6T2JQu7EhILtwVrSh4rWzBrW3oWnePUZ6gCyEwgRbLGMdHFEV1GTTgTzp175t7/LqTcAb+0N3zBwByPDO9NVuZnPERxQet6KvhG/UJaXh1FYFc6vdxM9SHQ321Z/skeVH4iXweXi0Se63FwoNUobCpbvo3vWINyoQbvD5LEENbAOM6fFnoE9PJ1RDcev5XZQrdlKvZns8H3igj5qUru/s2Kk/S+G+PcxUxKjgj5S1qZrzvXC6OTFJ6hiRj11ueFNqCt3wUQKQh4MyJFSmnMklTdLWnrGUqB5/TpgeOdyJgcSjI1gRZAeUEc07i76Tz/6gZ8FkNXY/+XdPhGte1XaW1IR oqk6IS6i YJhpgGAEnvfCeDpk06rIE+Do3yWCuuad5ao+ZTUghz+yMK2Qe7zWR0wm/rc+6d0nfY0i5o76Pp/ofAWUrjfdneVI3gpeHWP61NpvsjqJJ6X5r5ZEpN3Rj23sLPSCF3F0Bl4qtuBin+nfiGQMRO5djEQksaiSuKrfG7ABoZBIFRZdpgG0x9ay0Vnt4JQDVSyHqCS0tMJ5QokauzND5ySHFA2pbcfWbygeM0FTi 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: Let's work on folio->swap instead. While at it, use folio_test_anon() and folio_test_swapcache() -- the original folio remains valid even after splitting (but is then an order-0 folio). We can probably convert a lot more to folios in that code, let's focus on folio->swap handling only for now. Signed-off-by: David Hildenbrand Reviewed-by: Chris Li --- mm/huge_memory.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index c04702ae71d2..4465915711c3 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2401,10 +2401,16 @@ static void lru_add_page_tail(struct page *head, struct page *tail, } } -static void __split_huge_page_tail(struct page *head, int tail, +static void __split_huge_page_tail(struct folio *folio, int tail, struct lruvec *lruvec, struct list_head *list) { + struct page *head = &folio->page; struct page *page_tail = head + tail; + /* + * Careful: new_folio is not a "real" folio before we cleared PageTail. + * Don't pass it around before clear_compound_head(). + */ + struct folio *new_folio = (struct folio *)page_tail; VM_BUG_ON_PAGE(atomic_read(&page_tail->_mapcount) != -1, page_tail); @@ -2453,8 +2459,8 @@ static void __split_huge_page_tail(struct page *head, int tail, VM_WARN_ON_ONCE_PAGE(true, page_tail); page_tail->private = 0; } - if (PageSwapCache(head)) - set_page_private(page_tail, (unsigned long)head->private + tail); + if (folio_test_swapcache(folio)) + new_folio->swap.val = folio->swap.val + tail; /* Page flags must be visible before we make the page non-compound. */ smp_wmb(); @@ -2500,11 +2506,9 @@ static void __split_huge_page(struct page *page, struct list_head *list, /* complete memcg works before add pages to LRU */ split_page_memcg(head, nr); - if (PageAnon(head) && PageSwapCache(head)) { - swp_entry_t entry = { .val = page_private(head) }; - - offset = swp_offset(entry); - swap_cache = swap_address_space(entry); + if (folio_test_anon(folio) && folio_test_swapcache(folio)) { + offset = swp_offset(folio->swap); + swap_cache = swap_address_space(folio->swap); xa_lock(&swap_cache->i_pages); } @@ -2514,7 +2518,7 @@ static void __split_huge_page(struct page *page, struct list_head *list, ClearPageHasHWPoisoned(head); for (i = nr - 1; i >= 1; i--) { - __split_huge_page_tail(head, i, lruvec, list); + __split_huge_page_tail(folio, i, lruvec, list); /* Some pages can be beyond EOF: drop them from page cache */ if (head[i].index >= end) { struct folio *tail = page_folio(head + i); @@ -2559,11 +2563,8 @@ static void __split_huge_page(struct page *page, struct list_head *list, remap_page(folio, nr); - if (PageSwapCache(head)) { - swp_entry_t entry = { .val = page_private(head) }; - - split_swap_cluster(entry); - } + if (folio_test_swapcache(folio)) + split_swap_cluster(folio->swap); for (i = 0; i < nr; i++) { struct page *subpage = head + i;