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 806DEC61DA4 for ; Tue, 14 Feb 2023 09:17:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E2DA36B0073; Tue, 14 Feb 2023 04:17:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DDD1D6B0074; Tue, 14 Feb 2023 04:17:12 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C7E6F6B0075; Tue, 14 Feb 2023 04:17:12 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id B417E6B0073 for ; Tue, 14 Feb 2023 04:17:12 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 68EFB1A0E16 for ; Tue, 14 Feb 2023 09:17:12 +0000 (UTC) X-FDA: 80465343504.06.B589017 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf23.hostedemail.com (Postfix) with ESMTP id 3991B14000F for ; Tue, 14 Feb 2023 09:17:10 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=F5t8KeR7; spf=pass (imf23.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) 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=1676366230; 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=stZkDlYkb1TUePaSeudFaELIWH0qbeUMQe5FKThxbNY=; b=pQH9GLE7MKo/XO3/WuSGE46gML92zct2XYFVtj4jm7IlzL4fue29KSIyw6qSqiku9O2DqY M7oL0yEbb4B+wJYKlpuyjwcgNDlIZKTJoUEt8uLyRTzNrkzwVCDtEInPfwk1WX/bn6HDVe VSKH8ZDVQNGuGXJOHKIPFzMO4a7mfpE= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=F5t8KeR7; spf=pass (imf23.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676366230; a=rsa-sha256; cv=none; b=ICkD7RdcP8Ea910NRYcKHVjuUsrflFv649/4pSJ3xYfbfgM7/P+Ko0a/+qkVO+SXSVeoDL 5KXIca8Ug7FsxhHiiG+yajomIdK4HoWaCPfnbjkW/rh/k8KO8BEBTuBGmey/uQucxBViLz YTr99s86S/Dj4F/miD1ton02ayrHbNs= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1676366229; 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=stZkDlYkb1TUePaSeudFaELIWH0qbeUMQe5FKThxbNY=; b=F5t8KeR7ZipZ7ldODs3Go3x2Z0smldb1hQNdE13RFrHNh82bp7LH7nqCHQBgKTdv9QzfYr 2qjbFV0gDT6f+HorInrHKDU5KH9o/ymupiwzomY0/aLaifXfUNdHCF7tDkbaycvBdugSSY 1vARDCelIKqSA8TQPwWQL7oE7RBe3+E= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-49-UPNZgMEoO1eKIxBkyQtDGg-1; Tue, 14 Feb 2023 04:17:06 -0500 X-MC-Unique: UPNZgMEoO1eKIxBkyQtDGg-1 Received: by mail-wm1-f71.google.com with SMTP id bd21-20020a05600c1f1500b003dc5cb10dcfso7486477wmb.9 for ; Tue, 14 Feb 2023 01:17:06 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=stZkDlYkb1TUePaSeudFaELIWH0qbeUMQe5FKThxbNY=; b=TbWE7hw/VgWH2iNzZ8xEuz+elVS9wS1DFvg5xWN+e2uHo9q4CGX3t3qRC6uMS/8mTQ kz7u4UJpB7/ai/IIDyqDkkDwEd9fZdf0y0QGI/gQZ2Eat6mTxDYA86DkjHnKO45pR3x1 vZEzD2XWa4YfmnF1rTRx3pIRBCkCqDq+lqzzLCPnMs6Xat/wMPDrCdqxNrV7RqCsjtoQ Oc7F5Ln8xBlTd1ohab7ODcutTT3ETrwY5VgucIUiW0tWhxJeiNhKZAaCPwPTA0MHUFuh y8/rKsmz3QvHRGGiAjE9y8WLVltTQvBwbp0VAVFAwOOc//SglyorqrubqasocDE4Dx4Y Bdfg== X-Gm-Message-State: AO0yUKVdlGSIzE8suxnYg72JcNJt06Pv4MSQkSYRX36rU+CJgy0paAZA 7pdg907BVh5+W4yUmIKbPJgc4E18j182N6jSbIb+Swiw9ezOaAmjO6iHNEMzGn3M49BcNMwzz+c XC22VLYh+Dxo= X-Received: by 2002:a05:600c:91d:b0:3df:eda1:43b9 with SMTP id m29-20020a05600c091d00b003dfeda143b9mr1458559wmp.4.1676366225242; Tue, 14 Feb 2023 01:17:05 -0800 (PST) X-Google-Smtp-Source: AK7set+ycz0IC1I6k2bpLGRNvKfsXo87T6s/E3RwQk+9PHOkoLPxL7ChlRJwHipS/3WqDbPqyW6kGA== X-Received: by 2002:a05:600c:91d:b0:3df:eda1:43b9 with SMTP id m29-20020a05600c091d00b003dfeda143b9mr1458539wmp.4.1676366224946; Tue, 14 Feb 2023 01:17:04 -0800 (PST) Received: from [192.168.3.108] (p5b0c60e7.dip0.t-ipconnect.de. [91.12.96.231]) by smtp.gmail.com with ESMTPSA id f21-20020a05600c43d500b003dc522dd25esm15958603wmn.30.2023.02.14.01.17.03 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 14 Feb 2023 01:17:04 -0800 (PST) Message-ID: Date: Tue, 14 Feb 2023 10:17:03 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.0 Subject: Re: [PATCH] mm: page_alloc: don't allocate page from memoryless nodes To: Vlastimil Babka , Qi Zheng , akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Teng Hu , Mike Rapoport , Matthew Wilcox , Mel Gorman , Oscar Salvador , Muchun Song References: <20230212110305.93670-1-zhengqi.arch@bytedance.com> <2484666e-e78e-549d-e075-b2c39d460d71@suse.cz> <85af4ada-96c8-1f99-90fa-9b6d63d0016e@bytedance.com> From: David Hildenbrand Organization: Red Hat In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 3991B14000F X-Stat-Signature: 948dtztyh9464ndeuhh575fcnja35jez X-HE-Tag: 1676366230-76675 X-HE-Meta: U2FsdGVkX19IvcIV98hgXB82Vl0Wxf6jgSdSVve1Cy94n92QrsbneCJhgEoaUz6qGP6Xj3qcd2mvRxnob8k877olI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fLcyQvMcCGf0VFQEbkGd37eKLuoLDTtjIQb3F7SjSOIygZx2YQ7nwBj1NXhQRG1SdTAVGLAReNB6CFZ7LhMxNtpMnJKPBaSd0CvCzHwoCMZmQ/BgtMtRao80iy2IXxDVdONRBiaOp/Xp5xgQLZUacBtNY32JktbHoHL/JdXZOEQwfK312pYhTrtEjsc9T2Ex2VNKW4+voXFuptTScLpoS9a9uh/o56oQTtYOjyfoBrBemG2m+crCh3K/estzwHed8EMKGN7yVggkQ8xMz36vrLlzYEcDdgc3Uv3rz1+1bMsFjzUYjbH1g5gMykT8xXk4K58Z5ZjuBt7VJLkNChCDII6UaA64pJ3cYSnv57nIu2OB4YM= 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 14.02.23 09:42, Vlastimil Babka wrote: > On 2/13/23 12:00, Qi Zheng wrote: >> >> >> On 2023/2/13 16:47, Vlastimil Babka wrote: >>> On 2/12/23 12:03, Qi Zheng wrote: >>>> In x86, numa_register_memblks() is only interested in >>>> those nodes which have enough memory, so it skips over >>>> all nodes with memory below NODE_MIN_SIZE (treated as >>>> a memoryless node). Later on, we will initialize these >>>> memoryless nodes (allocate pgdat in free_area_init() >>>> and build zonelist etc), and will online these nodes >>>> in init_cpu_to_node() and init_gi_nodes(). >>>> >>>> After boot, these memoryless nodes are in N_ONLINE >>>> state but not in N_MEMORY state. But we can still allocate >>>> pages from these memoryless nodes. >>>> >>>> In SLUB, we only process nodes in the N_MEMORY state, >>>> such as allocating their struct kmem_cache_node. So if >>>> we allocate a page from the memoryless node above to >>>> SLUB, the struct kmem_cache_node of the node corresponding >>>> to this page is NULL, which will cause panic. >>>> >>>> For example, if we use qemu to start a two numa node kernel, >>>> one of the nodes has 2M memory (less than NODE_MIN_SIZE), >>>> and the other node has 2G, then we will encounter the >>>> following panic: >>>> >>>> [ 0.149844] BUG: kernel NULL pointer dereference, address: 0000000000000000 >>>> [ 0.150783] #PF: supervisor write access in kernel mode >>>> [ 0.151488] #PF: error_code(0x0002) - not-present page >>>> <...> >>>> [ 0.156056] RIP: 0010:_raw_spin_lock_irqsave+0x22/0x40 >>>> <...> >>>> [ 0.169781] Call Trace: >>>> [ 0.170159] >>>> [ 0.170448] deactivate_slab+0x187/0x3c0 >>>> [ 0.171031] ? bootstrap+0x1b/0x10e >>>> [ 0.171559] ? preempt_count_sub+0x9/0xa0 >>>> [ 0.172145] ? kmem_cache_alloc+0x12c/0x440 >>>> [ 0.172735] ? bootstrap+0x1b/0x10e >>>> [ 0.173236] bootstrap+0x6b/0x10e >>>> [ 0.173720] kmem_cache_init+0x10a/0x188 >>>> [ 0.174240] start_kernel+0x415/0x6ac >>>> [ 0.174738] secondary_startup_64_no_verify+0xe0/0xeb >>>> [ 0.175417] >>>> [ 0.175713] Modules linked in: >>>> [ 0.176117] CR2: 0000000000000000 >>>> >>>> In addition, we can also encountered this panic in the actual >>>> production environment. We set up a 2c2g container with two >>>> numa nodes, and then reserved 128M for kdump, and then we >>>> can encountered the above panic in the kdump kernel. >>>> >>>> To fix it, we can filter memoryless nodes when allocating >>>> pages. >>>> >>>> Signed-off-by: Qi Zheng >>>> Reported-by: Teng Hu >>> >>> Well AFAIK the key mechanism to only allocate from "good" nodes is the >>> zonelist, we shouldn't need to start putting extra checks like this. So it >>> seems to me that the code building the zonelists should take the >>> NODE_MIN_SIZE constraint in mind. >> >> Indeed. How about the following patch: > > +Cc also David, forgot earlier. > > Looks good to me, at least. > >> @@ -6382,8 +6378,11 @@ int find_next_best_node(int node, nodemask_t >> *used_node_mask) >> int min_val = INT_MAX; >> int best_node = NUMA_NO_NODE; >> >> - /* Use the local node if we haven't already */ >> - if (!node_isset(node, *used_node_mask)) { >> + /* >> + * Use the local node if we haven't already. But for memoryless >> local >> + * node, we should skip it and fallback to other nodes. >> + */ >> + if (!node_isset(node, *used_node_mask) && node_state(node, >> N_MEMORY)) { >> node_set(node, *used_node_mask); >> return node; >> } >> >> For memoryless node, we skip it and fallback to other nodes when >> build its zonelists. >> >> Say we have node0 and node1, and node0 is memoryless, then: >> >> [ 0.102400] Fallback order for Node 0: 1 >> [ 0.102931] Fallback order for Node 1: 1 >> >> In this way, we will not allocate pages from memoryless node0. >> In offline_pages(), we'll first build_all_zonelists() to then node_states_clear_node()->node_clear_state(node, N_MEMORY); So at least on the offlining path, we wouldn't detect it properly yet I assume, and build a zonelist that contains a now-memory-less node? -- Thanks, David / dhildenb