From patchwork Wed Oct 26 11:29:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 13020481 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 459C8C38A2D for ; Wed, 26 Oct 2022 11:30:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DA3288E000A; Wed, 26 Oct 2022 07:30:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D535C8E0001; Wed, 26 Oct 2022 07:30:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BA6488E000A; Wed, 26 Oct 2022 07:30:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id A557F8E0001 for ; Wed, 26 Oct 2022 07:30:29 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 55D75A0F2B for ; Wed, 26 Oct 2022 11:30:29 +0000 (UTC) X-FDA: 80062882578.13.4FA84F4 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) by imf08.hostedemail.com (Postfix) with ESMTP id DFD7E16000F for ; Wed, 26 Oct 2022 11:30:28 +0000 (UTC) Received: by mail-pl1-f176.google.com with SMTP id n7so13758244plp.1 for ; Wed, 26 Oct 2022 04:30:28 -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=aT/Z4fhTkuAT6uqwfGOJvQ0sBMgcsQNCZVCxP8pxlBo=; b=PEXB9400YJgrNIKIbuMPW5DJZ23hEezyDssKRTAzHdBfEGRoNYv61tFk5sPh9u9LZB UmuRibWhoyaZqjdPjwLjUsgUxDr1AZy3km0Wmbuz/mkPvzP+Egd8E9h2e6AK5sPjA6pM KOme3SNEaFZ4JFG5Zj/kIuo/mNuJPW0c/jWQU= 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=aT/Z4fhTkuAT6uqwfGOJvQ0sBMgcsQNCZVCxP8pxlBo=; b=HtgKr4geTgGywGT2U62E/PZJ7mUNgLqDxrRvorIHjZ3zsc5jm0vlQKbfAl7FkmEOMH dyvczEM8hQp0P5InkE9QgOt3hQyosVTIw55+siQu9RdUNF5iE+uIxz5d2jVUFfdCtTgy D29WswcMhW0iYR9PaPz/S9W7v5x+ISuRYaNWYrpgi+uIlaUq1PpLwfEXyTZ3/0Q/dsdl 9INjoipCKkzeniaDffZvfA40pDPXgU24C6Y84m4lMZ3hEbIUXlbjbn+Q8E+SqOhRBFuu rztSAhYY7TGJa/PeN/LZF5b+i0oKrC7izKNfwWgCZzgsDpWrq73E36HWa1En+wKTgmSW VwMg== X-Gm-Message-State: ACrzQf3Jjz2K15M0mAxXucjri9aBt8NzpdxuPvwk4qZUuJwUH2tW+Q5W rtNT8nlDiFZxCI/Yys/SDuc9+g== X-Google-Smtp-Source: AMsMyM65lQWcdY1GRCZiFV+e7hmD7bxw4SxJccZ6E0WPQ0NgzAs46f1Zgdpb2wZ/sRCii0KuaBJ8hg== X-Received: by 2002:a17:90b:1d08:b0:212:de5d:e9e5 with SMTP id on8-20020a17090b1d0800b00212de5de9e5mr3704791pjb.239.1666783827887; Wed, 26 Oct 2022 04:30:27 -0700 (PDT) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:749c:f7f5:1a8e:d0be]) by smtp.gmail.com with ESMTPSA id x127-20020a626385000000b005627868e27esm2814919pfb.127.2022.10.26.04.30.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Oct 2022 04:30:27 -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: [PATCHv2 7/9] zram: add pages_per_pool_page device attribute Date: Wed, 26 Oct 2022 20:29:31 +0900 Message-Id: <20221026112933.4122957-8-senozhatsky@chromium.org> X-Mailer: git-send-email 2.38.0.135.g90850a2211-goog In-Reply-To: <20221026112933.4122957-1-senozhatsky@chromium.org> References: <20221026112933.4122957-1-senozhatsky@chromium.org> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666783828; a=rsa-sha256; cv=none; b=vM/Dt0+aKpegpL+uWp7WnPDdIAdThlPvbPIJeSjMcKCTr/XYlouJMeKDSj3q2SV0Rd0ijF cAK3p/ZjH2vK4uemhWIOPMeIEjCKW4usfiVnzXgc5wn4dc0YJ50BQ+vkiH4UxgC4WEl//I qT1fiVdlO0H8dRxKlEEF8rxjGJ4NGEw= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=PEXB9400; spf=pass (imf08.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.214.176 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=1666783828; 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=aT/Z4fhTkuAT6uqwfGOJvQ0sBMgcsQNCZVCxP8pxlBo=; b=YlZNMN29V10kfZsiFqgZU1RFLl/z4EcL4Ux0apDjGjL+XNOo2ug59YFiIZr6UD+W6lENnM p0JooQw/mPnZu4KC/mvc9cS3iaWv4Y1FDbBSVAFNBU0q1+LNYVA6mH1IVA4WiHSeMWQ+/8 0JYixoE98U7HIWPnAdd9pu7X5X/kq4s= X-Rspam-User: X-Rspamd-Queue-Id: DFD7E16000F Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=PEXB9400; spf=pass (imf08.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.214.176 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org; dmarc=pass (policy=none) header.from=chromium.org X-Stat-Signature: guq6pjnmyebpa44bru63mwi54m9gu91u X-Rspamd-Server: rspam03 X-HE-Tag: 1666783828-254350 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.