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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6D24CC433EF for ; Thu, 9 Dec 2021 08:23:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ACD446B0071; Thu, 9 Dec 2021 03:23:44 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A7D546B0073; Thu, 9 Dec 2021 03:23:44 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9452C6B0074; Thu, 9 Dec 2021 03:23:44 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay040.a.hostedemail.com [64.99.140.40]) by kanga.kvack.org (Postfix) with ESMTP id 853C56B0071 for ; Thu, 9 Dec 2021 03:23:44 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 4D94C20766 for ; Thu, 9 Dec 2021 08:23:34 +0000 (UTC) X-FDA: 78897566748.04.BAEFBB4 Received: from mail-pj1-f52.google.com (mail-pj1-f52.google.com [209.85.216.52]) by imf26.hostedemail.com (Postfix) with ESMTP id D7D88140004 for ; Thu, 9 Dec 2021 08:23:33 +0000 (UTC) Received: by mail-pj1-f52.google.com with SMTP id gx15-20020a17090b124f00b001a695f3734aso4269812pjb.0 for ; Thu, 09 Dec 2021 00:23:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:subject:to:cc:references:in-reply-to:mime-version :message-id:content-transfer-encoding; bh=dLqP1guCn/r+kGclQ+T8fzrANkza7YB7+xALSKJG+GI=; b=pV/RKtzJbD+t9CgjEoqdplktI2KSASrvxsMvsUWeafO+4Jo4qOphpQCuJ/wtceOzn0 JBrW4BwkrKfz+ULAcQxuzmkh/Ivzf3Ow41rO2nKo8pK3a5Wsg1L3NGH34xY9EuwfHZXt ydmdKknpMgc+lrWoh4ozrgTiJCshjNfJ9/F3fVhC8Maawt6O9aIFEZ/FSJCXe9gLTZlp X/bkV6k+Po0HAAYt7biKYdGU4+D7UoXENtrmYgLbHclZa20xhzAZiGmGLhliNLUcbTU0 UxlxOjCU/F+0OBntLn+QLiT1XukASmlt8w98NvjwRlgiYSeZASu//S7QyQwKuO+auJsM Bqqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:subject:to:cc:references:in-reply-to :mime-version:message-id:content-transfer-encoding; bh=dLqP1guCn/r+kGclQ+T8fzrANkza7YB7+xALSKJG+GI=; b=r59Y+Z1hiCKTFy8hRJrxDAgJszO3GkwoYA7jWmQ/ZOb1X1boG173sgFq7bmYL86i07 h2YbE+974NvxYCPyWyOb040iulpvdBOuqvT6H778wzzphVHoyn4eBbU6ioSPWflewISI jllVR49MK1/kTfyij/l9VeEG/dC2w52yhl0QiGnqQWf1UQ1YMY7BdyIC6XAMhN1s632P fnz1B03p8JfaIEc8dvTi8ZPcOsqDvE1tJgQCTetkBEV9mH2Xz/Wcbkl8SNDDiK+IBOKU ZRyXwYhG/jc5ES+EE4pJDInQycAn7c5w401Qe4Jje2x6X7DEamUzpDaLfeJPryJBAzcB m8xQ== X-Gm-Message-State: AOAM531SlGUbZtyJOouEYUcdzoqPKROrXQve3eMlx1rFP+yZnSQ8mZsQ H11zYiS0CLLK/ZgmyqIQlhdN4FW1Amg= X-Google-Smtp-Source: ABdhPJxI8BPKYP7gTdZruvCIOUpoKihJ3ufFkiiviMs2CEbAXbZE0w6TLqhcnbuJEliK6T8HERQRJg== X-Received: by 2002:a17:90b:4d86:: with SMTP id oj6mr13864797pjb.101.1639038212692; Thu, 09 Dec 2021 00:23:32 -0800 (PST) Received: from localhost (203-219-139-206.static.tpgi.com.au. [203.219.139.206]) by smtp.gmail.com with ESMTPSA id s38sm6748679pfg.17.2021.12.09.00.23.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Dec 2021 00:23:32 -0800 (PST) Date: Thu, 09 Dec 2021 18:23:25 +1000 From: Nicholas Piggin Subject: Re: [PATCH] mm/vmalloc: allocate small pages for area->pages To: linux-mm@kvack.org, Xu Yu Cc: akpm@linux-foundation.org References: In-Reply-To: MIME-Version: 1.0 Message-Id: <1639037882.ddpnbp5ftw.astroid@bobo.none> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b="pV/RKtzJ"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf26.hostedemail.com: domain of npiggin@gmail.com designates 209.85.216.52 as permitted sender) smtp.mailfrom=npiggin@gmail.com X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: D7D88140004 X-Stat-Signature: fr9ok88ybkkhthyje1ea96s8999x46f9 X-HE-Tag: 1639038213-527312 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: Excerpts from Xu Yu's message of December 7, 2021 7:46 pm: > The area->pages stores the struct pages allocated for vmalloc mappings. > The allocated memory can be hugepage if arch has HAVE_ARCH_HUGE_VMALLOC > set, while area->pages itself does not have to be hugepage backed. >=20 > Suppose that we want to vmalloc 1026M of memory, then area->pages is > 2052K in size, which is large than PMD_SIZE when the pagesize is 4K. > Currently, 4096K will be allocated for area->pages, wherein 2044K is > wasted. >=20 > This introduces __vmalloc_node_no_huge, and makes area->pages backed by > small pages, because I think to allocate hugepage for area->pages is > unnecessary and vulnerable to abuse. Any vmalloc allocation will be subject to internal fragmentation like this. What makes this one special? Is there a way to improve it for all with some heuristic? There would be an argument for a size-optimised vmalloc vs a space=20 optimised one. An accounting strucutre like this doesn't matter much for speed. A vfs hash table does. Is it worth doing though? How much do you gain in practice? Thanks, Nick >=20 > Signed-off-by: Xu Yu > --- > include/linux/vmalloc.h | 2 ++ > mm/vmalloc.c | 15 ++++++++++++--- > 2 files changed, 14 insertions(+), 3 deletions(-) >=20 > diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h > index 6e022cc712e6..e93f39eb46a5 100644 > --- a/include/linux/vmalloc.h > +++ b/include/linux/vmalloc.h > @@ -150,6 +150,8 @@ extern void *__vmalloc_node_range(unsigned long size,= unsigned long align, > const void *caller) __alloc_size(1); > void *__vmalloc_node(unsigned long size, unsigned long align, gfp_t gfp_= mask, > int node, const void *caller) __alloc_size(1); > +void *__vmalloc_node_no_huge(unsigned long size, unsigned long align, > + gfp_t gfp_mask, int node, const void *caller) __alloc_size(1); > void *vmalloc_no_huge(unsigned long size) __alloc_size(1); > =20 > extern void vfree(const void *addr); > diff --git a/mm/vmalloc.c b/mm/vmalloc.c > index d2a00ad4e1dd..0bdbb96d3e3f 100644 > --- a/mm/vmalloc.c > +++ b/mm/vmalloc.c > @@ -2925,17 +2925,18 @@ static void *__vmalloc_area_node(struct vm_struct= *area, gfp_t gfp_mask, > unsigned long size =3D get_vm_area_size(area); > unsigned long array_size; > unsigned int nr_small_pages =3D size >> PAGE_SHIFT; > + unsigned int max_small_pages =3D ALIGN(size, 1UL << page_shift) >> PAGE= _SHIFT; > unsigned int page_order; > =20 > - array_size =3D (unsigned long)nr_small_pages * sizeof(struct page *); > + array_size =3D (unsigned long)max_small_pages * sizeof(struct page *); > gfp_mask |=3D __GFP_NOWARN; > if (!(gfp_mask & (GFP_DMA | GFP_DMA32))) > gfp_mask |=3D __GFP_HIGHMEM; > =20 > /* Please note that the recursion is strictly bounded. */ > if (array_size > PAGE_SIZE) { > - area->pages =3D __vmalloc_node(array_size, 1, nested_gfp, node, > - area->caller); > + area->pages =3D __vmalloc_node_no_huge(array_size, 1, nested_gfp, > + node, area->caller); > } else { > area->pages =3D kmalloc_node(array_size, nested_gfp, node); > } > @@ -3114,6 +3115,14 @@ void *__vmalloc_node(unsigned long size, unsigned = long align, > return __vmalloc_node_range(size, align, VMALLOC_START, VMALLOC_END, > gfp_mask, PAGE_KERNEL, 0, node, caller); > } > + > +void *__vmalloc_node_no_huge(unsigned long size, unsigned long align, > + gfp_t gfp_mask, int node, const void *caller) > +{ > + return __vmalloc_node_range(size, align, VMALLOC_START, VMALLOC_END, > + gfp_mask, PAGE_KERNEL, VM_NO_HUGE_VMAP, node, caller); > +} > + > /* > * This is only for performance analysis of vmalloc and stress purpose. > * It is required by vmalloc test module, therefore do not use it other > --=20 > 2.20.1.2432.ga663e714 >=20 >=20