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 5BF6F3B8939 for ; Wed, 15 Jul 2026 05:57:43 +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=1784095067; cv=none; b=sGBpIa6FuGZePHeqW37T+RP5KPUFVB8ovdCYOojDOCUu8P0kd9qkyt78O3+OBFjydSn+GX0F+vAeE5Pcodu7FDbY6hmNrjitKo/BN4O36mjwaIRWPfgP1D6uhYZIImDB7QP+CiF3F8VmQDdZHPpueHdEc4OZCmU87cX8FIUpj5M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784095067; c=relaxed/simple; bh=AxhU404+8gisR0wepl2FexLZ8ri4j5Bdrr52h4XBFUQ=; h=Message-ID:Date:MIME-Version:From:Subject:To:Cc:References: In-Reply-To:Content-Type; b=IV3QXXhtFum5p2xjihfFpp7yvno55TUVjXrbLa8uaqpIlpzX72pe/g15aJ9tclBPTS3YvjVekm9bi7cHmcLS9zEA2NAjYrlL0qnZcXfHVr3MWzVAn06mNyVvmMtHXeL4wGmJFhZaK1PE8M2Pq1lJnkhAh+SskKdQXcJ/IwE8hc0= 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=R+SES0MY; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=X7z/9uMV; 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="R+SES0MY"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="X7z/9uMV" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1784095062; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kij3xGA0X8XYDtppR8rZ3L/GKbMGs4DT7boZ6eQOym8=; b=R+SES0MYgvToyIBH4hwVbAlG/dI5S0T/jxMw2ytmUkE2H9VOXSVi0mRKecR0Pm1KDo3rgh OYiEw7Pf7KmQG2W767wz+lL8Ls452vdspEJX/nnRNQjm/Vz4Mj8z6KssowBr1+A6Ozh1hp lhqVJEHhVJAIZKyTQoW/aZCdtnEjuLU= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-676-skrY9iHxNFiu6LgWgpZnrA-1; Wed, 15 Jul 2026 01:57:39 -0400 X-MC-Unique: skrY9iHxNFiu6LgWgpZnrA-1 X-Mimecast-MFC-AGG-ID: skrY9iHxNFiu6LgWgpZnrA_1784095059 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-92ac0a54110so821451585a.2 for ; Tue, 14 Jul 2026 22:57:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1784095059; x=1784699859; darn=vger.kernel.org; h=content-transfer-encoding:content-type:in-reply-to:content-language :references:cc:to:subject:from:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to:content-type; bh=kij3xGA0X8XYDtppR8rZ3L/GKbMGs4DT7boZ6eQOym8=; b=X7z/9uMVS7jRbizOFyHqsYXZ1OXwFdfzTKR/5ih3Cuz4vha0/M/McSzypPnPG7Ygyc szvoXTCgmJGqNMA+XfRpzwwlbBWFiVrRjXFeAnxX5v0XtWZT92KOAjFdK9lHqdLCDLpd wFE6S7bOJpzHAOkVGnzTCAbh6O/QtRfopyx4+7jL+VUtKDkBVnwVZQumFbo2TOUC/FOM xhHfnz52z0YyJcsb01E/MDawr6swpUYX3BFZTjfg7dPMLImJdt9MnxG5Ci9AcunMpLFj qblxXwKssQRt99E5PB+5SCgpBoH65/FfXG7gFJIv54maEboYpUcc4VT2c50Bna1+/EER SHVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784095059; x=1784699859; h=content-transfer-encoding:content-type:in-reply-to:content-language :references:cc:to:subject:from:user-agent:mime-version:date :message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=kij3xGA0X8XYDtppR8rZ3L/GKbMGs4DT7boZ6eQOym8=; b=AdvCUVlkQhhePzqtO9InuzYPe6kLzx1KaSEvmY54H9RV75XnEFpZwp+rQoO6jKt3Am oLs3FcKjs5IPgRGrRjgHQejkuH9mvTje4X09obGVLCeBQYSUvbM3swEY5fsTX/8SzcFU VuM4j8QjsB3hHcc92WPMeg7C48eYPf8IE+Yf5zSzTxqxoNu1Vhl9pyLexEsWzTI7ozbA YRDNYPSsyl3Oh6/N8GRSH6YVABq50y9QNlE9SCmjhWmxP86jLj2I6RxesGUc11GZJ63Z ef1vFuDRwcLqwXgR4lwntHtZFD7gw/noWBFxUEVgz5eziLI0M+4O5jZH9y5sdTx+i3WK BZXg== X-Forwarded-Encrypted: i=1; AHgh+Ro1kh+XJxcOv2oi0f3s8JMOgw0Fd1oCMtTbpt+3r9PrwVwxIYSdDltdAHeoHPHqDM5QpYos6UD45RfBOEE=@vger.kernel.org X-Gm-Message-State: AOJu0YwwQyC/ENDkDGWsBLijS/UQ6Oy3F9KODXw1NddL600e0yZOzqMw T+cjknEB1ix6JTfpgVvWKx5c8ioI8fc3F14X1si2sYlbU6jeWDatK2l/yXGP27zG9MevdzSC8rj 0qJohH13oNEyJoxcKQsAEdEjBBiWb1azBOTtCSoc85GR8YcN0oVSglQSi8A6884MKMw== X-Gm-Gg: AfdE7ckDMSwLT9vl0cRGMbm68qQQuADSWDe1bxkPhu+kFGvvp+pPY/6XvB4u/aMcguZ 2oZmft9ieVmsmac0pVMuF8N5NXTeQriFP1zVr6E27Vvs/Jk2ukiBOYgljsOoxZ2X8XIsJSfTFym B9os96+cEqJK/rrJ9mzQ4vhThkLO2++SaLFDPdXWDui/ZARYYaPQKqbmr1cQuOsb8VzHVRnOeH2 3dp40THNPeLDGOqX0Uvs68rZv1DpLhiBphIJt4QDCahcM0kYwa1iCBqvmZs/Qfd85rch0EmmEZJ EFSoQTPMlEKwucbYGboU7WX7BbyPoBBwGTK0L9TIO3G7JpP2d1PvVRZFoDtcCQsm/ih8ERGNn1w 9ggK/NWz/Dg== X-Received: by 2002:a05:620a:1b92:b0:92e:5610:e478 with SMTP id af79cd13be357-9309627ff75mr119500085a.53.1784095059241; Tue, 14 Jul 2026 22:57:39 -0700 (PDT) X-Received: by 2002:a05:620a:1b92:b0:92e:5610:e478 with SMTP id af79cd13be357-9309627ff75mr119498285a.53.1784095058764; Tue, 14 Jul 2026 22:57:38 -0700 (PDT) Received: from [192.168.8.207] ([45.81.3.233]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-900a7f8f5d6sm173173106d6.15.2026.07.14.22.57.33 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 14 Jul 2026 22:57:38 -0700 (PDT) Message-ID: Date: Tue, 14 Jul 2026 23:59:17 -0600 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird From: Nico Pache Subject: Re: [PATCH v2 0/7] mm/khugepaged: several cleanups To: Andrew Morton Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, 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 References: <20260715025941.1571316-1-npache@redhat.com> <20260714214121.090238f5f0f318f8d82cbaa2@linux-foundation.org> Content-Language: en-US In-Reply-To: <20260714214121.090238f5f0f318f8d82cbaa2@linux-foundation.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On Tue, Jul 14, 2026 at 10:41 PM Andrew Morton wrote: > > On Tue, 14 Jul 2026 20:59:29 -0600 Nico Pache wrote: > > > The following changes stem from a number of reviews during my khugepaged > > mTHP support series [1]. Some of these are minor code cleanups, issues or > > reviews that we decided to deferred to a followup series, or in the case > > of the more major patch of the series, changes [2] Lance Yang attempted > > while my series was in-flight and we decided to wait till later to try. > > > > The first 3 patches introduce helper functions to increase code reuse and > > readability. This includes a per-scan state clearing function, extracting > > the young page check into a helper, and a count_collapse_event() function > > to reduce a repetative pattern used across mTHP collapse. > > > > The 4th patch was the byproduct of me throwing Claude at all the > > comments in khugepaged verifying and looking for any outdated info. > > > > The 5th patch is based on Lance Yang's commit series [2] trying to extract > > the PTE state checking into a helper function. This required a bit of > > rewriting due to differences after mTHP collapse was introduced. I also > > took into account the changes requested during his patches review cycle. > > > > The remaining 2 patches were review points during my mTHP series that we > > agreed can be deferred to a later series. > > > > Thank you to those whos reviews and work I leveraged to achieve these > > cleanups. > > Sashiko seems to have a good point about [5/7]: > https://sashiko.dev/#/patchset/20260715025941.1571316-1-npache@redhat.com Ah whoops! When i sent the fixup for V1 I only did it in one location when it should have been for both callers of collapse_check_pte(). Sorry about that. Here is the fixup for the missing variable assignment Thank you, -- Nico commit 52adeb9998fe84c1f997a3b3b6e98c93f9754c95 Author: Nico Pache Date: Tue Jul 14 23:50:54 2026 -0600 fixup: always set the local folio after collapse_check_pte() If we dont set the local folio to the result from collapse_check_pte() we can end up with cases that the goto out will result in pointing to a stale folio from the last successful PTE check. Signed-off-by: Nico Pache diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 40125dcb4de9..e5e349d0662e 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -1747,13 +1747,13 @@ static enum scan_result collapse_scan_pmd(struct mm_struct *mm, cc->progress++; pte_check = collapse_check_pte(pteval, addr, &ctx); + folio = ctx.folio; if (pte_check == PTE_CHECK_FAIL) { result = ctx.result; goto out_unmap; } if (pte_check == PTE_CHECK_CONTINUE) continue; - folio = ctx.folio; /* Set bit for occupied pages */ __set_bit(i, cc->mthp_present_ptes); >