From patchwork Mon Oct 31 05:41:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 13025396 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 91D23C38A02 for ; Mon, 31 Oct 2022 05:41:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 32E3580009; Mon, 31 Oct 2022 01:41:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2DD0280007; Mon, 31 Oct 2022 01:41:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 17EA480009; Mon, 31 Oct 2022 01:41:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id E3EF380007 for ; Mon, 31 Oct 2022 01:41:36 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 905E6409F4 for ; Mon, 31 Oct 2022 05:41:36 +0000 (UTC) X-FDA: 80080147392.30.4C4B5F1 Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) by imf03.hostedemail.com (Postfix) with ESMTP id 22B9C20008 for ; Mon, 31 Oct 2022 05:41:35 +0000 (UTC) Received: by mail-pj1-f49.google.com with SMTP id m14-20020a17090a3f8e00b00212dab39bcdso15006592pjc.0 for ; Sun, 30 Oct 2022 22:41:35 -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=+Nf0+I2pfgnRZzXVFRfDlyfCUhznpUvJ315tu0OUOiI=; b=MbpTgPIBDUbHWkS+9YopOfHoRnV74v+JNz6BX6X//rBB/LmgPIElbp4GRlLTwjJzxc alebDGyAW4DJc/zlleAs/HRTGa9HptGICD/6ejNkUbdmk/vWUa3Ai/OhOrukv76eLsnd na8Fa3d+5bCIlVErli3M7VEvFks54n/u5Xz0I= 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=+Nf0+I2pfgnRZzXVFRfDlyfCUhznpUvJ315tu0OUOiI=; b=E/hUjENMjnlKbQaE7lVE94VSnWTXZZOUDU3mqP9QeQW10mfjod1rJIaQY8asV8WdDk 90H/gqpPnmWkdU3CriDZ76aC+RnsBI4Jx33w/5xFWvHLdhEaeW5K1eEXR7nEEe/+r2jM JzUMZhSLEIOtBv02rx/6lRCyX+ao8qr+aMSIDowY7Sc2BOGcvEw0YAvrTCk9Ib1SyE13 7InOwRDNeipYimFEyW0C5vsXo5P//XNz8PRSATm+JINPOxr7i7R1zEJI+VZbfIXXbklI XFG33xMRgmomy01X1k0ZnQ1yJCgbfb3YLkD0/QuoHzU8Od3Hka558J5/zoUe2VYoEuMk liiA== X-Gm-Message-State: ACrzQf1Po18pdvxpLP05FElZHD88TqgRLK0B0gzK2v865rjhAVARLVbB h+yjd1C+fzZvPwperZ33thZJ3fGMlEsjeA== X-Google-Smtp-Source: AMsMyM6aj/ay4NFqqeS6lMD0qg9sOyjXe4OVHq+CQp3TJTjjwqL7C30ANPBoUZZhZIHNH3n4pSp/5w== X-Received: by 2002:a17:90b:1bca:b0:213:c9ce:dad4 with SMTP id oa10-20020a17090b1bca00b00213c9cedad4mr7600860pjb.205.1667194895001; Sun, 30 Oct 2022 22:41:35 -0700 (PDT) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:7616:afe0:ba6c:96f4]) by smtp.gmail.com with ESMTPSA id w12-20020aa79a0c000000b0056befcd7958sm3573308pfj.84.2022.10.30.22.41.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Oct 2022 22:41:34 -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: [PATCHv4 7/9] zram: add pages_per_pool_page device attribute Date: Mon, 31 Oct 2022 14:41:06 +0900 Message-Id: <20221031054108.541190-8-senozhatsky@chromium.org> X-Mailer: git-send-email 2.38.1.273.g43a17bfeac-goog In-Reply-To: <20221031054108.541190-1-senozhatsky@chromium.org> References: <20221031054108.541190-1-senozhatsky@chromium.org> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1667194896; a=rsa-sha256; cv=none; b=7gsXrJitsE7BNJ0leOL+WXt+ZR8+FccQ7xiM3qGYTA/aK7iGGobAhV0ea7lqfDdahcdY0G 5IWMmNzGRWIC0t2AMcS1VpT5etgUvi17/oE2b60hziNwVEMDJzAUd9KnPzOFOHrLtOXmp1 iCdbA1lePPlvgfjgE0bctCkCAlDMWBk= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=MbpTgPIB; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf03.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.216.49 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1667194896; 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=+Nf0+I2pfgnRZzXVFRfDlyfCUhznpUvJ315tu0OUOiI=; b=SMd5SsXzCKgbv6od+DLNeglr9SpxokxSc6nFiY6hre311NCFC7S2xo6G5q9hEmSgOAPE8e +V+45tUKirx7CBykr1BzBb7xqnL23MxQsgPHP/6QI8yOyN9xwM25XCHCpBDlOy5y5Z7p9H cplxhQrFkF3R1Y7NU4u5UTWQ5i6CdiQ= X-Stat-Signature: jjjm3qdwj158nwifs5un34ghjprdbfdu X-Rspamd-Queue-Id: 22B9C20008 X-Rspam-User: Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=MbpTgPIB; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf03.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.216.49 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org X-Rspamd-Server: rspam09 X-HE-Tag: 1667194895-478895 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 pages per-zspage limit value on per-device basis. Signed-off-by: Sergey Senozhatsky --- drivers/block/zram/zram_drv.c | 44 ++++++++++++++++++++++++++++++++++- drivers/block/zram/zram_drv.h | 2 ++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index bec02f636bce..cf9d3474b80c 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -1180,6 +1180,45 @@ static ssize_t mm_stat_show(struct device *dev, return ret; } +static ssize_t pages_per_pool_page_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->pages_per_pool_page; + up_read(&zram->init_lock); + + return scnprintf(buf, PAGE_SIZE, "%d\n", val); +} + +static ssize_t pages_per_pool_page_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_PAGES_PER_ZSPAGE || val > ZS_MAX_PAGES_PER_ZSPAGE) + return -EINVAL; + + down_read(&zram->init_lock); + if (init_done(zram)) { + up_read(&zram->init_lock); + return -EINVAL; + } + + zram->pages_per_pool_page = 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, @@ -1248,7 +1287,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_PAGES_PER_ZSPAGE); + zram->pages_per_pool_page); if (!zram->mem_pool) { vfree(zram->table); return false; @@ -2174,6 +2213,7 @@ static DEVICE_ATTR_RW(writeback_limit_enable); static DEVICE_ATTR_RW(recomp_algorithm); static DEVICE_ATTR_WO(recompress); #endif +static DEVICE_ATTR_RW(pages_per_pool_page); static struct attribute *zram_disk_attrs[] = { &dev_attr_disksize.attr, @@ -2201,6 +2241,7 @@ static struct attribute *zram_disk_attrs[] = { &dev_attr_recomp_algorithm.attr, &dev_attr_recompress.attr, #endif + &dev_attr_pages_per_pool_page.attr, NULL, }; @@ -2238,6 +2279,7 @@ static int zram_add(void) goto out_free_idr; } + zram->pages_per_pool_page = ZS_DEFAULT_PAGES_PER_ZSPAGE; 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 9d6fcfdf7aa7..bdfc9bf0bdd5 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 pages_per_pool_page; /* * Pages that compress to sizes equal or greater than this are stored * uncompressed in memory.