From nobody Mon Nov 25 09:24:43 2024 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (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 86FF81DE2C1 for ; Mon, 28 Oct 2024 15:36:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730129799; cv=none; b=o1cZufc5vMZJePNdL8cdZZYzDNSfWD6NowrbjFsdEZYpoNBKJbBXNnsleudXwQbI8jGhb8tkAB4tA8FjKxH2g6oWnl9H1+E4Ga/LHdyGsQnBnGk4i0K/30tYlRwRDiO/wos8FOgNU2K1XKd4rBOIhd42RBdUmIklv2q4jZQRKoQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730129799; c=relaxed/simple; bh=D8qVhLY7cp5ZrIFs787hS9zu2zE924eQQ00QtofptCU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GNCOl7r+RDOQPy1/UJ3luBaOT+xwxomWTidFkzaItYuZsY3NBbhdg9AXdysryx6zmkBSuVLFRX7OWOEejFtu1fOFwS+B2sjWaC6YWncl428lYWNLctKstosgb7Qwnp4KjEjRS+b7PKMUdA4iM6KEHetd0+0jhNokhgwdFq/MKs4= 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=Ydy77of1; arc=none smtp.client-ip=209.85.214.181 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="Ydy77of1" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-20cbcd71012so46700515ad.3 for ; Mon, 28 Oct 2024 08:36:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1730129797; x=1730734597; 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=VekKtOcIL2XlAiZyaRpPMpDMSW/07N1v4rzhUHMgj/M=; b=Ydy77of1RvgWx0TfYnC/BC2hnOv71Tcxc4eJUmQwimYL6iqYl9Zg4bznKaI/MweqeS wAwwtMDh2EY/vsZfQZ1Zk7SGMW3/SvzKFe7zy68Z87RrGlADCt+YSIXPEBu4KfprWY9F XmDXE036gIKMZqYG1UKS1OL7x1D6qGgH5BEeQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730129797; x=1730734597; 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=VekKtOcIL2XlAiZyaRpPMpDMSW/07N1v4rzhUHMgj/M=; b=hbu1ZfZjXmuo0pIaPI7OMYJ9b4Hn+QHUAIcVVOOsD3lIQlKIg2Qx5pR50zuFR9Go7g jkI1ugA7/zug2pWn4plS49YLVSj/8IdPEFFuGR74GxvEQxUfKisQBCf+FMoyMfawtyIF CzOcAAuQtdv6fmlLpXZihXgauEre2qulOp8iy/RwNHLmaqecJP4wae1nX0xt8r/qSkJx mprma4Dh3iCtuDE0NfRfgYgaoe3X1dVdl+fgtE+3d2aIJUEjpQ1fsrNLNWg0DDXwtQGP eORXoTZnvceKLNnbDkN9wFM2nCXp0MOKTpNazFDtez+Qwma/ECfDCeEbb/P/AX+Aijop aYEw== X-Forwarded-Encrypted: i=1; AJvYcCX45ewx/y3GKBnAhV/Pj9UYhJyHziJdLc6TyCnqQFebNFMf6FpYPkmZQnAHA14UemEsSBVKIG4dUlMr0ak=@vger.kernel.org X-Gm-Message-State: AOJu0Yy0QgWz2k2WI8i10AQ7AHKLxBHS8yUuqYLhk15DIiIZir3MTm8M nze2kvulZjMdGnGURKBcbz9Lz+MpbfEQb3UR6iCzeMwIjkmON3suOseBRdNhcw== X-Google-Smtp-Source: AGHT+IEoIA3Hzn8CW7zUq26D/IwpzgMrKpXv7lx8YAfS3tHdZM4tQamdP55uxpfeZjalR4wKk14uRg== X-Received: by 2002:a17:903:2283:b0:20c:8331:cb6e with SMTP id d9443c01a7336-210c68c951cmr134720385ad.19.1730129796825; Mon, 28 Oct 2024 08:36:36 -0700 (PDT) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:f1f8:97e1:9c5b:d66f]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-210bbf4a230sm52148315ad.31.2024.10.28.08.36.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2024 08:36:36 -0700 (PDT) From: Sergey Senozhatsky To: Andrew Morton Cc: Minchan Kim , linux-kernel@vger.kernel.org, Sergey Senozhatsky Subject: [PATCHv2 1/2] zram: clear IDLE flag after recompression Date: Tue, 29 Oct 2024 00:36:14 +0900 Message-ID: <20241028153629.1479791-2-senozhatsky@chromium.org> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog In-Reply-To: <20241028153629.1479791-1-senozhatsky@chromium.org> References: <20241028153629.1479791-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" Recompression should clear ZRAM_IDLE flag on the entries it has accessed, because otherwise some entries, specifically those for which recompression has failed, become immediate candidate entries for another post-processing (e.g. writeback). Consider the following case: - recompression marks entries IDLE every 4 hours and attempts to recompress them - some entries are incompressible, so we keep them intact and hence preserve IDLE flag - writeback marks entries IDLE every 8 hours and writebacks IDLE entries, however we have IDLE entries left from recompression, so writeback prematurely writebacks those entries. The bug was reported by Shin Kawamura. Fixes: 84b33bf78889 ("zram: introduce recompress sysfs knob") Signed-off-by: Sergey Senozhatsky Acked-by: Brian Geffon Reported-by: Shin Kawamura --- drivers/block/zram/zram_drv.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index e6d12e81241d..a16dbffcdca3 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -1864,6 +1864,13 @@ static int recompress_slot(struct zram *zram, u32 in= dex, struct page *page, if (ret) return ret; =20 + /* + * We touched this entry so mark it as non-IDLE. This makes sure that + * we don't preserve IDLE flag and don't incorrectly pick this entry + * for different post-processing type (e.g. writeback). + */ + zram_clear_flag(zram, index, ZRAM_IDLE); + class_index_old =3D zs_lookup_class_index(zram->mem_pool, comp_len_old); /* * Iterate the secondary comp algorithms list (in order of priority) --=20 2.47.0.163.g1226f6d8fa-goog From nobody Mon Nov 25 09:24:43 2024 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (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 E78AE1DE4D7 for ; Mon, 28 Oct 2024 15:36:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730129801; cv=none; b=cX3TpCWIFTPusZogujaOr2YclXBjBXQQkXdcWqp71Rk2u5q+V7W9fcpve59KxXQ7Trsef2v7HyDuSCPWmEHRoOGttAbMQVUO7BmChnHyD/jKdPVNpMuGv2A+sy8yZZ5F1dmaF9Qp6pTYx67xqtmzAFTv/Lsr8hhPpRmrgGzVG6M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730129801; c=relaxed/simple; bh=h/sYbjBtUQyTXv3lWKehaN8u4xS1tuIY7Lx/bC7eiMc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZiCrPBpZVDWGESEiMIkkBc+DrTGs2TEgZoteJ0MRWHr8eAEDsSYmgSKjSAzxq7uEJqd5+mxtGysFv9K8em1wIFYP1xX5+1brk/pwhQ1IJ6vICz0CyKhatMcpeRZtoVUDX7a+Eg+K/oI0Y1nZgdpX7HQ98GBu/XJRl/xWujEuuXg= 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=Bn+/cViJ; arc=none smtp.client-ip=209.85.214.181 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="Bn+/cViJ" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-20c7edf2872so40088145ad.1 for ; Mon, 28 Oct 2024 08:36:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1730129799; x=1730734599; 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=vjToYipGNG7BRjJmYYUN95GYe0BFvqocrUKKBYihP5M=; b=Bn+/cViJWxET6LJzheGiMsk6+EErfCY376g66HKGh/DY8mAlEhKp8tQvRY7IQ3HvT7 ihef+OP3ddVYaU+IO0k3jXQKUp9+DtfSmQiHD3gnb1NVkEJhblcQ3BiuDgwAxYryzphi d4RyEDE+UJC9FcalJcmlFiXt1VmePKbj/1LT0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730129799; x=1730734599; 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=vjToYipGNG7BRjJmYYUN95GYe0BFvqocrUKKBYihP5M=; b=QXoaXKp1vnO/cdV3ytuoSLMjY4T8pqga9JBxgg3avEdgniiRzmDrJa1NfmfLvwFj8N m0V3A/+mcbVLHY7igFHT0i26c+AQKc+Lb9pDQ7W1MbcBBgx2KJDXE47bBTE/6gCgJxeu rYxJ9OzGvU5BJbE//hMFx4FRmtcMiNeh2egRWiw85XuyuPDZhUAmR5p3pM1BEtX3Ag8X 6TlhvzPBQ7kJ2TqxsUhCrlBgr7jWgOWvbQF1ExLSk1p+H0wOp4i2IVS1AYbxoc87XGM9 GxpIoyUTn8bF777zb5pEN/Apn1ztd1fKTcZRGXuvjZjtQ8FdBDcazvaGNOINecVKmPI+ syOA== X-Forwarded-Encrypted: i=1; AJvYcCWRpEnyJfdT2PHcKHhYzwf6ZP4J2jV4UP2pQUfSRGoKLHSSxXsPha11ihpjZpG0AAcQgLwe+wqxAwn+mq0=@vger.kernel.org X-Gm-Message-State: AOJu0YyeNlXHqbw1v6/9i/aurDAM1ztATZCuP6Ws/SE5eF2by4qaBc+t hqNjInIOyq2G7OZUOFGybg5joJ1XVb8yGjNemiSMPxDFFqM+7gaJPqzmEhy8u9UecDkwLY8cXd0 = X-Google-Smtp-Source: AGHT+IEhW49x326CUSg5pYX2QhNQvIE1pFpUgquKoiZ4DdCT0c/L21tirfRTum/rMTE3NF54rgjhNA== X-Received: by 2002:a17:902:f642:b0:20b:a73b:3f5 with SMTP id d9443c01a7336-210e85f5c62mr3889195ad.14.1730129799203; Mon, 28 Oct 2024 08:36:39 -0700 (PDT) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:f1f8:97e1:9c5b:d66f]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-210bbf4a230sm52148315ad.31.2024.10.28.08.36.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2024 08:36:38 -0700 (PDT) From: Sergey Senozhatsky To: Andrew Morton Cc: Minchan Kim , linux-kernel@vger.kernel.org, Sergey Senozhatsky Subject: [PATCHv2 2/2] zram: clear IDLE flag in mark_idle() Date: Tue, 29 Oct 2024 00:36:15 +0900 Message-ID: <20241028153629.1479791-3-senozhatsky@chromium.org> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog In-Reply-To: <20241028153629.1479791-1-senozhatsky@chromium.org> References: <20241028153629.1479791-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" If entry does not fulfill current mark_idle() parameters, e.g. cutoff time, then we should clear its ZRAM_IDLE from previous mark_idle() invocations. Consider the following case: - mark_idle() cutoff time 8h - mark_idle() cutoff time 4h - writeback() idle - will writeback entries with cutoff time 8h, while it should only pick entries with cutoff time 4h The bug was reported by Shin Kawamura. Fixes: 755804d16965 ("zram: introduce an aged idle interface") Signed-off-by: Sergey Senozhatsky Acked-by: Brian Geffon Reported-by: Shin Kawamura --- drivers/block/zram/zram_drv.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index a16dbffcdca3..cee49bb0126d 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -410,6 +410,8 @@ static void mark_idle(struct zram *zram, ktime_t cutoff) #endif if (is_idle) zram_set_flag(zram, index, ZRAM_IDLE); + else + zram_clear_flag(zram, index, ZRAM_IDLE); zram_slot_unlock(zram, index); } } --=20 2.47.0.163.g1226f6d8fa-goog