From patchwork Thu Oct 27 06:59:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 13021696 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 4E2A4C67871 for ; Thu, 27 Oct 2022 06:59:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A85878E0002; Thu, 27 Oct 2022 02:59:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A0E878E0001; Thu, 27 Oct 2022 02:59:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8AF4F8E0002; Thu, 27 Oct 2022 02:59:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 78AC38E0001 for ; Thu, 27 Oct 2022 02:59:42 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 14653A028E for ; Thu, 27 Oct 2022 06:59:42 +0000 (UTC) X-FDA: 80065829004.03.89C7DE9 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by imf14.hostedemail.com (Postfix) with ESMTP id 98B4D100035 for ; Thu, 27 Oct 2022 06:59:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1666853980; x=1698389980; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=V14uG5yjLb6jlXg9bU1RN+1W4f8+KLhPzp7C9u7WGug=; b=WJSPINb2jE75FhasQPI+Jj8BjAXLIIKUPlwsTL8YxH9UBiBUBRp+b3K4 pgP/UbtGwi0clDzCVWW/LZL1NBL9xyqGxJCE76cV1eA2Q8Vh3Pm6n7yF0 92/BFQDQX/Yvndeh5KwNwduawtudeRk/aVeNmYrX1N/WAvGRGMzTIzuM9 zsaMoShXRLRbZHCbz69VSByh5t7gYKegZYWivY9Tw5Yhn0C8qYo8NG90C A/2TJfoVIEzd1ffLJ+r7Q6gT8edQl0e7adS2KMPJudOUWQ1FtFMCwPHPO fFdNJIyqzAJU3k2DjVD/KA6CCluxIzXT08UiZXbGjXXulADZw+w1vVMLR A==; X-IronPort-AV: E=McAfee;i="6500,9779,10512"; a="306876211" X-IronPort-AV: E=Sophos;i="5.95,217,1661842800"; d="scan'208";a="306876211" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Oct 2022 23:59:39 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10512"; a="774884708" X-IronPort-AV: E=Sophos;i="5.95,217,1661842800"; d="scan'208";a="774884708" Received: from yunfeima-mobl.ccr.corp.intel.com (HELO yhuang6-mobl2.ccr.corp.intel.com) ([10.254.212.241]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Oct 2022 23:59:35 -0700 From: Huang Ying To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, Andrew Morton , Huang Ying , "Aneesh Kumar K . V" , Alistair Popple , Bharata B Rao , Dan Williams , Dave Hansen , Davidlohr Bueso , Hesham Almatary , Jagdish Gediya , Johannes Weiner , Jonathan Cameron , Michal Hocko , Tim Chen , Wei Xu , Yang Shi Subject: [RFC] memory tiering: use small chunk size and more tiers Date: Thu, 27 Oct 2022 14:59:25 +0800 Message-Id: <20221027065925.476955-1-ying.huang@intel.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666853980; a=rsa-sha256; cv=none; b=D4E7I64djmEwHKf15HudvxUIVSM5b+nDNwiAfvn4K0ziBaJ4Q2oj5pP5wx0snrg3qnoNr0 MPFQlr2Vqy0vj2hkKPxssEgYx/qP5Z8idZrA6O7CVv6KJocRRUq+J7E3yjs8ipXrUoUtfV UdHeSGT42so4R8K34s5WXh4sWM+RUqM= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b=WJSPINb2; spf=pass (imf14.hostedemail.com: domain of ying.huang@intel.com designates 192.55.52.120 as permitted sender) smtp.mailfrom=ying.huang@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1666853980; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=tjQK/66cZjnK/a0qHUKzpizplVokBuVmEgVSyN+o1YQ=; b=FAg8W/l6yAnXVDy9+qy70GQFJIsSE+oFe4UhHpEBu90ksb/LvwCUWRzGAO0dTRJHMZuqSF aEWWJZDTxH7yeGT3UdmwNC7IXwc6DKaTr9P6fA+0diCeekdpqfJmXfasv/e8i7VSvYo1Gu gmu7Z8KOHPqhd4B91y389AN3a37W3Hw= X-Rspamd-Queue-Id: 98B4D100035 X-Rspam-User: Authentication-Results: imf14.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b=WJSPINb2; spf=pass (imf14.hostedemail.com: domain of ying.huang@intel.com designates 192.55.52.120 as permitted sender) smtp.mailfrom=ying.huang@intel.com; dmarc=pass (policy=none) header.from=intel.com X-Rspamd-Server: rspam04 X-Stat-Signature: 4z39odmb54ywbz5uetfhpridbejn8ofd X-HE-Tag: 1666853980-603072 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: We need some way to override the system default memory tiers. For the example system as follows, type abstract distance ---- ----------------- HBM 300 DRAM 1000 CXL_MEM 5000 PMEM 5100 Given the memory tier chunk size is 100, the default memory tiers could be, tier abstract distance types range ---- ----------------- ----- 3 300-400 HBM 10 1000-1100 DRAM 50 5000-5100 CXL_MEM 51 5100-5200 PMEM If we want to group CXL MEM and PMEM into one tier, we have 2 choices. 1) Override the abstract distance of CXL_MEM or PMEM. For example, if we change the abstract distance of PMEM to 5050, the memory tiers become, tier abstract distance types range ---- ----------------- ----- 3 300-400 HBM 10 1000-1100 DRAM 50 5000-5100 CXL_MEM, PMEM 2) Override the memory tier chunk size. For example, if we change the memory tier chunk size to 200, the memory tiers become, tier abstract distance types range ---- ----------------- ----- 1 200-400 HBM 5 1000-1200 DRAM 25 5000-5200 CXL_MEM, PMEM But after some thoughts, I think choice 2) may be not good. The problem is that even if 2 abstract distances are almost same, they may be put in 2 tier if they sit in the different sides of the tier boundary. For example, if the abstract distance of CXL_MEM is 4990, while the abstract distance of PMEM is 5010. Although the difference of the abstract distances is only 20, CXL_MEM and PMEM will put in different tiers if the tier chunk size is 50, 100, 200, 250, 500, .... This makes choice 2) hard to be used, it may become tricky to find out the appropriate tier chunk size that satisfying all requirements. So I suggest to abandon choice 2) and use choice 1) only. This makes the overall design and user space interface to be simpler and easier to be used. The overall design of the abstract distance could be, 1. Use decimal for abstract distance and its chunk size. This makes them more user friendly. 2. Make the tier chunk size as small as possible. For example, 10. This will put different memory types in one memory tier only if their performance is almost same by default. And we will not provide the interface to override the chunk size. 3. Make the abstract distance of normal DRAM large enough. For example, 1000, then 100 tiers can be defined below DRAM, this is more than enough in practice. 4. If we want to override the default memory tiers, just override the abstract distances of some memory types with a per memory type interface. This patch is to apply the design choices above in the existing code. Signed-off-by: "Huang, Ying" Cc: Aneesh Kumar K.V Cc: Alistair Popple Cc: Bharata B Rao Cc: Dan Williams Cc: Dave Hansen Cc: Davidlohr Bueso Cc: Hesham Almatary Cc: Jagdish Gediya Cc: Johannes Weiner Cc: Jonathan Cameron Cc: Michal Hocko Cc: Tim Chen Cc: Wei Xu Cc: Yang Shi --- include/linux/memory-tiers.h | 7 +++---- mm/memory-tiers.c | 7 +++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/include/linux/memory-tiers.h b/include/linux/memory-tiers.h index 965009aa01d7..2e39d9a6c8ce 100644 --- a/include/linux/memory-tiers.h +++ b/include/linux/memory-tiers.h @@ -7,17 +7,16 @@ #include #include /* - * Each tier cover a abstrace distance chunk size of 128 + * Each tier cover a abstrace distance chunk size of 10 */ -#define MEMTIER_CHUNK_BITS 7 -#define MEMTIER_CHUNK_SIZE (1 << MEMTIER_CHUNK_BITS) +#define MEMTIER_CHUNK_SIZE 10 /* * Smaller abstract distance values imply faster (higher) memory tiers. Offset * the DRAM adistance so that we can accommodate devices with a slightly lower * adistance value (slightly faster) than default DRAM adistance to be part of * the same memory tier. */ -#define MEMTIER_ADISTANCE_DRAM ((4 * MEMTIER_CHUNK_SIZE) + (MEMTIER_CHUNK_SIZE >> 1)) +#define MEMTIER_ADISTANCE_DRAM ((100 * MEMTIER_CHUNK_SIZE) + (MEMTIER_CHUNK_SIZE / 2)) #define MEMTIER_HOTPLUG_PRIO 100 struct memory_tier; diff --git a/mm/memory-tiers.c b/mm/memory-tiers.c index fa8c9d07f9ce..e03011428fa5 100644 --- a/mm/memory-tiers.c +++ b/mm/memory-tiers.c @@ -165,11 +165,10 @@ static struct memory_tier *find_create_memory_tier(struct memory_dev_type *memty bool found_slot = false; struct memory_tier *memtier, *new_memtier; int adistance = memtype->adistance; - unsigned int memtier_adistance_chunk_size = MEMTIER_CHUNK_SIZE; lockdep_assert_held_once(&memory_tier_lock); - adistance = round_down(adistance, memtier_adistance_chunk_size); + adistance = rounddown(adistance, MEMTIER_CHUNK_SIZE); /* * If the memtype is already part of a memory tier, * just return that. @@ -204,7 +203,7 @@ static struct memory_tier *find_create_memory_tier(struct memory_dev_type *memty else list_add_tail(&new_memtier->list, &memory_tiers); - new_memtier->dev.id = adistance >> MEMTIER_CHUNK_BITS; + new_memtier->dev.id = adistance / MEMTIER_CHUNK_SIZE; new_memtier->dev.bus = &memory_tier_subsys; new_memtier->dev.release = memory_tier_device_release; new_memtier->dev.groups = memtier_dev_groups; @@ -641,7 +640,7 @@ static int __init memory_tier_init(void) #endif mutex_lock(&memory_tier_lock); /* - * For now we can have 4 faster memory tiers with smaller adistance + * For now we can have 100 faster memory tiers with smaller adistance * than default DRAM tier. */ default_dram_type = alloc_memory_type(MEMTIER_ADISTANCE_DRAM);