From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-lj1-f169.google.com (mail-lj1-f169.google.com [209.85.208.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 92D0722A4EE for ; Sat, 23 May 2026 16:20:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.169 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779553245; cv=none; b=hdWCQTcYbHGyZJFNJrGzQgZuzRdoACGH8HKmiXOflsGs7ykk1RkM1z6DVJ+YsiHImgYXhhhRbZ4cebSYW6StH+TLRD3yQAbxD0kYrg+Hbs2x/XCGbdEy6SoMqbId5lOGGNjCyU2p3eFC0G6GOKrvFxrHqDJ7lFZpBqqxegtDu/I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779553245; c=relaxed/simple; bh=8uimiW6WM2BEtwKJSAMb75JkltDRr/B6PG4blds856g=; h=From:Date:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=QsONB6x5VgCXgGWf7uKH2F6sHwfJgRTdKvtViKchs3NRXsGF++eUoKg+DjDtYraSkZhFqkPg228729xS6wNQeDUeasSP0rgEz5ssq2Y/N/JU9DJ17hGs0pJP9YgaUtqV9hmEoTn5AW7bvYWhYXw+w2HsripRMmLvmO4fv18jNRA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=natDeuGd; arc=none smtp.client-ip=209.85.208.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="natDeuGd" Received: by mail-lj1-f169.google.com with SMTP id 38308e7fff4ca-39556b00a85so64363881fa.0 for ; Sat, 23 May 2026 09:20:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779553242; x=1780158042; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:date:from:from:to:cc:subject:date:message-id:reply-to; bh=cQqOC5Q1VTx/Wh0wyRp5ePOnceO01hI9FXvQB9BCVGg=; b=natDeuGd2oVI/Ckc3PWGN0DWzTG7bFuypqk61KKAob+ZVARNwYXpN7AWmZagMnIHIT 7OVT4XG7fNU5DUpiajkGIDjmKKXZfVB6kFkyAisULlXLd0b0WH4I9ssSZcjpkm9Po+sz bZnX3B64vpFC89ZrfagkH2cJ/GWLuUD1p6gwNiAvJk58im85X2McAtJMhrNkhyKg6r0P QMkja0HsiblaDvRZojkMng+iek9pnk99ew5KZFEH8nXp5QnSBe7kxPhVX0hkQToA/f5U Ne5aCzcj7xRN4sqOpXLw4ZL3k60wHfvi9oh93RIekzHVGbeCR5hKbrFARHMkzYE5OGbo uOrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779553242; x=1780158042; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:date:from:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cQqOC5Q1VTx/Wh0wyRp5ePOnceO01hI9FXvQB9BCVGg=; b=brM4fQlaokcM7VIhvbyY2vmZ+u22rPKU2v9M/KSz8XwHSRDJafG7Pkvec/XcHrU+Aa HzJ5aqZYPq9VoaLfkTRZANaAFVHsUK+TWXyaJRHOGZV5z4KGu5lMSJMxZh2rr5mvL/bo RENXfS/wi3cIVuzhUlTm2baAU7s5qiZ+Lz85qG9kYzDkctT60oshHUgo5ReBPflyWcAF MftVZllYFslIflVpQiBTMdoVfvxD4dcgeTeqBNYf77PvdVM7Ieu+TIjH2HesB8A+JAud 5zDROA7tug9ATjUof1CEY64fwhQ4GqK+t84VjcU2eKPf+MOoDBNf0byU0G3zs6QuMkOj 30eA== X-Forwarded-Encrypted: i=1; AFNElJ/N+s2piqXmmP8fvpsK8ybMPxfHRhAqtrjwFFk5crIki3F7aEqjGwg8mhVpsKtkDkHL0SBVeZ04hqzUSaU=@vger.kernel.org X-Gm-Message-State: AOJu0YxQDQu010jnZSqqywgkJ7E/00JnYLERs4X0baqYsdDriddeg1pg fxTehRBLFbmzyaO3HofDXyPGGA0DMEkv/8ICGn5wqzchf80V/ZZ1foGc X-Gm-Gg: Acq92OG1wLsC9QQoxlS6fVj/yk91sVjk4XJ34xwVd6A6ReZ+1dz2AvG2EhOiKcYl3mD rCpvnLLo928EuCF6Hgf2o1u+q8MXMskaFLxpjX5m2c6swqowgAN3qvNClIg8zXvUBBcQ43L54Vz AkzI5ApkqQqlcWb72csla9+eeG8xRaCd+GBtCqg7ZMn2BznIQoFxcqkXSrFjbBmQIaW7jH9s9Sr mH4QGaLAjV1BfKkD8qnP3XV/s96RfBNxZLHsHr4WOzp8dS/QPpRF268SsEKgE/k4MQ4wndRrmA3 vaQXFmqesk7g6GkBC3zntbXS8UUwkNwrQ8WREVYflvW1NF7axrtgbwma0BsQCzsZlNz3rPu5jGE cu8PvfkFxttEaUDC95mKeplbx1AYLoApMg1+yVOQLpxNgpIy3JLLPaBwUcisgh4khTE/WMoEDhA Y= X-Received: by 2002:a05:651c:1470:b0:38e:9ece:61e9 with SMTP id 38308e7fff4ca-395d8d108b2mr24995211fa.25.1779553241553; Sat, 23 May 2026 09:20:41 -0700 (PDT) Received: from milan ([2001:9b1:d5a0:a500::24b]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-395dca02c2asm11915421fa.8.2026.05.23.09.20.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 May 2026 09:20:41 -0700 (PDT) From: Uladzislau Rezki X-Google-Original-From: Uladzislau Rezki Date: Sat, 23 May 2026 18:20:39 +0200 To: Jill Ravaliya Cc: akpm@linux-foundation.org, urezki@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/2] selftests/mm: add test for vrealloc() shrink page freeing Message-ID: References: <20260507114854.41117-1-jillravaliya@gmail.com> <20260507114854.41117-2-jillravaliya@gmail.com> 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=us-ascii Content-Disposition: inline In-Reply-To: <20260507114854.41117-2-jillravaliya@gmail.com> On Thu, May 07, 2026 at 05:18:54PM +0530, Jill Ravaliya wrote: > Add a selftest that verifies vrealloc() frees physical pages > when shrinking an allocation. > > The test loads a kernel module that: > 1. Allocates 10MB with vmalloc() > 2. Touches all pages to force physical allocation > 3. Shrinks to 2MB with vrealloc() > 4. Verifies free page count increased after shrink > > Without the fix, the test fails because no pages are freed. > With the fix applied, the test passes confirming ~2048 pages > are returned to the system after shrinking from 10MB to 2MB. > > Tested on kernel 7.0.0 in QEMU. > > Signed-off-by: Jill Ravaliya > --- > tools/testing/selftests/mm/Makefile | 5 ++ > .../selftests/mm/vrealloc_shrink_test.c | 65 +++++++++++++++++++ > 2 files changed, 70 insertions(+) > create mode 100644 tools/testing/selftests/mm/vrealloc_shrink_test.c > > diff --git a/tools/testing/selftests/mm/Makefile b/tools/testing/selftests/mm/Makefile > index cd24596cd..4eab7c76c 100644 > --- a/tools/testing/selftests/mm/Makefile > +++ b/tools/testing/selftests/mm/Makefile > @@ -104,6 +104,7 @@ TEST_GEN_FILES += hugetlb_dio > TEST_GEN_FILES += droppable > TEST_GEN_FILES += guard-regions > TEST_GEN_FILES += merge > +TEST_GEN_FILES += vrealloc_shrink_test > TEST_GEN_FILES += rmap > TEST_GEN_FILES += folio_split_race_test > > @@ -282,3 +283,7 @@ warn_missing_page_frag: > echo "Warning: $(PAGE_FRAG_WARNING). page_frag test will be skipped." ; \ > echo > endif > + > +# vrealloc shrink test module > +vrealloc_shrink_mod.ko: vrealloc_shrink_mod.c > + $(MAKE) -C $(KDIR) M=$(PWD) modules > diff --git a/tools/testing/selftests/mm/vrealloc_shrink_test.c b/tools/testing/selftests/mm/vrealloc_shrink_test.c > new file mode 100644 > index 000000000..cf4263074 > --- /dev/null > +++ b/tools/testing/selftests/mm/vrealloc_shrink_test.c > @@ -0,0 +1,65 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* > + * Test that vrealloc() frees physical pages when shrinking. > + * > + * vrealloc() shrink path previously zeroed unused memory and updated > + * vm->requested_size, but never freed the physical pages backing the > + * unused portion of the allocation. This test verifies the fix by > + * loading a kernel module that directly measures nr_pages before and > + * after vrealloc() shrink. > + * > + * Copyright (C) 2026 Jill Ravaliya > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include "../kselftest.h" > + > +#define MODULE_NAME "vrealloc_shrink_mod" > +#define DMESG_PASS "vrealloc_shrink: PASS" > +#define DMESG_FAIL "vrealloc_shrink: FAIL" > + > +static int run_cmd(const char *cmd) > +{ > + return system(cmd); > +} > + > +static int check_dmesg_for(const char *pattern) > +{ > + char cmd[256]; > + snprintf(cmd, sizeof(cmd), > + "dmesg | grep -q '%s'", pattern); > + return system(cmd) == 0; > +} > + > +int main(void) > +{ > + ksft_print_header(); > + ksft_set_plan(1); > + > + /* Insert the test module */ > + if (run_cmd("insmod " MODULE_NAME ".ko") != 0) { > + ksft_test_result_skip( > + "could not load %s.ko - is it built?\n", > + MODULE_NAME); > + ksft_finished(); > + } > + > + /* Check dmesg for pass/fail */ > + if (check_dmesg_for(DMESG_PASS)) { > + ksft_test_result_pass( > + "vrealloc shrink frees physical pages\n"); > + } else if (check_dmesg_for(DMESG_FAIL)) { > + ksft_test_result_fail( > + "vrealloc shrink did NOT free physical pages\n"); > + } else { > + ksft_test_result_fail( > + "could not find test result in dmesg\n"); > + } > + > + run_cmd("rmmod " MODULE_NAME); > + ksft_finished(); > +} > -- > 2.43.0 > We have a test case that covers vrealloc() functionality. See test_vmalloc.c file. -- Uladzislau Rezki