From patchwork Thu Oct 27 04:26:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 13021578 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 B5621FA3740 for ; Thu, 27 Oct 2022 04:27:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 579018E000A; Thu, 27 Oct 2022 00:27:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4DB7E8E0001; Thu, 27 Oct 2022 00:27:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3CA8C8E000A; Thu, 27 Oct 2022 00:27:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 2B43C8E0001 for ; Thu, 27 Oct 2022 00:27:15 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 1460640FF6 for ; Thu, 27 Oct 2022 04:27:15 +0000 (UTC) X-FDA: 80065444830.08.3665059 Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) by imf09.hostedemail.com (Postfix) with ESMTP id ACFC6140016 for ; Thu, 27 Oct 2022 04:27:14 +0000 (UTC) Received: by mail-pl1-f174.google.com with SMTP id io19so216551plb.8 for ; Wed, 26 Oct 2022 21:27:14 -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=N5K33E3z8EtL3Icy53kN5Y/g5Ea0lQ1Ab6ops7aLBNIS+jXKsvuIKf7pl/StQO4Sxi Tk2eabTStj0K/nNq7wkf19HB2NKmemzwv5wsGWC77OPM6noiXJ2I+dHJ0KiOK1Gup9o3 5Gc4eP30PwzFxV3FVrn9FP0Y+2Rz5+04mAQvU= 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=KD1jiMuAHoxajbEJEqTih1yTe1ryOjcxiz7M5BxsZ3EnThUd4C2dD5IfeAHMhBoH+Z v5+w7LTgNaZP06v0V6ITBiaJoHbkR1WbgvbA2jrMNtV0WsYgPXq5end1EorkBum6Evdd U1/tDliNvEpQMXuVKP6w6CZ/pVEs/WciRxlooHnTIpC0zfQF1YpQ+1fj3m3oJB3ftBvR OEdXMh4UgBYW7JPyk4V8PFakUt+Fhj95fpRucMeUGmbNnxojrASwkpePDRwd88TEdm3g 91LEPlwax43mDAcYiQc8cm/g84rhFCuTM8j9HPwXggsBrpH601qFKi9blXv4cMzgtJvK 7Nvg== X-Gm-Message-State: ACrzQf3EYsD7GSRLTHgsE97+UGJ4wVXNlUBWIPluEjesUQ+PMdmiNVX1 Z8eFpZvWKHGgTRgjt4TKtYV4jYMk78MAGQ== X-Google-Smtp-Source: AMsMyM64mQZiimWa8RxiZWxhQFGP3BD4EABEcOR3b5zGX9WlpvKLw+7QLjmGphKnAgGT50SjeoSrWw== X-Received: by 2002:a17:90b:1950:b0:212:de19:b3ce with SMTP id nk16-20020a17090b195000b00212de19b3cemr7807059pjb.16.1666844833835; Wed, 26 Oct 2022 21:27:13 -0700 (PDT) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:30f2:4501:65fa:df12]) by smtp.gmail.com with ESMTPSA id w23-20020aa79557000000b00565c8634e55sm203140pfq.135.2022.10.26.21.27.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Oct 2022 21:27:13 -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: [PATCHv3 7/9] zram: add pages_per_pool_page device attribute Date: Thu, 27 Oct 2022 13:26:49 +0900 Message-Id: <20221027042651.234524-8-senozhatsky@chromium.org> X-Mailer: git-send-email 2.38.0.135.g90850a2211-goog In-Reply-To: <20221027042651.234524-1-senozhatsky@chromium.org> References: <20221027042651.234524-1-senozhatsky@chromium.org> MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1666844834; 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=hOILPNInJVv5zQMvDyKVhkJ3lLjf8giaz7wcAmIHJk/p9P3EiOkjLe2YJGGc8xTSfoR/uP WT9PzjnvQOJOb2XMlh/LHUksuw2yKxKuCeBSFLZcirh4oQwuIfhnndLtMxSYtJB57U9JTm DeVZ4E268IM5pC1oCz/3GOnZqzEqZNk= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=N5K33E3z; spf=pass (imf09.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.214.174 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org; dmarc=pass (policy=none) header.from=chromium.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666844834; a=rsa-sha256; cv=none; b=i2iCiLSaIbuTPuA34viH6YABpDqI0ods46RukltpbRBhKKcs01hpdZvhnR0y3YDeKv7j1v Mo0fm2hWZ2i8g3VZoEZUR/qFz3mSRRWSZQMvOQwdKQc2vZs3pMHEB2CrtRq6JTp6403IVk avA3jJd9F/BM3X8NOkkT+8OR9dUGLoE= Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=N5K33E3z; spf=pass (imf09.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.214.174 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org; dmarc=pass (policy=none) header.from=chromium.org X-Stat-Signature: crrsebjbcuyw5czjdktuih1a8b81h6jz X-Rspamd-Queue-Id: ACFC6140016 X-Rspamd-Server: rspam07 X-Rspam-User: X-HE-Tag: 1666844834-87732 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.