From patchwork Thu Feb 8 02:32:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengming Zhou X-Patchwork-Id: 198162 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp2643349dyb; Wed, 7 Feb 2024 18:33:37 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXCT4qJqicLnUWGAXBwZ5qrRCxn8PC0rRKAI+kXokp4tjb+YrZBL041NGhWdw50Ky1GNIi2tP+JuhVKvgk8x/jXeLNehg== X-Google-Smtp-Source: AGHT+IE1LLVGXRMatQ2N83T+3F/SlmkRXNMMOjP++FeD7TGVO6c4FDUD6cD6xTyi4/UE8rtCgInp X-Received: by 2002:a05:6a20:a082:b0:19c:a30b:89e with SMTP id r2-20020a056a20a08200b0019ca30b089emr4928338pzj.16.1707359617305; Wed, 07 Feb 2024 18:33:37 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707359617; cv=pass; d=google.com; s=arc-20160816; b=GSglegLwUoVP00CgPJ+AyAKwpQOoUtdeGR5dhoHZiKEahvwvCabrRF9+UwcdyB+hGQ ki7beduc4FFoShMdYfjQ5X1gYGwMQILFYQMCg0Ro6MRAgECSwfgM0TlRFsQgDd6TTb6y c2jLkqYFJR3gkcoFbIUF2z1DciB+oqysMbfLHCMjz2N+P4XWFN2yGW38I5zWbNnlIjof lRMz4bLu9NGhxvCqXKjFZD5DOzhlERf0H6IPO8GhyW7MF9IshdIStCx5xCAy73piqwlf st53OnuSqxfe9P0FfZULturmba7tEhMEgp4trIZzdJC9aKgx7Fj+E1bJPLjsvb/uhb7h rFRg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=YCEnBpcFOe2C77Vjk6R5fbEVUxas4awh0L6SVKgqthY=; fh=1mzAyjGmqOqc+fNQ9IHOTTWHL7y8B8Wcw8W1GHA6R6Y=; b=D7dWi4y9EPe42BLr3H+l2OJxrqwWiiqXZQEDCjejbK5bORRI/qudLDblQBDtgHipbF AqUOPcNQZ6cvhTsUvMnsY3mXhKwP2TFgd2VlglovAfJdaCZ5TNwli2bWbaWmconRduSA gOori35RR1lWvFoAWVw7R4+6zq58/Yb7q2k6UTjW4BxtFLGiXClZFEFCbbOfRpdsJ6ss N1T4363fTK99CLemfUohjUiU3yeuzODtYtrk5GUy14kWlhN3FWghOiQDAgiLswYYuk0V ZVWDqZPMolwqUTTHS9x305PPAMbCLAAt54mZJnRFlypVcBJ7SxTI3EvLCRbIl6MpFDrM FVTQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=weZui6S4; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-57389-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57389-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev X-Forwarded-Encrypted: i=2; AJvYcCVc3nrPX9t5UFtzw8dYHOtvM83mSQG3CG6F9Wp8Szk0xUe8qHK7EV0bRgr/Vct1db3+18jtZQYcpG6B/jIkNEAdIndiTw== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id y9-20020a17090264c900b001d06d5f9533si2744579pli.619.2024.02.07.18.33.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 18:33:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-57389-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=weZui6S4; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-57389-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57389-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 17E562872FE for ; Thu, 8 Feb 2024 02:33:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 314E71CF91; Thu, 8 Feb 2024 02:33:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="weZui6S4" Received: from out-176.mta0.migadu.com (out-176.mta0.migadu.com [91.218.175.176]) (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 1F7461D525 for ; Thu, 8 Feb 2024 02:33:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707359600; cv=none; b=P3o3XDNwYrXvuZiakyCjMU/5h4xuCPHT0oDTK4XHsnB9i4An6GCQmr9ToaBVFU7BYMa73r1M0WH6/CFNFHiH0zCIYuCsayrTOfYn3E4J8FKTyGa+OBT1Gi4niR+GhZMy4KBUo8+3sWUWo71I7GD/n25DuMxm7N4LadKRliLd8Cc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707359600; c=relaxed/simple; bh=vtpZ0m9AT8C+oeZBqgjv+QOJtFQz8dCFsvLGUGtbHRc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=pbLeIqoa6GdGIEmjGiHvipN0QDfNLOd4rx9dc5EqcvydVEOBpf8MHgOMXogrT5pUJB3b6NhGp7CqjOr79k+Mv7inaOoYEu8DQkJ+mNtklM3Qsb9GoTGNRHP3RfceY4mW0ILBcwL509VvtLfk6oHS5tRepeUze9nt5KhX2r3cNIU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=weZui6S4; arc=none smtp.client-ip=91.218.175.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1707359594; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YCEnBpcFOe2C77Vjk6R5fbEVUxas4awh0L6SVKgqthY=; b=weZui6S4T5IvHb+TGoDKMyuF0wqgoxEl+MwiUCXhxT0Byj4eY3WO+9hTkCOHADRHRPdAVB UAuJ7a1R632aAgbm3fe4L57GphGBpIK2/1FzbA8KfdBeE/MTAMk568fpswQFaDvDEjISCH VGiR5eGWY7km86874ZBREE9N2wQx8rw= From: chengming.zhou@linux.dev To: hannes@cmpxchg.org, yosryahmed@google.com, nphamcs@gmail.com, akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, chengming.zhou@linux.dev, Chengming Zhou , stable@vger.kernel.org Subject: [PATCH mm-hotfixes-unstable] mm/zswap: invalidate duplicate entry when !zswap_enabled Date: Thu, 8 Feb 2024 02:32:54 +0000 Message-Id: <20240208023254.3873823-1-chengming.zhou@linux.dev> In-Reply-To: <20240207154308.bc275f3e72ec1c1fd06cf5a2@linux-foundation.org> References: <20240207154308.bc275f3e72ec1c1fd06cf5a2@linux-foundation.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790296318278205967 X-GMAIL-MSGID: 1790296318278205967 From: Chengming Zhou We have to invalidate any duplicate entry even when !zswap_enabled since zswap can be disabled anytime. If the folio store success before, then got dirtied again but zswap disabled, we won't invalidate the old duplicate entry in the zswap_store(). So later lru writeback may overwrite the new data in swapfile. Fixes: 42c06a0e8ebe ("mm: kill frontswap") Cc: Signed-off-by: Chengming Zhou Acked-by: Johannes Weiner --- mm/zswap.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mm/zswap.c b/mm/zswap.c index fe7ee2640c69..32633d0597dc 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -1516,7 +1516,7 @@ bool zswap_store(struct folio *folio) if (folio_test_large(folio)) return false; - if (!zswap_enabled || !tree) + if (!tree) return false; /* @@ -1531,6 +1531,10 @@ bool zswap_store(struct folio *folio) zswap_invalidate_entry(tree, dupentry); } spin_unlock(&tree->lock); + + if (!zswap_enabled) + return false; + objcg = get_obj_cgroup_from_folio(folio); if (objcg && !obj_cgroup_may_zswap(objcg)) { memcg = get_mem_cgroup_from_objcg(objcg);