From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-171.mta0.migadu.com (out-171.mta0.migadu.com [91.218.175.171]) (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 E26513D75B0 for ; Thu, 14 May 2026 08:11:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778746308; cv=none; b=WjXK517QfnD/3DR2D61P1XD3U+3jSSStr9AVao3Cq7z3aDhnv2Uq1WXDA/P+qeMEH0HrnhBTO4faG8jiV5sEw2xgUmSmmxz4Ht2JD29myRDFTYBpOZvT5L5jmTvz25p1KbLlM9DxJ0tU6tROCIv1UrNN1PER5FRosF0ifrKrXN4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778746308; c=relaxed/simple; bh=R7l5Gj7GzYikygKCtl1riAz5nbGTD8XOcNR/3PY7SDM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=AH9BodMAzAoUOT+dLuJLZ2WxXw2XGRm0Dxhx+7HkfNsBQ3kqeyuu8DpkGDFkYoNwYYVGjJ2WefyuKcOtDAtY1kDGpeSlXJOCAhSTFoAmnQAfqrY8R8psvMEAmCAukVwGNEpyddM/GV8Nr3WKkgAsKSeAzYE0OxOgdCHjA7/5Miw= 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=go8Hfoqt; arc=none smtp.client-ip=91.218.175.171 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="go8Hfoqt" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1778746303; 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=7d8pBMwlUmT1b6rr3QpvI3IHWFd3qcPl+TOQyqLsnxU=; b=go8HfoqtoEReSSq/ieZqqdZdWt7cCKm4uTLqLbOMB91XjqOYGN6K0Z5371rrh+7HwtCqYO JSumfynqMoUIzwG2Cqmxbjy/HEMzQQYu/xM2/l+3ktbd2CryZCCa8B/w8HmbsW+RV+dMOt TvCjZAcb8r0uH5yqqVnX0n4QFB/WXso= From: Lance Yang To: david@kernel.org, npache@redhat.com Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, yuzhao@google.com, usamaarif642@gmail.com, lance.yang@linux.dev, baohua@kernel.org, dev.jain@arm.com, ryan.roberts@arm.com, liam@infradead.org, baolin.wang@linux.alibaba.com, ziy@nvidia.com, ljs@kernel.org, akpm@linux-foundation.org Subject: Re: [RFC] mm: restrict zero-page remapping to underused THP splits Date: Thu, 14 May 2026 16:11:30 +0800 Message-Id: <20260514081130.7199-1-lance.yang@linux.dev> In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT On Tue, May 12, 2026 at 09:02:38PM +0200, David Hildenbrand (Arm) wrote: >On 5/12/26 20:36, Nico Pache wrote: >> On Tue, May 12, 2026 at 1:05 AM David Hildenbrand (Arm) >> wrote: >>> >>> On 5/11/26 20:40, Nico Pache wrote: >>>> >>>> And what was the expected behavior before this commit? Did we just >>>> deal with the wasted memory? >>> >>> Before your change, splitting will always free memory, no matter who triggers >>> splitting. So there is no wasted memory (regarding underused THPs). >>> >>> With your change, if we happen to split before the deferred shrinker runs, we >>> end up with zero-filled pages that waste memory. And reclaiming them (through >>> the deferred shrinker) first requires another re-collapse to a THP. >>> >>> Or am I misunderstanding your question? >> >> I meant before b1f202060afe ("mm: remap unused subpages to shared >> zeropage when splitting isolated thp"). Sorry, I should have been more >> specific. >> >> As in before the underutilized shrinker (and commit b1f202060afe), we >> had the exact problem you describe above and no way to handle it. >> Correct? > >Right. That's why the underused shrinker was added, to directly free pages that >have been over-allocated with a THP, but are actually never "used" (remain zero). > >> >> I guess at reclaim THPs would be split and we would swap out a zero filled page? >We don't necessarily split during swapout, we try to swap out the THP if >supported. But yes, that can happen. > >I'm more thinking about other reasons to split a THP (e.g., migration, partial >MADV_PAGEOUT/MADV_COLD/MADV_FREE), where the behavior would be changed. Yeah. Today any successful anon split gets TTU_USE_SHARED_ZEROPAGE. Would it be better to make KSM opt out, so other split paths keep the behavior they have today? That way we do not have to worry about changing anything else at the same time :D Cheers, Lance