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=-8.6 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=unavailable 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 80C5FC433E1 for ; Mon, 22 Jun 2020 21:55:25 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2E32F2073E for ; Mon, 22 Jun 2020 21:55:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="sUTCrE3X" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2E32F2073E 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 900A46B0006; Mon, 22 Jun 2020 17:55:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8D5706B0007; Mon, 22 Jun 2020 17:55:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7EAE46B000C; Mon, 22 Jun 2020 17:55:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0137.hostedemail.com [216.40.44.137]) by kanga.kvack.org (Postfix) with ESMTP id 660656B0006 for ; Mon, 22 Jun 2020 17:55:24 -0400 (EDT) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 0C0A9180AD806 for ; Mon, 22 Jun 2020 21:55:24 +0000 (UTC) X-FDA: 76958204568.07.beast22_1908e3026e36 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin07.hostedemail.com (Postfix) with ESMTP id CD7C21803F9AA for ; Mon, 22 Jun 2020 21:55:23 +0000 (UTC) X-HE-Tag: beast22_1908e3026e36 X-Filterd-Recvd-Size: 11422 Received: from mail-ed1-f67.google.com (mail-ed1-f67.google.com [209.85.208.67]) by imf37.hostedemail.com (Postfix) with ESMTP for ; Mon, 22 Jun 2020 21:55:23 +0000 (UTC) Received: by mail-ed1-f67.google.com with SMTP id d15so14824896edm.10 for ; Mon, 22 Jun 2020 14:55:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:reply-to:references:mime-version :content-disposition:in-reply-to:user-agent; bh=nmfIOoEWXQO5UWb+x+hANhrwfKmxtwc9Q6sKQna/1nE=; b=sUTCrE3XZcHOHhseT6Y556ECknuW8UzGRbGvF/PeTsQJv5nHMVp8C+CzbsAthKHDek Xn7AxhjKalej5xjICem+AzkKwcZd+/8PLK1QuEU8qeL8tcG1bpUvcd1ULVs61cE/QNGQ cSUQ/SkN1O4ktrEBtLRCYptPUa3QbLdlQPo7OojCrfDS5i9/O5bd1aFf4z4oPOMYcy5T liveyfCQSAGBOhsx1bnIPv+zMjLUVuJ+RU6IKEQP3J7CEYc4UMVQ+Gy4DSJmxte+8cr2 vZ9+E3wKwFCJWdgYeoOEEMgNszKF6J2nn3nGVtGfOmarhThQNDbs8di/jELfovfT7Ahn Jb6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:reply-to :references:mime-version:content-disposition:in-reply-to:user-agent; bh=nmfIOoEWXQO5UWb+x+hANhrwfKmxtwc9Q6sKQna/1nE=; b=NL68gcpkuNxZu6U30l165I4MuRDCmcMpqstllSYSdcCm8ElnNKHR0JilZomnTcm8wA 4EZYv1LUwr513yFh5rmwttwACXReniqvjQJQgCscpzbeWCJ1Lwzt0Hbn5DWxTp7J8N2s m32ETC3+JbOQ0oNCv7dOHNqvJYpZq4OLVh46Ov7+mEUw2kDYBxyJgR5YMAYC2CIFQe/q BVj+qh0FzkBtuPnuqvYJxHW70pHQXJN9mgayNf6ufRxrnZy0ymz6djKOS5HFxBSdwfOq mSRwut8soFbd67D0yHVwuO4S+SODl7Th3k7tAtighWvelVSEmMLnUhtRFJKnE7hT74xd 2lag== X-Gm-Message-State: AOAM530AhW5fzjlEvfufMSmJRqdWrGTpTLa4Xh/FLlsep9TWsIk5iQbN 6/oI8EGgt1vF7UxeaM1kc0c= X-Google-Smtp-Source: ABdhPJwwzYAjzPJc9JcvFrneSsdHo8tneX8UZylPARKhvEl31XokOrUWK7ELxb31eXR3WO3LqlgNzQ== X-Received: by 2002:a05:6402:228a:: with SMTP id cw10mr18284650edb.147.1592862922100; Mon, 22 Jun 2020 14:55:22 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id s2sm13470122edu.39.2020.06.22.14.55.21 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 22 Jun 2020 14:55:21 -0700 (PDT) Date: Mon, 22 Jun 2020 21:55:20 +0000 From: Wei Yang To: David Hildenbrand Cc: Wei Yang , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Michal Hocko , stable@vger.kernel.org, Andrew Morton , Johannes Weiner , Minchan Kim , Huang Ying , Wei Yang , Mel Gorman Subject: Re: [PATCH v2 1/3] mm/shuffle: don't move pages between zones and don't read garbage memmaps Message-ID: <20200622215520.wa6gjr2hplurwy57@master> Reply-To: Wei Yang References: <20200619125923.22602-1-david@redhat.com> <20200619125923.22602-2-david@redhat.com> <20200622082635.GA93552@L-31X9LVDL-1304.local> <2185539f-b210-5d3f-5da2-a497b354eebb@redhat.com> <20200622092221.GA96699@L-31X9LVDL-1304.local> <34f36733-805e-cc61-38da-2ee578ae096c@redhat.com> <20200622131003.GA98415@L-31X9LVDL-1304.local> <0f4edc1f-1ce2-95b4-5866-5c4888db7c65@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <0f4edc1f-1ce2-95b4-5866-5c4888db7c65@redhat.com> User-Agent: NeoMutt/20170113 (1.7.2) X-Rspamd-Queue-Id: CD7C21803F9AA X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam01 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 Mon, Jun 22, 2020 at 04:06:15PM +0200, David Hildenbrand wrote: >On 22.06.20 15:10, Wei Yang wrote: >> On Mon, Jun 22, 2020 at 11:51:34AM +0200, David Hildenbrand wrote: >>> On 22.06.20 11:22, Wei Yang wrote: >>>> On Mon, Jun 22, 2020 at 10:43:11AM +0200, David Hildenbrand wrote: >>>>> On 22.06.20 10:26, Wei Yang wrote: >>>>>> On Fri, Jun 19, 2020 at 02:59:20PM +0200, David Hildenbrand wrote: >>>>>>> Especially with memory hotplug, we can have offline sections (with a >>>>>>> garbage memmap) and overlapping zones. We have to make sure to only >>>>>>> touch initialized memmaps (online sections managed by the buddy) and that >>>>>>> the zone matches, to not move pages between zones. >>>>>>> >>>>>>> To test if this can actually happen, I added a simple >>>>>>> BUG_ON(page_zone(page_i) != page_zone(page_j)); >>>>>>> right before the swap. When hotplugging a 256M DIMM to a 4G x86-64 VM and >>>>>>> onlining the first memory block "online_movable" and the second memory >>>>>>> block "online_kernel", it will trigger the BUG, as both zones (NORMAL >>>>>>> and MOVABLE) overlap. >>>>>>> >>>>>>> This might result in all kinds of weird situations (e.g., double >>>>>>> allocations, list corruptions, unmovable allocations ending up in the >>>>>>> movable zone). >>>>>>> >>>>>>> Fixes: e900a918b098 ("mm: shuffle initial free memory to improve memory-side-cache utilization") >>>>>>> Acked-by: Michal Hocko >>>>>>> Cc: stable@vger.kernel.org # v5.2+ >>>>>>> Cc: Andrew Morton >>>>>>> Cc: Johannes Weiner >>>>>>> Cc: Michal Hocko >>>>>>> Cc: Minchan Kim >>>>>>> Cc: Huang Ying >>>>>>> Cc: Wei Yang >>>>>>> Cc: Mel Gorman >>>>>>> Signed-off-by: David Hildenbrand >>>>>>> --- >>>>>>> mm/shuffle.c | 18 +++++++++--------- >>>>>>> 1 file changed, 9 insertions(+), 9 deletions(-) >>>>>>> >>>>>>> diff --git a/mm/shuffle.c b/mm/shuffle.c >>>>>>> index 44406d9977c77..dd13ab851b3ee 100644 >>>>>>> --- a/mm/shuffle.c >>>>>>> +++ b/mm/shuffle.c >>>>>>> @@ -58,25 +58,25 @@ module_param_call(shuffle, shuffle_store, shuffle_show, &shuffle_param, 0400); >>>>>>> * For two pages to be swapped in the shuffle, they must be free (on a >>>>>>> * 'free_area' lru), have the same order, and have the same migratetype. >>>>>>> */ >>>>>>> -static struct page * __meminit shuffle_valid_page(unsigned long pfn, int order) >>>>>>> +static struct page * __meminit shuffle_valid_page(struct zone *zone, >>>>>>> + unsigned long pfn, int order) >>>>>>> { >>>>>>> - struct page *page; >>>>>>> + struct page *page = pfn_to_online_page(pfn); >>>>>> >>>>>> Hi, David and Dan, >>>>>> >>>>>> One thing I want to confirm here is we won't have partially online section, >>>>>> right? We can add a sub-section to system, but we won't manage it by buddy. >>>>> >>>>> Hi, >>>>> >>>>> there is still a BUG with sub-section hot-add (devmem), which broke >>>>> pfn_to_online_page() in corner cases (especially, see the description in >>>>> include/linux/mmzone.h). We can have a boot-memory section partially >>>>> populated and marked online. Then, we can hot-add devmem, marking the >>>>> remaining pfns valid - and as the section is maked online, also as online. >>>> >>>> Oh, yes, I see this description. >>>> >>>> This means we could have section marked as online, but with a sub-section even >>>> not added. >>>> >>>> While the good news is even the sub-section is not added, but its memmap is >>>> populated for an early section. So the page returned from pfn_to_online_page() >>>> is a valid one. >>>> >>>> But what would happen, if the sub-section is removed after added? Would >>>> section_deactivate() release related memmap to this "struct page"? >>> >>> If devmem is removed, the memmap will be freed and the sub-sections are >>> marked as non-present. So this works as expected. >>> >> >> Sorry, I may not catch your point. If my understanding is correct, the >> above behavior happens in function section_deactivate(). >> >> Let me draw my understanding of function section_deactivate(): >> >> section_deactivate(pfn, nr_pages) >> clear_subsection_map(pfn, nr_pages) >> depopulate_section_memmap(pfn, nr_pages) >> >> Since we just remove a sub-section, I skipped some un-related codes. These two >> functions would: >> >> * clear bitmap in ms->usage->subsection_map >> * free memmap for the sub-section >> >> While since the section is not empty, ms->section_mem_map is not set no null. > >Let me clarify, sub-section hotremove works differently when overlying >with (online) boot memory within a section. > >Early sections (IOW, boot memory) are never partially removed. See Thanks for your time and patience. Looked into the comment of section_deactivate(): * 1. deactivation of a partial hot-added section (only possible in * the SPARSEMEM_VMEMMAP=y case). * a) section was present at memory init. * b) section was hot-added post memory init. Case a) seems do partial remove for an early section? >mm/sparse.c:section_deactivate(). We only free a early memmap when the >section is completely empty. Also see how Hmm.. I thought this is the behavior for early section, while it looks current code doesn't work like this: if (section_is_early && memmap) free_map_bootmem(memmap); else depopulate_section_memmap(pfn, nr_pages, altmap); section_is_early is always "true" for early section, while memmap is not-NULL only when sub-section map is empty. If my understanding is correct, when we remove a sub-section in early section, the code would call depopulate_section_memmap(), which in turn free related memmap. By removing the memmap, the return value from pfn_to_online_page() is not a valid one. Maybe we want to write the code like this: if (section_is_early) if (memmap) free_map_bootmem(memmap); else depopulate_section_memmap(pfn, nr_pages, altmap); This makes sure we only free memmap for early section only when the whole section is removed. >include/linux/mmzone.h:pfn_valid() handles early sections. > >So when we have a partially present section with boot memory, we >a) marked the whole section present and online (there is only a single > bit) >b) allocated the memmap for the whole section >c) Only exposed the relevant pages to the buddy. The memmap of non- > present parts in a section were initialized and are reserved. > >pfn_valid() will return for all non-present pfns valid, because there is >a memmap. pfn_to_online_page() will return for all pfns "true", because >we only have a single bit for the whole section. This has been the case >before sub-section hotplug and is still the case. It simply looks like >just another memory hole for which we have a memmap. > >Now, with devmem it is possible to suddenly change these sub-section >holes (memmaps) to become ZONE_DEVICE memory. pfn_to_online_page() would >have to detect that and report a "false". Possible fixes were already >discussed (e.g., sub-section online map instead of a single bit). > >Again, the zone check safes us from the worst, just as in the case of >all other pfn walkers that use (as documented) pfn_to_online_page(). It >still needs a fix as dicussed, but it seems to work reasonably fine like >that for now. > >-- >Thanks, > >David / dhildenb -- Wei Yang Help you, Help me