From nobody Mon Apr 6 10:43:23 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 6621C361DA1 for ; Sun, 22 Mar 2026 06:11:28 +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=1774159889; cv=none; b=ZWy53t+dCxpRkWua54hENVSEa741N7mlOn8seirPNzwJ6mfkuOetiE3EoBtOD2ORw4Ulpb3mXO/bxDYo6ZYFJA2ndGH56TO5iDjdVf/YAA+Mm1jX9TC2dnae/5P5jzEwJTdi3GL0XvbG6MpVehzfjPJAY/aWprhacudevBC3eb4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774159889; c=relaxed/simple; bh=4JEq0xim6x1akSTc3YUYcMej5O5xD3wYlWtzBFff63E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=OT3FB8vc5GReuUPQGQeNT7eKAQLifFh3R3lxo1Tl+Lw7bxBjApF0f2r/GiD5WQ9rb2ismqInKRxk3zNknpDCYfcz5duqy3w1zE6zUl+J2wgmNNZZp7I4tqMp1qyEV8ijp/AYOLa+7SV16hEP7jWVXdwKM/Ty+IkJ8hD6NzkmmOI= 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=IgNUbFg9; 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="IgNUbFg9" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1774159887; 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=BHzuD1Q+ozuE+fNEcVbskPPcDVZUs5YK4U0mB0xkA0M=; b=IgNUbFg97lVh9eZb/BOpDPAnGuGZwjR0HeUMLxFHhza/Cf5M+Gfej1c+D/epI4toosIs1K lJN/KBjIcepFhc14Xs50px7cq+tXMp50ee07uLG2f7Ohgck2G0Y8FdWMoxcW3Q4U8ijraM 5Tc0ifp3f3xL+lKvXstUQhcdtctWgpo= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-550-CjW01H6BN4CvfivfR703GA-1; Sun, 22 Mar 2026 02:11:21 -0400 X-MC-Unique: CjW01H6BN4CvfivfR703GA-1 X-Mimecast-MFC-AGG-ID: CjW01H6BN4CvfivfR703GA_1774159880 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 9EB4A195608D; Sun, 22 Mar 2026 06:11:19 +0000 (UTC) Received: from fedora-laptop-x1.redhat.com (unknown [10.72.112.34]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 86C941955F21; Sun, 22 Mar 2026 06:11:13 +0000 (UTC) From: Li Wang To: akpm@linux-foundation.org, yosry@kernel.org, yosryahmed@google.com, nphamcs@gmail.com, hannes@cmpxchg.org, mhocko@kernel.org, mkoutny@suse.com, muchun.song@linux.dev, tj@kernel.org, roman.gushchin@linux.dev, shakeel.butt@linux.dev Cc: longman@redhat.com, liwang@redhat.com, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v4 4/7] selftests/cgroup: rename PAGE_SIZE to BUF_SIZE in cgroup_util Date: Sun, 22 Mar 2026 14:10:35 +0800 Message-ID: <20260322061038.156146-5-liwang@redhat.com> In-Reply-To: <20260322061038.156146-1-liwang@redhat.com> References: <20260322061038.156146-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.0 on 10.30.177.12 The cgroup utility code defines a local PAGE_SIZE macro hardcoded to 4096, which is used solely as a generic buffer size for reading cgroup and proc files. This is misleading because the value has nothing to do with the actual page size of the system, and 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 the PAGE_SIZE definition from system headers, leading to confusion or subtle bugs. Rename it to BUF_SIZE to accurately reflect its purpose as a general I/O buffer size. No functional change. Signed-off-by: Li Wang 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: v4: - Use page_size instead of BUF_SIZE in test_memcontrol.c =20 v3, v2, v1: - No changes. .../testing/selftests/cgroup/lib/cgroup_util.c | 18 +++++++++--------- .../selftests/cgroup/lib/include/cgroup_util.h | 4 ++-- tools/testing/selftests/cgroup/test_core.c | 2 +- tools/testing/selftests/cgroup/test_freezer.c | 2 +- .../testing/selftests/cgroup/test_memcontrol.c | 15 ++++++++------- 5 files changed, 21 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 ce6c2642fd9b..0be525ed11db 100644 --- a/tools/testing/selftests/cgroup/lib/cgroup_util.c +++ b/tools/testing/selftests/cgroup/lib/cgroup_util.c @@ -125,7 +125,7 @@ int cg_read_strcmp(const char *cgroup, const char *cont= rol, =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; @@ -155,7 +155,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))) @@ -191,7 +191,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; @@ -243,7 +243,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 @@ -298,7 +298,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 @@ -323,7 +323,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. */ @@ -533,7 +533,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)); @@ -545,7 +545,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)); @@ -572,7 +572,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 77f386dab5e8..ca4a161c17a4 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 102262555a59..df7fac7e5554 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..2a8d887a849f 100644 --- a/tools/testing/selftests/cgroup/test_memcontrol.c +++ b/tools/testing/selftests/cgroup/test_memcontrol.c @@ -33,7 +33,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 @@ -57,10 +57,11 @@ int alloc_pagecache(int fd, size_t size) int alloc_anon(const char *cgroup, void *arg) { size_t size =3D (unsigned long)arg; + size_t page_size =3D sysconf(_SC_PAGESIZE); 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 BUF_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 BUF_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 BUF_SIZE) *ptr =3D 0; =20 mem_current =3D cg_read_long(cgroup, "memory.current"); --=20 2.53.0