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=-6.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no 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 59F74C388F7 for ; Tue, 3 Nov 2020 09:23:15 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B60C722404 for ; Tue, 3 Nov 2020 09:23:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="JdWuxErS" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B60C722404 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id AEFD36B005C; Tue, 3 Nov 2020 04:23:13 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AA22D6B005D; Tue, 3 Nov 2020 04:23:13 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 91B496B0068; Tue, 3 Nov 2020 04:23:13 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0050.hostedemail.com [216.40.44.50]) by kanga.kvack.org (Postfix) with ESMTP id 5BDB96B005C for ; Tue, 3 Nov 2020 04:23:13 -0500 (EST) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id C4E79181AC9CC for ; Tue, 3 Nov 2020 09:23:12 +0000 (UTC) X-FDA: 77442568224.19.crowd20_571188f272b7 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin19.hostedemail.com (Postfix) with ESMTP id 8715E1AD1B5 for ; Tue, 3 Nov 2020 09:23:12 +0000 (UTC) X-HE-Tag: crowd20_571188f272b7 X-Filterd-Recvd-Size: 6702 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf36.hostedemail.com (Postfix) with ESMTP for ; Tue, 3 Nov 2020 09:23:11 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1604395391; 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: in-reply-to:in-reply-to:references:references; bh=ZirvJkFfS5KQWBeS+X1b4eLDAWA7Tfi5Tdja1+LJ1c4=; b=JdWuxErStXUT8gLHd/RYGe/UBTRaPIXthJXEuFtepLvLSQ1VotX1EG/2Owx3j8Y24w5/t/ mIduwBLlsf5JbdLIDvrBPVYncvRWBg+VOvNKLklGO62yrCnm2GdY5OnINFD29N+q8W+f5r q9u0w4UH1TKMoxQPoDRB0OzTBbOb2ow= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id DC1D8AC97; Tue, 3 Nov 2020 09:23:10 +0000 (UTC) Date: Tue, 3 Nov 2020 10:23:09 +0100 From: Michal Hocko To: David Hildenbrand Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Rashmica Gupta , Andrew Morton , Mike Rapoport , Oscar Salvador , Wei Yang Subject: Re: [PATCH v1 4/4] powernv/memtrace: don't abuse memory hot(un)plug infrastructure for memory allocations Message-ID: <20201103092309.GD21990@dhcp22.suse.cz> References: <20201029162718.29910-1-david@redhat.com> <20201029162718.29910-5-david@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201029162718.29910-5-david@redhat.com> 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 29-10-20 17:27:18, David Hildenbrand wrote: > Let's use alloc_contig_pages() for allocating memory and remove the > linear mapping manually via arch_remove_linear_mapping(). Mark all pages > PG_offline, such that they will definitely not get touched - e.g., > when hibernating. When freeing memory, try to revert what we did. > > The original idea was discussed in: > https://lkml.kernel.org/r/48340e96-7e6b-736f-9e23-d3111b915b6e@redhat.com > > This is similar to CONFIG_DEBUG_PAGEALLOC handling on other > architectures, whereby only single pages are unmapped from the linear > mapping. Let's mimic what memory hot(un)plug would do with the linear > mapping. > > We now need MEMORY_HOTPLUG and CONTIG_ALLOC as dependencies. > > Simple test under QEMU TCG (10GB RAM, single NUMA node): > > sh-5.0# mount -t debugfs none /sys/kernel/debug/ > sh-5.0# cat /sys/devices/system/memory/block_size_bytes > 40000000 > sh-5.0# echo 0x40000000 > /sys/kernel/debug/powerpc/memtrace/enable > [ 71.052836][ T356] memtrace: Allocated trace memory on node 0 at 0x0000000080000000 > sh-5.0# echo 0x80000000 > /sys/kernel/debug/powerpc/memtrace/enable > [ 75.424302][ T356] radix-mmu: Mapped 0x0000000080000000-0x00000000c0000000 with 64.0 KiB pages > [ 75.430549][ T356] memtrace: Freed trace memory back on node 0 > [ 75.604520][ T356] memtrace: Allocated trace memory on node 0 at 0x0000000080000000 > sh-5.0# echo 0x100000000 > /sys/kernel/debug/powerpc/memtrace/enable > [ 80.418835][ T356] radix-mmu: Mapped 0x0000000080000000-0x0000000100000000 with 64.0 KiB pages > [ 80.430493][ T356] memtrace: Freed trace memory back on node 0 > [ 80.433882][ T356] memtrace: Failed to allocate trace memory on node 0 > sh-5.0# echo 0x40000000 > /sys/kernel/debug/powerpc/memtrace/enable > [ 91.920158][ T356] memtrace: Allocated trace memory on node 0 at 0x0000000080000000 > > Note 1: We currently won't be allocating from ZONE_MOVABLE - because our > pages are not movable. However, as we don't run with any memory > hot(un)plug mechanism around, we could make an exception to > increase the chance of allocations succeeding. > > Note 2: PG_reserved isn't sufficient. E.g., kernel_page_present() used > along PG_reserved in hibernation code will always return "true" > on powerpc, resulting in the pages getting touched. It's too > generic - e.g., indicates boot allocations. > > Note 3: For now, we keep using memory_block_size_bytes() as minimum > granularity. I'm not able to come up with a better guess (most > probably, doing it on a section basis could be possible). > > Suggested-by: Michal Hocko > Cc: Michael Ellerman > Cc: Benjamin Herrenschmidt > Cc: Paul Mackerras > Cc: Rashmica Gupta > Cc: Andrew Morton > Cc: Mike Rapoport > Cc: Michal Hocko > Cc: Oscar Salvador > Cc: Wei Yang > Signed-off-by: David Hildenbrand Thanks! This looks like a move into the right direction. I cannot really judge implementation details because I am not familiar with the code. I have only one tiny concern: [...] > -/* called with device_hotplug_lock held */ > -static bool memtrace_offline_pages(u32 nid, u64 start_pfn, u64 nr_pages) > +static u64 memtrace_alloc_node(u32 nid, u64 size) > { > - const unsigned long start = PFN_PHYS(start_pfn); > - const unsigned long size = PFN_PHYS(nr_pages); > + const unsigned long nr_pages = PHYS_PFN(size); > + unsigned long pfn, start_pfn; > + struct page *page; > > - if (walk_memory_blocks(start, size, NULL, check_memblock_online)) > - return false; > - > - walk_memory_blocks(start, size, (void *)MEM_GOING_OFFLINE, > - change_memblock_state); > - > - if (offline_pages(start_pfn, nr_pages)) { > - walk_memory_blocks(start, size, (void *)MEM_ONLINE, > - change_memblock_state); > - return false; > - } > + /* > + * Trace memory needs to be aligned to the size, which is guaranteed > + * by alloc_contig_pages(). > + */ > + page = alloc_contig_pages(nr_pages, __GFP_THISNODE | __GFP_NOWARN, > + nid, NULL); __GFP_THISNODE without other modifiers looks suspicious. I suspect you want to enfore node locality and exclude movable zones by this. While this works it is an antipattern. I would rather use GFP_KERNEL | __GFP_THISNODE | __GFP_NOWARN to be more in line with other gfp usage. If for no other reasons we want to be able to work inside a normal compaction context (comparing to effectively GFP_NOIO which the above implies). Also this looks like a sleepable context. -- Michal Hocko SUSE Labs