From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id CDBBFC369CB for ; Wed, 23 Apr 2025 10:36:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6CF466B00A1; Wed, 23 Apr 2025 06:36:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 67C976B00A2; Wed, 23 Apr 2025 06:36:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 51EFE6B00A3; Wed, 23 Apr 2025 06:36:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 3000E6B00A1 for ; Wed, 23 Apr 2025 06:36:56 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 3A05CC7AA8 for ; Wed, 23 Apr 2025 10:36:56 +0000 (UTC) X-FDA: 83364955632.05.FB7EB89 Received: from out30-113.freemail.mail.aliyun.com (out30-113.freemail.mail.aliyun.com [115.124.30.113]) by imf18.hostedemail.com (Postfix) with ESMTP id 61F9E1C0002 for ; Wed, 23 Apr 2025 10:36:52 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=fBbZEXTm; dmarc=pass (policy=none) header.from=linux.alibaba.com; spf=pass (imf18.hostedemail.com: domain of feng.tang@linux.alibaba.com designates 115.124.30.113 as permitted sender) smtp.mailfrom=feng.tang@linux.alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1745404614; a=rsa-sha256; cv=none; b=iMA+elRSojvEQaDc1gNkJ7opV3lxx5oUGgszJ3dtM6+VugSgrLfjse4atCIPTycIDu46bg 5G7DmDN1UWkT0WfDnbjvryukpihHtEQynJCnKEZz0mbQodDnYg4xVy3gI6ljekAXGrcicM cF5ohl7Gkaq/+M8AWfZWybH+pf6S/UY= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=fBbZEXTm; dmarc=pass (policy=none) header.from=linux.alibaba.com; spf=pass (imf18.hostedemail.com: domain of feng.tang@linux.alibaba.com designates 115.124.30.113 as permitted sender) smtp.mailfrom=feng.tang@linux.alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1745404614; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=7UV3Sx7chqx94m/WYooWcJnWJngfPHWmkbDclQkQiqg=; b=ZxjgvkOlgKXxymA5ps3EGAv51S6WD2vktjierL8Qm7T+KxK4iv+Q5yxIFTcNH+Fd4pSpkR Pprs4C16fdCrddSmqtd0qohyBIIhMvy95oRpOw9GJDHT0vh49isHu/qittanPrhy8bXCwL rh1Qd6czW6ytR0a2fH45wpUR/6m7z8A= DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1745404607; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=7UV3Sx7chqx94m/WYooWcJnWJngfPHWmkbDclQkQiqg=; b=fBbZEXTmlQEspDAY5axvaXweBSflzDMB/SUiOYRg9zIpiU5ZAqpSSjOcLFdNWzI9UQKUymcjYTenPY8erz/fJHgi8DZ+ygzvoEOOm6YdmKJ0mRm0nA/sl5nazRl5Jz3L8eUED60VgYTJbbahkkAImh2JoeSYSjdjB6wlrnOrkNI= Received: from localhost(mailfrom:feng.tang@linux.alibaba.com fp:SMTPD_---0WXuKlPh_1745404605 cluster:ay36) by smtp.aliyun-inc.com; Wed, 23 Apr 2025 18:36:46 +0800 From: Feng Tang To: Andrew Morton , Shuah Khan , Sri Jayaramappa , linux-mm@kvack.org, linux-kselftest@vger.kernel.org Cc: baolin.wang@linux.alibaba.com, Feng Tang Subject: [PATCH] selftests/mm: compaction_test: Support platform with huge mount of memory Date: Wed, 23 Apr 2025 18:36:45 +0800 Message-Id: <20250423103645.2758-1-feng.tang@linux.alibaba.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspam-User: X-Rspamd-Queue-Id: 61F9E1C0002 X-Rspamd-Server: rspam04 X-Stat-Signature: ijrdp3rcgkgd8otqw9ocxme87w5p8hwk X-HE-Tag: 1745404612-206544 X-HE-Meta: U2FsdGVkX18vRzDtY0Vn18/pVIuFJH3Ca1RgCnH8Lblcmuen7VIqqfGpsShHTbhwD9IiyfhaUzAQYa7vQITO40svqhauAqVtSXmsEmXhNysPdAiIRk6FhbSxhGyQBVTSy3jSYdHSk30FVMryUAKMgQHwbQBimd0hWn9yysvQzlaLo8ergP/oJCEJQVmWJFqLP9z64sMuZZ0RZNd0N8TZGGNZEJE6YrEC3/NHNCIUYh7b4IM+uzr5Tyd8P9tlXXUi0HKR+SO+O4sj+MiYWa7ChcZZJjTe4WX7HaRg7hxrkN00qXfz/Ln6W16vq+LWPlFq49RC2t+Br65cbQttWwk/yCZQq3SR/T5JxKfKDjAOAUPKAERtADNuySoFQ9a6XQv6Ce74kxzLxx3qweRn23FWqWdCgmLDtAyKhIr1QwHGhG6oi/Yy30WFNB77DKvl6FfFjdGrJIzyABZCzLOVLNdvgcpFk8Og+bxfwzfa6Uc5KRGQeBsHZdyz3aegxsN/TGwbjCxKrGPF67TfVF3RsgexlhVq9Bhvdu5hc5mBX8ugRoHbDog+IE0k0xUqUJGCh7Nvg7LYgt/qX3zl3j4UVzRlyWZfcAlLYZ5sWghkHWt+83Ksf4HDY1+Y7nB1AfZ9CjsISzmPW3pqKYGNoPE4cLHEhSOxJXjPjQzaK0hDQiDz7c0avPkq5CnE3tUjcxDws28mts+CXjDTnxlD4m/qK8Q9ho5Sl3jfA+ufdClLj03l7WTtRzFX7nLYe9JPYk72RL7OYgYx8icZ8xAiv+FDatOBRQJ02ZmV/H29PyQrFKjOtx04XYc6TNdAgFLixCsm99H0v5Jp+BNMbly7Uo1FjLIFqayVBt4cDyC0+Gnk96p8yhbEq9dn8SDOIVClf/D1ch68vF6ZkfRooZEaPTxnpJQA4JtjtaZKz0A8yUjnZpycwu8KakD11lMuREn/fZ4HpFp27GuyeKOoJVX3p2qZsr1 duH7HCke T1RztkCSsN5lb4N9OoqR64SERMUTOq/unmGOmDh5mRckKyioIz4MvatbAfH0ddRI70qVGbXmXfHLrsBz1uPYjKN5SS2H1cWDLUHEnPOhDQ4h5RlOo1tRxprM1juUJIJnbRWSAMPP6vDLCCOvhtn3WwddsosKwd2J4GyltmR+eILy5EfJ49ch0CfdiBpBuTaqaTxxv6ndNk19E1WLplcoSNO9XyTsZ6n1AM1nuS+z49Y7y/EZ9VAkjag6z8EJ4Bm0a4m2QFaVysQvhwTxCC7VQ3+k2LQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: When running mm selftest to verify mm patches, 'compaction_test' case failed on an x86 server with 1TB memory. And the root cause is that it has too much free memory than what the test supports. The test case tries to allocate 100000 huge pages, which is about 200 GB for that x86 server, and when it succeeds, it expects it's large than 1/3 of 80% of the free memory in system. This logic only works for platform with 750 GB ( 200 / (1/3) / 80% ) or less free memory, and may raise false alarm for others. Fix it by changing the fixed page number to self-adjustable number according to the real number of free memory. Fixes: bd67d5c15cc19 ("Test compaction of mlocked memory") Signed-off-by: Feng Tang --- tools/testing/selftests/mm/compaction_test.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/mm/compaction_test.c b/tools/testing/selftests/mm/compaction_test.c index 2c3a0eb6b22d..9bc4591c7b16 100644 --- a/tools/testing/selftests/mm/compaction_test.c +++ b/tools/testing/selftests/mm/compaction_test.c @@ -90,6 +90,8 @@ int check_compaction(unsigned long mem_free, unsigned long hugepage_size, int compaction_index = 0; char nr_hugepages[20] = {0}; char init_nr_hugepages[24] = {0}; + char target_nr_hugepages[24] = {0}; + int slen; snprintf(init_nr_hugepages, sizeof(init_nr_hugepages), "%lu", initial_nr_hugepages); @@ -106,11 +108,18 @@ int check_compaction(unsigned long mem_free, unsigned long hugepage_size, goto out; } - /* Request a large number of huge pages. The Kernel will allocate - as much as it can */ - if (write(fd, "100000", (6*sizeof(char))) != (6*sizeof(char))) { - ksft_print_msg("Failed to write 100000 to /proc/sys/vm/nr_hugepages: %s\n", - strerror(errno)); + /* + * Request huge pages for about half of the free memory. The Kernel + * will allocate as much as it can, and we expect it will get at least 1/3 + */ + nr_hugepages_ul = mem_free / hugepage_size / 2; + snprintf(target_nr_hugepages, sizeof(target_nr_hugepages), + "%lu", nr_hugepages_ul); + + slen = strlen(target_nr_hugepages); + if (write(fd, target_nr_hugepages, slen) != slen) { + ksft_print_msg("Failed to write %lu to /proc/sys/vm/nr_hugepages: %s\n", + nr_hugepages_ul, strerror(errno)); goto close_fd; } -- 2.43.5