From patchwork Mon Dec 18 11:50:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengming Zhou X-Patchwork-Id: 13496762 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 E1C2BC46CCD for ; Mon, 18 Dec 2023 11:50:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6C0C48D0010; Mon, 18 Dec 2023 06:50:55 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5FB9B8D0001; Mon, 18 Dec 2023 06:50:55 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3D9CF8D0010; Mon, 18 Dec 2023 06:50:55 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 1BD7F8D0001 for ; Mon, 18 Dec 2023 06:50:55 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id E209741147 for ; Mon, 18 Dec 2023 11:50:54 +0000 (UTC) X-FDA: 81579772428.20.548C6B2 Received: from out-189.mta0.migadu.com (out-189.mta0.migadu.com [91.218.175.189]) by imf05.hostedemail.com (Postfix) with ESMTP id 1503510001A for ; Mon, 18 Dec 2023 11:50:51 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=bytedance.com (policy=quarantine); spf=pass (imf05.hostedemail.com: domain of chengming.zhou@linux.dev designates 91.218.175.189 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=1702900252; 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=7HR/MLv2aBLIXlJNr8b9Lqs7UJ1j9JsFWT1nUw7L6eQ=; b=4iHJqcrKNyIRSVJwS8hrSlcoX7qAnPq24xnxNsNi1JeMAsgnL1y0l/OApEi9c0+UKZtI/f rSJ7VOfT1xSNIsgYORFluTAY5nGYuAo8UmH/2hcWkr1KlZ1pB0lT11rVrWI2Qc1yplH5Vh x6KT3Aq7bSA5yVTFCGITsu9W5Eoau+k= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=bytedance.com (policy=quarantine); spf=pass (imf05.hostedemail.com: domain of chengming.zhou@linux.dev designates 91.218.175.189 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702900252; a=rsa-sha256; cv=none; b=jDuzalDt0Bv752RiHa0eD/u8YTZro01C0FSJ0wHOeLy/JuiEjakurWgEFq6zyNMy4LjzUr Q6JPIkUOYBqvzN/Y3z3+0JRi4CGde299G/uzu+lOKiK6uN0AcxmBALi8ADMeYt5LUenYvF twTnTtlQFOquCLOHsOPgudZRVNCM+/M= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Chengming Zhou Date: Mon, 18 Dec 2023 11:50:35 +0000 Subject: [PATCH v3 5/6] mm/zswap: cleanup zswap_writeback_entry() MIME-Version: 1.0 Message-Id: <20231213-zswap-dstmem-v3-5-4eac09b94ece@bytedance.com> References: <20231213-zswap-dstmem-v3-0-4eac09b94ece@bytedance.com> In-Reply-To: <20231213-zswap-dstmem-v3-0-4eac09b94ece@bytedance.com> To: Seth Jennings , Yosry Ahmed , Vitaly Wool , Dan Streetman , Johannes Weiner , Chris Li , Andrew Morton , Nhat Pham Cc: Chris Li , Yosry Ahmed , linux-kernel@vger.kernel.org, Chengming Zhou , linux-mm@kvack.org, Nhat Pham X-Developer-Signature: v=1; a=ed25519-sha256; t=1702900234; l=2215; i=zhouchengming@bytedance.com; s=20231204; h=from:subject:message-id; bh=u9D8B3ksO9G67avNjANTAO3qS+/SASwDD1QW2eXuPmA=; b=bX9QDtAp6LhqXJx8Yr0LWdcF0z06lztvYdnRzlwugcBS4LaRmP3c9JNAMHRIFxNxSVfv4KXJP 2yn6oW6AM20DLSOlXaQvsN42SgrRlNXTLt3ZWYzqDYQTNtDhy74I4xe X-Developer-Key: i=zhouchengming@bytedance.com; a=ed25519; pk=xFTmRtMG3vELGJBUiml7OYNdM393WOMv0iWWeQEVVdA= X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Rspamd-Pre-Result: action=add header; module=dmarc; Action set by DMARC X-Stat-Signature: 75wychpsodb7tcit5yikocrnbirbegcp X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 1503510001A X-Rspam: Yes X-HE-Tag: 1702900251-916467 X-HE-Meta: U2FsdGVkX1/sPXxmuW4xArzsDpwySKHn3WeM+CjdY8xNfhwOkyE+PoLWqMyO2vPxyxD9xFXQefmccOBRdoWO1dCBWjCBr7/y02DB4eVYgHKdDxBD4z7ixMowfZ7kW9bL6oqCQz4x59R2o0LHbNxScm/dINh+CHERtJGXfGcejhJyWoQiEuUgDbnDdahmOJSfwEEngWS0br1b5nibDrGyU7eGIWejBDtcRwR+6q06rEmAGACjWZnaE13SvsB7rYFfOZm+zEbYt4xiMA6pSSgZbQglYwXCh1dYkDUpJeHaDenJgTsNZ08layqtfhH2jSCyxy3VRGo+JAJzkGQbQIeveBuUCPxPyB+EdFxM8hIAqPL0g46f6T2xruoCTZspemYLKa6fiL1einA0ChjT4wPXcxFIII32BoESlYH3Z8vABMOTOfKRrEg3OAin3OJifSE9ib2+TelUqIQJd4cfX96cQHtMpXQIpNKnS2H2yASw+WYDpGRcYuRn76z0NhrLvVhjmljOaYpn1qxiR8ZarecE//YpMxeZNbvNNhv6prIVKw1t8nYaTWMo/e1YZo5tBUrj/nuX7ii5NlmjARLiWn1pGgogKT20ohKa7Q2/WM5Czb74Ruy4+syGCvwClU6hpVo+qtyCZ05okIVvZkSTH1igHRcZapbDKsvMfRuoYAi0PRWbV5AqtxVNY5FmOlNbGGtD9OmhMdWP6Nb+tJE+bc8SMYT6RjQ9cEA8rjYV9F6GadTuO7Cb8UC997SbcMLkBFEn49iEklIAD6e4MkAOuIJFsg0lwMccWcYFKcN284CtcYGHjpqBsMlUnifdc8gQtrgPKlXyApQfcPxv6915pAZ2TEYtOgvd2qRpnfLj9+o9vk3g//nE3Buy/zwdTeWKFnqGCW3NVMpwpbsyF2UMopBbKNT7Enr5mBOPoY+t8BtuvFnMXIGtZKweO1tDNlI2CuL6N4YHmcnBSQxzb/1R7Op nTifhgdp usLLFyM0RHSU/GO1oGyOa6UgeJD5mAvooufTUitCK9NwZUjKCJ/pTGJsvLQicprjRxwwqBn05E63lGBl+5VYe2CC1Ylbj75sEg4Xk0CWNvSIKmKlDBTRexTNPWxHMch6Dg5SEQFAf8EEqOmydt7y12nxidSX5YrUSf+CaEn/vxwACGEU+Frsws8tHPPCexSdvfhT4pcsp7OP9PPh7sjS62efnV2Q55yhmK1cNcMq5Z6ByZri61+XJvGzObzV5hlyW1dbG9pow9ht2jUyrH+zcf53KCPHLYyqpqVCZQyAOrbSgxaUof//xZD75NlpQLkCvYsOb5R+L0vRUYFYKO7uJff1V18WzyTYbjflMPc+cri+lbot2REudnjN6ugCgMdju5C49osv/NCxP8b8wLCrTSTzUaGD+0qQp+9vpqsHOztOITSE= 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 Signed-off-by: Chengming Zhou Acked-by: Chris Li (Google) --- mm/zswap.c | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index 86886276cb81..2c349fd88904 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, }; @@ -1453,15 +1452,18 @@ static int zswap_writeback_entry(struct zswap_entry *entry, page = __read_swap_cache_async(swpentry, GFP_KERNEL, mpol, NO_INTERLEAVE_INDEX, &page_was_allocated, true); if (!page) { - ret = -ENOMEM; - goto 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 -ENOMEM; } /* Found an existing page, we raced with load/swapin */ if (!page_was_allocated) { put_page(page); - ret = -EEXIST; - goto fail; + return -EEXIST; } /* @@ -1475,8 +1477,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 +1498,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)