From patchwork Tue Mar 26 18:50:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 13604899 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 24187C54E67 for ; Tue, 26 Mar 2024 19:04:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AA1426B009C; Tue, 26 Mar 2024 15:04:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A03346B009D; Tue, 26 Mar 2024 15:04:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 856026B009E; Tue, 26 Mar 2024 15:04:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 6D6CF6B009C for ; Tue, 26 Mar 2024 15:04:52 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 053C9C0DC8 for ; Tue, 26 Mar 2024 19:04:52 +0000 (UTC) X-FDA: 81940117224.29.99B8A18 Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) by imf20.hostedemail.com (Postfix) with ESMTP id 1623C1C001E for ; Tue, 26 Mar 2024 19:04:49 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=BW3BWmia; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf20.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.210.179 as permitted sender) smtp.mailfrom=ryncsn@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1711479890; h=from:from:sender:reply-to: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=+ERJb6WoHkZLLvZFbb96DVZc9OxyF4ifaYeM2AyqivE=; b=FkIvMbqjTEfQaSpJFL1jXmsgT7pFDQjvXNCDGstqmb9+sm48Vbyu2JVDE7Fu2CyC1FON+m gY5NWqiJ5UkSYODTeoBhUHg88ZMQg7j9eS4nHzXTKKHME3fwZFj6UHnT0WMfAjxLifOfGN /IBTPc7bW1NUffrZsrAimMbGc59YKAE= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=BW3BWmia; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf20.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.210.179 as permitted sender) smtp.mailfrom=ryncsn@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711479890; a=rsa-sha256; cv=none; b=OuuXoVMiAG9hx4PqtrdaNkw8jGk0Ze5Dqr6yH4ifZUMY6FyI1ohALLf5LEbroWMqsZxy1+ YmfF+Ixn5mF01BhH0QekJX46Mdv4WbKc1sT5KrZJGFsD3nBLK7E46FEJ1RL3lOXfoV8WCw Z4V4VPVSr3ywkMaEk1Kr4yynVTgQyPE= Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-6e6b6f86975so3800283b3a.1 for ; Tue, 26 Mar 2024 12:04:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711479888; x=1712084688; darn=kvack.org; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=+ERJb6WoHkZLLvZFbb96DVZc9OxyF4ifaYeM2AyqivE=; b=BW3BWmiamQo23QGHGK53gvQ+dQJNEBAIYc5jDnilLVBrM2+n2AMYd49mznQcZ4P3EJ wHS9wLawAEihBbYtLPXqzc3JvxpIW5kaVI+2AlZdkDUj9W7VbxSq+1Jiu6SVyrToSLWB 5OeK06I/6B+uQoIFqS3cNkbS7unazuiegM9TGjs4c6DYuakgRsFR0g2Ad6bPQQIK8xjN l1D5U9CgbmfaJgmCD7Ipn58bOuX3WqDE5uTHvm7CIxH6Dp7VEmXuD9KyT04+I95UdZ/t J87LDJJeuLocJ06v59Zz1N5ux/u9I6+bBZrvkhzxYMmlz0wBH9hSu7JZahxiEByBVEah T1NA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711479888; x=1712084688; h=content-transfer-encoding:mime-version:reply-to: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=+ERJb6WoHkZLLvZFbb96DVZc9OxyF4ifaYeM2AyqivE=; b=pJgKSax/D1qhy8JlKkL8TMT8glEr7k/MyCctsgDZKQVayCbQpW1TS9o3eIwAue2G8A 7cuU7wQbYUG5+ZrV8es+DdqkoOO57ldo/c46W1h3dqFUFGOOB7IQwLmumzG9OlCc/sAG qucbfXR0JuWvQpCHdUfaagyFpLYTI76Ez4f26PyEjbTzGT5fl5wqWSWIac1dOB8zFqSB f1q/HhmA6psPo2wCCMUWhijZBM6LhKXsC81OyaSD9hqC2KLyZJ1Umplk8gnnGEHn5/2k j66IKrlqsThgrcOe0nqgcRV7q/k1FHNUqzBg8PKjBsKgDMZyoUbLAnyQ3FfkiA1XtICL RSqA== X-Gm-Message-State: AOJu0YwFhh0JIMeg00ADERMhqNQUoQYvVVuR/pgYSWQto8i62xOFAgx1 qT5pu9L4S4+atiNA/BBkqO5WgT2hKdsggUJHs9uJMPesdoaAafKJQsHlxlqH4Y+YntIq X-Google-Smtp-Source: AGHT+IFI5c1XPfK9gSzn3T3e+978jVi9idobPChm0l6H2mPesS3FLokLOM//jRLMf4TOY19ha0SPPg== X-Received: by 2002:a05:6a00:701e:b0:6ea:c04c:71cb with SMTP id lf30-20020a056a00701e00b006eac04c71cbmr1408795pfb.3.1711479888011; Tue, 26 Mar 2024 12:04:48 -0700 (PDT) Received: from KASONG-MB2.tencent.com ([115.171.40.106]) by smtp.gmail.com with ESMTPSA id j14-20020aa783ce000000b006ea790c2232sm6298350pfn.79.2024.03.26.12.04.43 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 26 Mar 2024 12:04:47 -0700 (PDT) From: Kairui Song To: linux-mm@kvack.org Cc: "Huang, Ying" , Chris Li , Minchan Kim , Barry Song , Ryan Roberts , Yu Zhao , SeongJae Park , David Hildenbrand , Yosry Ahmed , Johannes Weiner , Matthew Wilcox , Nhat Pham , Chengming Zhou , Andrew Morton , linux-kernel@vger.kernel.org, Kairui Song Subject: [RFC PATCH 07/10] mm/swap: rename __read_swap_cache_async to swap_cache_alloc_or_get Date: Wed, 27 Mar 2024 02:50:29 +0800 Message-ID: <20240326185032.72159-8-ryncsn@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240326185032.72159-1-ryncsn@gmail.com> References: <20240326185032.72159-1-ryncsn@gmail.com> Reply-To: Kairui Song MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 1623C1C001E X-Stat-Signature: pxukk5me5ihpqa7xi3mmpaj6yugnztxz X-HE-Tag: 1711479889-701623 X-HE-Meta: U2FsdGVkX188Np27VHtqjNoUR/+6jnpsrxq93ekWgkR/UDNYxBhchYnkKLCblDO8oqgPDO4Niel1EJV2It6crXqr0E2k6pYgZgYWqZ/JFl2Bb1A1xp+cXXgFOnDeZ227VmcG3b0jRvFJXkV2H/9MWjHiMVcro35l1kfS4c8G0/XfhpxZ/gn4mLOPNksCpkLj3vofuuf3nF7BXN/rBS0rz/lkNPfYPjznl4zTpmSyACeQnkHGUo5AbKoTRrxLdiCQOsmErHnBHL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mpJJlD9MXHUFeg9+ABju29/IyQ0UW3LNjcWrmEfgLbNEForLDe3vOBGrQ2k5zoTlnb1Zz3Actpaz1IIjeZFeh8nOmiXsiylnagHPgHpQ8BLeag+bne3N6f/pcOs3nEmsNJyKbnjQT3Uqyg+GyDTeNZ3slFmNywsZqpAsRtsJZ1q0sTATY4EqOluI9nX1upeNzB3hOEGnPSbO2KC5Vt0itFArpJ2doxC9n5xUMW4kpLIJVfVTgWsgl9OY5SGyxif5hGVM81r9jmHZo5rwW6Bis3A090Jnqlmt+XDznuaS5OTxQrAWRmq0vTrRxeS/IBsU= 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: From: Kairui Song __read_swap_cache_async is widely used to allocate and ensure a folio is in swapcache, or get the folio if a folio is already there. Rename it to better present the usage. Signed-off-by: Kairui Song --- mm/swap.h | 2 +- mm/swap_state.c | 22 +++++++++++----------- mm/swapfile.c | 2 +- mm/zswap.c | 2 +- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/mm/swap.h b/mm/swap.h index 7721ddb3bdbc..5fbbc4a42787 100644 --- a/mm/swap.h +++ b/mm/swap.h @@ -48,7 +48,7 @@ struct folio *filemap_get_incore_folio(struct address_space *mapping, struct folio *read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask, struct vm_area_struct *vma, unsigned long addr, struct swap_iocb **plug); -struct folio *__read_swap_cache_async(swp_entry_t entry, gfp_t gfp_flags, +struct folio *swap_cache_alloc_or_get(swp_entry_t entry, gfp_t gfp_flags, struct mempolicy *mpol, pgoff_t ilx, bool *new_page_allocated, bool skip_if_exists); struct folio *swap_cluster_readahead(swp_entry_t entry, gfp_t flag, diff --git a/mm/swap_state.c b/mm/swap_state.c index caf69696f47c..cd1a16afcd9f 100644 --- a/mm/swap_state.c +++ b/mm/swap_state.c @@ -385,7 +385,7 @@ struct folio *filemap_get_incore_folio(struct address_space *mapping, return folio; } -struct folio *__read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask, +struct folio *swap_cache_alloc_or_get(swp_entry_t entry, gfp_t gfp_mask, struct mempolicy *mpol, pgoff_t ilx, bool *new_page_allocated, bool skip_if_exists) { @@ -443,12 +443,12 @@ struct folio *__read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask, goto fail_put_swap; /* - * Protect against a recursive call to __read_swap_cache_async() + * Protect against a recursive call to swap_cache_alloc_or_get() * on the same entry waiting forever here because SWAP_HAS_CACHE * is set but the folio is not the swap cache yet. This can * happen today if mem_cgroup_swapin_charge_folio() below * triggers reclaim through zswap, which may call - * __read_swap_cache_async() in the writeback path. + * swap_cache_alloc_or_get() in the writeback path. */ if (skip_if_exists) goto fail_put_swap; @@ -457,7 +457,7 @@ struct folio *__read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask, * We might race against __delete_from_swap_cache(), and * stumble across a swap_map entry whose SWAP_HAS_CACHE * has not yet been cleared. Or race against another - * __read_swap_cache_async(), which has set SWAP_HAS_CACHE + * swap_cache_alloc_or_get(), which has set SWAP_HAS_CACHE * in swap_map, but not yet added its folio to swap cache. */ schedule_timeout_uninterruptible(1); @@ -505,7 +505,7 @@ struct folio *__read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask, * the swap entry is no longer in use. * * get/put_swap_device() aren't needed to call this function, because - * __read_swap_cache_async() call them and swap_read_folio() holds the + * swap_cache_alloc_or_get() call them and swap_read_folio() holds the * swap cache folio lock. */ struct folio *read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask, @@ -518,7 +518,7 @@ struct folio *read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask, struct folio *folio; mpol = get_vma_policy(vma, addr, 0, &ilx); - folio = __read_swap_cache_async(entry, gfp_mask, mpol, ilx, + folio = swap_cache_alloc_or_get(entry, gfp_mask, mpol, ilx, &page_allocated, false); mpol_cond_put(mpol); @@ -634,7 +634,7 @@ struct folio *swap_cluster_readahead(swp_entry_t entry, gfp_t gfp_mask, blk_start_plug(&plug); for (offset = start_offset; offset <= end_offset ; offset++) { /* Ok, do the async read-ahead now */ - folio = __read_swap_cache_async( + folio = swap_cache_alloc_or_get( swp_entry(swp_type(entry), offset), gfp_mask, mpol, ilx, &page_allocated, false); if (!folio) @@ -653,7 +653,7 @@ struct folio *swap_cluster_readahead(swp_entry_t entry, gfp_t gfp_mask, lru_add_drain(); /* Push any new pages onto the LRU now */ skip: /* The page was likely read above, so no need for plugging here */ - folio = __read_swap_cache_async(entry, gfp_mask, mpol, ilx, + folio = swap_cache_alloc_or_get(entry, gfp_mask, mpol, ilx, &page_allocated, false); if (unlikely(page_allocated)) { zswap_folio_swapin(folio); @@ -809,7 +809,7 @@ static struct folio *swap_vma_readahead(swp_entry_t targ_entry, gfp_t gfp_mask, continue; pte_unmap(pte); pte = NULL; - folio = __read_swap_cache_async(entry, gfp_mask, mpol, ilx, + folio = swap_cache_alloc_or_get(entry, gfp_mask, mpol, ilx, &page_allocated, false); if (!folio) continue; @@ -829,7 +829,7 @@ static struct folio *swap_vma_readahead(swp_entry_t targ_entry, gfp_t gfp_mask, lru_add_drain(); skip: /* The folio was likely read above, so no need for plugging here */ - folio = __read_swap_cache_async(targ_entry, gfp_mask, mpol, targ_ilx, + folio = swap_cache_alloc_or_get(targ_entry, gfp_mask, mpol, targ_ilx, &page_allocated, false); if (unlikely(page_allocated)) { zswap_folio_swapin(folio); @@ -855,7 +855,7 @@ struct folio *swapin_direct(swp_entry_t entry, gfp_t gfp_mask, pgoff_t ilx; mpol = get_vma_policy(vmf->vma, vmf->address, 0, &ilx); - folio = __read_swap_cache_async(entry, gfp_mask, mpol, ilx, + folio = swap_cache_alloc_or_get(entry, gfp_mask, mpol, ilx, &page_allocated, false); mpol_cond_put(mpol); diff --git a/mm/swapfile.c b/mm/swapfile.c index bafae23c0f26..332ce4e578e8 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -1249,7 +1249,7 @@ static unsigned char __swap_entry_free_locked(struct swap_info_struct *p, * CPU1 CPU2 * do_swap_page() * ... swapoff+swapon - * __read_swap_cache_async() + * swap_cache_alloc_or_get() * swapcache_prepare() * __swap_duplicate() * // check swap_map diff --git a/mm/zswap.c b/mm/zswap.c index 9dec853647c8..e4d96816be70 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -1126,7 +1126,7 @@ static int zswap_writeback_entry(struct zswap_entry *entry, /* try to allocate swap cache folio */ mpol = get_task_policy(current); - folio = __read_swap_cache_async(swpentry, GFP_KERNEL, mpol, + folio = swap_cache_alloc_or_get(swpentry, GFP_KERNEL, mpol, NO_INTERLEAVE_INDEX, &folio_was_allocated, true); if (!folio) return -ENOMEM;