Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp306673imm; Tue, 24 Jul 2018 19:52:33 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfBLG+8OtkbKl8H9/qOY9H602iTWE7leT63JAwzGRFHLejtefPaR1yC1uz3GRGz1cKIynfq X-Received: by 2002:a62:c60e:: with SMTP id m14-v6mr20209440pfg.40.1532487152974; Tue, 24 Jul 2018 19:52:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532487152; cv=none; d=google.com; s=arc-20160816; b=JOQdUYFiQpu2cyp8Zx02LVWEivwrswaUjzsO1bRZb6yvec17rsMLsB+bLg78U1Ja3E IHagMHufEUJFQnMBpRdAgs8RoGbeaofYUx7EarfyUl6wSLdxn8fBWyH9TpNthdA0kxzk lWfKlL5o8L28pwE+ATnH9xtV0CZrWcrFo7DI1XiHheqM7Txw7tpEMPpHO9Vvgrs0q76/ SZuu10OPQxrpOryVUSqHdTxh5o1rfdmg/put+aRvrejm7hFW1Qllg2EOsMPj5cHN1Zdg 2EJ52X0S4SlgeqzOrSAQ7vbEcjjbgyAbnjLJknPV0K7opNr15Mcn/5OwUceU6dVx5CoF s3PA== 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:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature:arc-authentication-results; bh=TMuZbCsq1jdCLfh1ewS4vvDU8dd97geERUobvVJOT0Y=; b=apvfXbzm8NcMBm2qH7ld0uRVwj9mnT7S8iw0Fysami0HoP9DkDv6ujjVHQ+L5yLcR9 r4SyTboAMpqwAtTBLwnP+MZsG6EcwAdbOHh6vOeC6z1lh50/lDvNe+XefwKzHszyAJwd P1stB8Elmb5c/ORfAtySfcgVz8vBumpU4TKpmzeBgjNUVXn9DhKRNB9bjzoevNsNAMI0 s2Pk3TyqeCWsW7AZNVkS0FqkRXZB+855iqdxt4jssRYtNPFQ2at9mymdAgy/IsC/imEp Qkwjix967DH82WCleFeOFOek8UpWyGWM9sxUz8B6GXd0jcFMc1trfR85Mn7SCQFiyAyu 3vGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=crDHfJPJ; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 38-v6si12051699pln.92.2018.07.24.19.52.17; Tue, 24 Jul 2018 19:52:32 -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; dkim=pass header.i=@google.com header.s=20161025 header.b=crDHfJPJ; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725801AbeGYEAI (ORCPT + 99 others); Wed, 25 Jul 2018 00:00:08 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:34362 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725750AbeGYEAH (ORCPT ); Wed, 25 Jul 2018 00:00:07 -0400 Received: by mail-wm0-f68.google.com with SMTP id l2-v6so13674961wme.1 for ; Tue, 24 Jul 2018 19:50:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=TMuZbCsq1jdCLfh1ewS4vvDU8dd97geERUobvVJOT0Y=; b=crDHfJPJJSGF2e7Q2Q6EZnpFolAvb36XD7dfLOQdvuDozE243yaPqfHRqxTEmtlKRo spnckbwH7hA0epVAk6fGWZOLhsPh4NjZtyN/DaJz9FdXQGqxwwSbRb+PaK16TrMGRIiB +RGQwiTEjsioevEzkJHVAbq771sgWb9xjtucfeX9i2V+Tqd/ReAx9eL8afZLHwZimBpy BFP3Z0K2cZEs/EZaXeb/lPYmi/OTpPvLERlzDvtL4TbvLRl4atbi2DVuLhEUzJZuR7E+ 1sDpuSb6lv9hn5cdZZLWFDStBCiUqueamV7UKgoj+iO5Z2apfzwvie7DwpYQnm1mc3Rt IQwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=TMuZbCsq1jdCLfh1ewS4vvDU8dd97geERUobvVJOT0Y=; b=UtuYqoILbtietFpOI87RGxFoiHcVDM9KMeZfHfNEGOZASz9fm+kN6xt1MlmKRm9VSu ltY/fBwiWf7WjaHQUtXcIht+0nOT0GbiI7PKL5cRSklh1I5BBJqW5WWocV+v4dKVfDaB iSE94I4dqZfkEg9nwQJk8OnpTut1d3Ov2RNnZWhpVZJwixXLUHKEA2FpgmgZRSV+zmLN FzgzLRJ9ROHC0gs+geptjK3yF2izze7Hi9xmLOtBlpdehgCRjsKWH0oxToh/3SWuCZuk oiLdUxf2i8wO/euq0EzaW0YQUby3DgMokU47Na0bQ36JSnqu12PD8Ycyk0cFgm9II4n4 lCng== X-Gm-Message-State: AOUpUlEYDZfeeFNOg+8sT0/IWNWTnA5zj5dxyrysTmAx6satalVGaxki 75ddnoDPYr1CNlxJDBBeFdVezWF/ed8mfbHi151gqw== X-Received: by 2002:a1c:ae8d:: with SMTP id x135-v6mr3362198wme.20.1532487036291; Tue, 24 Jul 2018 19:50:36 -0700 (PDT) MIME-Version: 1.0 References: <20180724204639.26934-1-cannonmatthews@google.com> <20180724135350.91a90f4f8742ec59c42721c3@linux-foundation.org> In-Reply-To: <20180724135350.91a90f4f8742ec59c42721c3@linux-foundation.org> From: Cannon Matthews Date: Tue, 24 Jul 2018 19:50:25 -0700 Message-ID: Subject: Re: [PATCH] RFC: clear 1G pages with streaming stores on x86 To: akpm@linux-foundation.org Cc: mhocko@kernel.org, mike.kravetz@oracle.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andres Lagar-Cavilla , sqazi@google.com, Paul Turner , David Matlack , Peter Feiner , nullptr@google.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jul 24, 2018 at 1:53 PM Andrew Morton w= rote: > > On Tue, 24 Jul 2018 13:46:39 -0700 Cannon Matthews wrote: > > > Reimplement clear_gigantic_page() to clear gigabytes pages using the > > non-temporal streaming store instructions that bypass the cache > > (movnti), since an entire 1GiB region will not fit in the cache anyway. > > > > ... > > > > Tested: > > Time to `mlock()` a 512GiB region on broadwell CPU > > AVG time (s) % imp. ms/page > > clear_page_erms 133.584 - 261 > > clear_page_nt 34.154 74.43% 67 > > A gigantic improvement! > > > --- a/arch/x86/include/asm/page_64.h > > +++ b/arch/x86/include/asm/page_64.h > > @@ -56,6 +56,9 @@ static inline void clear_page(void *page) > > > > void copy_page(void *to, void *from); > > > > +#define __HAVE_ARCH_CLEAR_GIGANTIC_PAGE > > +void __clear_page_nt(void *page, u64 page_size); > > Nit: the modern way is > > #ifndef __clear_page_nt > void __clear_page_nt(void *page, u64 page_size); > #define __clear_page_nt __clear_page_nt > #endif > > Not sure why, really. I guess it avoids adding two symbols and > having to remember and maintain the relationship between them. > That makes sense, changed to this style. Thanks. > > --- /dev/null > > +++ b/arch/x86/lib/clear_gigantic_page.c > > @@ -0,0 +1,30 @@ > > +#include > > + > > +#include > > +#include > > +#include > > + > > +#if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_HUGETLBFS) > > +#define PAGES_BETWEEN_RESCHED 64 > > +void clear_gigantic_page(struct page *page, > > + unsigned long addr, > > + unsigned int pages_per_huge_page) > > +{ > > + int i; > > + void *dest =3D page_to_virt(page); > > + int resched_count =3D 0; > > + > > + BUG_ON(pages_per_huge_page % PAGES_BETWEEN_RESCHED !=3D 0); > > + BUG_ON(!dest); > > + > > + might_sleep(); > > cond_resched() already does might_sleep() - it doesn't seem needed here. =EF=BF=BCAh gotcha, removed it. The original implementation called both, wh= ich does seem redundant. > > > + for (i =3D 0; i < pages_per_huge_page; i +=3D PAGES_BETWEEN_RESCH= ED) { > > + __clear_page_nt(dest + (i * PAGE_SIZE), > > + PAGES_BETWEEN_RESCHED * PAGE_SIZE); > > + resched_count +=3D cond_resched(); > > + } > > + /* __clear_page_nt requrires and `sfence` barrier. */ > > + wmb(); > > + pr_debug("clear_gigantic_page: rescheduled %d times\n", resched_c= ount); > > +} > > +#endif >