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 79565C4345F for ; Fri, 3 May 2024 15:11:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AD12A6B0093; Fri, 3 May 2024 11:11:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A80756B0098; Fri, 3 May 2024 11:11:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 949146B0099; Fri, 3 May 2024 11:11:16 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 784916B0093 for ; Fri, 3 May 2024 11:11:16 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 2B2F51A0E9B for ; Fri, 3 May 2024 15:11:16 +0000 (UTC) X-FDA: 82077422952.07.473C54B Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) by imf17.hostedemail.com (Postfix) with ESMTP id 315FD4001F for ; Fri, 3 May 2024 15:11:13 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=IiXBT3aa; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf17.hostedemail.com: domain of usamaarif642@gmail.com designates 209.85.128.49 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=1714749074; 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=u+3HzXMAKOQPznx02Kq/PyKDV/8AD6lCk3ecRCC6kGo=; b=uC3t2k1XAvq2Q4WN28NQmwsrr312mej5r5nt/czZoSN3sZVZx5zqI6/ckuGMSxpfWXBSbK 6olzfLX0L6/YKUJjzEBLR5E4ZXG2rqbF345XSHmedwxrIz7OQ6YQkTfJh92VCoopNuNxTu zut6UMXWm9N68XrofCcwqbF2cwMQD/E= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=IiXBT3aa; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf17.hostedemail.com: domain of usamaarif642@gmail.com designates 209.85.128.49 as permitted sender) smtp.mailfrom=usamaarif642@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1714749074; a=rsa-sha256; cv=none; b=neKW1Wb6krBQ9s+fd2VE8WmLOfkOWd9bYhyxl9nbosOAprGy/cExTnHhTHVlB/Jg7Q1ZfK RyHwVKVJNtHSdhCOCLEGhwoTfb6Sr8htiMn51SZq2CHJR89LM8Z0j8XXq/3vviLhMBUIdb 0oSCU+/hz+s2uun23Hm+8JzpdwNHsFE= Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-41a1d88723bso65873155e9.0 for ; Fri, 03 May 2024 08:11:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714749073; x=1715353873; 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=u+3HzXMAKOQPznx02Kq/PyKDV/8AD6lCk3ecRCC6kGo=; b=IiXBT3aaG7IJaHywMHLZHRCk+FbC6Zl9+4/hcNYhf1YzdOS1mKb4HjbkhhI60eNv7M oHM5KhHEtRqUmTrgkJXWL+k3xw/6DgKxIw3aWs5k8pdjgInSXm60ht5XE3+lrFcoTi46 VDN83UHlnpePP5dEQiP3Q9/DxZUm2DaACFGhRzaq2EHAXwLE9MhYbNc4z50S9xB4k4r+ wvq12opDeNJMJLHzsmvnzAIDi5evisTrgHhmNpcBEn5xlkhv0lw4LRoWQkl5s8RGYrHD Jb/BTMadTPLs4RKCI16JLCF5UrWaLw2v0OQmTZUfqZyyb58x5pLOmczVzbedi2ONL6e2 e/rA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714749073; x=1715353873; 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=u+3HzXMAKOQPznx02Kq/PyKDV/8AD6lCk3ecRCC6kGo=; b=ppfM9eRTVjOZFd9QXU/T3duutgvVc2/T5VO+ylhdvweoiZ8cEyVZvvBDsJ+Uq6oRTV KHgG6hgGHR6S8vX3arMX+jZMydErkUDx515vRFTdXVGr5clJO44AJjCg3Oda2pmAOC0Y JphKG4lORgPMGDzULwzKkMQTHfFP2W4xSq2Pl2VWnFTt3YnBHlxaXs+Mj+sAi5beAKav 1oiKkBW79cQmHofklqCywQNQ2mLtrT6mBS+X0KWYVVcuFysd0/8PiOQ23LuqwUfvvZjK OXbmHyDPA8AzrZrPdRQC/w/RFhD7VPJ0c6Oo+smSiIf4HH39vY+KExznPQRkJfdIklgx Xh0A== X-Forwarded-Encrypted: i=1; AJvYcCWHKeHjw1mI6/NyuZDdfXJUhnGRuyeCL4xWPkFObzrHuywYAASnX/WgvI3c24jMWJVXswVM5NEOajHSjV/LoN7J8xE= X-Gm-Message-State: AOJu0Yxs9ppZpSzfdw5Xdpp1tJv91NnyhUZzVQ4egRC3weMYIe1mvNrP uC/t+gi7t0zaU9TimKPx/MHugLD2+7LtIJlMFDUAY83rY8gX6of6 X-Google-Smtp-Source: AGHT+IFR6bDoRgVKy5/VkEevpa6wJTuILz8VoTMyMcw1BZebqA4gt/GfjtqFf34tA3O4v2QErQ/ADw== X-Received: by 2002:a05:600c:4706:b0:41a:b56c:2929 with SMTP id v6-20020a05600c470600b0041ab56c2929mr2469373wmo.34.1714749072502; Fri, 03 May 2024 08:11:12 -0700 (PDT) Received: from ?IPV6:2a01:4b00:b211:ad00:1490:6cc2:4d06:940f? ([2a01:4b00:b211:ad00:1490:6cc2:4d06:940f]) by smtp.gmail.com with ESMTPSA id z10-20020a05600c220a00b0041bef325c4esm12059011wml.1.2024.05.03.08.11.12 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 03 May 2024 08:11:12 -0700 (PDT) Message-ID: Date: Fri, 3 May 2024 16:11:11 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] selftests: cgroup: add tests to verify the zswap writeback path To: Nhat Pham 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 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: rspam07 X-Rspamd-Queue-Id: 315FD4001F X-Stat-Signature: 3go6zbbhudif4uqmm5u576m8tpnguyn6 X-Rspam-User: X-HE-Tag: 1714749073-363790 X-HE-Meta: U2FsdGVkX19cI+GpdELA72Vq3DEjnKwWyrkowbETjKMUlGQHqAsYjtk//OT15qIo8rYsi5Y3NpIYfFCVnvthdj2PdmUBbUyfgw/ppg0Fk6U0QYiojWRWfDGWW9RMsESh2wzLgUA3MFl5eIzSAJIrT1ikle/2U32Mpq7ox2jEEcBcyDXP6SshM+SQgcamGSZeQTzYoVK6aWQccp/1/3ocCTtBCuW8A0+V1nX1AJduYJ5YQqPnQiNk8QNWVJcd+ubDLYKzSMJzaPPgDPPadtiSkZYU8ki9qsyZ39ywQIXgBsYlc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zm8Z2U0pmRO/EsTs1q4Oej/8l8JBbcNWqMwdIGp1EYLjHNm64REWu7OYJzCp9kfzCrT6yUxcaLCuH1J2BWQKtXRRQxdOJVf8HlAgI/yiAmyfQUBLsOI+wtrACnT47Bl87MnElhApFCjTpcwUFS0K9BVwPUnT0VB X-Bogosity: Ham, tests=bogofilter, spamicity=0.363270, 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 03/05/2024 00:30, Nhat Pham wrote: > On Thu, May 2, 2024 at 12:05 PM Usama Arif wrote: >> >> On 01/05/2024 16:44, Nhat Pham wrote: >>> 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 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 *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; >>> 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 = 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; >>>> + } >>> 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 :) So I think what the equation would be is pgsteal = zswpout + number of pages that couldnt be compressed and directly moved to swap? We have pgsteal and zswpout, but I cant see from existing metrics if we can get the 3rd thing. As a reference these are some of the metrics at the end of writeback enabled test from v2: zswpin 1024 zswpout 1801 zswpwb 297 pgsteal 2057 zswap 0 zswapped 0 We need a metric that is 2057-1801 = 256, but can't find any :)