From patchwork Tue Jun 11 03:08:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 13692802 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 9821BC27C55 for ; Tue, 11 Jun 2024 03:08:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 015BA6B00A4; Mon, 10 Jun 2024 23:08:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EE06D6B00A8; Mon, 10 Jun 2024 23:08:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D59BE6B00AA; Mon, 10 Jun 2024 23:08:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id B29D56B00A4 for ; Mon, 10 Jun 2024 23:08:30 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 432291411C6 for ; Tue, 11 Jun 2024 03:08:30 +0000 (UTC) X-FDA: 82217124780.06.02E1879 Received: from mail-ej1-f54.google.com (mail-ej1-f54.google.com [209.85.218.54]) by imf17.hostedemail.com (Postfix) with ESMTP id 8BD6A4000E for ; Tue, 11 Jun 2024 03:08:28 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=BDNhK8HK; spf=pass (imf17.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.218.54 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1718075308; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references:dkim-signature; bh=oyBjQPmg6WNoseiQ1FbfPFWK5ISNGEOan8e2vSPgPxY=; b=sIX/JdHJm0VOr0fJea5uvsSPL/NNviv3mTk61sO6hBEpfozSJtryWZR6twVxeAAJnJPOJK V2x5oXNQuVIRn69ao0kaD374Aa5Bc+acfHicj+/gqKaw/KeIMi/LfzU2r/w/QkobPA7KBo R4667ovW8ETyixyXkyTfurjUNTzEBnA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718075308; a=rsa-sha256; cv=none; b=NAWHIZ785wbAGiECXRQz3dhshaE0Or+UYVBHeW6jcTt1Re0lp9YYSHb3s2LDLaEfGvy2jk ztUUDUy17egnzIVS0hG3tFfx3McXqMN+/gcwR7riK/+ax3kaOqfHapkC0o0xOycDsPM7ES X9pMH4MHOmDLtiLd7En2ZrB3/AYEdU0= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=BDNhK8HK; spf=pass (imf17.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.218.54 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-ej1-f54.google.com with SMTP id a640c23a62f3a-a6265d48ec3so49720966b.0 for ; Mon, 10 Jun 2024 20:08:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718075307; x=1718680107; darn=kvack.org; h=message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=oyBjQPmg6WNoseiQ1FbfPFWK5ISNGEOan8e2vSPgPxY=; b=BDNhK8HKc9Rwk8U+3tfzVitoVbpsVyg6fUtDMVn7Q8rIp/wh29g4eWkrBmYQyssGGf ub+6KCqtyJIyny9sR06Kv/AwHPApY2w8RaJgkv4TtHDDPI4VZFFVFG0HP5RY1JsKrb1T yUyH+t0w++CjPBRZh0AEqMa3ZaPrQ4/w6OGMd5Mk4pQLAJo5WcTaeLKdcegfGJDXgYl2 xmHlt4ZLoITXrK1Y3ftgV6XaEWhxjBh1jV1lQf+rWegieQLvxUeJt3q02vyZojhewIjM VvxuxRTd88Hi0Z1f8YQrKCVyHzcQ1iRHSdiAEl+aMwVuvfDCPoVjGezIDIAFRUeFrqhq +xvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718075307; x=1718680107; h=message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=oyBjQPmg6WNoseiQ1FbfPFWK5ISNGEOan8e2vSPgPxY=; b=hQ/U0du/yEWRPIneritEEzntIH/L8kW6KQynyl/x6gVzo8cDyeyeGa2QFTyUthWllj JR1jTHD2shaW0eusiUHCW7/ZJeaWlIEiaftiLA43gl5Rlgco9JlkQ/8vIhFbO78d0vte v+MuruM0icIeRYb58fH7sKFez0piJgMhw1SQyCMkPqzqa9WBoTtnHBJ6DQViu3bZoOFF 6AW+veZauVmWvLoG5JTquwktKpZpM4/7Gsor11IWqVqO1Xe/aYcF6GDRhLTWLGrKHRlx Q4X4n+MWK0Wf/QS+CHMtj79VeiNAVz+nOUBlLy3OFiw1D8WQ3RXeI1n7VvO2RQK0Yt+I 4i2A== X-Gm-Message-State: AOJu0YxwmlrWE2xcmFBF8+TXRawTuSD4YNdc2xhw70JVNjyeMFkgldc4 UxBbSUw7bSTBovg4Lqn30hbAqoWyIwwKh3gLtqtIEnJUfk3ebfab X-Google-Smtp-Source: AGHT+IEEkOnmkIchcAzdBBa2CVW2E0kSiDTswcxVIjeM1Y83AfgQxbhE0GyLVDwx89ZwG5/LVdvOuQ== X-Received: by 2002:a17:906:2bd0:b0:a6e:4498:984 with SMTP id a640c23a62f3a-a6e449809cbmr514634566b.39.1718075306615; Mon, 10 Jun 2024 20:08:26 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a6efec85ae8sm410287966b.184.2024.06.10.20.08.25 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 10 Jun 2024 20:08:25 -0700 (PDT) From: Wei Yang To: rppt@kernel.org, akpm@linux-foundation.org Cc: linux-mm@kvack.org, Wei Yang , David Hildenbrand Subject: [PATCH] mm/mm_init.c: print mem_init info after defer_init is done Date: Tue, 11 Jun 2024 03:08:12 +0000 Message-Id: <20240611030812.9582-1-richard.weiyang@gmail.com> X-Mailer: git-send-email 2.11.0 X-Rspamd-Server: rspam03 X-Stat-Signature: 9bsooz6m8r5fozqpk4kbidydbffn311i X-Rspamd-Queue-Id: 8BD6A4000E X-Rspam-User: X-HE-Tag: 1718075308-373184 X-HE-Meta: U2FsdGVkX18xU/B41dc3dmvkVYyZ8/aa9XLBYn3EYUk2jMzabplQ5nYVhrXtsld+nMI3XBnh8MdLPieR3J49+UT+vQ7vhcOWfyj4fThYe3UBuCZAh7f+fw5F/iweEqKELK9XrwB2RawvHvf/pcuoBI6Y8baY/PAsp1jxB/DeoPVb5e/9GNzb2IZLG6q70/V5kk42UZbSGVXZsMuSCll29NkfLvRfpBfFJ89O5KuHb9B1CKMw4dNcAKK4pUzi0zKSduPZeNgwGz0eF7ZURp7VQmedwHDd/N3oesWU7Se72j9EaiOEKAipKmbfKRMFWQsLU4/Qtf4mfnnrl9oHYdD+a+bFCn8fR09y6vuhV6biqIxgdQ+GM4dG+Up1W4RllzJmyHUaV9vFGeokq1peqQY+lenlRFDFA7+ulojM5Dk4n0oZUyjVi/C2FouAWKjVm0aW5KzDtRmEKc3454oy01KjVIxYPQKn/wyjw1bsEUwBWvGiTjQXC6ZimPO6UBvm36cmiPTB/lTpLjp7b4igOzpZzb9ZYcAvKsB3MbHWarD4sVVkcs+/7sut4GYFt3ee7jthRXP0jCv5XNtVi/E7wme6EZ0ua/q1vFvKEZdrmDlIQRAM8Rv/ux71KqcLEZcrF4/mG0kxdOPlcLDoY+emaBb7wmY9CqOmGN8EXyaEWWeSLOFAaIQ8ITXDZEhgY5D37PjtgYLxPBsundTtGmF90/vtDa+RCxUz8G3CTFn3cLliUzgMxRbnEtcitKCGa3EqX3x+iPq8XPyUeX9gHYxOg2leOD/q5RxIcLzBzZ5NqF+vTuDO6um5YU5F8pDgylTwuPTNb24IAVHbDRzHF42BmZDGTA+AzmwfXqaPRVRLzLpVEFhfT2v6TtICc6K3YAv3lv90V16zhymR/fCGIzsqW1l+Q8hdOCx26EUeeiehJReTiCoKVJ/lNQpAJ6qkiGrDH3kFVYv76zaq+uz85SgN3Ft JTxSeuvM 22frN23TwmxyBiuHKGrfVm5B/rejHqGCIXzsZIdmYY24cM4MujnUtBAMH+YEdam4I3sHKXhbqDZIIHSukC6NX3ho5bnrp6S7jEAP2x0UXQ5uGL1tqpverq6VyDputIjQ1leWMKV636gu7P4SyHX9XTY/zOF+GEup3O64xWpWDcWRXLYIiFsO9nK9ZF70Tq3dcfSWEgD/hLPi8nlQ+XRI+H/ahNDyG/yBpFpTDeGMLcT9cDgZLrMrxtB4t6izWno3Dd5IXMvoHnNzceQ5Vn3XGwMgWVqz5vkoUDijvOt1K8s7h6L9vqK27E06ylZJTBn2mJWxPxvKR3WWgjBXmE6o6NsGghKm+jmeaF5FT7wQo3Z8M9ClAiypcORa66kf3U59n95zG0RdRsmyaneIyMRoMWkT3gK4URqPY1eEjekoL5B8+bQY5WTmNkufvxmTncqg9FJ1g+163OhfDoWu9GAHyCEOAbPBY8zbkXwQGPWH7N636av4= 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: Current call flow looks like this: start_kernel mm_core_init mem_init mem_init_print_info rest_init kernel_init kernel_init_freeable page_alloc_init_late deferred_init_memmap If CONFIG_DEFERRED_STRUCT_PAGE_INIT, the time mem_init_print_info() calls, pages are not totally initialized and freed to buddy. This has one issue * nr_free_pages() just contains partial free pages in the system, which is not we expect. Let's print the mem info after defer_init is done. Signed-off-by: Wei Yang CC: David Hildenbrand --- mm/mm_init.c | 104 +++++++++++++++++++++++++-------------------------- 1 file changed, 52 insertions(+), 52 deletions(-) diff --git a/mm/mm_init.c b/mm/mm_init.c index f72b852bd5b8..34a6de20ef77 100644 --- a/mm/mm_init.c +++ b/mm/mm_init.c @@ -2322,6 +2322,57 @@ void set_zone_contiguous(struct zone *zone) zone->contiguous = true; } +static void __init mem_init_print_info(void) +{ + unsigned long physpages, codesize, datasize, rosize, bss_size; + unsigned long init_code_size, init_data_size; + + physpages = get_num_physpages(); + codesize = _etext - _stext; + datasize = _edata - _sdata; + rosize = __end_rodata - __start_rodata; + bss_size = __bss_stop - __bss_start; + init_data_size = __init_end - __init_begin; + init_code_size = _einittext - _sinittext; + + /* + * Detect special cases and adjust section sizes accordingly: + * 1) .init.* may be embedded into .data sections + * 2) .init.text.* may be out of [__init_begin, __init_end], + * please refer to arch/tile/kernel/vmlinux.lds.S. + * 3) .rodata.* may be embedded into .text or .data sections. + */ +#define adj_init_size(start, end, size, pos, adj) \ + do { \ + if (&start[0] <= &pos[0] && &pos[0] < &end[0] && size > adj) \ + size -= adj; \ + } while (0) + + adj_init_size(__init_begin, __init_end, init_data_size, + _sinittext, init_code_size); + adj_init_size(_stext, _etext, codesize, _sinittext, init_code_size); + adj_init_size(_sdata, _edata, datasize, __init_begin, init_data_size); + adj_init_size(_stext, _etext, codesize, __start_rodata, rosize); + adj_init_size(_sdata, _edata, datasize, __start_rodata, rosize); + +#undef adj_init_size + + pr_info("Memory: %luK/%luK available (%luK kernel code, %luK rwdata, %luK rodata, %luK init, %luK bss, %luK reserved, %luK cma-reserved" +#ifdef CONFIG_HIGHMEM + ", %luK highmem" +#endif + ")\n", + K(nr_free_pages()), K(physpages), + codesize / SZ_1K, datasize / SZ_1K, rosize / SZ_1K, + (init_data_size + init_code_size) / SZ_1K, bss_size / SZ_1K, + K(physpages - totalram_pages() - totalcma_pages), + K(totalcma_pages) +#ifdef CONFIG_HIGHMEM + , K(totalhigh_pages()) +#endif + ); +} + void __init page_alloc_init_late(void) { struct zone *zone; @@ -2348,6 +2399,7 @@ void __init page_alloc_init_late(void) files_maxfiles_init(); #endif + mem_init_print_info(); buffer_init(); /* Discard memblock private memory */ @@ -2666,57 +2718,6 @@ static void __init report_meminit(void) pr_info("mem auto-init: clearing system memory may take some time...\n"); } -static void __init mem_init_print_info(void) -{ - unsigned long physpages, codesize, datasize, rosize, bss_size; - unsigned long init_code_size, init_data_size; - - physpages = get_num_physpages(); - codesize = _etext - _stext; - datasize = _edata - _sdata; - rosize = __end_rodata - __start_rodata; - bss_size = __bss_stop - __bss_start; - init_data_size = __init_end - __init_begin; - init_code_size = _einittext - _sinittext; - - /* - * Detect special cases and adjust section sizes accordingly: - * 1) .init.* may be embedded into .data sections - * 2) .init.text.* may be out of [__init_begin, __init_end], - * please refer to arch/tile/kernel/vmlinux.lds.S. - * 3) .rodata.* may be embedded into .text or .data sections. - */ -#define adj_init_size(start, end, size, pos, adj) \ - do { \ - if (&start[0] <= &pos[0] && &pos[0] < &end[0] && size > adj) \ - size -= adj; \ - } while (0) - - adj_init_size(__init_begin, __init_end, init_data_size, - _sinittext, init_code_size); - adj_init_size(_stext, _etext, codesize, _sinittext, init_code_size); - adj_init_size(_sdata, _edata, datasize, __init_begin, init_data_size); - adj_init_size(_stext, _etext, codesize, __start_rodata, rosize); - adj_init_size(_sdata, _edata, datasize, __start_rodata, rosize); - -#undef adj_init_size - - pr_info("Memory: %luK/%luK available (%luK kernel code, %luK rwdata, %luK rodata, %luK init, %luK bss, %luK reserved, %luK cma-reserved" -#ifdef CONFIG_HIGHMEM - ", %luK highmem" -#endif - ")\n", - K(nr_free_pages()), K(physpages), - codesize / SZ_1K, datasize / SZ_1K, rosize / SZ_1K, - (init_data_size + init_code_size) / SZ_1K, bss_size / SZ_1K, - K(physpages - totalram_pages() - totalcma_pages), - K(totalcma_pages) -#ifdef CONFIG_HIGHMEM - , K(totalhigh_pages()) -#endif - ); -} - /* * Set up kernel memory allocators */ @@ -2737,7 +2738,6 @@ void __init mm_core_init(void) kmsan_init_shadow(); stack_depot_early_init(); mem_init(); - mem_init_print_info(); kmem_cache_init(); /* * page_owner must be initialized after buddy is ready, and also after