From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-185.mta0.migadu.com (out-185.mta0.migadu.com [91.218.175.185]) (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 19D223ACF10 for ; Fri, 24 Jul 2026 10:27:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.185 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784888866; cv=none; b=m4tfMl+difWyjO0U/galoTm6FpESdV95eL3gDk3vIw83/OPUh7358ZPVtxZmRXChT37oD352MD1iN4DXxrZdsQ1/EASkQKRtGJnRqHHVpJVMUmVn6Eq/FEBkBVrIR7I0im72sZ0BxH/E47+G1K4r54MbYnVplk6puLkDFSLl50M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784888866; c=relaxed/simple; bh=cHUTS4L4tlefBIYXamsLjbHOoKSeRWZmBUagiGNOEgU=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=RadbbGCWG18NYhTSnLcetC4Bjzq3/MvvGWpv4D3FNE8cw9mGkQAmWVFk6VkHkmYvFoRrazGWEcJ8jhWJ1rWyWxrHqVmW6pj9hmYNa2Mjg/ha+rStFqL0m7BbOAsUu4No1zoTotRlrFs+FGXMMEQEGLNdLnQjX25U8J9uaXA7MV8= 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=N4ziqE8w; arc=none smtp.client-ip=91.218.175.185 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="N4ziqE8w" Message-ID: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1784888858; 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=ccsuifxVD4ccTawr4skf2XENOpZrUTl0tM5ESKoH++4=; b=N4ziqE8wqT1nGDUzerglRm6kGNykObDiNIcnOZpr5A5XqStRs+sJFKIlJBhGUnWym+FzhA LD3d0d2X+zuK+vVMdutpO0/xLyNlBurgiNU9erAcSpt/tLEAPt+Cuz3FjQqh2lHQiU1Le4 YV8rWix0eKZneWpH/PlsA3p2OqygvIg= Date: Fri, 24 Jul 2026 11:27:26 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [PATCH v5 10/11] mm: install PMD swap entries on swap-out To: Matthew Wilcox 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 , youngjun.park@lge.com, hannes@cmpxchg.org, riel@surriel.com, shakeel.butt@linux.dev, alex@ghiti.fr, kas@kernel.org, baohua@kernel.org, dev.jain@arm.com, baolin.wang@linux.alibaba.com, Nico Pache , "Liam R. Howlett" , ryan.roberts@arm.com, Vlastimil Babka , lance.yang@linux.dev, linux-kernel@vger.kernel.org, nphamcs@gmail.com, shikemeng@huaweicloud.com, yosry@kernel.org, kernel-team@meta.com References: <20260722152043.2273289-1-usama.arif@linux.dev> <20260722152043.2273289-11-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 23/07/2026 20:16, Matthew Wilcox wrote: > On Wed, Jul 22, 2026 at 08:19:41AM -0700, Usama Arif wrote: >> +++ b/mm/rmap.c >> @@ -2282,6 +2282,25 @@ static bool try_to_unmap_one(struct folio *folio, struct vm_area_struct *vma, >> goto walk_abort; >> } >> >> +#ifdef CONFIG_THP_SWAP >> + /* >> + * If the folio is in the swap cache and we're not >> + * asked to split, install a PMD-level swap entry. >> + */ >> + if (!(flags & TTU_SPLIT_HUGE_PMD) && >> + folio_test_anon(folio) && >> + folio_test_swapcache(folio)) { >> + if (set_pmd_swap_entry(&pvmw, folio)) >> + goto walk_abort; >> + >> + add_mm_counter(mm, MM_ANONPAGES, >> + -HPAGE_PMD_NR); >> + add_mm_counter(mm, MM_SWAPENTS, >> + HPAGE_PMD_NR); >> + goto walk_done; >> + } >> +#endif >> + >> if (flags & TTU_SPLIT_HUGE_PMD) { >> /* >> * We temporarily have to drop the PTL and > > This makes me sad. It feels like we're bolting more complexity onto > try_to_unmap() instead of removing TTU_SPLIT_HUGE_PMD entirely. > > Ideally we'd just cope with folios of whatever size (including > PMD and PUD mapped folios) and only handle hugetlb weirdness when we > absolutely have to. Similarly, we could split PUDs to PMDs and > PMDs to PTEs when we need to, without the caller specifying > TTU_SPLIT_anything. > > Is there a reason we can't do that? I will prototype what the code would look like without TTU_SPLIT_HUGE_PMD and get back to you on this. Looking at the code right now, I feel like I would be shifting complexity, but let me try and do something about this.