From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-170.mta0.migadu.com (out-170.mta0.migadu.com [91.218.175.170]) (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 6EB36292B4B for ; Mon, 6 Jul 2026 12:23:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783340618; cv=none; b=L6tme7CtqM+MI+LzjIA/fZm/SshLWAnOLvJ+DMhn0EXY4ctKBRLYbfkEs/oxZiSInQ0BLwwI1HqOSmJQkun0e8m9iB7LqioOTQu6SKkYgyp4YMlTcytSPp5lEPNLQ+GvW8z84s+cr2Tm+vIDpWSA2zpu432HXHFrOLzuYjgzlEg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783340618; c=relaxed/simple; bh=OYWMiJ9XsaP+oAlqB0lfp4vX3BS3MpzRIryDiTv+OeI=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=GkFfMyVXXb+oWyEe1yLDGIJUKXxyqapOcXzMukjIJV/cV5586TjCh1gXRou58TcSkx2Kp/PsWK5pCHmfmvXHQlrxqHNIpctSIe6/zmQgS7pb2Pim+0kV3mOngdizCcg/lKOIHdndu3f3aPVt/c9tgtRGTQvoKneT7xbjoptrYdc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=rMW3Piaf; arc=none smtp.client-ip=91.218.175.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="rMW3Piaf" Message-ID: <642efd6d-7366-4641-a999-2d419fd38f8d@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1783340615; 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=9j0GOdBfYeLx2CUbyWxmjGIwhc/AnYvsLCc56GZQxMQ=; b=rMW3PiafInDZbNyrGZzU42E3W5uKNLvaWtlr2sGsIt7yxxWMILZr6otgwwFAl3pihY9pY/ +VvnCec0pE9JQcAA03fmlFPA/Qzuzj9Zxt6XPDWrAJRZDjZc1f4b7U4mUNCew2UYcNy//X CovhfrR5+XhKWfIuDPt6qqW8VfnsTbY= Date: Mon, 6 Jul 2026 13:23:29 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [PATCH v2 2/6] mm: extract mm_prepare_for_swap_entries() helper To: Kiryl Shutsemau Cc: Andrew Morton , david@kernel.org, chrisl@kernel.org, kasong@tencent.com, ljs@kernel.org, ziy@nvidia.com, linux-mm@kvack.org, ying.huang@linux.alibaba.com, Baoquan He , willy@infradead.org, youngjun.park@lge.com, hannes@cmpxchg.org, riel@surriel.com, shakeel.butt@linux.dev, alex@ghiti.fr, baohua@kernel.org, dev.jain@arm.com, baolin.wang@linux.alibaba.com, npache@redhat.com, "Liam R. Howlett" , ryan.roberts@arm.com, Vlastimil Babka , lance.yang@linux.dev, linux-kernel@vger.kernel.org, nphamcs@gmail.com, shikemeng@huaweicloud.com, kernel-team@meta.com References: <20260706114320.1643046-1-usama.arif@linux.dev> <20260706114320.1643046-3-usama.arif@linux.dev> Content-Language: en-US X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Usama Arif In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT On 06/07/2026 13:01, Kiryl Shutsemau wrote: > On Mon, Jul 06, 2026 at 04:42:04AM -0700, Usama Arif wrote: >> When a swap entry is installed in a page table, the mm must be added >> to init_mm.mmlist so that swapoff can find and unuse its swap entries. >> This double-checked locking pattern is currently open-coded in >> try_to_unmap_one() and copy_nonpresent_pte(). >> >> Move it into mm_prepare_for_swap_entries() in mm/internal.h and convert >> both callers so it can be reused by upcoming PMD-level swap entry code >> paths that also need to register the mm with swapoff. >> >> copy_nonpresent_pte() previously inserted into &src_mm->mmlist rather >> than &init_mm.mmlist, but the insertion point is irrelevant, mmlist >> is a circular list and swapoff walks it entirely from init_mm.mmlist, >> so only membership matters, not position. >> >> Reviewed-by: Dev Jain >> Reviewed-by: Zi Yan >> Acked-by: David Hildenbrand (Arm) >> Signed-off-by: Usama Arif >> --- >> mm/internal.h | 10 ++++++++++ >> mm/memory.c | 9 +-------- >> mm/rmap.c | 7 +------ >> 3 files changed, 12 insertions(+), 14 deletions(-) >> >> diff --git a/mm/internal.h b/mm/internal.h >> index 430aa72a4575..0360648e5726 100644 >> --- a/mm/internal.h >> +++ b/mm/internal.h >> @@ -1955,4 +1955,14 @@ static inline int get_sysctl_max_map_count(void) >> bool may_expand_vm(struct mm_struct *mm, const vma_flags_t *vma_flags, >> unsigned long npages); >> >> +static inline void mm_prepare_for_swap_entries(struct mm_struct *mm) >> +{ >> + if (list_empty(&mm->mmlist)) { >> + spin_lock(&mmlist_lock); >> + if (list_empty(&mm->mmlist)) >> + list_add(&mm->mmlist, &init_mm.mmlist); > > The patch is fine, but the name of the field is awful. Seeing mmlist I > assumed it listed all mm_structs. It has to have "swap" somewhere in the > field name. > I can send a separate patch once this is replaced to replace mmlist with swap_mmlist if that sounds better? Thanks Usama