From nobody Mon Nov 25 10:16:35 2024 Received: from mail-ot1-f54.google.com (mail-ot1-f54.google.com [209.85.210.54]) (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 4D1E41FCF66 for ; Mon, 28 Oct 2024 07:35:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730100947; cv=none; b=mIUWnSENNAitGdruM8phHe9VZvnajXppUfLBvrRA975iZIkW9FTmZXsepjY4V0rAPYfmiNvdKu4TmT4bFYfD9pM2BkALaQI7eKGi99MufZOPa0pBu3wRepu+bpQPUMBjUeWIcLIM0y8mQxawD1DngeicJOe26F8l1cN2JgCoJqg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730100947; c=relaxed/simple; bh=5C6DBvGmT5i07ri7JujTGzVFRrILdJa6VrgjkTKYFNg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=q2L+1DWyTyHkSmaUax7C41mvLsfw79l5dnuKzLpL6M7bl6P9P5Z+SoPY6xJdauLZy63mViBqcXd8SDT8kw8P1iLqwbX7YWzjnQ09E/VfGSDwd+cTxaM2rXDKTD6JkFt1bIw9aPkNvS/8GcmQIsQXvlT2aa3s3JzbeVrV7yRixF0= 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=QMRcfsK2; arc=none smtp.client-ip=209.85.210.54 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="QMRcfsK2" Received: by mail-ot1-f54.google.com with SMTP id 46e09a7af769-7180ab89c58so2033896a34.1 for ; Mon, 28 Oct 2024 00:35:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1730100943; x=1730705743; 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=hmjWQcwWRYj7eMjpIQsNdFdyWK14BHSWWqmxxEvL6kM=; b=QMRcfsK2YU4C+L3QJw6vY9RVwI/Pe1Li/enY2K4momtuFTgmARd6CkQjtudtYlbbZP P7Pt42gUmGzWxNefjVWBDxdL/IOZMXVSCiZYuUkFxXfwssJEsFRFD6V3ADPWK9NQDjN6 fYLwVMvyCInIGTZiUgXBx1318oLAk97SPLKNI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730100943; x=1730705743; 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=hmjWQcwWRYj7eMjpIQsNdFdyWK14BHSWWqmxxEvL6kM=; b=WewLe4Djp19p+x98pjbDJDAYWgjV8Ner93qwu3blk9t+xT7uaRFkFzBOqR6Uttt7Xe k6rtu4xOkuXGkNocNN2vxO3sK8WHbTV+O5mv01JPyNtwpeBpg8ooJ2I8csFK7+9N9EJV Xspl+8MhbISt/GXYZow2pz1pPqTlIPEBF3KSNu00gVT5Ir5wCZM9htOi+zj0t0qN/WAR +K6mt47rq7spAa8KQLzcFt2JP3Vq2JdUBqqiTS487gHpd/pkdg7K+f305MrBqXM8m2qg lQ3ntXPUbTo1lIlFy9igLmj+bKJNeIhtMsqbUlqDShp94BN7/GHnHzdTQeNwHmqPd+sk WPzA== X-Forwarded-Encrypted: i=1; AJvYcCVmJh7cTHF2qNkFJ394AK8Hkblu+/Esseouv4k9yiaBU3b8GmtdmutK6iQF/lt6zaP/J+U66qFR/1KAIu4=@vger.kernel.org X-Gm-Message-State: AOJu0YytqtEhBRLtcSadcSltlP/8Q4tP37qNBs2VrTvriJuOGy485MVw frWDSs8rUZPm1pMHysRxmX5x6oysjtWvcAKNJQ/8X1ztzmu74wZ8U2dsQubfc2hVqKcCNmGPgzU = X-Google-Smtp-Source: AGHT+IG4oFx85VTTOQd9EbtUPk0T6vWbtu4r9HKqH9g2BWUweVvxM2LtSpJdWcbLGASiu3ipiopbZg== X-Received: by 2002:a05:6830:4194:b0:718:787:b416 with SMTP id 46e09a7af769-718682801d0mr6096180a34.16.1730100943210; Mon, 28 Oct 2024 00:35:43 -0700 (PDT) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:f1f8:97e1:9c5b:d66f]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-720579360f5sm5131189b3a.88.2024.10.28.00.35.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2024 00:35:42 -0700 (PDT) From: Sergey Senozhatsky To: Andrew Morton Cc: Minchan Kim , linux-kernel@vger.kernel.org, Sergey Senozhatsky , Shin Kawamura Subject: [PATCH 1/2] zram: clear IDLE flag after recompression Date: Mon, 28 Oct 2024 16:34:57 +0900 Message-ID: <20241028073529.1383980-2-senozhatsky@chromium.org> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog In-Reply-To: <20241028073529.1383980-1-senozhatsky@chromium.org> References: <20241028073529.1383980-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 entires 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. Reported-by: Shin Kawamura Signed-off-by: Sergey Senozhatsky --- 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..764c5b79b42b 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 10:16:35 2024 Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) (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 B4F99201271 for ; Mon, 28 Oct 2024 07:35:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730100951; cv=none; b=q3QXp1s+F1JOBFimm6GR7Z569XoGUewMOzO0Th0tpYMQAek78vdb8xMKLtW+ixPKMsLlmYYGNhXK0aUtYgRt2XpNZMrpnw18vtKxTf/XOCcJ7xfClKqngk1W0Pu44OWR+PQizk12JT4ZaASIukJWbS9LJY/llkKrki0qU8IU3ag= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730100951; c=relaxed/simple; bh=7WhDu8mPAasUOn/jj+GA9KHptAyrb2IdX+xOjw7cWGE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Co96lAmpeBR6A6c3gKILotlcYJ7hTy8rCwXiS4pnXluX5cl7H9TPTG2hcE30bRB3XIUdwVi5pBgwGScG0qWwh8kcl5cxu0xN7F+VTBQM/CBVXXe4Tw91T+WFlALTDvBHIl2H/O5bk2By9X1VrkNCOsYarSV3mX7xlMGUGpcLjTE= 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=LTkK1sVv; arc=none smtp.client-ip=209.85.210.178 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="LTkK1sVv" Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-7204dff188eso2458341b3a.1 for ; Mon, 28 Oct 2024 00:35:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1730100948; x=1730705748; 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=x+EhFv+UYwGBfkV4RUwC0LMN5UJxUbHPj+o8inaBXUc=; b=LTkK1sVvn9y5PrV39R2wNK/sGx7MRK1xpXaPVinDIUkwtR0554mkVpp0pa9g52Zf4A ygagoMdGxgNdnN0C7KomOYAqU0noS59mlwmOvr/4ANVxmBQ7FJIxwbS+4wE9SXRMbOua WyPx9A+XWr7i6a2/0DmRbS8p2A5XOyKruAuk0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730100948; x=1730705748; 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=x+EhFv+UYwGBfkV4RUwC0LMN5UJxUbHPj+o8inaBXUc=; b=t4NNCerQ2nktYWjrnnw5iZ02eDMlcydL+dFK07XE9nU1PlCXnuV/0/p2SXC+50zBCG n9sz4/oJIbzvONl1xQwp4wIN50IJOhtcoshSkssUdNtuZKTEOI+zy4S9gs0CIaErWaXJ MXNxbup2BsKSSzhDTtB+grpm0O/19PE5vNdVCls7us4xYCBLg4+cbv3zz5nfqEPiy3V8 tcdIUmhra52e54RgkbiqNApvE1Bhl7vYubHZvtjd4Ti0kPwkFht0YGBw1pIbeHCCwRUy iWuZDaPZoiGIxgav3muWjmgJ4OalP4wEBAiqwJKL0P8Jz3Kc2F8uwvKodwGrvRfBjIYy NWpg== X-Forwarded-Encrypted: i=1; AJvYcCXbWo1SqDhQfj727gKc1LkYPlnwZeUCAVFEm11p4lyKkegXebuBOTYbe2nLEWbjJ8fpFFiDTXVRJ+neUK8=@vger.kernel.org X-Gm-Message-State: AOJu0YzzVuofeRmP7bHi049w2l4QtcsvmGkBnd5l84Rykg2bfPM59F6b m5kpB5eSo5ViV6sHEdRUK457zxVKLZMYUi7v2mymsh7wLEHT3j4Ic7Mf1fseAg== X-Google-Smtp-Source: AGHT+IHWPjPq1Gk1zKDED36EHV354uMSQFNpddiQ+1ZfsoQdyzCivLoYxafq+XY7jMjO/pvMCL6phw== X-Received: by 2002:a05:6a00:b81:b0:71d:feb7:37f4 with SMTP id d2e1a72fcca58-72062f4bebfmr11467339b3a.6.1730100947969; Mon, 28 Oct 2024 00:35:47 -0700 (PDT) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:f1f8:97e1:9c5b:d66f]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-720579360f5sm5131189b3a.88.2024.10.28.00.35.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2024 00:35:47 -0700 (PDT) From: Sergey Senozhatsky To: Andrew Morton Cc: Minchan Kim , linux-kernel@vger.kernel.org, Sergey Senozhatsky , Shin Kawamura Subject: [PATCH 2/2] zram: clear IDLE flag in mark_idle() Date: Mon, 28 Oct 2024 16:34:58 +0900 Message-ID: <20241028073529.1383980-3-senozhatsky@chromium.org> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog In-Reply-To: <20241028073529.1383980-1-senozhatsky@chromium.org> References: <20241028073529.1383980-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 Reported-by: Shin Kawamura Signed-off-by: Sergey Senozhatsky --- 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 764c5b79b42b..d3b1c1bfaf18 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