From: Wei Yang <richard.weiyang@gmail.com>
To: David Hildenbrand <david@redhat.com>
Cc: Wei Yang <richard.weiyang@gmail.com>,
rppt@kernel.org, akpm@linux-foundation.org, linux-mm@kvack.org
Subject: Re: [PATCH] mm/mm_init.c: print mem_init info after defer_init is done
Date: Tue, 11 Jun 2024 14:42:47 +0000 [thread overview]
Message-ID: <20240611144247.4nspdna7oxbntgnz@master> (raw)
In-Reply-To: <bd2a0bf3-dbda-4146-b0ba-e1c863528306@redhat.com>
On Tue, Jun 11, 2024 at 04:26:56PM +0200, David Hildenbrand wrote:
>On 11.06.24 05:08, Wei Yang wrote:
>> 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.
>>
>
>Maybe mention that this will also help changing totalpage accounting.
>
Sure.
>> Let's print the mem info after defer_init is done.
>>
>> Signed-off-by: Wei Yang <richard.weiyang@gmail.com>
>> CC: David Hildenbrand <david@redhat.com>
>> ---
>> 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)
>
>Can you avoid all that churn simply by doing a
>
>static void __init mem_init_print_info(void);
>
>somewhere at the beginning of this file?
Ok, if this is preferred.
>
>> +{
>> + 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
>
>Maybe add a comment like
>
>/* Accounting of total+free memory is stable at this point. */
>
>> + mem_init_print_info();
>
>
>--
>Cheers,
>
>David / dhildenb
--
Wei Yang
Help you, Help me
prev parent reply other threads:[~2024-06-11 14:42 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-11 3:08 Wei Yang
2024-06-11 14:26 ` David Hildenbrand
2024-06-11 14:42 ` Wei Yang [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240611144247.4nspdna7oxbntgnz@master \
--to=richard.weiyang@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=david@redhat.com \
--cc=linux-mm@kvack.org \
--cc=rppt@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox