From patchwork Thu Jul 28 20:45:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 12931709 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 E641DC19F2B for ; Thu, 28 Jul 2022 20:45:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 647EE6B0073; Thu, 28 Jul 2022 16:45:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5CFD96B0074; Thu, 28 Jul 2022 16:45:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 35E0B8E0001; Thu, 28 Jul 2022 16:45:25 -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 1FEF56B0073 for ; Thu, 28 Jul 2022 16:45:25 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id EC141ABEFE for ; Thu, 28 Jul 2022 20:45:24 +0000 (UTC) X-FDA: 79737688968.21.CA6C7FE Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) by imf17.hostedemail.com (Postfix) with ESMTP id E1ACC4002C for ; Thu, 28 Jul 2022 20:45:23 +0000 (UTC) Received: by mail-pl1-f170.google.com with SMTP id w10so2838702plq.0 for ; Thu, 28 Jul 2022 13:45:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references:reply-to :mime-version:content-transfer-encoding; bh=fEJL5O/8Mtexvm+J+r1cHRwPR897J/MIFhWHBeDpdlE=; b=LJO5mQsP4juN5xvNbTYM56FRLCmFDkgErNYmMEF/d4UxE93cf83tbCdmy5z9y3tTVw zvtIXcmCccQhzroNCgyJKAXd9xJJQsAEqwOqLtqm9LlRTlYodX54TFGQXZVrPzhKisjf ChA407NCENtAqKPBqnbCxq/18lGmRNyh0MQK7F5s22aUwo2e0C6+KqbziljzayQo10gM TF/fBk6+QiGIeXVyuO+eA5L3yFx/xmDbeudT6Ro6V7LI7awXDV/TljUZmi1Q/LkVlJUZ h/FvZe9wQP0L7CXI7zUqjl+XOisurJZgww1fpxRVLGX4AZDvUy5D45vYb6oeAUKy0Orr varA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:reply-to:mime-version:content-transfer-encoding; bh=fEJL5O/8Mtexvm+J+r1cHRwPR897J/MIFhWHBeDpdlE=; b=FzREJVDtAe8iz6RGiLm+3ScvPPDktUMm5Z0HXqjTjoW3UtSUmm4ooRcUSuF0NzPpJt wS5a2I4Go0aqoxpUsBrW3XY10drnG8jbuIULOVtzpZ85TSsWzLLlTDP6rQXQftg3oHVY IoFGfrR8HO+uQ73sr2mlYlgORcvD9w9qDbMxZGxai2r7bHPYavPMofNqFSBi5C6bFd7g /sTOz2ZIXM9BXUmGq3hdkGFt4NMH2DBKysvhW0dYkX4C/6YjtZBHQPMMMvwbYIQc2U0n S1mfMEJ+L9Ucr5G7rvRH5KDQHhkSoZpXU8Y+PSB3JaWInDXp4OWoOipXJIPq26K2t8Zb ZiiA== X-Gm-Message-State: ACgBeo2AEVa2Z3Tw08zdgkDAHotnLmsoHjUIFwF7GvVW8nuucCrreDM2 1o5vWYHHz9wg4Ufm8uKiyKIZO9BaHZ2TqRrWXy4= X-Google-Smtp-Source: AA6agR7gaJDHwuNty0e2Q772Que215+AfrAqz2a4Nol+uHZaE2IVzWbEJW8m+7P6ryUuMNqvlr67dA== X-Received: by 2002:a17:90b:4c03:b0:1f2:b977:c64e with SMTP id na3-20020a17090b4c0300b001f2b977c64emr473596pjb.211.1659041122887; Thu, 28 Jul 2022 13:45:22 -0700 (PDT) Received: from KASONG-MB0.tencent.com ([114.254.3.190]) by smtp.gmail.com with ESMTPSA id 21-20020a170902c11500b0016c40f8cb58sm1787304pli.81.2022.07.28.13.45.20 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 28 Jul 2022 13:45:22 -0700 (PDT) From: Kairui Song To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, Andrew Morton , Kairui Song Subject: [RFC PATCH 2/7] mm: move check_mm to memory.c Date: Fri, 29 Jul 2022 04:45:06 +0800 Message-Id: <20220728204511.56348-3-ryncsn@gmail.com> X-Mailer: git-send-email 2.35.2 In-Reply-To: <20220728204511.56348-1-ryncsn@gmail.com> References: <20220728204511.56348-1-ryncsn@gmail.com> Reply-To: Kairui Song MIME-Version: 1.0 ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=LJO5mQsP; spf=pass (imf17.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.214.170 as permitted sender) smtp.mailfrom=ryncsn@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1659041124; a=rsa-sha256; cv=none; b=oe1GqEBq76EYvCGGy8TOrZkg8Wb5+PkBdGk0PYPxQbWhyKN/IwB/rDM89v0Q7XW+aEsvbN CEZbRFu7yxUPeXaFle97S9xWRiSpkuEiFuyBXnDl/DHA0lmhUMhx0P/xRucH7S0VyRRFc6 f6L5vl4Ffkgn/Lr0GXyraaxrnPcmgGE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1659041124; h=from:from:sender:reply-to: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:dkim-signature; bh=fEJL5O/8Mtexvm+J+r1cHRwPR897J/MIFhWHBeDpdlE=; b=ziQRGHkpyug9OZ25NtSG7sFDgXPk4T92jNVSrsxWeKffUa54Kzt/I8HgRu11jbSDqXBz6j cfO6WYnN99zvAI0GGTsumIFxlt12N+wB4LUAvzEwuYiklvn6G09kOiujDpsDfhkGPjGJr5 Nk3QdavEnBEpWLPxV7LNN4oGhz/Efzk= X-Stat-Signature: zg7eji4q3r98ffsy658gcxosdxg41zh8 X-Rspamd-Queue-Id: E1ACC4002C X-Rspam-User: Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=LJO5mQsP; spf=pass (imf17.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.214.170 as permitted sender) smtp.mailfrom=ryncsn@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspamd-Server: rspam12 X-HE-Tag: 1659041123-403446 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: From: Kairui Song No function change, make it possible to do extra mm operation on mm exit, prepare for following commits. Signed-off-by: Kairui Song --- include/linux/mm.h | 3 +++ kernel/fork.c | 33 --------------------------------- mm/memory.c | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 33 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 6346f7e77dc7..81ad91621078 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1993,6 +1993,9 @@ static inline bool get_user_page_fast_only(unsigned long addr, { return get_user_pages_fast_only(addr, 1, gup_flags, pagep) == 1; } + +void check_mm(struct mm_struct *mm); + /* * per-process(per-mm_struct) statistics. */ diff --git a/kernel/fork.c b/kernel/fork.c index c090ebd55063..86a239772208 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -128,15 +128,6 @@ int nr_threads; /* The idle threads do not count.. */ static int max_threads; /* tunable limit on nr_threads */ -#define NAMED_ARRAY_INDEX(x) [x] = __stringify(x) - -static const char * const resident_page_types[] = { - NAMED_ARRAY_INDEX(MM_FILEPAGES), - NAMED_ARRAY_INDEX(MM_ANONPAGES), - NAMED_ARRAY_INDEX(MM_SWAPENTS), - NAMED_ARRAY_INDEX(MM_SHMEMPAGES), -}; - DEFINE_PER_CPU(unsigned long, process_counts) = 0; __cacheline_aligned DEFINE_RWLOCK(tasklist_lock); /* outer */ @@ -748,30 +739,6 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm) #define mm_free_pgd(mm) #endif /* CONFIG_MMU */ -static void check_mm(struct mm_struct *mm) -{ - int i; - - BUILD_BUG_ON_MSG(ARRAY_SIZE(resident_page_types) != NR_MM_COUNTERS, - "Please make sure 'struct resident_page_types[]' is updated as well"); - - for (i = 0; i < NR_MM_COUNTERS; i++) { - long x = atomic_long_read(&mm->rss_stat.count[i]); - - if (unlikely(x)) - pr_alert("BUG: Bad rss-counter state mm:%p type:%s val:%ld\n", - mm, resident_page_types[i], x); - } - - if (mm_pgtables_bytes(mm)) - pr_alert("BUG: non-zero pgtables_bytes on freeing mm: %ld\n", - mm_pgtables_bytes(mm)); - -#if defined(CONFIG_TRANSPARENT_HUGEPAGE) && !USE_SPLIT_PMD_PTLOCKS - VM_BUG_ON_MM(mm->pmd_huge_pte, mm); -#endif -} - #define allocate_mm() (kmem_cache_alloc(mm_cachep, GFP_KERNEL)) #define free_mm(mm) (kmem_cache_free(mm_cachep, (mm))) diff --git a/mm/memory.c b/mm/memory.c index 6bf7826e666b..c0597214f9b3 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -179,6 +179,38 @@ void mm_trace_rss_stat(struct mm_struct *mm, int member, long count) #define inc_mm_counter_fast(mm, member) inc_mm_counter(mm, member) #define dec_mm_counter_fast(mm, member) dec_mm_counter(mm, member) +#define NAMED_ARRAY_INDEX(x) [x] = __stringify(x) +static const char * const resident_page_types[] = { + NAMED_ARRAY_INDEX(MM_FILEPAGES), + NAMED_ARRAY_INDEX(MM_ANONPAGES), + NAMED_ARRAY_INDEX(MM_SWAPENTS), + NAMED_ARRAY_INDEX(MM_SHMEMPAGES), +}; + +void check_mm(struct mm_struct *mm) +{ + int i; + + BUILD_BUG_ON_MSG(ARRAY_SIZE(resident_page_types) != NR_MM_COUNTERS, + "Please make sure 'struct resident_page_types[]' is updated as well"); + + for (i = 0; i < NR_MM_COUNTERS; i++) { + long x = atomic_long_read(&mm->rss_stat.count[i]); + + if (unlikely(x)) + pr_alert("BUG: Bad rss-counter state mm:%p type:%s val:%ld\n", + mm, resident_page_types[i], x); + } + + if (mm_pgtables_bytes(mm)) + pr_alert("BUG: non-zero pgtables_bytes on freeing mm: %ld\n", + mm_pgtables_bytes(mm)); + +#if defined(CONFIG_TRANSPARENT_HUGEPAGE) && !USE_SPLIT_PMD_PTLOCKS + VM_BUG_ON_MM(mm->pmd_huge_pte, mm); +#endif +} + /* * Note: this doesn't free the actual pages themselves. That * has been handled earlier when unmapping all the memory regions.