Received: by 2002:a05:6358:111d:b0:dc:6189:e246 with SMTP id f29csp3639724rwi; Wed, 2 Nov 2022 01:05:37 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5wFNm5/9fwohiomR7dZ//VD6i4CiIifODoLe3Pa5ZUmxKWRE/pLyBm4g23mZCM1dj1PTkS X-Received: by 2002:a05:6402:90a:b0:458:ca4d:a2f8 with SMTP id g10-20020a056402090a00b00458ca4da2f8mr23308165edz.230.1667376337663; Wed, 02 Nov 2022 01:05:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667376337; cv=none; d=google.com; s=arc-20160816; b=pkTS5VQsXomTZWhH+4JatvyOPQWHL/qdcwYVV5CwhrEPj3huxhNftTMrIGwjN0Z66X 4+j0RkMGOop/vh5n68aK2nEqHFgqxk+pBjHsS3EjApIBn/LrFiEvLyMbj5wWcE0uKIrj Qb7/WRY5gAKQ2gdSBu3vfVURCe76XSNmwVm209KWZtT+AngbylR1OaWtTAE+C4MzSx+W PVZ7uaJ157QsERf5OowVrih3bKLlBSdWQlZ6lXpq4vwVHXV2PkNuOCaO6NtUxbI3j/nr 1Q9rUl/fuMl3oKZTrGuaQEhHrC5MBhvzvnaAXJzADK58m5ZGnhCClvaiO6HGzNcl1aOX fL0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=Cst1b3RBrCokRDWz1s7fqBTo7DXxaSid3C3ZueSC0aU=; b=MQdE1xSdjfPFxwCiqTKba7WuhArkZN2pQ36IWEak/ZhDnD1Bs58pnbpataLy7t9CVR hQ8ahcMByshT0QlrDkM2idVvFwdpj62QFxfsWHE3UBWGctU58jyqfCEXYXQeQBjE2yyG w603q2rpgD6w7ry+FKsxwSpmNiI2sNApHVjVSnn5K2IimQWiE2K/MO4/QWcYTdqdUr4I kxnLj//KkKIQyzLaHzMsINIexdJC+Xnm450/iT2+MfOu8up8jrBCwrPkc/b7ppU7FIew BwAPO9elEStorDCwGBzTJ/sj/5NS3JsKAprUepUitfN1jorGNm2WY8iTbWGeQcgehPnS a0jg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=MCUs88mx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f15-20020a50ee8f000000b0045d4a88c735si12664784edr.220.2022.11.02.01.05.10; Wed, 02 Nov 2022 01:05:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=MCUs88mx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230087AbiKBHjc (ORCPT + 97 others); Wed, 2 Nov 2022 03:39:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229468AbiKBHj1 (ORCPT ); Wed, 2 Nov 2022 03:39:27 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5372424F30 for ; Wed, 2 Nov 2022 00:39:26 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 0D59122990; Wed, 2 Nov 2022 07:39:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1667374765; h=from:from:reply-to: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=Cst1b3RBrCokRDWz1s7fqBTo7DXxaSid3C3ZueSC0aU=; b=MCUs88mxzmOlTAc8mxrTiceCrXQdLwvWBAJV8SwDzupNgOaTNt8sTrGZVSG2GD4oXEagEB hg1Zqx1Z4P8cHuITpVoSz35y1uhJ+eZgpH/P3FWVF0YC4fEvRP/vh48HBM+cVT7wvYF9+a fRFaHO580IffnBfH7CJeVuZ8CPL6Cms= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id E67941376E; Wed, 2 Nov 2022 07:39:24 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id Y/b8NaweYmOUbgAAMHmgww (envelope-from ); Wed, 02 Nov 2022 07:39:24 +0000 Date: Wed, 2 Nov 2022 08:39:24 +0100 From: Michal Hocko To: Zach O'Keefe Cc: Yang Shi , akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] mm: don't warn if the node is offlined Message-ID: References: <20221031183122.470962-1-shy828301@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue 01-11-22 12:13:35, Zach O'Keefe wrote: [...] > This is slightly tangential - but I don't want to send a new mail > about it -- but I wonder if we should be doing __GFP_THISNODE + > explicit node vs having hpage_collapse_find_target_node() set a > nodemask. We could then provide fallback nodes for ties, or if some > node contained > some threshold number of pages. I would simply go with something like this (not even compile tested): diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 4734315f7940..947a5158fe11 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -96,9 +96,6 @@ struct collapse_control { /* Num pages scanned per node */ u32 node_load[MAX_NUMNODES]; - - /* Last target selected in hpage_collapse_find_target_node() */ - int last_target_node; }; /** @@ -734,7 +731,6 @@ static void khugepaged_alloc_sleep(void) struct collapse_control khugepaged_collapse_control = { .is_khugepaged = true, - .last_target_node = NUMA_NO_NODE, }; static bool hpage_collapse_scan_abort(int nid, struct collapse_control *cc) @@ -772,7 +768,7 @@ static inline gfp_t alloc_hugepage_khugepaged_gfpmask(void) } #ifdef CONFIG_NUMA -static int hpage_collapse_find_target_node(struct collapse_control *cc) +static int hpage_collapse_find_target_node(struct collapse_control *cc, nodemask_t *alloc_mask) { int nid, target_node = 0, max_value = 0; @@ -783,28 +779,25 @@ static int hpage_collapse_find_target_node(struct collapse_control *cc) target_node = nid; } + nodes_clear(&alloc_mask); /* do some balance if several nodes have the same hit record */ - if (target_node <= cc->last_target_node) - for (nid = cc->last_target_node + 1; nid < MAX_NUMNODES; - nid++) - if (max_value == cc->node_load[nid]) { - target_node = nid; - break; - } + for_each_online_node(nid) {_ + if (max_value == cc->node_load[nid]) + node_set(nid, &alloc_mask) + } - cc->last_target_node = target_node; return target_node; } #else -static int hpage_collapse_find_target_node(struct collapse_control *cc) +static int hpage_collapse_find_target_node(struct collapse_control *cc, nodemask_t *alloc_mask) { return 0; } #endif -static bool hpage_collapse_alloc_page(struct page **hpage, gfp_t gfp, int node) +static bool hpage_collapse_alloc_page(struct page **hpage, gfp_t gfp, int node, nodemask_t *nmask) { - *hpage = __alloc_pages_node(node, gfp, HPAGE_PMD_ORDER); + *hpage = __alloc_pages(gfp, HPAGE_PMD_ORDER, node, nmask); if (unlikely(!*hpage)) { count_vm_event(THP_COLLAPSE_ALLOC_FAILED); return false; @@ -958,9 +951,18 @@ static int alloc_charge_hpage(struct page **hpage, struct mm_struct *mm, /* Only allocate from the target node */ gfp_t gfp = (cc->is_khugepaged ? alloc_hugepage_khugepaged_gfpmask() : GFP_TRANSHUGE) | __GFP_THISNODE; - int node = hpage_collapse_find_target_node(cc); + NODEMASK_ALLOC(nodemask_t, nmask, GFP_KERNEL); + int node; + int ret; + + if (!nmaks) + return SCAN_ALLOC_HUGE_PAGE_FAIL; + + node = hpage_collapse_find_target_node(cc, nmask); + ret = hpage_collapse_alloc_page(hpage, gfp, node, nmask); + NODEMASK_FREE(nmask); - if (!hpage_collapse_alloc_page(hpage, gfp, node)) + if (!ret) return SCAN_ALLOC_HUGE_PAGE_FAIL; if (unlikely(mem_cgroup_charge(page_folio(*hpage), mm, gfp))) return SCAN_CGROUP_CHARGE_FAIL; @@ -2576,7 +2578,6 @@ int madvise_collapse(struct vm_area_struct *vma, struct vm_area_struct **prev, if (!cc) return -ENOMEM; cc->is_khugepaged = false; - cc->last_target_node = NUMA_NO_NODE; mmgrab(mm); lru_add_drain_all(); -- Michal Hocko SUSE Labs