From patchwork Wed Jan 8 23:31:23 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nico Pache X-Patchwork-Id: 13931717 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 64744E7719A for ; Wed, 8 Jan 2025 23:34:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EE9B76B009A; Wed, 8 Jan 2025 18:34:04 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E73486B009B; Wed, 8 Jan 2025 18:34:04 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C9D746B009C; Wed, 8 Jan 2025 18:34:04 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id A812E6B009A for ; Wed, 8 Jan 2025 18:34:04 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 696B7141371 for ; Wed, 8 Jan 2025 23:34:04 +0000 (UTC) X-FDA: 82985890008.20.3F23BE2 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf24.hostedemail.com (Postfix) with ESMTP id B3168180012 for ; Wed, 8 Jan 2025 23:34:02 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=TXVSVi90; spf=pass (imf24.hostedemail.com: domain of npache@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=npache@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=1736379242; 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=NlWBk/L/IkPkjBErBKE0II3MThdDUOorzPsxzF/l62g=; b=VrlTPiUB0ziWBTCTox6YmGE+bDThT1mYO4AGOYh/uDGF4kM2Et3E5iAw8Rbn74k0YyYD+p 9n1g/KZtQq/lx3uWFF4/7DxWi2JYGVWySQ1zuDZg7Ilec0a5/KmATzWPdVUsZoEFtx1pFN FQ44WSh6m1I3zMtfpEN7mLJDU5BNWeQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736379242; a=rsa-sha256; cv=none; b=ucumnwYj/SKzi9RdF4YineMZ0fcScUrGe4ctas+VbVCguXpv56nv04VnGZf5duIoYSzJUs euaKWkDZLIH/hyes2xEjc+i5SpilGc0/LtynrEoh8GFYWW+HxDC7FwT7v6xg4naclB7f26 vw5IaCuuz/+JfDkbXdmJwgPiiPvtlcE= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=TXVSVi90; spf=pass (imf24.hostedemail.com: domain of npache@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=npache@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=1736379242; 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=NlWBk/L/IkPkjBErBKE0II3MThdDUOorzPsxzF/l62g=; b=TXVSVi906bcJJn/s7foZhiwPJKYi1GcTtgfXdEDFi3mY4rGv0FhXRrw1gSecyoz7nbBg6p SX0APVpnpMW0gBBsoBoqyFvn0DGtmyvMRZvF5FTvFg0esALWvFQTaQbYjEseFZO30HP6cq lCYEIshxcSMuiImB5KL+qhuCh3oB6dk= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-529-f2Ks21HyPQGtWMlhN9XdfA-1; Wed, 08 Jan 2025 18:34:00 -0500 X-MC-Unique: f2Ks21HyPQGtWMlhN9XdfA-1 X-Mimecast-MFC-AGG-ID: f2Ks21HyPQGtWMlhN9XdfA Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (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 mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id BCE641956083; Wed, 8 Jan 2025 23:33:56 +0000 (UTC) Received: from h1.redhat.com (unknown [10.22.80.41]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 92A9019560AE; Wed, 8 Jan 2025 23:33:48 +0000 (UTC) From: Nico Pache To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: ryan.roberts@arm.com, anshuman.khandual@arm.com, catalin.marinas@arm.com, cl@gentwo.org, vbabka@suse.cz, mhocko@suse.com, apopple@nvidia.com, dave.hansen@linux.intel.com, will@kernel.org, baohua@kernel.org, jack@suse.cz, srivatsa@csail.mit.edu, haowenchao22@gmail.com, hughd@google.com, aneesh.kumar@kernel.org, yang@os.amperecomputing.com, peterx@redhat.com, ioworker0@gmail.com, wangkefeng.wang@huawei.com, ziy@nvidia.com, jglisse@google.com, surenb@google.com, vishal.moola@gmail.com, zokeefe@google.com, zhengqi.arch@bytedance.com, jhubbard@nvidia.com, 21cnbao@gmail.com, willy@infradead.org, kirill.shutemov@linux.intel.com, david@redhat.com, aarcange@redhat.com, raquini@redhat.com, dev.jain@arm.com, sunnanyong@huawei.com, usamaarif642@gmail.com, audra@redhat.com, akpm@linux-foundation.org Subject: [RFC 07/11] khugepaged: generalize __collapse_huge_page_* for mTHP support Date: Wed, 8 Jan 2025 16:31:23 -0700 Message-ID: <20250108233128.14484-8-npache@redhat.com> In-Reply-To: <20250108233128.14484-1-npache@redhat.com> References: <20250108233128.14484-1-npache@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: B3168180012 X-Stat-Signature: r3fa83zkqwnmkc9ca7scyoe6kg7gog6d X-Rspam-User: X-HE-Tag: 1736379242-368473 X-HE-Meta: U2FsdGVkX181mLcM2WDwaA1zkjPGpWy8vZD7S9fpVLf0sN9dYlHmcY++e5elxWJO9UBjygNbclGZDMNIuPQRNnr64A9k9uydBDvr4VdI+hVcd42EVT8t8ZQDzhADn4iJEN49AQVw0Q7i+W1wXD5KZtp9NXEQRSoGOq4gpB21QV4u/FijiXryR7G2pIZwID3ss57acTVCgXrP3kKGxHbz19Rb3tjRkOWObvrBiub0U8hpo2Sgrah1nY7aJ6CZpf4VhunDFKtJf+32GRpHw2K4QqcjBETpz7V16lf5pp0VvDE68ZP5KpVt8V8zN+PpYyWazGppt7P4mha6SDVhjnR3u9azegbUr3CfQeAeqyhhnchWQOijTujwvo8jTfvPPmvusL27vSeD45NRch776Kg4eEuYm7uAcsT1u+z7avrIyVDD/6eQA00gXXtBID7NimLMHLz4GczG0YQ0yYGjHImw8Fdvv+tMdmc19TFqis/etlmvcWJqES9RSYQRxJz54EveU5BHB01UH055ahoAIHg0BmQP+1NS4QiMQpFE0M9hBrsW1adlZwKcNy1HAmor2DivszYJUhNqFopRtO3sAwszqLOmDMOE/1WqCvbnNI/t3CtScbaRaWteDMrI0Zb34cWzZnb7tjm6psqLzPXbr2t9SqYI/Gdg7bJB67stbvvAfpwJI5rlXcA7CiMCCAMFTOF0aqN2HjuzpY8vkl+HaZTGmjjVK3oFkzNq0anyIZULO8xOyXIhzgmEmR7gozSrjaHH3hJGbuT6gQ7W1DVHv98jprCHzw3ZqlVPQWM5SUh/KgGMRd9i6EJSsbYpir0giDUkyp+mS4CXhDQOQvkGveeWR0CCw+2uZV1lKXF7J3D+LU4w5CNUfA1wX5kNSBiz803qLD67CXV2xbi4uFgNWbnswOjiYgej2+0F0u5t2nn4mXCVFSsPj0kThsKwLWOCFIHHnb5EzxIlHL1DvC/NISt 8MhWVrsf ht7IMDBdTgOB5CVetsD8uABQni26ot73UvdGk/RWBgPvTY53KTnJ07q+7V7XAhK5PuTuv5/MYv/hk1tjEpNZvovOPEsH+kCRuxFZuDq8QXOmPn8f1evOUYaYcGfp/VtDMM0A5AZ2KW4AgBv3yobLchHTUSBCV+OPQ5uwEVxaF+DIS2Jm1vEWAIq9Xi/44C+QY8EZg2nws51uui81xjpyYOXaeFbNdp+JNCNbG8Ar4wCn+Jo1OG/mH8apy2JZjl/sHPtRsmHSeaUwSFeWnY8wh/r++7o58QyODaFgUSW/BBj3t7AL1C5ZTCTC/2PbxF5dHwGC5g3DqMpVGRNJDtnkD9e6DtT26MOx5xsNv6cCxubv6uvNABF8drfyGhAY5766usxHpdhklGEKHKZJ+vLZigDuZUe+tRT809LzqH3VPo8RhdEvO/IX5OIStLtT9CQzEoEwo 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: generalize the order of the __collapse_huge_page_* functions to support future mTHP collapse. No functional changes in this patch. Signed-off-by: Nico Pache --- mm/khugepaged.c | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 6daf3a943a1a..9eb161b04ee4 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -565,7 +565,8 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma, unsigned long address, pte_t *pte, struct collapse_control *cc, - struct list_head *compound_pagelist) + struct list_head *compound_pagelist, + u8 order) { struct page *page = NULL; struct folio *folio = NULL; @@ -573,7 +574,7 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma, int none_or_zero = 0, shared = 0, result = SCAN_FAIL, referenced = 0; bool writable = false; - for (_pte = pte; _pte < pte + HPAGE_PMD_NR; + for (_pte = pte; _pte < pte + (1 << order); _pte++, address += PAGE_SIZE) { pte_t pteval = ptep_get(_pte); if (pte_none(pteval) || (pte_present(pteval) && @@ -711,14 +712,15 @@ static void __collapse_huge_page_copy_succeeded(pte_t *pte, struct vm_area_struct *vma, unsigned long address, spinlock_t *ptl, - struct list_head *compound_pagelist) + struct list_head *compound_pagelist, + u8 order) { struct folio *src, *tmp; pte_t *_pte; pte_t pteval; - for (_pte = pte; _pte < pte + HPAGE_PMD_NR; - _pte++, address += PAGE_SIZE) { + for (_pte = pte; _pte < pte + (1 << order); + _pte++, address += PAGE_SIZE) { pteval = ptep_get(_pte); if (pte_none(pteval) || is_zero_pfn(pte_pfn(pteval))) { add_mm_counter(vma->vm_mm, MM_ANONPAGES, 1); @@ -764,7 +766,8 @@ static void __collapse_huge_page_copy_failed(pte_t *pte, pmd_t *pmd, pmd_t orig_pmd, struct vm_area_struct *vma, - struct list_head *compound_pagelist) + struct list_head *compound_pagelist, + u8 order) { spinlock_t *pmd_ptl; @@ -781,7 +784,7 @@ static void __collapse_huge_page_copy_failed(pte_t *pte, * Release both raw and compound pages isolated * in __collapse_huge_page_isolate. */ - release_pte_pages(pte, pte + HPAGE_PMD_NR, compound_pagelist); + release_pte_pages(pte, pte + (1 << order), compound_pagelist); } /* @@ -802,7 +805,7 @@ static void __collapse_huge_page_copy_failed(pte_t *pte, static int __collapse_huge_page_copy(pte_t *pte, struct folio *folio, pmd_t *pmd, pmd_t orig_pmd, struct vm_area_struct *vma, unsigned long address, spinlock_t *ptl, - struct list_head *compound_pagelist) + struct list_head *compound_pagelist, u8 order) { unsigned int i; int result = SCAN_SUCCEED; @@ -810,7 +813,7 @@ static int __collapse_huge_page_copy(pte_t *pte, struct folio *folio, /* * Copying pages' contents is subject to memory poison at any iteration. */ - for (i = 0; i < HPAGE_PMD_NR; i++) { + for (i = 0; i < (1 << order); i++) { pte_t pteval = ptep_get(pte + i); struct page *page = folio_page(folio, i); unsigned long src_addr = address + i * PAGE_SIZE; @@ -829,10 +832,10 @@ static int __collapse_huge_page_copy(pte_t *pte, struct folio *folio, if (likely(result == SCAN_SUCCEED)) __collapse_huge_page_copy_succeeded(pte, vma, address, ptl, - compound_pagelist); + compound_pagelist, order); else __collapse_huge_page_copy_failed(pte, pmd, orig_pmd, vma, - compound_pagelist); + compound_pagelist, order); return result; } @@ -996,11 +999,11 @@ static int check_pmd_still_valid(struct mm_struct *mm, static int __collapse_huge_page_swapin(struct mm_struct *mm, struct vm_area_struct *vma, unsigned long haddr, pmd_t *pmd, - int referenced) + int referenced, u8 order) { int swapped_in = 0; vm_fault_t ret = 0; - unsigned long address, end = haddr + (HPAGE_PMD_NR * PAGE_SIZE); + unsigned long address, end = haddr + ((1 << order) * PAGE_SIZE); int result; pte_t *pte = NULL; spinlock_t *ptl; @@ -1110,7 +1113,6 @@ static int collapse_huge_page(struct mm_struct *mm, unsigned long address, int result = SCAN_FAIL; struct vm_area_struct *vma; struct mmu_notifier_range range; - VM_BUG_ON(address & ~HPAGE_PMD_MASK); /* @@ -1145,7 +1147,7 @@ static int collapse_huge_page(struct mm_struct *mm, unsigned long address, * that case. Continuing to collapse causes inconsistency. */ result = __collapse_huge_page_swapin(mm, vma, address, pmd, - referenced); + referenced, HPAGE_PMD_ORDER); if (result != SCAN_SUCCEED) goto out_nolock; } @@ -1192,7 +1194,7 @@ static int collapse_huge_page(struct mm_struct *mm, unsigned long address, pte = pte_offset_map_lock(mm, &_pmd, address, &pte_ptl); if (pte) { result = __collapse_huge_page_isolate(vma, address, pte, cc, - &compound_pagelist); + &compound_pagelist, HPAGE_PMD_ORDER); spin_unlock(pte_ptl); } else { result = SCAN_PMD_NULL; @@ -1222,7 +1224,7 @@ static int collapse_huge_page(struct mm_struct *mm, unsigned long address, result = __collapse_huge_page_copy(pte, folio, pmd, _pmd, vma, address, pte_ptl, - &compound_pagelist); + &compound_pagelist, HPAGE_PMD_ORDER); pte_unmap(pte); if (unlikely(result != SCAN_SUCCEED)) goto out_up_write;