From patchwork Wed Nov 9 11:50:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 13037457 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 BD359C43217 for ; Wed, 9 Nov 2022 11:51:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 615E78E0001; Wed, 9 Nov 2022 06:51:43 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5763E6B0078; Wed, 9 Nov 2022 06:51:43 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3F0118E0001; Wed, 9 Nov 2022 06:51:43 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 3283C6B0075 for ; Wed, 9 Nov 2022 06:51:43 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id D67C11212C0 for ; Wed, 9 Nov 2022 11:51:42 +0000 (UTC) X-FDA: 80113739244.30.8C53740 Received: from mail-pj1-f47.google.com (mail-pj1-f47.google.com [209.85.216.47]) by imf28.hostedemail.com (Postfix) with ESMTP id 56707C0012 for ; Wed, 9 Nov 2022 11:51:37 +0000 (UTC) Received: by mail-pj1-f47.google.com with SMTP id f5-20020a17090a4a8500b002131bb59d61so3300744pjh.1 for ; Wed, 09 Nov 2022 03:51:37 -0800 (PST) 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=Rh+SDXfLWIiVuWyo4HoAJrWsmodyn/AWQvoZfxriBos=; b=lg6XyX6EZCivsCvPp8F8Rk6MdzQU/pZ+5B2QkiAgYr9uOdlZI8FpXbs7pOWgOxaC27 Ha1xmVXR8wH+qelEb8KwopTpXVQWggLiLk+qU61M2tVtEFOJ5v89IAhpSrgx7rGO6XZ+ rZpDnypFeVyF+dtrNl7DFImc7xwrivwZmV2cU= 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=Rh+SDXfLWIiVuWyo4HoAJrWsmodyn/AWQvoZfxriBos=; b=Y/7klxe/NMfdrWJjLVlKpLPfQyZeAir0yrpil274to8wVFt7DwsxePjJzhcRaohoo1 +nBL5/QF72wKDfeX0k8jbrG5Dtw6XoF7PJH1n8jB217D3nXbAm7hWZyfhGzmLlqHy6AR LtmlpGn2mFiuUDdl5+NlHE2KltE2CCSSmF3WZBEeecInijP1OyDV+8hwHDtwrrsCu7ZL Fc5RIFFLMd77NVbD6SXiNGlEKpxuCKyUdqLnz4mdg8L69NXpHzSD3Z0XO3aKernHD/r0 RrCT+3wWJcZTgfS01lF4va8bmpAOzjMOuKGtz751SXfaRiiRPqqJRqZTysvSIdxfAHWn KRRw== X-Gm-Message-State: ACrzQf1vrFKTENPBw+CVhNB9t/5jm0c0k3T55LDYn84MzvYvc+qULtRc x4z4u90V0/0bHZsZzZKXYHERFJGpnUR+zg== X-Google-Smtp-Source: AMsMyM5ap4cnFJgQIJB7Qd+V3iIFej6hsh6xDMaaJARu3Yb9BdtCqFiYi2/jyzLy7wFP2TGgAFTMcA== X-Received: by 2002:a17:903:11cd:b0:170:cde8:18b7 with SMTP id q13-20020a17090311cd00b00170cde818b7mr44212976plh.165.1667994657224; Wed, 09 Nov 2022 03:50:57 -0800 (PST) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:61f1:44d3:3f47:2cdb]) by smtp.gmail.com with ESMTPSA id f5-20020a655505000000b00434760ee36asm7292311pgr.16.2022.11.09.03.50.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Nov 2022 03:50:56 -0800 (PST) From: Sergey Senozhatsky To: Minchan Kim , Andrew Morton Cc: Nitin Gupta , Suleiman Souhlal , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Sergey Senozhatsky Subject: [PATCHv5 01/13] zram: Preparation for multi-zcomp support Date: Wed, 9 Nov 2022 20:50:35 +0900 Message-Id: <20221109115047.2921851-2-senozhatsky@chromium.org> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog In-Reply-To: <20221109115047.2921851-1-senozhatsky@chromium.org> References: <20221109115047.2921851-1-senozhatsky@chromium.org> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1667994697; a=rsa-sha256; cv=none; b=dZTzUCwOx9PDNXYO23Vwcgrw6Om9Tiav1NNaeQbw8j6FMZmHChlimpe1TdYL144sJVrkQI eObd2ZQol/x4R2Svb79UmqqiIPnJgo5Dgj+QqINhlzMuOOToyLvnv2xQ1VHR56IwzNdvPd n5Vij/wZxj5Mdout4MXvWYkBFo4jEE4= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=lg6XyX6E; spf=pass (imf28.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.216.47 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=1667994697; 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=Rh+SDXfLWIiVuWyo4HoAJrWsmodyn/AWQvoZfxriBos=; b=H86a1+sgcQzbR11JJzFBuTHcHDjzjNG9YU9Yzb22GnFDRATyvKUbLnQ/P8AiD3kj8A5Kpl 8VoCXqI/Qavi8RqEp3Po+XSFx807Yk3F2CTEivuoFEyspoRcWYS4SlP3BDx8qRTxkIh6a/ mfwxQjy4FYDZOpEMei+XaPwf7x54Sac= Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=lg6XyX6E; spf=pass (imf28.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.216.47 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org; dmarc=pass (policy=none) header.from=chromium.org X-Rspamd-Server: rspam12 X-Rspam-User: X-Stat-Signature: iu6fdbu8md9h46qy78qakm53txj4ucp1 X-Rspamd-Queue-Id: 56707C0012 X-HE-Tag: 1667994697-920818 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: The patch turns compression streams and compressor algorithm name struct zram members into arrays, so that we can have multiple compression streams support (in the next patches). The patch uses a rather explicit API for compressor selection: - Get primary (default) compression stream zcomp_stream_get(zram->comps[ZRAM_PRIMARY_COMP]) - Get secondary compression stream zcomp_stream_get(zram->comps[ZRAM_SECONDARY_COMP]) We use similar API for compression streams put(). At this point we always have just one compression stream, since CONFIG_ZRAM_MULTI_COMP is not yet defined. Signed-off-by: Sergey Senozhatsky --- drivers/block/zram/zcomp.c | 6 +-- drivers/block/zram/zcomp.h | 2 +- drivers/block/zram/zram_drv.c | 90 +++++++++++++++++++++++++---------- drivers/block/zram/zram_drv.h | 14 +++++- 4 files changed, 80 insertions(+), 32 deletions(-) diff --git a/drivers/block/zram/zcomp.c b/drivers/block/zram/zcomp.c index 0916de952e09..55af4efd7983 100644 --- a/drivers/block/zram/zcomp.c +++ b/drivers/block/zram/zcomp.c @@ -206,7 +206,7 @@ void zcomp_destroy(struct zcomp *comp) * case of allocation error, or any other error potentially * returned by zcomp_init(). */ -struct zcomp *zcomp_create(const char *compress) +struct zcomp *zcomp_create(const char *alg) { struct zcomp *comp; int error; @@ -216,14 +216,14 @@ struct zcomp *zcomp_create(const char *compress) * is not loaded yet. We must do it here, otherwise we are about to * call /sbin/modprobe under CPU hot-plug lock. */ - if (!zcomp_available_algorithm(compress)) + if (!zcomp_available_algorithm(alg)) return ERR_PTR(-EINVAL); comp = kzalloc(sizeof(struct zcomp), GFP_KERNEL); if (!comp) return ERR_PTR(-ENOMEM); - comp->name = compress; + comp->name = alg; error = zcomp_init(comp); if (error) { kfree(comp); diff --git a/drivers/block/zram/zcomp.h b/drivers/block/zram/zcomp.h index 40f6420f4b2e..cdefdef93da8 100644 --- a/drivers/block/zram/zcomp.h +++ b/drivers/block/zram/zcomp.h @@ -27,7 +27,7 @@ int zcomp_cpu_dead(unsigned int cpu, struct hlist_node *node); ssize_t zcomp_available_show(const char *comp, char *buf); bool zcomp_available_algorithm(const char *comp); -struct zcomp *zcomp_create(const char *comp); +struct zcomp *zcomp_create(const char *alg); void zcomp_destroy(struct zcomp *comp); struct zcomp_strm *zcomp_stream_get(struct zcomp *comp); diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index 966aab902d19..5371ed63c785 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -1007,36 +1007,53 @@ static ssize_t comp_algorithm_show(struct device *dev, struct zram *zram = dev_to_zram(dev); down_read(&zram->init_lock); - sz = zcomp_available_show(zram->compressor, buf); + sz = zcomp_available_show(zram->comp_algs[ZRAM_PRIMARY_COMP], buf); up_read(&zram->init_lock); return sz; } +static void comp_algorithm_set(struct zram *zram, u32 prio, const char *alg) +{ + /* Do not kfree() algs that we didn't allocate, IOW the default ones */ + if (zram->comp_algs[prio] != default_compressor) + kfree(zram->comp_algs[prio]); + zram->comp_algs[prio] = alg; +} + static ssize_t comp_algorithm_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t len) { struct zram *zram = dev_to_zram(dev); - char compressor[ARRAY_SIZE(zram->compressor)]; + char *compressor; size_t sz; - strscpy(compressor, buf, sizeof(compressor)); + sz = strlen(buf); + if (sz >= CRYPTO_MAX_ALG_NAME) + return -E2BIG; + + compressor = kstrdup(buf, GFP_KERNEL); + if (!compressor) + return -ENOMEM; + /* ignore trailing newline */ - sz = strlen(compressor); if (sz > 0 && compressor[sz - 1] == '\n') compressor[sz - 1] = 0x00; - if (!zcomp_available_algorithm(compressor)) + if (!zcomp_available_algorithm(compressor)) { + kfree(compressor); return -EINVAL; + } down_write(&zram->init_lock); if (init_done(zram)) { up_write(&zram->init_lock); + kfree(compressor); pr_info("Can't change algorithm for initialized device\n"); return -EBUSY; } - strcpy(zram->compressor, compressor); + comp_algorithm_set(zram, ZRAM_PRIMARY_COMP, compressor); up_write(&zram->init_lock); return len; } @@ -1284,7 +1301,7 @@ static int __zram_bvec_read(struct zram *zram, struct page *page, u32 index, size = zram_get_obj_size(zram, index); if (size != PAGE_SIZE) - zstrm = zcomp_stream_get(zram->comp); + zstrm = zcomp_stream_get(zram->comps[ZRAM_PRIMARY_COMP]); src = zs_map_object(zram->mem_pool, handle, ZS_MM_RO); if (size == PAGE_SIZE) { @@ -1296,7 +1313,7 @@ static int __zram_bvec_read(struct zram *zram, struct page *page, u32 index, dst = kmap_atomic(page); ret = zcomp_decompress(zstrm, src, size, dst); kunmap_atomic(dst); - zcomp_stream_put(zram->comp); + zcomp_stream_put(zram->comps[ZRAM_PRIMARY_COMP]); } zs_unmap_object(zram->mem_pool, handle); zram_slot_unlock(zram, index); @@ -1363,13 +1380,13 @@ static int __zram_bvec_write(struct zram *zram, struct bio_vec *bvec, kunmap_atomic(mem); compress_again: - zstrm = zcomp_stream_get(zram->comp); + zstrm = zcomp_stream_get(zram->comps[ZRAM_PRIMARY_COMP]); src = kmap_atomic(page); ret = zcomp_compress(zstrm, src, &comp_len); kunmap_atomic(src); if (unlikely(ret)) { - zcomp_stream_put(zram->comp); + zcomp_stream_put(zram->comps[ZRAM_PRIMARY_COMP]); pr_err("Compression failed! err=%d\n", ret); zs_free(zram->mem_pool, handle); return ret; @@ -1397,7 +1414,7 @@ static int __zram_bvec_write(struct zram *zram, struct bio_vec *bvec, __GFP_HIGHMEM | __GFP_MOVABLE); if (IS_ERR((void *)handle)) { - zcomp_stream_put(zram->comp); + zcomp_stream_put(zram->comps[ZRAM_PRIMARY_COMP]); atomic64_inc(&zram->stats.writestall); handle = zs_malloc(zram->mem_pool, comp_len, GFP_NOIO | __GFP_HIGHMEM | @@ -1414,14 +1431,14 @@ static int __zram_bvec_write(struct zram *zram, struct bio_vec *bvec, * zstrm buffer back. It is necessary that the dereferencing * of the zstrm variable below occurs correctly. */ - zstrm = zcomp_stream_get(zram->comp); + zstrm = zcomp_stream_get(zram->comps[ZRAM_PRIMARY_COMP]); } alloced_pages = zs_get_total_pages(zram->mem_pool); update_used_max(zram, alloced_pages); if (zram->limit_pages && alloced_pages > zram->limit_pages) { - zcomp_stream_put(zram->comp); + zcomp_stream_put(zram->comps[ZRAM_PRIMARY_COMP]); zs_free(zram->mem_pool, handle); return -ENOMEM; } @@ -1435,7 +1452,7 @@ static int __zram_bvec_write(struct zram *zram, struct bio_vec *bvec, if (comp_len == PAGE_SIZE) kunmap_atomic(src); - zcomp_stream_put(zram->comp); + zcomp_stream_put(zram->comps[ZRAM_PRIMARY_COMP]); zs_unmap_object(zram->mem_pool, handle); atomic64_add(comp_len, &zram->stats.compr_data_size); out: @@ -1710,6 +1727,20 @@ static int zram_rw_page(struct block_device *bdev, sector_t sector, return ret; } +static void zram_destroy_comps(struct zram *zram) +{ + u32 prio; + + for (prio = 0; prio < ZRAM_MAX_COMPS; prio++) { + struct zcomp *comp = zram->comps[prio]; + + zram->comps[prio] = NULL; + if (!comp) + continue; + zcomp_destroy(comp); + } +} + static void zram_reset_device(struct zram *zram) { down_write(&zram->init_lock); @@ -1727,11 +1758,11 @@ static void zram_reset_device(struct zram *zram) /* I/O operation under all of CPU are done so let's free */ zram_meta_free(zram, zram->disksize); zram->disksize = 0; + zram_destroy_comps(zram); memset(&zram->stats, 0, sizeof(zram->stats)); - zcomp_destroy(zram->comp); - zram->comp = NULL; reset_bdev(zram); + comp_algorithm_set(zram, ZRAM_PRIMARY_COMP, default_compressor); up_write(&zram->init_lock); } @@ -1742,6 +1773,7 @@ static ssize_t disksize_store(struct device *dev, struct zcomp *comp; struct zram *zram = dev_to_zram(dev); int err; + u32 prio; disksize = memparse(buf, NULL); if (!disksize) @@ -1760,22 +1792,28 @@ static ssize_t disksize_store(struct device *dev, goto out_unlock; } - comp = zcomp_create(zram->compressor); - if (IS_ERR(comp)) { - pr_err("Cannot initialise %s compressing backend\n", - zram->compressor); - err = PTR_ERR(comp); - goto out_free_meta; - } + for (prio = 0; prio < ZRAM_MAX_COMPS; prio++) { + if (!zram->comp_algs[prio]) + continue; + + comp = zcomp_create(zram->comp_algs[prio]); + if (IS_ERR(comp)) { + pr_err("Cannot initialise %s compressing backend\n", + zram->comp_algs[prio]); + err = PTR_ERR(comp); + goto out_free_comps; + } - zram->comp = comp; + zram->comps[prio] = comp; + } zram->disksize = disksize; set_capacity_and_notify(zram->disk, zram->disksize >> SECTOR_SHIFT); up_write(&zram->init_lock); return len; -out_free_meta: +out_free_comps: + zram_destroy_comps(zram); zram_meta_free(zram, disksize); out_unlock: up_write(&zram->init_lock); @@ -1962,7 +2000,7 @@ static int zram_add(void) if (ret) goto out_cleanup_disk; - strscpy(zram->compressor, default_compressor, sizeof(zram->compressor)); + zram->comp_algs[ZRAM_PRIMARY_COMP] = default_compressor; zram_debugfs_register(zram); pr_info("Added device: %s\n", zram->disk->disk_name); diff --git a/drivers/block/zram/zram_drv.h b/drivers/block/zram/zram_drv.h index a2bda53020fd..7a643c8c38ec 100644 --- a/drivers/block/zram/zram_drv.h +++ b/drivers/block/zram/zram_drv.h @@ -89,10 +89,20 @@ struct zram_stats { #endif }; +#ifdef CONFIG_ZRAM_MULTI_COMP +#define ZRAM_PRIMARY_COMP 0U +#define ZRAM_SECONDARY_COMP 1U +#define ZRAM_MAX_COMPS 4U +#else +#define ZRAM_PRIMARY_COMP 0U +#define ZRAM_SECONDARY_COMP 0U +#define ZRAM_MAX_COMPS 1U +#endif + struct zram { struct zram_table_entry *table; struct zs_pool *mem_pool; - struct zcomp *comp; + struct zcomp *comps[ZRAM_MAX_COMPS]; struct gendisk *disk; /* Prevent concurrent execution of device init */ struct rw_semaphore init_lock; @@ -107,7 +117,7 @@ struct zram { * we can store in a disk. */ u64 disksize; /* bytes */ - char compressor[CRYPTO_MAX_ALG_NAME]; + const char *comp_algs[ZRAM_MAX_COMPS]; /* * zram is claimed so open request will be failed */ From patchwork Wed Nov 9 11:50:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 13037455 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 150DCC433FE for ; Wed, 9 Nov 2022 11:51:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8AB646B0074; Wed, 9 Nov 2022 06:51:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 85C3F8E0001; Wed, 9 Nov 2022 06:51:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 723F56B0078; Wed, 9 Nov 2022 06:51:42 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 648426B0074 for ; Wed, 9 Nov 2022 06:51:42 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 1E3C5C06B3 for ; Wed, 9 Nov 2022 11:51:42 +0000 (UTC) X-FDA: 80113739244.08.09C6C5C Received: from mail-pj1-f47.google.com (mail-pj1-f47.google.com [209.85.216.47]) by imf03.hostedemail.com (Postfix) with ESMTP id BA5C020012 for ; Wed, 9 Nov 2022 11:51:36 +0000 (UTC) Received: by mail-pj1-f47.google.com with SMTP id m14-20020a17090a3f8e00b00212dab39bcdso1640224pjc.0 for ; Wed, 09 Nov 2022 03:51:36 -0800 (PST) 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=2STvSSncO0NE+Pc4XM/M24vXge8hgNvkyOrZLLo09CU=; b=Gnj8YxkZmSXisqpa9f9O26JNP3w9Jr92llhfl96tANf3bFA1UUpYeanXW/x1XBpd1T ReKNHsqAsLWVqB7RONpDvI1p9U74iuIlieuE7HOpICpJzJKH1kBktLXfHl103bUf82Lr eDAqyc0zNwuD4OrOAil0SbC8M8KIN6gRnOxnc= 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=2STvSSncO0NE+Pc4XM/M24vXge8hgNvkyOrZLLo09CU=; b=3AmwHBmQoGd+eSfSwSEJnKsqT+HIVRkpOdoiAnl6RwT0FEw57rdQVS7mpFdEp8sedZ UfZqfMA7gSn/bww5TwW+GQUwSESwz0FNn6puqPopYP/SfpJUGQTKX/HsgPoGw1U0r/uU RKLWaGRBJTLBEyQ/ibOSDGZ6XVJ9sLb0R3PrGQ141uNxpFqsyLyGTEh3sc/x2s+ZxHNs +vC4oNSgOxXUd9lqcTYwksMooK5rYhAEE+ifFD+39/eI1qEIdwY/WAanaUdhm+4W9mBa lsmWYwPyNtEQcrvrgx2+bq/RpFEwlO3Bhwv1jPUuiPvW1Nvtb+lnrvB3RZheoUP9z15a L9Ew== X-Gm-Message-State: ACrzQf0TigQIYmG3AwptBO3TCvNONqeKgb9z0URJ18gox2OQEy0+eaYN U2FLShOzxJ05gSLFeW8PWu8Z197mH70YBg== X-Google-Smtp-Source: AMsMyM6xPKvI1rFKl5nOfDTS3HUFzInmPELN0OJL4VTq5t1OcpxDaMsalY0qlRJ2qAgEQis7z+sUuA== X-Received: by 2002:a17:90b:3113:b0:213:82ad:9bc7 with SMTP id gc19-20020a17090b311300b0021382ad9bc7mr71655635pjb.131.1667994659864; Wed, 09 Nov 2022 03:50:59 -0800 (PST) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:61f1:44d3:3f47:2cdb]) by smtp.gmail.com with ESMTPSA id f5-20020a655505000000b00434760ee36asm7292311pgr.16.2022.11.09.03.50.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Nov 2022 03:50:59 -0800 (PST) From: Sergey Senozhatsky To: Minchan Kim , Andrew Morton Cc: Nitin Gupta , Suleiman Souhlal , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Sergey Senozhatsky Subject: [PATCHv5 02/13] zram: Add recompression algorithm sysfs knob Date: Wed, 9 Nov 2022 20:50:36 +0900 Message-Id: <20221109115047.2921851-3-senozhatsky@chromium.org> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog In-Reply-To: <20221109115047.2921851-1-senozhatsky@chromium.org> References: <20221109115047.2921851-1-senozhatsky@chromium.org> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1667994696; a=rsa-sha256; cv=none; b=EwlgdxpR+SrqcKgp+CnQ40SK5brvcWGubvMiuAvTWda9Vb3p0/wjMC7dClBzqaf8ojb2Q4 dzUxD1wzeY+xQ1PFDqjUDE6KouhT2bAfi63TbCESdLTxMq+oRvQy6gqTTLRc7PsGCEN5A7 u69wK3lBWEbS8uhLX+Dz4iRMTrPtS3c= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=Gnj8YxkZ; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf03.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.216.47 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=1667994696; 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=2STvSSncO0NE+Pc4XM/M24vXge8hgNvkyOrZLLo09CU=; b=VFMo9DNsSm5gyR80jDTSuCbt7rQfcb6l2WNuGA0o+N1oh09vkIPsoMjJb+roCLKPoyzElt eM06Q95INy2F1wW3AZtWXwzIV/Ji4n/OqbWAM21lqyzWb9TqZz1wHzCyBEdr1wWP599ZA9 zL0fvnw1t3OabpGllSUJryFRmz8Fkxk= X-Rspam-User: X-Stat-Signature: xu6bi18p9uok3q6xdpimr9re8orc3k8h X-Rspamd-Queue-Id: BA5C020012 Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=Gnj8YxkZ; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf03.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.216.47 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org X-Rspamd-Server: rspam03 X-HE-Tag: 1667994696-999124 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: Introduce recomp_algorithm sysfs knob that controls secondary algorithm selection used for recompression. We will support up to 3 secondary compression algorithms which are sorted in order of their priority. To select an algorithm user has to provide its name and priority: echo "algo=zstd priority=1" > /sys/block/zramX/recomp_algorithm echo "algo=deflate priority=2" > /sys/block/zramX/recomp_algorithm During recompression zram iterates through the list of registered secondary algorithms in order of their priorities. We also have a short version for cases when there is only one secondary compression algorithm: echo "algo=zstd" > /sys/block/zramX/recomp_algorithm This will register zstd as the secondary algorithm with priority 1. Signed-off-by: Sergey Senozhatsky --- drivers/block/zram/zram_drv.c | 124 ++++++++++++++++++++++++++++------ 1 file changed, 105 insertions(+), 19 deletions(-) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index 5371ed63c785..56026a6deb70 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -1000,31 +1000,28 @@ static ssize_t max_comp_streams_store(struct device *dev, return len; } -static ssize_t comp_algorithm_show(struct device *dev, - struct device_attribute *attr, char *buf) +static void comp_algorithm_set(struct zram *zram, u32 prio, const char *alg) { - size_t sz; - struct zram *zram = dev_to_zram(dev); + /* Do not free statically defined compression algorithms */ + if (zram->comp_algs[prio] != default_compressor) + kfree(zram->comp_algs[prio]); + + zram->comp_algs[prio] = alg; +} + +static ssize_t __comp_algorithm_show(struct zram *zram, u32 prio, char *buf) +{ + ssize_t sz; down_read(&zram->init_lock); - sz = zcomp_available_show(zram->comp_algs[ZRAM_PRIMARY_COMP], buf); + sz = zcomp_available_show(zram->comp_algs[prio], buf); up_read(&zram->init_lock); return sz; } -static void comp_algorithm_set(struct zram *zram, u32 prio, const char *alg) +static int __comp_algorithm_store(struct zram *zram, u32 prio, const char *buf) { - /* Do not kfree() algs that we didn't allocate, IOW the default ones */ - if (zram->comp_algs[prio] != default_compressor) - kfree(zram->comp_algs[prio]); - zram->comp_algs[prio] = alg; -} - -static ssize_t comp_algorithm_store(struct device *dev, - struct device_attribute *attr, const char *buf, size_t len) -{ - struct zram *zram = dev_to_zram(dev); char *compressor; size_t sz; @@ -1053,11 +1050,94 @@ static ssize_t comp_algorithm_store(struct device *dev, return -EBUSY; } - comp_algorithm_set(zram, ZRAM_PRIMARY_COMP, compressor); + comp_algorithm_set(zram, prio, compressor); up_write(&zram->init_lock); - return len; + return 0; +} + +static ssize_t comp_algorithm_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct zram *zram = dev_to_zram(dev); + + return __comp_algorithm_show(zram, ZRAM_PRIMARY_COMP, buf); +} + +static ssize_t comp_algorithm_store(struct device *dev, + struct device_attribute *attr, + const char *buf, + size_t len) +{ + struct zram *zram = dev_to_zram(dev); + int ret; + + ret = __comp_algorithm_store(zram, ZRAM_PRIMARY_COMP, buf); + return ret ? ret : len; } +#ifdef CONFIG_ZRAM_MULTI_COMP +static ssize_t recomp_algorithm_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct zram *zram = dev_to_zram(dev); + ssize_t sz = 0; + u32 prio; + + for (prio = ZRAM_SECONDARY_COMP; prio < ZRAM_MAX_COMPS; prio++) { + if (!zram->comp_algs[prio]) + continue; + + sz += scnprintf(buf + sz, PAGE_SIZE - sz - 2, "#%d: ", prio); + sz += __comp_algorithm_show(zram, prio, buf + sz); + } + + return sz; +} + +static ssize_t recomp_algorithm_store(struct device *dev, + struct device_attribute *attr, + const char *buf, + size_t len) +{ + struct zram *zram = dev_to_zram(dev); + int prio = ZRAM_SECONDARY_COMP; + char *args, *param, *val; + char *alg = NULL; + int ret; + + args = skip_spaces(buf); + while (*args) { + args = next_arg(args, ¶m, &val); + + if (!*val) + return -EINVAL; + + if (!strcmp(param, "algo")) { + alg = val; + continue; + } + + if (!strcmp(param, "priority")) { + ret = kstrtoint(val, 10, &prio); + if (ret) + return ret; + continue; + } + } + + if (!alg) + return -EINVAL; + + if (prio < ZRAM_SECONDARY_COMP || prio >= ZRAM_MAX_COMPS) + return -EINVAL; + + ret = __comp_algorithm_store(zram, prio, alg); + return ret ? ret : len; +} +#endif + static ssize_t compact_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t len) { @@ -1898,6 +1978,9 @@ static DEVICE_ATTR_WO(writeback); static DEVICE_ATTR_RW(writeback_limit); static DEVICE_ATTR_RW(writeback_limit_enable); #endif +#ifdef CONFIG_ZRAM_MULTI_COMP +static DEVICE_ATTR_RW(recomp_algorithm); +#endif static struct attribute *zram_disk_attrs[] = { &dev_attr_disksize.attr, @@ -1921,6 +2004,9 @@ static struct attribute *zram_disk_attrs[] = { &dev_attr_bd_stat.attr, #endif &dev_attr_debug_stat.attr, +#ifdef CONFIG_ZRAM_MULTI_COMP + &dev_attr_recomp_algorithm.attr, +#endif NULL, }; @@ -2000,7 +2086,7 @@ static int zram_add(void) if (ret) goto out_cleanup_disk; - zram->comp_algs[ZRAM_PRIMARY_COMP] = default_compressor; + comp_algorithm_set(zram, ZRAM_PRIMARY_COMP, default_compressor); zram_debugfs_register(zram); pr_info("Added device: %s\n", zram->disk->disk_name); From patchwork Wed Nov 9 11:50:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 13037463 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 D7D66C433FE for ; Wed, 9 Nov 2022 11:52:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 724918E0006; Wed, 9 Nov 2022 06:52:09 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6D5298E0005; Wed, 9 Nov 2022 06:52:09 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 59D2C8E0006; Wed, 9 Nov 2022 06:52:09 -0500 (EST) 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 4E23E8E0005 for ; Wed, 9 Nov 2022 06:52:09 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 01CF8AB36E for ; Wed, 9 Nov 2022 11:52:03 +0000 (UTC) X-FDA: 80113740168.29.9633929 Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) by imf06.hostedemail.com (Postfix) with ESMTP id 9CA2C180012 for ; Wed, 9 Nov 2022 11:51:58 +0000 (UTC) Received: by mail-pl1-f172.google.com with SMTP id 4so16908919pli.0 for ; Wed, 09 Nov 2022 03:51:58 -0800 (PST) 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=NwLhHMvq7VueCMpUkTq+C+HTS32+Lk3Kl1y4kkNY1lI=; b=XU5vLFwkohaoQzaV3wsD4syG9ewC5z9qtbUASnBpI7yZfx6A/26UPA/KGss1F89lzr bLhHgQibUdXpBvhVKkTalBkDQSjdosyCaORUHtLQtl3nxDZaeFifxXfpsE09Dx1L42Ag Lh43EhiVNoB8JL3gbSz6XvnAW519pupdtZBZ0= 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=NwLhHMvq7VueCMpUkTq+C+HTS32+Lk3Kl1y4kkNY1lI=; b=RXUk7OFxKpgVzoWB19WJSQHImliQNHe54F0cI7n+4GQz/tRGYDIizYcmp8rKkGsvG9 H2Ba0b/9MCt3+YMlKsxkLsvuOZIP/ntzSMjFFtBRPBw1+mVIQjELq/uj/UiJ1r2xBLQ9 Rfztd1n3VD/PCuJQ1KHCcOJj14m7cQyYjWbH7tcN31WqZv4oDjZTc5RnAWv/gUhdqvKd BxnnOmbr5nq7X4MZ18U5WYVerfEWVHHq1lS2PvyAKKyiEBtDQ3bgxSIm5dsZjLWVp2a+ oIzYWCEB5jJJUCETH9mod0D05m/RV29TiLb719ZCnhnYCL2ThwrRCgEh6cwDfjFTAOfL BRxg== X-Gm-Message-State: ACrzQf2JcFRNmNKYTpa6cl3a3Xvwntt67AHq7lhVsW1RocHfEAgYQFYs FzLvux69THrNRq65/HbjSsEUxw== X-Google-Smtp-Source: AMsMyM6YjoApz2cmt93xkc5aPeuhMLaP2uc6ExE39WsDWmfAadxJs9lufYlSSW28eW1IwTrpZrxuvA== X-Received: by 2002:a17:90b:3b8d:b0:214:1066:67c7 with SMTP id pc13-20020a17090b3b8d00b00214106667c7mr45511923pjb.209.1667994662480; Wed, 09 Nov 2022 03:51:02 -0800 (PST) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:61f1:44d3:3f47:2cdb]) by smtp.gmail.com with ESMTPSA id f5-20020a655505000000b00434760ee36asm7292311pgr.16.2022.11.09.03.51.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Nov 2022 03:51:02 -0800 (PST) From: Sergey Senozhatsky To: Minchan Kim , Andrew Morton Cc: Nitin Gupta , Suleiman Souhlal , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Sergey Senozhatsky Subject: [PATCHv5 03/13] zram: Factor out WB and non-WB zram read functions Date: Wed, 9 Nov 2022 20:50:37 +0900 Message-Id: <20221109115047.2921851-4-senozhatsky@chromium.org> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog In-Reply-To: <20221109115047.2921851-1-senozhatsky@chromium.org> References: <20221109115047.2921851-1-senozhatsky@chromium.org> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1667994718; a=rsa-sha256; cv=none; b=5czQ/3KlrmczbBZ0FDzUuo3Yj8sEbPkidoPgXWD8lX1qm/9CTgPljevlH7xresvmEO7xue hVOHXM71cG1ziF1gLd6LZJBHBZxOR371aJYLznGLfT5vYE/mu7yzxqKEhtN0qszAYlCY7P dFIPeZ8yhXNNvPHlxe5GR10oaW3Ngns= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=XU5vLFwk; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf06.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.214.172 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=1667994718; 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=NwLhHMvq7VueCMpUkTq+C+HTS32+Lk3Kl1y4kkNY1lI=; b=HNr0Egr6/vwl3BnFt9EO0M5j3o8m1H09zGcpu8pOhsiKiVPOsmouse7xib0MxnmQ+TbJXb TYdVdm1hCRE+9Z6SJ1g4P/AZ0nYz2jyomr8ayUR6DwBg5NhcV3SCsiYLnZ47R49ezWPGN6 I4uoL9UQD1AMATQFemw0PfNIUyjGEdU= Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=XU5vLFwk; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf06.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.214.172 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org X-Rspam-User: X-Stat-Signature: s848she7g4qqk6f6z31j3nhijhykq4z7 X-Rspamd-Queue-Id: 9CA2C180012 X-Rspamd-Server: rspam05 X-HE-Tag: 1667994718-241825 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: We will use non-WB variant in ZRAM page recompression path. Signed-off-by: Sergey Senozhatsky --- drivers/block/zram/zram_drv.c | 72 ++++++++++++++++++++++++----------- 1 file changed, 49 insertions(+), 23 deletions(-) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index 56026a6deb70..a6a5fd2474d7 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -1339,8 +1339,29 @@ static void zram_free_page(struct zram *zram, size_t index) ~(1UL << ZRAM_LOCK | 1UL << ZRAM_UNDER_WB)); } -static int __zram_bvec_read(struct zram *zram, struct page *page, u32 index, - struct bio *bio, bool partial_io) +/* + * Reads a page from the writeback devices. Corresponding ZRAM slot + * should be unlocked. + */ +static int zram_bvec_read_from_bdev(struct zram *zram, struct page *page, + u32 index, struct bio *bio, bool partial_io) +{ + struct bio_vec bvec = { + .bv_page = page, + .bv_len = PAGE_SIZE, + .bv_offset = 0, + }; + + return read_from_bdev(zram, &bvec, zram_get_element(zram, index), bio, + partial_io); +} + +/* + * Reads (decompresses if needed) a page from zspool (zsmalloc). + * Corresponding ZRAM slot should be locked. + */ +static int zram_read_from_zspool(struct zram *zram, struct page *page, + u32 index) { struct zcomp_strm *zstrm; unsigned long handle; @@ -1348,23 +1369,6 @@ static int __zram_bvec_read(struct zram *zram, struct page *page, u32 index, void *src, *dst; int ret; - zram_slot_lock(zram, index); - if (zram_test_flag(zram, index, ZRAM_WB)) { - struct bio_vec bvec; - - zram_slot_unlock(zram, index); - /* A null bio means rw_page was used, we must fallback to bio */ - if (!bio) - return -EOPNOTSUPP; - - bvec.bv_page = page; - bvec.bv_len = PAGE_SIZE; - bvec.bv_offset = 0; - return read_from_bdev(zram, &bvec, - zram_get_element(zram, index), - bio, partial_io); - } - handle = zram_get_handle(zram, index); if (!handle || zram_test_flag(zram, index, ZRAM_SAME)) { unsigned long value; @@ -1374,7 +1378,6 @@ static int __zram_bvec_read(struct zram *zram, struct page *page, u32 index, mem = kmap_atomic(page); zram_fill_page(mem, PAGE_SIZE, value); kunmap_atomic(mem); - zram_slot_unlock(zram, index); return 0; } @@ -1396,17 +1399,40 @@ static int __zram_bvec_read(struct zram *zram, struct page *page, u32 index, zcomp_stream_put(zram->comps[ZRAM_PRIMARY_COMP]); } zs_unmap_object(zram->mem_pool, handle); - zram_slot_unlock(zram, index); + return ret; +} + +static int __zram_bvec_read(struct zram *zram, struct page *page, u32 index, + struct bio *bio, bool partial_io) +{ + int ret; + + zram_slot_lock(zram, index); + if (!zram_test_flag(zram, index, ZRAM_WB)) { + /* Slot should be locked through out the function call */ + ret = zram_read_from_zspool(zram, page, index); + zram_slot_unlock(zram, index); + } else { + /* Slot should be unlocked before the function call */ + zram_slot_unlock(zram, index); + + /* A null bio means rw_page was used, we must fallback to bio */ + if (!bio) + return -EOPNOTSUPP; + + ret = zram_bvec_read_from_bdev(zram, page, index, bio, + partial_io); + } /* Should NEVER happen. Return bio error if it does. */ - if (WARN_ON(ret)) + if (WARN_ON(ret < 0)) pr_err("Decompression failed! err=%d, page=%u\n", ret, index); return ret; } static int zram_bvec_read(struct zram *zram, struct bio_vec *bvec, - u32 index, int offset, struct bio *bio) + u32 index, int offset, struct bio *bio) { int ret; struct page *page; From patchwork Wed Nov 9 11:50:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 13037453 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 7E715C433FE for ; Wed, 9 Nov 2022 11:51:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E03176B0072; Wed, 9 Nov 2022 06:51:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DDA4C8E0002; Wed, 9 Nov 2022 06:51:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CA32D8E0001; Wed, 9 Nov 2022 06:51:19 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id BCF586B0072 for ; Wed, 9 Nov 2022 06:51:19 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 92C97ABEAB for ; Wed, 9 Nov 2022 11:51:19 +0000 (UTC) X-FDA: 80113738278.27.84E9772 Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.180]) by imf29.hostedemail.com (Postfix) with ESMTP id 2C2B7120015 for ; Wed, 9 Nov 2022 11:51:10 +0000 (UTC) Received: by mail-pg1-f180.google.com with SMTP id s196so16027499pgs.3 for ; Wed, 09 Nov 2022 03:51:05 -0800 (PST) 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=n33F25aQVl5gMALLYTt7F+KllpnjMjEm9LlYHN1WT00=; b=Rh2BlWtYS21q0RL18T9fNl9H/b1v7TFvFlPRO/DpVHp+5NppILseTVaEWsK9ZpAFR2 gVvXlR10W5bORh+1bAKmeuf2JHm7eYWkze5Ysg4+LSwQNlYj+PoCgz4bUzxa2VNBInas fd0c3WKvxwSED3juQz7UrslELXMc/sBuqQy7w= 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=n33F25aQVl5gMALLYTt7F+KllpnjMjEm9LlYHN1WT00=; b=OC9s2X7a7JEARtHGaNvNum77wzyWhB0OW5lnFSOixIZkpZhtweFel3MOxpPU+fY3rW 5cncbKKLC/85D6SP+VDNNaZWpU0pCKG8eT85kuJnVOvSgufuH6CCeoSp+yT8Ny+BHrGg ul7xtEiNB4HYU7Xmjjgsyv6Ac/M+2ZxQB9aydJni61VTrtsDctfRcJCa9f88PFTJhGKl 1iB51ffAzgGyLo8KDQjaaoOco2OE/UoOMr1kLCOyJC8IhGzFoJem5FRx/v+5w6MORUyf 872nY/hp2TJNlql6+9YrnIrnGvM9ywTKS+EFffRy90DaI38YzBU/H3nyvj2NxKgcf5ru KsRw== X-Gm-Message-State: ACrzQf3Z1kZDE7uhRHs68KxqKZb5XQY/5k7z34zPMmoUNyj4q8BM5Y9a 5o97tDN6UiO6o2q2+EuNFNuMbQ== X-Google-Smtp-Source: AMsMyM7p8pimAY7i/uNHTUklIfUHS9rEp4bNx9mbfWjFZIjoKxPIfq1X7n0uEgwxpOt6ckLrwn/gOQ== X-Received: by 2002:a05:6a00:10cf:b0:528:48c3:79e0 with SMTP id d15-20020a056a0010cf00b0052848c379e0mr60134369pfu.18.1667994665061; Wed, 09 Nov 2022 03:51:05 -0800 (PST) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:61f1:44d3:3f47:2cdb]) by smtp.gmail.com with ESMTPSA id f5-20020a655505000000b00434760ee36asm7292311pgr.16.2022.11.09.03.51.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Nov 2022 03:51:04 -0800 (PST) From: Sergey Senozhatsky To: Minchan Kim , Andrew Morton Cc: Nitin Gupta , Suleiman Souhlal , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Sergey Senozhatsky Subject: [PATCHv5 04/13] zram: Introduce recompress sysfs knob Date: Wed, 9 Nov 2022 20:50:38 +0900 Message-Id: <20221109115047.2921851-5-senozhatsky@chromium.org> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog In-Reply-To: <20221109115047.2921851-1-senozhatsky@chromium.org> References: <20221109115047.2921851-1-senozhatsky@chromium.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 2C2B7120015 X-Rspam-User: X-Rspamd-Server: rspam08 Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=Rh2BlWtY; spf=pass (imf29.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.215.180 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org; dmarc=temperror reason="query timed out" header.from=chromium.org (policy=temperror) X-Stat-Signature: sejqs1iobk5pm57o1rwac7gofyxmy4j8 X-HE-Tag: 1667994670-637296 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: Allow zram to recompress (using secondary compression streams) pages. Re-compression algorithms (we support up to 3 at this stage) are selected via recomp_algorithm: echo "algo=zstd priority=1" > /sys/block/zramX/recomp_algorithm Please read documentation for more details. We support several recompression modes: 1) IDLE pages recompression is activated by `idle` mode echo "type=idle" > /sys/block/zram0/recompress 2) Since there may be many idle pages user-space may pass a size threshold value (in bytes) and we will recompress pages only of equal or greater size: echo "threshold=888" > /sys/block/zram0/recompress 3) HUGE pages recompression is activated by `huge` mode echo "type=huge" > /sys/block/zram0/recompress 4) HUGE_IDLE pages recompression is activated by `huge_idle` mode echo "type=huge_idle" > /sys/block/zram0/recompress Signed-off-by: Sergey Senozhatsky --- drivers/block/zram/Kconfig | 9 ++ drivers/block/zram/zram_drv.c | 264 +++++++++++++++++++++++++++++++++- drivers/block/zram/zram_drv.h | 7 + 3 files changed, 277 insertions(+), 3 deletions(-) diff --git a/drivers/block/zram/Kconfig b/drivers/block/zram/Kconfig index d4100b0c083e..0386b7da02aa 100644 --- a/drivers/block/zram/Kconfig +++ b/drivers/block/zram/Kconfig @@ -78,3 +78,12 @@ config ZRAM_MEMORY_TRACKING /sys/kernel/debug/zram/zramX/block_state. See Documentation/admin-guide/blockdev/zram.rst for more information. + +config ZRAM_MULTI_COMP + bool "Enable multiple compression streams" + depends on ZRAM + help + This will enable multi-compression streams, so that ZRAM can + re-compress pages using a potentially slower but more effective + compression algorithm. Note, that IDLE page recompression + requires ZRAM_MEMORY_TRACKING. diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index a6a5fd2474d7..749e4266dd72 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -155,6 +155,25 @@ static inline bool is_partial_io(struct bio_vec *bvec) } #endif +static inline void zram_set_priority(struct zram *zram, u32 index, u32 prio) +{ + prio &= ZRAM_COMP_PRIORITY_MASK; + /* + * Clear previous priority value first, in case if we recompress + * further an already recompressed page + */ + zram->table[index].flags &= ~(ZRAM_COMP_PRIORITY_MASK << + ZRAM_COMP_PRIORITY_BIT1); + zram->table[index].flags |= (prio << ZRAM_COMP_PRIORITY_BIT1); +} + +static inline u32 zram_get_priority(struct zram *zram, u32 index) +{ + u32 prio = zram->table[index].flags >> ZRAM_COMP_PRIORITY_BIT1; + + return prio & ZRAM_COMP_PRIORITY_MASK; +} + /* * Check if request is within bounds and aligned on zram logical blocks. */ @@ -1307,6 +1326,11 @@ static void zram_free_page(struct zram *zram, size_t index) atomic64_dec(&zram->stats.huge_pages); } + if (zram_test_flag(zram, index, ZRAM_INCOMPRESSIBLE)) + zram_clear_flag(zram, index, ZRAM_INCOMPRESSIBLE); + + zram_set_priority(zram, index, 0); + if (zram_test_flag(zram, index, ZRAM_WB)) { zram_clear_flag(zram, index, ZRAM_WB); free_block_bdev(zram, zram_get_element(zram, index)); @@ -1367,6 +1391,7 @@ static int zram_read_from_zspool(struct zram *zram, struct page *page, unsigned long handle; unsigned int size; void *src, *dst; + u32 prio; int ret; handle = zram_get_handle(zram, index); @@ -1383,8 +1408,10 @@ static int zram_read_from_zspool(struct zram *zram, struct page *page, size = zram_get_obj_size(zram, index); - if (size != PAGE_SIZE) - zstrm = zcomp_stream_get(zram->comps[ZRAM_PRIMARY_COMP]); + if (size != PAGE_SIZE) { + prio = zram_get_priority(zram, index); + zstrm = zcomp_stream_get(zram->comps[prio]); + } src = zs_map_object(zram->mem_pool, handle, ZS_MM_RO); if (size == PAGE_SIZE) { @@ -1396,7 +1423,7 @@ static int zram_read_from_zspool(struct zram *zram, struct page *page, dst = kmap_atomic(page); ret = zcomp_decompress(zstrm, src, size, dst); kunmap_atomic(dst); - zcomp_stream_put(zram->comps[ZRAM_PRIMARY_COMP]); + zcomp_stream_put(zram->comps[prio]); } zs_unmap_object(zram->mem_pool, handle); return ret; @@ -1627,6 +1654,235 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, return ret; } +#ifdef CONFIG_ZRAM_MULTI_COMP +/* + * This function will decompress (unless it's ZRAM_HUGE) the page and then + * attempt to compress it using provided compression algorithm priority + * (which is potentially more effective). + * + * Corresponding ZRAM slot should be locked. + */ +static int zram_recompress(struct zram *zram, u32 index, struct page *page, + u32 threshold, u32 prio, u32 prio_max) +{ + struct zcomp_strm *zstrm = NULL; + unsigned long handle_old; + unsigned long handle_new; + unsigned int comp_len_old; + unsigned int comp_len_new; + void *src, *dst; + int ret; + + handle_old = zram_get_handle(zram, index); + if (!handle_old) + return -EINVAL; + + comp_len_old = zram_get_obj_size(zram, index); + /* + * Do not recompress objects that are already "small enough". + */ + if (comp_len_old < threshold) + return 0; + + ret = zram_read_from_zspool(zram, page, index); + if (ret) + return ret; + + /* + * Iterate the secondary comp algorithms list (in order of priority) + * and try to recompress the page. + */ + for (; prio < prio_max; prio++) { + if (!zram->comps[prio]) + continue; + + /* + * Skip if the object is already re-compressed with a higher + * priority algorithm (or same algorithm). + */ + if (prio <= zram_get_priority(zram, index)) + continue; + + zstrm = zcomp_stream_get(zram->comps[prio]); + src = kmap_atomic(page); + ret = zcomp_compress(zstrm, src, &comp_len_new); + kunmap_atomic(src); + + if (ret) { + zcomp_stream_put(zram->comps[prio]); + return ret; + } + + /* Continue until we make progress */ + if (comp_len_new >= huge_class_size || + comp_len_new >= comp_len_old || + (threshold && comp_len_new >= threshold)) { + zcomp_stream_put(zram->comps[prio]); + continue; + } + + /* Recompression was successful so break out */ + break; + } + + /* + * We did not try to recompress, e.g. when we have only one + * secondary algorithm and the page is already recompressed + * using that algorithm + */ + if (!zstrm) + return 0; + + /* + * All secondary algorithms failed to re-compress the page in a way + * that would save memory, mark the object as incompressible so that + * we will not try to compress it again. + */ + if (comp_len_new >= huge_class_size || comp_len_new >= comp_len_old) { + zram_set_flag(zram, index, ZRAM_INCOMPRESSIBLE); + return 0; + } + + /* Successful recompression but above threshold */ + if (threshold && comp_len_new >= threshold) + return 0; + + /* + * No direct reclaim (slow path) for handle allocation and no + * re-compression attempt (unlike in __zram_bvec_write()) since + * we already have stored that object in zsmalloc. If we cannot + * alloc memory for recompressed object then we bail out and + * simply keep the old (existing) object in zsmalloc. + */ + handle_new = zs_malloc(zram->mem_pool, comp_len_new, + __GFP_KSWAPD_RECLAIM | + __GFP_NOWARN | + __GFP_HIGHMEM | + __GFP_MOVABLE); + if (IS_ERR_VALUE(handle_new)) { + zcomp_stream_put(zram->comps[prio]); + return PTR_ERR((void *)handle_new); + } + + dst = zs_map_object(zram->mem_pool, handle_new, ZS_MM_WO); + memcpy(dst, zstrm->buffer, comp_len_new); + zcomp_stream_put(zram->comps[prio]); + + zs_unmap_object(zram->mem_pool, handle_new); + + zram_free_page(zram, index); + zram_set_handle(zram, index, handle_new); + zram_set_obj_size(zram, index, comp_len_new); + zram_set_priority(zram, index, prio); + + atomic64_add(comp_len_new, &zram->stats.compr_data_size); + atomic64_inc(&zram->stats.pages_stored); + + return 0; +} + +#define RECOMPRESS_IDLE (1 << 0) +#define RECOMPRESS_HUGE (1 << 1) + +static ssize_t recompress_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t len) +{ + struct zram *zram = dev_to_zram(dev); + u32 mode = 0, threshold = 0, prio = ZRAM_SECONDARY_COMP; + unsigned long nr_pages = zram->disksize >> PAGE_SHIFT; + char *args, *param, *val; + unsigned long index; + struct page *page; + ssize_t ret; + + args = skip_spaces(buf); + while (*args) { + args = next_arg(args, ¶m, &val); + + if (!*val) + return -EINVAL; + + if (!strcmp(param, "type")) { + if (!strcmp(val, "idle")) + mode = RECOMPRESS_IDLE; + if (!strcmp(val, "huge")) + mode = RECOMPRESS_HUGE; + if (!strcmp(val, "huge_idle")) + mode = RECOMPRESS_IDLE | RECOMPRESS_HUGE; + continue; + } + + if (!strcmp(param, "threshold")) { + /* + * We will re-compress only idle objects equal or + * greater in size than watermark. + */ + ret = kstrtouint(val, 10, &threshold); + if (ret) + return ret; + continue; + } + } + + if (threshold >= PAGE_SIZE) + return -EINVAL; + + down_read(&zram->init_lock); + if (!init_done(zram)) { + ret = -EINVAL; + goto release_init_lock; + } + + page = alloc_page(GFP_KERNEL); + if (!page) { + ret = -ENOMEM; + goto release_init_lock; + } + + ret = len; + for (index = 0; index < nr_pages; index++) { + int err; + + zram_slot_lock(zram, index); + + if (!zram_allocated(zram, index)) + goto next; + + if (mode & RECOMPRESS_IDLE && + !zram_test_flag(zram, index, ZRAM_IDLE)) + goto next; + + if (mode & RECOMPRESS_HUGE && + !zram_test_flag(zram, index, ZRAM_HUGE)) + goto next; + + if (zram_test_flag(zram, index, ZRAM_WB) || + zram_test_flag(zram, index, ZRAM_UNDER_WB) || + zram_test_flag(zram, index, ZRAM_SAME) || + zram_test_flag(zram, index, ZRAM_INCOMPRESSIBLE)) + goto next; + + err = zram_recompress(zram, index, page, threshold, + prio, ZRAM_MAX_COMPS); +next: + zram_slot_unlock(zram, index); + if (err) { + ret = err; + break; + } + + cond_resched(); + } + + __free_page(page); + +release_init_lock: + up_read(&zram->init_lock); + return ret; +} +#endif + /* * zram_bio_discard - handler on discard request * @index: physical block index in PAGE_SIZE units @@ -2006,6 +2262,7 @@ static DEVICE_ATTR_RW(writeback_limit_enable); #endif #ifdef CONFIG_ZRAM_MULTI_COMP static DEVICE_ATTR_RW(recomp_algorithm); +static DEVICE_ATTR_WO(recompress); #endif static struct attribute *zram_disk_attrs[] = { @@ -2032,6 +2289,7 @@ static struct attribute *zram_disk_attrs[] = { &dev_attr_debug_stat.attr, #ifdef CONFIG_ZRAM_MULTI_COMP &dev_attr_recomp_algorithm.attr, + &dev_attr_recompress.attr, #endif NULL, }; diff --git a/drivers/block/zram/zram_drv.h b/drivers/block/zram/zram_drv.h index 7a643c8c38ec..b80faae76835 100644 --- a/drivers/block/zram/zram_drv.h +++ b/drivers/block/zram/zram_drv.h @@ -40,6 +40,9 @@ */ #define ZRAM_FLAG_SHIFT (PAGE_SHIFT + 1) +/* Only 2 bits are allowed for comp priority index */ +#define ZRAM_COMP_PRIORITY_MASK 0x3 + /* Flags for zram pages (table[page_no].flags) */ enum zram_pageflags { /* zram slot is locked */ @@ -49,6 +52,10 @@ enum zram_pageflags { ZRAM_UNDER_WB, /* page is under writeback */ ZRAM_HUGE, /* Incompressible page */ ZRAM_IDLE, /* not accessed page since last idle marking */ + ZRAM_INCOMPRESSIBLE, /* none of the algorithms could compress it */ + + ZRAM_COMP_PRIORITY_BIT1, /* First bit of comp priority index */ + ZRAM_COMP_PRIORITY_BIT2, /* Second bit of comp priority index */ __NR_ZRAM_PAGEFLAGS, }; From patchwork Wed Nov 9 11:50:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 13037454 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 AAB6BC4332F for ; Wed, 9 Nov 2022 11:51:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4B4276B0073; Wed, 9 Nov 2022 06:51:39 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 464416B0074; Wed, 9 Nov 2022 06:51:39 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3536A8E0001; Wed, 9 Nov 2022 06:51:39 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 2790D6B0073 for ; Wed, 9 Nov 2022 06:51:39 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id F2424A1371 for ; Wed, 9 Nov 2022 11:51:38 +0000 (UTC) X-FDA: 80113739076.03.2DE0353 Received: from mail-pj1-f46.google.com (mail-pj1-f46.google.com [209.85.216.46]) by imf15.hostedemail.com (Postfix) with ESMTP id 93037A0009 for ; Wed, 9 Nov 2022 11:51:32 +0000 (UTC) Received: by mail-pj1-f46.google.com with SMTP id m6-20020a17090a5a4600b00212f8dffec9so1689383pji.0 for ; Wed, 09 Nov 2022 03:51:32 -0800 (PST) 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=CxgUv5Jq0W8ZFLhbjb9RaEmetBmdXcouEW/1Ze+ngG4=; b=hv/tWsa79zDploMiCRfP2WLvQCUm6/oR3RjNrpKYsUVMrG2aG4DHN667JQcPpo0Xd5 oW4yapOp9W+yIMxkRkbFUEHfQKYMTDId71N/E0NS1bLMEaWFLJmV1rKZ6K0enEDy3NzR d6ZjFjGXP38VU3BuVVaL+nxLbjBqyBONMDet4= 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=CxgUv5Jq0W8ZFLhbjb9RaEmetBmdXcouEW/1Ze+ngG4=; b=J75D+4V+YOFoZjJcNWqq5yoHCEpZ3BlMhkFtcuwL6jFBft71kAQ2xfP+HN6X6dhJsz u/bx0GaEsgUx1iOBHmgMx5e68gkKaqFZ1x3QqqmNb70eB9lC51gnvs0u9dTQJPwqiI4G Kj37TvmY3EntwCidigJSLHD1SwTwzU7fT2uI3AE9zQtDUnWoSz8OQ5HLrmwdUDq3285m QL+8ReCiihk0Lljs6EVaooApHfqzmyGcCKN7X1PQTLg5A8YnK0kY2AS+MqKdCeXHmyKy XXpBiw0cW3DsxKR4Onk75w8Z2srEtupmhwA6UJnUSw0i6SvHK9LiP/8Gcmr9vuvjoVMt UECw== X-Gm-Message-State: ANoB5pmlhZW9cn0z7SO8CmECdejhaiBez79HadMZ6s6qX57rFUneFjng 3BXxEDpuSL6O9lG+5PjqTeNpwb/M2x24QQ== X-Google-Smtp-Source: AA0mqf4tBVBjmJv7avLtutcZSy3HULQ3lJ8Pc/mYPVodPYE5ju4Xo3CDRE/ta5HYDn3SR+WNZbg5ig== X-Received: by 2002:a17:902:6aca:b0:188:736c:befa with SMTP id i10-20020a1709026aca00b00188736cbefamr764365plt.8.1667994667622; Wed, 09 Nov 2022 03:51:07 -0800 (PST) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:61f1:44d3:3f47:2cdb]) by smtp.gmail.com with ESMTPSA id f5-20020a655505000000b00434760ee36asm7292311pgr.16.2022.11.09.03.51.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Nov 2022 03:51:07 -0800 (PST) From: Sergey Senozhatsky To: Minchan Kim , Andrew Morton Cc: Nitin Gupta , Suleiman Souhlal , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Sergey Senozhatsky Subject: [PATCHv5 05/13] zram: Add recompress flag to read_block_state() Date: Wed, 9 Nov 2022 20:50:39 +0900 Message-Id: <20221109115047.2921851-6-senozhatsky@chromium.org> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog In-Reply-To: <20221109115047.2921851-1-senozhatsky@chromium.org> References: <20221109115047.2921851-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=1667994693; 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=CxgUv5Jq0W8ZFLhbjb9RaEmetBmdXcouEW/1Ze+ngG4=; b=m/ekmbrS60Nabp2cYTCU4PzubMsiPiIuAzECiWvjEF6wFmpIuR2+cJtNiCSAoSgVU0HZSd k9FNmzyaMiUrA9pxPocMG+z8W69c0i/ve4EhkCpGc9EQniig7UxL9C3yCzZSYulXHhvMCJ StAxn9wPFqdKvbODSFll0VUBesRA2Oc= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b="hv/tWsa7"; spf=pass (imf15.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.216.46 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=1667994693; a=rsa-sha256; cv=none; b=8m2UVHeaqjAP6CH8zsyS5p4XpO5WQwEPzVJRb60E856eJQcpdPmJOQWiQl/6vKKmaccmUG neGSoSr8fwNCw+/ppJaODp9cPzfsS78Cb4QfDnkXzr1CMZ3VY46OmM/2sVAr2DorQlSchK c+eio3Mlv+afUAjuHd7DCXsC5KMPawM= X-Rspamd-Queue-Id: 93037A0009 X-Rspam-User: X-Rspamd-Server: rspam08 Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b="hv/tWsa7"; spf=pass (imf15.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.216.46 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org; dmarc=pass (policy=none) header.from=chromium.org X-Stat-Signature: 31xputrypanp6z55n18tuceh9cxne3zb X-HE-Tag: 1667994692-249837 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 flag to zram block state that shows if the page was recompressed (using alternative compression algorithm). Signed-off-by: Sergey Senozhatsky --- Documentation/admin-guide/blockdev/zram.rst | 9 ++++++--- drivers/block/zram/zram_drv.c | 5 +++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Documentation/admin-guide/blockdev/zram.rst b/Documentation/admin-guide/blockdev/zram.rst index c73b16930449..177a142c3146 100644 --- a/Documentation/admin-guide/blockdev/zram.rst +++ b/Documentation/admin-guide/blockdev/zram.rst @@ -411,9 +411,10 @@ pages of the process with*pagemap. If you enable the feature, you could see block state via /sys/kernel/debug/zram/zram0/block_state". The output is as follows:: - 300 75.033841 .wh. - 301 63.806904 s... - 302 63.806919 ..hi + 300 75.033841 .wh.. + 301 63.806904 s.... + 302 63.806919 ..hi. + 303 62.801919 ....r First column zram's block index. @@ -430,6 +431,8 @@ Third column huge page i: idle page + r: + recompressed page (secondary compression algorithm) First line of above example says 300th block is accessed at 75.033841sec and the block's state is huge so it is written back to the backing diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index 749e4266dd72..560e2932021e 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -939,13 +939,14 @@ static ssize_t read_block_state(struct file *file, char __user *buf, ts = ktime_to_timespec64(zram->table[index].ac_time); copied = snprintf(kbuf + written, count, - "%12zd %12lld.%06lu %c%c%c%c\n", + "%12zd %12lld.%06lu %c%c%c%c%c\n", index, (s64)ts.tv_sec, ts.tv_nsec / NSEC_PER_USEC, zram_test_flag(zram, index, ZRAM_SAME) ? 's' : '.', zram_test_flag(zram, index, ZRAM_WB) ? 'w' : '.', zram_test_flag(zram, index, ZRAM_HUGE) ? 'h' : '.', - zram_test_flag(zram, index, ZRAM_IDLE) ? 'i' : '.'); + zram_test_flag(zram, index, ZRAM_IDLE) ? 'i' : '.', + zram_get_priority(zram, index) ? 'r' : '.'); if (count <= copied) { zram_slot_unlock(zram, index); From patchwork Wed Nov 9 11:50:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 13037465 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 A8421C433FE for ; Wed, 9 Nov 2022 11:52:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 90E628E0005; Wed, 9 Nov 2022 06:52:14 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 83E2E8E0007; Wed, 9 Nov 2022 06:52:14 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7233F8E0008; Wed, 9 Nov 2022 06:52:14 -0500 (EST) 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 562D88E0007 for ; Wed, 9 Nov 2022 06:52:14 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 6EC91C131F for ; Wed, 9 Nov 2022 11:52:13 +0000 (UTC) X-FDA: 80113740546.23.463B433 Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) by imf27.hostedemail.com (Postfix) with ESMTP id 256E440015 for ; Wed, 9 Nov 2022 11:52:07 +0000 (UTC) Received: by mail-pf1-f170.google.com with SMTP id y13so16455641pfp.7 for ; Wed, 09 Nov 2022 03:52:07 -0800 (PST) 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=Yx/j6NFsqMiBfWUe9MAE1kY4nyT9uBWrAowemE/mjWM=; b=PRtW06hqJjnQd/kkrH5EdBvx+MeI+nT/zaRSXLQ34yFFZSjedoVDMt0ITBHY9lEJZL zv+rYGTJbr/jbll1pBLICDHoduO6RLnRUwbZgzJ4UPSTNt9sozFtY/xW98UZAXvjbMTU R6GqKRwlu/wYEXfZCbhs9SLFZ3xhLlXZm6oO4= 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=Yx/j6NFsqMiBfWUe9MAE1kY4nyT9uBWrAowemE/mjWM=; b=LO+qnPC2UmGqpje+NMdR+sjfgpCbyEu3FZhNqtFyer7YhhU837SKKUdcimXy/Kexp9 ef7pfDgktruYsCkGfj2SESl0JG7wh9VCos+vpOiblL2yEIDz6Y43u5xB44w5HZbrF5fC VE0xvM3XOPpZ1gCcEZdNYpyNkCmuliS/MG3VZZwXXKqaROa/TLY/1nqHXrnQNGw7bBh8 sa05uFYdSAgV5F1JzhYS7MHAR48tJ8sJ0uqx0bi2snsWVMTuRE6gMhvBYOQ9koJKGwkW jxLvE5Z8WhJLHZcokIXeo3xJPb0RaVVc7FsNJkJ4itpUREzF2NZm71FQx89jPLZInsOs waNg== X-Gm-Message-State: ACrzQf2mMWRqPzwiCzmX/+S5X/Z8yTItCrFXZujVc9rrkaJ3YlF9Ivf4 gfnFL9V79OFDq2OXY81wTyJx/A== X-Google-Smtp-Source: AMsMyM4QC8IeHoMzd41nyT4jdl6i2t22PgNfGcqVzLXa+joYnG9IWHujjdaIiEn2O1jPLNxZ/+ziUQ== X-Received: by 2002:a63:f755:0:b0:44b:e438:ef2f with SMTP id f21-20020a63f755000000b0044be438ef2fmr52609729pgk.314.1667994670169; Wed, 09 Nov 2022 03:51:10 -0800 (PST) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:61f1:44d3:3f47:2cdb]) by smtp.gmail.com with ESMTPSA id f5-20020a655505000000b00434760ee36asm7292311pgr.16.2022.11.09.03.51.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Nov 2022 03:51:09 -0800 (PST) From: Sergey Senozhatsky To: Minchan Kim , Andrew Morton Cc: Nitin Gupta , Suleiman Souhlal , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Sergey Senozhatsky Subject: [PATCHv5 06/13] zram: Clarify writeback_store() comment Date: Wed, 9 Nov 2022 20:50:40 +0900 Message-Id: <20221109115047.2921851-7-senozhatsky@chromium.org> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog In-Reply-To: <20221109115047.2921851-1-senozhatsky@chromium.org> References: <20221109115047.2921851-1-senozhatsky@chromium.org> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1667994728; a=rsa-sha256; cv=none; b=1YVPPJo6EVF1MiJ9zpnaUKfKwbhRWARvxz1L+3jZ0shUIfCcKGjWPoBEd0t3/h8SdGqdeM gA/W0eP3lv+kJx8ih4Y90cjQLZDxSdeWktp7r0TS2hsUFqwHAvyuYWphvPGXkv2me5ew0E xDtGSIT1ZexJkP0uFnTEVb+WMn6X91E= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=PRtW06hq; spf=pass (imf27.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.210.170 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=1667994728; 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=Yx/j6NFsqMiBfWUe9MAE1kY4nyT9uBWrAowemE/mjWM=; b=NEx8IFTI61es27BWzms/gyWjC8rWZI1cMCd5e014FOnolbXM9IDd/7gp6vau8oGbDFAG6R fcJRsP/DJUAOGCWfi9EnK1zxjYHkfvQvikEBmHv5I7pjfjTQY/pCLylazctw25oGlRGVvb T3BGwHipbWudZAfv1CrUIMLYprFo/KY= X-Stat-Signature: uhqx4zkzgs3mjtfrnnygiyde6kkpwujk X-Rspam-User: Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=PRtW06hq; spf=pass (imf27.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.210.170 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org; dmarc=pass (policy=none) header.from=chromium.org X-Rspamd-Queue-Id: 256E440015 X-Rspamd-Server: rspam09 X-HE-Tag: 1667994727-301620 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: Re-phrase writeback BIO error comment. Reported-by: Andrew Morton Signed-off-by: Sergey Senozhatsky --- drivers/block/zram/zram_drv.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index 560e2932021e..a5d2ce0bcd5d 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -772,8 +772,12 @@ static ssize_t writeback_store(struct device *dev, zram_clear_flag(zram, index, ZRAM_IDLE); zram_slot_unlock(zram, index); /* - * Return last IO error unless every IO were - * not suceeded. + * BIO errors are not fatal, we continue and simply + * attempt to writeback the remaining objects (pages). + * At the same time we need to signal user-space that + * some writes (at least one, but also could be all of + * them) were not successful and we do so by returning + * the most recent BIO error. */ ret = err; continue; From patchwork Wed Nov 9 11:50:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 13037464 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 D78A4C4332F for ; Wed, 9 Nov 2022 11:52:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 724EB8E0009; Wed, 9 Nov 2022 06:52:14 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6AE9A8E0005; Wed, 9 Nov 2022 06:52:14 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5A92B8E0008; Wed, 9 Nov 2022 06:52:14 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 4E07B8E0005 for ; Wed, 9 Nov 2022 06:52:14 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 1BA98C13C6 for ; Wed, 9 Nov 2022 11:52:09 +0000 (UTC) X-FDA: 80113740378.24.01F06ED Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) by imf13.hostedemail.com (Postfix) with ESMTP id B22D320014 for ; Wed, 9 Nov 2022 11:52:03 +0000 (UTC) Received: by mail-pf1-f173.google.com with SMTP id m6so16501086pfb.0 for ; Wed, 09 Nov 2022 03:52:03 -0800 (PST) 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=LtxYsj6E0bxgea4oeDPQD6uPBfUoT8WqWkKOxHgnlE8=; b=BhhFMs1ML3PGfZKVrN186Q97ul+1G9ZHCoV+RVoLQr8lz4T5uyEB8FVWXqOd2MPEJV WXRNdPNw5zFbek9OBqFeG95mqUcpvBVSA9OgxkLNbzSfXs/gtXDE0iZciXnFTnO7xbEx VVL2cpPMLshWAYupNPDK+0SFTzwaSKVuxvrqg= 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=LtxYsj6E0bxgea4oeDPQD6uPBfUoT8WqWkKOxHgnlE8=; b=t31ixJMqLQtq9ogXC2Bf1/5BM3ZHoM5Tj+VV2EW+JUUaNDiWEPSccnG5Hg/xqwifEN UtrFOu1S4nvpe3q+JZzSwTTgS2RQ4knJx+6d3219wYXPXSNyzJq+2I+kPqfp1TONgQTj rPQkTy9B75/tE+aj5AGzSlYlUOhxcKToNoQpve4Jner7ezX6BoP645wTh57CS3BCZ1lb 8JY8z9g7nwSlOWbJBeK6nfkPRNgDGQeM9vd+p4nT0hBYeD8riN/hMtoQp01isO4Awi5m hFu7l/FWU1kXCEUUfupfr2zVsBOu33/Mg1C0AT/yVCop0e4bvW4lTV35ia3KzRrGhIl7 4IBg== X-Gm-Message-State: ANoB5pnS3AGKGnw3r8wMTrQIcnZMc23Lv6OXz+OXuxddZUgzgnomSqwq kjRvzrdMZK7hjGwQfJo2rZqTfEgw/ydM8g== X-Google-Smtp-Source: AA0mqf5O4dQwnhqX2UIonKGx0YaOrk9LZS0ppNcJn3lPaVyD2Siq7naWMzUGxAKXAAnyXSHio9Vedw== X-Received: by 2002:a65:6846:0:b0:470:8e8f:fe89 with SMTP id q6-20020a656846000000b004708e8ffe89mr5699996pgt.172.1667994672770; Wed, 09 Nov 2022 03:51:12 -0800 (PST) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:61f1:44d3:3f47:2cdb]) by smtp.gmail.com with ESMTPSA id f5-20020a655505000000b00434760ee36asm7292311pgr.16.2022.11.09.03.51.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Nov 2022 03:51:12 -0800 (PST) From: Sergey Senozhatsky To: Minchan Kim , Andrew Morton Cc: Nitin Gupta , Suleiman Souhlal , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Sergey Senozhatsky Subject: [PATCHv5 07/13] zram: Use IS_ERR_VALUE() to check for zs_malloc() errors Date: Wed, 9 Nov 2022 20:50:41 +0900 Message-Id: <20221109115047.2921851-8-senozhatsky@chromium.org> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog In-Reply-To: <20221109115047.2921851-1-senozhatsky@chromium.org> References: <20221109115047.2921851-1-senozhatsky@chromium.org> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1667994723; a=rsa-sha256; cv=none; b=LmVzyOW4oUz+jKcLPzVIZZ4bGlycoNBDdwvQxxUx2u6TrHmGzFf/l47rVcZL5YncTt4kC7 Od3CnYoJetBEthQuMgykyUw54p7i6nTfBbagH8j2sTcRSkLofzSkxhusJU2+jUqBvPZT0I NzzHwM58SJkmrpxRjYxMm3ViIGO9C8Y= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=BhhFMs1M; spf=pass (imf13.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.210.173 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=1667994723; 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=LtxYsj6E0bxgea4oeDPQD6uPBfUoT8WqWkKOxHgnlE8=; b=tGkXeaUcqme4iz/fDKUXQbk1JiW3h0JMuaYzzjD8UyD5TRddLos4gOUn8z3NmFQNzUmiGh fdZwtNrwmYPSZK4lPPTApImVG4GZoA8pLfuZqlt1Wlr3cSiI5YXzXTwlFAdWE+HlguPjUH 51oXfeE9WzXdW3xt6FqFdLNEYiz51Bo= X-Stat-Signature: 9k7y68cek8dsb3tjdtyu5yfyw16iii55 X-Rspamd-Queue-Id: B22D320014 Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=BhhFMs1M; spf=pass (imf13.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.210.173 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org; dmarc=pass (policy=none) header.from=chromium.org X-Rspam-User: X-Rspamd-Server: rspam11 X-HE-Tag: 1667994723-189328 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: Avoid type casts that are needed for IS_ERR() and use IS_ERR_VALUE() instead. Suggested-by: Andrew Morton Signed-off-by: Sergey Senozhatsky --- drivers/block/zram/zram_drv.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index a5d2ce0bcd5d..9561569273fe 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -1545,19 +1545,19 @@ static int __zram_bvec_write(struct zram *zram, struct bio_vec *bvec, * if we have a 'non-null' handle here then we are coming * from the slow path and handle has already been allocated. */ - if (IS_ERR((void *)handle)) + if (IS_ERR_VALUE(handle)) handle = zs_malloc(zram->mem_pool, comp_len, __GFP_KSWAPD_RECLAIM | __GFP_NOWARN | __GFP_HIGHMEM | __GFP_MOVABLE); - if (IS_ERR((void *)handle)) { + if (IS_ERR_VALUE(handle)) { zcomp_stream_put(zram->comps[ZRAM_PRIMARY_COMP]); atomic64_inc(&zram->stats.writestall); handle = zs_malloc(zram->mem_pool, comp_len, GFP_NOIO | __GFP_HIGHMEM | __GFP_MOVABLE); - if (IS_ERR((void *)handle)) + if (IS_ERR_VALUE(handle)) return PTR_ERR((void *)handle); if (comp_len != PAGE_SIZE) From patchwork Wed Nov 9 11:50:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 13037456 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 3CC5BC43219 for ; Wed, 9 Nov 2022 11:51:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4194B8E0002; Wed, 9 Nov 2022 06:51:44 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3CA1B6B0078; Wed, 9 Nov 2022 06:51:44 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 21CBF8E0002; Wed, 9 Nov 2022 06:51:44 -0500 (EST) 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 121A56B0075 for ; Wed, 9 Nov 2022 06:51:44 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id D3D8940655 for ; Wed, 9 Nov 2022 11:51:38 +0000 (UTC) X-FDA: 80113739076.29.492F71C Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) by imf28.hostedemail.com (Postfix) with ESMTP id 5828CC0020 for ; Wed, 9 Nov 2022 11:51:30 +0000 (UTC) Received: by mail-pg1-f182.google.com with SMTP id h193so15991530pgc.10 for ; Wed, 09 Nov 2022 03:51:30 -0800 (PST) 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=ISzeUQbltZw2zOA4vUeGiMYh+5K7aaZl+AlK2yoDkbI=; b=abhQ1Lg35Ucp+NagZfYKvx4GbY0NqG+/hyXy+da3FyfoeakVv8aDDXACjC5rRaYMlE E3LixsEmNHw/j0vp8f/7HSXIgTj/qjh5U/zqtfM2h03rzuq8Scn+ixTQLqjY4CV5PBYE 62QyHJ431/vUwvGW0FiMJTSIr0gK1BLKAlU3Q= 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=ISzeUQbltZw2zOA4vUeGiMYh+5K7aaZl+AlK2yoDkbI=; b=12zQdiNvr6AkqxOaz8fKEGiaHuJfZgy47G6hbIHyhO3qM+Vt2F/IVquoiK16gt/IRo ImoGi7Ni1/J2Imi5GTrcr+D9zFLE6V29U1loRm555VZjPmQ7I5yJNZmHLDyWU7ZbB2uW wTXvCIQsc9LPDKFQNCAhBWYTibOzLxoqRcCVWS1H7TdOzBUE7TRUe7pXE7e83w0f5nj9 bzdzlqjxIRVEoAM7TuBcAMvvEUV/NiII2EhOETIKngY4yJyIGiiNPXkztoLG3yR/maqL GbLAnX0R09rGvWU7ILsLV0h8qMOmhrEOMrGAfUZsyfRUA+G8w7X7DKzchjyOS/V+ChCA S7Ow== X-Gm-Message-State: ACrzQf0/GwmRbz4MyLlNOI6qc1l78vB+DNd9tW9Fex5tP6LtQn7mXj4B L/q2UoafT9x8TEb0Vz3ZmLsXOA== X-Google-Smtp-Source: AMsMyM5bs/os1qCUXnfE9uDJ3/tdq0rmqwrB+hDi9koev9Tj6IMDU384APFO34LPFle2GUW6mVXbfw== X-Received: by 2002:a63:f047:0:b0:46e:b1d4:2a68 with SMTP id s7-20020a63f047000000b0046eb1d42a68mr51073818pgj.496.1667994675340; Wed, 09 Nov 2022 03:51:15 -0800 (PST) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:61f1:44d3:3f47:2cdb]) by smtp.gmail.com with ESMTPSA id f5-20020a655505000000b00434760ee36asm7292311pgr.16.2022.11.09.03.51.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Nov 2022 03:51:15 -0800 (PST) From: Sergey Senozhatsky To: Minchan Kim , Andrew Morton Cc: Nitin Gupta , Suleiman Souhlal , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Sergey Senozhatsky , Alexey Romanov Subject: [PATCHv5 08/13] zram: add size class equals check into recompression Date: Wed, 9 Nov 2022 20:50:42 +0900 Message-Id: <20221109115047.2921851-9-senozhatsky@chromium.org> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog In-Reply-To: <20221109115047.2921851-1-senozhatsky@chromium.org> References: <20221109115047.2921851-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=1667994693; 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=ISzeUQbltZw2zOA4vUeGiMYh+5K7aaZl+AlK2yoDkbI=; b=BOqWmkP9cOLZIATUgdP2jQm9DI/Jzxz64TRET+/mM7lhuQcUiFd6YqaMQKX2cJIGhULpZo Y7vHbM7g2YJRd1Lg2Pi6l8fBii6rE8SrzbZiCcDenypD6ztQAujh2UdlM+1vBjbj8WZXS3 cR/tk2+sPEuKSl+kyVtDLqQwwqYACqY= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=abhQ1Lg3; spf=pass (imf28.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.215.182 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=1667994693; a=rsa-sha256; cv=none; b=4wZQTTbT51T5v+lf5hZiPmRogwMS4l0AjxFDffTR4yyQBa4bqjiFKI6mYJzYF+xxlXAIRU 5uRx01wFk/JEbsbqNJJIfOdaxO2qzntg0dMsUCe329rz431oSlb9nUjsLF4SchSszv7llh wET1UlRqKa8KAFfIaTOSRi78phmwtRs= X-Rspamd-Queue-Id: 5828CC0020 Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=abhQ1Lg3; spf=pass (imf28.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.215.182 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org; dmarc=pass (policy=none) header.from=chromium.org X-Rspamd-Server: rspam10 X-Rspam-User: X-Stat-Signature: n7ag6jde8tnackj7rtc68skaihchqxyf X-HE-Tag: 1667994690-225263 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: From: Alexey Romanov It makes no sense for us to recompress the object if it will be in the same size class. We anyway don't get any memory gain. But, at the same time, we get a CPU time overhead when inserting this object into zspage and decompressing it afterwards. [senozhatsky: rebased and fixed conflicts] Signed-off-by: Alexey Romanov Signed-off-by: Sergey Senozhatsky --- drivers/block/zram/zram_drv.c | 11 ++++++++++- include/linux/zsmalloc.h | 2 ++ mm/zsmalloc.c | 21 +++++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index 9561569273fe..383d967ef4c7 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -1675,6 +1675,8 @@ static int zram_recompress(struct zram *zram, u32 index, struct page *page, unsigned long handle_new; unsigned int comp_len_old; unsigned int comp_len_new; + unsigned int class_index_old; + unsigned int class_index_new; void *src, *dst; int ret; @@ -1693,6 +1695,7 @@ static int zram_recompress(struct zram *zram, u32 index, struct page *page, if (ret) return ret; + class_index_old = zs_lookup_class_index(zram->mem_pool, comp_len_old); /* * Iterate the secondary comp algorithms list (in order of priority) * and try to recompress the page. @@ -1718,9 +1721,13 @@ static int zram_recompress(struct zram *zram, u32 index, struct page *page, return ret; } + class_index_new = zs_lookup_class_index(zram->mem_pool, + comp_len_new); + /* Continue until we make progress */ if (comp_len_new >= huge_class_size || comp_len_new >= comp_len_old || + class_index_new >= class_index_old || (threshold && comp_len_new >= threshold)) { zcomp_stream_put(zram->comps[prio]); continue; @@ -1743,7 +1750,9 @@ static int zram_recompress(struct zram *zram, u32 index, struct page *page, * that would save memory, mark the object as incompressible so that * we will not try to compress it again. */ - if (comp_len_new >= huge_class_size || comp_len_new >= comp_len_old) { + if (comp_len_new >= huge_class_size || + comp_len_new >= comp_len_old || + class_index_new >= class_index_old) { zram_set_flag(zram, index, ZRAM_INCOMPRESSIBLE); return 0; } diff --git a/include/linux/zsmalloc.h b/include/linux/zsmalloc.h index 2a430e713ce5..a48cd0ffe57d 100644 --- a/include/linux/zsmalloc.h +++ b/include/linux/zsmalloc.h @@ -55,5 +55,7 @@ void zs_unmap_object(struct zs_pool *pool, unsigned long handle); unsigned long zs_get_total_pages(struct zs_pool *pool); unsigned long zs_compact(struct zs_pool *pool); +unsigned int zs_lookup_class_index(struct zs_pool *pool, unsigned int size); + void zs_pool_stats(struct zs_pool *pool, struct zs_pool_stats *stats); #endif diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index d03941cace2c..065744b7e9d8 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -1205,6 +1205,27 @@ static bool zspage_full(struct size_class *class, struct zspage *zspage) return get_zspage_inuse(zspage) == class->objs_per_zspage; } +/** + * zs_lookup_class_index() - Returns index of the zsmalloc &size_class + * that hold objects of the provided size. + * @pool: zsmalloc pool to use + * @size: object size + * + * Context: Any context. + * + * Return: the index of the zsmalloc &size_class that hold objects of the + * provided size. + */ +unsigned int zs_lookup_class_index(struct zs_pool *pool, unsigned int size) +{ + struct size_class *class; + + class = pool->size_class[get_size_class_index(size)]; + + return class->index; +} +EXPORT_SYMBOL_GPL(zs_lookup_class_index); + unsigned long zs_get_total_pages(struct zs_pool *pool) { return atomic_long_read(&pool->pages_allocated); From patchwork Wed Nov 9 11:50:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 13037462 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 D99DBC433FE for ; Wed, 9 Nov 2022 11:52:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 836156B0078; Wed, 9 Nov 2022 06:52:06 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7E7A68E0005; Wed, 9 Nov 2022 06:52:06 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6AE656B007D; Wed, 9 Nov 2022 06:52:06 -0500 (EST) 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 607686B0078 for ; Wed, 9 Nov 2022 06:52:06 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 2F782C1400 for ; Wed, 9 Nov 2022 11:52:06 +0000 (UTC) X-FDA: 80113740252.14.01C7344 Received: from mail-pj1-f48.google.com (mail-pj1-f48.google.com [209.85.216.48]) by imf18.hostedemail.com (Postfix) with ESMTP id D66EE1C0003 for ; Wed, 9 Nov 2022 11:52:05 +0000 (UTC) Received: by mail-pj1-f48.google.com with SMTP id b11so16492282pjp.2 for ; Wed, 09 Nov 2022 03:52:05 -0800 (PST) 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=LTJSMGQnVr536MHmH+z5uAcQ4mxEF9ubNphP3SWXc38=; b=JugrdxVHc3EVPtfDqUoNOLZ1kNs5JPOJ8YZcAaOous+St7ne5PyANDUJXAtNY2rhEi n//X6QGWh/U5eKuz/qRvjJjhPJDLKEKXuOXggdKo3dJVy++tIRmqYSSouzcUMrqrK99F y82p7gDbtsucgtq6MfVMebxhThBUzWo1dXpBE= 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=LTJSMGQnVr536MHmH+z5uAcQ4mxEF9ubNphP3SWXc38=; b=XSoKQrbmODc/K8ekSHAJIhy/0pTqBLr4ITGX8hOln6zdWqa8t2KbUI1pZJgguIjzeg tnsNkI322Uxc/kUHbhvgC5sS6XebUFHNuucmRdSN7brwCbkLqKHjgFvWLMXD0hwjM5eU 3ZLJm98sR/q8UnbVcQAWb0t6ApJAiWDu8+Cw2ksHhcS4j1R328+RKSpSZhILJJDLWmyS rA5vCOat06yJeaR1sYwQW73sTsGXFK6K5pAs9no0kmZ9t4uNVhrU0gJv6gtzKmYRzj/s eSoMNC8Q2tEr4k/VF2Vn1PdApYXVvyj/2mN7wu1CzihTTMhn22frv2oqiov9S00aVpjB CBGw== X-Gm-Message-State: ACrzQf0wPRrL4dahDwruw9Ph/V/rPR9Ri9Mm8nuU7D0xxcCUoPK/nKuo kNPxCP3wq2XAGNEYk/i2jBPUpw== X-Google-Smtp-Source: AMsMyM7MLI40Iy3R2HZvtqnUxgbgUMiou0kBc/wNNyE+pA7d0aC//esy4rrsRm2ejyOyrIpOAHrfIA== X-Received: by 2002:a17:90a:f414:b0:212:cacf:42c3 with SMTP id ch20-20020a17090af41400b00212cacf42c3mr79536832pjb.198.1667994677913; Wed, 09 Nov 2022 03:51:17 -0800 (PST) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:61f1:44d3:3f47:2cdb]) by smtp.gmail.com with ESMTPSA id f5-20020a655505000000b00434760ee36asm7292311pgr.16.2022.11.09.03.51.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Nov 2022 03:51:17 -0800 (PST) From: Sergey Senozhatsky To: Minchan Kim , Andrew Morton Cc: Nitin Gupta , Suleiman Souhlal , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Sergey Senozhatsky Subject: [PATCHv5 09/13] zram: remove redundant checks from zram_recompress() Date: Wed, 9 Nov 2022 20:50:43 +0900 Message-Id: <20221109115047.2921851-10-senozhatsky@chromium.org> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog In-Reply-To: <20221109115047.2921851-1-senozhatsky@chromium.org> References: <20221109115047.2921851-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=1667994725; 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=LTJSMGQnVr536MHmH+z5uAcQ4mxEF9ubNphP3SWXc38=; b=hllDdaddn3HM6d2qEsHET5R4RXrP8YlX2+Dvd750COdE48+AHZcqINH0YxFTdZ9haeNPM3 C6VPnG8yedRLoap722pz7aU4zf3B53FsVfNbtyUyKPraW8Socd9L/SUwVdr38vBG7WzPph X6acJpVGAnDVSjJZv66Ul6ZsvmCrNAU= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=JugrdxVH; spf=pass (imf18.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.216.48 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=1667994725; a=rsa-sha256; cv=none; b=M31c3h078qhqb4aH/uArrgL2qcJVYZX68Pev3Rzljbmh+sRpf5y3TEuQ7fEVdPrlfWju12 r/sH/DcQjyXej+0EDK6J7nz9kmZt7UOfLqNt6pilFtv2l+FGBvqqATWzsdNumrdhUVHv/s bU/vxKivscg9AbX0GgYk2TCw6U3PqYk= X-Rspamd-Queue-Id: D66EE1C0003 Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=JugrdxVH; spf=pass (imf18.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.216.48 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org; dmarc=pass (policy=none) header.from=chromium.org X-Rspamd-Server: rspam10 X-Rspam-User: X-Stat-Signature: dy5sj1trdz8ydfn85wypa4taop7tkef6 X-HE-Tag: 1667994725-836285 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: Size class index comparison is powerful enough so we can remove object size comparisons. Signed-off-by: Sergey Senozhatsky --- drivers/block/zram/zram_drv.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index 383d967ef4c7..67b58f2255db 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -1725,9 +1725,7 @@ static int zram_recompress(struct zram *zram, u32 index, struct page *page, comp_len_new); /* Continue until we make progress */ - if (comp_len_new >= huge_class_size || - comp_len_new >= comp_len_old || - class_index_new >= class_index_old || + if (class_index_new >= class_index_old || (threshold && comp_len_new >= threshold)) { zcomp_stream_put(zram->comps[prio]); continue; @@ -1750,9 +1748,7 @@ static int zram_recompress(struct zram *zram, u32 index, struct page *page, * that would save memory, mark the object as incompressible so that * we will not try to compress it again. */ - if (comp_len_new >= huge_class_size || - comp_len_new >= comp_len_old || - class_index_new >= class_index_old) { + if (class_index_new >= class_index_old) { zram_set_flag(zram, index, ZRAM_INCOMPRESSIBLE); return 0; } From patchwork Wed Nov 9 11:50:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 13037461 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 8C218C4332F for ; Wed, 9 Nov 2022 11:52:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2DF308E0003; Wed, 9 Nov 2022 06:52:04 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 28F076B007B; Wed, 9 Nov 2022 06:52:04 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 157828E0003; Wed, 9 Nov 2022 06:52:04 -0500 (EST) 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 077666B0078 for ; Wed, 9 Nov 2022 06:52:04 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id C76331C688C for ; Wed, 9 Nov 2022 11:51:58 +0000 (UTC) X-FDA: 80113739916.16.159825F Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) by imf25.hostedemail.com (Postfix) with ESMTP id 68E01A0017 for ; Wed, 9 Nov 2022 11:51:58 +0000 (UTC) Received: by mail-pl1-f182.google.com with SMTP id l2so16832062pld.13 for ; Wed, 09 Nov 2022 03:51:58 -0800 (PST) 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=n7l0gcyZTSMtgONlgCq8JYmzNKlzJdwXwSa9TtKzHX4=; b=dCtnfolV7NZTjIQst7bLm+R0e8lXueKVV0v7b/QjyVHeRBIdxnvcnXoOnCxxFDvSvk EwwKsn9H/c3u3wxAH18AuVZrTTGa0xtsRdZ2lQvewblpJv1hQ/BJ1/cVh02T51kqwibA 9TfwfyIhmJ1AFeRqYwaDl6PjbFd3przV0Cnok= 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=n7l0gcyZTSMtgONlgCq8JYmzNKlzJdwXwSa9TtKzHX4=; b=3x+wMVfzPn1uBpUFRT2NsRrSugIacnHwoqGEn+ywIez1XKKIJ71uk6lSZw/rQdXvAz kuUXZeaIXM0mxsPKj3eFwLLoEpxkqwOjk+D5OKCYcJBMKNM8sk7dnWYXtI7QVS36N2Ei kobClr9I8XsZeY++brWmgYSbd1tMcSdrYjwzSgq7zQZK/0P33WjqstnnoZUV4ikatcSo Sh0NbwnXGJ2mzxGBqjPpwFF69Hrr/nOFkQixQKKX+MC6D9TEi/zGwKlbU+eFPDIjZToO 9nJYdxus80U+okJFfc8HP0ICYyjGA2YM5eVi8nisBGY6THluWDvDqPOyKGYvI8LdHVE5 hxBg== X-Gm-Message-State: ACrzQf2lv36xU9FVqYNiHOxezj7I0sC1MZ0G1JyDFPbjoFdXlVPD30eM MZvCBzoPlmSXyo0kNfaXjjWjJg== X-Google-Smtp-Source: AMsMyM7Rg2hU/k1WD6TqY27OHXzxKTED3WjneC0q/KoUbZcCmKt04o1vVWc7COK2SZU7DinwUBf6Tg== X-Received: by 2002:a17:90a:cb03:b0:214:219:b2b9 with SMTP id z3-20020a17090acb0300b002140219b2b9mr48462292pjt.191.1667994680525; Wed, 09 Nov 2022 03:51:20 -0800 (PST) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:61f1:44d3:3f47:2cdb]) by smtp.gmail.com with ESMTPSA id f5-20020a655505000000b00434760ee36asm7292311pgr.16.2022.11.09.03.51.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Nov 2022 03:51:20 -0800 (PST) From: Sergey Senozhatsky To: Minchan Kim , Andrew Morton Cc: Nitin Gupta , Suleiman Souhlal , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Sergey Senozhatsky Subject: [PATCHv5 10/13] zram: Add algo parameter support to zram_recompress() Date: Wed, 9 Nov 2022 20:50:44 +0900 Message-Id: <20221109115047.2921851-11-senozhatsky@chromium.org> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog In-Reply-To: <20221109115047.2921851-1-senozhatsky@chromium.org> References: <20221109115047.2921851-1-senozhatsky@chromium.org> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1667994718; a=rsa-sha256; cv=none; b=JfjyK0e2CGV8EkQMpVWgxS4DPr1+Ey2iIh9g3Vj3leThCBu7Yn7ZtEoSU1LpAiG/DNnNrX ogEG2yS2t3YMHTlJ09zqHuHoAlVNGZlqe/YVvm7oJYX96gCS8Yi6NNgNmDLg3LwSaX+fvI N5ZMRfBSvPyavYwFF/sHsh8RLBO+eC4= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=dCtnfolV; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf25.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.214.182 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=1667994718; 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=n7l0gcyZTSMtgONlgCq8JYmzNKlzJdwXwSa9TtKzHX4=; b=zP7q9GY8brUqDMAHS56qwpXBDCPmojWLqTL9PE3HJhQObPgCWSk0Wfh8GjjeWur5HmvAW/ qmka364gzA+v7avPO19Bl9LZw6NX1fytG7nD+kC/ZZOa9GzOWAcYTOmvVTKY5VFPVHylIS ZcnsF5nCZMtyaNDJzll5yfW2Jglmhog= Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=dCtnfolV; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf25.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.214.182 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org X-Rspam-User: X-Stat-Signature: hrpqmyjn7dd9stkmsfp3kq576amfs8gt X-Rspamd-Queue-Id: 68E01A0017 X-Rspamd-Server: rspam05 X-HE-Tag: 1667994718-976512 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: Recompression iterates through all the registered secondary compression algorithms in order of their priorities so that we have higher chances of finding the algorithm that compresses a particular page. This, however, may not always be best approach and sometimes we may want to limit recompression to only one particular algorithm. For instance, when a higher priority algorithm uses too much power and device has a relatively low battery level we may want to limit recompression to use only a lower priority algorithm, which uses less power. Introduce algo= parameter support to recompression sysfs knob so that user-sapce can request recompression with particular algorithm only: echo "type=idle algo=zstd" > /sys/block/zramX/recompress Signed-off-by: Sergey Senozhatsky --- drivers/block/zram/zram_drv.c | 54 +++++++++++++++++++++++++++++------ drivers/block/zram/zram_drv.h | 1 + 2 files changed, 46 insertions(+), 9 deletions(-) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index 67b58f2255db..89d25f60b33e 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -1677,6 +1677,7 @@ static int zram_recompress(struct zram *zram, u32 index, struct page *page, unsigned int comp_len_new; unsigned int class_index_old; unsigned int class_index_new; + u32 num_recomps = 0; void *src, *dst; int ret; @@ -1711,6 +1712,7 @@ static int zram_recompress(struct zram *zram, u32 index, struct page *page, if (prio <= zram_get_priority(zram, index)) continue; + num_recomps++; zstrm = zcomp_stream_get(zram->comps[prio]); src = kmap_atomic(page); ret = zcomp_compress(zstrm, src, &comp_len_new); @@ -1743,13 +1745,19 @@ static int zram_recompress(struct zram *zram, u32 index, struct page *page, if (!zstrm) return 0; - /* - * All secondary algorithms failed to re-compress the page in a way - * that would save memory, mark the object as incompressible so that - * we will not try to compress it again. - */ if (class_index_new >= class_index_old) { - zram_set_flag(zram, index, ZRAM_INCOMPRESSIBLE); + /* + * Secondary algorithms failed to re-compress the page + * in a way that would save memory, mark the object as + * incompressible so that we will not try to compress + * it again. + * + * We need to make sure that all secondary algorithms have + * failed, so we test if the number of recompressions matches + * the number of active secondary algorithms. + */ + if (num_recomps == zram->num_active_comps - 1) + zram_set_flag(zram, index, ZRAM_INCOMPRESSIBLE); return 0; } @@ -1798,10 +1806,11 @@ static ssize_t recompress_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t len) { + u32 prio = ZRAM_SECONDARY_COMP, prio_max = ZRAM_MAX_COMPS; struct zram *zram = dev_to_zram(dev); - u32 mode = 0, threshold = 0, prio = ZRAM_SECONDARY_COMP; unsigned long nr_pages = zram->disksize >> PAGE_SHIFT; - char *args, *param, *val; + char *args, *param, *val, *algo = NULL; + u32 mode = 0, threshold = 0; unsigned long index; struct page *page; ssize_t ret; @@ -1833,6 +1842,11 @@ static ssize_t recompress_store(struct device *dev, return ret; continue; } + + if (!strcmp(param, "algo")) { + algo = val; + continue; + } } if (threshold >= PAGE_SIZE) @@ -1844,6 +1858,26 @@ static ssize_t recompress_store(struct device *dev, goto release_init_lock; } + if (algo) { + bool found = false; + + for (; prio < ZRAM_MAX_COMPS; prio++) { + if (!zram->comp_algs[prio]) + continue; + + if (!strcmp(zram->comp_algs[prio], algo)) { + prio_max = min(prio + 1, ZRAM_MAX_COMPS); + found = true; + break; + } + } + + if (!found) { + ret = -EINVAL; + goto release_init_lock; + } + } + page = alloc_page(GFP_KERNEL); if (!page) { ret = -ENOMEM; @@ -1874,7 +1908,7 @@ static ssize_t recompress_store(struct device *dev, goto next; err = zram_recompress(zram, index, page, threshold, - prio, ZRAM_MAX_COMPS); + prio, prio_max); next: zram_slot_unlock(zram, index); if (err) { @@ -2110,6 +2144,7 @@ static void zram_destroy_comps(struct zram *zram) if (!comp) continue; zcomp_destroy(comp); + zram->num_active_comps--; } } @@ -2177,6 +2212,7 @@ static ssize_t disksize_store(struct device *dev, } zram->comps[prio] = comp; + zram->num_active_comps++; } zram->disksize = disksize; set_capacity_and_notify(zram->disk, zram->disksize >> SECTOR_SHIFT); diff --git a/drivers/block/zram/zram_drv.h b/drivers/block/zram/zram_drv.h index b80faae76835..473325415a74 100644 --- a/drivers/block/zram/zram_drv.h +++ b/drivers/block/zram/zram_drv.h @@ -125,6 +125,7 @@ struct zram { */ u64 disksize; /* bytes */ const char *comp_algs[ZRAM_MAX_COMPS]; + s8 num_active_comps; /* * zram is claimed so open request will be failed */ From patchwork Wed Nov 9 11:50:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 13037458 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 70F1CC4332F for ; Wed, 9 Nov 2022 11:51:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E033A8E0003; Wed, 9 Nov 2022 06:51:47 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DB4966B0078; Wed, 9 Nov 2022 06:51:47 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C7D948E0003; Wed, 9 Nov 2022 06:51:47 -0500 (EST) 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 B7ECF6B0075 for ; Wed, 9 Nov 2022 06:51:47 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 97FA61414D6 for ; Wed, 9 Nov 2022 11:51:47 +0000 (UTC) X-FDA: 80113739454.22.1D70488 Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) by imf22.hostedemail.com (Postfix) with ESMTP id 40311C001E for ; Wed, 9 Nov 2022 11:51:47 +0000 (UTC) Received: by mail-pf1-f179.google.com with SMTP id q9so16463472pfg.5 for ; Wed, 09 Nov 2022 03:51:46 -0800 (PST) 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=78mZXjDUqjc2CGPH2b0kN46OixnL1hoGKm7bE9XBgUM=; b=IYn1pZPbT037tiskU40SdcUjr00Tb2lBA9rYT1D2KmHOqM8EdBQ1VdZg5ulYfsHP9S 6TKjKXb8ojMut+VZdnTW4d1VRfI7CfvfRNdt+nviVa7k35eGqRtMxtMJsHHgyGLW1otC FMK6emkiAqsGvvLekKvM1N8+He8/Dg8Ekinew= 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=78mZXjDUqjc2CGPH2b0kN46OixnL1hoGKm7bE9XBgUM=; b=0bckO0bxozWdGbiPCTkkLoTWUdrjf1AwN3kcYv3r4vTfepYlNDGQdaH3UKDQOnmNAd M2EfOPsaXNFo1yQcA5bUmsRqVDzpzwqrs/qtVWbeYM6Q17OBwDrECoSuL4jR7W/ygLtk GCuA3z0wgMGazrTKlMNmTfIoVIyDvhvWBIPvd5Eg2orSP9EdhQXoSCC++zHszfQMgGmD AXP8ZZ9+TGJMkSHhm0syDIQOzIiA3fbhNdziAFYx8w7k4bFTcwJG1fdsSVgVvqKgPesv 4vzazShQ/c4XwnuklttK8UeBLFfkHUSPy5WHdKi7lHf1JC1fIwGckRi3S4taTBz0zGYZ TbLw== X-Gm-Message-State: ACrzQf1x0sZhXsIbRuNiKbS42OCe66QE1kLTqiazbGVRrVfcU2gInkOj pjXjFVIm0YTeBUU9qPdN9RTtpQ== X-Google-Smtp-Source: AMsMyM4evVnWSvLkw+dSHbFX3CGE0wpnSBNFc155E+fkSbYY7z5M05e2ebLt+A3Ah2OBlfptSutn1w== X-Received: by 2002:a05:6a02:113:b0:43f:3554:ff9c with SMTP id bg19-20020a056a02011300b0043f3554ff9cmr52961284pgb.578.1667994683200; Wed, 09 Nov 2022 03:51:23 -0800 (PST) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:61f1:44d3:3f47:2cdb]) by smtp.gmail.com with ESMTPSA id f5-20020a655505000000b00434760ee36asm7292311pgr.16.2022.11.09.03.51.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Nov 2022 03:51:22 -0800 (PST) From: Sergey Senozhatsky To: Minchan Kim , Andrew Morton Cc: Nitin Gupta , Suleiman Souhlal , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Sergey Senozhatsky Subject: [PATCHv5 11/13] documentation: Add zram recompression documentation Date: Wed, 9 Nov 2022 20:50:45 +0900 Message-Id: <20221109115047.2921851-12-senozhatsky@chromium.org> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog In-Reply-To: <20221109115047.2921851-1-senozhatsky@chromium.org> References: <20221109115047.2921851-1-senozhatsky@chromium.org> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1667994707; a=rsa-sha256; cv=none; b=Gh9ynqSimCD6zFoLt3yFtYYJTtLc8D53FOguMUwXqA7Rc65vgawOYN5Mxt+AR8zJBnS5Su Lxv4Wk4mX3TQkBCr87cnDjOPSe5KXYNnLII3Ov/rFNXBMeDul9yXxUHeU1/Bv+KZ9KGTVI ndi4nDox5h2BMGG8Adnmd3opWcxyg9I= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=IYn1pZPb; spf=pass (imf22.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.210.179 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=1667994707; 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=78mZXjDUqjc2CGPH2b0kN46OixnL1hoGKm7bE9XBgUM=; b=yrT87XxIZ/U1IV74bYtcl3NVU1eN+LLBwJyCr6e5uK2CACrGMgQObBLYClhkPfTqEqZBcD +BIdoHksqQMWh0R0sOky/6jWVoiXy9U7wrDSrrflWGqQZrR69clBA7iOc5ptzli0YwfWts W5Y5JWYVQ1M5N2MN6ZakewqAUb4S7UQ= Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=IYn1pZPb; spf=pass (imf22.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.210.179 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org; dmarc=pass (policy=none) header.from=chromium.org X-Rspamd-Server: rspam12 X-Rspam-User: X-Stat-Signature: woze1tbixgricmp9c8ze65j3xrm971ty X-Rspamd-Queue-Id: 40311C001E X-HE-Tag: 1667994707-257128 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: Document user-space visible device attributes that are enabled by ZRAM_MULTI_COMP. Signed-off-by: Sergey Senozhatsky --- Documentation/admin-guide/blockdev/zram.rst | 81 +++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/Documentation/admin-guide/blockdev/zram.rst b/Documentation/admin-guide/blockdev/zram.rst index 177a142c3146..d898b7ace33d 100644 --- a/Documentation/admin-guide/blockdev/zram.rst +++ b/Documentation/admin-guide/blockdev/zram.rst @@ -401,6 +401,87 @@ budget in next setting is user's job. If admin wants to measure writeback count in a certain period, they could know it via /sys/block/zram0/bd_stat's 3rd column. +recompression +------------- + +With CONFIG_ZRAM_MULTI_COMP, zram can recompress pages using alternative +(secondary) compression algorithms. The basic idea is that alternative +compression algorithm can provide better compression ratio at a price of +(potentially) slower compression/decompression speeds. Alternative compression +algorithm can, for example, be more successful compressing huge pages (those +that default algorithm failed to compress). Another application is idle pages +recompression - pages that are cold and sit in the memory can be recompressed +using more effective algorithm and, hence, reduce zsmalloc memory usage. + +With CONFIG_ZRAM_MULTI_COMP, zram supports up to 4 compression algorithms: +one primary and up to 3 secondary ones. Primary zram compressor is explained +in "3) Select compression algorithm", secondary algorithms are configured +using recomp_algorithm device attribute. + +Example::: + + #show supported recompression algorithms + cat /sys/block/zramX/recomp_algorithm + #1: lzo lzo-rle lz4 lz4hc [zstd] + #2: lzo lzo-rle lz4 [lz4hc] zstd + +Alternative compression algorithms are sorted by priority. In the example +above, zstd is used as the first alternative algorithm, which has priority +of 1, while lz4hc is configured as a compression algorithm with priority 2. +Alternative compression algorithm's priority is provided during algorithms +configuration::: + + #select zstd recompression algorithm, priority 1 + echo "algo=zstd priority=1" > /sys/block/zramX/recomp_algorithm + + #select deflate recompression algorithm, priority 2 + echo "algo=deflate priority=2" > /sys/block/zramX/recomp_algorithm + +Another device attribute that CONFIG_ZRAM_MULTI_COMP enables is recompress, +which controls recompression. + +Examples::: + + #IDLE pages recompression is activated by `idle` mode + echo "type=idle" > /sys/block/zramX/recompress + + #HUGE pages recompression is activated by `huge` mode + echo "type=huge" > /sys/block/zram0/recompress + + #HUGE_IDLE pages recompression is activated by `huge_idle` mode + echo "type=huge_idle" > /sys/block/zramX/recompress + +The number of idle pages can be significant, so user-space can pass a size +threshold (in bytes) to the recompress knob: zram will recompress only pages +of equal or greater size::: + + #recompress all pages larger than 3000 bytes + echo "threshold=3000" > /sys/block/zramX/recompress + + #recompress idle pages larger than 2000 bytes + echo "type=idle threshold=2000" > /sys/block/zramX/recompress + +Recompression of idle pages requires memory tracking. + +During re-compression for every page, that matches re-compression criteria, +ZRAM iterates the list of registered alternative compression algorithms in +order of their priorities. ZRAM stops either when re-compression was +successful (re-compressed object is smaller in size than the original one) +and matches re-compression criteria (e.g. size threshold) or when there are +no secondary algorithms left to try. If none of the secondary algorithms can +successfully re-compressed the page such a page is marked as incompressible, +so ZRAM will not attempt to re-compress it in the future. + +This re-compression behaviour, when it iterates through the list of +registered compression algorithms, increases our chances of finding the +algorithm that successfully compresses a particular page. Sometimes, however, +it is convenient (and sometimes even necessary) to limit recompression to +only one particular algorithm so that it will not try any other algorithms. +This can be achieved by providing a algo=NAME parameter::: + + #use zstd algorithm only (if registered) + echo "type=huge algo=zstd" > /sys/block/zramX/recompress + memory tracking =============== From patchwork Wed Nov 9 11:50:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 13037466 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 17EB1C433FE for ; Wed, 9 Nov 2022 11:52:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AA7B48E0001; Wed, 9 Nov 2022 06:52:26 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A0A166B0074; Wed, 9 Nov 2022 06:52:26 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 883718E0001; Wed, 9 Nov 2022 06:52:26 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 752EA6B0072 for ; Wed, 9 Nov 2022 06:52:26 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 23472141473 for ; Wed, 9 Nov 2022 11:52:21 +0000 (UTC) X-FDA: 80113740882.14.95C1B1E Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) by imf13.hostedemail.com (Postfix) with ESMTP id C33AA20013 for ; Wed, 9 Nov 2022 11:52:15 +0000 (UTC) Received: by mail-pj1-f49.google.com with SMTP id o7so16503771pjj.1 for ; Wed, 09 Nov 2022 03:52:15 -0800 (PST) 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=ylEXai1pRtcdgY4n/dSSiM2pUBQ7klnnGwSEjhZhHnw=; b=Y8CaZZpNNRXSN720dhEH8GJYbNFPJnj7qu6nXjDoVmEhFp1S6sV0e5ZQD+4UJySJNP 6DPd+IsRr86SFqTWAIdYjHgWtQNzwRPeddZW8CfJIS+alIOMUtWqfLZYH9fKJUQ8sb1r Q+bjOa0eFHIPuVVvPiHll8unqEXUpibFpPrb4= 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=ylEXai1pRtcdgY4n/dSSiM2pUBQ7klnnGwSEjhZhHnw=; b=sEJjuzgcT3vrnduE19dSZSV5Xn3bSaWwNQ4az6F+mJCBUlTpatFOqrgA6KvlacYGBI ijGpP1xDZl2o1HtqZbyX6iDMMICTzoxbpMGub/jDtBNsKvq5w0n7B/U6WSDWkVDpHgaI bXV9mN9561diNxF2ibU75ljIxUU0NqV/0f/jLOckP714wEnvWpjp2IBJW6rXau+DQPeu HlpmayT4vz83zsjgRiPYbd1BYWgrHgz0qVU3GO0+M6+JzHIbhLSXdQfq/9sB2uDzi9o0 PGPy8g0Hm5IczWUhv1GiiSQre2p/U/0SuKmiq7LYJgXEqRuEXtsQ+5Aco8YzhnZQY7Or dfOA== X-Gm-Message-State: ACrzQf1n7+UxCHl8YqkQ60iED5V9YoZJpqRM6oxUIpyo0+LpiiuOPt2i EYgvNA8Vg+m3uopmP1arKZ/uPw== X-Google-Smtp-Source: AMsMyM7uMF0Rz+8FL9QxtxgFBHi/+RsBUmvD/klEYsmwj83jE4uQ0gTGXKrZehLIcGHB3AaAGJSvPw== X-Received: by 2002:a17:902:d708:b0:187:2721:68ca with SMTP id w8-20020a170902d70800b00187272168camr50203566ply.92.1667994685692; Wed, 09 Nov 2022 03:51:25 -0800 (PST) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:61f1:44d3:3f47:2cdb]) by smtp.gmail.com with ESMTPSA id f5-20020a655505000000b00434760ee36asm7292311pgr.16.2022.11.09.03.51.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Nov 2022 03:51:25 -0800 (PST) From: Sergey Senozhatsky To: Minchan Kim , Andrew Morton Cc: Nitin Gupta , Suleiman Souhlal , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Sergey Senozhatsky Subject: [PATCHv5 12/13] zram: add incompressible writeback Date: Wed, 9 Nov 2022 20:50:46 +0900 Message-Id: <20221109115047.2921851-13-senozhatsky@chromium.org> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog In-Reply-To: <20221109115047.2921851-1-senozhatsky@chromium.org> References: <20221109115047.2921851-1-senozhatsky@chromium.org> MIME-Version: 1.0 ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=Y8CaZZpN; spf=pass (imf13.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.216.49 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=1667994735; a=rsa-sha256; cv=none; b=1ZluC1OQCfrTNdEbbEwalV1U6V2IAV+pHnYHeaQFLN1fjxG0g0TFOhrjA8N9hgFeubf34U /cGLb9Styw6tn9+nr3ROIq9ryMGzvhoAN1an0Gt78UOOdlepaql/z9bY97Ginr0/nCO4Gz u5R4AHD4nVZDSdSvkYp1AlgFbvYERAc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1667994735; 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=ylEXai1pRtcdgY4n/dSSiM2pUBQ7klnnGwSEjhZhHnw=; b=e9mSiSfsmv3yfG3ti0k8zTe2ZO5SpX0+MusLf4ocbMONBdAHaQmVl7slOdbpY55OvSgFR6 FtVHmMN3is4x1IC9WqvU+L++wPxOdA6dHhG8u1hTEAYiWMYyBtKPPu9fXqpp2SOgLhnnxR 9/FvHEFrIc/kz1SFmszRWwnHbo6zjgg= X-Stat-Signature: mmgj8bb11tsthrz3mgkxxznynaekgwjd X-Rspamd-Queue-Id: C33AA20013 Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=Y8CaZZpN; spf=pass (imf13.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.216.49 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org; dmarc=pass (policy=none) header.from=chromium.org X-Rspam-User: X-Rspamd-Server: rspam06 X-HE-Tag: 1667994735-945051 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 support for incompressible pages writeback: echo incompressible > /sys/block/zramX/writeback Signed-off-by: Sergey Senozhatsky --- Documentation/admin-guide/blockdev/zram.rst | 7 ++++++- drivers/block/zram/zram_drv.c | 18 ++++++++++++------ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/Documentation/admin-guide/blockdev/zram.rst b/Documentation/admin-guide/blockdev/zram.rst index d898b7ace33d..f14c8c2e42f3 100644 --- a/Documentation/admin-guide/blockdev/zram.rst +++ b/Documentation/admin-guide/blockdev/zram.rst @@ -348,8 +348,13 @@ this can be accomplished with:: echo huge_idle > /sys/block/zramX/writeback +If a user chooses to writeback only incompressible pages (pages that none of +algorithms can compress) this can be accomplished with:: + + echo incompressible > /sys/block/zramX/writeback + If an admin wants to write a specific page in zram device to the backing device, -they could write a page index into the interface. +they could write a page index into the interface:: echo "page_index=1251" > /sys/block/zramX/writeback diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index 89d25f60b33e..2e4ef1ba1973 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -648,10 +648,10 @@ static int read_from_bdev_async(struct zram *zram, struct bio_vec *bvec, #define PAGE_WB_SIG "page_index=" -#define PAGE_WRITEBACK 0 -#define HUGE_WRITEBACK (1<<0) -#define IDLE_WRITEBACK (1<<1) - +#define PAGE_WRITEBACK 0 +#define HUGE_WRITEBACK (1<<0) +#define IDLE_WRITEBACK (1<<1) +#define INCOMPRESSIBLE_WRITEBACK (1<<2) static ssize_t writeback_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t len) @@ -672,6 +672,8 @@ static ssize_t writeback_store(struct device *dev, mode = HUGE_WRITEBACK; else if (sysfs_streq(buf, "huge_idle")) mode = IDLE_WRITEBACK | HUGE_WRITEBACK; + else if (sysfs_streq(buf, "incompressible")) + mode = INCOMPRESSIBLE_WRITEBACK; else { if (strncmp(buf, PAGE_WB_SIG, sizeof(PAGE_WB_SIG) - 1)) return -EINVAL; @@ -734,11 +736,15 @@ static ssize_t writeback_store(struct device *dev, goto next; if (mode & IDLE_WRITEBACK && - !zram_test_flag(zram, index, ZRAM_IDLE)) + !zram_test_flag(zram, index, ZRAM_IDLE)) goto next; if (mode & HUGE_WRITEBACK && - !zram_test_flag(zram, index, ZRAM_HUGE)) + !zram_test_flag(zram, index, ZRAM_HUGE)) goto next; + if (mode & INCOMPRESSIBLE_WRITEBACK && + !zram_test_flag(zram, index, ZRAM_INCOMPRESSIBLE)) + goto next; + /* * Clearing ZRAM_UNDER_WB is duty of caller. * IOW, zram_free_page never clear it. From patchwork Wed Nov 9 11:50:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 13037460 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 AE485C433FE for ; Wed, 9 Nov 2022 11:51:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5040A6B0075; Wed, 9 Nov 2022 06:51:58 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 465E58E0006; Wed, 9 Nov 2022 06:51:58 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 32C8A8E0005; Wed, 9 Nov 2022 06:51:58 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 2686D6B0075 for ; Wed, 9 Nov 2022 06:51:58 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 88BD41414D4 for ; Wed, 9 Nov 2022 11:51:53 +0000 (UTC) X-FDA: 80113739706.01.E9180E1 Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) by imf29.hostedemail.com (Postfix) with ESMTP id 3649E120014 for ; Wed, 9 Nov 2022 11:51:47 +0000 (UTC) Received: by mail-pf1-f180.google.com with SMTP id m6so16501672pfb.0 for ; Wed, 09 Nov 2022 03:51:47 -0800 (PST) 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=0dJwSSVWle5wAKsSMx0YgyDVQ6OL2lYtX7lIC3B32aM=; b=HPHG6Yl1KI8mjO7OGpNfDk9YjeU3vICc9sLqJbjbfAmOJLAc5WywPSQFJB18fJuCwG 7+L+GS+xMO9FXwYZsNZrYXG+YjRzsXJIVihSbtuJ/zBxUltuJrhH3vDMFNUNPYo4NYGb 4jwiks5wtyeCwT4bKKf8lTT4cLaN0kL0Hrfnc= 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=0dJwSSVWle5wAKsSMx0YgyDVQ6OL2lYtX7lIC3B32aM=; b=MOUM8NehWlFJgEQEyh++pSqMtlnIlTVw/uEBT34UQ6T80jjljOeW7PWlVG+h4PEmav 0eO3EOVQcYUM2TepZSnKAoyOVBObxRsFWHxMfOk9TEyXg1IOZF+X9Cj49vs2gGT2Labm rXZAd2GTe6Ob3Xfly2lYi95BjhAuaw3KXlVI8gEg8hCllg/Kxhp1zwgJZn1LrtCBzaN6 LMHc8Uw7UWtfNTcjRscTRsz+kdzkKVX8rLB819+OjknLqvlpWSwm72aLIXYbR/eoSODd r/8xovdgK8dDHX7DPyFmZ6BANt42RayPfLir3HFUabepc0DeM9g6IRHxIj7KWdbgSvw1 c1+Q== X-Gm-Message-State: ACrzQf1JgRL2/c4YBrnaw9/tZGQkjbmrHXewEQazkp57tYXQ/OMYnzvC Otu5cLd8pJSjI4zSD4lQXXudxQ== X-Google-Smtp-Source: AMsMyM4qP0VAZ/9g6k/1c2ELzDcyARTP25CtfOUKLGpwh2OuBRIs5q2CH788dxqVBNgKjab/wWnGJg== X-Received: by 2002:a63:5a63:0:b0:42f:e143:80d4 with SMTP id k35-20020a635a63000000b0042fe14380d4mr53000571pgm.456.1667994688240; Wed, 09 Nov 2022 03:51:28 -0800 (PST) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:61f1:44d3:3f47:2cdb]) by smtp.gmail.com with ESMTPSA id f5-20020a655505000000b00434760ee36asm7292311pgr.16.2022.11.09.03.51.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Nov 2022 03:51:27 -0800 (PST) From: Sergey Senozhatsky To: Minchan Kim , Andrew Morton Cc: Nitin Gupta , Suleiman Souhlal , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Sergey Senozhatsky Subject: [PATCHv5 13/13] zram: Add incompressible flag to read_block_state() Date: Wed, 9 Nov 2022 20:50:47 +0900 Message-Id: <20221109115047.2921851-14-senozhatsky@chromium.org> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog In-Reply-To: <20221109115047.2921851-1-senozhatsky@chromium.org> References: <20221109115047.2921851-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=1667994708; 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=0dJwSSVWle5wAKsSMx0YgyDVQ6OL2lYtX7lIC3B32aM=; b=ZgDqrvhveHbf5Kuq1MHtSQM8oaOO7qRgkZaoO8bkx4TIPKC/gAxzJrtIAHR1qeQYycRRcf wv70ktyn8NY5NYrs47XlEhA1b2nQhlHtj9HHymF+o51PCeQh3d3Sz8YIs+Q6b7euKSZMQ1 HotLSx3UW9ENcRl9vSzZ1tLaBGO5Ypo= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=HPHG6Yl1; spf=pass (imf29.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.210.180 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=1667994708; a=rsa-sha256; cv=none; b=Zr7RScNBtrjTJNSNXQOsXBesjAPzY+kSafOiJnpXZLJolemZTJtoip7fUm/i1UwPNPSDbJ 27Xd7/QZEizPBhXpU/qqR5Zg/AN0iz7TzWF9wsKHaepqWJbNYDv1Wi+ol/wUtePej6Bhs9 8WaedgvfhdJY6WU7FgciSmCRSiorqBo= X-Rspam-User: X-Stat-Signature: 6d1on3gbdke7kpu3qoafrz6bc46eq46x X-Rspamd-Queue-Id: 3649E120014 Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=HPHG6Yl1; spf=pass (imf29.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.210.180 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org; dmarc=pass (policy=none) header.from=chromium.org X-Rspamd-Server: rspam07 X-HE-Tag: 1667994707-327147 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 flag to zram block state that shows if the page is incompressible: that none of the algorithm (including secondary ones) could compress it. Suggested-by: Minchan Kim Signed-off-by: Sergey Senozhatsky --- Documentation/admin-guide/blockdev/zram.rst | 11 +++++++---- drivers/block/zram/zram_drv.c | 6 ++++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/Documentation/admin-guide/blockdev/zram.rst b/Documentation/admin-guide/blockdev/zram.rst index f14c8c2e42f3..e4551579cb12 100644 --- a/Documentation/admin-guide/blockdev/zram.rst +++ b/Documentation/admin-guide/blockdev/zram.rst @@ -497,10 +497,11 @@ pages of the process with*pagemap. If you enable the feature, you could see block state via /sys/kernel/debug/zram/zram0/block_state". The output is as follows:: - 300 75.033841 .wh.. - 301 63.806904 s.... - 302 63.806919 ..hi. - 303 62.801919 ....r + 300 75.033841 .wh... + 301 63.806904 s..... + 302 63.806919 ..hi.. + 303 62.801919 ....r. + 304 146.781902 ..hi.n First column zram's block index. @@ -519,6 +520,8 @@ Third column idle page r: recompressed page (secondary compression algorithm) + n: + none (including secondary) of algorithms could compress it First line of above example says 300th block is accessed at 75.033841sec and the block's state is huge so it is written back to the backing diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index 2e4ef1ba1973..3447df3ca75e 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -949,14 +949,16 @@ static ssize_t read_block_state(struct file *file, char __user *buf, ts = ktime_to_timespec64(zram->table[index].ac_time); copied = snprintf(kbuf + written, count, - "%12zd %12lld.%06lu %c%c%c%c%c\n", + "%12zd %12lld.%06lu %c%c%c%c%c%c\n", index, (s64)ts.tv_sec, ts.tv_nsec / NSEC_PER_USEC, zram_test_flag(zram, index, ZRAM_SAME) ? 's' : '.', zram_test_flag(zram, index, ZRAM_WB) ? 'w' : '.', zram_test_flag(zram, index, ZRAM_HUGE) ? 'h' : '.', zram_test_flag(zram, index, ZRAM_IDLE) ? 'i' : '.', - zram_get_priority(zram, index) ? 'r' : '.'); + zram_get_priority(zram, index) ? 'r' : '.', + zram_test_flag(zram, index, + ZRAM_INCOMPRESSIBLE) ? 'n' : '.'); if (count <= copied) { zram_slot_unlock(zram, index);