Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp1957270rdb; Sun, 19 Nov 2023 18:41:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IHkjOItXTSE/LbFnT4Tfrvvo6lpj6ZZWVGAxmB3EXp4GUknGy10kWUJAStGkEL/Ce7m+4E4 X-Received: by 2002:a05:6a20:9781:b0:188:973c:ef82 with SMTP id hx1-20020a056a20978100b00188973cef82mr9392426pzc.29.1700448109504; Sun, 19 Nov 2023 18:41:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700448109; cv=none; d=google.com; s=arc-20160816; b=Meaifq9e8IWUH8Bmz7nfPkO0k7u/lobb/uD385OLF/2249EepV5rJ+SE8cuTCoz9NV 1+H1LEMrIi+UpYPD0kM7LZSJbXIIz7hw7f1IRqFZBxUs+GmwJHHP45SmO5vD9fcKM68x U+cSBpD5MTviuwhu4U6CJP/cECu04viHb4pujf0cO2uLa5OTSbPgNqUsZFoqseEfzmVK egzsAQb+NiE0ecFFhOBu6ZK2eqG8hZSmUOJ8LzdXMHbrpHJeOIsVckTagbWbChIOEZli oWlLnv+dp3V8nfLivFRj8nw+dWT4mpxEIzOlO0VoftpiVR8p9fhIYwK3hWy2Tts2TjpG YO/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=lCG9ZawC3ztul0nCGCI4RHneLck6XEIyYbizhx+EprY=; fh=GaNPqD88nZkZMS7PxgGPoZq2oMTQaux2ATtDJcJk6+E=; b=RfZN1QG45BLLpWb4SwY6FhsrYYQQMQ8ubyWZD0bSCp7sO3svO+sM+ThrXJfT8kqx9T uTTwI5zcXCWEO/queG4icrdwIpshb2u/TPIWrflAFAoJz5HuwmzLDaSrx3V1gETJl4rS 3uXlbt/22bEzHlmMEPG8eeP9glMp7GyZR/bII+vsSfWGlX3nKlsqafstjvjNpp0XzLe9 Y2ExKksuvwLBLqZKuIp+pSUzSyjvUhh6HHrZXH3mnhu3dPnpnDLaVimUGBZ8Ti1Kbq49 Wo5mVKhbVQongqgX0AWx+ik1oFd2USA0L+kbwjSoypJuVZR4xILsi0jA89o3pv9f5CaX jrtw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="o/0Z/1/j"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id 15-20020a63104f000000b005b909e678dfsi6788138pgq.450.2023.11.19.18.41.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Nov 2023 18:41:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="o/0Z/1/j"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 4032B80560E3; Sun, 19 Nov 2023 18:41:46 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231760AbjKTClj (ORCPT + 99 others); Sun, 19 Nov 2023 21:41:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231676AbjKTCli (ORCPT ); Sun, 19 Nov 2023 21:41:38 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 88068115 for ; Sun, 19 Nov 2023 18:41:35 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0AFE6C433C8; Mon, 20 Nov 2023 02:41:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700448094; bh=UiWuaKeTiSFKQxVccuysbinvCkmLWJ1QXqtmU4c9M9o=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=o/0Z/1/jlmTimJm9937305yEJETPIoA66Qdh+9bcGh4iO1jC7uwn5sAd36iHbSjfF y5073eOz1lEnL5m3wFSz+1ILlybe2uy2Rr7g2ANq8FuQVZjZySqzgVBrnuTj55kuec W/BBC+TgPpbkDkulF6xyej5O57aBSgYOqfSM8dL4QcR5dWPS3Ol+IfXsSKi2L3qPC8 slYmHD0Q0xTpui580WF/xxTH3hnDRteip0YpBaJ4l9c/EObCSkSXsUcMtvI4iMgYcO rQEGHHyGoNic200lCdcB8PDVuKrs2sR1Ccje+ypBCoXPRrypbL+y3FwSgKbK9M5gr3 Wvs4axuOecFJw== Date: Sun, 19 Nov 2023 18:41:32 -0800 From: Chris Li To: Nhat Pham Cc: Yosry Ahmed , Andrew Morton , tj@kernel.org, lizefan.x@bytedance.com, Johannes Weiner , Domenico Cerasuolo , Seth Jennings , Dan Streetman , Vitaly Wool , Michal Hocko , Roman Gushchin , Shakeel Butt , Muchun Song , Hugh Dickins , corbet@lwn.net, Konrad Rzeszutek Wilk , senozhatsky@chromium.org, rppt@kernel.org, linux-mm , kernel-team@meta.com, LKML , linux-doc@vger.kernel.org, david@ixit.cz Subject: Re: [PATCH v5] zswap: memcontrol: implement zswap writeback disabling Message-ID: References: <20231115172344.4155593-1-nphamcs@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Sun, 19 Nov 2023 18:41:46 -0800 (PST) Hi Nhat, On Sun, Nov 19, 2023 at 01:50:17PM -0800, Chris Li wrote: > On Sun, Nov 19, 2023 at 11:08 AM Nhat Pham wrote: > > I don't have any major argument against this. It just seems a bit > > heavyweight for what we need at the moment (only disabling > > swap-to-disk usage). > > The first milestone we just implement the reserved keywords without > the custom swap tier list. > That should be very similar to "zswap.writeback". Instead of writing 0 > to "zswap.writeback". > You write "zswap" to "swap.tiers". Writing "none" will disable all > swap. Writing "all" will allow all swap devices. > I consider this conceptually cleaner than the "zswap.writeback" == 0 > will also disable other swap types behavior. "disabled zswap writeback > == disable all swap" feels less natural. I implement a minimal version of the "swap.tiers" to replace the "zswap.writeback". It only implements the ABI level. Under the hook it is using the writeback bool. This patch builds on top of your V5 patch. implement memory.swap.tiers on top of memory.zswap.writeback. "memory.swap.tiers" supports two key words for now: all: all swap swap tiers are considered. (previously zswap.writback == 1) zswap: only zswap tier are considered. (previously zswap.writeback == 0) Index: linux/mm/memcontrol.c =================================================================== --- linux.orig/mm/memcontrol.c +++ linux/mm/memcontrol.c @@ -7992,6 +7992,32 @@ static int swap_events_show(struct seq_f return 0; } +static int swap_tiers_show(struct seq_file *m, void *v) +{ + struct mem_cgroup *memcg = mem_cgroup_from_seq(m); + + seq_printf(m, "%s\n", READ_ONCE(memcg->zswap_writeback) ? "all" : "zswap"); + return 0; +} + +static ssize_t swap_tiers_write(struct kernfs_open_file *of, + char *buf, size_t nbytes, loff_t off) +{ + struct mem_cgroup *memcg = mem_cgroup_from_css(of_css(of)); + int zswap_writeback; + + buf = strstrip(buf); + if (!strcmp(buf, "all")) + zswap_writeback = 1; + else if (!strcmp(buf, "zswap")) + zswap_writeback = 0; + else + return -EINVAL; + + WRITE_ONCE(memcg->zswap_writeback, zswap_writeback); + return nbytes; +} + static struct cftype swap_files[] = { { .name = "swap.current", @@ -8021,6 +8047,12 @@ static struct cftype swap_files[] = { .file_offset = offsetof(struct mem_cgroup, swap_events_file), .seq_show = swap_events_show, }, + { + .name = "swap.tiers", + .seq_show = swap_tiers_show, + .write = swap_tiers_write, + }, + { } /* terminate */ }; @@ -8183,31 +8215,6 @@ static ssize_t zswap_max_write(struct ke return nbytes; } -static int zswap_writeback_show(struct seq_file *m, void *v) -{ - struct mem_cgroup *memcg = mem_cgroup_from_seq(m); - - seq_printf(m, "%d\n", READ_ONCE(memcg->zswap_writeback)); - return 0; -} - -static ssize_t zswap_writeback_write(struct kernfs_open_file *of, - char *buf, size_t nbytes, loff_t off) -{ - struct mem_cgroup *memcg = mem_cgroup_from_css(of_css(of)); - int zswap_writeback; - ssize_t parse_ret = kstrtoint(strstrip(buf), 0, &zswap_writeback); - - if (parse_ret) - return parse_ret; - - if (zswap_writeback != 0 && zswap_writeback != 1) - return -EINVAL; - - WRITE_ONCE(memcg->zswap_writeback, zswap_writeback); - return nbytes; -} - static struct cftype zswap_files[] = { { .name = "zswap.current", @@ -8220,11 +8227,6 @@ static struct cftype zswap_files[] = { .seq_show = zswap_max_show, .write = zswap_max_write, }, - { - .name = "zswap.writeback", - .seq_show = zswap_writeback_show, - .write = zswap_writeback_write, - }, { } /* terminate */ }; #endif /* CONFIG_MEMCG_KMEM && CONFIG_ZSWAP */