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 AE8C1C433EF for ; Wed, 22 Jun 2022 08:45:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4CE318E0099; Wed, 22 Jun 2022 04:45:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 47EEE8E008A; Wed, 22 Jun 2022 04:45:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3466B8E0099; Wed, 22 Jun 2022 04:45:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 167908E008A for ; Wed, 22 Jun 2022 04:45:26 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id C9F94213C9 for ; Wed, 22 Jun 2022 08:45:25 +0000 (UTC) X-FDA: 79605237810.03.19BB60C Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf03.hostedemail.com (Postfix) with ESMTP id 85FC220015 for ; Wed, 22 Jun 2022 08:45:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655887503; 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=yM2ilXtSj5hOwfP2Q9CCS31/P/1OntUXQBpNb3rtn7M=; b=UxuLco+6YbQXUqMOeCZp3UImfkuU14YBVBl1LeDX31ZEdzkNYZO5z6+dyU5r1dpZMgA4kX tji2tlPnu/mNA9Xpi6VxZpFPex52L1zpCh3DMt/Rrn5twcz8MrmjhBB3NT1Sg61a/e+F42 tkiYItOARf5N5Brg1nga/CirL/85Ty8= 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.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-127-PeFE85zONHS7hH50sOYw3g-1; Wed, 22 Jun 2022 04:45:00 -0400 X-MC-Unique: PeFE85zONHS7hH50sOYw3g-1 Received: by mail-wm1-f71.google.com with SMTP id v184-20020a1cacc1000000b0039c7efa3e95so5275226wme.3 for ; Wed, 22 Jun 2022 01:45:00 -0700 (PDT) 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 :content-language:to:cc:references:from:organization:subject :in-reply-to:content-transfer-encoding; bh=yM2ilXtSj5hOwfP2Q9CCS31/P/1OntUXQBpNb3rtn7M=; b=gg43ppnfB38uJRJ6YzDEGRnA2F1CmYe8xh7jAwhSZX/pgp97K2y+7kulmPqNOTfR3+ Zst89us3Yg/HFqbT1bL6DZm/MByxeCBZf/yT9FWj+oEbkJj7zxqUXIsODlKTiotbniet eIQHdLrBr5afM9P15YUdF+fm8aSxuw8RpywmRc6Ou6G/HRMnHMILaPFvF1YL9BtJqJ57 e6p2QzMueMIlvYyDsduyS4vbat4F4KJluWyzcosu5n6SK9VUqSLq7aJBjMopFbP2IVCx vZDfBIyAUh6COFV5TGmQK9Wbs42HsW2PA7rSmCms3xBjADQCZzJlkM2dPYrTdzWvsKxj EWOw== X-Gm-Message-State: AJIora8ibxL+/7AZQHUu2GmuU5khsbNvr1l3qTL5jxft08K9GhwKsfZe G5hMTe6xu16mFmh3sY2C+ZWmoBXDGRWJ98gwvVTT7nWD2K3qQXWEDARG3kX6NNE7zJkNoPZGBEF ozamSVMO5CyA= X-Received: by 2002:a05:600c:a4c:b0:39c:34d0:fd25 with SMTP id c12-20020a05600c0a4c00b0039c34d0fd25mr2645104wmq.172.1655887499345; Wed, 22 Jun 2022 01:44:59 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tqm7fcwKotWffGWNRwGJlX7MqnLDontN9cjXI+cyLOnldlC1tmwlxVGQvXplktCYZVjJwYsw== X-Received: by 2002:a05:600c:a4c:b0:39c:34d0:fd25 with SMTP id c12-20020a05600c0a4c00b0039c34d0fd25mr2645078wmq.172.1655887498965; Wed, 22 Jun 2022 01:44:58 -0700 (PDT) Received: from ?IPV6:2003:cb:c703:5100:9c77:ce13:2aeb:8748? (p200300cbc70351009c77ce132aeb8748.dip0.t-ipconnect.de. [2003:cb:c703:5100:9c77:ce13:2aeb:8748]) by smtp.gmail.com with ESMTPSA id a14-20020a056000100e00b0021b862ad439sm1299360wrx.9.2022.06.22.01.44.58 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 22 Jun 2022 01:44:58 -0700 (PDT) Message-ID: <4dccc61d-d8fa-c2b2-d744-398b48ea8a89@redhat.com> Date: Wed, 22 Jun 2022 10:44:57 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.0 To: Oscar Salvador Cc: Andrew Morton , Michal Hocko , linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20220621041717.6355-1-osalvador@suse.de> <20220621041717.6355-3-osalvador@suse.de> <139fc140-142f-c467-a5e3-0a0954dca127@redhat.com> From: David Hildenbrand Organization: Red Hat Subject: Re: [PATCH v2 2/2] mm/memory_hotplug: Reset node's state when empty during offline 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 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655887521; 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=yM2ilXtSj5hOwfP2Q9CCS31/P/1OntUXQBpNb3rtn7M=; b=N3b2eTADXT3ZPiofMijiYmbUf9qMf1w4u19yWEghbPqnW6Ab4iPChSrZdvsvdx4/oCx2mv S3oh3Yvc7WHKEZUVVpYsVd6iQjyOnY5wsq9ssNdm2iXRZy8hx4KVxxEfHY63w9g6HWpGpq JYrDJ3WbgDXbohavEq28VoZg8zqu8QI= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=UxuLco+6; spf=none (imf03.hostedemail.com: domain of david@redhat.com has no SPF policy when checking 170.10.129.124) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655887521; a=rsa-sha256; cv=none; b=rVr/Gp+vlmKnzgekt6iXXCmrMs2iUq4bLIt0nLF51LaIV70j1G53UPzD0ZfxG8mUR1fKc2 Fm9O5hkCQHzej9iZjETP6x85Mby5DvomCZYiC2/u6bhTjQjGaowmY95VwFlWaJz0tmvm+i 92u133ilx0JHYQCtrb5iiQCXmQkC7CQ= X-Rspamd-Queue-Id: 85FC220015 Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=UxuLco+6; spf=none (imf03.hostedemail.com: domain of david@redhat.com has no SPF policy when checking 170.10.129.124) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspam-User: X-Stat-Signature: hk76sn89t7ggt5nhbxyqoctypgqnkwwz X-Rspamd-Server: rspam04 X-HE-Tag: 1655887520-265127 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 22.06.22 06:25, Oscar Salvador wrote: > On Tue, Jun 21, 2022 at 09:59:07AM +0200, David Hildenbrand wrote: >>> +static void node_reset_state(int node) >>> +{ >>> + pg_data_t *pgdat = NODE_DATA(node); >>> + int cpu; >>> + >>> + kswapd_stop(node); >>> + kcompactd_stop(node); >>> + >>> + pgdat->nr_zones = 0; >> >> ^ what is that? it should be "highest_zone_idx" and I don't see any >> reason that we really need this. > > Uhm, I thought we need to reset this, otherwise init_currently_empty_zone() > might not set it to a right value: > > ... > if (zone_idx > pgdat->nr_zones) > pgdat->nr_zones = zone_idx > ... > > At least we set it to 0 in free_area_init_core_hotplug() (before this patch). Yeah, I don't think we need to, the nodes+zones should be empty either way. Maybe a micro-optimization that doesn't really optimize anything that much? free_area_init_node() warns if it isn't reset, but my gut feeling is this is completely unnecessary. We're not dealing with 200 zones ... > >> To detect if a node is empty we can use pgdat_is_empty(). To detect if a >> zone is empty we can use zone_is_empty(). >> >> The usage of "pgdat->nr_zones" as an optimization is questionable, >> especially when iterating over our handful of zones where most nodes >> miss the *lower* zones like ZONE_DMA* in practice and have ZONE_NORMAL. >> >> Can we get rid of that and just check pgdat_is_empty() and >> zone_is_empty() and iterate all applicable zones from 0..X? > > So, lemme see if I get you. > You mean to e.g: replace the following (code snippet from set_pgdat_percpu_threshold) > > for (i = 0; i < pgdat->nr_zones; i++) { > zone = &pgdat->node_zones[i]; > > [some code] > } > > with this: > > for (zid = 0; zid < MAX_NR_ZONES; i++) { > struct zone *zone = pgdat->node_zones + i; > > if (zone_is_empty(zone)) > continue; > } Yes, some places that are not interested in ZONE_DEVICE might want to skip that completely. See below. > > I guess we can, and I can see that we have a mix of both usages, so it might be > good to consolidate one. > And actually, I think we do the same amount of work, right? So not really an > optimization in those pieces of code. That's my understanding. > > The only thing that unsettles me is the compaction part. > We set pgdat->kcompactd_highest_zoneidx by checking pgdat->nr_zones, and use > that as our compact_control->highest_zoneidx. (kcompactd->kcompactd_do_work) I wonder why we would want to use ZONE_DEVICE there ... move_pfn_range_to_zone()->init_currently_empty_zone() would set pgdat->nr_zones = ZONE_DEVICE. Which looks unnecessary. > > Now, I do not really see any reason we could not adapt that code to not > realy on pgdat->nr_zones, but I would have to check further how this > interacts with highest_zoneidx down the road, and where else should > we rewrite code. I wonder if all we want is: diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index aab70355d64f..905919683025 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -497,8 +497,9 @@ enum zone_type { * there can be false negatives). */ ZONE_MOVABLE, + __MAX_NR_BUDDY_ZONES, #ifdef CONFIG_ZONE_DEVICE - ZONE_DEVICE, + ZONE_DEVICE = __MAX_NR_BUDDY_ZONES, #endif __MAX_NR_ZONES diff --git a/tools/testing/memblock/linux/mmzone.h b/tools/testing/memblock/linux/mmzone.h index 7c2eb5c9bb54..2c3492239e45 100644 --- a/tools/testing/memblock/linux/mmzone.h +++ b/tools/testing/memblock/linux/mmzone.h @@ -17,6 +17,7 @@ enum zone_type { }; #define MAX_NR_ZONES __MAX_NR_ZONES +#define MAX_NR_BUDDY_ZONES __MAX_NR_BUDDY_ZONES #define MAX_ORDER 11 #define MAX_ORDER_NR_PAGES (1 << (MAX_ORDER - 1)) Then, all relevant buddy-related code (compaction ...) can simply run for (i = 0; i < MAX_NR_BUDDY_ZONES; i++) or for (i = MAX_NR_BUDDY_ZONES - 1; i >= 0; i--) and check if the relevant zone is empty. There will still be users of MAX_NR_ZONES, though, that have to consider ZONE_DEVICE as well. -- Thanks, David / dhildenb