From patchwork Mon Dec 18 08:22:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengming Zhou X-Patchwork-Id: 13496354 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 1A69CC35274 for ; Mon, 18 Dec 2023 08:22:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A40018D000A; Mon, 18 Dec 2023 03:22:45 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9C8A68D0001; Mon, 18 Dec 2023 03:22:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 81B8E8D000A; Mon, 18 Dec 2023 03:22:45 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 6F2148D0001 for ; Mon, 18 Dec 2023 03:22:45 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 516621608A2 for ; Mon, 18 Dec 2023 08:22:45 +0000 (UTC) X-FDA: 81579247890.09.7660A69 Received: from out-177.mta1.migadu.com (out-177.mta1.migadu.com [95.215.58.177]) by imf19.hostedemail.com (Postfix) with ESMTP id 674531A0010 for ; Mon, 18 Dec 2023 08:22:43 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=none; spf=pass (imf19.hostedemail.com: domain of chengming.zhou@linux.dev designates 95.215.58.177 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=bytedance.com (policy=quarantine) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1702887763; 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=N8fc81Ep4XYdiKSxHTmTu5s6pOBORCL5pbUZnN0hIR6gDtOto7PoLCCNiJ3teX0f9NRo6n odgbulG2ryl31ChhTrJqUxcgoM9oMRhUYvQGq959pQ7pGEvchKDw24CMIybW0ahkLjGZfW NfZGs57NkKskdMfXXkcbDODpOHEIUes= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702887763; a=rsa-sha256; cv=none; b=KwkgDbxpCDrrwLFTWinbcltVOmsP8N3z2gzAcPB0OxGdOH/xl0sUqhCbogavF6npmC86cu UQa5kxIOkUc4ja43yTPLoRWYhlCSscrYSZDQCahGXkItXn3UgzLsy7i70mFYQU0mwHb2sN eTks8xPrfJZh18g7r/fm5BD+R4YBmNk= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=none; spf=pass (imf19.hostedemail.com: domain of chengming.zhou@linux.dev designates 95.215.58.177 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=bytedance.com (policy=quarantine) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Chengming Zhou Date: Mon, 18 Dec 2023 08:22:04 +0000 Subject: [PATCH v2 5/6] mm/zswap: cleanup zswap_writeback_entry() MIME-Version: 1.0 Message-Id: <20231213-zswap-dstmem-v2-5-daa5d9ae41a7@bytedance.com> References: <20231213-zswap-dstmem-v2-0-daa5d9ae41a7@bytedance.com> In-Reply-To: <20231213-zswap-dstmem-v2-0-daa5d9ae41a7@bytedance.com> To: Seth Jennings , Dan Streetman , Chris Li , Nhat Pham , Vitaly Wool , Yosry Ahmed , Andrew Morton , Johannes Weiner Cc: linux-kernel@vger.kernel.org, Nhat Pham , linux-mm@kvack.org, Yosry Ahmed , Chengming Zhou , Chris Li X-Developer-Signature: v=1; a=ed25519-sha256; t=1702887745; l=2215; i=zhouchengming@bytedance.com; s=20231204; h=from:subject:message-id; bh=u9D8B3ksO9G67avNjANTAO3qS+/SASwDD1QW2eXuPmA=; b=Y/k0K3dE80CEovxET6orobtOyqyRJJHYc5i0dttC7jiXtrRjSziXVF7ngHADT55LxnZB0hdN9 VU8d58ziWvID/Hp36IATF7GQgb3Z0riqtM9YUjDT6aMJe1wiTZkqkT7 X-Developer-Key: i=zhouchengming@bytedance.com; a=ed25519; pk=xFTmRtMG3vELGJBUiml7OYNdM393WOMv0iWWeQEVVdA= X-Migadu-Flow: FLOW_OUT X-Rspamd-Pre-Result: action=add header; module=dmarc; Action set by DMARC X-Rspam-User: X-Rspamd-Queue-Id: 674531A0010 X-Rspamd-Server: rspam11 X-Stat-Signature: gdxkcoenamegj1ssnqc4akfjtrhe7gks X-Rspam: Yes X-HE-Tag: 1702887763-49730 X-HE-Meta: U2FsdGVkX1+kQ236GltFO2OOBEnckGVhq8mX30rww86rwcUYw3dvP6TPt9UonQFfD6KkNpBNY8wPQcOrkRtY9N/RHdwMBuFhAjZd71X4aG8MwjZa/PJVjsmEHRsB+wZoSXaMok3BJfhms1I8LFwLn2Yav4cS2c6rzNkWJ3HRiVo9/25UOsyADiu9a6l7OIUE+jmA5J5F3kEJPLIEOn2l1m8yFZXFGoKe+O9dZo5IyHL0GI2jEdMDrZ4ss8rFHC+3V10emmIhpoA3G0kKKuMhQJxEsaB4IiInnZ1Sxw5C5/6f7KYb1RUYAaty0eAO2wuUr8O/gN5hcbf1bUA38VmbrUpmo0zIHlIqDcgDjRuSbbp/9JAKlXbWu3Fck5u/zwkxgZ0lHPtVWpK1//SjE1ID5XGWqRmBTNMJuN1Tb3sPEn0RChig3lNrtD0DSw83n5huksnzbASUJoSbMqtv0M6M14NcAqwmZCTeF6EWWnRCrhLC+SCuYZ5lZNn6lO64fm942csO3UfgqaRDCVwAr2mhNij01HzwreLJdO1jQINCU7igDxPb2e0Q7jCiGvMCEmRG7TfjWVKcLijYO0pwy1Cp3Of3CBh/o2/qoiTkmwnHkTd2EtInoA1l5anfja+K0wio7U5n5CuP6rqYBiw7D/0tEpaZ21m9sOLGK+CevmHCItK/B5KXOfk5jL6S1C51wD0M5nXfh9b2GECej8omJsrPV0qZ8b0fZG3XeNcWNjt5/hcnn42DPRh0skgg8IpvjapWcPmXssT8U+XdEch8L8kUya8Ar/+YqI1qTksj/46BAja/3Og2V7eHdDpVaU0AkaL4wTroc+cDURUFrWzKvoexD03zuHqFylCny7jA6klhAvGBiED05COc3ubCik6X8R+BHKGWtnJuq3WKxizOPjwWaXwhG4nADx2IgzuWYFoJyG5FBfbTOOd3VREZi6QwOHv/zgizKssTrLn/FnWZaUs EdI4NlgG 4H79FNq8f/T/f65YYyBUVy/K6tQhQkd/OuGkOgHUaRWhey/sDjo8JziiMgW2Kprbt+U8WkuoI82wR3NNetjltfSZqAhyriUcF99sYWze/58J93cZNHfq37yCjO+d+n3wI1x5jxtdhkThhJjgzasLVl9zLUy9fvRc9LtUazrexRMe19lWShkumCsdyW5bzpqLoLAnRjXYXrot/K9JZqN0e8wBvGReACHmw1+5+2ULAZidOWSSMCTjQGtm+tBTTKdCef+NFUhdi/u/YePCHUDrXcuHKSppG7a1TgW/7pts59fKiJVaKf4Hol9QOu57NA4KdaOnhqIgawnum3EoFObfBScX8Jk3GFboaasa8HA76mN3tKPBgCnmIDVA51Ormx5IbM5aF1IqN48F723IFZ/9tvCqXrHGwbhsd5rS77lAeAOuwPUTbH8mQ25J+JkFRAbMjZEbNTJc8KgcJ9gc= 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 --- 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)