From patchwork Fri Aug 16 17:21:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aryabhatta Dey X-Patchwork-Id: 13766683 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 80596C531DC for ; Fri, 16 Aug 2024 17:24:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9133A8D009E; Fri, 16 Aug 2024 13:24:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8C38E6B0386; Fri, 16 Aug 2024 13:24:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7637E8D009E; Fri, 16 Aug 2024 13:24:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 5720C6B0385 for ; Fri, 16 Aug 2024 13:24:23 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id C79ACA01B3 for ; Fri, 16 Aug 2024 17:24:22 +0000 (UTC) X-FDA: 82458782364.24.1EDBA7D Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) by imf17.hostedemail.com (Postfix) with ESMTP id 0FFAA40003 for ; Fri, 16 Aug 2024 17:24:20 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=GbJjwS6j; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf17.hostedemail.com: domain of aryabhattadey35@gmail.com designates 209.85.214.172 as permitted sender) smtp.mailfrom=aryabhattadey35@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723829006; a=rsa-sha256; cv=none; b=h5H9AD7x3gyhD29f+ZVw+1TE5iOumUTyaWx5DibFxHjlDWoCLVBHhIC7iDaDsfNfmVHcrQ q5ZSTlkcWPlNX/1ylUMFRQTcevAbwF5Tbmt6OB2NKUGDI0X7ht3GcrOrEZ3on0RWtw4u4e FhgUlGQwJdDSa8xIDtNKBfH2hh35EQ8= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=GbJjwS6j; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf17.hostedemail.com: domain of aryabhattadey35@gmail.com designates 209.85.214.172 as permitted sender) smtp.mailfrom=aryabhattadey35@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1723829006; 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=N/dmrRqqXj2v9b4YTwmz0D6SlhuRLFNEyjT4EiFc8HE=; b=SYSKV2tuQftRT9bL62xg+oAmBHwSuNYoLPzzECsY65+S0NvVYxTzH8M1puToilwascb4z1 e9evaZec+IlzFdrOi73PbzY3w8VdatfiSDRHRj8BJsTffLBbSKdYcf5Nuualct6t4fA/OU DO+ixUg/jzK91R1rDEJzDf/PzKei2+g= Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-2020b730049so7651695ad.3 for ; Fri, 16 Aug 2024 10:24:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723829059; x=1724433859; darn=kvack.org; h=content-disposition:mime-version:message-id:subject:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=N/dmrRqqXj2v9b4YTwmz0D6SlhuRLFNEyjT4EiFc8HE=; b=GbJjwS6jOQKR+do5Y0lei4As4qBddrSK7eNSxADzj87bIhGT9saYwEm6MK5oOMw2Uz LDIzEDGknhVL0ISAuAVOYwdjQwDzEOMQGszR9Jdqvh/k3wNGYPipXfhc/vnNfftE5+tq /5R+3qNy7IyPzxKrv2JwVLto3/mjA6/jbOcEZQA/kg64MSgN0bnRweNj1D7MQx6uhyMO ZgIabBazPFe29zZIlRKFW0Kankn/qJDSQALHl9bjnPsLzTWs0roURe89+zUCA2EVWB6Y AS36mfW/27/wmpVNi+/POo+t82uPg0aBBeD1wWM2ihuIDLxVc4k6XSNwZ5McJc4q66IA QsuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723829059; x=1724433859; 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=N/dmrRqqXj2v9b4YTwmz0D6SlhuRLFNEyjT4EiFc8HE=; b=rN3GUUOfuWGRJpx71kGZAUv18+nHskdvL9QcEsasH2XOvA5pPBzkc38dton61rhZuv WV5qsGUgFkEH3in0PUImNDEhTcveaphY+eTpPgm+2Vsde1VYiRQ8G0UpV6IPLjc1RoKS JjO7wOlxFyMn7lR8H6bKWntRSBjRNfJHIaeG5YvtwfQfKSBaO/egkXz6/1iNyO9vkmYt GxSpSVlMRNb4Co3PeaFJyjZVfo2BDtyCN+X0PMpmJXtORJDjVzsKkP1EwzaNB5mjcORe 8axBWs/jb9AI0jxEK83gm6E0rjM7tiAzDgbbHFueg9fCnWLXmTQg+Es9p2YorlpmXk6y aeNw== X-Forwarded-Encrypted: i=1; AJvYcCWbjh39wpVLyTUl7XVzJv1D1T/3ZkBnZSFtTQtYdKQqmmmGo5XkUwe5uyMBDUn4cDB9isSszG73EPNhSS/2zQeV+F0= X-Gm-Message-State: AOJu0YwG48JY85JzV+a2ddfvFG99TPI0xZN7Mu+H8yQYYCABuXrDlkEQ lxNp9qdjz1TbomxzBeCBp/A53Q2/xpglRCo9UPMAYgara5tem14q X-Google-Smtp-Source: AGHT+IGuHnGEDCRtfNvw9KKo4hDVg4qVJqRvhyCt1ml1QtQrt/cBiuDQmT43rzSeWvqOmG2vgLyyKQ== X-Received: by 2002:a17:902:d50f:b0:1fd:a503:88f0 with SMTP id d9443c01a7336-20203eefb29mr44980425ad.34.1723829059518; Fri, 16 Aug 2024 10:24:19 -0700 (PDT) Received: from localhost ([27.6.216.27]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-201f02fa2d5sm27913985ad.49.2024.08.16.10.24.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Aug 2024 10:24:19 -0700 (PDT) Date: Fri, 16 Aug 2024 22:51:02 +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: MIME-Version: 1.0 Content-Disposition: inline X-Rspamd-Queue-Id: 0FFAA40003 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 5i4e8ptgbhj1w646icbb9y95f3d9sftj X-HE-Tag: 1723829060-927530 X-HE-Meta: U2FsdGVkX19JHD4mJ2JMDPKbFDJTebUvcNjAG7jxslINTK4oC1n6U863y4LbcCha1G4YqgRD5suUVyjTBdfS6ZgZAOAMwiHeui+V2yMqZACl3hg3g2zY0PNFdHtfNdCFQwvTTd1wEFjh36+YcBa1zXxUTxrvbmqcX0ztObjJiLha7bY+X5QcjRGAB2KGYTXGiX+wcrknOBlp87keVXuhBjC4SAQ9oAjRgX6Uh2GHnYKcTlP29B5FSWWSdsA9K9BvdjSNvCk/mUFRsmKqntPFh4YmpnHYKMmVqHqgGBadx9dew0Jl7OS+EB+UP95zzu875Xli2HtDjXwPyYfQ6dKnDcGSUSO+NWh3D1451Z3V7Y/ygpOai8SsIe47CExIuuZlpIjCFLhk7kEkQdThJQZXBmQlPW9Dm30f6wSflXPZrqHOenNtnfptl2NUvIp6DY72DylLUYY5qjsKvyJYOZ8knY/4GDXZH4NlhK5h7UfIO14pGUWYtjfawMyCrboZxYVMYhdt4WGbCFGlnVVeZwE/m+2FKZEcnClzHPtpgGP/lz2+au2a8Urpn2liCHBWvwHSSMpBca7mxmMyIG4HyTD5ziY8FmY15dPWmkOQIx4RGwalMcgkECqx2FZe7ZgWGmxu7TogYWGOHZAMnW3AVlq7BhRPKfnRUpOo6zjqrrZCqAboLbHoonRMLYc4Fb35UvihDj206riPCUJzqMDJLF5uY1pVZDLxn6qAoVCwBAk6nd/NGkFSVgpyfD4rT3jUyj5mvckZZwoaZHx0/I2uVuHXpZffCpIZyuuiKhIMR0bZtU6ZeUbfHOimLf4RbIU6rnM8wKS5g+HIZStpXdx27lHUPV4Qka1OlOSiW1JITCrQM4bkdlRsA7T2n5v8DiJ943px6COAvdp5FnAcQ3oCMglTbp6b7X9iApjpdLDAkmwWfv6piuO0xeFg/DZ2ALclFxlXoH1FiVtQ86C8lgz1j9z FmR9Y7hi KaMAEk3V2bYrhPMqrVZ356ln0AH8psMrYtX8q+rg+kYz5ok+TVfCvAvDT+Slt1eBmgl3C/ZlIyhTCn0CPU0cUwPtH3nUrGqIMUV/1iqkmpxwFGzAWcrftsgCvR0r+mspxqihs434/EWIXhbRW0VKjlh6G/ti3IKY+L0CeEWGAHIof9151ua4JWMXgm1LNN0ExcyCwNZ1ghW1BcOd+hZ3Y9BRONrUTF8x4NAalPKvua/aFUcTkGGUaGTJyKTYXhF5/+mcHfVnIt4tW2Slt/9SNBAbWArXJk3lY0iOY3ZG2J0IICq4oSJuw3LuVAhDOGBM6Ja2b4umh9ROfDlKBXiHoxPRiOwyFwtqf17BeXaLlQYAqeWAmJhfT/TycjDtHs913ddgOSyRFsMCj9mKh2ThNzhv425I6TfibfBQwGTG+opdyrisbjT/zidaO15SOEccDGovU 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: Add defines for 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..541ac0373258 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 "/proc/sys/vm/compact_unevictable_allowed" +#define NR_HUGEPAGES "/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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, strerror(errno)); goto close_fd; }