[PATCH 1/4] mm/zswap: remove unnecessary dlen writes for incompressible pages

SeongJae Park posted 4 patches 4 months, 1 week ago
[PATCH 1/4] mm/zswap: remove unnecessary dlen writes for incompressible pages
Posted by SeongJae Park 4 months, 1 week ago
Incompressible pages handling logic in zswap_compress() is setting
'dlen' as PAGE_SIZE twice.  Once before deciding whether to save the
content as is, and once again after it is decided to save it as is.
But the value of 'dlen' is used only if it is decided to save the
content as is, so the first write is unnecessary.  It is not causing
real user issues, but making code confusing to read.  Remove the
unnecessary write operation.

Signed-off-by: SeongJae Park <sj@kernel.org>
---
 mm/zswap.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/mm/zswap.c b/mm/zswap.c
index c1af782e54ec..80619c8589a7 100644
--- a/mm/zswap.c
+++ b/mm/zswap.c
@@ -894,7 +894,6 @@ static bool zswap_compress(struct page *page, struct zswap_entry *entry,
 	 * to the active LRU list in the case.
 	 */
 	if (comp_ret || !dlen || dlen >= PAGE_SIZE) {
-		dlen = PAGE_SIZE;
 		if (!mem_cgroup_zswap_writeback_enabled(
 					folio_memcg(page_folio(page)))) {
 			comp_ret = comp_ret ? comp_ret : -EINVAL;
-- 
2.39.5
Re: [PATCH 1/4] mm/zswap: remove unnecessary dlen writes for incompressible pages
Posted by Chengming Zhou 4 months ago
On 2025/10/4 04:38, SeongJae Park wrote:
> Incompressible pages handling logic in zswap_compress() is setting
> 'dlen' as PAGE_SIZE twice.  Once before deciding whether to save the
> content as is, and once again after it is decided to save it as is.
> But the value of 'dlen' is used only if it is decided to save the
> content as is, so the first write is unnecessary.  It is not causing
> real user issues, but making code confusing to read.  Remove the
> unnecessary write operation.
> 
> Signed-off-by: SeongJae Park <sj@kernel.org>

Reviewed-by: Chengming Zhou <chengming.zhou@linux.dev>

> ---
>   mm/zswap.c | 1 -
>   1 file changed, 1 deletion(-)
> 
> diff --git a/mm/zswap.c b/mm/zswap.c
> index c1af782e54ec..80619c8589a7 100644
> --- a/mm/zswap.c
> +++ b/mm/zswap.c
> @@ -894,7 +894,6 @@ static bool zswap_compress(struct page *page, struct zswap_entry *entry,
>   	 * to the active LRU list in the case.
>   	 */
>   	if (comp_ret || !dlen || dlen >= PAGE_SIZE) {
> -		dlen = PAGE_SIZE;
>   		if (!mem_cgroup_zswap_writeback_enabled(
>   					folio_memcg(page_folio(page)))) {
>   			comp_ret = comp_ret ? comp_ret : -EINVAL;
Re: [PATCH 1/4] mm/zswap: remove unnecessary dlen writes for incompressible pages
Posted by Nhat Pham 4 months ago
On Fri, Oct 3, 2025 at 1:38 PM SeongJae Park <sj@kernel.org> wrote:
>
> Incompressible pages handling logic in zswap_compress() is setting
> 'dlen' as PAGE_SIZE twice.  Once before deciding whether to save the
> content as is, and once again after it is decided to save it as is.
> But the value of 'dlen' is used only if it is decided to save the
> content as is, so the first write is unnecessary.  It is not causing
> real user issues, but making code confusing to read.  Remove the
> unnecessary write operation.
>
> Signed-off-by: SeongJae Park <sj@kernel.org>

Acked-by: Nhat Pham <nphamcs@gmail.com>
Re: [PATCH 1/4] mm/zswap: remove unnecessary dlen writes for incompressible pages
Posted by Yosry Ahmed 4 months ago
On Fri, Oct 03, 2025 at 01:38:48PM -0700, SeongJae Park wrote:
> Incompressible pages handling logic in zswap_compress() is setting
> 'dlen' as PAGE_SIZE twice.  Once before deciding whether to save the
> content as is, and once again after it is decided to save it as is.
> But the value of 'dlen' is used only if it is decided to save the
> content as is, so the first write is unnecessary.  It is not causing
> real user issues, but making code confusing to read.  Remove the
> unnecessary write operation.
> 
> Signed-off-by: SeongJae Park <sj@kernel.org>

Acked-by: Yosry Ahmed <yosry.ahmed@linux.dev>

> ---
>  mm/zswap.c | 1 -
>  1 file changed, 1 deletion(-)
> 
> diff --git a/mm/zswap.c b/mm/zswap.c
> index c1af782e54ec..80619c8589a7 100644
> --- a/mm/zswap.c
> +++ b/mm/zswap.c
> @@ -894,7 +894,6 @@ static bool zswap_compress(struct page *page, struct zswap_entry *entry,
>  	 * to the active LRU list in the case.
>  	 */
>  	if (comp_ret || !dlen || dlen >= PAGE_SIZE) {
> -		dlen = PAGE_SIZE;
>  		if (!mem_cgroup_zswap_writeback_enabled(
>  					folio_memcg(page_folio(page)))) {
>  			comp_ret = comp_ret ? comp_ret : -EINVAL;
> -- 
> 2.39.5