From patchwork Mon Oct 24 16:12:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 13017768 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 5F3F0ECAAA1 for ; Mon, 24 Oct 2022 16:12:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EFEE894000C; Mon, 24 Oct 2022 12:12:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EAE2F940007; Mon, 24 Oct 2022 12:12:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D4EB494000C; Mon, 24 Oct 2022 12:12:34 -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 C7E19940007 for ; Mon, 24 Oct 2022 12:12:34 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 8FA0040114 for ; Mon, 24 Oct 2022 16:12:34 +0000 (UTC) X-FDA: 80056335828.09.7F0D1FC Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) by imf18.hostedemail.com (Postfix) with ESMTP id 25EDF1C0003 for ; Mon, 24 Oct 2022 16:12:33 +0000 (UTC) Received: by mail-pf1-f175.google.com with SMTP id b185so3153110pfb.9 for ; Mon, 24 Oct 2022 09:12:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=w9VjWrNf/YPNyhVI/eZNl14XBpdcpcyeDNi5KSdPpF8=; b=DFrjiwdNQ/wdO9nKOl8hS0v7J4HbfNZAVkr+2ftKxzzo+O9vReSREpw1NYFHbezRKn eBEwBH2umkuDsdKyeiDvfWjEGRH5JhiZsjtymd15Sgevf3KIL3zwgLkmB/+KZ0YUfKiA Ek3WOVt4CrLCmoyFBzoDGXdqxrFsXBd1kkZJE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=w9VjWrNf/YPNyhVI/eZNl14XBpdcpcyeDNi5KSdPpF8=; b=q+7cGRp1MU66s6spcdP7c/1dif20gMze4b00eCPQ7aZLztGtMtKZi/SpNWTAyJvMQy smt+1QcoGwxUGm+KJotpD47yZNfWrLrHnyC+mBytsYtfezuUZj9Ro6FK54tIrQgivGY0 ByTz75Frntu13IKZ3x33Jo0vYv//tc4dQ6m4G2LxDLyWFGxOZrXUijQ2CMacwPpcwp8h WUxJ0WWjGIiUa3Yz95CC+5z4BI/5jSYK4IsLBLsUGJMBhcPCx5/0Z6OdDE/Xhwx7t5XW Bj42VXupQPi6nh+deMu6/ujQ70mr76uLer1EPyEuDr3mDoxF8Qv2D7rWitENQZ1fME2x ptog== X-Gm-Message-State: ACrzQf1nyfCa9h81xzvShnKtDTIhpLTzo3XxxLE1fDe8mdopy54ohNy9 WOJHRPSN6jW/RhjCuXQvEwjAig== X-Google-Smtp-Source: AMsMyM4pWXeIkQZMKXeLRzJlOTVBNKHApO1SSdt9yK/brvG4rWMIRgYyvbCaOua+m9Y+zJiQ9HhkdA== X-Received: by 2002:a63:914b:0:b0:46e:dbd5:ae15 with SMTP id l72-20020a63914b000000b0046edbd5ae15mr11048144pge.94.1666627952967; Mon, 24 Oct 2022 09:12:32 -0700 (PDT) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:5f9c:c5bc:902f:3da4]) by smtp.gmail.com with ESMTPSA id u70-20020a627949000000b0056b8726d2d3sm5162pfc.157.2022.10.24.09.12.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Oct 2022 09:12:32 -0700 (PDT) From: Sergey Senozhatsky To: Andrew Morton , Minchan Kim Cc: Nitin Gupta , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Sergey Senozhatsky Subject: [PATCH 3/6] zram: add pool_page_order device attribute Date: Tue, 25 Oct 2022 01:12:10 +0900 Message-Id: <20221024161213.3221725-4-senozhatsky@chromium.org> X-Mailer: git-send-email 2.38.0.135.g90850a2211-goog In-Reply-To: <20221024161213.3221725-1-senozhatsky@chromium.org> References: <20221024161213.3221725-1-senozhatsky@chromium.org> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666627954; a=rsa-sha256; cv=none; b=iqBRgf0cyuioMsazVUDaKrymN4uCcsaNFhAsCoqmAfKauKqJWBeIBTirWVepUVhDHevE5k VKEohIwR2MnBBzUkYVTvZScX0NJeYFtdRqaP7bBU1Eq0fdrpD+GFH0MpzQ/Qf3w6PzP+Gz JElL4mm34Y0q/ho3IeOtgTEOylycloE= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=DFrjiwdN; spf=pass (imf18.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.210.175 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org; dmarc=pass (policy=none) header.from=chromium.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1666627954; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=w9VjWrNf/YPNyhVI/eZNl14XBpdcpcyeDNi5KSdPpF8=; b=5c2o9Xwjhv/w85iGm+B7HaXmqeH1ERQtVdF193p3m1nZ/92Hfc6n32RcIO++HWiVlnkRW6 DNo0MSTMloykyPlhfefMr815SSxH5HDJtjIW4qHoVlyMhqxk3pY0jLRemDVSYrz+Z/lqEv MFw3oOpoU+CRo5IMnquH2AxHFShKu24= X-Rspamd-Queue-Id: 25EDF1C0003 X-Rspam-User: Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=DFrjiwdN; spf=pass (imf18.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.210.175 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org; dmarc=pass (policy=none) header.from=chromium.org X-Rspamd-Server: rspam04 X-Stat-Signature: 3fasqmem3i1odmhzuzwdnitqdgck1dpp X-HE-Tag: 1666627953-896603 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Add a new sysfs knob that allows user-space to set zsmalloc page order value on per-device basis. Signed-off-by: Sergey Senozhatsky --- drivers/block/zram/zram_drv.c | 43 ++++++++++++++++++++++++++++++++++- drivers/block/zram/zram_drv.h | 2 ++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index e3ef542f9618..517dae4ff21c 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -1186,6 +1186,44 @@ static ssize_t mm_stat_show(struct device *dev, return ret; } +static ssize_t pool_page_order_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + u32 val; + struct zram *zram = dev_to_zram(dev); + + down_read(&zram->init_lock); + val = zram->pool_page_order; + up_read(&zram->init_lock); + + return scnprintf(buf, PAGE_SIZE, "%d\n", val); +} + +static ssize_t pool_page_order_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t len) +{ + struct zram *zram = dev_to_zram(dev); + u32 val; + + if (kstrtou32(buf, 10, &val)) + return -EINVAL; + + if (val < ZS_MIN_PAGE_ORDER || val > ZS_MAX_PAGE_ORDER) + return -EINVAL; + + down_read(&zram->init_lock); + if (init_done(zram)) { + up_read(&zram->init_lock); + return -EINVAL; + } + + zram->pool_page_order = val; + up_read(&zram->init_lock); + + return len; +} + #ifdef CONFIG_ZRAM_WRITEBACK #define FOUR_K(x) ((x) * (1 << (PAGE_SHIFT - 12))) static ssize_t bd_stat_show(struct device *dev, @@ -1254,7 +1292,7 @@ static bool zram_meta_alloc(struct zram *zram, u64 disksize) return false; zram->mem_pool = zs_create_pool(zram->disk->disk_name, - ZS_DEFAULT_PAGE_ORDER); + zram->pool_page_order); if (!zram->mem_pool) { vfree(zram->table); return false; @@ -2176,6 +2214,7 @@ static DEVICE_ATTR_RW(writeback_limit_enable); static DEVICE_ATTR_RW(recomp_algorithm); static DEVICE_ATTR_WO(recompress); #endif +static DEVICE_ATTR_RW(pool_page_order); static struct attribute *zram_disk_attrs[] = { &dev_attr_disksize.attr, @@ -2203,6 +2242,7 @@ static struct attribute *zram_disk_attrs[] = { &dev_attr_recomp_algorithm.attr, &dev_attr_recompress.attr, #endif + &dev_attr_pool_page_order.attr, NULL, }; @@ -2240,6 +2280,7 @@ static int zram_add(void) goto out_free_idr; } + zram->pool_page_order = ZS_DEFAULT_PAGE_ORDER; zram->disk->major = zram_major; zram->disk->first_minor = device_id; zram->disk->minors = 1; diff --git a/drivers/block/zram/zram_drv.h b/drivers/block/zram/zram_drv.h index 09b9ceb5dfa3..076d5b17a954 100644 --- a/drivers/block/zram/zram_drv.h +++ b/drivers/block/zram/zram_drv.h @@ -120,6 +120,8 @@ struct zram { */ u64 disksize; /* bytes */ const char *comp_algs[ZRAM_MAX_ZCOMPS]; + + u32 pool_page_order; /* * zram is claimed so open request will be failed */