From mboxrd@z Thu Jan 1 00:00:00 1970 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 C2016C282EC for ; Fri, 14 Mar 2025 08:39:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BAC9F280004; Fri, 14 Mar 2025 04:39:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B5A9E280001; Fri, 14 Mar 2025 04:39:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9FD1A280004; Fri, 14 Mar 2025 04:39:21 -0400 (EDT) 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 80545280001 for ; Fri, 14 Mar 2025 04:39:21 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 1AB00160D9B for ; Fri, 14 Mar 2025 08:39:22 +0000 (UTC) X-FDA: 83219507364.27.E76800E Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) by imf14.hostedemail.com (Postfix) with ESMTP id 259CF100006 for ; Fri, 14 Mar 2025 08:39:17 +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.56 as permitted sender) smtp.mailfrom=shikemeng@huaweicloud.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1741941560; a=rsa-sha256; cv=none; b=pq7u5NUiL1i7HyM84xk3d+qgyIa/ekZcOiZCF4wmeyZqc72jpkI7U3cNtc6k65aTgimhWm K52Hy3aLA6zty2UX8Uk0iK2sExG7YEyyNiG9Yy7MuEHVnTzkfdwF6b9Z/TuI78Rk5n8i4V o1RkfxLwkEjM00EJnIsSCO1mzxC+Qgw= 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.56 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=1741941560; 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=ojhWYZBBH5Jl7+cM7LNlSaRX1up3c//v/2z16wT5y0U=; b=rO0fZ7YyGIb4I3T0XwaqG+HQRQAJtcQJbF1hHlK22eTJ+fxx7cYYBhHEUnXo6MMk+A1zig gCFTaDM7xvcPiTwGDo/tmAj0KrlM9jI2oSBaFXCTrewaUGll1EM6CZogr33IdCrVfxWvsZ ggki/81BjRTPRzdySgYUQS+b40caMag= Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4ZDd7Z06Zhz4f3jXP for ; Fri, 14 Mar 2025 16:38:50 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.128]) by mail.maildlp.com (Postfix) with ESMTP id 794711A07BD for ; Fri, 14 Mar 2025 16:39:12 +0800 (CST) Received: from [10.174.178.129] (unknown [10.174.178.129]) by APP4 (Coremail) with SMTP id gCh0CgBnyl4v69NnV4_UGQ--.7807S2; Fri, 14 Mar 2025 16:39:12 +0800 (CST) Subject: Re: [PATCH 2/9] mm: swap: factor out the actual swap entry freeing logic to new helper To: Kairui Song Cc: akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20250313210515.9920-1-shikemeng@huaweicloud.com> <20250313210515.9920-3-shikemeng@huaweicloud.com> From: Kemeng Shi Message-ID: <2ca0c9be-765a-4fa1-c74b-62499cab7ce4@huaweicloud.com> Date: Fri, 14 Mar 2025 16:39:10 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.9.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-CM-TRANSID:gCh0CgBnyl4v69NnV4_UGQ--.7807S2 X-Coremail-Antispam: 1UD129KBjvJXoWxWFyrZw1rGFyDKFWrKw1ftFb_yoWrWr48pF 9IqFn0kF4kJryxJr4aqw1qqrZIvw4fKF18XFnrKw1fAasIyr97tFyDArWY9rykAwn7C34F v3WDK3sxuF4YyrDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUyCb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4 vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7Cj xVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x 0267AKxVW0oVCq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG 6I80ewAv7VC0I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFV Cjc4AY6r1j6r4UM4x0Y48IcVAKI48JMxk0xIA0c2IEe2xFo4CEbIxvr21l42xK82IYc2Ij 64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x 8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r126r1DMIIYrxkI7VAKI48JMIIF0xvE 2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r1j6r4UMIIF0xvE42 xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF 7I0E14v26r1j6r4UYxBIdaVFxhVjvjDU0xZFpf9x07UE-erUUUUU= X-CM-SenderInfo: 5vklyvpphqwq5kxd4v5lfo033gof0z/ X-Rspam-User: X-Rspamd-Queue-Id: 259CF100006 X-Stat-Signature: 36drwagqyqeoxdshxyosw8rs6xbq4pt7 X-Rspamd-Server: rspam06 X-HE-Tag: 1741941557-720308 X-HE-Meta: U2FsdGVkX1+jjaelz9s4+0IYFB7r6+B6N7k4bfGAokF6bG8bRlfOweftzXhutNphRKcgYj1ZO77uy077So3cvfk3x/+vWPnlp1aAl8hOzMcPZNLPo3rqU6FggErsHOxkESfS6yceiqQrly7M4UeOlf/qy8MNG392ZMuWdYu97jMa/tsXU4ggN59jFKjUKzH0vSZEQ5ehy/o4WNcqahpPLN4YCh1Vfet0irhj4DEvb3rn0mR7x141ecqjNiSsn+NPw80ml2CWL1hQsaPYvZ6OOPXs62SM94cxvMJo29Se9UMwPtW7CNP3WG4rcxHdyuOWgpt2resVdtTjxUNjemRRkDkuFsk7U15gGiqyvQjchc39tpbqlfMYK4BGz+1LyE59zsLUj3s1k6FykRV/YuJilRwJpTYxK+GPjV0PyIFHGlZd9G4REt4OV1IO35tYCOWM+vjNG/0SUWexeCpE1ax/fW1Ac63PjECzD1FdM+P3nD3mMqdJUZhvIKheVndV7tA4eiwysB3moJUTU9Xi349YWz8z5wo4wMD5iVS/belrCXG+OUbjliVs09o2gspHs37/YS/HSKMSJ/et4rojfWijb30uSfuviwn9yuGZLvEbgETrdwLtp3CkhJ3Licp02bZS8uZq9HgiU8kn8ZxyGrmDf7FGGP9Yh5M7iE2OJ+XhgzDNhBUS0BoTaXtJmAd3GwrQ4p7UPkno/+URtQ7Blci/Xf+NC+qmqsaX98+bRuCfrpKfgDcdf+rAJnqgJfWUu6rB2h0F+bqiYyYsY2sHjqwXy9bmW+zXIzyDAmkl+fmXr0zLCF83aixLH+vS9bAWbMCBK7bW/1doAvE98SnfibUANaSk8avlmPsUkYoD4fx2o9+8TVW0K+3kLrZR3Xu74bg2oU3ekAHu3deAE2PNv+v/CDxmiL5DJUPeEkv3NHtoepYjAU95opZTsmR1bcDZxxPpt0Z2tD5Hm91oqqAP7Cr YCcPtmJV wZZbQYQckk3ALh/ILrzTYRiBmWLp6FTTnWe4CHk5ss4OxzoupmqsOWg+hZ5DvRVawqqQXl4V03IMQKOL+XnEBo3QjF4+3YHghiewDcqApu7PpOS+/jQTeDk2b0vxIfq8YLod/zsQkHIdKeYzxXIpKaCG2whY75i63VVPi5P7ugtSATQuEn5PWDgzVhyRhDV6NpOs5yFFWJaXS3/Y= 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: on 3/14/2025 3:47 PM, Kairui Song wrote: > On Fri, Mar 14, 2025 at 3:32 PM Kemeng Shi wrote: >> >> on 3/14/2025 1:42 AM, Kairui Song wrote: >>> On Thu, Mar 13, 2025 at 8:09 PM Kemeng Shi wrote: >>>> >>>> Factor out the actual swap entry freeing logic to new helper >>>> __swap_entries_free(). >>>> This allow us to futher simplify other swap entry freeing code by >>>> leveraging __swap_entries_free() helper function. >>>> >>>> Signed-off-by: Kemeng Shi >>>> --- >>>> mm/swapfile.c | 30 ++++++++++++++++++++---------- >>>> 1 file changed, 20 insertions(+), 10 deletions(-) >>>> >>>> diff --git a/mm/swapfile.c b/mm/swapfile.c >>>> index 5a775456e26c..7c886f9dd6f9 100644 >>>> --- a/mm/swapfile.c >>>> +++ b/mm/swapfile.c >>>> @@ -1347,6 +1347,25 @@ static struct swap_info_struct *_swap_info_get(swp_entry_t entry) >>>> return NULL; >>>> } >>>> >>>> +static inline void __swap_entries_free(struct swap_info_struct *si, >>>> + struct swap_cluster_info *ci, >>>> + swp_entry_t entry, unsigned int nr_pages) >>>> +{ >>>> + unsigned long offset = swp_offset(entry); >>>> + >>>> + VM_BUG_ON(cluster_is_empty(ci)); >>>> + VM_BUG_ON(ci->count < nr_pages); >>>> + >>>> + ci->count -= nr_pages; >>>> + mem_cgroup_uncharge_swap(entry, nr_pages); >>>> + swap_range_free(si, offset, nr_pages); >>>> + >>>> + if (!ci->count) >>>> + free_cluster(si, ci); >>>> + else >>>> + partial_free_cluster(si, ci); >>>> +} >>>> + >>>> static unsigned char swap_entry_put_locked(struct swap_info_struct *si, >>>> unsigned long offset, >>>> unsigned char usage) >>>> @@ -1525,22 +1544,13 @@ static void swap_entry_range_free(struct swap_info_struct *si, >>>> >>>> /* It should never free entries across different clusters */ >>>> VM_BUG_ON(ci != offset_to_cluster(si, offset + nr_pages - 1)); >>>> - VM_BUG_ON(cluster_is_empty(ci)); >>>> - VM_BUG_ON(ci->count < nr_pages); >>>> >>>> - ci->count -= nr_pages; >>>> do { >>>> VM_BUG_ON(*map != SWAP_HAS_CACHE); >>>> *map = 0; >>>> } while (++map < map_end); >>>> >>>> - mem_cgroup_uncharge_swap(entry, nr_pages); >>>> - swap_range_free(si, offset, nr_pages); >>>> - >>>> - if (!ci->count) >>>> - free_cluster(si, ci); >>>> - else >>>> - partial_free_cluster(si, ci); >>>> + __swap_entries_free(si, ci, entry, nr_pages); >>>> } >>>> >>>> static void cluster_swap_free_nr(struct swap_info_struct *si, >>>> -- >>>> 2.30.0 >>>> >>>> >>> >>> Hi Kemeng, >> Hello Kairui, >> >> Thanks for feedback. >>> >>> This patch is a bit too trivial to be a standalone one, you can fold >>> it with the later one easily. Also you may want to carry the >>> VM_BUG_ON(ci != offset_to_cluster(si, offset + nr_pages - 1)); check >>> as well. >> Sure, I will do this in next version. >>> >>> But, that is basically just renaming swap_entry_range_free, you may >>> just remove the HAS_CACHE check as you rename it, that way the changes >>> should be cleaner. >>> >> Sorry, I don't quite follow. Are you suggesting that should fold this >> patch to later one which removes the HAS_CACHE check and renmae the >> swap_entry_range_free. > > Hi, > > Just some of my nitpicks :) > > After you move these parts out of swap_entry_put_locked, there is > almost nothing left in swap_entry_put_locked except an "open coded > memset". And in your next patch (also after the whole series), all > callers of __swap_entries_free will have to call an "open coded > memset" anyway, so these changes seem redundant and could be improved. Right, we can simply use swap_entries_free() instead of __swap_entries_free() int swap_entry_put_locked() after the whole series and this change seems not necessary. Will improve this in next version. > > BTW your next patch has a typo in the commit message: > s/__swap_entriy_free/__swap_entries_free/g. Will fix this in next version. Thanks, Kemeng > >> >> Thanks, >> Kemeng >> >