From nobody Mon Dec 1 22:05:43 2025 Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6C99D3019A6 for ; Mon, 1 Dec 2025 09:48:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764582494; cv=none; b=UrLWeEj8HdSZJkwXCsxjVEZQu6ajcSyGoVotsayVWDPTAUVBcVlfLVpEFtiSFnBhmTFGopJVHoCfxGmD9hxbmgkyfDQ0PwS55GiC5tCSpTBNBDEg5F6luHoXzAQtVxe5o0xvAevPTtcvDb27ghoLEY7fN/D0sYIavtn52j1wZTg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764582494; c=relaxed/simple; bh=pBIHL/+s3slAbUIkwhX3xs51RwCrZ2BcTqbC6s/6oF4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Iw2zqSmCTAP3PXnTXHcX2Ufy06mGkFpUJYoBHJ6Zj0XAm8O4btQBfvYxOanF9u1YgRCO4dcIJfDZlXn8rQ6trctHGAfJ2EE3dGEudncp+K8+I8dkUoUBoKd9zdJj3kZ5gRt92xvSHYD91dadmJgzi1Pz9GC32PCg2mVkbHiL1q8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=eACAm8yR; arc=none smtp.client-ip=209.85.210.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="eACAm8yR" Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-7bb3092e4d7so4026848b3a.0 for ; Mon, 01 Dec 2025 01:48:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1764582492; x=1765187292; darn=vger.kernel.org; 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=BqN6IsMp+xic4hsBD/TTSEY4e1QCsNoi7vBlxa2loK0=; b=eACAm8yRoPgEPZdvlasJxEfm1e1d0KxdJp4ceqjPQqEjBSMp3ZFyusLC7X9yFpwNBR OKvDo/N3y7LafNSKUVSmyGrhwepDtBE98Q4gR9JUv8xrE/hsrJecQxex8aBsaiCUlI7c 0OmIJ6rBAXQ3XW9GagYo5U70bR36dhtRPJB9o= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764582492; x=1765187292; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=BqN6IsMp+xic4hsBD/TTSEY4e1QCsNoi7vBlxa2loK0=; b=FoN2OgYGpvJXMCxYu9UH//hcxUG7KZVM0ehF7b0dPHJWowdfG9pDt8Cx2J/Gjh0sQ4 Rewb6n/xIv09g9J0t3D44IR+KnPklhKP5q7k8NKVYYosEKo2WV1w7YOuFmmXXaBpqfnz TQPWK8MtKO1fmATrv+2+dbLKliNZyhRpJ53EqNpK3vNN2FhDHNX+ES/MwX8d2XDFAJKh DIUYOw+R9wtfKlyAVWnQrB8R7+1vvIvx68Vk0RjYobWTzSNtooG/DoCEvTbi6NRBWbm9 XyUKuFguX6d3srjCVSGHgRV7hjSIrlU4ndwqTVnB4PAt9S6MHtfOn+g1Pu86teINBo8c BISQ== X-Forwarded-Encrypted: i=1; AJvYcCWcU7MKqoPVcOrQctMSbOh9K7XFiqVuJK5MyL7bwZipBsMacdFS2XDicoVMQntkPICfGR+8yX76Cqsg4nc=@vger.kernel.org X-Gm-Message-State: AOJu0YyAeF4gSTiTzMHfcSmBWhfOxBUk3t7hfaDGCBKsZq3547fENy8X Wg2SjPvEKEW+h47X1USipfHvvOzuSkCrv9iwjMdOGlSuIn5Jiw04WOTEVAXvM03TjA== X-Gm-Gg: ASbGnctCyk3l8IvuK7WuC9D9pmhSB0e2E7dnGG3enKQDA/CoGwJY+xL/CrpVQENJm5J 9DcWiTMBJGpxzMzfHDwTQebTrGvCZVN0A4IJW1tpMLgjL+ji6VyQzBO+cnp9vZzADfMk7oEcU+V kCrOTLEhNpCn81C7KW1al2QxoeN20z+JChqhETnWFOm02cvfBvuqwpOlCwxxtOsHID4HWTdcKF/ t+lv4/ngw9Fjfs8XFH3BosRFSmymNQcRz01IU4onaJqlmftnZN6TlBhn8xGcoXHSGaFsQ123WIf 7v3O9Gb4dXCjDgBje8fsmdhTYuia4uN4d8WwavNvOnadxWPzt/SQFvYoG1vdMLS/Kg7xAIThHcc oLXcXcImWdh6ZzBMCvSgA4e1YBe1/0X9B5LkDRJxsRoz8zjdJCmGQU1bZZu4FpJyn78dJpVFVrj EPyki7bd8n1KayxKGBmnj4zBBMNi8k47fWURIw5IDSIDo60x0V1DbUPXpjuXVatUQTeMHVHr/zn g== X-Google-Smtp-Source: AGHT+IFPOKXBPxIWlb2N5bOWQcJ4Qpt2yM3sF83+3IIpZZQ0LRK1r32xVMYgoCct611DyaOc2sndNw== X-Received: by 2002:a05:6a20:9184:b0:340:d065:c8b3 with SMTP id adf61e73a8af0-3614ed971edmr40400894637.36.1764582491688; Mon, 01 Dec 2025 01:48:11 -0800 (PST) Received: from tigerii.tok.corp.google.com ([2a00:79e0:2031:6:943c:f651:f00f:2459]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7d15e7db577sm12882074b3a.31.2025.12.01.01.48.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Dec 2025 01:48:11 -0800 (PST) From: Sergey Senozhatsky To: Andrew Morton , Richard Chang , Minchan Kim Cc: Brian Geffon , David Stevens , linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-block@vger.kernel.org, Sergey Senozhatsky Subject: [PATCHv2 2/7] zram: introduce writeback_compressed device attribute Date: Mon, 1 Dec 2025 18:47:49 +0900 Message-ID: <20251201094754.4149975-3-senozhatsky@chromium.org> X-Mailer: git-send-email 2.52.0.487.g5c8c507ade-goog In-Reply-To: <20251201094754.4149975-1-senozhatsky@chromium.org> References: <20251201094754.4149975-1-senozhatsky@chromium.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Richard Chang Introduce witeback_compressed device attribute to toggle compressed writeback (decompression on demand) feature. [senozhatsky: rewrote original patch, added documentation] Signed-off-by: Richard Chang Co-developed-by: Sergey Senozhatsky --- Documentation/ABI/testing/sysfs-block-zram | 7 ++++ Documentation/admin-guide/blockdev/zram.rst | 13 +++++++ drivers/block/zram/zram_drv.c | 38 +++++++++++++++++++++ 3 files changed, 58 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-block-zram b/Documentation/ABI= /testing/sysfs-block-zram index 36c57de0a10a..ed10c2e4b5c2 100644 --- a/Documentation/ABI/testing/sysfs-block-zram +++ b/Documentation/ABI/testing/sysfs-block-zram @@ -150,3 +150,10 @@ Contact: Sergey Senozhatsky Description: The algorithm_params file is write-only and is used to setup compression algorithm parameters. + +What: /sys/block/zram/writeback_compressed +Date: Decemeber 2025 +Contact: Richard Chang +Description: + The writeback_compressed device atrribute toggles compressed + writeback feature. diff --git a/Documentation/admin-guide/blockdev/zram.rst b/Documentation/ad= min-guide/blockdev/zram.rst index 3e273c1bb749..9547e4e95979 100644 --- a/Documentation/admin-guide/blockdev/zram.rst +++ b/Documentation/admin-guide/blockdev/zram.rst @@ -214,6 +214,7 @@ mem_limit WO specifies the maximum amount of m= emory ZRAM can writeback_limit WO specifies the maximum amount of write IO zram can write out to backing device as 4KB unit writeback_limit_enable RW show and set writeback_limit feature +writeback_compressed RW show and set compressed writeback feature comp_algorithm RW show and change the compression algorithm algorithm_params WO setup compression algorithm parameters compact WO trigger memory compaction @@ -434,6 +435,18 @@ system reboot, echo 1 > /sys/block/zramX/reset) so kee= ping how many of writeback happened until you reset the zram to allocate extra writeback budget in next setting is user's job. =20 +By default zram stores written back pages in decompressed (raw) form, which +means that writeback operation involves decompression of the page before +writing it to the backing device. This behavior can be changed by enabling +`writeback_compressed` feature, which causes zram to write compressed pages +to the backing device, thus avoiding decompression overhead. To enable +this feature, execute:: + + $ echo yes > /sys/block/zramX/writeback_compressed + +Note that this feature should be configured before the `zramX` device is +initialized. + If admin wants to measure writeback count in a certain period, they could know it via /sys/block/zram0/bd_stat's 3rd column. =20 diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index 6263d300312e..3cc03c3f7389 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -539,6 +539,42 @@ struct zram_rb_req { u32 index; }; =20 +static ssize_t writeback_compressed_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t len) +{ + struct zram *zram =3D dev_to_zram(dev); + bool val; + + if (kstrtobool(buf, &val)) + return -EINVAL; + + down_write(&zram->init_lock); + if (init_done(zram)) { + up_write(&zram->init_lock); + return -EBUSY; + } + + zram->wb_compressed =3D val; + up_write(&zram->init_lock); + + return len; +} + +static ssize_t writeback_compressed_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + bool val; + struct zram *zram =3D dev_to_zram(dev); + + down_read(&zram->init_lock); + val =3D zram->wb_compressed; + up_read(&zram->init_lock); + + return sysfs_emit(buf, "%d\n", val); +} + static ssize_t writeback_limit_enable_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t len) @@ -3048,6 +3084,7 @@ static DEVICE_ATTR_WO(writeback); static DEVICE_ATTR_RW(writeback_limit); static DEVICE_ATTR_RW(writeback_limit_enable); static DEVICE_ATTR_RW(writeback_batch_size); +static DEVICE_ATTR_RW(writeback_compressed); #endif #ifdef CONFIG_ZRAM_MULTI_COMP static DEVICE_ATTR_RW(recomp_algorithm); @@ -3070,6 +3107,7 @@ static struct attribute *zram_disk_attrs[] =3D { &dev_attr_writeback_limit.attr, &dev_attr_writeback_limit_enable.attr, &dev_attr_writeback_batch_size.attr, + &dev_attr_writeback_compressed.attr, #endif &dev_attr_io_stat.attr, &dev_attr_mm_stat.attr, --=20 2.52.0.487.g5c8c507ade-goog