From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-187.mta1.migadu.com (out-187.mta1.migadu.com [95.215.58.187]) (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 D0946376BF7 for ; Thu, 26 Feb 2026 11:35:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.187 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772105715; cv=none; b=H1ydmXY2GAcfTA99I2zMsoWThQmZyc63ltaCeerIfg+K+1bonj3lHxx8uaZnXgcSKfjAloX7wEYFmamqnjEHbj+xwgFt4W9twLotXxTOdqBC7wfteov1BDPTpmAl0j/UPwdeKmbsdp2qYeglReBPCxLakHftoBKzcIxCsXNa80Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772105715; c=relaxed/simple; bh=7bs/amAnuw+tLe58u6OiuFWJqr2A9j/wVQKfsSz7kP4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cpO5WqpL17KUDwp73MPT2VKcbqIpOvgMqqWEfqx6kak7RT34RwyzokZBvCimy03yZHXb8CFxCLGgyWMwgFUzAZl7z/qMvOS2u3io2QLGYovQLQKfrHh3/cahpT3+2268jwzQ2dAjLiVcmNvz6VE3wEllWNScO+P8d1WieoV+lZQ= 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=KI9SLjRO; arc=none smtp.client-ip=95.215.58.187 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="KI9SLjRO" 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=1772105711; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NNFcsrTCJuN3pq1P0jDB1SWfqOIjrkZR0u7eCL/hrlc=; b=KI9SLjROFcSirL2mTS5OuZAfOP+ehi28WMw/ahTS4caHqgegRKvYlaWKxelk0oDyR0nsl5 /QixN5IwhA0UcIZAWfR1y/OvtYWnl7Ph+KBswIu2u7tJvUJmFOgV/00DoRlyspgzic/ovd xV36dvYGWz99ZyLasi42ArQFEIfukOw= From: Usama Arif To: Andrew Morton , david@kernel.org, lorenzo.stoakes@oracle.com, willy@infradead.org, linux-mm@kvack.org Cc: fvdl@google.com, hannes@cmpxchg.org, riel@surriel.com, shakeel.butt@linux.dev, kas@kernel.org, baohua@kernel.org, dev.jain@arm.com, baolin.wang@linux.alibaba.com, npache@redhat.com, Liam.Howlett@oracle.com, ryan.roberts@arm.com, Vlastimil Babka , lance.yang@linux.dev, linux-kernel@vger.kernel.org, kernel-team@meta.com, maddy@linux.ibm.com, mpe@ellerman.id.au, linuxppc-dev@lists.ozlabs.org, hca@linux.ibm.com, gor@linux.ibm.com, agordeev@linux.ibm.com, borntraeger@linux.ibm.com, svens@linux.ibm.com, linux-s390@vger.kernel.org, Usama Arif Subject: [RFC v2 21/21] selftests/mm: add madv_dontneed_partial test Date: Thu, 26 Feb 2026 03:23:50 -0800 Message-ID: <20260226113233.3987674-22-usama.arif@linux.dev> In-Reply-To: <20260226113233.3987674-1-usama.arif@linux.dev> References: <20260226113233.3987674-1-usama.arif@linux.dev> Precedence: bulk X-Mailing-List: linux-s390@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT Add test for partial MADV_DONTNEED on THP. This verifies that MADV_DONTNEED correctly triggers a PMD split, discards only the requested page (which becomes zero-filled), and preserves data in the surrounding pages. Signed-off-by: Usama Arif --- .../testing/selftests/mm/thp_pmd_split_test.c | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tools/testing/selftests/mm/thp_pmd_split_test.c b/tools/testing/selftests/mm/thp_pmd_split_test.c index 1f29296759a5b..060ca1e341b75 100644 --- a/tools/testing/selftests/mm/thp_pmd_split_test.c +++ b/tools/testing/selftests/mm/thp_pmd_split_test.c @@ -253,4 +253,38 @@ TEST_F(thp_pmd_split, partial_mremap) self->split_pmd_failed_before); } +/* + * MADV_DONTNEED on THP + * + * Tests that MADV_DONTNEED on a partial THP correctly handles + * the PMD split and discards only the requested pages. + */ +TEST_F(thp_pmd_split, partial_madv_dontneed) +{ + volatile unsigned char *ptr = (volatile unsigned char *)self->aligned; + int ret; + + ret = allocate_thp(self->aligned, self->pmdsize); + if (ret) + SKIP(return, "Failed to allocate THP"); + + /* Write pattern */ + memset(self->aligned, 0xDD, self->pmdsize); + + /* Partial MADV_DONTNEED - discard middle page */ + ret = madvise((char *)self->aligned + self->pagesize, self->pagesize, MADV_DONTNEED); + ASSERT_EQ(ret, 0); + + /* Verify non-discarded pages still have data */ + ASSERT_EQ(ptr[0], (unsigned char)0xDD); + ASSERT_EQ(ptr[2 * self->pagesize], (unsigned char)0xDD); + ASSERT_EQ(ptr[self->pmdsize - 1], (unsigned char)0xDD); + + /* Discarded page should be zero */ + ASSERT_EQ(ptr[self->pagesize], (unsigned char)0x00); + + log_and_check_pmd_split(_metadata, self->split_pmd_before, + self->split_pmd_failed_before); +} + TEST_HARNESS_MAIN -- 2.47.3