From patchwork Tue Mar 18 15:06:07 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kemeng Shi X-Patchwork-Id: 14020348 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 1E5E0C282EC for ; Tue, 18 Mar 2025 06:10:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E9180280004; Tue, 18 Mar 2025 02:10:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7751928000A; Tue, 18 Mar 2025 02:10:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5A412280007; Tue, 18 Mar 2025 02:10:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 13D7A28000A for ; Tue, 18 Mar 2025 02:10:40 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 4E75DB8488 for ; Tue, 18 Mar 2025 06:10:41 +0000 (UTC) X-FDA: 83233647882.26.87E76AC Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by imf20.hostedemail.com (Postfix) with ESMTP id AC21A1C000D for ; Tue, 18 Mar 2025 06:10:36 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=none; spf=pass (imf20.hostedemail.com: domain of shikemeng@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=shikemeng@huaweicloud.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1742278239; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=y3K71R1y9DvNQDZ49hR12YZuj91hQ39OgzmyWifmOsY=; b=Y2VYDcjul1LMOKgF6GPu0KrFAV2mzPnXAfG4afYZ509/KPf4PE7PIwlcCYcmwuCxTJRX/W CcKciTTOXAy7moe3zLAAkFx/An2CVOeJVWUpoWvqSbyTzohOdE3dTO4q8qSIZnAmzEwRPb ZTbTfygEL/DFCaG92ugOQ0GFk8Dza6M= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=none; spf=pass (imf20.hostedemail.com: domain of shikemeng@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=shikemeng@huaweicloud.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1742278239; a=rsa-sha256; cv=none; b=le8lbQqoVsOrEYsGZtP10LsvydbAlSSduQ35HLTcl8lRWKJUjVmqBwWbHxTCT2UealnykW qLVuiBsADCNdnWA7vFRUhOLgjY/aDtRdWnWSRpI5TBRT32QojegvpxtrRGLzkNjLgZq7cV xtE7ms61teYf2LdGsC1dSl1T5DvuKwg= Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4ZH1f705wGz4f3lgM for ; Tue, 18 Mar 2025 14:10:07 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id 1F62E1A01A1 for ; Tue, 18 Mar 2025 14:10:31 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.101.6]) by APP2 (Coremail) with SMTP id Syh0CgD3AGRVDtln65ErGw--.37695S3; Tue, 18 Mar 2025 14:10:31 +0800 (CST) From: Kemeng Shi To: akpm@linux-foundation.org Cc: tim.c.chen@linux.intel.com, ryncsn@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/8] mm: swap: rename __swap_[entry/entries]_free[_locked] to swap_[entry/entries]_put[_locked] Date: Tue, 18 Mar 2025 23:06:07 +0800 Message-Id: <20250318150614.6415-2-shikemeng@huaweicloud.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20250318150614.6415-1-shikemeng@huaweicloud.com> References: <20250318150614.6415-1-shikemeng@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: Syh0CgD3AGRVDtln65ErGw--.37695S3 X-Coremail-Antispam: 1UD129KBjvJXoWxZrWUKFW5Zw1DuF4rGF47CFg_yoWrKr45pF 9Igrn8KFs7Jr1xGws7Xw48Zr4Fvw4xW3W8tFy7Gw12vasxJryFqFyDC3y7KFyUCr95CF90 ya1Utry7GF4jqr7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPFb4IE77IF4wAFF20E14v26r4j6ryUM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M280x2IEY4vEnII2IxkI6r1a6r45M2 8IrcIa0xkI8VA2jI8067AKxVWUGwA2048vs2IY020Ec7CjxVAFwI0_Jrv_JF4l8cAvFVAK 0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVW7JVWDJwA2z4 x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l 84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I 8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AK xVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lc7CjxVAaw2AFwI 0_JF0_Jw1l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVA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96uBvjn1o+2KDoaP29fe17eU07FdFAUCpj8lh6HnJ1YbliQnxqd2k3HHvc5JlZdWPMUXi6Z/JPZJu2FCr6dLIYFh7DkGAsIvElgVKQlL2io8wG37xOgde37TJLPo6E9jBJPhy2BpSJ6YSUZMvfMBJsrNYsSy7sGtJtobZkbruQGhqzbEj3i8qUV6ZWby6TddIjjEwWQLlZ+mIVW0XM6O6qoNSvKIVPxjTdqctzGealWScGSNTSxzZnR0zMqSwjX2Wl3i99Exiz2TfZWs8MUTIiJerS19kDAUot69kqC2riOjmz1t2GmRiEaSVHH+qZVcKAJn2zWktbdOLvfTt6yBiOJNn8hzhCtSZdvRCgzbvH8g5FG 7vT72DeI z+ysaX0Y3kht/mqWMm8Q1o8zvWHwCyMG3FX1rxCHu1jV4Uqj+7sN5Z2HzzvsZjw4DUURSD7LI4HhTA/aMhj/PMAXCSDwMqPAqrnBZHdoI7Jup4vacbqOkjwGuXVsoXC1JIzjwZrxBPyr182XzoTU8FbUV0VxuiJowsd+ZRverIHne+A/XAfJ4v+jxTuaJTddVtyR5okAuG3P+eOeWpuwVepY7ORJ+GwGG8J0srCIJ6uEdFko= 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: In __swap_entry_free[_locked] and __swap_entries_free, we decrease count first and only free swap entry if count drops to zero. This behavior is more akin to a put() operation rather than a free() operation. Therefore, rename these functions with "put" instead of "free". Additionally, add "_nr" suffix to swap_entries_put to indicate the input range may span swap clusters. Signed-off-by: Kemeng Shi Reviewed-by: Tim Chen --- mm/swapfile.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/mm/swapfile.c b/mm/swapfile.c index 628f67974a7c..5a775456e26c 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -1347,9 +1347,9 @@ static struct swap_info_struct *_swap_info_get(swp_entry_t entry) return NULL; } -static unsigned char __swap_entry_free_locked(struct swap_info_struct *si, - unsigned long offset, - unsigned char usage) +static unsigned char swap_entry_put_locked(struct swap_info_struct *si, + unsigned long offset, + unsigned char usage) { unsigned char count; unsigned char has_cache; @@ -1453,15 +1453,15 @@ struct swap_info_struct *get_swap_device(swp_entry_t entry) return NULL; } -static unsigned char __swap_entry_free(struct swap_info_struct *si, - swp_entry_t entry) +static unsigned char swap_entry_put(struct swap_info_struct *si, + swp_entry_t entry) { struct swap_cluster_info *ci; unsigned long offset = swp_offset(entry); unsigned char usage; ci = lock_cluster(si, offset); - usage = __swap_entry_free_locked(si, offset, 1); + usage = swap_entry_put_locked(si, offset, 1); if (!usage) swap_entry_range_free(si, ci, swp_entry(si->type, offset), 1); unlock_cluster(ci); @@ -1469,8 +1469,8 @@ static unsigned char __swap_entry_free(struct swap_info_struct *si, return usage; } -static bool __swap_entries_free(struct swap_info_struct *si, - swp_entry_t entry, int nr) +static bool swap_entries_put_nr(struct swap_info_struct *si, + swp_entry_t entry, int nr) { unsigned long offset = swp_offset(entry); unsigned int type = swp_type(entry); @@ -1501,7 +1501,7 @@ static bool __swap_entries_free(struct swap_info_struct *si, fallback: for (i = 0; i < nr; i++) { if (data_race(si->swap_map[offset + i])) { - count = __swap_entry_free(si, swp_entry(type, offset + i)); + count = swap_entry_put(si, swp_entry(type, offset + i)); if (count == SWAP_HAS_CACHE) has_cache = true; } else { @@ -1552,7 +1552,7 @@ static void cluster_swap_free_nr(struct swap_info_struct *si, ci = lock_cluster(si, offset); do { - if (!__swap_entry_free_locked(si, offset, usage)) + if (!swap_entry_put_locked(si, offset, usage)) swap_entry_range_free(si, ci, swp_entry(si->type, offset), 1); } while (++offset < end); unlock_cluster(ci); @@ -1599,7 +1599,7 @@ void put_swap_folio(struct folio *folio, swp_entry_t entry) swap_entry_range_free(si, ci, entry, size); else { for (int i = 0; i < size; i++, entry.val++) { - if (!__swap_entry_free_locked(si, offset + i, SWAP_HAS_CACHE)) + if (!swap_entry_put_locked(si, offset + i, SWAP_HAS_CACHE)) swap_entry_range_free(si, ci, entry, 1); } } @@ -1798,7 +1798,7 @@ void free_swap_and_cache_nr(swp_entry_t entry, int nr) /* * First free all entries in the range. */ - any_only_cache = __swap_entries_free(si, entry, nr); + any_only_cache = swap_entries_put_nr(si, entry, nr); /* * Short-circuit the below loop if none of the entries had their @@ -1811,7 +1811,7 @@ void free_swap_and_cache_nr(swp_entry_t entry, int nr) * Now go back over the range trying to reclaim the swap cache. This is * more efficient for large folios because we will only try to reclaim * the swap once per folio in the common case. If we do - * __swap_entry_free() and __try_to_reclaim_swap() in the same loop, the + * swap_entry_put() and __try_to_reclaim_swap() in the same loop, the * latter will get a reference and lock the folio for every individual * page but will only succeed once the swap slot for every subpage is * zero. @@ -3758,7 +3758,7 @@ int add_swap_count_continuation(swp_entry_t entry, gfp_t gfp_mask) * into, carry if so, or else fail until a new continuation page is allocated; * when the original swap_map count is decremented from 0 with continuation, * borrow from the continuation and report whether it still holds more. - * Called while __swap_duplicate() or caller of __swap_entry_free_locked() + * Called while __swap_duplicate() or caller of swap_entry_put_locked() * holds cluster lock. */ static bool swap_count_continued(struct swap_info_struct *si,