From patchwork Thu Dec 28 09:45:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengming Zhou X-Patchwork-Id: 13505767 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 2AD43C3DA6E for ; Thu, 28 Dec 2023 09:46:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B57CF8D0009; Thu, 28 Dec 2023 04:46:34 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B09B56B00BA; Thu, 28 Dec 2023 04:46:34 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9F73A8D0009; Thu, 28 Dec 2023 04:46:34 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 9075E6B00B9 for ; Thu, 28 Dec 2023 04:46:34 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 6F865C0821 for ; Thu, 28 Dec 2023 09:46:34 +0000 (UTC) X-FDA: 81615747108.11.7B05BA7 Received: from out-172.mta0.migadu.com (out-172.mta0.migadu.com [91.218.175.172]) by imf02.hostedemail.com (Postfix) with ESMTP id 9310A80016 for ; Thu, 28 Dec 2023 09:46:32 +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.172 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=1703756792; 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=PT9H08eJXH/H7Ml+YE+PXwYs8Lv/GEpxQ360CTv1z9M=; b=Lb48X7KX5FjQiNlPERt4PHBNqlJvhO+lpJYECApulDktVV8jDYgZfOElPVq8ty5Si7fSiT k4bPPg86bDsRVHVBUbPh2wMOBuekTwDUFutNxdxzUthbzu7hTGvHRkXwqpKDMsC5QGss4Y qCO7Xqwko+lAyfXkXzyorT8jRgB2tqY= 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.172 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1703756792; a=rsa-sha256; cv=none; b=WiItJ4JSkPn1TVT6Oyi/gwrBFXBVE0QjLzV6gpXw6lwFAWXM3XI1k7CcbI0v5f1vsh6Esx iCd0xApmzK2Zu5ShFX2alF9zKi3n27qtymsFAbv6rKbs0+bRCMe/op8vY6x31zDkXYadD/ xC3m+YbXg8wY4JK6dbDhYnwIVP7dzc0= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Chengming Zhou Date: Thu, 28 Dec 2023 09:45:45 +0000 Subject: [PATCH v5 4/5] mm/zswap: cleanup zswap_writeback_entry() MIME-Version: 1.0 Message-Id: <20231213-zswap-dstmem-v5-4-9382162bbf05@bytedance.com> References: <20231213-zswap-dstmem-v5-0-9382162bbf05@bytedance.com> In-Reply-To: <20231213-zswap-dstmem-v5-0-9382162bbf05@bytedance.com> To: Barry Song <21cnbao@gmail.com>, Yosry Ahmed , Nhat Pham , Andrew Morton , Dan Streetman , Vitaly Wool , Johannes Weiner , Chris Li , Seth Jennings Cc: Yosry Ahmed , Nhat Pham , Chris Li , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Chengming Zhou X-Developer-Signature: v=1; a=ed25519-sha256; t=1703756775; l=2338; i=zhouchengming@bytedance.com; s=20231204; h=from:subject:message-id; bh=5hrzED6ruCvN+7YOlRuh0wDVEni4Jtsv4F8FioAoDqA=; b=QqMwHN+kvR++JhOibm6XsrYrAW9xa7b2cN1gUvUDvJ80DjHT4cwxyemA4TSJvXgr7FctXn0HV LoHrcUfJc1BBavTLmSy4+K67MYc0NCDltyXkviDKPDg+/7snuwJFxJP X-Developer-Key: i=zhouchengming@bytedance.com; a=ed25519; pk=xFTmRtMG3vELGJBUiml7OYNdM393WOMv0iWWeQEVVdA= X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Rspamd-Queue-Id: 9310A80016 X-Rspamd-Server: rspam12 X-Stat-Signature: jw113eyq7mh7n9kt1g6hq7ic8extstsc X-Rspamd-Pre-Result: action=add header; module=dmarc; Action set by DMARC X-Rspam: Yes X-HE-Tag: 1703756792-842694 X-HE-Meta: U2FsdGVkX1/GL8wVoYoKeQnj8t7Jj2JH5f2p9pA7C81o0e18VOPSDVgsBfCG1b7BMxfObqARbRm2p56d3+08DZv2Ddc6xTTMGbqmPDmm1AyVRmOHHyCQ5doV6fs5XyQAYrUPmQ7pQY9h6Qdd+58WVpSIqeeeh0pqo7shvOiszhv6p3L+rPSSPrU6O5NG1S1GAlh/HXvOJMGljsCvEJY5l58Kz5dws2m2nkWgfC+g+ZjHyR567lAExQwxJ44sL3igTTVuNUWjIP/R6ML1IcJ7tF0KWlg4C+ce8ZKHBVZKRKYY92/ZBg74kQC4+ziAy0QoIMTxmOILK8Me/FLlaXxlc3gHB9KTgRYomrsWzH0WKz8X/AqfbAX0AQzSIIE15vjbvjG5msltTANk4wUbRQq/P6FU0LoOJ/2FH9sVi1F9v3GDxpQomEEFjH4htYjLHnEeVCjWfXn3JRAuccXx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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 618989463535..e756b2af838b 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)