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 E26E2C4332F for ; Thu, 24 Feb 2022 05:58:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 757378D0002; Thu, 24 Feb 2022 00:58:10 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 706808D0001; Thu, 24 Feb 2022 00:58:10 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5F4648D0002; Thu, 24 Feb 2022 00:58:10 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.28]) by kanga.kvack.org (Postfix) with ESMTP id 3B0238D0001 for ; Thu, 24 Feb 2022 00:58:10 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id E095623214 for ; Thu, 24 Feb 2022 05:58:09 +0000 (UTC) X-FDA: 79176617898.09.6FB3BB5 Received: from mail-yb1-f172.google.com (mail-yb1-f172.google.com [209.85.219.172]) by imf09.hostedemail.com (Postfix) with ESMTP id 2AF79140006 for ; Thu, 24 Feb 2022 05:58:09 +0000 (UTC) Received: by mail-yb1-f172.google.com with SMTP id w63so1753488ybe.10 for ; Wed, 23 Feb 2022 21:58:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=aZRlDF8hWNRYQY9pK6CTd02SSyMoTN/lFolx1y0wAt4=; b=5U57mpz8cHyPxqbNyydMgJINUZ6JPYutw2vLH9XEsfFf1KtY4MwXRKrW0fEAb2sOLR KN9NjNlXKrGrlmKcqKNpWCq4P8K3v0wniPhnPeTKcZ6ndkP+27NgvY7bhAapWs1csev1 yLaIE5pPyF9OjQ1OSyhKX2j4ST3k9HFqIq7NWubDkeefk+rIYzOM8U8jYJolwxTXjhU+ PSF118d8xYQSwWzk26vpszyxw2HToe/WtSKzDVsWd39wlKKGv9Zjpk1zPyYgobWhMsQw c5OVp7YpmfN4J3KO4mKhKNOvIBBJ9c3bKYhLvEeXZNz7dM+6j5iL/8onn8XGpgfwPe2M HEgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=aZRlDF8hWNRYQY9pK6CTd02SSyMoTN/lFolx1y0wAt4=; b=lUtxPbSpyfDXa8abuehHeb9K64OCUVr5J1PmZ17AQvJQnvHx+5G/wdC6n3CRmRuNwY KBzn4XRbiz5mKLnLvIM+Zya6ZSs4ZX9G4EUeo7c7GHo2rJUaxGMY3m1C0lkPUNq/xjwf xt8qaTAfyxEwwdyRbM4FcHYjmFVOo7NQkfp6QmES80vN/pa6aGtHwZ34v6Diq1tq9AOG TIAWfvgutbU8nDK4OtcZvVMFDA5DAd9Aju3fwZkBjWCeJngn8az17EGmz88eO93lFQum DOAFc3hIi3uXcVGwkqSlGtWX3Ycc5GQau90Jnfl1v+sX5lKR4E1ntUo7uS1mweRosap3 Rr/A== X-Gm-Message-State: AOAM531JG1dxxbOV7xqoVkUjJekwagn5xrcpXJxdMs5nCIy4J1y5C1nk 5TjPKIIbAKOqPVWVADrjDrH2ngigpqTPsXeW7uwkQcG6rsg7j1w5 X-Google-Smtp-Source: ABdhPJxj92w4OLuJgUtu5oDa3uKzHyY/QkH+o6gXG7Vt0gJW3V64WOAMsC3/biXjaU5LVT7b8gCx6yPGtav8NBjybHE= X-Received: by 2002:a25:d2cd:0:b0:61d:6a33:8129 with SMTP id j196-20020a25d2cd000000b0061d6a338129mr1101624ybg.246.1645682288360; Wed, 23 Feb 2022 21:58:08 -0800 (PST) MIME-Version: 1.0 References: <20220223194807.12070-1-joao.m.martins@oracle.com> <20220223194807.12070-6-joao.m.martins@oracle.com> In-Reply-To: <20220223194807.12070-6-joao.m.martins@oracle.com> From: Muchun Song Date: Thu, 24 Feb 2022 13:57:30 +0800 Message-ID: Subject: Re: [PATCH v6 5/5] mm/page_alloc: reuse tail struct pages for compound devmaps To: Joao Martins Cc: Linux Memory Management List , Dan Williams , Vishal Verma , Matthew Wilcox , Jason Gunthorpe , Jane Chu , Mike Kravetz , Andrew Morton , Jonathan Corbet , Christoph Hellwig , nvdimm@lists.linux.dev, Linux Doc Mailing List Content-Type: text/plain; charset="UTF-8" X-Stat-Signature: 6jtduzb5jwaz3rwiouo7e9e3akwg1xe5 X-Rspam-User: Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=5U57mpz8; spf=pass (imf09.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.219.172 as permitted sender) smtp.mailfrom=songmuchun@bytedance.com; dmarc=pass (policy=none) header.from=bytedance.com X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 2AF79140006 X-HE-Tag: 1645682289-794570 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 Thu, Feb 24, 2022 at 3:48 AM Joao Martins wrote: > > Currently memmap_init_zone_device() ends up initializing 32768 pages > when it only needs to initialize 128 given tail page reuse. That > number is worse with 1GB compound pages, 262144 instead of 128. Update > memmap_init_zone_device() to skip redundant initialization, detailed > below. > > When a pgmap @vmemmap_shift is set, all pages are mapped at a given > huge page alignment and use compound pages to describe them as opposed > to a struct per 4K. > > With @vmemmap_shift > 0 and when struct pages are stored in ram > (!altmap) most tail pages are reused. Consequently, the amount of > unique struct pages is a lot smaller that the total amount of struct > pages being mapped. > > The altmap path is left alone since it does not support memory savings > based on compound pages devmap. > > Signed-off-by: Joao Martins > --- > mm/page_alloc.c | 16 +++++++++++++++- > 1 file changed, 15 insertions(+), 1 deletion(-) > > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > index e0c1e6bb09dd..01f10b5a4e47 100644 > --- a/mm/page_alloc.c > +++ b/mm/page_alloc.c > @@ -6653,6 +6653,20 @@ static void __ref __init_zone_device_page(struct page *page, unsigned long pfn, > } > } > > +/* > + * With compound page geometry and when struct pages are stored in ram most > + * tail pages are reused. Consequently, the amount of unique struct pages to > + * initialize is a lot smaller that the total amount of struct pages being > + * mapped. This is a paired / mild layering violation with explicit knowledge > + * of how the sparse_vmemmap internals handle compound pages in the lack > + * of an altmap. See vmemmap_populate_compound_pages(). > + */ > +static inline unsigned long compound_nr_pages(struct vmem_altmap *altmap, > + unsigned long nr_pages) > +{ > + return !altmap ? 2 * (PAGE_SIZE/sizeof(struct page)) : nr_pages; > +} > + Should be: return is_power_of_2(sizeof(struct page)) && !altmap ? 2 * (PAGE_SIZE/sizeof(struct page)) : nr_pages; Thanks.