From nobody Fri Apr 3 01:22:49 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0099F2F5321 for ; Thu, 2 Apr 2026 06:38:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775111892; cv=none; b=b6UN1Ge+6mySOvTelwbNDfU6NI/y5U5tI+FtDWy6vyqJQ0mQ05PbnMM9i5jJ1Ok/7a1XzUfwygR6Rr/tjfk5O0/C57JSWC8mnP5dsTUJ3lFgqZvQZf2R+zyVo7+7sRxdZ4xnrNFU6UO/QQJio1fCJWiClWM5cl4iUiW14iw3VwM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775111892; c=relaxed/simple; bh=9fMeWMmJsgQaIwk/ZD624ixch1cfORUOPSfRQP72GMg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=FszWTQJMPVABpl1DL6NjGHj0eIP/Fo5TP3xPTLsAqwjmEjLCV4YDEw86L/1di9eoOyycWZnijr4J5DGAzIssYy+peMX/vwsH7eYa/TPkqQTNmhUg3d+EINK7OCzz69wI9oZm6or3stNBXdHVPc2L8gFYltj+800ATiJPTxv5vSI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=bVF/e5A0; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="bVF/e5A0" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1775111890; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6xITEB/o4W7V44LNKdzXwQHA6xAoRTOl1JFgHYsjoo4=; b=bVF/e5A0qzaPKU1bsDY7Y5074CbV7WzL108BCPh/ZKAw3aNJAvPf6IoYDoRsOTEYqDfGiP iQyAz8QoejEDasfhrlvaZQsC0+hVs5+p27b1Wm+B4ybiyta7Dmg7HaboWOnSB8klKPozRS 42eRjP49EwQPNqOUUnN0PPjm4GV+GYI= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-328-6plKfXNYN3SoZcDF2Il8AA-1; Thu, 02 Apr 2026 02:38:08 -0400 X-MC-Unique: 6plKfXNYN3SoZcDF2Il8AA-1 X-Mimecast-MFC-AGG-ID: 6plKfXNYN3SoZcDF2Il8AA_1775111886 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 0B6751800345; Thu, 2 Apr 2026 06:38:06 +0000 (UTC) Received: from fedora-laptop-x1.redhat.com (unknown [10.72.112.158]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4F6F018005AE; Thu, 2 Apr 2026 06:37:55 +0000 (UTC) From: Li Wang To: akpm@linux-foundation.org, rppt@kernel.org, david@kernel.org, hannes@cmpxchg.org, yosry@kernel.org, ljs@kernel.org, Liam.Howlett@oracle.com, mhocko@suse.com, shuah@kernel.org, chengming.zhou@linux.dev, longman@redhat.com, nphamcs@gmail.com Cc: linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, Michal Hocko , =?UTF-8?q?Michal=20Koutn=C3=BD?= , Muchun Song , Tejun Heo , Roman Gushchin , Shakeel Butt , Yosry Ahmed Subject: [PATCH v6 4/8] selftests/cgroup: rename PAGE_SIZE to BUF_SIZE in cgroup_util Date: Thu, 2 Apr 2026 14:37:10 +0800 Message-ID: <20260402063714.55124-5-liwang@redhat.com> In-Reply-To: <20260402063714.55124-1-liwang@redhat.com> References: <20260402063714.55124-1-liwang@redhat.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="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 The cgroup utility code defines a local PAGE_SIZE macro hardcoded to 4096, which is used primarily as a generic buffer size for reading cgroup and proc files. This naming is misleading because the value has nothing to do with the actual page size of the system. On architectures with larger pages (e.g., 64K on arm64 or ppc64), the name suggests a relationship that does not exist. Additionally, the name can shadow or conflict with PAGE_SIZE definitions from system headers, leading to confusion or subtle bugs. To resolve this, rename the macro to BUF_SIZE to accurately reflect its purpose as a general I/O buffer size. Furthermore, test_memcontrol currently relies on this hardcoded 4K value to stride through memory and trigger page faults. Update this logic to use the actual system page size dynamically. This micro-optimizes the memory faulting process by ensuring it iterates correctly and efficiently based on the underlying architecture's true page size. (This part from Waim= an) Signed-off-by: Li Wang Signed-off-by: Waiman Long Cc: Johannes Weiner Cc: Michal Hocko Cc: Michal Koutn=C3=BD Cc: Muchun Song Cc: Nhat Pham Cc: Tejun Heo Cc: Roman Gushchin Cc: Shakeel Butt Cc: Yosry Ahmed --- Notes: v6: - Use page_size instead of BUF_SIZE - Declear page_size as int but not size_t v5: - Merge Waiman's work into this patch (use page_size) v4: - Use page_size instead of BUF_SIZE in test_memcontrol.c v3, v2, v1: - No changes. .../selftests/cgroup/lib/cgroup_util.c | 18 +++++++++--------- .../cgroup/lib/include/cgroup_util.h | 4 ++-- tools/testing/selftests/cgroup/test_core.c | 2 +- tools/testing/selftests/cgroup/test_freezer.c | 2 +- .../selftests/cgroup/test_memcontrol.c | 19 ++++++++++++------- 5 files changed, 25 insertions(+), 20 deletions(-) diff --git a/tools/testing/selftests/cgroup/lib/cgroup_util.c b/tools/testi= ng/selftests/cgroup/lib/cgroup_util.c index 6a7295347e90..9be8ac256574 100644 --- a/tools/testing/selftests/cgroup/lib/cgroup_util.c +++ b/tools/testing/selftests/cgroup/lib/cgroup_util.c @@ -140,7 +140,7 @@ int cg_read_strcmp_wait(const char *cgroup, const char = *control, =20 int cg_read_strstr(const char *cgroup, const char *control, const char *ne= edle) { - char buf[PAGE_SIZE]; + char buf[BUF_SIZE]; =20 if (cg_read(cgroup, control, buf, sizeof(buf))) return -1; @@ -170,7 +170,7 @@ long cg_read_long_fd(int fd) =20 long cg_read_key_long(const char *cgroup, const char *control, const char = *key) { - char buf[PAGE_SIZE]; + char buf[BUF_SIZE]; char *ptr; =20 if (cg_read(cgroup, control, buf, sizeof(buf))) @@ -206,7 +206,7 @@ long cg_read_key_long_poll(const char *cgroup, const ch= ar *control, =20 long cg_read_lc(const char *cgroup, const char *control) { - char buf[PAGE_SIZE]; + char buf[BUF_SIZE]; const char delim[] =3D "\n"; char *line; long cnt =3D 0; @@ -258,7 +258,7 @@ int cg_write_numeric(const char *cgroup, const char *co= ntrol, long value) static int cg_find_root(char *root, size_t len, const char *controller, bool *nsdelegate) { - char buf[10 * PAGE_SIZE]; + char buf[10 * BUF_SIZE]; char *fs, *mount, *type, *options; const char delim[] =3D "\n\t "; =20 @@ -313,7 +313,7 @@ int cg_create(const char *cgroup) =20 int cg_wait_for_proc_count(const char *cgroup, int count) { - char buf[10 * PAGE_SIZE] =3D {0}; + char buf[10 * BUF_SIZE] =3D {0}; int attempts; char *ptr; =20 @@ -338,7 +338,7 @@ int cg_wait_for_proc_count(const char *cgroup, int coun= t) =20 int cg_killall(const char *cgroup) { - char buf[PAGE_SIZE]; + char buf[BUF_SIZE]; char *ptr =3D buf; =20 /* If cgroup.kill exists use it. */ @@ -548,7 +548,7 @@ int cg_run_nowait(const char *cgroup, =20 int proc_mount_contains(const char *option) { - char buf[4 * PAGE_SIZE]; + char buf[4 * BUF_SIZE]; ssize_t read; =20 read =3D read_text("/proc/mounts", buf, sizeof(buf)); @@ -560,7 +560,7 @@ int proc_mount_contains(const char *option) =20 int cgroup_feature(const char *feature) { - char buf[PAGE_SIZE]; + char buf[BUF_SIZE]; ssize_t read; =20 read =3D read_text("/sys/kernel/cgroup/features", buf, sizeof(buf)); @@ -587,7 +587,7 @@ ssize_t proc_read_text(int pid, bool thread, const char= *item, char *buf, size_t =20 int proc_read_strstr(int pid, bool thread, const char *item, const char *n= eedle) { - char buf[PAGE_SIZE]; + char buf[BUF_SIZE]; =20 if (proc_read_text(pid, thread, item, buf, sizeof(buf)) < 0) return -1; diff --git a/tools/testing/selftests/cgroup/lib/include/cgroup_util.h b/too= ls/testing/selftests/cgroup/lib/include/cgroup_util.h index 567b1082974c..febc1723d090 100644 --- a/tools/testing/selftests/cgroup/lib/include/cgroup_util.h +++ b/tools/testing/selftests/cgroup/lib/include/cgroup_util.h @@ -2,8 +2,8 @@ #include #include =20 -#ifndef PAGE_SIZE -#define PAGE_SIZE 4096 +#ifndef BUF_SIZE +#define BUF_SIZE 4096 #endif =20 #define MB(x) (x << 20) diff --git a/tools/testing/selftests/cgroup/test_core.c b/tools/testing/sel= ftests/cgroup/test_core.c index 7b83c7e7c9d4..88ca832d4fc1 100644 --- a/tools/testing/selftests/cgroup/test_core.c +++ b/tools/testing/selftests/cgroup/test_core.c @@ -87,7 +87,7 @@ static int test_cgcore_destroy(const char *root) int ret =3D KSFT_FAIL; char *cg_test =3D NULL; int child_pid; - char buf[PAGE_SIZE]; + char buf[BUF_SIZE]; =20 cg_test =3D cg_name(root, "cg_test"); =20 diff --git a/tools/testing/selftests/cgroup/test_freezer.c b/tools/testing/= selftests/cgroup/test_freezer.c index 97fae92c8387..160a9e6ad277 100644 --- a/tools/testing/selftests/cgroup/test_freezer.c +++ b/tools/testing/selftests/cgroup/test_freezer.c @@ -642,7 +642,7 @@ static int test_cgfreezer_ptrace(const char *root) */ static int proc_check_stopped(int pid) { - char buf[PAGE_SIZE]; + char buf[BUF_SIZE]; int len; =20 len =3D proc_read_text(pid, 0, "stat", buf, sizeof(buf)); diff --git a/tools/testing/selftests/cgroup/test_memcontrol.c b/tools/testi= ng/selftests/cgroup/test_memcontrol.c index 2fb096a2a9f9..acc748f4c878 100644 --- a/tools/testing/selftests/cgroup/test_memcontrol.c +++ b/tools/testing/selftests/cgroup/test_memcontrol.c @@ -25,6 +25,7 @@ =20 static bool has_localevents; static bool has_recursiveprot; +static int page_size; =20 int get_temp_fd(void) { @@ -33,7 +34,7 @@ int get_temp_fd(void) =20 int alloc_pagecache(int fd, size_t size) { - char buf[PAGE_SIZE]; + char buf[BUF_SIZE]; struct stat st; int i; =20 @@ -60,7 +61,7 @@ int alloc_anon(const char *cgroup, void *arg) char *buf, *ptr; =20 buf =3D malloc(size); - for (ptr =3D buf; ptr < buf + size; ptr +=3D PAGE_SIZE) + for (ptr =3D buf; ptr < buf + size; ptr +=3D page_size) *ptr =3D 0; =20 free(buf); @@ -69,7 +70,7 @@ int alloc_anon(const char *cgroup, void *arg) =20 int is_swap_enabled(void) { - char buf[PAGE_SIZE]; + char buf[BUF_SIZE]; const char delim[] =3D "\n"; int cnt =3D 0; char *line; @@ -112,7 +113,7 @@ static int test_memcg_subtree_control(const char *root) { char *parent, *child, *parent2 =3D NULL, *child2 =3D NULL; int ret =3D KSFT_FAIL; - char buf[PAGE_SIZE]; + char buf[BUF_SIZE]; =20 /* Create two nested cgroups with the memory controller enabled */ parent =3D cg_name(root, "memcg_test_0"); @@ -183,7 +184,7 @@ static int alloc_anon_50M_check(const char *cgroup, voi= d *arg) return -1; } =20 - for (ptr =3D buf; ptr < buf + size; ptr +=3D PAGE_SIZE) + for (ptr =3D buf; ptr < buf + size; ptr +=3D page_size) *ptr =3D 0; =20 current =3D cg_read_long(cgroup, "memory.current"); @@ -413,7 +414,7 @@ static int alloc_anon_noexit(const char *cgroup, void *= arg) return -1; } =20 - for (ptr =3D buf; ptr < buf + size; ptr +=3D PAGE_SIZE) + for (ptr =3D buf; ptr < buf + size; ptr +=3D page_size) *ptr =3D 0; =20 while (getppid() =3D=3D ppid) @@ -999,7 +1000,7 @@ static int alloc_anon_50M_check_swap(const char *cgrou= p, void *arg) return -1; } =20 - for (ptr =3D buf; ptr < buf + size; ptr +=3D PAGE_SIZE) + for (ptr =3D buf; ptr < buf + size; ptr +=3D page_size) *ptr =3D 0; =20 mem_current =3D cg_read_long(cgroup, "memory.current"); @@ -1670,6 +1671,10 @@ int main(int argc, char **argv) char root[PATH_MAX]; int i, proc_status; =20 + page_size =3D sysconf(_SC_PAGE_SIZE); + if (page_size <=3D 0) + page_size =3D BUF_SIZE; + ksft_print_header(); ksft_set_plan(ARRAY_SIZE(tests)); if (cg_find_unified_root(root, sizeof(root), NULL)) --=20 2.53.0