From patchwork Thu Mar 20 11:48:22 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kemeng Shi X-Patchwork-Id: 14023364 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 3AE5FC35FFC for ; Thu, 20 Mar 2025 02:53:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B00FA28001C; Wed, 19 Mar 2025 22:52:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 92075280018; Wed, 19 Mar 2025 22:52:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 42306280016; Wed, 19 Mar 2025 22:52:59 -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 97EE7280013 for ; Wed, 19 Mar 2025 22:52:58 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 6E9E7160A11 for ; Thu, 20 Mar 2025 02:52:58 +0000 (UTC) X-FDA: 83240407236.23.EA54517 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by imf14.hostedemail.com (Postfix) with ESMTP id BC80F100005 for ; Thu, 20 Mar 2025 02:52:54 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf14.hostedemail.com: domain of shikemeng@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=shikemeng@huaweicloud.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1742439176; a=rsa-sha256; cv=none; b=eFBCQUrA8f6arLxPmsHqDmvDDTnC0xyvAmc/7i+IpkKaoM5ibjoF2j9gB+dLFktXlMOAIe AcyQb9Dfu1LQ52zZHk7SVuh5j8r1jI75RWPZj3vS0oI2+SvzapAYgW/tgSp3fda+GTEcxG gFClJhtsexyG0hz/zvQgNYo3LJM0DPI= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf14.hostedemail.com: domain of shikemeng@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=shikemeng@huaweicloud.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1742439176; 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=V5qWHJQMPs9IbW/nlysxxxqE+k6Bov1ZmRyy+wq+79tRiERIlpzSFnksd21ieCfNDfCs1/ cGs7EbuWh/xgYzEoqIXGTRzufPywGkHCmSsf5bCQRt3qBk854VFr2FPjz96Yabhb/Suec1 1mFDL3T3mIhuiTwp3sKT2hNfCWxVK0Q= Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4ZJ99D0Pg6z4f3jt8 for ; Thu, 20 Mar 2025 10:52:32 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.252]) by mail.maildlp.com (Postfix) with ESMTP id 5A41A1A06DC for ; Thu, 20 Mar 2025 10:52:49 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.101.6]) by APP3 (Coremail) with SMTP id _Ch0CgAHW8X_gttnYGGmGw--.42197S3; Thu, 20 Mar 2025 10:52:49 +0800 (CST) From: Kemeng Shi To: akpm@linux-foundation.org Cc: kasong@tencent.com, tim.c.chen@linux.intel.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 1/8] mm: swap: rename __swap_[entry/entries]_free[_locked] to swap_[entry/entries]_put[_locked] Date: Thu, 20 Mar 2025 19:48:22 +0800 Message-Id: <20250320114829.25751-2-shikemeng@huaweicloud.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20250320114829.25751-1-shikemeng@huaweicloud.com> References: <20250320114829.25751-1-shikemeng@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: _Ch0CgAHW8X_gttnYGGmGw--.42197S3 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_Gr1lx2IqxVAqx4xG 67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r126r1DMI IYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E 14v26r1j6r4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJV W8JwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjxUswZ2 DUUUU X-CM-SenderInfo: 5vklyvpphqwq5kxd4v5lfo033gof0z/ X-Stat-Signature: yomcit3q9hzp5endryqdne5n39dpuwes X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: BC80F100005 X-Rspam-User: X-HE-Tag: 1742439174-603384 X-HE-Meta: U2FsdGVkX18ycYvm7N/WFIfHX5IQl+/2ywd5SuFywCePQZKlbiVyEA38kvucVUUZSv7D+lQ0AjIihTpi71ljNgd7k1JFjVhZ0e4jngMnClS+CKQOY5sN4eBfZ7ONpDA3Li/IZNSaGI5rk0dLaBPRBG6cZaO7++vrNaCa85aWK+Bq5mv6Lu7QUUuSfaH+kNjoRYuQrMiAWGoIKmBWE6vuwZcMJXJT0MvhVSbtqG0dLJfv03B9yI+IftvZQKArIlPkTi27+Dp4mqY1HInhY/AZWY9Dk+qIAN2nnTT4D4aiK5d8HbnDb0ouLEjEAODOigy54aum+FV5DeAVIlbQ9VSAd9Ui+KHT6CE8l8fitFZWPYy2YTZTFhCh4aW1WHX7gJtv7Bq7ibDIfl5n3GPJCiZYGR4IqzBBQqFuz6lAwoEtBJ8yfWarwWX62QLJmNRKdA/gqtDdyuxEf/UiyBmLELb8lj4D/JpcUkID7/TzjT7WVa+rq4g4t71imJS0HG4FoRSPMsfhPAmvAdO/sXwhqpu5C+bOLe7lkmyEM+rExUaLJeb6GNctmVjJk9rvyXMOUH46ScaYHJfChwPghi6xaYbts7lAeidvv1lY0Zjob1T5AZmcijxgKeTwP1ep+GAl++xLQ6kgAmAhHNp0rlgkmBgIZwQmYW9Y+ztUfdVIvZgrq/cYi9e7UkZw8ZiyI3db4skY/9KHzEDYIwTIgqTPAALUjhBc0hMQbe1J5ySWTUd4zI/fl+Of6lFcST1otev+rAPdkwUeOSzBMvXYgFDxKPMl79MLlGHrgj0vTaBAcHkJcHmAtIH6R5fuHRusTJ9Hri444/C79MNghDP5dYRBzMuWN5h4ChaW5a0BPg+zi09s9zjHWRYtDItHRKqvOOo616FMLKD7v2xtDMl8RGz2bchXlkG2wTEHxCVgUPJRxzEub6HgbITvvvc5LloFY9C5pFqkOIgHXzZ3gDiSDRbxDuT 9vnpF5Eq IPKCGZkJpx5FJ2JeIPHFVh8WdkHCZiKYZypCXmlXLQO0XF1HM3Frk/HncnU23o+8MNnykI2pOyU5EoY5ZuMCoGCKGkwHtMWhE+68ZxACiqp2gLNg4krdTiRFNbJf25U2jRuvRq5dGoeyLw/udl0yogBzPQxZzSvpOWnNaeL1Mxpjn+MIWP6hkg/zisWCpUdrOoJ8WkZ9vyJfYdaJx/s4oTMgMW5Ftjp37gv67AKP5RqRV69E= 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,