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 17CD0C282EC for ; Tue, 18 Mar 2025 01:29:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1A145280002; Mon, 17 Mar 2025 21:29:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 12B2A280001; Mon, 17 Mar 2025 21:29:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EE789280002; Mon, 17 Mar 2025 21:29:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id CC98D280001 for ; Mon, 17 Mar 2025 21:29:20 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 05D08A9306 for ; Tue, 18 Mar 2025 01:29:22 +0000 (UTC) X-FDA: 83232938964.09.EBA5475 Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) by imf21.hostedemail.com (Postfix) with ESMTP id C85811C0004 for ; Tue, 18 Mar 2025 01:29:16 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=none; spf=pass (imf21.hostedemail.com: domain of shikemeng@huaweicloud.com designates 45.249.212.56 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=1742261360; 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=4YDw3qxCNVQcwOOWwFIaVptJ+ZfcYpboFqcS4RHp4iU=; b=PPWnpNQBg+E6qSggD5dFcqrqeY6BtEnMlxjJyfVCuqk76e7Kp9hjlpbCc3cRw8wLOOlMyA 4hXWlesIBOoUO9HFpeP55bFIPqgHTl8/6oToOqKJbun7ig9k841ThOJETMUhLkM8YPGJJo 1cbIWnX4jhIvQWpv1rkTqCGtFHnU080= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=none; spf=pass (imf21.hostedemail.com: domain of shikemeng@huaweicloud.com designates 45.249.212.56 as permitted sender) smtp.mailfrom=shikemeng@huaweicloud.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1742261360; a=rsa-sha256; cv=none; b=X2S4WQTmF0HYi+fTq2c0vQ0aOYhpo38MWLSEV6QFh/xEkJf0+OFBcMEu6dRfyPIJKAKy2B frA+cFaDsLOvHt2WAPKhewBtrGvjnHbDQdRUyQESQdVWaAT6+2/wQrIrtC8edFRSVvNGhN TTvg9S0XpVM9f/F25Y+6SpL5W+R8+AY= Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4ZGvPX6D3zz4f3jY9 for ; Tue, 18 Mar 2025 09:28:48 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.128]) by mail.maildlp.com (Postfix) with ESMTP id 766D61A12EF for ; Tue, 18 Mar 2025 09:29:11 +0800 (CST) Received: from [10.174.178.129] (unknown [10.174.178.129]) by APP4 (Coremail) with SMTP id gCh0CgDnlltlzNhnzv4+Gw--.16554S2; Tue, 18 Mar 2025 09:29:11 +0800 (CST) Subject: Re: [PATCH 0/9] Minor cleanups and improvements to swap freeing code To: Tim Chen , akpm@linux-foundation.org Cc: kasong@tencent.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20250313210515.9920-1-shikemeng@huaweicloud.com> <94a5ebb9bd4c8076f23489e014462ac6d169cae0.camel@linux.intel.com> From: Kemeng Shi Message-ID: <91963cc7-a02d-08ff-6063-a1d97e69d8f6@huaweicloud.com> Date: Tue, 18 Mar 2025 09:29:09 +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: <94a5ebb9bd4c8076f23489e014462ac6d169cae0.camel@linux.intel.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-CM-TRANSID:gCh0CgDnlltlzNhnzv4+Gw--.16554S2 X-Coremail-Antispam: 1UD129KBjvJXoWxurW8Cw4UJr47Gw4UJw1xGrg_yoW5Zr18pF Wag3ZxKF1kXr1Iyrn7Aw10qw1Fq3yrKFyUG3WUur1rZ3ZxGF1ruryvyrZ5CFyDu395X34U tF48K34Uu3ZYyFJanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUkEb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4 vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7Cj xVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x 0267AKxVW0oVCq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG 6I80ewAv7VC0I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFV Cjc4AY6r1j6r4UM4x0Y48IcVAKI48JMxk0xIA0c2IEe2xFo4CEbIxvr21lc7CjxVAaw2AF wI0_JF0_Jw1l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4 xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r126r1D MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I 0E14v26r1j6r4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWU JVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r1j6r4UYxBIdaVFxhVjvjDU0xZFpf9x07jjVb kUUUUU= X-CM-SenderInfo: 5vklyvpphqwq5kxd4v5lfo033gof0z/ X-Rspam-User: X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: C85811C0004 X-Stat-Signature: fpeuxbgqgxjx3wpu8wuzsbkct3bisobx X-HE-Tag: 1742261356-274072 X-HE-Meta: U2FsdGVkX19Rd8tIov9hIKG8RiQAxOmWCA4JREG2GdrLDnRiHRaUcdGHQes7XN3HZPPfWddy8CVGlTLXSyLNaBUROtFWN8pNKDAYHprULhdude25WmPO0sQlANnUaF2Sk8mlS71V1lT6IXzKbvXFMaBNDxJkDqQccJuGrGlDko3aCUmE0/VcRR3RQgwU+FIrV0iIiifELWujDEIv1W4BOIRRw1Iu+lf8HIdVWznhqZ1FC8ePUYzd8M8J6r6E6lIbx3eCpoWhs/OuiJUsqKPVqY1bles67LRNWdDR4g/1+NlsU1qd9xbfjv7ldXPT5Kq3ktoP/TSjdbxsaqyPeeo+oDUQP9rVaUB/+JYEK6J5f98xIyl9PN3x61Vb7HfBicAkrJzTcDQ9Edf6nlsLFcg8bbE7F7dsbANm7UMlpgx68Yb3Pk9uJ/SMYGGjbApAptSM2znPdwFm8J5Xu1KmJq3No1suBvxKZwH0q4ALx8GeeKk66O5kp0seVNCwmyyIsKx7ChrSINceGJYLCLiSA6mTsaMkdRECKon/Kz5w4N8qTSesmZUyDGkWAMDXctIgmvFxybrszu18ewTcITKw6+nJYOR7vm9hvJTh0sUpesmVHHgN7gbjhNVhVDFABZuQ0sEyQIl/za7sW6lu7Cv73YhepBA6geO/E6BWLacBo8etUMCYNA7VwjkCbiKLIdjAIOPtE1LQoHnjrz34z3V/LFh+nmtKmiDnt9uxFJM6euv9qmSxfFn0mJ+UMHvmS55f27hg5jbG9Tbbcs8+zfxr2ECfCq17emlDGi2XyYGZdxHXYnrC00ZheMLO5aIxKCohp5ht1z/uO0bmHRqznmn+/RNVOkayie1pxk6ivL9wh7Bc2s8WtyZZjzg5py0JynU49Utsd8OAda9N0W9sycc1HOxc8n6pM7+dj1WzOC3gsb0LVBg1R+cKpLwGH2cY9Ilihm7K96ZHYFvFqnud0cav6I2 7sxM0Y1h 3DTx3U2jJ6ED7BcuqNScAqHLL79XJrGV0RXGKxGpZMBHPyRvrR9XaO7O+3gwHuPg/WFQCAH5hHJ4PrdS80x69AsqJhi8E58XgQUubqq69rIzJz3kpzvxcK1vW9TFOhsMsQaCzxaqAfwNjbY0= 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/15/2025 4:27 AM, Tim Chen wrote: > On Fri, 2025-03-14 at 05:05 +0800, Kemeng Shi wrote: >> Hi All, >> This series contains some cleanups and improvements which are made >> during learning swapfile. Here is a summary of the changes: > Hello, > Nice work> >> 1. Function nameing improvments. >> -Use "put" instead of "free" to name functions which only do actual free >> when count drops to zero. >> -Use "entry" to name function only frees one swap slot. Use "entries" to >> name function could may free multi swap slots within one cluster. Use >> "_nr" suffix to name function which could free multi swap slots spanning >> cross multi clusters. > > Will be nice to add some comments in the code about functions with _nrĀ  > crossing the cluster boundaries and those without stay within a cluster. Thanks for reviewing and all advises to this series. Will improve in next version. > >> 2. Eliminate the need to set swap slot to intermediate SWAP_HAS_CACHE >> value before do actual free by using swap_entry_range_free() >> 3. Add helpers swap_entries_put_map() and swap_entries_put_cache() as a >> general-purpose routine to free swap entries within a single cluster >> which will try batch-remove first and fallback to put eatch entry >> indvidually with cluster lock acquired/released only once. By using >> these helpers, we could remove repeated code, levarage batch-remove in >> more cases and aoivd to acquire/release cluster lock for each single >> swap entry. > > Wonder if the batching shows up in any swap performance improvement I have a simple test which is roughly as following: #define SIZE 1024*1024*1024 #define HP_SIZE 2 * 1024 * 1024 p = mmap(...,SIZE,...) madvise(p, SIZE, MADV_HUGEPAGE) memset(p, 0x11, SIZE); /* alloc page */ madvise(p, SIZE, MADV_PAGEOUT); /* swap out */ gettimeofday(&tv_b, NULL); for (j = 0; j < SIZE; j+= HP_SIZE) { ((char *)p)[j] = 0; /* swap in and free swap entry */ } The time for swap-in and free swap entry shows no significant change. Since this is more of a cleanup series, no further testing has been conducted yet. I would appreciate it if you have any additional test cases that could benefit from batching. Thank, Kemeng . > > Tim > >> >> Kemeng Shi (9): >> mm: swap: rename __swap_[entry/entries]_free[_locked] to >> swap_[entry/entries]_put[_locked] >> mm: swap: factor out the actual swap entry freeing logic to new helper >> mm: swap: use __swap_entry_free() to free swap entry in >> swap_entry_put_locked() >> mm: swap: remove unneeded VM_BUG_ON(*map != SWAP_HAS_CACHE) in >> swap_entry_range_free() >> mm: swap: use swap_entries_free() drop last 1 flag in >> swap_entries_put_nr() >> mm: swap: drop last SWAP_MAP_SHMEM flag in batch in >> swap_entries_put_nr() >> mm: swap: free each cluster individually in swap_entries_put_map_nr() >> mm: swap: factor out helper to drop cache of entries within a single >> cluster >> mm: swap: replace cluster_swap_free_nr() with >> swap_entries_put_[map/cache]() >> >> mm/swapfile.c | 173 +++++++++++++++++++++++++------------------------- >> 1 file changed, 86 insertions(+), 87 deletions(-) >> > >