From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F0160330305 for ; Fri, 13 Mar 2026 01:50:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773366620; cv=none; b=vBkcn2MDpPnCM4A6Omk2esobLUaMupPKfcsssOVz8zXH8N4T0i7XTQZF+TkbTD7G/NtcSWFyvXU0rWgzaNqKGXJkW3lyAWUJUbMACl8oEbge4+0DVUNo9DfK0PXUSdCz4By5S/xmASL4yQLG4aACuUVWH7NyjARXMq5SF07Z12E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773366620; c=relaxed/simple; bh=5+oh1fTVx/qCGTJzIUo21LMERZnPTfVr3BOQL3Ul/e4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=nGWrE96mNFE3uRRtxMgKTtZYzpXhtD71cQDqjuPnCJP9zLb7Bqd9eIDHSMMQFttS0nEus3j6/DLBUFpyzjPn8vKkv2O/gXXkFmOc9FH/NT23eh/k08ZoNjMahjlwtj9cronpiMWC/GWepE/vZFbCA9eF+MU9PeJfPzQ8GFKy+gg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=f6iO2DxB; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=hiE8Na3J; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="f6iO2DxB"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="hiE8Na3J" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1773366615; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=+8qvvOJTfwWE8tG5TRMJ16Dwr1E/YePgvm9DgBu+yJg=; b=f6iO2DxBbSdtR5un4FV57aN2TTWj3mxJgS0+AkMERY731nYm5a6afd9pYaN3dzUMUgQ6ob N6e4vyD0cJv1CGJaItCel80+Hesjq0ycclIBTeDlcReot9EX3erWp6FKj+R1Ob7yvcEcK3 lhmkaicbSKLWWoLW+/JS2RNK6LpvK64= Received: from mail-pg1-f200.google.com (mail-pg1-f200.google.com [209.85.215.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-327-igeCGTXlNWmLSNfM37fp-g-1; Thu, 12 Mar 2026 21:50:14 -0400 X-MC-Unique: igeCGTXlNWmLSNfM37fp-g-1 X-Mimecast-MFC-AGG-ID: igeCGTXlNWmLSNfM37fp-g_1773366613 Received: by mail-pg1-f200.google.com with SMTP id 41be03b00d2f7-c6e24ee93a6so1605442a12.0 for ; Thu, 12 Mar 2026 18:50:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1773366613; x=1773971413; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=+8qvvOJTfwWE8tG5TRMJ16Dwr1E/YePgvm9DgBu+yJg=; b=hiE8Na3JFZVKHeBGrunaAM4xguDFKSiJzZwJPeFoaN1QtGsyuE3u0EhyuwwwwzRzhH zswoXfn6/jDV2/QhAnyTGx8cAElsy77pAoWFewpDdIV0hb4aIUTEPo3G3lM4UCZl8NAO l4FPdoGhoRhzjfPAZ738PyQvz2OdIEfUKMv55LXOYaUdLJBSs7mC74YauHPiQJY5Pu2D 9I3pk93s9Nw3VcIboo80rv9ldMIua9qei9QW/MCf+ar8YSIg2WcXvhzl5BVggSuKlCOF LJFRICZE83Nxi0gz2eh1FKIUxgpLA6DPn/6kBr/ovfziE+8IZDWZB5Ca+JI/rbqRovy6 H5Fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773366613; x=1773971413; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+8qvvOJTfwWE8tG5TRMJ16Dwr1E/YePgvm9DgBu+yJg=; b=hP0Q0V7DpQJFRoD+hCSnrTquaQRZGo79PvWG8eLomPbZrcW0v9IKOEvqnDOsFH8MNe 4clhC2iGiwLA8xdwVeQpCq5RsfJW8aLfRIulEdJxIAROcaoU33GhoiyNumTBrj+iD/0h a9Nh5jshIuCGQF+XdIFiGYnYO+Pwir3F9DFKmsipO9KYyY6KXTBpQi77G8Jjg80v0r20 8mL+D58RzT1Yy7jlLn9BXnhGB/rlLtd3ABjKxE24ma0gKoGHRpcFTjureBwFGRm5BaJr PXB6wF0E2Tq4ATWZKdVWay3K7XGct/maVf+10ZX5MgohesdfDFCTy5acRgKF9yLUshn9 5WOA== X-Forwarded-Encrypted: i=1; AJvYcCWdGvp6mNoEyEZK9wKksFkkadLo3ioAZnV4HcqbRJQUi0DQzg5MPN4jZdoIwhkZlMbNoIGHfJ0jLdzyifw=@vger.kernel.org X-Gm-Message-State: AOJu0Yxt8/Yzxs21rbnIKVe7RzOAuW/HOw312fPWp//d6AxipOyHl3tY NFamkvDijXLm8+QT5uwKsG3Y8eKp3qQ529h3kN/slIHB3432dmto4h/mMzVAonPdh7va+TEsu4g 0sL3S3+OJEN40xuhuGhTIfcyml27n9woaIxx/gDpcHfdSjs/tisNl9ADhm0JUa14ZxA== X-Gm-Gg: ATEYQzz4y2yGXa8icdSJA6wasy45SvM9nJJh9RXGnd7s2v6O3IJveUmRoWg0c26JhlN bwV8sHiayugjH37V8irkDBRsifZDKzv62oh32cQ0ZCQItTlz+zzvxwJjfiT9WiOopOvKs2VfGXy q/9eJd+WQTyzZ4SpIGIQXTP3nTPmxqxXA7bJwcfnSHGpDykItTOo9dkHnTK1pnrxzTC0I4BUtV2 3OXVRBHCZCqzzaPLI8e5slfACHz1/AaK6Tbpyf/h+X21u/NMwhkbHmF9fFeHLBS8RmQKuMnrxJJ oIwZc3aq5pDT3nFnTYdXyqiCOc/u9xRRZQqGBxJZIN698TcYX5tvi7wOTzn6tyL6IF4PAXXK7DQ taEJYIXcQ+cKwZxygXA== X-Received: by 2002:a17:902:f542:b0:2ae:5628:a180 with SMTP id d9443c01a7336-2aeba5594c1mr45919105ad.25.1773366613153; Thu, 12 Mar 2026 18:50:13 -0700 (PDT) X-Received: by 2002:a17:902:f542:b0:2ae:5628:a180 with SMTP id d9443c01a7336-2aeba5594c1mr45918945ad.25.1773366612701; Thu, 12 Mar 2026 18:50:12 -0700 (PDT) Received: from redhat.com ([209.132.188.88]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2aece56c2b9sm3981305ad.18.2026.03.12.18.50.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Mar 2026 18:50:12 -0700 (PDT) Date: Fri, 13 Mar 2026 09:50:09 +0800 From: Li Wang To: Yosry Ahmed , Nhat Pham Cc: mkoutny@suse.com, yosryahmed@google.com, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Johannes Weiner , Michal Hocko , Muchun Song , Tejun Heo , Roman Gushchin , Shakeel Butt Subject: Re: [PATCH v2 1/7] selftests/cgroup: skip test_zswap if zswap is globally disabled Message-ID: References: <20260312040627.55257-1-liwang@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Thu, Mar 12, 2026 at 02:09:30PM -0700, Yosry Ahmed wrote: > > > diff --git a/tools/testing/selftests/cgroup/test_zswap.c b/tools/testing/selftests/cgroup/test_zswap.c > > > index 64ebc3f3f203..ec64daaa2f5a 100644 > > > --- a/tools/testing/selftests/cgroup/test_zswap.c > > > +++ b/tools/testing/selftests/cgroup/test_zswap.c > > > @@ -589,23 +589,41 @@ struct zswap_test { > > > }; > > > #undef T > > > > > > -static bool zswap_configured(void) > > > +static int zswap_enabled(void) > > > { > > > - return access("/sys/module/zswap", F_OK) == 0; > > > + char buf[16]; > > > + ssize_t n; > > > + > > > + if (access("/sys/module/zswap", F_OK)) > > > + ksft_exit_skip("zswap isn't configured\n"); > > > + > > > + n = read_text("/sys/module/zswap/parameters/enabled", buf, sizeof(buf)); > > > + if (n <= 0) > > > + return -1; > > > + > > > + if (buf[0] == 'Y') > > > + return 1; > > > + else if (buf[0] == 'N') > > > + return 0; > > > + > > > + return -1; > > > } > > > > > > int main(int argc, char **argv) > > > { > > > char root[PATH_MAX]; > > > - int i; > > > + int i, state; > > > > > > ksft_print_header(); > > > ksft_set_plan(ARRAY_SIZE(tests)); > > > if (cg_find_unified_root(root, sizeof(root), NULL)) > > > ksft_exit_skip("cgroup v2 isn't mounted\n"); > > > > > > - if (!zswap_configured()) > > > - ksft_exit_skip("zswap isn't configured\n"); > > > + state = zswap_enabled(); > > > + if (state == 0) > > > + ksft_exit_skip("zswap is disabled (hint: echo 1 > /sys/module/zswap/parameters/enabled)\n"); > > > + else if (state < 0) > > > + ksft_exit_fail_msg("Failed to read zswap state\n"); > > > > > > /* > > > * Check that memory controller is available: > > > -- > > > 2.53.0 > > > > > > > Seems a bit convoluted. You ksft_exit_skip() for one case in > > zswap_enabled(), but return some value in other cases. This value is > > checked in the caller (main()) and then used to decide whether to skip > > or fail as well? > > > > Why don't you just consolidate them in one place. If zswap_enabled() > > has no other callers, let's just open code it, yeah? > > Hmm I actually like having the helper. What if we move all the > ksft_exit_skip() and ksft_exit_fail_msg() calls inside and rename it > to check_zswap_enabled()? We can also just read one character: Yes, this looks more tidy than open it. I'll go this helper in v3. > > static void check_zswap_enabled(void) > { > char value; read_text() requires string but not char. > > if (access("/sys/module/zswap", F_OK)) > ksft_exit_skip("zswap isn't configured\n"); > > if (read_text("/sys/module/zswap/parameters/enabled", value, > sizeof(value)) <= 0) > ksft_exit_fail_msg("Failed to read > /sys/module/zswap/parameters/enabled\n"); > > if (value == 'N') > ksft_exit_skip("zswap is disabled (hint: echo 1 > > /sys/module/zswap/parameters/enabled)\n"); > } > -- Regards, Li Wang