From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EBADFC10F27 for ; Wed, 11 Mar 2020 12:00:25 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4385220873 for ; Wed, 11 Mar 2020 12:00:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4385220873 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id E31AA6B0003; Wed, 11 Mar 2020 08:00:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DE3026B0006; Wed, 11 Mar 2020 08:00:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CD0766B0007; Wed, 11 Mar 2020 08:00:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0226.hostedemail.com [216.40.44.226]) by kanga.kvack.org (Postfix) with ESMTP id B19066B0003 for ; Wed, 11 Mar 2020 08:00:24 -0400 (EDT) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 83A6281D6 for ; Wed, 11 Mar 2020 12:00:24 +0000 (UTC) X-FDA: 76582938768.29.card04_36fc780acf62 X-HE-Tag: card04_36fc780acf62 X-Filterd-Recvd-Size: 18262 Received: from out4436.biz.mail.alibaba.com (out4436.biz.mail.alibaba.com [47.88.44.36]) by imf01.hostedemail.com (Postfix) with ESMTP for ; Wed, 11 Mar 2020 12:00:23 +0000 (UTC) X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R161e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e07417;MF=shile.zhang@linux.alibaba.com;NM=1;PH=DS;RN=7;SR=0;TI=SMTPD_---0TsIQDda_1583928008; Received: from ali-6c96cfdd1403.local(mailfrom:shile.zhang@linux.alibaba.com fp:SMTPD_---0TsIQDda_1583928008) by smtp.aliyun-inc.com(127.0.0.1); Wed, 11 Mar 2020 20:00:09 +0800 Subject: Re: [PATCH v2 1/1] mm: fix interrupt disabled long time inside deferred_init_memmap() To: Kirill Tkhai , Andrew Morton , Pavel Tatashin Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Vlastimil Babka , Michal Hocko References: <20200303161551.132263-1-shile.zhang@linux.alibaba.com> <20200303161551.132263-2-shile.zhang@linux.alibaba.com> <386d7d5f-a57d-f5b1-acee-131ce23d35ec@linux.alibaba.com> <2d4defb7-8816-3447-3d65-f5d80067a9fd@virtuozzo.com> <1856c956-858f-82d4-f3b3-05b2d0e5641c@linux.alibaba.com> <094fcf02-37bd-c9b9-7156-77b9b34955e0@virtuozzo.com> From: Shile Zhang Message-ID: <59c7f8c7-d2ef-8b59-637e-88a353d4daf0@linux.alibaba.com> Date: Wed, 11 Mar 2020 20:00:08 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 In-Reply-To: <094fcf02-37bd-c9b9-7156-77b9b34955e0@virtuozzo.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: quoted-printable 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: On 2020/3/11 19:42, Kirill Tkhai wrote: > On 11.03.2020 04:44, Shile Zhang wrote: >> Hi Kirill, >> >> Sorry for late to reply! >> I'm not fully understood the whole thing about deferred page init, so = I >> just force on the jiffies update issue itself. >> >> Maybe I'm in wrong path, it seems make no sense that deferred page ini= t in 1 CPU system, >> it cannot be initialize memory parallel. > Yes, it can't be initialized in parallel. But scheduler interprets defe= rred thread as a separate > task, so CPU time will be shared between that thread and the rest of ta= sks. This still should > make boot faster. Thanks for your quickly reply! Sorry, I don't think the CPU time can be shared to the rest of tasks=20 since the CPU be blocked until the deferred pages are all initialized, as following code: 8<------ #ifdef CONFIG_DEFERRED_STRUCT_PAGE_INIT =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 /* There will be num_node_sta= te(N_MEMORY) threads */ =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 atomic_set(&pgdat_init_n_undo= ne, num_node_state(N_MEMORY)); =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 for_each_node_state(nid, N_ME= MORY) { =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 kthread_run(deferred_init_memmap, NODE_DATA(nid),=20 "pgdatinit%d", nid); =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 /* Block until all are initia= lised */ =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 wait_for_completion(&pgdat_in= it_all_done_comp); 8<------- Maybe I misunderstood this point. @Pavel, Could you please give any advice on this point? Thanks! >> It might be better to disable deferred page init in 'deferred_init' in= case of 1 CPU >> (or only one memory node). >> >> In other word, seems the better way to solve this issue is do not bind= 'pgdatinit' thread >> on boot CPU. >> >> I also refactor the patch based on your comment, please help to check,= thanks! >> >> >> On 2020/3/4 18:47, Kirill Tkhai wrote: >>> On 04.03.2020 05:34, Shile Zhang wrote: >>>> Hi Kirill, >>>> >>>> Thanks for your quickly reply! >>>> >>>> On 2020/3/4 00:52, Kirill Tkhai wrote: >>>>> On 03.03.2020 19:15, Shile Zhang wrote: >>>>>> When 'CONFIG_DEFERRED_STRUCT_PAGE_INIT' is set, 'pgdatinit' kthrea= d will >>>>>> initialise the deferred pages with local interrupts disabled. It i= s >>>>>> introduced by commit 3a2d7fa8a3d5 ("mm: disable interrupts while >>>>>> initializing deferred pages"). >>>>>> >>>>>> The local interrupt will be disabled long time inside >>>>>> deferred_init_memmap(), depends on memory size. >>>>>> On machine with NCPUS <=3D 2, the 'pgdatinit' kthread could be pin= ed on >>>>>> boot CPU, then the tick timer will stuck long time, which caused t= he >>>>>> system wall time inaccuracy. >>>>>> >>>>>> For example, the dmesg shown that: >>>>>> >>>>>> =C2=A0=C2=A0=C2=A0 [=C2=A0=C2=A0=C2=A0 0.197975] node 0 initialis= ed, 32170688 pages in 1ms >>>>>> >>>>>> Obviously, 1ms is unreasonable. >>>>>> Now, fix it by restore in the pending interrupts inside the while = loop. >>>>>> The reasonable demsg shown likes: >>>>>> >>>>>> [=C2=A0=C2=A0=C2=A0 1.069306] node 0 initialised, 32203456 pages i= n 894ms >>>>> The way I understand the original problem, that Pavel fixed: >>>>> >>>>> we need disable irqs in deferred_init_memmap() since this function = may be called >>>>> in parallel with deferred_grow_zone() called from interrupt handler= . So, Pavel >>>>> added lock to fix the race. >>>>> >>>>> In case of we temporary unlock the lock, interrupt still be possibl= e, >>>>> so my previous proposition returns the problem back. >>>>> >>>>> Now thought again, I think we have to just add: >>>>> >>>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0pgdat_resize_unlock(); >>>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0pgdat_resize_lock(); >>>>> >>>>> instead of releasing interrupts, since in case of we just release t= hem with lock held, >>>>> a call of interrupt->deferred_grow_zone() bring us to a deadlock. >>>>> >>>>> So, unlock the lock is must. >>>> Yes, you're right! I missed this point. >>>> Thanks for your comment! >>>> >>>>>> Signed-off-by: Shile Zhang >>>>>> --- >>>>>> =C2=A0=C2=A0 mm/page_alloc.c | 6 +++++- >>>>>> =C2=A0=C2=A0 1 file changed, 5 insertions(+), 1 deletion(-) >>>>>> >>>>>> diff --git a/mm/page_alloc.c b/mm/page_alloc.c >>>>>> index 3c4eb750a199..d3f337f2e089 100644 >>>>>> --- a/mm/page_alloc.c >>>>>> +++ b/mm/page_alloc.c >>>>>> @@ -1809,8 +1809,12 @@ static int __init deferred_init_memmap(void= *data) >>>>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 * that we can avoid in= troducing any issues with the buddy >>>>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 * allocator. >>>>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 */ >>>>>> -=C2=A0=C2=A0=C2=A0 while (spfn < epfn) >>>>>> +=C2=A0=C2=A0=C2=A0 while (spfn < epfn) { >>>>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 nr_p= ages +=3D deferred_init_maxorder(&i, zone, &spfn, &epfn); >>>>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 /* let in any pending = interrupts */ >>>>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 local_irq_restore(flag= s); >>>>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 local_irq_save(flags); >>>>>> +=C2=A0=C2=A0=C2=A0 } >>>>>> =C2=A0=C2=A0 zone_empty: >>>>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 pgdat_resize_unlock(pgdat, &= flags); >>>>> I think we need here something like below (untested): >>>>> >>>>> diff --git a/mm/page_alloc.c b/mm/page_alloc.c >>>>> index 79e950d76ffc..323afa9a4db5 100644 >>>>> --- a/mm/page_alloc.c >>>>> +++ b/mm/page_alloc.c >>>>> @@ -1828,7 +1828,7 @@ static int __init deferred_init_memmap(void *= data) >>>>> =C2=A0=C2=A0 { >>>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 pg_data_t *pgdat =3D data; >>>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 const struct cpumask *cpumask= =3D cpumask_of_node(pgdat->node_id); >>>>> -=C2=A0=C2=A0=C2=A0 unsigned long spfn =3D 0, epfn =3D 0, nr_pages = =3D 0; >>>>> +=C2=A0=C2=A0=C2=A0 unsigned long spfn =3D 0, epfn =3D 0, nr_pages = =3D 0, prev_nr_pages =3D 0; >>>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 unsigned long first_init_pfn,= flags; >>>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 unsigned long start =3D jiffi= es; >>>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 struct zone *zone; >>>>> @@ -1869,8 +1869,18 @@ static int __init deferred_init_memmap(void = *data) >>>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 * that we can avoid int= roducing any issues with the buddy >>>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 * allocator. >>>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 */ >>>>> -=C2=A0=C2=A0=C2=A0 while (spfn < epfn) >>>>> +=C2=A0=C2=A0=C2=A0 while (spfn < epfn) { >>>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 nr_pa= ges +=3D deferred_init_maxorder(&i, zone, &spfn, &epfn); >>>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 /* >>>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 * Release interru= pts every 1Gb to give a possibility >>>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 * a timer to adva= nce jiffies. >>>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 */ >>>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (nr_pages - prev_nr_= pages > (1UL << (30 - PAGE_SHIFT))) { >>>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= prev_nr_pages =3D nr_pages; >>>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= pgdat_resize_unlock(pgdat, &flags); >>>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= pgdat_resize_lock(pgdat, &flags); >>>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } >>>>> +=C2=A0=C2=A0=C2=A0 } >>>>> =C2=A0=C2=A0 zone_empty: >>>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 pgdat_resize_unlock(pgdat, &f= lags); >>>>> =C2=A0 (I believe the comment may be improved more). >>>> Yeah, your patch is better! >>>> I test your code and it works! >>>> But it seems that 1G is still hold the interrupts too long, about 40= ms in my env >>>> with Intel(R) Xeon(R) 2.5GHz). I tried other size, it is OK to use 1= 024 pages (4MB), >>>> which suggested by Andrew's before. >>>> >>>> Could you please help to review it again? >>>> >>>> diff --git a/mm/page_alloc.c b/mm/page_alloc.c >>>> index 3c4eb750a199..5def66d3ffcd 100644 >>>> --- a/mm/page_alloc.c >>>> +++ b/mm/page_alloc.c >>>> @@ -1768,7 +1768,7 @@ static int __init deferred_init_memmap(void *d= ata) >>>> =C2=A0=C2=A0{ >>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 pg_data_t *pgdat =3D= data; >>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 const struct cpuma= sk *cpumask =3D cpumask_of_node(pgdat->node_id); >>>> -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 unsigned long spfn =3D 0, epfn= =3D 0, nr_pages =3D 0; >>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 unsigned long spfn =3D 0, epfn= =3D 0, nr_pages =3D 0, prev_nr_pages =3D 0; >>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 unsigned long firs= t_init_pfn, flags; >>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 unsigned long star= t =3D jiffies; >>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 struct zone *zone; >>>> @@ -1809,8 +1809,17 @@ static int __init deferred_init_memmap(void *= data) >>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 * that we ca= n avoid introducing any issues with the buddy >>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 * allocator. >>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 */ >>>> -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 while (spfn < epfn) >>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 while (spfn < epfn) { >>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 nr_pages +=3D deferred_init_maxorder(&i, zone= , &spfn, &epfn); >>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 /* >>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 * Restore pending interrupts every 1024 pages to gi= ve >>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 * the chance tick timer to advance jiffies. >>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 */ >>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 if (nr_pages - prev_nr_pages > 1024) { >>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 pgdat_res= ize_unlock(&flags); >>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 pgdat_res= ize_lock(&flags); >>> Here is problem: prev_nr_pages must be updated. >>> >>> Anyway, releasing every 4M looks wrong for me, since you removes the = fix that Pavel introduced. >>> He protected against big allocations made from interrupt content. But= in case of we unlock >>> the lock after 4Mb, only 4Mb will be available for allocations from i= nterrupts. pgdat->first_deferred_pfn >>> is updated at the start of function, so interrupt allocations won't b= e able to initialize >>> mode for themselve. >> Yes, you're right. I missed this point since I'm not fully understood = the code before. >> Thanks for your advice! >>> In case of you want unlock interrupts very often, you should make som= e creativity with first_deferred_pfn. >>> We should update it sequentially. Something like below (untested): >> I got your point now, thanks! >>> --- >>> diff --git a/mm/page_alloc.c b/mm/page_alloc.c >>> index 79e950d76ffc..be09d158baeb 100644 >>> --- a/mm/page_alloc.c >>> +++ b/mm/page_alloc.c >>> @@ -1828,7 +1828,7 @@ static int __init deferred_init_memmap(void *da= ta) >>> =C2=A0 { >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 pg_data_t *pgdat =3D data; >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 const struct cpumask *cpumask =3D cpu= mask_of_node(pgdat->node_id); >>> -=C2=A0=C2=A0=C2=A0 unsigned long spfn =3D 0, epfn =3D 0, nr_pages =3D= 0; >>> +=C2=A0=C2=A0=C2=A0 unsigned long spfn =3D 0, epfn =3D 0, nr_pages; >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 unsigned long first_init_pfn, flags; >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 unsigned long start =3D jiffies; >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 struct zone *zone; >>> @@ -1838,7 +1838,7 @@ static int __init deferred_init_memmap(void *da= ta) >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 /* Bind memory initialisation thread = to a local node if possible */ >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (!cpumask_empty(cpumask)) >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 set_cpus_allo= wed_ptr(current, cpumask); >>> - >>> +again: >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 pgdat_resize_lock(pgdat, &flags); >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 first_init_pfn =3D pgdat->first_defer= red_pfn; >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (first_init_pfn =3D=3D ULONG_MAX) = { >>> @@ -1850,7 +1850,6 @@ static int __init deferred_init_memmap(void *da= ta) >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 /* Sanity check boundaries */ >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 BUG_ON(pgdat->first_deferred_pfn < pg= dat->node_start_pfn); >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 BUG_ON(pgdat->first_deferred_pfn > pg= dat_end_pfn(pgdat)); >>> -=C2=A0=C2=A0=C2=A0 pgdat->first_deferred_pfn =3D ULONG_MAX; >>> =C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 /* Only the highest zone is de= ferred so find it */ >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 for (zid =3D 0; zid < MAX_NR_ZONES; z= id++) { >>> @@ -1864,14 +1863,30 @@ static int __init deferred_init_memmap(void *= data) >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0 first_init_pfn)) >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 goto zone_emp= ty; >>> =C2=A0 +=C2=A0=C2=A0=C2=A0 nr_pages =3D 0; >> 'nr_pages' used to mark the total init pages before, so it cannot be z= erolized each round. >> seems we need one more to count the pages init each round. >> >>> + >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 /* >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 * Initialize and free pages in = MAX_ORDER sized increments so >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 * that we can avoid introducing= any issues with the buddy >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 * allocator. >>> +=C2=A0=C2=A0=C2=A0=C2=A0 * Final iteration marker is: spfn=3DULONG_M= AX and epfn=3D0. >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 */ >>> -=C2=A0=C2=A0=C2=A0 while (spfn < epfn) >>> +=C2=A0=C2=A0=C2=A0 while (spfn < epfn) { >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 nr_pages +=3D= deferred_init_maxorder(&i, zone, &spfn, &epfn); >>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (!epfn) >>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 b= reak; >> Seems 'epfn' never goes to 0 since it is "end page frame number", righ= t? >> So this is needless. >>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 pgdat->first_deferred_pfn= =3D epfn; >> I think first_deferred_pfn update wrong value here, it seems should be= the spfn, the start pfn right? >>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 /* >>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 * Restore pending i= nterrupts every 128Mb to give >>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 * the chance tick t= imer to advance jiffies. >>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 */ >>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (nr_pages > (1UL << 27= - PAGE_SHIFT)) { >>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 p= gdat_resize_unlock(pgdat, &flags); >>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 g= oto again; >>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } >>> +=C2=A0=C2=A0=C2=A0 } >>> =C2=A0 zone_empty: >>> +=C2=A0=C2=A0=C2=A0 pgdat->first_deferred_pfn =3D ULONG_MAX; >>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 pgdat_resize_unlock(pgdat, &flags); >>> =C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 /* Sanity check that the next = zone really is unpopulated */ >>> >>> >> I update the patch based on your comment, it passed the test. >> Could you please help to review it again? Thanks! > The patch is OK for me. It may be sent into ml with an appropriate desc= ription. > > Feel free to not forget to add my: > > Co-developed-by: Kirill Tkhai Yeah, sure! Many thanks for your kindly help on this issue! I'll send out v3 later for further review. >> diff --git a/mm/page_alloc.c b/mm/page_alloc.c >> index 3c4eb750a199..841c902d4509 100644 >> --- a/mm/page_alloc.c >> +++ b/mm/page_alloc.c >> @@ -1763,12 +1763,17 @@ deferred_init_maxorder(u64 *i, struct zone *zo= ne, unsigned long *start_pfn, >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return nr_pages; >> =C2=A0} >> >> +/* >> + * Release the tick timer interrupts for every TICK_PAGE_COUNT pages. >> + */ >> +#define TICK_PAGE_COUNT=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (32= * 1024) >> + >> =C2=A0/* Initialise remaining memory on a node */ >> =C2=A0static int __init deferred_init_memmap(void *data) >> =C2=A0{ >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 pg_data_t *pgdat =3D data; >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 const struct cpumask *cpum= ask =3D cpumask_of_node(pgdat->node_id); >> -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 unsigned long spfn =3D 0, epfn =3D= 0, nr_pages =3D 0; >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 unsigned long spfn =3D 0, epfn =3D= 0, nr_pages =3D 0, prev_nr_pages =3D 0; >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 unsigned long first_init_p= fn, flags; >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 unsigned long start =3D ji= ffies; >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 struct zone *zone; >> @@ -1779,6 +1784,7 @@ static int __init deferred_init_memmap(void *dat= a) >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (!cpumask_empty(cpumask= )) >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 set_cpus_allowed_ptr(current, cpumask); >> >> +again: >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 pgdat_resize_lock(pgdat, &= flags); >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 first_init_pfn =3D pgdat->= first_deferred_pfn; >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (first_init_pfn =3D=3D = ULONG_MAX) { >> @@ -1790,7 +1796,6 @@ static int __init deferred_init_memmap(void *dat= a) >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 /* Sanity check boundaries= */ >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 BUG_ON(pgdat->first_deferr= ed_pfn < pgdat->node_start_pfn); >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 BUG_ON(pgdat->first_deferr= ed_pfn > pgdat_end_pfn(pgdat)); >> -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 pgdat->first_deferred_pfn =3D UL= ONG_MAX; >> >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 /* Only the highest zone i= s deferred so find it */ >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 for (zid =3D 0; zid < MAX_= NR_ZONES; zid++) { >> @@ -1809,9 +1814,23 @@ static int __init deferred_init_memmap(void *da= ta) >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 * that we can avoid = introducing any issues with the buddy >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 * allocator. >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 */ >> -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 while (spfn < epfn) >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 while (spfn < epfn) { >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 nr_pages +=3D deferred_init_maxorder(&i, zone, &spf= n, &epfn); >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 /* >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 * Release the interrupts for every TICK_PAGE_COUNT = pages >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 * (128MB) to give the chance that tick timer to adv= ance >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 * the jiffies. >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 */ >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 if ((nr_pages - prev_nr_pages) > TICK_PAGE_COUNT) { >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 prev_nr_p= ages =3D nr_pages; >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 pgdat->fi= rst_deferred_pfn =3D spfn; >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 pgdat_res= ize_unlock(pgdat, &flags); >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 goto agai= n; >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 } >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } >> + >> =C2=A0zone_empty: >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 pgdat->first_deferred_pfn =3D UL= ONG_MAX; >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 pgdat_resize_unlock(pgdat,= &flags); >> >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 /* Sanity check that the n= ext zone really is unpopulated */ >>