From patchwork Sun Apr 28 10:06:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: alexs@kernel.org X-Patchwork-Id: 13645976 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 E83E9C4345F for ; Sun, 28 Apr 2024 10:03:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1EFB06B0087; Sun, 28 Apr 2024 06:03:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1A1C06B0088; Sun, 28 Apr 2024 06:03:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F35B66B0089; Sun, 28 Apr 2024 06:03:13 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id D45AC6B0087 for ; Sun, 28 Apr 2024 06:03:13 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 6797B120E1E for ; Sun, 28 Apr 2024 10:03:11 +0000 (UTC) X-FDA: 82058502582.17.FEEF1CB Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf02.hostedemail.com (Postfix) with ESMTP id 58EDB8000B for ; Sun, 28 Apr 2024 10:03:08 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=svEjzXYQ; spf=pass (imf02.hostedemail.com: domain of alexs@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=alexs@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1714298590; a=rsa-sha256; cv=none; b=PgmF8/csQx6/SL6Uf6Gy3Xk95F3sVGGVC/uzP4meOPvxkpPgC2zloOh4mLlGTBLD+I7lM2 9oFWavpOPBo2ce4sZ39ie+q6eWTRCJ9pq4Y4kzEIZKf2bRFXqjV7V3WZ9DrXSo136u1VKg THcEjF9AAiVaL9taNZ3HP4LzLGte1uw= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=svEjzXYQ; spf=pass (imf02.hostedemail.com: domain of alexs@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=alexs@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1714298590; 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:references:dkim-signature; bh=19N+NWSQcEOwgwXo00Qxt0YAxPspAmBgr0IM0ASXgoU=; b=WhEARuDiUhNMkAlHaUp8LFtZMMqWu3WiL0Zlj1B5NgTFswzXFxtGI/dBIihD0/PAxR2PcK azriUInIVwV9HVma1jmCIPwCduyJNWLdZxSC2I65nEqMNuc4rOODkm81qcYTYBKqz3aT23 LawU1CmFwGmV1fVoE0ZslEQEX7fuFQI= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id CF865CE0185; Sun, 28 Apr 2024 10:03:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A0D9AC113CC; Sun, 28 Apr 2024 10:03:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714298583; bh=HHMumcOA0H9IUBHkmzzjX+ZWQGYMXSboQb1ob6VnGX0=; h=From:To:Cc:Subject:Date:From; b=svEjzXYQEbgXg3LvM1M3DpRi706lXfPWsUc9ig1+xRxOLV/8FiH50xiTLPkEjm/zQ sOrixVduy/1RS3bGAkpgM+rL/3H9zErUBN4f4ndGalpE/VoHe+EACMAKWf6I5q7BZT HQEUg4vEiSZaUxgQn5052xdW3M6qvFmfQywYvFeDaWBf9jIRz+52oi85sN5FiHzSJv XMy8wKI008t/us8P1Om08taBdd7ts4IjF83eA8mPmEqdJlG5CGoZHQi/L+Gapqgcjf Xecu3YuZ/Cbnd+/n5h3AL7XfM9Bph9z7fiFugJDiJm3kDjoD91/IisPbXOODrr53ox aXGkgid45qLPA== From: alexs@kernel.org To: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, willy@infradead.org, izik.eidus@ravellosystems.com Cc: "Alex Shi (tencent)" , David Hildenbrand Subject: [PATCH 1/4] mm/ksm: rename mm_slot members to ksm_slot for better readability. Date: Sun, 28 Apr 2024 18:06:15 +0800 Message-ID: <20240428100619.3332036-1-alexs@kernel.org> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-Stat-Signature: k7pkdqejp88yz1j4moiu5nbbnbojykqk X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 58EDB8000B X-HE-Tag: 1714298588-532740 X-HE-Meta: U2FsdGVkX1+XQxMqZJP4WdesLbpK4cNy43vgXjySOsel9Apo7eHWwoPqSQ4PRHBWY8ppsf/Y2B5susv/qe0t24M2qIRVgX8jcuxN9jhKvrVMOFtZqc97jZe0t3BWf3tXW558MOGIFCoAV82gUwZGBvTFRTNBTa+ddM+/OSpeyrJAgjlEIJmR72CPeAjePCys+ojU2tXEHmMo4DWfZ5ldPLpemh0EZs95goLYHddFOxRSRaN8pfEoQSjHiN8PP/wMap2oP0BlT8bv4uZYaGDynAo2wH3OSf0AraH1cVoEfINJnJXnLu36IzPOPoCtbn5rEdo2wI4rA7w8ip0q0VSApRz7+aAuBzNKLfNjcIDKjupL9bUjTDsUhO09carsTwu1RHwtuMiEVCR7f2gCg/ifD2gV1fWmw5Qbiz2glVRBKkBRISdVxM6LzjPhkjngskg9M8ff/lqg68Ylxzc5fmgeqcNM4+aqPVQ2gwZLBl7YS17vpUFDu0uJZukZhiWSCIE4dJNmadySsnJbo79J+mHqtXlxDO+4OKkpESzwXMFVSFUZJNiMWgTHIfXMx2CIR8Xku0wgjbCFUMLZCcJcvoSwKDtUoRKbVOjYdnYKJglVdLRr3nEv34eBlKYL5sv05mOjXsPQYFV8uM0k0aWY35sUU86xBP0evIQAOP+szPW0QobfbzRDtbFJd/uOKbyH5Vpz4kU1I2Wid1SIl3ADoQfBb96NaJsNCHBWrZgUEt2asozdWshoFJc2YEcpy09AUR56Xir/bgDSE4M4gNGyd6mWwX/N2F2xvmgwys548bi/HS5iMVvadEni3iAe+ipehQwFvhcShy/z/JITOgvNsopvlRyPUm8CV+uCRjgP4g5NA/nim81SEaPjE0I6EUg/5lsAIZx79LygQEuMHcVHdhA1hIWwzM9buGANGEnQCIWnCb3wfj9tUm9X2Pvq/d41ddT4OKpx8Pj3RGloL4yo19t srNaM8Mv xMDOY 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: "Alex Shi (tencent)" mm_slot is a struct of mm, and ksm_mm_slot is named the same again in ksm_scan struct. Furthermore, the ksm_mm_slot pointer is named as mm_slot again in functions, beside with 'struct mm_slot' variable. That makes code readability pretty worse. struct ksm_mm_slot { struct mm_slot slot; ... }; struct ksm_scan { struct ksm_mm_slot *mm_slot; ... }; int __ksm_enter(struct mm_struct *mm) { struct ksm_mm_slot *mm_slot; struct mm_slot *slot; ... So let's rename the mm_slot member to ksm_slot in ksm_scan, and ksm_slot for ksm_mm_slot* type variables in functions to reduce this confusing. struct ksm_scan { - struct ksm_mm_slot *mm_slot; + struct ksm_mm_slot *ksm_slot; Signed-off-by: Alex Shi (tencent) Cc: David Hildenbrand --- mm/ksm.c | 84 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/mm/ksm.c b/mm/ksm.c index 486c9974f8e2..d2c4eb98816d 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -131,7 +131,7 @@ struct ksm_mm_slot { /** * struct ksm_scan - cursor for scanning - * @mm_slot: the current mm_slot we are scanning + * @ksm_slot: the current ksm_slot we are scanning * @address: the next address inside that to be scanned * @rmap_list: link to the next rmap to be scanned in the rmap_list * @seqnr: count of completed full scans (needed when removing unstable node) @@ -139,7 +139,7 @@ struct ksm_mm_slot { * There is only the one ksm_scan instance of this cursor structure. */ struct ksm_scan { - struct ksm_mm_slot *mm_slot; + struct ksm_mm_slot *ksm_slot; unsigned long address; struct ksm_rmap_item **rmap_list; unsigned long seqnr; @@ -187,7 +187,7 @@ struct ksm_stable_node { /** * struct ksm_rmap_item - reverse mapping item for virtual addresses - * @rmap_list: next rmap_item in mm_slot's singly-linked rmap_list + * @rmap_list: next rmap_item in ksm_slot's singly-linked rmap_list * @anon_vma: pointer to anon_vma for this mm,address, when in stable tree * @nid: NUMA node id of unstable tree in which linked (may not match page) * @mm: the memory structure this rmap_item is pointing into @@ -242,7 +242,7 @@ static struct ksm_mm_slot ksm_mm_head = { .slot.mm_node = LIST_HEAD_INIT(ksm_mm_head.slot.mm_node), }; static struct ksm_scan ksm_scan = { - .mm_slot = &ksm_mm_head, + .ksm_slot = &ksm_mm_head, }; static struct kmem_cache *rmap_item_cache; @@ -1205,11 +1205,11 @@ static int unmerge_and_remove_all_rmap_items(void) spin_lock(&ksm_mmlist_lock); slot = list_entry(ksm_mm_head.slot.mm_node.next, struct mm_slot, mm_node); - ksm_scan.mm_slot = mm_slot_entry(slot, struct ksm_mm_slot, slot); + ksm_scan.ksm_slot = mm_slot_entry(slot, struct ksm_mm_slot, slot); spin_unlock(&ksm_mmlist_lock); - for (mm_slot = ksm_scan.mm_slot; mm_slot != &ksm_mm_head; - mm_slot = ksm_scan.mm_slot) { + for (mm_slot = ksm_scan.ksm_slot; mm_slot != &ksm_mm_head; + mm_slot = ksm_scan.ksm_slot) { VMA_ITERATOR(vmi, mm_slot->slot.mm, 0); mm = mm_slot->slot.mm; @@ -1238,7 +1238,7 @@ static int unmerge_and_remove_all_rmap_items(void) spin_lock(&ksm_mmlist_lock); slot = list_entry(mm_slot->slot.mm_node.next, struct mm_slot, mm_node); - ksm_scan.mm_slot = mm_slot_entry(slot, struct ksm_mm_slot, slot); + ksm_scan.ksm_slot = mm_slot_entry(slot, struct ksm_mm_slot, slot); if (ksm_test_exit(mm)) { hash_del(&mm_slot->slot.hash); list_del(&mm_slot->slot.mm_node); @@ -1260,7 +1260,7 @@ static int unmerge_and_remove_all_rmap_items(void) error: mmap_read_unlock(mm); spin_lock(&ksm_mmlist_lock); - ksm_scan.mm_slot = &ksm_mm_head; + ksm_scan.ksm_slot = &ksm_mm_head; spin_unlock(&ksm_mmlist_lock); return err; } @@ -2565,7 +2565,7 @@ static bool should_skip_rmap_item(struct page *page, static struct ksm_rmap_item *scan_get_next_rmap_item(struct page **page) { struct mm_struct *mm; - struct ksm_mm_slot *mm_slot; + struct ksm_mm_slot *ksm_slot; struct mm_slot *slot; struct vm_area_struct *vma; struct ksm_rmap_item *rmap_item; @@ -2575,8 +2575,8 @@ static struct ksm_rmap_item *scan_get_next_rmap_item(struct page **page) if (list_empty(&ksm_mm_head.slot.mm_node)) return NULL; - mm_slot = ksm_scan.mm_slot; - if (mm_slot == &ksm_mm_head) { + ksm_slot = ksm_scan.ksm_slot; + if (ksm_slot == &ksm_mm_head) { advisor_start_scan(); trace_ksm_start_scan(ksm_scan.seqnr, ksm_rmap_items); @@ -2616,23 +2616,23 @@ static struct ksm_rmap_item *scan_get_next_rmap_item(struct page **page) root_unstable_tree[nid] = RB_ROOT; spin_lock(&ksm_mmlist_lock); - slot = list_entry(mm_slot->slot.mm_node.next, + slot = list_entry(ksm_slot->slot.mm_node.next, struct mm_slot, mm_node); - mm_slot = mm_slot_entry(slot, struct ksm_mm_slot, slot); - ksm_scan.mm_slot = mm_slot; + ksm_slot = mm_slot_entry(slot, struct ksm_mm_slot, slot); + ksm_scan.ksm_slot = ksm_slot; spin_unlock(&ksm_mmlist_lock); /* * Although we tested list_empty() above, a racing __ksm_exit * of the last mm on the list may have removed it since then. */ - if (mm_slot == &ksm_mm_head) + if (ksm_slot == &ksm_mm_head) return NULL; next_mm: ksm_scan.address = 0; - ksm_scan.rmap_list = &mm_slot->rmap_list; + ksm_scan.rmap_list = &ksm_slot->rmap_list; } - slot = &mm_slot->slot; + slot = &ksm_slot->slot; mm = slot->mm; vma_iter_init(&vmi, mm, ksm_scan.address); @@ -2662,7 +2662,7 @@ static struct ksm_rmap_item *scan_get_next_rmap_item(struct page **page) if (PageAnon(*page)) { flush_anon_page(vma, *page, ksm_scan.address); flush_dcache_page(*page); - rmap_item = get_next_rmap_item(mm_slot, + rmap_item = get_next_rmap_item(ksm_slot, ksm_scan.rmap_list, ksm_scan.address); if (rmap_item) { ksm_scan.rmap_list = @@ -2687,7 +2687,7 @@ static struct ksm_rmap_item *scan_get_next_rmap_item(struct page **page) if (ksm_test_exit(mm)) { no_vmas: ksm_scan.address = 0; - ksm_scan.rmap_list = &mm_slot->rmap_list; + ksm_scan.rmap_list = &ksm_slot->rmap_list; } /* * Nuke all the rmap_items that are above this current rmap: @@ -2696,9 +2696,9 @@ static struct ksm_rmap_item *scan_get_next_rmap_item(struct page **page) remove_trailing_rmap_items(ksm_scan.rmap_list); spin_lock(&ksm_mmlist_lock); - slot = list_entry(mm_slot->slot.mm_node.next, + slot = list_entry(ksm_slot->slot.mm_node.next, struct mm_slot, mm_node); - ksm_scan.mm_slot = mm_slot_entry(slot, struct ksm_mm_slot, slot); + ksm_scan.ksm_slot = mm_slot_entry(slot, struct ksm_mm_slot, slot); if (ksm_scan.address == 0) { /* * We've completed a full scan of all vmas, holding mmap_lock @@ -2709,11 +2709,11 @@ static struct ksm_rmap_item *scan_get_next_rmap_item(struct page **page) * or when all VM_MERGEABLE areas have been unmapped (and * mmap_lock then protects against race with MADV_MERGEABLE). */ - hash_del(&mm_slot->slot.hash); - list_del(&mm_slot->slot.mm_node); + hash_del(&ksm_slot->slot.hash); + list_del(&ksm_slot->slot.mm_node); spin_unlock(&ksm_mmlist_lock); - mm_slot_free(mm_slot_cache, mm_slot); + mm_slot_free(mm_slot_cache, ksm_slot); clear_bit(MMF_VM_MERGEABLE, &mm->flags); clear_bit(MMF_VM_MERGE_ANY, &mm->flags); mmap_read_unlock(mm); @@ -2725,14 +2725,14 @@ static struct ksm_rmap_item *scan_get_next_rmap_item(struct page **page) * spin_unlock(&ksm_mmlist_lock) run, the "mm" may * already have been freed under us by __ksm_exit() * because the "mm_slot" is still hashed and - * ksm_scan.mm_slot doesn't point to it anymore. + * ksm_scan.ksm_slot doesn't point to it anymore. */ spin_unlock(&ksm_mmlist_lock); } /* Repeat until we've completed scanning the whole list */ - mm_slot = ksm_scan.mm_slot; - if (mm_slot != &ksm_mm_head) + ksm_slot = ksm_scan.ksm_slot; + if (ksm_slot != &ksm_mm_head) goto next_mm; advisor_stop_scan(); @@ -2968,15 +2968,15 @@ EXPORT_SYMBOL_GPL(ksm_madvise); int __ksm_enter(struct mm_struct *mm) { - struct ksm_mm_slot *mm_slot; + struct ksm_mm_slot *ksm_slot; struct mm_slot *slot; int needs_wakeup; - mm_slot = mm_slot_alloc(mm_slot_cache); - if (!mm_slot) + ksm_slot = mm_slot_alloc(mm_slot_cache); + if (!ksm_slot) return -ENOMEM; - slot = &mm_slot->slot; + slot = &ksm_slot->slot; /* Check ksm_run too? Would need tighter locking */ needs_wakeup = list_empty(&ksm_mm_head.slot.mm_node); @@ -2996,7 +2996,7 @@ int __ksm_enter(struct mm_struct *mm) if (ksm_run & KSM_RUN_UNMERGE) list_add_tail(&slot->mm_node, &ksm_mm_head.slot.mm_node); else - list_add_tail(&slot->mm_node, &ksm_scan.mm_slot->slot.mm_node); + list_add_tail(&slot->mm_node, &ksm_scan.ksm_slot->slot.mm_node); spin_unlock(&ksm_mmlist_lock); set_bit(MMF_VM_MERGEABLE, &mm->flags); @@ -3011,40 +3011,40 @@ int __ksm_enter(struct mm_struct *mm) void __ksm_exit(struct mm_struct *mm) { - struct ksm_mm_slot *mm_slot; + struct ksm_mm_slot *ksm_slot; struct mm_slot *slot; int easy_to_free = 0; /* * This process is exiting: if it's straightforward (as is the - * case when ksmd was never running), free mm_slot immediately. + * case when ksmd was never running), free ksm_slot immediately. * But if it's at the cursor or has rmap_items linked to it, use * mmap_lock to synchronize with any break_cows before pagetables - * are freed, and leave the mm_slot on the list for ksmd to free. + * are freed, and leave the ksm_slot on the list for ksmd to free. * Beware: ksm may already have noticed it exiting and freed the slot. */ spin_lock(&ksm_mmlist_lock); slot = mm_slot_lookup(mm_slots_hash, mm); - mm_slot = mm_slot_entry(slot, struct ksm_mm_slot, slot); - if (mm_slot && ksm_scan.mm_slot != mm_slot) { - if (!mm_slot->rmap_list) { + ksm_slot = mm_slot_entry(slot, struct ksm_mm_slot, slot); + if (ksm_slot && ksm_scan.ksm_slot != ksm_slot) { + if (!ksm_slot->rmap_list) { hash_del(&slot->hash); list_del(&slot->mm_node); easy_to_free = 1; } else { list_move(&slot->mm_node, - &ksm_scan.mm_slot->slot.mm_node); + &ksm_scan.ksm_slot->slot.mm_node); } } spin_unlock(&ksm_mmlist_lock); if (easy_to_free) { - mm_slot_free(mm_slot_cache, mm_slot); + mm_slot_free(mm_slot_cache, ksm_slot); clear_bit(MMF_VM_MERGE_ANY, &mm->flags); clear_bit(MMF_VM_MERGEABLE, &mm->flags); mmdrop(mm); - } else if (mm_slot) { + } else if (ksm_slot) { mmap_write_lock(mm); mmap_write_unlock(mm); }