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 8EB43C433EF for ; Fri, 17 Jun 2022 09:25:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 21C876B0071; Fri, 17 Jun 2022 05:25:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1A5B86B0073; Fri, 17 Jun 2022 05:25:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 01F7A6B0074; Fri, 17 Jun 2022 05:25:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id E605E6B0071 for ; Fri, 17 Jun 2022 05:25:25 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id B6B7B616B5 for ; Fri, 17 Jun 2022 09:25:25 +0000 (UTC) X-FDA: 79587194610.28.ED911A7 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf04.hostedemail.com (Postfix) with ESMTP id 41A334008A for ; Fri, 17 Jun 2022 09:25:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655457924; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tmMZZlGvSvdh2hTmabuYfRqYWpBV+3TCqKNOP8IXD/M=; b=O5kOchTDjYeU4jG4HkEvRyvDEOeS4/mqrdZv2tbvbgnj6Wl9k4gyeviOU1VKuokOBVuOOE yW36I1LDRZf+zCaqPkbbUEFjAIUXi8fnBhNras+HLDslCxgCY3MvnA+gRgkbfEN88UyHGK pniGIWnnDzlMi4IgZNFZ+G9gHFEQQh0= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-644-0yUGeJPYNd-7KH9FB8Qn_w-1; Fri, 17 Jun 2022 05:25:23 -0400 X-MC-Unique: 0yUGeJPYNd-7KH9FB8Qn_w-1 Received: by mail-wm1-f72.google.com with SMTP id i188-20020a1c3bc5000000b0039db971c6d9so1171590wma.7 for ; Fri, 17 Jun 2022 02:25:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent :content-language:to:cc:references:from:organization:subject :in-reply-to:content-transfer-encoding; bh=tmMZZlGvSvdh2hTmabuYfRqYWpBV+3TCqKNOP8IXD/M=; b=MUbWmplGWdopfgXL5aD0a0lDQhT7syUgmQ0H3qEbHrPQ4jhTsLbIIeggXrWDeD+7E9 iUWJAOQmGLdoJbnRpR86OJIZ66L6JP5KlSZDrROAV5WvU7cwNT1gdrMJZDBnHjnZpd5o +PrmU6/XrjplHu1a0Dc43MVbrBjPNuVunwHL68CrECP+GiyPqGCkRayeIK7bBVErAq1o iNaGoC0G7UA4oLOUlzMnzeqWMZNv79ULMLAI7+1uHjtF3djWGoywJQnXZjs+6V6+bTWR 5pTu/wAF8Hz86YeoYJYrYFG48Hi2+mAJAXtgwT2FsVaseIWlr1Lakrrlg5+vUmzf+sI5 gqPQ== X-Gm-Message-State: AJIora9eIwaUySQLf3ahRK1ao/usJKosgvlHYaHsuSoQkqju1CcF9228 bVkbxwTK1ML6Dq/TgltX1yuOw3tXyEhq7ZcNtmBY3F4e15wZfUFtQUOUI995xGDELQM1keLyi4k uCtSxopAM9bQ= X-Received: by 2002:a05:6000:15c1:b0:218:468b:4c01 with SMTP id y1-20020a05600015c100b00218468b4c01mr8374773wry.60.1655457922415; Fri, 17 Jun 2022 02:25:22 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vbRD1a81zVORetLZlsNt+vWdgYgBN064PniTn95nDzzDO8cGAEUW0+QIhIctwr2t3x43pbvw== X-Received: by 2002:a05:6000:15c1:b0:218:468b:4c01 with SMTP id y1-20020a05600015c100b00218468b4c01mr8374735wry.60.1655457922070; Fri, 17 Jun 2022 02:25:22 -0700 (PDT) Received: from ?IPV6:2003:cb:c70a:7e00:bb5b:b526:5b76:5824? (p200300cbc70a7e00bb5bb5265b765824.dip0.t-ipconnect.de. [2003:cb:c70a:7e00:bb5b:b526:5b76:5824]) by smtp.gmail.com with ESMTPSA id i9-20020a05600c354900b003975c7058bfsm4950928wmq.12.2022.06.17.02.25.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 17 Jun 2022 02:25:21 -0700 (PDT) Message-ID: <751b003d-e7c2-dfcc-82b3-e80612cdc104@redhat.com> Date: Fri, 17 Jun 2022 11:25:20 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.0 To: Muchun Song Cc: Oscar Salvador , corbet@lwn.net, akpm@linux-foundation.org, paulmck@kernel.org, mike.kravetz@oracle.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, duanxiongchun@bytedance.com, smuchun@gmail.com References: <20220520025538.21144-1-songmuchun@bytedance.com> <20220520025538.21144-3-songmuchun@bytedance.com> <53024884-0182-df5f-9ca2-00652c64ce36@redhat.com> <24d5ec20-9c9e-93aa-11f4-c4619f51f7d1@redhat.com> <79a1ca29-de8e-6456-460b-a9099340fec4@redhat.com> From: David Hildenbrand Organization: Red Hat Subject: Re: [PATCH v2 2/2] mm: memory_hotplug: introduce SECTION_CANNOT_OPTIMIZE_VMEMMAP In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655457925; a=rsa-sha256; cv=none; b=yqUhuRZVmtOjp+h8n2W5vauWPXcHMIOY1JTVkd5LNkgjJOTcbDHo5C4SPpBLv5s7uUalrC 7cIbKAWSvMkt6N1KDhrMeNtNOOF8mYLooFRS7qDpUlo5eNxY3T+VO11RC9NW5w1rQEKL6H 0aGZlSBKYG3QmUQfFOjMSUslkq8AIgg= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=O5kOchTD; spf=none (imf04.hostedemail.com: domain of david@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655457925; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=tmMZZlGvSvdh2hTmabuYfRqYWpBV+3TCqKNOP8IXD/M=; b=P95dlWnn5ClGEMpObEz8d21YDwtxYjZIvWzCabU+mqkCBr1FE1JldWlrau5IeBEr/NwRyg jh0MlYaPyJyeErRoStrBCns5Er9ei9YtQeYmMrjiwBGNAPLenatV0Ur8lqwIba0/h6wMle R3eKW1N9/r9KgGvM2r66KCv/lfB6tLI= X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 41A334008A X-Stat-Signature: 5pyjj3p48f9iia9cgzt76cqoib8tnku1 Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=O5kOchTD; spf=none (imf04.hostedemail.com: domain of david@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspam-User: X-HE-Tag: 1655457925-219352 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 17.06.22 11:10, Muchun Song wrote: > On Fri, Jun 17, 2022 at 09:39:27AM +0200, David Hildenbrand wrote: >> On 17.06.22 09:28, Muchun Song wrote: >>> On Fri, Jun 17, 2022 at 07:46:53AM +0200, Oscar Salvador wrote: >>>> On Thu, Jun 16, 2022 at 09:30:33AM +0200, David Hildenbrand wrote: >>>>> IIRC, that was used to skip these patches on the offlining path before >>>>> we provided the ranges to offline_pages(). >>>> >>>> Yeah, it was designed for that purpose back then. >>>> >>>>> I'd not mess with PG_reserved, and give them a clearer name, to not >>>>> confuse them with other, ordinary, vmemmap pages that are not >>>>> self-hosted (maybe in the future we might want to flag all vmemmap pages >>>>> with a new type?). >>>> >>>> Not sure whether a new type is really needed, or to put it another way, I >>>> cannot see the benefit. >>>> >>>>> >>>>> I'd just try reusing the flag PG_owner_priv_1. And eventually, flag all >>>>> (v)memmap pages with a type PG_memmap. However, the latter would be >>>>> optional and might not be strictly required >>>>> >>>>> >>>>> So what think could make sense is >>>>> >>>>> /* vmemmap pages that are self-hosted and cannot be optimized/freed. */ >>>>> PG_vmemmap_self_hosted = PG_owner_priv_1, >>>> >>>> Sure, I just lightly tested the below, and seems to work, but not sure >>>> whether that is what you are referring to. >>>> @Munchun: thoughts? >>>> >>> >>> I think it works and fits my requirement. >>> >>>> diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h >>>> index e66f7aa3191d..a4556afd7bda 100644 >>>> --- a/include/linux/page-flags.h >>>> +++ b/include/linux/page-flags.h >>>> @@ -193,6 +193,11 @@ enum pageflags { >>>> >>>> /* Only valid for buddy pages. Used to track pages that are reported */ >>>> PG_reported = PG_uptodate, >>>> + >>>> +#ifdef CONFIG_MEMORY_HOTPLUG >>>> + /* For self-hosted memmap pages */ >>>> + PG_vmemmap_self_hosted = PG_owner_priv_1, >>>> +#endif >>>> }; >>>> >>>> #define PAGEFLAGS_MASK ((1UL << NR_PAGEFLAGS) - 1) >>>> @@ -628,6 +633,10 @@ PAGEFLAG_FALSE(SkipKASanPoison, skip_kasan_poison) >>>> */ >>>> __PAGEFLAG(Reported, reported, PF_NO_COMPOUND) >>>> >>>> +#ifdef CONFIG_MEMORY_HOTPLUG >>>> +PAGEFLAG(Vmemmap_self_hosted, vmemmap_self_hosted, PF_ANY) >>>> +#endif >>>> + >>>> /* >>>> * On an anonymous page mapped into a user virtual memory area, >>>> * page->mapping points to its anon_vma, not to a struct address_space; >>>> diff --git a/mm/hugetlb_vmemmap.c b/mm/hugetlb_vmemmap.c >>>> index 1089ea8a9c98..e2de7ed27e9e 100644 >>>> --- a/mm/hugetlb_vmemmap.c >>>> +++ b/mm/hugetlb_vmemmap.c >>>> @@ -101,6 +101,14 @@ void hugetlb_vmemmap_free(struct hstate *h, struct page *head) >>>> { >>>> unsigned long vmemmap_addr = (unsigned long)head; >>>> unsigned long vmemmap_end, vmemmap_reuse, vmemmap_pages; >>>> + struct mem_section *ms = __pfn_to_section(page_to_pfn(head)); >>>> + struct page *memmap; >>>> + >>>> + memmap = sparse_decode_mem_map(ms->section_mem_map, >>>> + pfn_to_section_nr(page_to_pfn(head))); >>>> + >>>> + if (PageVmemmap_self_hosted(memmap)) >>>> + return; >>> >>> I think here needs a loop if it is a 1GB page (spans multiple sections). >>> Right? Here is an implementation based on another approach. But I think >>> your implementation is more simpler and efficient. Would you mind me >>> squash your diff into my patch and with your "Co-developed-by"? >> >> Due to hugtlb alignment requirements, and the vmemmap pages being at the >> start of the hotplugged memory region, I think that cannot currently >> happen. Checking the first vmemmap page might be good enough for now, >> and probably for the future. >> > > If the memory block size is 128MB, then a 1GB huge page spans 8 blocks. > Is it possible that some blocks of them are vmemmap-hosted? No, don't think so. If you think about it, a huge/gigantic page can only start in a memmap-on-memory region but never end in on (or overlap one) -- because the reserved memmap part of the memory block always precedes actually usable data. So even with variable-size memory blocks and weird address alignment, checking the first memmap of a huge page for vmemmp-on-memory should be sufficient. Unless I am missing something. -- Thanks, David / dhildenb