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=-17.0 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS, 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 5B0DBC433DB for ; Tue, 23 Mar 2021 20:49:46 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id DCC0C6148E for ; Tue, 23 Mar 2021 20:49:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DCC0C6148E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 67B7F8D001C; Tue, 23 Mar 2021 16:49:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 605B98D0017; Tue, 23 Mar 2021 16:49:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 430CB8D001C; Tue, 23 Mar 2021 16:49:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0056.hostedemail.com [216.40.44.56]) by kanga.kvack.org (Postfix) with ESMTP id 22A9E8D0017 for ; Tue, 23 Mar 2021 16:49:45 -0400 (EDT) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id DB227180B2607 for ; Tue, 23 Mar 2021 20:49:44 +0000 (UTC) X-FDA: 77952330288.02.0EC9D4B Received: from mail-lf1-f53.google.com (mail-lf1-f53.google.com [209.85.167.53]) by imf03.hostedemail.com (Postfix) with ESMTP id A0B97C0007C8 for ; Tue, 23 Mar 2021 20:49:43 +0000 (UTC) Received: by mail-lf1-f53.google.com with SMTP id a198so28657359lfd.7 for ; Tue, 23 Mar 2021 13:49:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:date:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=ovYAdVajAyXtjN+CNCMcxEXjoG9u3DCv652EWDHLb+U=; b=dH+1Vra1FvaZnh3o1V2Xcbmb7AAAnhDf2KJGsfCWjWS+AZN1/hZj14WTDG49On1bWs ijeyOOSibU7EHfF/a4XSfhQ2Mey64CmyElQZlJ6jrOsa4n9AzENYAIPtQCyu5EJo9cye wVI7SKnO2woPUaAQnHtUYIQ4ivgUwOAZesVvi66TvyXvUewU2oFND5o7MEc8vj7m8GWL DlFnzRyTQocy5WwKM2byImdIiNG0iwv3W1hU+hEJjxqKV8B0RDzwCMe3vyXHV7yP6nNP avS6dCvc/aLhaEHpZZ4JiBoeI8hfy0FSkybt556eHQBewX48INB0sea8uebysicx4oSS C+HQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=ovYAdVajAyXtjN+CNCMcxEXjoG9u3DCv652EWDHLb+U=; b=eoCPtn012pUl6p6Hd98SMWOk+RqlF8cT0I4bsTV18jSBuFh1O5jOZriXYV3YfgXMEc prx3age8Q7tKA/DARLlNjxkGbGtKdNDXWnlfadbX1W+ColJp4qeXf4Fvfim0vu1tMQ/I BFhShrl5HuPwxXewy0G6jIF6J3XJSedqiRrANJ/s1sfw2VFREKnMQqZSjUN+LX0hnf+i DzP1QAjPH2Y6Ee0dAGYIcX9/ix+yytavXJSfvRYq/zoRvetgrEVvvTJq+l5lUywOKsH3 cSLWr3wgfNui4HA+7xYQAPhL+6QUO0NzhDkysbQUwbKWgOn31ojNN2mb/dYa/HVkTCui xsyA== X-Gm-Message-State: AOAM532oSKNPL/6fvheTwlh/JDgGVPe5A/0oWsV/Gj2lenN0s3VxbBb+ kd3DX4xX8IcysEfarU6p8IY= X-Google-Smtp-Source: ABdhPJzU56a+X3rwCrMwEZT0dt02LSMyA5QJrFOLR2BYBtGE6sn91UufLCUMvTgX/xPRNvMD+Gm4hw== X-Received: by 2002:a05:6512:991:: with SMTP id w17mr3629952lft.85.1616532582884; Tue, 23 Mar 2021 13:49:42 -0700 (PDT) Received: from pc638.lan (h5ef52e3d.seluork.dyn.perspektivbredband.net. [94.245.46.61]) by smtp.gmail.com with ESMTPSA id 196sm18178lfo.29.2021.03.23.13.49.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Mar 2021 13:49:42 -0700 (PDT) From: Uladzislau Rezki X-Google-Original-From: Uladzislau Rezki Date: Tue, 23 Mar 2021 21:49:40 +0100 To: Matthew Wilcox Cc: Uladzislau Rezki , Andrew Morton , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Vlastimil Babka , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Nicholas Piggin Subject: Re: [PATCH 2/2] mm/vmalloc: Use kvmalloc to allocate the table of pages Message-ID: <20210323204940.GB52881@pc638.lan> References: <20210322193820.2140045-1-willy@infradead.org> <20210322193820.2140045-2-willy@infradead.org> <20210322223619.GA56503@pc638.lan> <20210322230311.GY1719932@casper.infradead.org> <20210323120436.GA1949@pc638.lan> <20210323123913.GD1719932@casper.infradead.org> <20210323133948.GA10046@pc638.lan> <20210323140722.GG1719932@casper.infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20210323140722.GG1719932@casper.infradead.org> User-Agent: Mutt/1.10.1 (2018-07-13) X-Stat-Signature: 8eooobjnzsdrf35siyg3rbqcxfegp7zw X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: A0B97C0007C8 Received-SPF: none (gmail.com>: No applicable sender policy available) receiver=imf03; identity=mailfrom; envelope-from=""; helo=mail-lf1-f53.google.com; client-ip=209.85.167.53 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1616532583-919105 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 Tue, Mar 23, 2021 at 02:07:22PM +0000, Matthew Wilcox wrote: > On Tue, Mar 23, 2021 at 02:39:48PM +0100, Uladzislau Rezki wrote: > > On Tue, Mar 23, 2021 at 12:39:13PM +0000, Matthew Wilcox wrote: > > > On Tue, Mar 23, 2021 at 01:04:36PM +0100, Uladzislau Rezki wrote: > > > > On Mon, Mar 22, 2021 at 11:03:11PM +0000, Matthew Wilcox wrote: > > > > > I suspect the vast majority of the time is spent calling alloc_= pages_node() > > > > > 1024 times. Have you looked at Mel's patch to do ... well, exa= ctly what > > > > > vmalloc() wants? > > > > >=20 > > > > > > > > - __vmalloc_node_range > > > > - 45.25% __alloc_pages_nodemask > > > > - 37.59% get_page_from_freelist > > > [...] > > > > - 44.61% 0xffffffffc047348d > > > > - __vunmap > > > > - 35.56% free_unref_page > > >=20 > > > Hmm! I hadn't been thinking about the free side of things. > > > Does this make a difference? > > >=20 > > > diff --git a/mm/vmalloc.c b/mm/vmalloc.c > > > index 4f5f8c907897..61d5b769fea0 100644 > > > --- a/mm/vmalloc.c > > > +++ b/mm/vmalloc.c > > > @@ -2277,16 +2277,8 @@ static void __vunmap(const void *addr, int d= eallocate_pages) > > > vm_remove_mappings(area, deallocate_pages); > > > =20 > > > if (deallocate_pages) { > > > - int i; > > > - > > > - for (i =3D 0; i < area->nr_pages; i++) { > > > - struct page *page =3D area->pages[i]; > > > - > > > - BUG_ON(!page); > > > - __free_pages(page, 0); > > > - } > > > + release_pages(area->pages, area->nr_pages); > > > atomic_long_sub(area->nr_pages, &nr_vmalloc_pages); > > > - > > > kvfree(area->pages); > > > } > > >=20 > > Will check it today! > >=20 > > > release_pages does a bunch of checks that are unnecessary ... we co= uld > > > probably just do: > > >=20 > > > LIST_HEAD(pages_to_free); > > >=20 > > > for (i =3D 0; i < area->nr_pages; i++) { > > > struct page *page =3D area->pages[i]; > > > if (put_page_testzero(page)) > > > list_add(&page->lru, &pages_to_free); > > > } > > > free_unref_page_list(&pages_to_free); > > >=20 > > > but let's see if the provided interface gets us the performance we = want. > > > =20 > > > > Reviewed-by: Uladzislau Rezki (Sony) > > > >=20 > > > > Thanks! > > >=20 > > > Thank you! > > You are welcome. A small nit: > >=20 > > CC mm/vmalloc.o > > mm/vmalloc.c: In function =E2=80=98__vmalloc_area_node=E2=80=99: > > mm/vmalloc.c:2492:14: warning: passing argument 4 of =E2=80=98kvmallo= c_node_caller=E2=80=99 makes integer from pointer without a cast [-Wint-c= onversion] > > area->caller); > > ~~~~^~~~~~~~ > > In file included from mm/vmalloc.c:12: > > ./include/linux/mm.h:782:7: note: expected =E2=80=98long unsigned int= =E2=80=99 but argument is of type =E2=80=98const void *=E2=80=99 > > void *kvmalloc_node_caller(size_t size, gfp_t flags, int node, >=20 > Oh, thank you! I confused myself by changing the type halfway through. > vmalloc() uses void * to match __builtin_return_address while most > of the rest of the kernel uses unsigned long to match _RET_IP_. > I'll submit another patch to convert vmalloc to use _RET_IP_. >=20 Thanks! > > As for the bulk-array interface. I have checked the: > >=20 > > git://git.kernel.org/pub/scm/linux/kernel/git/mel/linux.git mm-bulk-r= ebase-v6r2 > >=20 > > applied the patch that is in question + below one: > >=20 > > > > @@ -2503,25 +2498,13 @@ static void *__vmalloc_area_node(struct vm_st= ruct *area, gfp_t gfp_mask, > > area->pages =3D pages; > > area->nr_pages =3D nr_pages; > > =20 > > - for (i =3D 0; i < area->nr_pages; i++) { > > - struct page *page; > > - > > - if (node =3D=3D NUMA_NO_NODE) > > - page =3D alloc_page(gfp_mask); > > - else > > - page =3D alloc_pages_node(node, gfp_mask, 0); > > - > > - if (unlikely(!page)) { > > - /* Successfully allocated i pages, free them = in __vfree() */ > > - area->nr_pages =3D i; > > - atomic_long_add(area->nr_pages, &nr_vmalloc_p= ages); > > - goto fail; > > - } > > - area->pages[i] =3D page; > > - if (gfpflags_allow_blocking(gfp_mask)) > > - cond_resched(); > > + ret =3D alloc_pages_bulk_array(gfp_mask, area->nr_pages, area= ->pages); > > + if (ret =3D=3D nr_pages) > > + atomic_long_add(area->nr_pages, &nr_vmalloc_pages); > > + else { > > + area->nr_pages =3D ret; > > + goto fail; > > } > > - atomic_long_add(area->nr_pages, &nr_vmalloc_pages); > > > >=20 > > single CPU, 4MB allocation, 1000000 avg: 70639437 usec > > single CPU, 4MB allocation, 1000000 avg: 89218654 usec > >=20 > > and now we get ~21% delta. That is very good :) >=20 > Amazing! That's great news for Mel's patch as well as the kvmalloc > change. >=20 Cool! I am glad if it gives some points to the bulk-array interface :) -- Vlad Rezki