From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out30-101.freemail.mail.aliyun.com (out30-101.freemail.mail.aliyun.com [115.124.30.101]) (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 CF2CD38423A for ; Fri, 13 Mar 2026 08:33:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.101 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773390842; cv=none; b=lad88BwSPWqHv95sjQF07M+c6rLjxydoGs0BfuSlZrTDgTbe4tyVhymLTa3hHGF9DMouUJKyWXQHltjC2S6raoddjErlGAItFw497oLu+wnqzer/dDb15rMy8q9RSMWDcuhsvHqjnowuXmXU8raVteASiKJGRh6UWSb5lzrqoOA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773390842; c=relaxed/simple; bh=25ycBRugst7L9EpQPqHXQeQJvsHLVmQqnFTxSZ+pOEc=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=o1ArkjfYpCZyifHwmgumyVthfBr/BEPW3b2r6W8JutH3fH0K5MSXhKgqbsAojKhe5ZX/AFcY74l4hCeCIicXfPqJAflSvbCh8K/0/TzsXnDctiDBg1YsjrLYSjuRcNeFNkRFIScL6VmETH80R4lZF+whJmZAEb7IfB4sd4cdKPI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=ug4cMJbR; arc=none smtp.client-ip=115.124.30.101 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="ug4cMJbR" DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1773390832; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=Pz3DEQxmz7FEkfqJW1qx0kp2uvXH/vjQNuM+Q6I8Wow=; b=ug4cMJbRy7ITvF9tONOC+9PUhsdG9J1k6bxa+/nJ4ZkYsUv7lh8NFbfV+AI9fZptUfe9vS+UE5MozGbDuLjPF0geNLS3krzqJfmLwVgRPP5u0obp9YwuFaU8Kj4mJd5R9To3iL35fhleoyB2WtdRw672IJGt/liteAcj7nFwMWg= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R151e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033037026112;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=56;SR=0;TI=SMTPD_---0X-rk77J_1773390827; Received: from 30.74.144.121(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0X-rk77J_1773390827 cluster:ay36) by smtp.aliyun-inc.com; Fri, 13 Mar 2026 16:33:48 +0800 Message-ID: Date: Fri, 13 Mar 2026 16:33:47 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH mm-unstable v3 5/5] mm/khugepaged: unify khugepaged and madv_collapse with collapse_single_pmd() To: Nico Pache , linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: aarcange@redhat.com, akpm@linux-foundation.org, anshuman.khandual@arm.com, apopple@nvidia.com, baohua@kernel.org, byungchul@sk.com, catalin.marinas@arm.com, cl@gentwo.org, corbet@lwn.net, dave.hansen@linux.intel.com, david@kernel.org, dev.jain@arm.com, gourry@gourry.net, hannes@cmpxchg.org, hughd@google.com, jackmanb@google.com, jack@suse.cz, jannh@google.com, jglisse@google.com, joshua.hahnjy@gmail.com, kas@kernel.org, lance.yang@linux.dev, Liam.Howlett@oracle.com, lorenzo.stoakes@oracle.com, mathieu.desnoyers@efficios.com, matthew.brost@intel.com, mhiramat@kernel.org, mhocko@suse.com, peterx@redhat.com, pfalcato@suse.de, rakie.kim@sk.com, raquini@redhat.com, rdunlap@infradead.org, richard.weiyang@gmail.com, rientjes@google.com, rostedt@goodmis.org, rppt@kernel.org, ryan.roberts@arm.com, shivankg@amd.com, sunnanyong@huawei.com, surenb@google.com, thomas.hellstrom@linux.intel.com, tiwai@suse.de, usamaarif642@gmail.com, vbabka@suse.cz, vishal.moola@gmail.com, wangkefeng.wang@huawei.com, will@kernel.org, willy@infradead.org, yang@os.amperecomputing.com, ying.huang@linux.alibaba.com, ziy@nvidia.com, zokeefe@google.com References: <20260311211315.450947-1-npache@redhat.com> <20260311211315.450947-6-npache@redhat.com> From: Baolin Wang In-Reply-To: <20260311211315.450947-6-npache@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 3/12/26 5:13 AM, Nico Pache wrote: > The khugepaged daemon and madvise_collapse have two different > implementations that do almost the same thing. Create collapse_single_pmd > to increase code reuse and create an entry point to these two users. > > Refactor madvise_collapse and collapse_scan_mm_slot to use the new > collapse_single_pmd function. This introduces a minor behavioral change > that is most likely an undiscovered bug. The current implementation of > khugepaged tests collapse_test_exit_or_disable before calling > collapse_pte_mapped_thp, but we weren't doing it in the madvise_collapse > case. By unifying these two callers madvise_collapse now also performs > this check. We also modify the return value to be SCAN_ANY_PROCESS which > properly indicates that this process is no longer valid to operate on. > > By moving the madvise_collapse writeback-retry logic into the helper > function we can also avoid having to revalidate the VMA. > > We also guard the khugepaged_pages_collapsed variable to ensure its only > incremented for khugepaged. > > Signed-off-by: Nico Pache > --- LGTM. Reviewed-by: Baolin Wang