Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp1186078rdb; Fri, 2 Feb 2024 17:36:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IFBnrpaPus3E0yEOlFzxRGDv++AQwqGHx4tM88szbmgYyWa2PzwVCv5UTvyLTq9h1sisTOt X-Received: by 2002:ad4:5fc8:0:b0:68c:4167:fc5f with SMTP id jq8-20020ad45fc8000000b0068c4167fc5fmr13111248qvb.52.1706924200495; Fri, 02 Feb 2024 17:36:40 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706924200; cv=pass; d=google.com; s=arc-20160816; b=uDxwR39kqfXA8m32C3T+CQrC91Xjgd8z/nVNSfc5xrtVX/yPAyHIG/l4AR3Xg1/Jkq oSsAzDlxrkYUo2+XlDgmNnyxP4HfZacG6dVuk/HVGBSsxbIr0UTNLH0O7zThIQqB1nvk yAbaBuKkUYd75dhcFBt/auDWQKUVz1iMeZq73yu3kenF+BUVSIk8L4b+B2D5ohcSbLpk 3JH2fsrCbyzJjbWMS+4heRgkKeNmmAW6D7p8W6tWW8KOJ/6+Nqf9X48iLPOniNLICSlK sZLKjImtbXJOx6M5m+zWych/EycbJEcwF4tDhKz+Deh9SAPh+0rR4a1Sh5ZXfBcs4B1l FQxg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :dkim-signature; bh=+ZtJdSb7EI9zmC17ta56Eu+wHYjQhwSEAchKE32W20c=; fh=OZrMRwTHORmHU4G90yB4pYE9A9Gxc8vB1NAX9pnjGjM=; b=aUrz6SyCKnuQ+2rpTQBW/CYgl3uKen5JfA6KmEXtckH6ytBJWxdZ69FuSEdW8RxEqW KMC+CZAbWYNzSgfxQsXWw9xaQ/T+UKgERj/hqGhOkgu6+U5v+qvGCECPtK6dcPKIHk8x RyGoEJwGaM5DdzV6c5Kr2kI28a8VEGfEoYkc+2ylJM8ToptdW6GBw+cgEnCnLax82x+K dS1C0MPp8gHKrCflh1DJDhB30Ry+jGo0XqKp6qWJLfl1FrFuHlW277iaXdMw2hj7weMM KLRnaNFHQ1YbIpVwH07R2yDai2/SKzQFwZxqGhtC7CdNAWVT6lwlt0lOfOrhP2UWintV cFTw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=TpVskmD+; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-50811-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50811-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=1; AJvYcCXe7kZZLpnMTqXOfIhqQVUorz/6WaEtAYqNKiiviHWVw1bXDKiFLIE8kSy++tUB5fFZsTF4HzwxrqOZSSjT8MbXOLhwyA7VI4XIlQT/tA== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id jh21-20020a0562141fd500b0068c641b286fsi3364699qvb.84.2024.02.02.17.36.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 17:36:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-50811-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=TpVskmD+; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-50811-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50811-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 3034F1C21B2D for ; Sat, 3 Feb 2024 01:36:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F25475244; Sat, 3 Feb 2024 01:36:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="TpVskmD+" Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com [209.85.218.52]) (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 55C9F1FDD for ; Sat, 3 Feb 2024 01:36:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.52 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706924192; cv=none; b=oyIlYLkiPmp9+BWcdtkoqKi+uBFcDEKXkFhehdt4xGFYnHfqo2auMGBsFPepwuK+YR51GnIsniyOJIMY/eILUs+/oECydJ0ity1QSSdYaveZI7KKRCaLNFRZXE6IY+5gK+sZIG6QSOeZVNdeogJYkzmcMVnmJ/JJLQO5kmQEPNk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706924192; c=relaxed/simple; bh=Hf6uyk3PkhlfPyC3HRqmW4VM5M44oxj62qu0PS7I3jk=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=jyHGVpa6WC51nlRE6ICHV2KgA/M5Kk/+n9E3ODQjZCA0qFzhm7bXtpQ89R+oVivWPn6hKKcOoM1mYwRojbt+vNpz9LjQqlSanCLdlAdVH78AA1YpfJag96QWs18dYwH98C53drTf7pkjagLWn8266HsWzjMcva1QMseVhQvlNw0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=TpVskmD+; arc=none smtp.client-ip=209.85.218.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-ej1-f52.google.com with SMTP id a640c23a62f3a-a318ccfe412so304920566b.1 for ; Fri, 02 Feb 2024 17:36:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706924188; x=1707528988; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=+ZtJdSb7EI9zmC17ta56Eu+wHYjQhwSEAchKE32W20c=; b=TpVskmD+gga1/dXm1v3DEPQN+/3QUZ2KjZC8QrTCoDjmIot4QuOKBGcCgjag+YMphE BEwDcnrHJyoH0Y9wWoWr7am2FPPDr/P6rI2K9Epwke5tR62hBJMIUMZd7dRQoL0AMWzr CGIqsB5T8GgOieFornDqQelozvoDRr4n9VDO1rEtbbBKSSmo9dwSZImdN+Luei2xyTck j8zZxUm7+BEZegQ1m2rY2bqHRFnMk0v1fB4yvVrfrP7DWICSpzr+VO/y3ZzciLZeKx8k Yk4psBLjtdwIbersIKf3mH2wAh9+hhDsqRyFBZJhrZIjCf1mA/WAcyYkejghdxE1uY/w 4yyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706924188; x=1707528988; h=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=+ZtJdSb7EI9zmC17ta56Eu+wHYjQhwSEAchKE32W20c=; b=Z5pTNdUj+TRQGm9lbBqfzx1ZU3NRnDUAnRUjxU5Xscly2KYM+YKFO/SfP4016X3bvw I3hKubB45xG/QmZnirA6EU4YTJTiGQnbsEF+iLMXO+h1ODU817UYW915sHneUcAg0d8U NBro+RVeoml2dvPAed2H3/p1bJ13FODa+W9lXjaB2HgfGFrRCwLYoN7nCVlyjSK0ygbG L+F0WBSYI9aRsiX5hlpKEYsxuXICOmzON/14zlf5+q3uhz33tuAtepugqU62BZfaQUj5 78eyz42z9ONS98aiK344Uw3WRO2dZZ96AvRmckC2eR12ofty7gHfRqVThELSmc5W+eMA WAEw== X-Gm-Message-State: AOJu0YzGQZ8ny8LFZ9sTcAEPktNLsw4HBV+S+AlyIrwqkNvzbo555EIU DjH9SjBx4vVAkrtJy+TN9Fzr4DNVf2Pzn1AGGEPBspundzFcrNWo9mj0n3w0dUNNS4K+gEb4QoX zkIaPXzCZ+sPKr/Ojrw0Bj8LsPyAOVLVNMGOx X-Received: by 2002:a17:906:36cd:b0:a36:55d5:2364 with SMTP id b13-20020a17090636cd00b00a3655d52364mr2781404ejc.21.1706924188353; Fri, 02 Feb 2024 17:36:28 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240201032718.1968208-1-nphamcs@gmail.com> <20240201032718.1968208-4-nphamcs@gmail.com> In-Reply-To: From: Yosry Ahmed Date: Fri, 2 Feb 2024 17:35:49 -0800 Message-ID: Subject: Re: [PATCH v2 3/3] selftests: add zswapin and no zswap tests To: Nhat Pham Cc: akpm@linux-foundation.org, riel@surriel.com, shuah@kernel.org, hannes@cmpxchg.org, tj@kernel.org, lizefan.x@bytedance.com, roman.gushchin@linux.dev, linux-mm@kvack.org, kernel-team@meta.com, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-kselftest@vger.kernel.org Content-Type: text/plain; charset="UTF-8" > > > +{ > > > + size_t size = (size_t)arg; > > > + char *mem = (char *)malloc(size); > > > + int ret = 0; > > > + > > > + if (!mem) > > > + return -1; > > > + for (int i = 0; i < size; i += 4095) > > > + mem[i] = 'a'; > > > > cgroup_util.h defines PAGE_SIZE, see alloc_anon() for example. > > > > On that note, alloc_anon() is awfully close to allocate_bytes() below, > > perhaps we should consolidate them. The only difference I see is that > > alloc_anon() does not check for the allocation failure, but a lot of > > functions in cgroup_helpers.c don't, so it seems intentional for > > simplification. > > Hmm I didn't know about this function. I think it was Domenico who > added allocate_bytes() for the initial zswap tests, and I've just been > piggybacking on it ever since: > https://github.com/torvalds/linux/commit/d9cfaf405b8ffe2c716b1ce4c82e0a19d50951da > > I can send a separate patch to clean this up later :) Doesn't seem that bad. SGTM. [..] > > > > > + if (cg_write(test_group, "memory.zswap.max", "0")) > > > + goto out; > > > + > > > + /* Allocate and read more than memory.max to trigger swapin */ > > > + if (cg_run(test_group, allocate_bytes_and_read, (void *)MB(32))) > > > + goto out; > > > + > > > + /* Verify that no zswap happened */ > > > > If we want to be really meticulous, we can verify that we did swap out, > > but not to zswap. IOW, we can check memory.swap.current or something. > > Hmm would memory.swap.current go back to 0 once the memory-in-swap is > freed? It doesn't seem like we have any counters at the cgroup level > for swapout/swapin events. Maybe such counters were not useful enough > to justify the extra overhead of maintaining them? :) > > Anyway, I think checking zswpout should probably be enough here. > That's the spirit of the test anyway - make absolutely sure that no > zswap-out happened. The test is making sure that even though we used real swap, we did not use zswap. In other words, we may see a false positive if something goes wrong and we don't swap anything at all. I know I am probably being paranoid here :) How about we check memory.swap.peak? [..] > > > + test_group = cg_name(root, "zswapin_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.zswap.max", "max")) > > > + goto out; > > > + > > > + /* Allocate and read more than memory.max to trigger (z)swap in */ > > > + if (cg_run(test_group, allocate_bytes_and_read, (void *)MB(32))) > > > + goto out; > > > > We should probably check for a positive zswapin here, no? > > Oh right. I'll just do a quick check here: > > zswpin = cg_read_key_long(test_group, "memory.stat", "zswpin "); > if (zswpin < 0) { > ksft_print_msg("Failed to get zswpin\n"); > goto out; > } > > if (zswpin == 0) { > ksft_print_msg("zswpin should not be 0\n"); > goto out; > } SGTM. Thanks!