From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f181.google.com (mail-pg1-f181.google.com [209.85.215.181]) (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 46F603B895B for ; Thu, 7 May 2026 11:49:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778154595; cv=none; b=pKFtqBrzKv1fdi+tauU3ApvgaqPm6wuzvNbTnx9X76xK/ii6ylLdyEKqxmXJSeGWsjfWO1DCaGt90QL7fuKTxmQE6rLphsHOhvgR2lZ3SnVEtL3EZjM+/ubM+9jfrKxoS/MgF6/ersD6QHrjQBX4CWKttzJy6xa1BY5zFW4i8xw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778154595; c=relaxed/simple; bh=jWdMv7N0p2XMg27E7mGXhb8MzmM9r+x7SzhYahymILY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kGBLm79SJEK69ZMaUfESPZi6yocEXjVZsDqzJSZOEg3FK7Uqjq/fRa3Eg1nB4cfbij/tFta9D9nMtH8YwPewpIp50oWMvCBnCMQTe6+pI3ovuD/w2Lte5pW+h3MyrQvb9xJhM/X8WEDwhGIylKeeDWfq1C5gnB9VN14zvoRrASI= 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=hZGZz86c; arc=none smtp.client-ip=209.85.215.181 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="hZGZz86c" Received: by mail-pg1-f181.google.com with SMTP id 41be03b00d2f7-c6dd5b01e14so269792a12.0 for ; Thu, 07 May 2026 04:49:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778154594; x=1778759394; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=z6CMcPMHo1KjTKUz3wKsL1u6+inZkBTTdzPKKufaP7s=; b=hZGZz86c/X4bnbRTLqEXXNH/IhN3aAEhX2O1sWBonNqpoo4/7RcHXqaQDMrNc0f0A0 KT8jbh+5mfEPrDM5nbnDXH+DFpPWo2cO26q0oizJicdzd3bHi2kxlLHQ/2arKiBctXhx FR6tsR/3HfAG0kEmtZgSGWfDny8OX9Uoyw+6vwYxBYg8nRYj+tejGYTq7euoJOve2Mzd +tigEn7C2J46W6A1M+0M+ILOswq/UBQnQRvbgaxKgsDYHS1ZUKX31dHSd9pKaC2RQb9+ cyNTWdATlAEJ+9km4zKIkJVyMXnooGmSIKS7KHz3GLa1rH7jdwx8yHmW0dBbdqPXavGi mCtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778154594; x=1778759394; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=z6CMcPMHo1KjTKUz3wKsL1u6+inZkBTTdzPKKufaP7s=; b=ecNLBD8AkVpg8rM+/p9b0VINrwbbRRN8BpbR4GsY1ybEJGM36DKTksdY6YyL1+c82e mMlOp2Kv74ZlkjKFzhX0BrltSDfP/aZJAm2jIASk1isoGs4nRUaU2FwPxmafOY9S3/+O zWsceUHgeRUkc11hDfUm7xsL1uDa1BH31jIrQlF6e6tZxbv56os7cXUYSUtUgMtTZz6t hKW5ZoT/34s3niL+R6BHVpz+oYx5g5fcf+EkhrWJBafay3NkVMFuIuP2WqkRO9bjoVQk C8iVYrefG8q7ODaBhza93t5XnCdSG+86Ajj+0awQBM0GHWnJRyYToxGLWEE6qRUuBvRE mR9A== X-Forwarded-Encrypted: i=1; AFNElJ9hI6h2+mNNRBdfjbkSYdoFEfHfnDSo3y1+srt6JpWjFtrDhizatzaO9FARRjQuUiZkhXB1TrFLkJhegfc=@vger.kernel.org X-Gm-Message-State: AOJu0YxWEk5Vo21WVVj0Jm6SFC4+6C4QcauGjD3T5L9sZQ2Ygs7o31Kw Ib43hSD8VhIHwL2OA+i4V9xk18fg0Q1SFPsVILmwOOJHOkNap9IdHOUD X-Gm-Gg: AeBDiesD2wNnBdJbRwTWgSNf32mV8HkrF7Tbx+PjVmSLXDZxkNdFNuUmqRRynAc0OpB ObWsfl1EbNwi5ipEUIIhpC093mx3CuPjJFghlSX1zQ0JlLirRX85Xn72goTAgXzI0LXaUE/a/13 gGmTcE7/Ca06SoNFmhCy1cJwJOzXiSwGXyWPHUTbLSt6LOV30R9YjmIZXj+ta4Fqnk7kYj2aXKY mOmvqN3JvqIrscPU8fD9+w86hvdCgQxJW9TNQxsT7f2GU9/sVtox2ppcHm5x+PPHE1w9BT/HwDE vBRmFFDobUwqYLewAV7XyOzN7M/5K90y3tXKwV+CnauSSpN7V+e7Tp361OgumhzLcwAuIpBOsKW bF/iIaw0ibR/RvLkGM6XUd93MK0UUWU3iA7ICP47mM98i9kuaE3Q3EbsfcBnsYLmY9fsVlgbc6g mp7nianxRadixpL4dKVoCD4ur8ciB5mpDVCVKy5WpAg9lxtPjBxwiGyJMp6tLz7pf/YTrN5FlL4 7XXG9FqYqk= X-Received: by 2002:a05:6a21:338d:b0:3a0:aee6:acc1 with SMTP id adf61e73a8af0-3aa5a9aee9fmr8053006637.33.1778154593516; Thu, 07 May 2026 04:49:53 -0700 (PDT) Received: from jillravaliya-ASUS-Vivo-AIO-V241DAP-M241DA.. ([2409:40c1:2022:5af0:565b:1ce7:b5ad:c8ae]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c825378fd56sm2014106a12.8.2026.05.07.04.49.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 May 2026 04:49:53 -0700 (PDT) From: Jill Ravaliya To: akpm@linux-foundation.org, urezki@gmail.com Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Jill Ravaliya Subject: [PATCH 2/2] selftests/mm: add test for vrealloc() shrink page freeing Date: Thu, 7 May 2026 17:18:54 +0530 Message-ID: <20260507114854.41117-2-jillravaliya@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260507114854.41117-1-jillravaliya@gmail.com> References: <20260507114854.41117-1-jillravaliya@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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