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 271E7C4345F for ; Thu, 2 May 2024 23:31:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AFBD96B009A; Thu, 2 May 2024 19:31:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AABE86B009B; Thu, 2 May 2024 19:31:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 973556B009C; Thu, 2 May 2024 19:31:05 -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 71D636B009A for ; Thu, 2 May 2024 19:31:05 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 2CF8E1C081F for ; Thu, 2 May 2024 23:31:05 +0000 (UTC) X-FDA: 82075053690.07.C577E36 Received: from mail-ua1-f52.google.com (mail-ua1-f52.google.com [209.85.222.52]) by imf30.hostedemail.com (Postfix) with ESMTP id 705A080003 for ; Thu, 2 May 2024 23:31:03 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="BC4z/QYh"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf30.hostedemail.com: domain of nphamcs@gmail.com designates 209.85.222.52 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=1714692663; 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=t7HSYA3SAE5+eP7zUudXzBfNTptQeJcVL00rOgFP/iY=; b=huxNWSLej3UbjTkPgJoZx1i9uHVwcaCQFgSCeDAMFtKSaqw1lkpoNYcOsjy9PdkG2bdS54 Myw1jxkzmWR3thr/5q0XRkutICVuden6u9zWmetNbJasvEgSPcy5owVkSscoqZc/muX0G+ 9cBqsmNPmcSbH/a4jigY4j/XeM2zsLI= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="BC4z/QYh"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf30.hostedemail.com: domain of nphamcs@gmail.com designates 209.85.222.52 as permitted sender) smtp.mailfrom=nphamcs@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1714692663; a=rsa-sha256; cv=none; b=cFI9kPRLw2gDyhoQ0TrdS5dOg+jC3ypeM4q2dIw0qjilvRGX9Q13dmKYwQPmq8d69R7HVw In8UwALAs6UaIkqkKMpymNR3jhJIdfJUGrTP9M/ZkCftSmWsTzC2yoV20h2NTaftdZEyFM 7OQhSy33txkeQX4VcMu89go331JTcN0= Received: by mail-ua1-f52.google.com with SMTP id a1e0cc1a2514c-7f169d3ef53so1124177241.1 for ; Thu, 02 May 2024 16:31:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714692662; x=1715297462; 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=t7HSYA3SAE5+eP7zUudXzBfNTptQeJcVL00rOgFP/iY=; b=BC4z/QYhBtOnrHgPZqJ+vk5pXy8PmgB3eMq22P5BHrWw6G/8FB8dDGb9Fe5kSV0ZvY l+ikl5aqCB+ADYFLybMTP19hu9k7i1c2dCPAACAzPP0rHjFhmHNfa7S12lAnevuLzd86 L8dJ6bKXQ2OXcTsqMzdIbL4KpsGFEniQUl3jZ7KeN+WBy5Be/FlFawijYVxJhwtv3deS oLK8GywZQTDT8fty4ci7+ducIEoCp7VuhExBnbbGUJUvMXE2WHgZM2mafbJXaN78gBSA YDqGJ6kpnCbFgcQPt/jtAUOuJw+gdlDnXNhvg12zdPl3fOPxaPLwo4Hch1KLHbi6fIU0 C7Xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714692662; x=1715297462; 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=t7HSYA3SAE5+eP7zUudXzBfNTptQeJcVL00rOgFP/iY=; b=WwwLEe2NsV1ViqFGtVBdpSChhdJNFSDrRNo3k9ZAMSZ1eVnJ4IjH3qdXdMLCXQPL/g mz8HmeCjzK5NMZN0USJjRt1johhdbM2C0r2+CdmhiBkHTriq0jl4Ix+HV+jb2+JSIXWT EUV40LWIV+sodD+6NiKjLEoawOXAHX//iXIT1l1Y3+jBaMSpaKW0KG8N30O3dc2f7f+q tFRDw5DCz34spMihBGBwAEm1pWpmk2SyG28Hd1znAF0QE1ZKXKNZX0ZCT8L+iRG1pNyh zaTuXskCs71BXf0SQZKlPymE+eurupzI0bdB9vfr4MKZs56Y6jOeex3Q8gCKc3aLn9vE dR8w== X-Forwarded-Encrypted: i=1; AJvYcCW+IPQRZ4bqb2EPQ63q1kXvT657sn+lfpXiXM3OB5QAkq4+uuQTYY2eWGcJ8rKJszkDebPwlOdhbSX972AhgeA53R8= X-Gm-Message-State: AOJu0Yy7E0bznMsXa1wuakdL/tg2yMaRWRMTc5hPIChuJO3HE7hwb3PH 5feE5GX3kVDhwAG52Gt8KHuZlmBEPGjYcgThIKk0jC9uWB0cOA5+CI2KIb8iNrLLEG2940jA4GM kHKTOKpSMaDh3VLwYQUWVfRGH+P0= X-Google-Smtp-Source: AGHT+IFvFR+KtCwDF/iF8MGRYco7iaU0ctLQLNYm1AvCvx89JOMXySoFJmFYYC5bHfUN4zYCVqIOUqTRb8UfyJmo+rI= X-Received: by 2002:a05:6122:469e:b0:4da:e777:a8e6 with SMTP id di30-20020a056122469e00b004dae777a8e6mr1356370vkb.14.1714692662103; Thu, 02 May 2024 16:31:02 -0700 (PDT) MIME-Version: 1.0 References: <20240501100446.1454264-1-usamaarif642@gmail.com> In-Reply-To: From: Nhat Pham Date: Thu, 2 May 2024 16:30:49 -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-Stat-Signature: 1mrwczo7hrrykowudpzin7tatnx98xis X-Rspamd-Queue-Id: 705A080003 X-Rspam-User: X-Rspamd-Server: rspam12 X-HE-Tag: 1714692663-145592 X-HE-Meta: U2FsdGVkX18lnkaMOBsocRf/AcBLWCks4eUD3gJ1BFl+YNsgiKT2UaUcfWrQgZxyP+Jul9GXAlDGzbRCm4oF+zXx724HOcW/z9E37ELEowpPONpLxHJZGkOW2XQKRBkJTDqRmOqRa/jZ3UQMObjCTRbyVLmgKw+/Ilvijmrbjaab9enXctKlKtSfEwcb3tQi4p7niWnhPK2b4pVpOyzTo7M7E6oeMjuYR0hOu+ByEgYti66iiTLIA5AmIb7NiOsAOn48+SKcK7UVbplL7yGRBkezuP8buXeXob4v0CzD1L1If4a0/myyEzhS4zUykIie8m/CsiNP+5ohU6rLXMMJHOevhzQD6XXOg547l0mquOUGyvsasTMEc5WtLx+P2APHfHp/bsGDiUUF+D0yLBUtq0NJrtUlPPlPKVvI/GwcWNjuCTN/k6GLxCzGOWvLJnfZjc+eL4aVPPKugOM7OHZk1Smlc/AZyNEiqLYvKsoLiIR/G7Wfxo5YhVX9gMt9r+DscI8tiSCV5QiiO9JxmqIjowqs4D4p6KbAJ0A61gBy2gugU9MjcZOvZXf4+m5hOXaLTtBhuA2Rb7jdg6rgb2m7QAsJ2dfIIOdbINYUzqksFNR8n6pk0mtMzOlfsW5NX96A6v8+uF6Gnx9v3gARejhVNZJLjx9SGOf/ZcEUj1FTi2e7Y4CPx+d55L4TuXb9vPSAEP2CDXxwQiN5iu+qZqm2QGMd002ypCYYk9c0JZ+eFeVPuwsHg04ZtXQOBimCLwlmuEFGsg4gN8/1z9jgpZmtl3Xq7rpPNjKveYuzf008JGpcYQ/GpcLOUM+/Z701Vc7u6M+5b8adbfZSx0OO8CIQlbTuRlPJPfQIC7eGm+YH+3kRviPqYqV62LxyEAia9+yZXSjfmaDfKq2w1DBj1eWa+7g2BvL1g6ABpmuYLUdl2TQXLJdwy+3v8URCQ825zlpF7EGf4/0JtOLFG+rav99 KF0LHG8P tghlTjMY/c9malMg6oui+TRCFXKu0r7QS84WDm2TfxaLZ68vdD5FUburztGtrq75WuthNO2jfSQoaLmNhIHCoY714gLXxBmRq1d+YMBKpCY4Hy2R25J7LW6CmqtqdhC26w9SCa7rH1I7NJbpoCbV0aqF2tTkAUg7CTgzw6vp7LiftxZKJH3KE/ZTDi0kBtxuzOV9Z9f7WshCLLtwxGdba4xEXm0lsHHv3vN8nxUCNFwgBFDMcTmm1/fZjuroIg2pw5IvHR5t3/WiiOAnS+bzpCQXA2HKuX9w5KSfgOfHnPf3x+TDsI++LyRaElsjD31tWESKc X-Bogosity: Ham, tests=bogofilter, spamicity=0.176395, 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 Thu, May 2, 2024 at 12:05=E2=80=AFPM Usama Arif = wrote: > > > On 01/05/2024 16:44, Nhat Pham wrote: > > 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/testi= ng/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 = *arg) > >> 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= _disabled_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", = "zswpwb "); > >> + 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? > > Thanks for the review! I have added doc in v2 explaining why random > memory is used. > > > >> + > >> + /* Verify that zswap writeback occurred only if writeback was = enabled */ > >> + zswpwb_after =3D cg_read_key_long(test_group, "memory.stat", "= zswpwb "); > >> + if (wb) { > >> + if (zswpwb_after <=3D zswpwb_before) { > >> + ksft_print_msg("writeback enabled and zswpwb_a= fter <=3D zswpwb_before\n"); > >> + goto out; > >> + } > >> + } else { > >> + if (zswpwb_after !=3D zswpwb_before) { > >> + ksft_print_msg("writeback disabled and zswpwb_= after !=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 :) > > I think with the method in v2, this might not be easily tracked as some > metrics are all time (zswpout) while others are current. Hmm would pgsteal be a good candidate for this purpose? Just throwing out ideas - I'll leave this up to you to decide :)