From patchwork Tue Oct 25 20:06:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 10967 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1196054wru; Tue, 25 Oct 2022 13:12:49 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4NmnjKwJqdRcNDqAGDRB8BgN9UIdmBELxr9NceScwMkU+D+623BqNIcAiSYM6ARgZZyKW/ X-Received: by 2002:a17:90b:691:b0:20d:6171:c94 with SMTP id m17-20020a17090b069100b0020d61710c94mr14984pjz.25.1666728769679; Tue, 25 Oct 2022 13:12:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666728769; cv=none; d=google.com; s=arc-20160816; b=i0EertDm0gQWoX55Ml4+85mJ52TGqd8UxR33De0UG7ihwxhd1Rt1keqil2DNavLOo1 inIutnqLUdxxqg4HHp/zpvfmoMZUaq0B2BJZZamOBnXw4H0Vbx9VpP2/1jMDcT0g7MkW 6I8vM6fxnWMjvjTJnM98BYfCZCikJfSnjK4CLnHUHpDNv9pgOBkDd/kkn5xsrYRcQrs7 Y+YRrpx70Yj+LhoqypM9fbH6tH4/mOtfPutko1aJY+GYyLU4O/pamDaCjGwEmBjtpbFP YEzvBVeL6//Nu1o56YbdgoBDPub2/12RZriUODrxYrhVcjg6FSePf2jbOGT/FvwsbAts SfuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:subject:cc:to:from:date :user-agent:message-id:dkim-signature; bh=UvZ0A5YMgLIp6qjx93Bx4vopUfVlvYD0i9vsQFxAYRM=; b=iBouLoMTY7SSl2grgSqYFpu2yV3I90YNRggDIg2M7v+zpWOxXSdN93koH3770tkeNi hUUkMkUBqeyaWG/0vkP6x+A4TKHESU0VyvqvfZ7WUWZb5jEyvACMShy8PvHSubcu2iah cJdkBUitWW7CtgQM+DrUjqiOKktwKzxWiYzy2gaMo4JhAPkVYUnZ2CR2iNRcrNhBmXWE 0UPnSShQOjXy7xHmCaTVAE5sFe+UJaB+q+QofAIVO5PPGoqUeFdnV3xgkTP8dPJE7zXK xpIzsfSa3mbi3mExRsyHKG0OfmRaKS73W01SycsQE5xmYvWsGxt5ND7OKv6BSCdToc6r M0jQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b="dW/slevq"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q5-20020a17090a2dc500b0020d4f2e056csi4048835pjm.151.2022.10.25.13.12.19; Tue, 25 Oct 2022 13:12:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b="dW/slevq"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231748AbiJYULl (ORCPT + 99 others); Tue, 25 Oct 2022 16:11:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57074 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231244AbiJYULg (ORCPT ); Tue, 25 Oct 2022 16:11:36 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E29979EC6 for ; Tue, 25 Oct 2022 13:11:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=UvZ0A5YMgLIp6qjx93Bx4vopUfVlvYD0i9vsQFxAYRM=; b=dW/slevqqrlkPqDipH2N24ioFq ulGSbcJXeRK+kDZeRbpzM/GVbrIP5v+bIK6nxrlTWlYLAjZL9RqVI1CcRgUEixULXAjglX4tSAtO4 4h/WClTyNIB+h5I+CLuPWdrodL4uWnbgDRBJ5XjQw8y8pxTB8IQW78KQ/vCqr9xUQvwEJUeLCYQog lRcIoCihCgWvzvGTxehh/oOHS4PiC1FKaXRX3Nk9VqqNP+WwJGbiFlKw+YXlQAt1OaJiJEYT1ooE9 Xw4o6aPkkJYgQmXcT6IicdEl63ccikyBVzubCY/al2LoQHMk7/1hx88xb2M+jgOTyht+aJTpFGll7 VaP2/YVQ==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1onQGm-00GWF4-EP; Tue, 25 Oct 2022 20:11:28 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id A3C13300169; Tue, 25 Oct 2022 22:11:22 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id 8C43F2C4502E9; Tue, 25 Oct 2022 22:11:22 +0200 (CEST) Message-ID: <20221025201057.751153381@infradead.org> User-Agent: quilt/0.66 Date: Tue, 25 Oct 2022 22:06:57 +0200 From: Peter Zijlstra To: torvalds@linux-foundation.org, rostedt@goodmis.org, dave.hansen@intel.com Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, x86@kernel.org, keescook@chromium.org, seanjc@google.com Subject: [PATCH 1/5] mm: Move mm_cachep initialization to mm_init() References: <20221025200656.951281799@infradead.org> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747691786483684640?= X-GMAIL-MSGID: =?utf-8?q?1747691786483684640?= In order to allow using mm_alloc() much earlier, move initializing mm_cachep into mm_init(). Signed-off-by: Peter Zijlstra (Intel) --- include/linux/sched/task.h | 1 + init/main.c | 1 + kernel/fork.c | 32 ++++++++++++++++++-------------- 3 files changed, 20 insertions(+), 14 deletions(-) --- a/include/linux/sched/task.h +++ b/include/linux/sched/task.h @@ -65,6 +65,7 @@ extern void sched_dead(struct task_struc void __noreturn do_task_dead(void); void __noreturn make_task_dead(int signr); +extern void mm_cache_init(void); extern void proc_caches_init(void); extern void fork_init(void); --- a/init/main.c +++ b/init/main.c @@ -860,6 +860,7 @@ static void __init mm_init(void) /* Should be run after espfix64 is set up. */ pti_init(); kmsan_init_runtime(); + mm_cache_init(); } #ifdef CONFIG_RANDOMIZE_KSTACK_OFFSET --- a/kernel/fork.c +++ b/kernel/fork.c @@ -3015,10 +3015,27 @@ static void sighand_ctor(void *data) init_waitqueue_head(&sighand->signalfd_wqh); } -void __init proc_caches_init(void) +void __init mm_cache_init(void) { unsigned int mm_size; + /* + * The mm_cpumask is located at the end of mm_struct, and is + * dynamically sized based on the maximum CPU number this system + * can have, taking hotplug into account (nr_cpu_ids). + */ + mm_size = sizeof(struct mm_struct) + cpumask_size(); + + mm_cachep = kmem_cache_create_usercopy("mm_struct", + mm_size, ARCH_MIN_MMSTRUCT_ALIGN, + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_ACCOUNT, + offsetof(struct mm_struct, saved_auxv), + sizeof_field(struct mm_struct, saved_auxv), + NULL); +} + +void __init proc_caches_init(void) +{ sighand_cachep = kmem_cache_create("sighand_cache", sizeof(struct sighand_struct), 0, SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_TYPESAFE_BY_RCU| @@ -3036,19 +3053,6 @@ void __init proc_caches_init(void) SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_ACCOUNT, NULL); - /* - * The mm_cpumask is located at the end of mm_struct, and is - * dynamically sized based on the maximum CPU number this system - * can have, taking hotplug into account (nr_cpu_ids). - */ - mm_size = sizeof(struct mm_struct) + cpumask_size(); - - mm_cachep = kmem_cache_create_usercopy("mm_struct", - mm_size, ARCH_MIN_MMSTRUCT_ALIGN, - SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_ACCOUNT, - offsetof(struct mm_struct, saved_auxv), - sizeof_field(struct mm_struct, saved_auxv), - NULL); vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC|SLAB_ACCOUNT); mmap_init(); nsproxy_cache_init();