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 C7AEAC4345F for ; Thu, 2 May 2024 19:13:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4957B6B009C; Thu, 2 May 2024 15:13:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4453F6B009D; Thu, 2 May 2024 15:13:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2E5236B009E; Thu, 2 May 2024 15:13:57 -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 0A8176B009C for ; Thu, 2 May 2024 15:13:57 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id B2CC71C0C04 for ; Thu, 2 May 2024 19:13:56 +0000 (UTC) X-FDA: 82074405672.27.B240EDE Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) by imf30.hostedemail.com (Postfix) with ESMTP id B4E168000D for ; Thu, 2 May 2024 19:13:54 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="K/4bkL5R"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf30.hostedemail.com: domain of usamaarif642@gmail.com designates 209.85.221.45 as permitted sender) smtp.mailfrom=usamaarif642@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1714677234; 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=v7xERDFuJA/0OWgymjug68y27n1wkoWLTkEYX8JNLw8=; b=kSBHHLrjFsZjVN7ZN2Pip7DE5tyHm/jhSk9jirx+n3wB/1bhzGzAitMb6P3CUlEG4xHP2F LTbEnmCFKlv6Gk7sLYwb6UWpLBVork03Hvym5K2RrWO/Fg7cjn3KKnPt/i7Nr2ONUkxIU6 T9OkRZ3A7jUNmgX894jkSImDPvJUfYA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1714677234; a=rsa-sha256; cv=none; b=CiHA5ZTRaUWQNP1/Kb5s7Sgm4ZGa4AU5t4ZQhEfLfrGEdRKvvkEvttBi5Uk0jQXXQ72Djg 5pKNmxa5b99W38B6t4Dfjox2MN2knXUkwY13F+JLJTM94i//Z70C0srY/ppvG4MLs8hi+z pM3jVP/C9vlvANFnl8PKFAcSdIaGTXk= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="K/4bkL5R"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf30.hostedemail.com: domain of usamaarif642@gmail.com designates 209.85.221.45 as permitted sender) smtp.mailfrom=usamaarif642@gmail.com Received: by mail-wr1-f45.google.com with SMTP id ffacd0b85a97d-34cfd924eaeso3743441f8f.1 for ; Thu, 02 May 2024 12:13:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714677233; x=1715282033; darn=kvack.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=v7xERDFuJA/0OWgymjug68y27n1wkoWLTkEYX8JNLw8=; b=K/4bkL5R7Ogf8U3x//zCba0fdsSvIuafwoyfZiecnlyvUPj+9ELF+a/JPngcCdcisC mfwYva5wk16Lb3UNj8/p66Kb/ekmjoUj3oecXZiJh9oo4Mh2hCXjtIvWGfdHAoipqs8q 2Swbs/GdU9uFBTRiX/5VmaDfNJveXCvxDWvPg7GbIuXYrZWr0f+gzFoilbJ/lfvdaXFM 3Nc5dSnEf4Dv3EcCXtGSUBXD7YS15DSTyXpfgk8sMqoqGtLhJgkDPZjdKWz9xtgZysNh xevnk1Qw9k1sA6Jbu2VHpTnX/ZuMEAY8yx0U4gzgAiwlKVUzbsE7HtTmthM6c/V0jgkk jORQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714677233; x=1715282033; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=v7xERDFuJA/0OWgymjug68y27n1wkoWLTkEYX8JNLw8=; b=ke3mStSrVqM0A8gn5vCBNQf1Bo0Q3TKsVJ0Fm9aNXwJq2BFp8EiDX42tUE3cMvebmb juRoOYzyTDuVpFe5BPlM2ecZG8PCMRSvAOLKFQ/XlANuxkVLu7FWGzOoad71bhMrvGbA gKiVT7s8wVBDWIl3pLg6QcHyAaNgMMWKST0nZFGixmQSRB7BTRn1yRXpczlWWzWvRmxb +zo5eiQYDamILu1p9xMZuMnDTe9M1KzOqQIJVNxUZqlxysD7TL3NrYtUE1y9R9oS9lrP dFRpR00NiZCATm/NnCClxb3bdcp2VXJgwZXwx46mE7OoGa+z3NcPh1Az3b1ELn2DzwY2 o6OA== X-Forwarded-Encrypted: i=1; AJvYcCXRfC33lR/+cOk26+QqWxvl9GeEUEjs5XaO8JcaXKp4cFL0K2DyvFhJJHnSSy33VcSbs22qKBtQ/dYbk9pySFoaUcI= X-Gm-Message-State: AOJu0YxW2/noXYccrlrJqIrA+7qFrXOOT71nLXJnRDZHjQKo46xu+K2L pxUoXaQZ0JJfy4aNWiY1+k9esa19+XGr0W4QsD6Z+xkQmDu4oTTU X-Google-Smtp-Source: AGHT+IG0sXFqYpDGCdmsA4nZVVkTR4Vc9mf/7tEkWAuYoVCeKkTXc/VOSbLpnPcnSqA/IVKlgsESPA== X-Received: by 2002:adf:e88f:0:b0:34c:71a0:426c with SMTP id d15-20020adfe88f000000b0034c71a0426cmr490323wrm.37.1714677233059; Thu, 02 May 2024 12:13:53 -0700 (PDT) Received: from ?IPV6:2a02:6b6a:b75d:0:64:3301:4710:ec21? ([2a02:6b6a:b75d:0:64:3301:4710:ec21]) by smtp.gmail.com with ESMTPSA id cx14-20020a056000092e00b0034a2d0b9a4fsm1927591wrb.17.2024.05.02.12.13.52 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 02 May 2024 12:13:52 -0700 (PDT) Message-ID: <1e9383d8-98a7-4ef4-9c30-4f068fc38db1@gmail.com> Date: Thu, 2 May 2024 20:13:51 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] selftests: cgroup: add tests to verify the zswap writeback path To: Yosry Ahmed Cc: akpm@linux-foundation.org, hannes@cmpxchg.org, nphamcs@gmail.com, chengming.zhou@linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@meta.com References: <20240501100446.1454264-1-usamaarif642@gmail.com> Content-Language: en-US From: Usama Arif In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: B4E168000D X-Stat-Signature: a3s1emkinjn6and4ydj3kykirqnzghir X-Rspam-User: X-HE-Tag: 1714677234-518563 X-HE-Meta: U2FsdGVkX1+70kssR7CqTV7vLJYjvA2uqD7cTjCjo/51RA+2bErwrcQciwJ2QyJ6JLgw5Q1RkjnIPJyUgzAQT8Ir1jGpfpE41eBJQAjEBjTw7LxP3/EkoB+NfdCRuZwzdK0CHzRyWP+T+UNZ9ijiVUf2vJabHnRJgAJH3dx1V7ivsRIpRU95dn6vSQWi9JGG8029ckgMvDKsM2/S1JLChJTrSr7fbJSK2lb418LbuIQU7chVjCanPHv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xyiffa7YGNDOuFhWNVZdUe8E+wqcp40Qbl7+IQbDZCLwNxUJOSwjYIeD4Az45i8eXnUX/B92u48xySyG+ix4mj69j0S8ZyA7CLzll7VJObqTW94eUWMZQY6tWeT2z/sXVfNBuzxNdEIR8Uo4o0TRHimZDUgx8LH/TR0zDD8rIjilo6vxza1thRLm9p9dmc75L7HSzKBRMIwufrpMSBRVHitMJXJHURBMgoauNahsOs3YMSDMYXgMX3Xw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.053672, 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 01/05/2024 18:15, Yosry Ahmed wrote: > Hi Usama, > > On Wed, May 1, 2024 at 3:04 AM 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 working on this :) > >> 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 *arg) >> return 0; >> } >> >> +static int allocate_random_bytes(const char *cgroup, void *arg) >> +{ >> + size_t size = (size_t)arg; >> + char *mem = (char *)malloc(size); >> + >> + if (!mem) >> + return -1; >> + for (int i = 0; i < size; i++) >> + mem[i] = rand() % 128; >> + free(mem); >> + return 0; >> +} >> + >> static char *setup_test_group_1M(const char *root, const char *name) >> { >> char *group_name = 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 = KSFT_FAIL; >> + char *test_group; >> + long zswpwb_before, zswpwb_after; >> + >> + test_group = 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 = 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; > We set the zswap limit to 2M. So for this to work properly we need to > guarantee that the 3M of random data will compress into more than 2M. > Is this true for all possible zpool implementations and compression > algorithms? How likely for this to break and start producing false > negatives if zswap magically becomes more efficient? > > One alternative approach that I used before, although more complex, is > to start by compressing the memory (i.e. through reclaim) without a > zswap limit, and check the zswap usage. Then, fault the memory back > in, set the zswap limit lower than the observed usage, and repeat. > This should guarantee writeback AFAICT. > > Also, using memory.reclaim may be easier than memory.high if you > follow this approach, as you would need to raise memory.high again to > be able to decompress the memory. > Thanks for the review! I have sent a v2 with the method you described. I did like the simplicity of the method in this v1 a lot more, and we could have increased the random memory, which eventhough theoretically would mean it might not trigger a writeback if there was some new magic compression method, in practice it would always trigger it and work. Your suggestion which is in v2 covers both theory and practice :) >> + >> + /* Verify that zswap writeback occurred only if writeback was enabled */ >> + zswpwb_after = cg_read_key_long(test_group, "memory.stat", "zswpwb "); >> + if (wb) { >> + if (zswpwb_after <= zswpwb_before) { >> + ksft_print_msg("writeback enabled and zswpwb_after <= zswpwb_before\n"); >> + goto out; >> + } >> + } else { >> + if (zswpwb_after != zswpwb_before) { >> + ksft_print_msg("writeback disabled and zswpwb_after != zswpwb_before\n"); >> + goto out; >> + } >> + } >> + >> + ret = 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 memory >> * limit in zswap, writeback should affect only the zswapped pages of that >> @@ -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 >>