From patchwork Mon May 2 18:17:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zach O'Keefe X-Patchwork-Id: 12834613 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 90126C433F5 for ; Mon, 2 May 2022 18:17:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DD74F6B0081; Mon, 2 May 2022 14:17:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D3A6E6B0082; Mon, 2 May 2022 14:17:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AF1C46B0083; Mon, 2 May 2022 14:17:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.27]) by kanga.kvack.org (Postfix) with ESMTP id 8CF7B6B0081 for ; Mon, 2 May 2022 14:17:44 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 6857061825 for ; Mon, 2 May 2022 18:17:44 +0000 (UTC) X-FDA: 79421611248.30.218AFDE Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) by imf09.hostedemail.com (Postfix) with ESMTP id CD0BD140068 for ; Mon, 2 May 2022 18:17:38 +0000 (UTC) Received: by mail-pj1-f74.google.com with SMTP id m8-20020a17090aab0800b001cb1320ef6eso29420pjq.3 for ; Mon, 02 May 2022 11:17:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=Q/9aZGSnPZ21ElKjV9y+LJSB6/AyGVS0QWYpzNBYeKQ=; b=eCeTuvRo7rnFDDMcY0ftap58Ts/WBC3lSKK6iH9IzkxBbzAfseIBvMgP0oeaBNkQbs kddKe5wRIWF2CcwUQOtgtdayghV8J9wI98RRYGK6tESdnINqDA9eLeUX/HoZsG8XR9zs Jr2elkChGPaOcVzVc7XqfvAwwgZQkaJVhw7wYUmAVAaMTUz5weWApU/2ftWLXXZNPg5Y aEOYQL4qrKLDLLht5khxAh6DKbgx0ANqHePIPsZ20oR+4YAovTU/5Rv1+NWxGGn0PkdZ fkLZUESlIamVaZR2v1HQqeqbnYdfRH5UkWqFqpMUQa0XUgBdod+sGBgrMIpkvABD3eHB yRUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=Q/9aZGSnPZ21ElKjV9y+LJSB6/AyGVS0QWYpzNBYeKQ=; b=BlmaQOdzpKltx0Y77HxRtBr55h5DRpEacR2pZZyLbJYgkhobcAiipQtyI7rElM3+4A U0HHNLFUzi74Zo/wAiqhWWAtkoeHASeVWWRKtOnC+nnwjLKxVRRE8oLkSZ0I7VadM8ek AbAR/aJ1Ot177DsEAJ/URsqWA8Bg/hWptmWMW/pNcb+ocD1ImUCBCzxL6SuFf/5tvYZa VsBkiirG50Fbh5crhdQFoXpN4AVo0AwWSqW/79QwRKqVsAc/yk+i0ET2k8FDqv2d54M1 i+YGhd0qI3LTyh8ZGQ1y4U5N0BvWzfv+1rc69MYs9qwKDQNqjT/O/TGdye2wDqsUCPEm JrRA== X-Gm-Message-State: AOAM530abdLvW/YC0+u5kkS5Y8FuF7hVdtcYVSJzr9FmHWUs2Pu1ID8G IRjrOqw1Z7yRFTU2T4gf7OwuSdSOziyw X-Google-Smtp-Source: ABdhPJyS41DKolokIfiU1uB3DKoH5OMCI4TMGPfTO5QmKuvRXdneQ6kVfnXGLIQ6z3rGh0e11wgkz+a4k60L X-Received: from zokeefe3.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1b6]) (user=zokeefe job=sendgmr) by 2002:a17:903:230f:b0:15e:8bbb:f7b0 with SMTP id d15-20020a170903230f00b0015e8bbbf7b0mr12829483plh.75.1651515462932; Mon, 02 May 2022 11:17:42 -0700 (PDT) Date: Mon, 2 May 2022 11:17:10 -0700 In-Reply-To: <20220502181714.3483177-1-zokeefe@google.com> Message-Id: <20220502181714.3483177-10-zokeefe@google.com> Mime-Version: 1.0 References: <20220502181714.3483177-1-zokeefe@google.com> X-Mailer: git-send-email 2.36.0.464.gb9c8b46e94-goog Subject: [PATCH v4 09/13] mm/khugepaged: rename prefix of shared collapse functions From: "Zach O'Keefe" To: Alex Shi , David Hildenbrand , David Rientjes , Matthew Wilcox , Michal Hocko , Pasha Tatashin , Peter Xu , SeongJae Park , Song Liu , Vlastimil Babka , Yang Shi , Zi Yan , linux-mm@kvack.org Cc: Andrea Arcangeli , Andrew Morton , Arnd Bergmann , Axel Rasmussen , Chris Kennelly , Chris Zankel , Helge Deller , Hugh Dickins , Ivan Kokshaysky , "James E.J. Bottomley" , Jens Axboe , "Kirill A. Shutemov" , Matt Turner , Max Filippov , Miaohe Lin , Minchan Kim , Patrick Xia , Pavel Begunkov , Thomas Bogendoerfer , "Zach O'Keefe" Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=eCeTuvRo; spf=pass (imf09.hostedemail.com: domain of 3RiBwYgcKCGEYNJDDEDFNNFKD.BNLKHMTW-LLJU9BJ.NQF@flex--zokeefe.bounces.google.com designates 209.85.216.74 as permitted sender) smtp.mailfrom=3RiBwYgcKCGEYNJDDEDFNNFKD.BNLKHMTW-LLJU9BJ.NQF@flex--zokeefe.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspam-User: X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: CD0BD140068 X-Stat-Signature: 96sf69fe8phpwhsj6mrkaq3apsbaokou X-HE-Tag: 1651515458-743284 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: The following functions/tracepoints are shared between khugepaged and madvise collapse contexts. Replace the "khugepaged_" prefixe with generic "hpage_collapse_" prefix in such cases: huge_memory:mm_khugepaged_scan_pmd -> huge_memory:mm_hpage_collapse_scan_pmd khugepaged_test_exit() -> hpage_collapse_test_exit() khugepaged_scan_abort() -> hpage_collapse_scan_abort() khugepaged_scan_pmd() -> hpage_collapse_scan_pmd() khugepaged_find_target_node() -> hpage_collapse_find_target_node() Signed-off-by: Zach O'Keefe --- include/trace/events/huge_memory.h | 2 +- mm/khugepaged.c | 72 ++++++++++++++++-------------- 2 files changed, 39 insertions(+), 35 deletions(-) diff --git a/include/trace/events/huge_memory.h b/include/trace/events/huge_memory.h index 55392bf30a03..fb6c73632ff3 100644 --- a/include/trace/events/huge_memory.h +++ b/include/trace/events/huge_memory.h @@ -48,7 +48,7 @@ SCAN_STATUS #define EM(a, b) {a, b}, #define EMe(a, b) {a, b} -TRACE_EVENT(mm_khugepaged_scan_pmd, +TRACE_EVENT(mm_hpage_collapse_scan_pmd, TP_PROTO(struct mm_struct *mm, struct page *page, bool writable, int referenced, int none_or_zero, int status, int unmapped), diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 3ba2c570da5e..9f1b7e9e78c2 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -96,7 +96,7 @@ struct collapse_control { /* Num pages scanned per node */ int node_load[MAX_NUMNODES]; - /* Last target selected in khugepaged_find_target_node() */ + /* Last target selected in hpage_collapse_find_target_node() */ int last_target_node; struct page *hpage; @@ -453,7 +453,7 @@ static void insert_to_mm_slots_hash(struct mm_struct *mm, hash_add(mm_slots_hash, &mm_slot->hash, (long)mm); } -static inline int khugepaged_test_exit(struct mm_struct *mm) +static inline int hpage_collapse_test_exit(struct mm_struct *mm) { return atomic_read(&mm->mm_users) == 0; } @@ -502,7 +502,7 @@ int __khugepaged_enter(struct mm_struct *mm) return -ENOMEM; /* __khugepaged_exit() must not run from under us */ - VM_BUG_ON_MM(khugepaged_test_exit(mm), mm); + VM_BUG_ON_MM(hpage_collapse_test_exit(mm), mm); if (unlikely(test_and_set_bit(MMF_VM_HUGEPAGE, &mm->flags))) { free_mm_slot(mm_slot); return 0; @@ -566,11 +566,10 @@ void __khugepaged_exit(struct mm_struct *mm) } else if (mm_slot) { /* * This is required to serialize against - * khugepaged_test_exit() (which is guaranteed to run - * under mmap sem read mode). Stop here (after we - * return all pagetables will be destroyed) until - * khugepaged has finished working on the pagetables - * under the mmap_lock. + * hpage_collapse_test_exit() (which is guaranteed to run + * under mmap sem read mode). Stop here (after we return all + * pagetables will be destroyed) until khugepaged has finished + * working on the pagetables under the mmap_lock. */ mmap_write_lock(mm); mmap_write_unlock(mm); @@ -807,7 +806,7 @@ static void khugepaged_alloc_sleep(void) remove_wait_queue(&khugepaged_wait, &wait); } -static bool khugepaged_scan_abort(int nid, struct collapse_control *cc) +static bool hpage_collapse_scan_abort(int nid, struct collapse_control *cc) { int i; @@ -854,7 +853,7 @@ static bool alloc_hpage(gfp_t gfp, int node, struct collapse_control *cc) } #ifdef CONFIG_NUMA -static int khugepaged_find_target_node(struct collapse_control *cc) +static int hpage_collapse_find_target_node(struct collapse_control *cc) { int nid, target_node = 0, max_value = 0; @@ -901,7 +900,7 @@ static bool khugepaged_alloc_page(gfp_t gfp, int node, return alloc_hpage(gfp, node, cc); } #else -static int khugepaged_find_target_node(struct collapse_control *cc) +static int hpage_collapse_find_target_node(struct collapse_control *cc) { return 0; } @@ -981,7 +980,7 @@ static int hugepage_vma_revalidate(struct mm_struct *mm, unsigned long address, struct vm_area_struct *vma; unsigned long hstart, hend; - if (unlikely(khugepaged_test_exit(mm))) + if (unlikely(hpage_collapse_test_exit(mm))) return SCAN_ANY_PROCESS; *vmap = vma = find_vma(mm, address); @@ -1025,7 +1024,7 @@ static int find_pmd_or_thp_or_none(struct mm_struct *mm, /* * Bring missing pages in from swap, to complete THP collapse. - * Only done if khugepaged_scan_pmd believes it is worthwhile. + * Only done if hpage_collapse_scan_pmd believes it is worthwhile. * * Called and returns without pte mapped or spinlocks held, * but with mmap_lock held to protect against vma changes. @@ -1092,7 +1091,7 @@ static int alloc_charge_hpage(struct mm_struct *mm, struct collapse_control *cc) const struct cpumask *cpumask; #endif gfp_t gfp = alloc_hugepage_khugepaged_gfpmask() | __GFP_THISNODE; - int node = khugepaged_find_target_node(cc); + int node = hpage_collapse_find_target_node(cc); #ifdef CONFIG_NUMA /* sched to specified node before huge page memory copy */ @@ -1262,9 +1261,10 @@ static int collapse_huge_page(struct mm_struct *mm, unsigned long address, return result; } -static int khugepaged_scan_pmd(struct mm_struct *mm, struct vm_area_struct *vma, - unsigned long address, bool *mmap_locked, - struct collapse_control *cc) +static int hpage_collapse_scan_pmd(struct mm_struct *mm, + struct vm_area_struct *vma, + unsigned long address, bool *mmap_locked, + struct collapse_control *cc) { pmd_t *pmd; pte_t *pte, *_pte; @@ -1358,7 +1358,7 @@ static int khugepaged_scan_pmd(struct mm_struct *mm, struct vm_area_struct *vma, * hit record. */ node = page_to_nid(page); - if (khugepaged_scan_abort(node, cc)) { + if (hpage_collapse_scan_abort(node, cc)) { result = SCAN_SCAN_ABORT; goto out_unmap; } @@ -1423,8 +1423,8 @@ static int khugepaged_scan_pmd(struct mm_struct *mm, struct vm_area_struct *vma, unmapped, cc); } out: - trace_mm_khugepaged_scan_pmd(mm, page, writable, referenced, - none_or_zero, result, unmapped); + trace_mm_hpage_collapse_scan_pmd(mm, page, writable, referenced, + none_or_zero, result, unmapped); return result; } @@ -1434,7 +1434,7 @@ static void collect_mm_slot(struct mm_slot *mm_slot) lockdep_assert_held(&khugepaged_mm_lock); - if (khugepaged_test_exit(mm)) { + if (hpage_collapse_test_exit(mm)) { /* free mm_slot */ hash_del(&mm_slot->hash); list_del(&mm_slot->mm_node); @@ -1605,7 +1605,7 @@ static void khugepaged_collapse_pte_mapped_thps(struct mm_slot *mm_slot) if (!mmap_write_trylock(mm)) return; - if (unlikely(khugepaged_test_exit(mm))) + if (unlikely(hpage_collapse_test_exit(mm))) goto out; for (i = 0; i < mm_slot->nr_pte_mapped_thp; i++) @@ -1668,7 +1668,8 @@ static void retract_page_tables(struct address_space *mapping, pgoff_t pgoff) * it'll always mapped in small page size for uffd-wp * registered ranges. */ - if (!khugepaged_test_exit(mm) && !userfaultfd_wp(vma)) + if (!hpage_collapse_test_exit(mm) && + !userfaultfd_wp(vma)) collapse_and_free_pmd(mm, vma, addr, pmd); mmap_write_unlock(mm); } else { @@ -2094,7 +2095,7 @@ static int khugepaged_scan_file(struct mm_struct *mm, } node = page_to_nid(page); - if (khugepaged_scan_abort(node, cc)) { + if (hpage_collapse_scan_abort(node, cc)) { result = SCAN_SCAN_ABORT; break; } @@ -2183,7 +2184,7 @@ static unsigned int khugepaged_scan_mm_slot(unsigned int pages, vma = NULL; if (unlikely(!mmap_read_trylock(mm))) goto breakouterloop_mmap_lock; - if (likely(!khugepaged_test_exit(mm))) + if (likely(!hpage_collapse_test_exit(mm))) vma = find_vma(mm, khugepaged_scan.address); progress++; @@ -2191,7 +2192,7 @@ static unsigned int khugepaged_scan_mm_slot(unsigned int pages, unsigned long hstart, hend; cond_resched(); - if (unlikely(khugepaged_test_exit(mm))) { + if (unlikely(hpage_collapse_test_exit(mm))) { progress++; break; } @@ -2217,7 +2218,7 @@ static unsigned int khugepaged_scan_mm_slot(unsigned int pages, bool mmap_locked; cond_resched(); - if (unlikely(khugepaged_test_exit(mm))) + if (unlikely(hpage_collapse_test_exit(mm))) goto breakouterloop; VM_BUG_ON(khugepaged_scan.address < hstart || @@ -2234,9 +2235,10 @@ static unsigned int khugepaged_scan_mm_slot(unsigned int pages, cc); fput(file); } else { - result = khugepaged_scan_pmd(mm, vma, - khugepaged_scan.address, - &mmap_locked, cc); + result = hpage_collapse_scan_pmd(mm, vma, + khugepaged_scan.address, + &mmap_locked, + cc); } if (result == SCAN_SUCCEED) ++khugepaged_pages_collapsed; @@ -2260,7 +2262,7 @@ static unsigned int khugepaged_scan_mm_slot(unsigned int pages, * Release the current mm_slot if this mm is about to die, or * if we scanned all vmas of this mm. */ - if (khugepaged_test_exit(mm) || !vma) { + if (hpage_collapse_test_exit(mm) || !vma) { /* * Make sure that if mm_users is reaching zero while * khugepaged runs here, khugepaged_exit will find @@ -2500,7 +2502,8 @@ static int madvise_collapse_errno(enum scan_result r) static int madvise_alloc_charge_hpage(struct mm_struct *mm, struct collapse_control *cc) { - if (!alloc_hpage(GFP_TRANSHUGE, khugepaged_find_target_node(cc), cc)) + if (!alloc_hpage(GFP_TRANSHUGE, hpage_collapse_find_target_node(cc), + cc)) return SCAN_ALLOC_HUGE_PAGE_FAIL; if (unlikely(mem_cgroup_charge(page_folio(cc->hpage), mm, GFP_TRANSHUGE))) @@ -2547,13 +2550,14 @@ int madvise_collapse(struct vm_area_struct *vma, struct vm_area_struct **prev, cond_resched(); result = SCAN_FAIL; - if (unlikely(khugepaged_test_exit(mm))) { + if (unlikely(hpage_collapse_test_exit(mm))) { result = SCAN_ANY_PROCESS; break; } memset(cc.node_load, 0, sizeof(cc.node_load)); - result = khugepaged_scan_pmd(mm, vma, addr, &mmap_locked, &cc); + result = hpage_collapse_scan_pmd(mm, vma, addr, &mmap_locked, + &cc); if (!mmap_locked) *prev = NULL; /* tell madvise we dropped mmap_lock */