From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 70404346E56 for ; Mon, 6 Jul 2026 15:44:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783352667; cv=none; b=hcOnPEOiWv3wVWLQDIEkrxqlAKXSgDUsUmoUxOl1grtvDv41JQcv+mmMSj/aheUIAeRXcPVeZ/NM6bE5UUsavMjlerTCUGbZoRB+0gX7rrAXXSvw3mYbptPTg0GZWMEliXvun/wL0VAjkH/tkOBU/mxH33LhODWlxMAreVitYJ4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783352667; c=relaxed/simple; bh=7/kw+AzJQKuBUjqhS2bAXm4UrK/nLXxNNckGtYgO8Kw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Hz6TkXL7sMzt6nES0NLneCdx53oC0xvyu6vGoEHDSGmqvP5xj0fBSzdzpdFqDxm0FTPeu43NRajFFe3ujqCr1CSua0OT85Qy+WlanIpT6lSLYkSbNy/Mvy26n9MbNIDgFqs9v1gFcE5HBAyeR/vni2Z3Y9a/3TlVh/GOxFHO9tM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=PxFV4+/D; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="PxFV4+/D" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1783352665; 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=QtCuXPTs/0xQBoZ84al1coYi4yVh7/txmWENN/pYDxo=; b=PxFV4+/D/5eiW8o2c73vTn9tIJ/iBgRSUBnoCXtOOBxNCrLF7eJQB8lwiQBvIobRcccY3A L2YfAPcxTPRT6DxPsGahnBn4RMlHpr0DIAneSzH6OLCygz/mSFjMIRq8J89UYrh6s7NxxM AMNwSBaIcLFxzrAkCounbTI81GE34J8= Received: from mx-prod-mc-03.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-594-C_KETv4KPaWgJSJjxJTPfw-1; Mon, 06 Jul 2026 11:44:22 -0400 X-MC-Unique: C_KETv4KPaWgJSJjxJTPfw-1 X-Mimecast-MFC-AGG-ID: C_KETv4KPaWgJSJjxJTPfw_1783352659 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D5DAE1955E7E; Mon, 6 Jul 2026 15:44:18 +0000 (UTC) Received: from p1.redhat.com (unknown [10.22.58.4]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 1A314195604E; Mon, 6 Jul 2026 15:44:08 +0000 (UTC) From: Nico Pache To: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Nico Pache , Andrew Morton , David Hildenbrand , Lorenzo Stoakes , Zi Yan , Baolin Wang , "Liam R. Howlett" , Ryan Roberts , Dev Jain , Barry Song , Lance Yang , Usama Arif , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Jonathan Corbet , Shuah Khan Subject: [PATCH 1/8] mm/khugepaged: refactor per-scan state clearing into collapse_control_init_scan() Date: Mon, 6 Jul 2026 09:44:48 -0600 Message-ID: <20260706154500.39178-2-npache@redhat.com> In-Reply-To: <20260706154500.39178-1-npache@redhat.com> References: <20260706154500.39178-1-npache@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Extract the repeated clearing of node_load, alloc_nmask, and mthp_present_ptes into a helper to reduce duplication in collapse_scan_pmd() and collapse_scan_file(). Althought file scans do not current use the bitmap, they will in the future, and clearing it now is harmless. Signed-off-by: Nico Pache --- mm/khugepaged.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 617bca76db49..b3985b854e77 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -628,6 +628,17 @@ void __khugepaged_exit(struct mm_struct *mm) } } +/* + * collapse_control_init_scan() - initialize/reset collapse_control variables + * that require being cleared once per-scan. + */ +static void collapse_control_init_scan(struct collapse_control *cc) +{ + memset(cc->node_load, 0, sizeof(cc->node_load)); + nodes_clear(cc->alloc_nmask); + bitmap_zero(cc->mthp_present_ptes, MAX_PTRS_PER_PTE); +} + static void release_pte_folio(struct folio *folio) { node_stat_mod_folio(folio, @@ -1616,9 +1627,7 @@ static enum scan_result collapse_scan_pmd(struct mm_struct *mm, goto out; } - bitmap_zero(cc->mthp_present_ptes, MAX_PTRS_PER_PTE); - memset(cc->node_load, 0, sizeof(cc->node_load)); - nodes_clear(cc->alloc_nmask); + collapse_control_init_scan(cc); enabled_orders = collapse_possible_orders(vma, vma->vm_flags, tva_flags); @@ -2686,8 +2695,7 @@ static enum scan_result collapse_scan_file(struct mm_struct *mm, present = 0; swap = 0; - memset(cc->node_load, 0, sizeof(cc->node_load)); - nodes_clear(cc->alloc_nmask); + collapse_control_init_scan(cc); rcu_read_lock(); xas_for_each(&xas, folio, start + HPAGE_PMD_NR - 1) { if (xas_retry(&xas, folio)) -- 2.54.0