From patchwork Thu Jul 27 16:22:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Weiner X-Patchwork-Id: 13330363 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 19448C04A6A for ; Thu, 27 Jul 2023 16:23:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9E9666B007B; Thu, 27 Jul 2023 12:23:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 998EC6B007E; Thu, 27 Jul 2023 12:23:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 79CBC6B0080; Thu, 27 Jul 2023 12:23:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 6CBF36B007B for ; Thu, 27 Jul 2023 12:23:51 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 42508C0608 for ; Thu, 27 Jul 2023 16:23:50 +0000 (UTC) X-FDA: 81057913020.01.10574E9 Received: from mail-qv1-f42.google.com (mail-qv1-f42.google.com [209.85.219.42]) by imf28.hostedemail.com (Postfix) with ESMTP id 78BE5C0013 for ; Thu, 27 Jul 2023 16:23:48 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=cmpxchg-org.20221208.gappssmtp.com header.s=20221208 header.b=qNto7iFR; spf=pass (imf28.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.219.42 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org; dmarc=pass (policy=none) header.from=cmpxchg.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690475028; a=rsa-sha256; cv=none; b=NsyWfxWzMvT3XgeFxfTuRZc0rmtTu3HdoRr0BNCJntRvAXtNjRxYSlGwRh2Obs+EnWYOaK CWVIY/85V4uk5d6cnSN4Zdf8QG2hhh1PiN5gQCSkV6hr93ZXDcvkSDi641YpQwoZ2pBTM+ 2pCMInm/7/SqbfSnixgxIDhVc+mA+oU= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=cmpxchg-org.20221208.gappssmtp.com header.s=20221208 header.b=qNto7iFR; spf=pass (imf28.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.219.42 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org; dmarc=pass (policy=none) header.from=cmpxchg.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1690475028; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=V4WqUpKSmXvGR1M+fIFBD/JXbqB10oByq1yE4svjvKk=; b=g81Kn/0cZkvSl7I8I6bkuiE0Svqf1dkPNbqcrNqlEK0WRJ0QBFppHm2xfgmxfDGHQWUDj9 WvpOJLlL9GVj/dLzUGxoUfCO2+HaK7oxAUpcbyHtUUMIIyjZY6RqPc04nFL2VjXxiPoBia blgRT3ilUyUlTfejRf6fqMjCfbZlroA= Received: by mail-qv1-f42.google.com with SMTP id 6a1803df08f44-63cff46ddb8so11219576d6.1 for ; Thu, 27 Jul 2023 09:23:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20221208.gappssmtp.com; s=20221208; t=1690475027; x=1691079827; 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=V4WqUpKSmXvGR1M+fIFBD/JXbqB10oByq1yE4svjvKk=; b=qNto7iFRrzOxESe9fv4KXfCHzvEpqtjq8zKP6G+FHbxknRdRQyruOVS/C6JV+mmMvY +/rWcuLtgsi9NpP8YgxSITdR8dLpz4uKoeqElIiF8b0B/yCc6cd24rpY8lAY+hhsYZCj nuB6QswJUQX/5foZILCFhUOhAhxdSuiL48uJ9//IKXR5DiNmxdHTFCXSUib5GYajdUMC BZX4uCMOPsz4wm4GIKg0pa4I8kmWdNTYMyl1/gbCDWOOuOnTP6xcrq/91YCR699FRai3 uD/9XMZLJawLy/Dvhly73UgklITjc1pFzK3nbx3xqKttOiuUSz1YJoFeSUFYn+hyS7zH wtww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690475027; x=1691079827; 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=V4WqUpKSmXvGR1M+fIFBD/JXbqB10oByq1yE4svjvKk=; b=XdHKizn+GNPo3F0AT0+yf024l3WuMll3v72H1czBpruu+1IZkEKrkjh1QdVI9njI3t P/ITsmhoQMQ9sGa19v6TsIMjuLjCDN/deC2W9qB2UPIU8Eb7am/5S0ffPcwW6C8R2g60 H3iTNiFuEBYh8MdotYboRhE4re7hE7C1jQXH56+2VLXVvfAUqLkSfMWHJoaeeMaKbOiE ldoZfhG/1TPNSJId8CXXF2mU+PHtBCTwGClFrfF38zGrE8dNwCbxfnkcB8t0mXOCziS9 pufyq4wPRsEL4VygeWxfXUqrJc7y0Uoz+3J864os7GEiXIAbXhmVKzUFSfaDcw/TfUZt ZbPQ== X-Gm-Message-State: ABy/qLZwSknbdeBZl/DobzzERkdoU4mm3S0bDoNC8HcXzMGCs2auXhoQ vVHGc5kN0lEmbytWjFsGQUySDg== X-Google-Smtp-Source: APBJJlEf3a+4nlFwkjw+loMNGiZ+A28qMm0A+SS4AICZPLdvjR5GWT3rErmZtaoO4i263nli3LNnqA== X-Received: by 2002:a05:6214:d6a:b0:635:dbab:a588 with SMTP id 10-20020a0562140d6a00b00635dbaba588mr850652qvs.16.1690475027432; Thu, 27 Jul 2023 09:23:47 -0700 (PDT) Received: from localhost ([2620:10d:c091:400::5:ad06]) by smtp.gmail.com with ESMTPSA id s18-20020a0cb312000000b0063762ab2f90sm527074qve.83.2023.07.27.09.23.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 09:23:47 -0700 (PDT) From: Johannes Weiner To: Andrew Morton Cc: Yosry Ahmed , Nhat Pham , Domenico Cerasuolo , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/3] mm: zswap: use zswap_invalidate_entry() for duplicates Date: Thu, 27 Jul 2023 12:22:23 -0400 Message-ID: <20230727162343.1415598-2-hannes@cmpxchg.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230727162343.1415598-1-hannes@cmpxchg.org> References: <20230727162343.1415598-1-hannes@cmpxchg.org> MIME-Version: 1.0 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 78BE5C0013 X-Stat-Signature: p31ogwoz1wjc7wfcj1ppg34n4xuqzqy1 X-Rspam-User: X-HE-Tag: 1690475028-985707 X-HE-Meta: U2FsdGVkX18PG/XglO4iBzJdaX0QxScTh7wVlw2wDs956v5vMMduiZ9flU4cJjwOr9STcU4KN/R0VYvAfo402u0A36aXRWY3/y/XtwKcbFHOb8LU11+By+EaBNxuepIB88NVKvT+2osyjgIO2z8OMe6g0js5hX5fiXW2v6+mgopOBULaRDTcs7KA+oTI8oi1pemILbi1bUnO2MQBpI5Lk1lt60KqucuT993jnaxRpNopreVTQuond8FG+ddZBZgw+xZRCrLyyLjj6QBC7SyWA3aZrmjJFGzuWPrKZdLp1z3uSxJ5BmX1gDcQ6EUUQUdsHIX7jQXESObfbqlq6EtCHTwtaDK0+8eViki4Inzjg8zveZB6XGmK3GedhmT3rI5aDQK60MqNRLgDLfYlbzUyUmSU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qVR52vBVXxn72/D/ZEU0AKxZFEwuYmLpbugUlM4Q8J X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Minor cleanup. Instead of open-coding the tree deletion and the put, use the zswap_invalidate_entry() convenience helper. Suggested-by: Yosry Ahmed Signed-off-by: Johannes Weiner Reviewed-by: Yosry Ahmed --- mm/zswap.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index 583ef7b84dc3..e123b1c7981c 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -1344,9 +1344,7 @@ bool zswap_store(struct page *page) spin_lock(&tree->lock); while (zswap_rb_insert(&tree->rbroot, entry, &dupentry) == -EEXIST) { zswap_duplicate_entry++; - /* remove from rbtree */ - zswap_rb_erase(&tree->rbroot, dupentry); - zswap_entry_put(tree, dupentry); + zswap_invalidate_entry(tree, dupentry); } if (entry->length) { spin_lock(&entry->pool->lru_lock); From patchwork Thu Jul 27 16:22:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Weiner X-Patchwork-Id: 13330364 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7ECFBC04A94 for ; Thu, 27 Jul 2023 16:23:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F19C46B007E; Thu, 27 Jul 2023 12:23:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EC9456B0080; Thu, 27 Jul 2023 12:23:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D43226B0081; Thu, 27 Jul 2023 12:23:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 9B18E6B0080 for ; Thu, 27 Jul 2023 12:23:51 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 563631A10D1 for ; Thu, 27 Jul 2023 16:23:51 +0000 (UTC) X-FDA: 81057913062.17.2B0A634 Received: from mail-qk1-f177.google.com (mail-qk1-f177.google.com [209.85.222.177]) by imf12.hostedemail.com (Postfix) with ESMTP id 6318E40013 for ; Thu, 27 Jul 2023 16:23:49 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=cmpxchg-org.20221208.gappssmtp.com header.s=20221208 header.b=t1KwP89h; spf=pass (imf12.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.222.177 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org; dmarc=pass (policy=none) header.from=cmpxchg.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1690475029; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=g6xeXNZ7MmGxs9MCe+qdgeE1O4rbj13SYexzHrnrzbc=; b=2IJoYoL6IY3PfadkdVloAq0WmTUw9MmCoxVDrn1Pdy8ht24xjNIPILmFUhH3eOjz0U6bOt XEQguu9bBzfHlKdsp+5STp4TTH3AGGGbO0HTNccyoLV8LxgjYhdJTfNCiP2gpcRpEl4osG HInQhUE+aF7lUYbN0aw6RNInJ76ww9Q= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690475029; a=rsa-sha256; cv=none; b=JglWG0XbvCiE+yxPufeB7DuCHuc4ukdlOaP+jKm5WnR+GqeKjisiOu7w2cddibFTLbRvJx ICQgQi98DMCnEdn0UC1xfoGVD8CDABFmdJIx2QElP5o9gZsO6GVB9CJ3td43d5ZKrCtkKH 3FJH9XLkV2YKgK7QgtOhI6LUOQvabyY= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=cmpxchg-org.20221208.gappssmtp.com header.s=20221208 header.b=t1KwP89h; spf=pass (imf12.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.222.177 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org; dmarc=pass (policy=none) header.from=cmpxchg.org Received: by mail-qk1-f177.google.com with SMTP id af79cd13be357-765a7768f1dso103176585a.0 for ; Thu, 27 Jul 2023 09:23:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20221208.gappssmtp.com; s=20221208; t=1690475028; x=1691079828; 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=g6xeXNZ7MmGxs9MCe+qdgeE1O4rbj13SYexzHrnrzbc=; b=t1KwP89hpnwg0NYhi1k1hMQB/3gQRSOWAy1zvJ7pueqsOL6lMhlnGs29bj9q3R7ed2 5TGX5AbXfBOKFrqHxQDMSSGFph1MqS/IIURzJrYtuyq5DJDNQSlPgyx6HKbsJCFrgyMs etJArP1Qo7jM62rDTvet0BjBWc9wIdYpICMtw4B6tf9ouYzlHD0s6flS1M2mtpzmsp3P Tg1utgnTtVxz7Ck+6yn7HuwnCpOeXrrLAxZP/B7IVeVZfU45bb/Ad1ZLt/8jOMuY4acP s9Ljx+sG57pZI23evKzyyIa5rmfHvAJu7nn7DIh1eF/R8VZWmTH5gwWvPzEBnh8xunF7 LIIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690475028; x=1691079828; 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=g6xeXNZ7MmGxs9MCe+qdgeE1O4rbj13SYexzHrnrzbc=; b=QXLD1hizssBaTyGO8ZQ+ZGpBmXeJIF0yNy+Jt2pmMGm0hFrEDi6llr4T9tZqtWZXlU 5+1OHr0+ZOZCshE7SnG0hU5dVTRZda3NUzyq35fhxh+5CUsvCc8EM2/sNcIgfqLuYwsw DIumOrF1umH4pqlIaRoOa/wjZEo8/wM33VeaeUzsmDP6v6flOLZd51ZzMEZ1H86x+um+ SBihQ3ClK4WxphiPe6Sj7CYjeGaF1OzcVHbxRwnYWwIRR/W/hYr8tMxoTjEx8RSzpAQa JoH5YuthyyASEoI2pAQkKtflUkZkDL6JyN3LmWptZrkjbKkyCG5gmWDasmEazJXvodOQ WwTw== X-Gm-Message-State: ABy/qLaG75sRUo0jJ5n4e5M+fF+VE6+34SRsaCUBwKuITJ+i+056GWPr BpFKWmF1gf5VHDUNkcRTr5tuhw== X-Google-Smtp-Source: APBJJlHsm+mf07gWGmI92coTtdUdEWEsIic/VUEsa+GtEeTjX9B1tCutvPQZueF/jzY9ZsnEbTyiCA== X-Received: by 2002:a05:620a:ccf:b0:768:b0c:e4c1 with SMTP id b15-20020a05620a0ccf00b007680b0ce4c1mr434494qkj.27.1690475028555; Thu, 27 Jul 2023 09:23:48 -0700 (PDT) Received: from localhost ([2620:10d:c091:400::5:ad06]) by smtp.gmail.com with ESMTPSA id p13-20020ae9f30d000000b0076816153dcdsm505827qkg.106.2023.07.27.09.23.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 09:23:48 -0700 (PDT) From: Johannes Weiner To: Andrew Morton Cc: Yosry Ahmed , Nhat Pham , Domenico Cerasuolo , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] mm: zswap: tighten up entry invalidation Date: Thu, 27 Jul 2023 12:22:24 -0400 Message-ID: <20230727162343.1415598-3-hannes@cmpxchg.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230727162343.1415598-1-hannes@cmpxchg.org> References: <20230727162343.1415598-1-hannes@cmpxchg.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 6318E40013 X-Rspam-User: X-Stat-Signature: eqbqjaims6bu8gq6i1rybcfa5ehwf5dz X-Rspamd-Server: rspam03 X-HE-Tag: 1690475029-114141 X-HE-Meta: U2FsdGVkX19o6xWCQd3a6m64it9uZOpVn0B2UsRd9wlKM16BAu2YvM6JDbzGvA5ENQcJ80fwozsmu2uf5iGRUzoUMBwJpldtXts9vDAj7Mw/ur7LyLfzaMVHqNSL44RyREiHDHEktNrtYBnhano1lMzygUJU1/VcNcNdJaR2R3MK9t4u0oIpzi+0bTIdUOA5vgB4gB+Vijjki8g+elLWxOZDQeNggTq+unXnAfkiNTKd39kGoxkivmRPRgGqcYotsYm6OfE7pd0/+BVynwgl2Blg38MfKL3pxtsqZeQwRcBCWJzsgZ20SPaxVpNpwuilHtSd5cxBaxNR7X+toqZH5CRWcz1eK/H3/ALuvBE0fDgMggHn6JHTAakcnwvKfsRFIqDDkm0F2YocL3KUD1hQys9c8O76CVjpMrNGwDFFJg+qhZVYYCwthUndM6le2WGumOB7mnBKUPZunsArRGMoDz8skO4wByCTEd1awHSOEGLCen4DVe+psCM5WwsRckqhlJ5exYDS0Dyitvg+HxwWUB1RrZ+m8yXl7QakaWKkyQjApseupY85weCH4biMfa0A+zex/DpaJ+gH5y3oNYGjWC30JX4Q6DahAb3IbL9wiopYYUZjTogLWmcGFB1Z6KihjRdhmKgOXL2I0J9OGEEcuNwMb7yixcaG+Qq1zlycGmnqO2KOz+pr7P9CdSKq4WUYeuAD7USt/ihNOD94xbMkIXsOgblhPXsgt0ntPRNj4EDSNh7DxBOkLl6HQOdl3NFOrvNDN/Wmf3I3vHDZLSnqV8T/GLUCP680JFFcLQkZlEqm3YLjlo+zk3EMyPVTsniO9qhLpb6i+jsRcSG7BkwA2I/uAxKYzQaBdJ6ES9tTGtDiofNm/2pl7orFlp3aDiWL/v4a+aul7A9KBQIp57Znkjr7tfhEmR8v6kT+3NtMDDvFjt4mm5G4qGU6lTGdeIUoph9vYQsb3rLVYl/mx2v ew6eZ8Z2 NYIXiaskkvcq2QXnYTnCyTOwes3yMrBSJrdFBxtk628Kb1xAyu6SInVXy1gB0IpLovCBoN+VP7+eFQWn2RdZwbCRGzehiArYi94kYRXf5sMFXcfEqBXebJPBKKE61LLATVavoIL/sb2WEjFKNU6/9cR/21DCD2+IND5qyNhqjOsiyLIKK00rSlVBwMc/uJmSJqLWH6R0Qn3lJPV1bM81e19xpt539IJn2Wf1c2GNoAaFuC5A/uoXPGs+W65Pjjv8MPJmnDQK0HhCvKycQPh5hp2btxlHQp3T60NZsEU57HLhriUr/UL8PjtfJQJFgV+wqQkhDdgxQz92bMlUkO0a+NksLgCzw0gXn0cUXQ7AExJQUfrQrpK+sfyicXwZBfZO4pl6CDI3CASKOZWjUVj5Z0g5fEjHvL7GVUjEtGJ7RrQxryBlq90kV/6OTplsS78a8SdEcdPaWF8kwIhcAlf5DAs7IHw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Removing a zswap entry from the tree is tied to an explicit operation that's supposed to drop the base reference: swap invalidation, exclusive load, duplicate store. Don't silently remove the entry on final put, but instead warn if an entry is in tree without reference. While in that diff context, convert a BUG_ON to a WARN_ON_ONCE. No need to crash on a refcount underflow. Signed-off-by: Johannes Weiner Reviewed-by: Yosry Ahmed --- mm/zswap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index e123b1c7981c..e34ac89e6098 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -402,9 +402,9 @@ static void zswap_entry_put(struct zswap_tree *tree, { int refcount = --entry->refcount; - BUG_ON(refcount < 0); + WARN_ON_ONCE(refcount < 0); if (refcount == 0) { - zswap_rb_erase(&tree->rbroot, entry); + WARN_ON_ONCE(!RB_EMPTY_NODE(&entry->rbnode)); zswap_free_entry(entry); } } From patchwork Thu Jul 27 16:22:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Weiner X-Patchwork-Id: 13330365 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 60CA7C04FDF for ; Thu, 27 Jul 2023 16:23:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 640BF6B0080; Thu, 27 Jul 2023 12:23:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5EFAC6B0081; Thu, 27 Jul 2023 12:23:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4698C6B0082; Thu, 27 Jul 2023 12:23:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 2E7826B0080 for ; Thu, 27 Jul 2023 12:23:53 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 09874B168B for ; Thu, 27 Jul 2023 16:23:53 +0000 (UTC) X-FDA: 81057913146.30.E993541 Received: from mail-oa1-f45.google.com (mail-oa1-f45.google.com [209.85.160.45]) by imf24.hostedemail.com (Postfix) with ESMTP id 1D8D3180026 for ; Thu, 27 Jul 2023 16:23:50 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=cmpxchg-org.20221208.gappssmtp.com header.s=20221208 header.b=ZM6siFmc; spf=pass (imf24.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.160.45 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org; dmarc=pass (policy=none) header.from=cmpxchg.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1690475031; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=9xKvUZAC/PcwLq4Mn3vj+fKTV8KIinkTpyaNVs2EYco=; b=US2PttDwDnG1tjr3UtfwHQhjzJTTpsEUxUN5OIk3CGbYBvILCsGx0Jj2C/9Mr1F9Lbd0LG fRL+gI81pxIw5wKE4sK9hB0g671PVJvHQIoh0146+NeQUwfEifKNXAZ1IMCNQNwNGKFw6G ggNjF2xprDoq320xWvdTVBwwA3UPgI4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690475031; a=rsa-sha256; cv=none; b=W4aZWMtW92EP4JS8aHez39rmRjYxTSC+BuEG0e1sq2u6ZnKSo2TBEi58Y102aKEUAlDqS0 c8n7gXHGLknE7xm56M2aEiWXpPi+f7J6OPzWjKBgH6FScGiCbeiFnl94QVnyTXvsqv3NVx XtH+0zaR8l44Se6AxVOnxAxeeQqaiko= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=cmpxchg-org.20221208.gappssmtp.com header.s=20221208 header.b=ZM6siFmc; spf=pass (imf24.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.160.45 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org; dmarc=pass (policy=none) header.from=cmpxchg.org Received: by mail-oa1-f45.google.com with SMTP id 586e51a60fabf-1bb5ce75e43so808469fac.3 for ; Thu, 27 Jul 2023 09:23:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20221208.gappssmtp.com; s=20221208; t=1690475030; x=1691079830; 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=9xKvUZAC/PcwLq4Mn3vj+fKTV8KIinkTpyaNVs2EYco=; b=ZM6siFmcEpT22TCKTBC20dzc2m3blvxe+fV7xBWQ5V/W+B8u2sR51MOrUVn0oe9H9r p3SLhh1gZWJjZ41HzedjMK816QkKQbpYiYtUKKn82b4C9atpUvnedHQf+0jDaBf3j77Q tJOmmfcGqfxttLoXBrJCFjVGF8sW0Q572CZ16Ht4fa8chGgIb2Jw6/K1cT/xLpr/JkM5 r3iilsyakH1SBZfuqYO5hwJQP1WMnOayvcj1j6HQ6bVFu643j76ZwjEXMY25LUTF4q1y UHe6Ly/6TR285I3CJYLC6dr76PLwRPjFwQFb634smNKQW1NJjIxSKuDdZhMfZRorHggK kV/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690475030; x=1691079830; 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=9xKvUZAC/PcwLq4Mn3vj+fKTV8KIinkTpyaNVs2EYco=; b=IxtsnzLbTdTVmbEmnMkSLc6jdRoBycV3YEiEhs/8BESNnKTdllK69fyC4jtc0jyUeU j8YE03emO8tNdkg4TmzpOWL6b5ZpAxIPMa6ZOROO0martR6utN3p6+7wIDOvey5RRcm0 sc2xZta8aIm8Q1b+vhDl0Q4Y6UntQaqmdZ1QL2l5Ir4m+ut88gmcrK8h9DQb47ko77AU T9wxOd0VyR3CJ1XoPvX+DiCwN3PmctTs9CPh2xhbocLwNU+ev9ZB14wJxiUj06Fc9sls INREZ0qfiOzH6w2YJdBt+VTPQv6bWVU+0zXFaMwuHmXkEg31cpZGNBBitLYHeBy1OQlE tzXA== X-Gm-Message-State: ABy/qLZ5FlI0T63L9zaxgXeeo16LQJ41GeelhBoZRilWSxufefQKwyLJ PzkTDhX79hAeyF5vIMG6kwsLNA== X-Google-Smtp-Source: APBJJlGe/1LwJSfSBsFM0E1SehZPQyy8thiIa1GfuOSx8pATP8cfV6nW9jnsPOBTG2/9/yJ+wCDfCQ== X-Received: by 2002:a05:6871:593:b0:1bb:5ef8:d606 with SMTP id u19-20020a056871059300b001bb5ef8d606mr3430099oan.41.1690475029900; Thu, 27 Jul 2023 09:23:49 -0700 (PDT) Received: from localhost ([2620:10d:c091:400::5:ad06]) by smtp.gmail.com with ESMTPSA id x19-20020ac87ed3000000b004055106ee80sm519047qtj.44.2023.07.27.09.23.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 09:23:49 -0700 (PDT) From: Johannes Weiner To: Andrew Morton Cc: Yosry Ahmed , Nhat Pham , Domenico Cerasuolo , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/3] mm: zswap: kill zswap_get_swap_cache_page() Date: Thu, 27 Jul 2023 12:22:25 -0400 Message-ID: <20230727162343.1415598-4-hannes@cmpxchg.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230727162343.1415598-1-hannes@cmpxchg.org> References: <20230727162343.1415598-1-hannes@cmpxchg.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 1D8D3180026 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: 5pzz5zi3yciuzw3oa6d1eq94u3hd7fhd X-HE-Tag: 1690475030-755713 X-HE-Meta: U2FsdGVkX1/iSt2PRGvjUHbV3qD5DjkhAW4kuSoaVm/bFGcbKkJCa92I0IVPbupnt/i6CUB4rns+s77DEG+R6xbgunOaKG1I68F7WpfvRdt0h8Px/hsofTDdlZoBVjiHAwEesEwEzzrcnEDnj8rbI9gzOEFRs65AumnnJXT5p1WWGOKFYhbG9kFxAcIDE2k9npgr7fWawifEX33Q6hxPfEme4pyjmlTPipz/9U4+E1dL9JlMvjaWLw5/ORx8MWSDqGW91lACgWbZtCRyOPqazmi1g3vU4aSrm58ZQpJDVt/uYSbXbVB200VpWcaSD+vo+7prIGTgGcCC9S/kKaydIwyEMGd7x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nVQ20pYsPQHVxbj44PLzlZDQUvaL7wh1QfFcZfVkvN6uxKfWcbr7yVBeTeCMBW5GAE99bmg7m7JbElIr13ZxW6Pl2j3RK8CNvSllfruiDxrfdeAJmVpZFIeW X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: The __read_swap_cache_async() interface isn't more difficult to understand than what the helper abstracts. Save the indirection and a level of indentation for the primary work of the writeback func. Signed-off-by: Johannes Weiner Reviewed-by: Yosry Ahmed --- mm/zswap.c | 142 ++++++++++++++++++++--------------------------------- 1 file changed, 53 insertions(+), 89 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index e34ac89e6098..bba4ead672be 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -1016,43 +1016,6 @@ static int zswap_enabled_param_set(const char *val, /********************************* * writeback code **********************************/ -/* return enum for zswap_get_swap_cache_page */ -enum zswap_get_swap_ret { - ZSWAP_SWAPCACHE_NEW, - ZSWAP_SWAPCACHE_EXIST, - ZSWAP_SWAPCACHE_FAIL, -}; - -/* - * zswap_get_swap_cache_page - * - * This is an adaption of read_swap_cache_async() - * - * This function tries to find a page with the given swap entry - * in the swapper_space address space (the swap cache). If the page - * is found, it is returned in retpage. Otherwise, a page is allocated, - * added to the swap cache, and returned in retpage. - * - * If success, the swap cache page is returned in retpage - * Returns ZSWAP_SWAPCACHE_EXIST if page was already in the swap cache - * Returns ZSWAP_SWAPCACHE_NEW if the new page needs to be populated, - * the new page is added to swapcache and locked - * Returns ZSWAP_SWAPCACHE_FAIL on error - */ -static int zswap_get_swap_cache_page(swp_entry_t entry, - struct page **retpage) -{ - bool page_was_allocated; - - *retpage = __read_swap_cache_async(entry, GFP_KERNEL, - NULL, 0, &page_was_allocated); - if (page_was_allocated) - return ZSWAP_SWAPCACHE_NEW; - if (!*retpage) - return ZSWAP_SWAPCACHE_FAIL; - return ZSWAP_SWAPCACHE_EXIST; -} - /* * Attempts to free an entry by adding a page to the swap cache, * decompressing the entry data into the page, and issuing a @@ -1073,7 +1036,7 @@ static int zswap_writeback_entry(struct zswap_entry *entry, struct scatterlist input, output; struct crypto_acomp_ctx *acomp_ctx; struct zpool *pool = entry->pool->zpool; - + bool page_was_allocated; u8 *src, *tmp = NULL; unsigned int dlen; int ret; @@ -1088,65 +1051,66 @@ static int zswap_writeback_entry(struct zswap_entry *entry, } /* try to allocate swap cache page */ - switch (zswap_get_swap_cache_page(swpentry, &page)) { - case ZSWAP_SWAPCACHE_FAIL: /* no memory or invalidate happened */ + page = __read_swap_cache_async(swpentry, GFP_KERNEL, NULL, 0, + &page_was_allocated); + if (!page) { ret = -ENOMEM; goto fail; + } - case ZSWAP_SWAPCACHE_EXIST: - /* page is already in the swap cache, ignore for now */ + /* Found an existing page, we raced with load/swapin */ + if (!page_was_allocated) { put_page(page); ret = -EEXIST; goto fail; + } - case ZSWAP_SWAPCACHE_NEW: /* page is locked */ - /* - * Having a local reference to the zswap entry doesn't exclude - * swapping from invalidating and recycling the swap slot. Once - * the swapcache is secured against concurrent swapping to and - * from the slot, recheck that the entry is still current before - * writing. - */ - spin_lock(&tree->lock); - if (zswap_rb_search(&tree->rbroot, swp_offset(entry->swpentry)) != entry) { - spin_unlock(&tree->lock); - delete_from_swap_cache(page_folio(page)); - ret = -ENOMEM; - goto fail; - } + /* + * Page is locked, and the swapcache is now secured against + * concurrent swapping to and from the slot. Verify that the + * swap entry hasn't been invalidated and recycled behind our + * backs (our zswap_entry reference doesn't prevent that), to + * avoid overwriting a new swap page with old compressed data. + */ + spin_lock(&tree->lock); + if (zswap_rb_search(&tree->rbroot, swp_offset(entry->swpentry)) != entry) { spin_unlock(&tree->lock); + delete_from_swap_cache(page_folio(page)); + ret = -ENOMEM; + goto fail; + } + spin_unlock(&tree->lock); - /* decompress */ - acomp_ctx = raw_cpu_ptr(entry->pool->acomp_ctx); - dlen = PAGE_SIZE; + /* decompress */ + acomp_ctx = raw_cpu_ptr(entry->pool->acomp_ctx); + dlen = PAGE_SIZE; - src = zpool_map_handle(pool, entry->handle, ZPOOL_MM_RO); - if (!zpool_can_sleep_mapped(pool)) { - memcpy(tmp, src, entry->length); - src = tmp; - zpool_unmap_handle(pool, entry->handle); - } + src = zpool_map_handle(pool, entry->handle, ZPOOL_MM_RO); + if (!zpool_can_sleep_mapped(pool)) { + memcpy(tmp, src, entry->length); + src = tmp; + zpool_unmap_handle(pool, entry->handle); + } - mutex_lock(acomp_ctx->mutex); - sg_init_one(&input, src, entry->length); - sg_init_table(&output, 1); - sg_set_page(&output, page, PAGE_SIZE, 0); - acomp_request_set_params(acomp_ctx->req, &input, &output, entry->length, dlen); - ret = crypto_wait_req(crypto_acomp_decompress(acomp_ctx->req), &acomp_ctx->wait); - dlen = acomp_ctx->req->dlen; - mutex_unlock(acomp_ctx->mutex); - - if (!zpool_can_sleep_mapped(pool)) - kfree(tmp); - else - zpool_unmap_handle(pool, entry->handle); + mutex_lock(acomp_ctx->mutex); + sg_init_one(&input, src, entry->length); + sg_init_table(&output, 1); + sg_set_page(&output, page, PAGE_SIZE, 0); + acomp_request_set_params(acomp_ctx->req, &input, &output, entry->length, dlen); + ret = crypto_wait_req(crypto_acomp_decompress(acomp_ctx->req), &acomp_ctx->wait); + dlen = acomp_ctx->req->dlen; + mutex_unlock(acomp_ctx->mutex); + + if (!zpool_can_sleep_mapped(pool)) + kfree(tmp); + else + zpool_unmap_handle(pool, entry->handle); - BUG_ON(ret); - BUG_ON(dlen != PAGE_SIZE); + BUG_ON(ret); + BUG_ON(dlen != PAGE_SIZE); - /* page is up to date */ - SetPageUptodate(page); - } + /* page is up to date */ + SetPageUptodate(page); /* move it to the tail of the inactive list after end_writeback */ SetPageReclaim(page); @@ -1157,16 +1121,16 @@ static int zswap_writeback_entry(struct zswap_entry *entry, zswap_written_back_pages++; return ret; + fail: if (!zpool_can_sleep_mapped(pool)) kfree(tmp); /* - * if we get here due to ZSWAP_SWAPCACHE_EXIST - * a load may be happening concurrently. - * it is safe and okay to not free the entry. - * it is also okay to return !0 - */ + * If we get here because the page is already in swapcache, a + * load may be happening concurrently. It is safe and okay to + * not free the entry. It is also okay to return !0. + */ return ret; }