From patchwork Wed Nov 15 02:42:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 13456164 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 89AEC644 for ; Wed, 15 Nov 2023 02:42:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="IbResloZ" Received: from mail-oi1-x229.google.com (mail-oi1-x229.google.com [IPv6:2607:f8b0:4864:20::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF1DBCA for ; Tue, 14 Nov 2023 18:42:33 -0800 (PST) Received: by mail-oi1-x229.google.com with SMTP id 5614622812f47-3b56b618217so3752697b6e.0 for ; Tue, 14 Nov 2023 18:42:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1700016153; x=1700620953; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=iNxsGh7O8Qrwyxy3QycDFsbHOojSVaRxAmLFQTto2P4=; b=IbResloZCbM+GRpuzwbCVcvtPBqgJlz7XjeuiBwyt1BycPgKmpNGGk5c7Ftp0+EQd/ gFN76gwNWeTvez/nv3NGzrHdNDROoVMyHzSdBPFHk81qPYQ6ASi3UE2c9k7HFMXdfyKx I+JlHXcmyZCKBi+C+zO4sCfNMTC3HU4Chq4rs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700016153; x=1700620953; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=iNxsGh7O8Qrwyxy3QycDFsbHOojSVaRxAmLFQTto2P4=; b=tSkCJb4eMBjmjstwC2kV0kaffYAC2Xfa6Ar7XemsfeDSnI468KkdkEfvxCxhBPHbt7 KmvMNen9hXaOEFPF+m9d7g6XyEiM8bPo0bODxm37M4+4Lb+BR9SLxTCjjt65LGN9ViDL +yDKndOd1McIepvnw4/63lnL7RHlsDOmOrVleNm1zgLdJ1h+umexjM1NsQscPg51vP5l mJ1fNc2tvgcxGx5sKdhTPQEBCuqP8jH/cfALJYI4ZQjD94zg3p9a7p1HYHIttpQTS1V/ r9Yu0w+/ck70Npp5EV6giNFTyu/nLCdqC7huFvMQCj542VIqzSYPmsd1u0nZhQlnLcDj FC+w== X-Gm-Message-State: AOJu0YxiMwpcZ5A44T0cTup5EN5RmeS4wq9RPU7TS5MXM9NL8A7/m51x Ksiui2ErZWAGSyLWD/+5NUNhR4CfD5xtBQ0YhzY= X-Google-Smtp-Source: AGHT+IFn97al+iQz35GaoiLcoDHRp1U4+X5Wc4pvZ38la847bt/RUgOnYLlhOsTW6uqOHxWr6PddnQ== X-Received: by 2002:a05:6808:2f17:b0:3af:983a:8129 with SMTP id gu23-20020a0568082f1700b003af983a8129mr15857252oib.53.1700016153179; Tue, 14 Nov 2023 18:42:33 -0800 (PST) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:dfe3:bfcd:e155:c392]) by smtp.gmail.com with ESMTPSA id c15-20020a62e80f000000b0068ffd56f705sm1862016pfi.118.2023.11.14.18.42.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Nov 2023 18:42:32 -0800 (PST) From: Sergey Senozhatsky To: Minchan Kim Cc: Andrew Morton , linux-block@vger.kernel.org, Sergey Senozhatsky Subject: [PATCH 1/2] zram: split memory-tracking and ac-time tracking Date: Wed, 15 Nov 2023 11:42:12 +0900 Message-ID: <20231115024223.4133148-1-senozhatsky@chromium.org> X-Mailer: git-send-email 2.43.0.rc0.421.g78406f8d94-goog Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 ZRAM_MEMORY_TRACKING enables two features: - per-entry ac-time tracking - debugfs interface The latter one is the reason why memory-tracking depends on DEBUG_FS, while the former one is used far beyond debugging these days. Namely ac-time is used for fine-grained writeback of idle entries (pages). Move ac-time tracking under its own config option so that it can be enabled (along with writeback) on systems without DEBUG_FS. Signed-off-by: Sergey Senozhatsky --- Documentation/admin-guide/blockdev/zram.rst | 2 +- drivers/block/zram/Kconfig | 11 ++++++++- drivers/block/zram/zram_drv.c | 27 ++++++++++----------- drivers/block/zram/zram_drv.h | 2 +- 4 files changed, 25 insertions(+), 17 deletions(-) diff --git a/Documentation/admin-guide/blockdev/zram.rst b/Documentation/admin-guide/blockdev/zram.rst index e4551579cb12..ee2b0030d416 100644 --- a/Documentation/admin-guide/blockdev/zram.rst +++ b/Documentation/admin-guide/blockdev/zram.rst @@ -328,7 +328,7 @@ as idle:: From now on, any pages on zram are idle pages. The idle mark will be removed until someone requests access of the block. IOW, unless there is access request, those pages are still idle pages. -Additionally, when CONFIG_ZRAM_MEMORY_TRACKING is enabled pages can be +Additionally, when CONFIG_ZRAM_TRACK_ENTRY_ACTIME is enabled pages can be marked as idle based on how long (in seconds) it's been since they were last accessed:: diff --git a/drivers/block/zram/Kconfig b/drivers/block/zram/Kconfig index 0386b7da02aa..af201392ed52 100644 --- a/drivers/block/zram/Kconfig +++ b/drivers/block/zram/Kconfig @@ -69,9 +69,18 @@ config ZRAM_WRITEBACK See Documentation/admin-guide/blockdev/zram.rst for more information. +config ZRAM_TRACK_ENTRY_ACTIME + bool "Track access time of zram entries" + depends on ZRAM + help + With this feature zram tracks access time of every stored + entry (page), which can be used for a more fine-grained IDLE + pages writeback. + config ZRAM_MEMORY_TRACKING bool "Track zRam block status" depends on ZRAM && DEBUG_FS + select ZRAM_TRACK_ENTRY_ACTIME help With this feature, admin can track the state of allocated blocks of zRAM. Admin could see the information via @@ -86,4 +95,4 @@ config ZRAM_MULTI_COMP 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. + requires ZRAM_TRACK_ENTRY_ACTIME. diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index d77d3664ca08..68e0a8187783 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -174,6 +174,14 @@ static inline u32 zram_get_priority(struct zram *zram, u32 index) return prio & ZRAM_COMP_PRIORITY_MASK; } +static void zram_accessed(struct zram *zram, u32 index) +{ + zram_clear_flag(zram, index, ZRAM_IDLE); +#ifdef CONFIG_ZRAM_TRACK_ENTRY_ACTIME + zram->table[index].ac_time = ktime_get_boottime(); +#endif +} + static inline void update_used_max(struct zram *zram, const unsigned long pages) { @@ -293,8 +301,9 @@ static void mark_idle(struct zram *zram, ktime_t cutoff) zram_slot_lock(zram, index); if (zram_allocated(zram, index) && !zram_test_flag(zram, index, ZRAM_UNDER_WB)) { -#ifdef CONFIG_ZRAM_MEMORY_TRACKING - is_idle = !cutoff || ktime_after(cutoff, zram->table[index].ac_time); +#ifdef ZRAM_TRACK_ENTRY_ACTIME + is_idle = !cutoff || ktime_after(cutoff, + zram->table[index].ac_time); #endif if (is_idle) zram_set_flag(zram, index, ZRAM_IDLE); @@ -317,7 +326,7 @@ static ssize_t idle_store(struct device *dev, */ u64 age_sec; - if (IS_ENABLED(CONFIG_ZRAM_MEMORY_TRACKING) && !kstrtoull(buf, 0, &age_sec)) + if (IS_ENABLED(CONFIG_ZRAM_TRACK_ENTRY_ACTIME) && !kstrtoull(buf, 0, &age_sec)) cutoff_time = ktime_sub(ktime_get_boottime(), ns_to_ktime(age_sec * NSEC_PER_SEC)); else @@ -841,12 +850,6 @@ static void zram_debugfs_destroy(void) debugfs_remove_recursive(zram_debugfs_root); } -static void zram_accessed(struct zram *zram, u32 index) -{ - zram_clear_flag(zram, index, ZRAM_IDLE); - zram->table[index].ac_time = ktime_get_boottime(); -} - static ssize_t read_block_state(struct file *file, char __user *buf, size_t count, loff_t *ppos) { @@ -930,10 +933,6 @@ static void zram_debugfs_unregister(struct zram *zram) #else static void zram_debugfs_create(void) {}; static void zram_debugfs_destroy(void) {}; -static void zram_accessed(struct zram *zram, u32 index) -{ - zram_clear_flag(zram, index, ZRAM_IDLE); -}; static void zram_debugfs_register(struct zram *zram) {}; static void zram_debugfs_unregister(struct zram *zram) {}; #endif @@ -1254,7 +1253,7 @@ static void zram_free_page(struct zram *zram, size_t index) { unsigned long handle; -#ifdef CONFIG_ZRAM_MEMORY_TRACKING +#ifdef CONFIG_ZRAM_TRACK_ENTRY_ACTIME zram->table[index].ac_time = 0; #endif if (zram_test_flag(zram, index, ZRAM_IDLE)) diff --git a/drivers/block/zram/zram_drv.h b/drivers/block/zram/zram_drv.h index d090753f97be..3b94d12f41b4 100644 --- a/drivers/block/zram/zram_drv.h +++ b/drivers/block/zram/zram_drv.h @@ -69,7 +69,7 @@ struct zram_table_entry { unsigned long element; }; unsigned long flags; -#ifdef CONFIG_ZRAM_MEMORY_TRACKING +#ifdef CONFIG_ZRAM_TRACK_ENTRY_ACTIME ktime_t ac_time; #endif }; From patchwork Wed Nov 15 02:42:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 13456165 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AE81D644 for ; Wed, 15 Nov 2023 02:42:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="awEMNyUf" Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C4F59C8 for ; Tue, 14 Nov 2023 18:42:38 -0800 (PST) Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-6c32a20d5dbso5720927b3a.1 for ; Tue, 14 Nov 2023 18:42:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1700016158; x=1700620958; 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=3VD/qfUA8hK9LrNVNGdNy45/FGzdZaL0XDcCmNsYDKk=; b=awEMNyUf3PS99csUDZtoHr1Oe6PHeW0+VoZEwZg1S6s39G8IyL/1GlP5lQCpYGpw/E TU7OFCcKOEbzuMEWECcKuXEYES9LdGQ1lwZJemSxXc1kQ5W895kWZFB0g8XpuDlF+MNN Ahv849U+JT6/OI+9sTK6TFFh//4NxKnK6oAxY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700016158; x=1700620958; 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=3VD/qfUA8hK9LrNVNGdNy45/FGzdZaL0XDcCmNsYDKk=; b=UHWGK5/DzF+4XCTB4loqul93t3E559j05k1RQ9yxLLT5INQriKFPVnmLcfL5A9ziEv TvLq0koYZkErDTV/ENpRcR97aNa3/3hoeCmUNSCDNWOI6cHo9OzMsIf9HZd+9tJIQrfw zjV3VmqoL9PVTQLie1CYyrPu9E0tKxhf3sBJ2TDJeGQRm3awMPZ/6BKn8S+/BhrjHrec bxc9GYLD3TOcIGTqdIlznn3+v1soOmtu43Y4bUyDPyEcr+J53ohqHHR31lzDWcdQUm05 ZDAzma+a+nAGNS/kEL8+XxXFxvKkcm6JJY/zl+CzqRnJJsEuMRjxMZpQKjLdvSsF6yK+ 4zqA== X-Gm-Message-State: AOJu0YyOe3X0yKa8cVsLcFLbwUVD6E1seL4t/rg2cU1RRgXIE6b/HEGc HZOZsn6UVrKNep9bOXob0MCLqfh8krtzDBvd4fE= X-Google-Smtp-Source: AGHT+IHSV0HQALZRrZs3q5DkDvLmgw0G/p1SXNykrNJdK5dx0Fyf6gr985MkByLq7NofCYDhQdbmCw== X-Received: by 2002:a05:6a00:8c05:b0:6c3:402a:d53d with SMTP id ih5-20020a056a008c0500b006c3402ad53dmr10257300pfb.2.1700016158230; Tue, 14 Nov 2023 18:42:38 -0800 (PST) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:dfe3:bfcd:e155:c392]) by smtp.gmail.com with ESMTPSA id c15-20020a62e80f000000b0068ffd56f705sm1862016pfi.118.2023.11.14.18.42.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Nov 2023 18:42:37 -0800 (PST) From: Sergey Senozhatsky To: Minchan Kim Cc: Andrew Morton , linux-block@vger.kernel.org, Sergey Senozhatsky Subject: [PATCH 2/2] zram: tweak writeback config help Date: Wed, 15 Nov 2023 11:42:13 +0900 Message-ID: <20231115024223.4133148-2-senozhatsky@chromium.org> X-Mailer: git-send-email 2.43.0.rc0.421.g78406f8d94-goog In-Reply-To: <20231115024223.4133148-1-senozhatsky@chromium.org> References: <20231115024223.4133148-1-senozhatsky@chromium.org> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Writeback is for incompressible and idle zram pages. Signed-off-by: Sergey Senozhatsky --- drivers/block/zram/Kconfig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/block/zram/Kconfig b/drivers/block/zram/Kconfig index af201392ed52..7b29cce60ab2 100644 --- a/drivers/block/zram/Kconfig +++ b/drivers/block/zram/Kconfig @@ -59,8 +59,8 @@ config ZRAM_WRITEBACK bool "Write back incompressible or idle page to backing device" depends on ZRAM help - With incompressible page, there is no memory saving to keep it - in memory. Instead, write it out to backing device. + This lets zram entries (incompressible or idle pages) be written + back to a backing device, helping save memory. For this feature, admin should set up backing device via /sys/block/zramX/backing_dev.