Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp257309imm; Tue, 24 Jul 2018 18:32:49 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdTcfdSK22jb08HK2JAAXBFLiR3Mvhxc0UkIvyKsWkWoKuIAfVEvATLJWY46yd9xMogUCOt X-Received: by 2002:a17:902:6b84:: with SMTP id p4-v6mr19029265plk.272.1532482369410; Tue, 24 Jul 2018 18:32:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532482369; cv=none; d=google.com; s=arc-20160816; b=f5Y1M4D3dNxeKVlAObz4Xe/SK7T000AS+QsZQEaMLRowDPSJqFjM0tothUKRVZ1MuP PFiAyS3x0fLQb9DmNdUKQDlmLJ/iLxDiZcxwk8yiyjmvaXPKJoPZqF6yyedCjc7mCI+T BKpUZp0P39pHFPjSccx03zGc0DSaXAbYmd79DnQJYvDQeiUDvnEFFxNu+aVwLcBkh4Rf pObKxhPZydVUOhtyU4P7tRy6cMa8eB6YxdYWDKIEXqpOHYiNXzd/qw3B2ZAi+VRX5GzC HcDzb/8syxToRRaJdQ8C5+l3qs383FR9CXZPScQ1IN8YsUseut5HXAaW9FHkcGHjtpil Ynaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :arc-authentication-results; bh=hKvty3D8tUJV9Hc+TJILvyOJqnOjcND2kg5P1qpWesQ=; b=UzJjCkRo+qmz2GXSGlPsEbOwZW+BDxU21ziHAscOoDUEHiFCRRfFPxOaMM91jvklaH 1RvTTfCRMNsyyOfqJKjQ2SBZj84aD2scE+kjwJ5E7UhFIkoDNkSbNNrM4g6FrFmSlZ2a eElyu8JNx9TT3851m47+/LSH732V35d0At9DvMGsrNi2h2AQhbXwJty92WWq6WhUsB6U OFGHrPd6CEdkjNY3Zn2QRUWYcav62n5ZyGnsZ5JKERp6+sw7ZUXT+E0oKVgF6EHsdPSG W3O1i6tvlGybfsBfdT4qybNf4f2XgfXbeWA8jqoKJwRAGWX27U7+ob1MXrSQaFtHpTu8 CWvg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i18-v6si12751919pgn.433.2018.07.24.18.32.34; Tue, 24 Jul 2018 18:32:49 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388539AbeGYCk7 (ORCPT + 99 others); Tue, 24 Jul 2018 22:40:59 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:34278 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388485AbeGYCk7 (ORCPT ); Tue, 24 Jul 2018 22:40:59 -0400 Received: from localhost.localdomain (c-24-4-125-7.hsd1.ca.comcast.net [24.4.125.7]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 90427D3A; Wed, 25 Jul 2018 01:31:44 +0000 (UTC) Date: Tue, 24 Jul 2018 18:31:42 -0700 From: Andrew Morton To: Pavel Tatashin Cc: steven.sistare@oracle.com, daniel.m.jordan@oracle.com, linux-kernel@vger.kernel.org, kirill.shutemov@linux.intel.com, mhocko@suse.com, linux-mm@kvack.org, dan.j.williams@intel.com, jack@suse.cz, jglisse@redhat.com, jrdr.linux@gmail.com, bhe@redhat.com, gregkh@linuxfoundation.org, vbabka@suse.cz, richard.weiyang@gmail.com, dave.hansen@intel.com, rientjes@google.com, mingo@kernel.org, osalvador@techadventures.net, abdhalee@linux.vnet.ibm.com, mpe@ellerman.id.au Subject: Re: [PATCH 2/3] mm: calculate deferred pages after skipping mirrored memory Message-Id: <20180724183142.d20798b43fd1215f6165649c@linux-foundation.org> In-Reply-To: <20180724235520.10200-3-pasha.tatashin@oracle.com> References: <20180724235520.10200-1-pasha.tatashin@oracle.com> <20180724235520.10200-3-pasha.tatashin@oracle.com> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 24 Jul 2018 19:55:19 -0400 Pavel Tatashin wrote: > update_defer_init() should be called only when struct page is about to be > initialized. Because it counts number of initialized struct pages, but > there we may skip struct pages if there is some mirrored memory. > > So move, update_defer_init() after checking for mirrored memory. > > Also, rename update_defer_init() to defer_init() and reverse the return > boolean to emphasize that this is a boolean function, that tells that the > reset of memmap initialization should be deferred. > > Make this function self-contained: do not pass number of already > initialized pages in this zone by using static counters. > > ... > > --- a/mm/page_alloc.c > +++ b/mm/page_alloc.c > @@ -306,24 +306,28 @@ static inline bool __meminit early_page_uninitialised(unsigned long pfn) > } > > /* > - * Returns false when the remaining initialisation should be deferred until > + * Returns true when the remaining initialisation should be deferred until > * later in the boot cycle when it can be parallelised. > */ > -static inline bool update_defer_init(pg_data_t *pgdat, > - unsigned long pfn, unsigned long zone_end, > - unsigned long *nr_initialised) > +static inline bool defer_init(int nid, unsigned long pfn, unsigned long end_pfn) > { > + static unsigned long prev_end_pfn, nr_initialised; So answer me quick, what happens with a static variable in an inlined function? Is there one copy kernel-wide? One copy per invocation site? One copy per compilation unit? Well I didn't know so I wrote a little test. One copy per compilation unit (.o file), it appears. It's OK in this case because the function is in .c (and has only one call site). But if someone moves it into a header and uses it from a different .c file, they have problems. So it's dangerous, and poor practice. I'll make this non-static __meminit. --- a/mm/page_alloc.c~mm-calculate-deferred-pages-after-skipping-mirrored-memory-fix +++ a/mm/page_alloc.c @@ -309,7 +309,8 @@ static inline bool __meminit early_page_ * Returns true when the remaining initialisation should be deferred until * later in the boot cycle when it can be parallelised. */ -static inline bool defer_init(int nid, unsigned long pfn, unsigned long end_pfn) +static bool __meminit +defer_init(int nid, unsigned long pfn, unsigned long end_pfn) { static unsigned long prev_end_pfn, nr_initialised; Also, what locking protects these statics? Our knowledge that this code is single-threaded, presumably?