From patchwork Fri Aug 16 18:08:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aryabhatta Dey X-Patchwork-Id: 13766752 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 005CBC3DA4A for ; Fri, 16 Aug 2024 18:12:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8E6928D00AB; Fri, 16 Aug 2024 14:12:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 896838D00A2; Fri, 16 Aug 2024 14:12:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 75E688D00AB; Fri, 16 Aug 2024 14:12:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 527998D00A2 for ; Fri, 16 Aug 2024 14:12:12 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 1B1D6A4ED9 for ; Fri, 16 Aug 2024 18:12:12 +0000 (UTC) X-FDA: 82458902904.23.09DA444 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) by imf08.hostedemail.com (Postfix) with ESMTP id 58F4D160011 for ; Fri, 16 Aug 2024 18:12:10 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=hJyP8c1Z; spf=pass (imf08.hostedemail.com: domain of aryabhattadey35@gmail.com designates 209.85.214.177 as permitted sender) smtp.mailfrom=aryabhattadey35@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1723831855; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=U5l/0VSy6fqZaacoTqYSq61RAXhnTHweezwv61jbJ0Y=; b=VgWlpKsADt582RUKjV27lNx2QIE7TUgmsq3mzlw7DXEbs5VQkH2jhNmsFfCfUpO8AHyJzQ bMXKx0eQkBputoSQdomfR0XSiV+HE7x8/B/00m7I88PGKg+ge+lAQ5Ela0Vg9i/UG0D55Q Ue5uDClSZwK+CYWx6+npL3ABcITy5NU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723831855; a=rsa-sha256; cv=none; b=VQy1CpmCCon8okSAaj7mASRkoezUnz5NPX6yoYsFXPFmo92kb7Zm2z5a7S0uXi8FsadKaD he9OVehCNa7xc685mVpLoxUOWc/XRw9SfB3EMjfuBGLiqEwGj/9cGjGok6nmwgQM1w4y8E G2vX2blykXMNZFoGLIhihzu6HNKLKhQ= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=hJyP8c1Z; spf=pass (imf08.hostedemail.com: domain of aryabhattadey35@gmail.com designates 209.85.214.177 as permitted sender) smtp.mailfrom=aryabhattadey35@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-1fec34f94abso22362585ad.2 for ; Fri, 16 Aug 2024 11:12:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723831929; x=1724436729; darn=kvack.org; h=content-disposition:mime-version:message-id:subject:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=U5l/0VSy6fqZaacoTqYSq61RAXhnTHweezwv61jbJ0Y=; b=hJyP8c1ZnTtNGNyhKP0wvAAxL0hRL0UTjpBgMog+5WeyCl5aOfJ2XMM6gmvKZ8tVDT 9m0dqFYvgm1yqBJd82qj+I7rSQrFV1ymG+S5BoVgzbzsdNLtpxPj80MvGbombC0hYwQr Kd5nWzQJDpMK04jR5mzcsMAyRKndkYTdwYGPozs50diHiKDkimPe7vcEjWviu07ORC6p 9Wt2aSt7FRjvKTFdLnStHc4m4qoUIDfeADtRpYS3l+sK6ipc6OiY6ott1r/pc9InjK2G Tvl7BFYr+GNO7g4pX/vXGgBP/VoSiODR2NE6sw80y7qZ+nHU1zA+8kEPveTHDj+f/+7r jZ0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723831929; x=1724436729; h=content-disposition:mime-version:message-id:subject:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=U5l/0VSy6fqZaacoTqYSq61RAXhnTHweezwv61jbJ0Y=; b=FBz9y5OquJIQfsFVoJhVH+/H1nKQZ/GI5XB8q4wEWhtd3w2iuFoDJm2dxZbFR6P9zG 2TsIEqQdZ7zhDbng+qfBf1sCakSNvsNijVKLOvTEI9nIguWnJcu2RQbR1mbpOEtLMilv c0ngWzHt3KBFjVm29WRIBDUs9b6YkK0cOZBeH8LS1U0vrOa4AAFJodyjP6TT2zIk5099 eNcrd6CUsUACACIQT8TuYegwMypME5+YjwJOrW0uXyFTzHJV3Bjy+jbE2vUWYmrorGg+ tkpmHTyUMZ5ruVEijuHsUWlpbITk+i9QbZgh7Ulys6Q+qBauuI5onhFo/haI+eHAtwRP G+RQ== X-Forwarded-Encrypted: i=1; AJvYcCXJS5D112JaIKDD4WKA0FeovTP2M0BF1cVB7JsByZofxYBgvUOc563/BdNBtD4BCdLOExc13G/iD5t5ZREEcmDcpfA= X-Gm-Message-State: AOJu0Yxb+7J5g0MYSJtvbaf0D7SWmVUG8qYeUiYkOpriP2YSC1aSN82t Gv3oocHNyNHKBs91CYmp/uznbRj6O9I0aGifsqwjgSWFVJgHUgFq X-Google-Smtp-Source: AGHT+IE9C/aLOhdS0C3ly72nc2bgoyh9bdEhmy1vCLr8xsbc57OwrGBuSeS6GRQihj7C/li24A4YOg== X-Received: by 2002:a17:902:cec1:b0:201:ef87:9535 with SMTP id d9443c01a7336-20203e4c9c5mr46728515ad.3.1723831928894; Fri, 16 Aug 2024 11:12:08 -0700 (PDT) Received: from localhost ([27.6.216.27]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-201f037599asm28293515ad.149.2024.08.16.11.12.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Aug 2024 11:12:08 -0700 (PDT) Date: Fri, 16 Aug 2024 23:38:51 +0530 From: Aryabhatta Dey To: akpm@linux-foundation.org, shuah@kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH] selftests/mm: compaction_test: Move often used filepaths to strings Message-ID: <5kedpmxee2wvblijsxmmyk5l6aufuwkjkiovnsyh7n7iuz7cok@7lfnhaobpzd7> MIME-Version: 1.0 Content-Disposition: inline X-Stat-Signature: gknrpd9m9gqt14jkn8u6bzo5m6u17d57 X-Rspamd-Queue-Id: 58F4D160011 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1723831930-865581 X-HE-Meta: U2FsdGVkX19ONPxQBR8DQziiqk3GVKfVBLYfELJg2268+hOPN7WCbHX5evsYO7+BLCOGf3ARqbUZwz00avK8Lk8y7ILjHFK5vWci2zIwRWqZ/WNMAxKwqK8CoG6ozSfPOwOqPVa1qVImL1U/557JODR+Z3RLCoDjNfDYnwFtxI6RLLll4ksiDC+qvk+ZzSuUu9dEVme2jUJVg83PKqTrgFmmWpq4iv18k9IlBbVby9pip4UchLV9Q8EhOeF3UOFCFgm5RYTDv6HPgzQI8pc8hFto90/lmn4+ucr67YYWvzj19eXiUl8nO4gDvYJOv4ashAZwZzQnu2kalTT/7Tsv0wuWxFaMiUmeIjIZgqBrJ4GZ9QC+51FVxHF7afZLSg6DV2hAMphc3ZsPV9D8416kG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-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Add defines for the file path names to avoid duplicate strings in print messages and make it easier to maintain. Signed-off-by: Aryabhatta Dey --- tools/testing/selftests/mm/compaction_test.c | 46 ++++++++++---------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/tools/testing/selftests/mm/compaction_test.c b/tools/testing/selftests/mm/compaction_test.c index e140558e6f53..8f46431a9182 100644 --- a/tools/testing/selftests/mm/compaction_test.c +++ b/tools/testing/selftests/mm/compaction_test.c @@ -21,6 +21,9 @@ #define MAP_SIZE_MB 100 #define MAP_SIZE (MAP_SIZE_MB * 1024 * 1024) +#define COMPACT_UNEVICTABLE_ALLOWED_FILE_PATH "/proc/sys/vm/compact_unevictable_allowed" +#define NR_HUGEPAGES_FILE_NAME_PATH "/proc/sys/vm/nr_hugepages" + struct map_list { void *map; struct map_list *next; @@ -59,17 +62,16 @@ int prereq(void) char allowed; int fd; - fd = open("/proc/sys/vm/compact_unevictable_allowed", - O_RDONLY | O_NONBLOCK); + fd = open(COMPACT_UNEVICTABLE_ALLOWED_FILE_PATH, O_RDONLY | O_NONBLOCK); if (fd < 0) { - ksft_print_msg("Failed to open /proc/sys/vm/compact_unevictable_allowed: %s\n", - strerror(errno)); + ksft_print_msg("Failed to open %s: %s\n", + COMPACT_UNEVICTABLE_ALLOWED_FILE_PATH, strerror(errno)); return -1; } if (read(fd, &allowed, sizeof(char)) != sizeof(char)) { - ksft_print_msg("Failed to read from /proc/sys/vm/compact_unevictable_allowed: %s\n", - strerror(errno)); + ksft_print_msg("Failed to read from %s: %s\n", + COMPACT_UNEVICTABLE_ALLOWED_FILE_PATH, strerror(errno)); close(fd); return -1; } @@ -97,10 +99,10 @@ int check_compaction(unsigned long mem_free, unsigned long hugepage_size, in to play */ mem_free = mem_free * 0.8; - fd = open("/proc/sys/vm/nr_hugepages", O_RDWR | O_NONBLOCK); + fd = open(NR_HUGEPAGES_FILE_NAME_PATH, O_RDWR | O_NONBLOCK); if (fd < 0) { - ksft_print_msg("Failed to open /proc/sys/vm/nr_hugepages: %s\n", - strerror(errno)); + ksft_print_msg("Failed to open %s: %s\n", + NR_HUGEPAGES_FILE_NAME_PATH, strerror(errno)); ret = -1; goto out; } @@ -108,16 +110,16 @@ int check_compaction(unsigned long mem_free, unsigned long hugepage_size, /* 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)); + ksft_print_msg("Failed to write 100000 to %s: %s\n", + NR_HUGEPAGES_FILE_NAME_PATH, strerror(errno)); goto close_fd; } lseek(fd, 0, SEEK_SET); if (read(fd, nr_hugepages, sizeof(nr_hugepages)) <= 0) { - ksft_print_msg("Failed to re-read from /proc/sys/vm/nr_hugepages: %s\n", - strerror(errno)); + ksft_print_msg("Failed to re-read from %s: %s\n", + NR_HUGEPAGES_FILE_NAME_PATH, strerror(errno)); goto close_fd; } @@ -134,8 +136,8 @@ int check_compaction(unsigned long mem_free, unsigned long hugepage_size, if (write(fd, init_nr_hugepages, strlen(init_nr_hugepages)) != strlen(init_nr_hugepages)) { - ksft_print_msg("Failed to write value to /proc/sys/vm/nr_hugepages: %s\n", - strerror(errno)); + ksft_print_msg("Failed to write value to %s: %s\n", + NR_HUGEPAGES_FILE_NAME_PATH, strerror(errno)); goto close_fd; } @@ -162,15 +164,15 @@ int set_zero_hugepages(unsigned long *initial_nr_hugepages) int fd, ret = -1; char nr_hugepages[20] = {0}; - fd = open("/proc/sys/vm/nr_hugepages", O_RDWR | O_NONBLOCK); + fd = open(NR_HUGEPAGES_FILE_NAME_PATH, O_RDWR | O_NONBLOCK); if (fd < 0) { - ksft_print_msg("Failed to open /proc/sys/vm/nr_hugepages: %s\n", - strerror(errno)); + ksft_print_msg("Failed to open %s: %s\n", + NR_HUGEPAGES_FILE_NAME_PATH, strerror(errno)); goto out; } if (read(fd, nr_hugepages, sizeof(nr_hugepages)) <= 0) { - ksft_print_msg("Failed to read from /proc/sys/vm/nr_hugepages: %s\n", - strerror(errno)); + ksft_print_msg("Failed to read from %s: %s\n", + NR_HUGEPAGES_FILE_NAME_PATH, strerror(errno)); goto close_fd; } @@ -178,8 +180,8 @@ int set_zero_hugepages(unsigned long *initial_nr_hugepages) /* Start with the initial condition of 0 huge pages */ if (write(fd, "0", sizeof(char)) != sizeof(char)) { - ksft_print_msg("Failed to write 0 to /proc/sys/vm/nr_hugepages: %s\n", - strerror(errno)); + ksft_print_msg("Failed to write 0 to %s: %s\n", + NR_HUGEPAGES_FILE_NAME_PATH, strerror(errno)); goto close_fd; }