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 24680C4332F for ; Wed, 8 Dec 2021 19:00:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 797436B0071; Wed, 8 Dec 2021 14:00:17 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 747096B0073; Wed, 8 Dec 2021 14:00:17 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 60ECC6B0074; Wed, 8 Dec 2021 14:00:17 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0132.hostedemail.com [216.40.44.132]) by kanga.kvack.org (Postfix) with ESMTP id 511386B0071 for ; Wed, 8 Dec 2021 14:00:17 -0500 (EST) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 172BB18579004 for ; Wed, 8 Dec 2021 19:00:07 +0000 (UTC) X-FDA: 78895542054.11.D2D9D35 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf17.hostedemail.com (Postfix) with ESMTP id 315B8F0001F7 for ; Wed, 8 Dec 2021 19:00:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1638990005; 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=/s5sY1q6PQLBZ20cR9DzmY70ulSv5YBsSaYi6x4GpDY=; b=QjJtTXKC5DmNt0X4XweHxmRuY5fF0wW8ncigiWMEaKI0AtaxntcT1mlfQP0e7Ttssr9Rf7 fP0p/eB+Z5OJGXseySzoFTt9WnsPgm4EGjSH9dLpGRIS97raqzaApDvvMzaqurU9l7pCC0 rTaELph05U5YBklKa+YRu86uIS8zxAQ= Received: from mail-il1-f198.google.com (mail-il1-f198.google.com [209.85.166.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-276-ohTDZN4MO-KgsWz7jUOdSQ-1; Wed, 08 Dec 2021 14:00:04 -0500 X-MC-Unique: ohTDZN4MO-KgsWz7jUOdSQ-1 Received: by mail-il1-f198.google.com with SMTP id m9-20020a056e021c2900b002a1d679b412so4277106ilh.2 for ; Wed, 08 Dec 2021 11:00:04 -0800 (PST) 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:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=/s5sY1q6PQLBZ20cR9DzmY70ulSv5YBsSaYi6x4GpDY=; b=ZL90KsWuC5RPaf7GPfMygjb4ECpFokIUpXT0l19G8WNFyuUGcNFZtPbELKGS/HEWIp Zp6MDXEgGeX7Ft1+KcPU1cdY6IIY6YFkRe3Dpgsxpxni782u4PKE/UNXKIE5QYJ0C7tq fHiDtN3LcpzGRz0G0Sdx9C5Tv26T/vyMfUmgkB9iMv/zUSVUHaslf3qjCH6nOGUQzBRD GKTLMga6Zltiy5tOYYtaGL/ZqqR9SDWaVIQ+4WuO4cHZBDB1aPXrtM6k91cw3SjuSIKH jBm3lOZpGmg3mx4lOnDrOidfmGjmA4FCzWrew86yg7dmUH6pf8HBpieIawsX2M5xXBsM rUTg== X-Gm-Message-State: AOAM532hSFEnEmNXP/JRKWFwnjnkL334XEkmryf46SErwU8DLvf0ycvu crholt3aA79nalk4WIZpjDZ2WIW6MUsi8isH8iux2892ThQXBCGXJFikCsQbxie0i39Z+6B2Af5 h3N/lTzK+g0A= X-Received: by 2002:a05:6e02:1a4e:: with SMTP id u14mr9503486ilv.121.1638990003215; Wed, 08 Dec 2021 11:00:03 -0800 (PST) X-Google-Smtp-Source: ABdhPJwa/4oyrYKSSiV1Tlcx49cqVJY9TfwWzcP/p9FEMpdLD7xA5zXrnnJowGLqiv143OngjfBbCw== X-Received: by 2002:a05:6e02:1a4e:: with SMTP id u14mr9503450ilv.121.1638990002973; Wed, 08 Dec 2021 11:00:02 -0800 (PST) Received: from ?IPV6:2601:280:4400:a2e0:7336:512c:930d:4f0e? ([2601:280:4400:a2e0:7336:512c:930d:4f0e]) by smtp.gmail.com with ESMTPSA id l9sm2215746ilh.82.2021.12.08.11.00.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 08 Dec 2021 11:00:02 -0800 (PST) Message-ID: Date: Wed, 8 Dec 2021 14:00:01 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.2.0 Subject: Re: [RFC PATCH 2/2] mm/vmscan.c: Prevent allocating shrinker_info on offlined nodes To: Michal Hocko , Kirill Tkhai , David Hildenbrand Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, akpm@linux-foundation.org, shakeelb@google.com, shy828301@gmail.com, guro@fb.com, vbabka@suse.cz, vdavydov.dev@gmail.com, raquini@redhat.com References: <20211206033338.743270-1-npache@redhat.com> <20211206033338.743270-3-npache@redhat.com> <24b4455c-aff9-ca9f-e29f-350833e7a0d1@virtuozzo.com> From: Nico Pache 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 X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 315B8F0001F7 X-Stat-Signature: cwdqdmt6jeprsrad8zn5aqpxdd9gy4hf Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=QjJtTXKC; spf=none (imf17.hostedemail.com: domain of npache@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=npache@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-HE-Tag: 1638990005-138239 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 12/6/21 08:24, Michal Hocko wrote: > On Mon 06-12-21 16:19:12, Kirill Tkhai wrote: >> On 06.12.2021 13:45, David Hildenbrand wrote: >>>> This doesn't seen complete. Slab shrinkers are used in the reclaim >>>> context. Previously offline nodes could be onlined later and this would >>>> lead to NULL ptr because there is no hook to allocate new shrinker >>>> infos. This would be also really impractical because this would have to >>>> update all existing memcgs... >>> >>> Instead of going through the trouble of updating... >>> >>> ... maybe just keep for_each_node() and check if the target node is >>> offline. If it's offline, just allocate from the first online node. >>> After all, we're not using __GFP_THISNODE, so there are no guarantees >>> either way ... >> >> Hm, can't we add shrinker maps allocation to __try_online_node() in addition >> to this patch? > > Either that or through hotplug notifier (which would be a better > solution). But allocating a new shrinker map for each memcg would have > to be done as has been mentioned earlier. I took a stab at this approach. It may be incomplete but please let me know what you think. This would go on top of this series. diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 0c5c403f4be6..6c842382fa73 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -520,6 +520,7 @@ static inline struct mem_cgroup *page_memcg_check(struct page *page) return (struct mem_cgroup *)(memcg_data & ~MEMCG_DATA_FLAGS_MASK); } +int alloc_mem_cgroup_per_node_info(struct mem_cgroup *memcg, int node); #ifdef CONFIG_MEMCG_KMEM /* * folio_memcg_kmem - Check if the folio has the memcg_kmem flag set. diff --git a/include/linux/node.h b/include/linux/node.h index bb21fd631b16..5e8c737ea751 100644 --- a/include/linux/node.h +++ b/include/linux/node.h @@ -19,7 +19,7 @@ #include #include #include - +#include /** * struct node_hmem_attrs - heterogeneous memory performance attributes * @@ -118,6 +118,7 @@ extern int __register_one_node(int nid); /* Registers an online node */ static inline int register_one_node(int nid) { + struct mem_cgroup *memcg; int error = 0; if (node_online(nid)) { @@ -130,6 +131,14 @@ static inline int register_one_node(int nid) return error; /* link memory sections under this node */ link_mem_sections(nid, start_pfn, end_pfn, MEMINIT_EARLY); + /* Iterate over memcgs and update nodeinfo */ + memcg = mem_cgroup_iter(NULL, NULL, NULL); + do { + if (alloc_mem_cgroup_per_node_info(memcg,nid)) { + mem_cgroup_iter_break(NULL, memcg); + return error; + } + } while ((memcg = mem_cgroup_iter(NULL, memcg, NULL)) != NULL); } return error; diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 6863a834ed42..2d55fad3229b 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -5041,18 +5041,11 @@ struct mem_cgroup *mem_cgroup_from_id(unsigned short id) return idr_find(&mem_cgroup_idr, id); } -static int alloc_mem_cgroup_per_node_info(struct mem_cgroup *memcg, int node) +int alloc_mem_cgroup_per_node_info(struct mem_cgroup *memcg, int node) { struct mem_cgroup_per_node *pn; int tmp = node; - /* - * This routine is called against possible nodes. - * But it's BUG to call kmalloc() against offline node. - * - * TODO: this routine can waste much memory for nodes which will - * never be onlined. It's better to use memory hotplug callback - * function. - */ + if (!node_state(node, N_NORMAL_MEMORY)) tmp = -1; pn = kzalloc_node(sizeof(*pn), GFP_KERNEL, tmp); @@ -5130,7 +5123,7 @@ static struct mem_cgroup *mem_cgroup_alloc(void) if (!memcg->vmstats_percpu) goto fail; - for_each_node(node) + for_each_online_node(node) if (alloc_mem_cgroup_per_node_info(memcg, node)) goto fail;