From patchwork Tue Dec 26 15:54:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengming Zhou X-Patchwork-Id: 13504909 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 5D5CCC46CD3 for ; Tue, 26 Dec 2023 15:55:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 001386B0085; Tue, 26 Dec 2023 10:55:05 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id EF3636B0087; Tue, 26 Dec 2023 10:55:04 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D6D7D6B0088; Tue, 26 Dec 2023 10:55:04 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id C46956B0085 for ; Tue, 26 Dec 2023 10:55:04 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id A07B91A05C1 for ; Tue, 26 Dec 2023 15:55:04 +0000 (UTC) X-FDA: 81609418128.03.4755F37 Received: from out-186.mta0.migadu.com (out-186.mta0.migadu.com [91.218.175.186]) by imf02.hostedemail.com (Postfix) with ESMTP id C772380006 for ; Tue, 26 Dec 2023 15:55:02 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=bytedance.com (policy=quarantine); spf=pass (imf02.hostedemail.com: domain of chengming.zhou@linux.dev designates 91.218.175.186 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1703606103; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Fj6IXPbKxUdaaVKYr+IKMxSX4wMJz6sg9yd9pI3CwMI=; b=YLfYTbMuhPeCEMYVeiXJa/UQlh4HsMvH5PYQkJXfsSyqOFGlziTa4B2yLYZgqCIBN3b+QD /upBuH+xxgQmyg5lM2fKyPH9Qd7KRo2XtZXsKnvJACjQxS5YqB+8DkrMVt+Qf6smNLzWjo OkY4u+o8EOPMoaUFtXwqrCNle2AQ54o= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=bytedance.com (policy=quarantine); spf=pass (imf02.hostedemail.com: domain of chengming.zhou@linux.dev designates 91.218.175.186 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1703606103; a=rsa-sha256; cv=none; b=17Aq2JSrdsllYBz7kiHVhvfCFllATo8VqpOu8s2E5RIGHe/6Eeqxfe3Of2HEDp6sqB/GeF buf3hFJZ7DpZjb85VPJRrj0WeUC9nJpcNOkpgoFs1jS9DIo4U9VUm0gWmqwdZW01gsNNFP FNYCWzb3BqD24S4xoEs4Pbe9pt9f1iI= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Chengming Zhou Date: Tue, 26 Dec 2023 15:54:12 +0000 Subject: [PATCH v4 5/6] mm/zswap: cleanup zswap_writeback_entry() MIME-Version: 1.0 Message-Id: <20231213-zswap-dstmem-v4-5-f228b059dd89@bytedance.com> References: <20231213-zswap-dstmem-v4-0-f228b059dd89@bytedance.com> In-Reply-To: <20231213-zswap-dstmem-v4-0-f228b059dd89@bytedance.com> To: Andrew Morton , Seth Jennings , Johannes Weiner , Vitaly Wool , Nhat Pham , Chris Li , Yosry Ahmed , Dan Streetman Cc: linux-kernel@vger.kernel.org, Chengming Zhou , linux-mm@kvack.org, Nhat Pham , Yosry Ahmed , Chris Li X-Developer-Signature: v=1; a=ed25519-sha256; t=1703606082; l=2338; i=zhouchengming@bytedance.com; s=20231204; h=from:subject:message-id; bh=tAV69Q+4us6Py1b2R2r8p5EYfYNSenhTMFhuOp7vNNQ=; b=afViGCtigOHtj8SqyE1/3tYO10W9zGnBEqlNj/WHy0NkwORwH+k6pwR/NJpbIHP3TQeqORo2h ERJwMflduKtC/okQR5pR1LwHwhvGLXlCdgX/gX53ZckJzqrZB76ELZ2 X-Developer-Key: i=zhouchengming@bytedance.com; a=ed25519; pk=xFTmRtMG3vELGJBUiml7OYNdM393WOMv0iWWeQEVVdA= X-Migadu-Flow: FLOW_OUT X-Rspamd-Queue-Id: C772380006 X-Rspamd-Server: rspam02 X-Rspam-User: X-Stat-Signature: rfdz3ck48s36n4r5x4kzr9xw9qwtrtzt X-Rspamd-Pre-Result: action=add header; module=dmarc; Action set by DMARC X-Rspam: Yes X-HE-Tag: 1703606102-886066 X-HE-Meta: U2FsdGVkX19LrUl9PViLXl4KTFLu84txoDbxjUniBkAsfTNW4N/eB0p02tdROG2FH2KkDXs0IC8Npjb4WYCatusLIHiFHSiur5qntXVGy/+ass0n843nUud6ESkLlpjGtVaI4RDY0vDkvvG/EI6nQ7gSWStN8y+6LeTDFlOn1CRvknaA+MXTAuMy8d3T9BYOelgBzc7tjR/PNC0BTkM1ga5ssQBKwZsQG6faBTnox+/JiQMDnaX70HDTjKrEkbQR3ZMkuGJCi8IajfHM6qa0RBt8Ed85rqZXEWX1sO/PzMvp7AePBGE4W9LwIT2oZdxUa743um0nAqw2aESQ0JN0rg1TIMStjHqIdj9otwST/z1iHvRa/L/gLrvckyvYGRRv+h3K4anmLvddSUPEkN5NUMYdKMrwQIB8u3+ok6gRxjh/3nNA4qpXlRHXnWoW6c55fBY1gAx8+EOgyEh5FxmLQxtxKLZezxU0XdMmuJFK5ApBS0SNATqk7AjvCqM/Dvlq9ntTMVpqeblsq14zDsMfHk69En8eolCiNHkrJCffddELwOY890Jp5A8EPJkNRGJEoclzQwlcMlIJlPxJA/H9oGK3SKGve4WsCdu7HgYB6hT5P18FA7f/3jC+x4Wm8sv3u9TshmcKOsbSGWm5k7CydwJE8sTgBE4Ooc3j1GUGATbt/egWRU4WC47Q0T3dRDbTBEwR412j+Op41ZVzr8jFQI7m/hcf1LOTlElgCDeg041EYqqKg7xAPffOYrk6Oshj3obSZwym2zAo2GpoxDi333eJ7Tk9U7uO+1vGatHGCc3jgrBhFNLXheDa0Ur8lq/OLSrStbSapnFuN9HL+aihfMBXtMTDYXkSUsx5bJJZd0sdBmbtKI0eS0MkRDEuPy24okE85NwTDdhuuH7ECqZ0GGz3tTwWnYsI6tVRHHHp2K44SvNcls1HJ3kQRueMBrrX0Ye9ts09jK9cH9/b+bg hMw2y+Mh 02GqeMhiGCgnMhrErYRvHg91TOrSbu9yDemez28SPATxIlBkPnZOWLVgImev89FLJR7FBNbmWtrzMbyHXvOSG4J2wncDBTlkd4xTS 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: List-Subscribe: List-Unsubscribe: Also after the common decompress part goes to __zswap_load(), we can cleanup the zswap_writeback_entry() a little. Reviewed-by: Yosry Ahmed Reviewed-by: Nhat Pham Acked-by: Chris Li (Google) Signed-off-by: Chengming Zhou --- mm/zswap.c | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index 86886276cb81..40ee9f109f98 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -1443,7 +1443,6 @@ static int zswap_writeback_entry(struct zswap_entry *entry, struct page *page; struct mempolicy *mpol; bool page_was_allocated; - int ret; struct writeback_control wbc = { .sync_mode = WB_SYNC_NONE, }; @@ -1452,16 +1451,17 @@ static int zswap_writeback_entry(struct zswap_entry *entry, mpol = get_task_policy(current); page = __read_swap_cache_async(swpentry, GFP_KERNEL, mpol, NO_INTERLEAVE_INDEX, &page_was_allocated, true); - if (!page) { - ret = -ENOMEM; - goto fail; - } + if (!page) + return -ENOMEM; - /* Found an existing page, we raced with load/swapin */ + /* + * Found an existing page, we raced with load/swapin. We generally + * writeback cold pages from zswap, and swapin means the page just + * became hot. Skip this page and let the caller find another one. + */ if (!page_was_allocated) { put_page(page); - ret = -EEXIST; - goto fail; + return -EEXIST; } /* @@ -1475,8 +1475,7 @@ static int zswap_writeback_entry(struct zswap_entry *entry, 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; + return -ENOMEM; } spin_unlock(&tree->lock); @@ -1497,15 +1496,7 @@ static int zswap_writeback_entry(struct zswap_entry *entry, __swap_writepage(page, &wbc); put_page(page); - return ret; - -fail: - /* - * 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; + return 0; } static int zswap_is_page_same_filled(void *ptr, unsigned long *value)