From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 944DA2FF643 for ; Sun, 8 Feb 2026 18:49:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770576545; cv=none; b=J7B96GXGeNq4f0Sj7uca1esqK2l+QfUqJT57pjWrTUX0QyVim+bzZ7caEnTiGPflZAvnLJYhr23JoB51qF6Do+rwuhq86Ikq9KS1hTEY1MlKYBkviY7zy3wjcuBDorBSripAxf3gCf1kQsubaM6zuyMM70/vy+YwpAxUd2kjBL4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770576545; c=relaxed/simple; bh=jbkOKX+7We/ed814ylwi+VmJ5YtwoCud7lki6vAYny8=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=c2D+To1sLLJLpwYxm/7rVViYyfae408zUML8X2WhfTqiGKxHPTkbkC9YTRFnnfMi4QYTAmUuaNPlwcJeASTQ4UaNbYTdxhQks3eGPfREonMOd53ErpTDoNI5ajmuD5oZqkWzDbap+dHmhJyhtPw0jVDV3pzKYGDaGeDewHzKlsU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=FLieK65i; arc=none smtp.client-ip=209.85.210.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FLieK65i" Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-81f39438187so2606236b3a.2 for ; Sun, 08 Feb 2026 10:49:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770576545; x=1771181345; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=ut1sGkenUeI9BD3BBVG16G8F8nlxjScJIq5pNB0m984=; b=FLieK65iSaA/+VgvWYvFCayVU/+JRn820zw0FFXth/biRGJS2kSErdw8/wq3tx12D/ Rop91pNnaDBdpldVStOsUu/sP50hpI2LT1v9qJc5xLA6x5tfM+DVe5ksQUi0dIwKVWpn 3ZV2jfRbcodYIDLE/FyEzGVWiXRBRIYX2bzkGlBR6vDcG6zl9toKrxHpdVDaZGxevRn1 aHF83doVlN+sVLNGs8JzYQJhnYmYyLQQ+x0mCSvMWw1znyZJSCvkGeRTPmuto5M02Dmn xN3wRng7vqwksKnlGGk0idnttjqyGCtrng0BI7xq2im6lX/5RJUMVVjjmy2A7VCRMq6D szew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770576545; x=1771181345; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ut1sGkenUeI9BD3BBVG16G8F8nlxjScJIq5pNB0m984=; b=KtvVJyg2Zd8nZKHn/ahna66v6nIVTPdneVtztRbAkv4/NsQC3poNgNcqE7/UBgMJqV Bc8xJtX5c3p742WS9RBpwrSLQ8/wpqmJwebM8hM49Woa2GL6eMHeq17/j0Kraw7AFvVO 5bgpVL8OPLag4Je9Nwttr6SnxeKnznVd2r0/FX9simEsSUnvm44e5quMSwoAE0ttJdSN MbpIqyH6ul3JNMjMLN6aVQ/doQFN6JfFy9Q41GymcJPMJDwD7WJ7Q/jS8Kaur9gdeftB 4F1t8KuGuMgtQLEFHTY5NIM0WCE5HpqENtTDi5SxNMbAIRdSZ8xuBQ5Eh6/YFnhJVryw 537w== X-Forwarded-Encrypted: i=1; AJvYcCW7nB9CsXYf38j65CyLzGrZfV5+0gwnAlEmcPK3OrLsY8IZZPFjtf4Y9O0623wZ2kdWVf6NvdcylcNt/LE=@vger.kernel.org X-Gm-Message-State: AOJu0YwMTra2LuwBpOiRQaUzR82W4aKYCw6aSq4TpyANXfD2Cg37P+1Q V3R+fzAU6/0qHSOodc7RUioIC2h/Jo0tj+m5+01evZGdemU4fBQp0Zl1 X-Gm-Gg: AZuq6aJ2bF/FlXmUA57rmWqencAQ8VXgKyAahG4S6D3CL3BWSRe1/vz8e3B8Xay8/KT aa74Gar7AB194kzW9yuqdNI2XA7HGdGlbKun6qipY08gv0p8PrD8KoB6yNFc8s/GJqUwc7HXnYF C32sdbhiRJsk6yuEuHSwX4ugVEi0i+o5GIXloL3kxQovZiRkR239As5BXBiPPP5LB8V550LmtDo qgQkqqMT81qr6EgdvF/JZmhb+hiiL9TIxj7xkshvvXq0H7jp+3XuaF/QrGOszJA5Aw27eOJ0yZu NjrFEX24koYNQ+vTabQ+g/K6BMSWscCp3wOUjJCcItd5SARj79VLTtPMLwjCIds7BoZandOCYdd rmn3XkRsN2iKSUHYbL4BPbFjahsA1OyVOEk9N44MPJuyWD7a6C6Ba8ycTroeJqlDQ8zDkDaYlX1 HKCdYEKdq3Az4yeAeLxXxU X-Received: by 2002:a05:6a20:d524:b0:2bf:183c:ac86 with SMTP id adf61e73a8af0-393ad00062amr8537931637.25.1770576544736; Sun, 08 Feb 2026 10:49:04 -0800 (PST) Received: from [192.168.4.196] ([73.222.117.172]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c6dcb3cb742sm7636288a12.0.2026.02.08.10.49.03 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 08 Feb 2026 10:49:04 -0800 (PST) Message-ID: <3d7e7e82-594c-4387-8dbd-2b78e888ead4@gmail.com> Date: Sun, 8 Feb 2026 10:49:02 -0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 2/2] selftests/cgroup: add test for zswap incompressible pages To: SeongJae Park , Jiayuan Chen Cc: linux-mm@kvack.org, Jiayuan Chen , Tejun Heo , Johannes Weiner , =?UTF-8?Q?Michal_Koutn=C3=BD?= , Jonathan Corbet , Michal Hocko , Roman Gushchin , Shakeel Butt , Muchun Song , Andrew Morton , Yosry Ahmed , Nhat Pham , Chengming Zhou , Shuah Khan , cgroups@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org References: <20260207013529.69681-1-sj@kernel.org> Content-Language: en-US From: JP Kobryn In-Reply-To: <20260207013529.69681-1-sj@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 2/6/26 5:35 PM, SeongJae Park wrote: > On Fri, 6 Feb 2026 15:22:16 +0800 Jiayuan Chen wrote: > >> From: Jiayuan Chen [...] >> diff --git a/tools/testing/selftests/cgroup/test_zswap.c b/tools/testing/selftests/cgroup/test_zswap.c >> index 64ebc3f3f203..8cb8a131357d 100644 >> --- a/tools/testing/selftests/cgroup/test_zswap.c >> +++ b/tools/testing/selftests/cgroup/test_zswap.c >> @@ -5,6 +5,7 @@ >> #include >> #include >> #include >> +#include >> #include >> #include >> #include >> @@ -574,6 +575,100 @@ static int test_no_kmem_bypass(const char *root) >> return ret; >> } >> >> +static int allocate_random_and_wait(const char *cgroup, void *arg) >> +{ >> + size_t size = (size_t)arg; >> + char *mem; >> + int fd; >> + ssize_t n; >> + >> + mem = malloc(size); >> + if (!mem) >> + return -1; >> + >> + /* Fill with random data from /dev/urandom - incompressible */ >> + fd = open("/dev/urandom", O_RDONLY); >> + if (fd < 0) { >> + free(mem); >> + return -1; >> + } >> + >> + for (size_t i = 0; i < size; ) { >> + n = read(fd, mem + i, size - i); >> + if (n <= 0) >> + break; >> + i += n; >> + } >> + close(fd); >> + >> + /* Touch all pages to ensure they're faulted in */ >> + for (size_t i = 0; i < size; i += 4096) > > Nit. I show test_zswapin() is using PAGE_SIZE. Maybe the above code can also > use it? > >> + mem[i] = mem[i]; >> + >> + /* Keep memory alive for parent to reclaim and check stats */ >> + pause(); >> + free(mem); >> + return 0; >> +} >> + >> +static long get_zswap_incomp(const char *cgroup) >> +{ >> + return cg_read_key_long(cgroup, "memory.stat", "zswap_incomp "); >> +} >> + >> +/* >> + * Test that incompressible pages (random data) are tracked by zswap_incomp. >> + * >> + * Since incompressible pages stored in zswap are charged at full PAGE_SIZE >> + * (no memory savings), we cannot rely on memory.max pressure to push them >> + * into zswap. Instead, we allocate random data within memory.max, then use >> + * memory.reclaim to proactively push pages into zswap while checking the stat >> + * before the child exits (zswap_incomp is a gauge that decreases on free). >> + */ >> +static int test_zswap_incompressible(const char *root) >> +{ >> + int ret = KSFT_FAIL; >> + char *test_group; >> + long zswap_incomp; >> + pid_t child_pid; >> + int child_status; >> + >> + test_group = cg_name(root, "zswap_incompressible_test"); >> + if (!test_group) >> + goto out; >> + if (cg_create(test_group)) >> + goto out; >> + if (cg_write(test_group, "memory.max", "32M")) >> + goto out; >> + >> + child_pid = cg_run_nowait(test_group, allocate_random_and_wait, >> + (void *)MB(4)); >> + if (child_pid < 0) >> + goto out; >> + >> + /* Wait for child to finish allocating */ >> + usleep(500000); > > We might be better to revisit here in future to avoid racy test results. But > this seems good enough for now. How about using some form of synchronization like an eventfd? The parent can wait here for the child to write the event and avoid the race with the arbitrary sleep.