Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp1104557rdh; Fri, 24 Nov 2023 05:28:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IEJj05JXrZtXhuEtJqiFtgx4fXILuSFDBnL2F0+VD6ZhDqvsEjsZtBt0FtNhhTqDCYxf46A X-Received: by 2002:a05:6a21:a5a0:b0:17a:4871:63fd with SMTP id gd32-20020a056a21a5a000b0017a487163fdmr4364204pzc.0.1700832536271; Fri, 24 Nov 2023 05:28:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700832536; cv=none; d=google.com; s=arc-20160816; b=lpgWZZJbWImJR6HImixSuddX1+N+5aKGEQ0ffRI3XNkvEeA+MkJ6tES2FeYlSgFVa2 EuuydVpqSLvwBtZ0iDObOVnvlTFQiVYh68aJK2P68REh6cQXKGLXe33/v9DmaTf+mgxw 3ve56HIa0qSi/7RHjfsIKCkyDZlB0E5l2VzeCybCrP+YZZfNKTL51NBhBlFA7CLpEqzB waMlihVCsfXPxET7fUGD/NeOLwPWg4SJ1ksQHSJqvGipdaz4m9EZHI9TDrBS2ubGSawX IxiXN5ddYXAtXlRyq/vMMMjR5JGvC6emqaOGwEiUBAIfM5qRMrj8Zuw38xrB+n+TZZBU fvmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=vCiq1mHEXhReKPGNK7ma5q/JWzLE5up94nYDqOWMaw0=; fh=UVV9UP3jB+jR+DJP/Pn6IwXb1P9vDh5E3FRL6G+mlkU=; b=fs5nUznSp5YtUUlEUcJCJY3y/aWk0KVgeqUAcIflg0wzXVk5Q8tP3D/z9VG+cOP80r SdjvmW2gi6C1wpooym+sB4af1jkYTl08TuY1+MGR0WHvBF+QyRm7gKQN6rFZ9NTw4oKA KRacAtl3Vzz464SA6nXabDlnoaO7fFpcwgKZmum7VWnEfgvQfK2vaS1ReerztLNGKMHW /aPRWhDfPgq86qsm3pHstC0spwoB2i4pWp/30NjSoI8UQuga9tZgi0bNNWRLoGqkStl0 nhWmSzx9rOCD2RPA0ziTa/ST+Y2RRk938Vce6z2FnWyf6h1tHGlhnaqylQAG5R0MtQdJ NIDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=KMtMf+7d; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id 4-20020a630a04000000b005c14fc66ccasi3459335pgk.370.2023.11.24.05.28.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Nov 2023 05:28:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=KMtMf+7d; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id B32E881825D2; Fri, 24 Nov 2023 05:28:53 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345366AbjKXN2Y (ORCPT + 99 others); Fri, 24 Nov 2023 08:28:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231172AbjKXN1r (ORCPT ); Fri, 24 Nov 2023 08:27:47 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0CB1E1FD5 for ; Fri, 24 Nov 2023 05:27:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700832443; 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=vCiq1mHEXhReKPGNK7ma5q/JWzLE5up94nYDqOWMaw0=; b=KMtMf+7dmBRtjbwxbYQXOrYTQcwZiZJDTFkfqfBZDVirfeYkN8AH/PvV7p0IXhMRq4/keh bYPgAC+g3Q580Km9kmZK6U8f8eP8GSYKjt1GZ0kjLjD9w//Bl75M7BQoShXl0h6+1VUUjC Q20c2Ym3edm/eG74EUt849f10Tw5pJc= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-654-EfryieQzPKuzYd766I-Umw-1; Fri, 24 Nov 2023 08:27:19 -0500 X-MC-Unique: EfryieQzPKuzYd766I-Umw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 805CE1C05142; Fri, 24 Nov 2023 13:27:18 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.39.194.71]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0717E2166B2A; Fri, 24 Nov 2023 13:27:14 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, David Hildenbrand , Andrew Morton , Linus Torvalds , Ryan Roberts , Matthew Wilcox , Hugh Dickins , Yin Fengwei , Yang Shi , Ying Huang , Zi Yan , Peter Zijlstra , Ingo Molnar , Will Deacon , Waiman Long , "Paul E. McKenney" Subject: [PATCH WIP v1 13/20] mm/huge_memory: batch rmap operations in __split_huge_pmd_locked() Date: Fri, 24 Nov 2023 14:26:18 +0100 Message-ID: <20231124132626.235350-14-david@redhat.com> In-Reply-To: <20231124132626.235350-1-david@redhat.com> References: <20231124132626.235350-1-david@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Fri, 24 Nov 2023 05:28:53 -0800 (PST) Let's batch the rmap operations, as a preparation to making individual page_add_anon_rmap() calls more expensive. While at it, use more folio operations (but only in the code branch we're touching), use VM_WARN_ON_FOLIO(), and pass RMAP_COMPOUND instead of manually setting PageAnonExclusive. We should never see non-anon pages on that branch: otherwise, the existing page_add_anon_rmap() call would have been flawed already. Signed-off-by: David Hildenbrand --- mm/huge_memory.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index fd7251923557..f47971d1afbf 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2100,6 +2100,7 @@ static void __split_huge_pmd_locked(struct vm_area_struct *vma, pmd_t *pmd, unsigned long haddr, bool freeze) { struct mm_struct *mm = vma->vm_mm; + struct folio *folio; struct page *page; pgtable_t pgtable; pmd_t old_pmd, _pmd; @@ -2195,16 +2196,18 @@ static void __split_huge_pmd_locked(struct vm_area_struct *vma, pmd_t *pmd, uffd_wp = pmd_swp_uffd_wp(old_pmd); } else { page = pmd_page(old_pmd); + folio = page_folio(page); if (pmd_dirty(old_pmd)) { dirty = true; - SetPageDirty(page); + folio_set_dirty(folio); } write = pmd_write(old_pmd); young = pmd_young(old_pmd); soft_dirty = pmd_soft_dirty(old_pmd); uffd_wp = pmd_uffd_wp(old_pmd); - VM_BUG_ON_PAGE(!page_count(page), page); + VM_WARN_ON_FOLIO(!folio_ref_count(folio), folio); + VM_WARN_ON_FOLIO(!folio_test_anon(folio), folio); /* * Without "freeze", we'll simply split the PMD, propagating the @@ -2221,11 +2224,18 @@ static void __split_huge_pmd_locked(struct vm_area_struct *vma, pmd_t *pmd, * * See page_try_share_anon_rmap(): invalidate PMD first. */ - anon_exclusive = PageAnon(page) && PageAnonExclusive(page); + anon_exclusive = PageAnonExclusive(page); if (freeze && anon_exclusive && page_try_share_anon_rmap(page)) freeze = false; - if (!freeze) - page_ref_add(page, HPAGE_PMD_NR - 1); + if (!freeze) { + rmap_t rmap_flags = RMAP_NONE; + + folio_ref_add(folio, HPAGE_PMD_NR - 1); + if (anon_exclusive) + rmap_flags = RMAP_EXCLUSIVE; + folio_add_anon_rmap_range(folio, page, HPAGE_PMD_NR, + vma, haddr, rmap_flags); + } } /* @@ -2268,8 +2278,6 @@ static void __split_huge_pmd_locked(struct vm_area_struct *vma, pmd_t *pmd, entry = mk_pte(page + i, READ_ONCE(vma->vm_page_prot)); if (write) entry = pte_mkwrite(entry, vma); - if (anon_exclusive) - SetPageAnonExclusive(page + i); if (!young) entry = pte_mkold(entry); /* NOTE: this may set soft-dirty too on some archs */ @@ -2279,7 +2287,6 @@ static void __split_huge_pmd_locked(struct vm_area_struct *vma, pmd_t *pmd, entry = pte_mksoft_dirty(entry); if (uffd_wp) entry = pte_mkuffd_wp(entry); - page_add_anon_rmap(page + i, vma, addr, RMAP_NONE); } VM_BUG_ON(!pte_none(ptep_get(pte))); set_pte_at(mm, addr, pte, entry); -- 2.41.0