From mboxrd@z Thu Jan 1 00:00:00 1970 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 EBB5CC4345F for ; Wed, 1 May 2024 15:44:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5B0516B008A; Wed, 1 May 2024 11:44:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 55FF66B008C; Wed, 1 May 2024 11:44:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 427D46B0092; Wed, 1 May 2024 11:44:59 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 264086B008A for ; Wed, 1 May 2024 11:44:59 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 774B11A08C0 for ; Wed, 1 May 2024 15:44:58 +0000 (UTC) X-FDA: 82070250276.21.AB60F1A Received: from mail-qv1-f54.google.com (mail-qv1-f54.google.com [209.85.219.54]) by imf04.hostedemail.com (Postfix) with ESMTP id 8D40C4001E for ; Wed, 1 May 2024 15:44:56 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=doCfbgym; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf04.hostedemail.com: domain of nphamcs@gmail.com designates 209.85.219.54 as permitted sender) smtp.mailfrom=nphamcs@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1714578296; h=from:from:sender: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:dkim-signature; bh=VC8US8zol/yb8tjvLb5M0Qn8qmdzxZDnXFO7sbqgY2U=; b=MU5fGmueFSw6HpP2G0qM7/xHy/YaMj6D+6HYIJ0P9RGhIRkLNxjTsHgHhibPpccMcw9PLM TUereyTckSlOeL4KBxbZVXxppHIrAB+s7rLMuHDJwCt83HSm9Ux7dyNKyCVRc3u+uX0zja O7z9lOFj3o32xz33vWJ+iofo4SBTuxs= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=doCfbgym; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf04.hostedemail.com: domain of nphamcs@gmail.com designates 209.85.219.54 as permitted sender) smtp.mailfrom=nphamcs@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1714578296; a=rsa-sha256; cv=none; b=iaYvoG4du6quHR27b2D9cA/bb2w+L+rrnGfNXFm9PvDfem9/eEoGcXSBHKff1fa5De+GB0 san0N3XunVY9fRoMxYtw62psZadPa8GyytjTTzyFC+Nh9mEqnhJJO9mPQpljv9C46BIhIh d9vi4dQT7vYq28l08wmIxLvdvFFMtpI= Received: by mail-qv1-f54.google.com with SMTP id 6a1803df08f44-6a0c8fb3540so9073166d6.1 for ; Wed, 01 May 2024 08:44:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714578295; x=1715183095; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=VC8US8zol/yb8tjvLb5M0Qn8qmdzxZDnXFO7sbqgY2U=; b=doCfbgymrQ55yw88AOg8YrO3kjUoPAciQBMj83pBcybiaBYP8E91XLiU01IA0cquUr SYTah3bDD3vPEWUjxNHkZqbmM4elAHcdcpUxjx0Cyd/4HIGSpsDmM0xlfriKh+/o8pIH k71z5IpngejBuU3ElK+ofq+ubmEcurtckrf9CUm0PnvNBgqDmzsA4szvU0wmvlZxWC6w ZIeflt6bATuEIMeqWBMhy032mCE0Sswo7LrjAFMJMx6ayiF/rfIlR133gyzngV855FDV IG7zVB2Ywz7zjo8BRy9EnaX9V5drR2gImDGAcIhiupjuLkZY3ToE+p14YtFk955hCkoI T4Vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714578295; x=1715183095; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VC8US8zol/yb8tjvLb5M0Qn8qmdzxZDnXFO7sbqgY2U=; b=IZzavbHtu4euVxMjpZv9oiWg3EBrUe4BiUve62yY8lf2w9qHEffWUGDekaqV+xkrUw iXG9E/eWvXYX295BTDksbOvuuAQ8knS53UIRKTGtiS6URtPM5YadNQOETHPZArglAMAM qpg48+j4T8m8FSXujz1IdNi+pDLfmKvODKXAN+MK5fVheyGAyDQSJCx2ly1iOZzeJKVb FYU6xQ9Igf/eS1xiUJtY/peArQlnMRVB9Lj+AIi+jyC+Antw1LjTwZ/j4FTFWagik+x3 iwSI4cwrHoazTD9E8OtyfUOkyBTyJHaQAsoyKI9wl5fcwoTc1nxGGqjp3ADpkAPmUrBd +oug== X-Forwarded-Encrypted: i=1; AJvYcCWS/rynrLcJHmx/sEEn/duNcWa4axEEdAC5yCykSKfZbyB463yJGKiK1UhGv51ngfyqpbs53pa1oHHHyzw6QW3iDDk= X-Gm-Message-State: AOJu0YxgZe82hCR5e4SypbR/cSQ/2153Y8tmiz9OQ0QfEK05ENpv90qu o/o3NX+k7iL3OtqTgKrSGdyu20LhZmyspi3Q6Fti8nHcBbyhEIrZ/S4xyeT003jRWnxIVR4Qavx O/WsBASX7UwMCHyLZEfOEWNokg5Y= X-Google-Smtp-Source: AGHT+IF3EGxuWVKHuHy3OXH0g4H/nbl1Vs9oLcMOr/2/LCZSd8+Ytw/9AuCX0u+xvshJ/BU4ulSodFpuLP+7OMzfH4E= X-Received: by 2002:a05:6214:5651:b0:6a0:f637:667 with SMTP id mh17-20020a056214565100b006a0f6370667mr70464qvb.12.1714578295498; Wed, 01 May 2024 08:44:55 -0700 (PDT) MIME-Version: 1.0 References: <20240501100446.1454264-1-usamaarif642@gmail.com> In-Reply-To: <20240501100446.1454264-1-usamaarif642@gmail.com> From: Nhat Pham Date: Wed, 1 May 2024 08:44:42 -0700 Message-ID: Subject: Re: [PATCH] selftests: cgroup: add tests to verify the zswap writeback path To: Usama Arif Cc: akpm@linux-foundation.org, hannes@cmpxchg.org, yosryahmed@google.com, chengming.zhou@linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@meta.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspam01 X-Stat-Signature: j5o85idcxyhrwzibmzpuwbnryqkwr1zi X-Rspam-User: X-Rspamd-Queue-Id: 8D40C4001E X-HE-Tag: 1714578296-48062 X-HE-Meta: U2FsdGVkX1/BPFjEb9OUjBfCkCZSeAVtxlykkSyP26ohPHQrYVwRP26O7Ez/Ad6fK6VMOfXuh9QDHcsblIux1Q+H79hmZjaW43ZQBMUvh0CH6Q37DLeYCRT4hzDNbS+3gVXqExvfVPfRa2tSEhg1SngF9GU4DvIX0H5w+is2onxIX7rhKMf768YAr6P+43dJ1McrWOx6vg+oEa3Ib0dZTZqizaMhQoq5UbUBNiTJSidOC8PMumr64LAxiC5fxM7Da5FMfNGZTiVolneaIfrAoYcddq84DH+VwSaj9Oru2Q0zvXWDNBBxvmyXHL36Py9DF7AvQfFwZFK3Ca6FiYolbm4jcR24fA27l1YRClzy3MyeCl9PZAKggHH4/WygFdLiFdA7kRWmZuRpVes5SZxNPEAVhny4VlJiyqjXywAFONWePjXm+vApB/mPYPOL3AQKmDl6pzKBBeD2RE+SPKbwUtradtEO6SXU73oZ5uiubouU2/hkwCF5kS47WAKCdZ4tw4oGQMYdd4zw7Q6MLRvqUhOyWv0jWj/0EkiJggL5K++eo2L9YKW7tF2hGbQUWRd79NgPaIlUOLwHaL3O+2vvHOgAK3/YPp8/TJtIiik/hEBB0mtltWKWYlZkDo6h/cbcTYHZQaATi7OkkLtwBDRFdAheKpNSYmsLHwD0r1w6G1C6yn6Vm64cbkSEpaMFCbP1Hw3YzsendeYf6TuJBayncHiHJHvxN6QnRnHxLAiGld4KZS58ubqdUCEk8keqwjDmSMxBpiNL0NJaxVU5d82NpW2QKM+jG1tzz//toShAWga+ylpeCABupHEHjBAvaLV1JjMj1vaEfZUeNzG8OGK26l1vNc+V5bGtBnf3dvlRSiipyhIvoNnFzAX9NK3nRV9cy85j20E04AfpnN8skzyIYhn8iOy9NeY2zLEo3qzI89+nSiVutx+4Wrr9zYngg5IveTCV7hxXGt2E7nZpH+s aScd61oz FOqMwhfkyRtZx2Q+4g787296ch/yCSxHMR69lCdxpVkHBxJj2BZ9GogHo8YM82u7G4ytFzDbQDIrK950rwX8IeAlzXyGnbMmVJe06TTsegS6hE8M9HMzfy2uyk9PC/A/NnhEAt20vSRFuT5erks4G1FhLQJcfGuiANRATNfbLWyPe/fTRfyz4ARSoBUuxdy2tzvDaMYDtTAlS/+94kPtyWdMDSHmoN5BBIBIUcB2KJ5Yn9fIew5Z9x3ioSXHvCYqpZuJzdOowV95JRCaUDMMZ85YTjjwRHu8kt3SwxOUyx2hVWVBlNmvb9i2uPNNRFkS7Ofb2+B+HexOo55flSX7NQqaANhFqUJMRBeFzf4/tNqXlwqrSElvTXakJgp8Gj+J3gx0T8OsIgBf49qBERjtHLTS9wtDINtYkEje8 X-Bogosity: Ham, tests=bogofilter, spamicity=0.237739, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Wed, May 1, 2024 at 3:04=E2=80=AFAM Usama Arif = wrote: > > The condition for writeback can be triggered by allocating random > memory more than memory.high to push memory into zswap, more than > zswap.max to trigger writeback if enabled, but less than memory.max > so that OOM is not triggered. Both values of memory.zswap.writeback > are tested. Thanks for adding the test, Usama :) A couple of suggestions below. > > Signed-off-by: Usama Arif > --- > tools/testing/selftests/cgroup/test_zswap.c | 83 +++++++++++++++++++++ > 1 file changed, 83 insertions(+) > > diff --git a/tools/testing/selftests/cgroup/test_zswap.c b/tools/testing/= selftests/cgroup/test_zswap.c > index f0e488ed90d8..fe0e7221525c 100644 > --- a/tools/testing/selftests/cgroup/test_zswap.c > +++ b/tools/testing/selftests/cgroup/test_zswap.c > @@ -94,6 +94,19 @@ static int allocate_bytes(const char *cgroup, void *ar= g) > return 0; > } > > +static int allocate_random_bytes(const char *cgroup, void *arg) > +{ > + size_t size =3D (size_t)arg; > + char *mem =3D (char *)malloc(size); > + > + if (!mem) > + return -1; > + for (int i =3D 0; i < size; i++) > + mem[i] =3D rand() % 128; > + free(mem); > + return 0; > +} > + > static char *setup_test_group_1M(const char *root, const char *name) > { > char *group_name =3D cg_name(root, name); > @@ -248,6 +261,74 @@ static int test_zswapin(const char *root) > return ret; > } > > +/* Test to verify the zswap writeback path */ > +static int test_zswap_writeback(const char *root, bool wb) > +{ > + int ret =3D KSFT_FAIL; > + char *test_group; > + long zswpwb_before, zswpwb_after; > + > + test_group =3D cg_name(root, > + wb ? "zswap_writeback_enabled_test" : "zswap_writeback_di= sabled_test"); > + if (!test_group) > + goto out; > + if (cg_create(test_group)) > + goto out; > + if (cg_write(test_group, "memory.max", "8M")) > + goto out; > + if (cg_write(test_group, "memory.high", "2M")) > + goto out; > + if (cg_write(test_group, "memory.zswap.max", "2M")) > + goto out; > + if (cg_write(test_group, "memory.zswap.writeback", wb ? "1" : "0"= )) > + goto out; > + > + zswpwb_before =3D cg_read_key_long(test_group, "memory.stat", "zs= wpwb "); > + if (zswpwb_before < 0) { > + ksft_print_msg("failed to get zswpwb_before\n"); > + goto out; > + } > + > + /* > + * Allocate more than memory.high to push memory into zswap, > + * more than zswap.max to trigger writeback if enabled, > + * but less than memory.max so that OOM is not triggered > + */ > + if (cg_run(test_group, allocate_random_bytes, (void *)MB(3))) > + goto out; I think we should document better why we allocate random bytes (rather than just using the existing allocation helper). This random allocation pattern (rand() % 128) is probably still compressible by zswap, albeit poorly. I assume this is so that zswap would not be able to just absorb all the swapped out pages? > + > + /* Verify that zswap writeback occurred only if writeback was ena= bled */ > + zswpwb_after =3D cg_read_key_long(test_group, "memory.stat", "zsw= pwb "); > + if (wb) { > + if (zswpwb_after <=3D zswpwb_before) { > + ksft_print_msg("writeback enabled and zswpwb_afte= r <=3D zswpwb_before\n"); > + goto out; > + } > + } else { > + if (zswpwb_after !=3D zswpwb_before) { > + ksft_print_msg("writeback disabled and zswpwb_aft= er !=3D zswpwb_before\n"); > + goto out; > + } It'd be nice if we can check that in this case, the number of pages that are "swapped out" matches the cgroup's zswpout stats :) > + } > + > + ret =3D KSFT_PASS; > + > +out: > + cg_destroy(test_group); > + free(test_group); > + return ret; > +} > + > +static int test_zswap_writeback_enabled(const char *root) > +{ > + return test_zswap_writeback(root, true); > +} > + > +static int test_zswap_writeback_disabled(const char *root) > +{ > + return test_zswap_writeback(root, false); > +} > + > /* > * When trying to store a memcg page in zswap, if the memcg hits its mem= ory > * limit in zswap, writeback should affect only the zswapped pages of th= at > @@ -425,6 +506,8 @@ struct zswap_test { > T(test_zswap_usage), > T(test_swapin_nozswap), > T(test_zswapin), > + T(test_zswap_writeback_enabled), > + T(test_zswap_writeback_disabled), > T(test_no_kmem_bypass), > T(test_no_invasive_cgroup_shrink), > }; > -- > 2.43.0 >