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 X-Spam-Level: X-Spam-Status: No, score=-10.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 74992C433F5 for ; Mon, 13 Sep 2021 15:11:03 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id BAB826103B for ; Mon, 13 Sep 2021 15:11:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org BAB826103B Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=soleen.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 1841D900002; Mon, 13 Sep 2021 11:11:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1348A6B0071; Mon, 13 Sep 2021 11:11:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0232D900002; Mon, 13 Sep 2021 11:11:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0025.hostedemail.com [216.40.44.25]) by kanga.kvack.org (Postfix) with ESMTP id E61376B006C for ; Mon, 13 Sep 2021 11:11:01 -0400 (EDT) Received: from smtpin38.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 81D3E19224 for ; Mon, 13 Sep 2021 15:11:01 +0000 (UTC) X-FDA: 78582887922.38.086DECA Received: from mail-lj1-f169.google.com (mail-lj1-f169.google.com [209.85.208.169]) by imf25.hostedemail.com (Postfix) with ESMTP id 37A50B000181 for ; Mon, 13 Sep 2021 15:11:01 +0000 (UTC) Received: by mail-lj1-f169.google.com with SMTP id f2so17937167ljn.1 for ; Mon, 13 Sep 2021 08:11:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=hTkZFDqvBskM3QKX3fNP94Bq2Ayy6wMoWEXbs10g4fU=; b=O916g++aj0vC1Ljl7aA0nsXTA3Wr3k1X3SoWLXxr3lFW/QZNJzDwcNVr0d2LtCnJFN eSwK2gB3+QHIrB1kYfFsl17d5T4ch5n8W3MifmBfUvTX5QnkiTONf3H118xd5EvXJKe+ vj0q46ld1eniPSOOZl0EmSSbFsOifdZPevbz0jNON+S6pqCG0CJcmw3toNKi19c6fSwK FXVKY1YTHcpjU42yd3TDDk656tKz33eJqNbJMOEIGTWmlWxCHIhVF9IAR91mr6yJLDZe lhkg+42aFz6Wsulwk9REKH/Jq6DKesD7NFMxiC/lc86FSVR2XGg2Bw3b92TPGdWx6t+m BdJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=hTkZFDqvBskM3QKX3fNP94Bq2Ayy6wMoWEXbs10g4fU=; b=p3uRncZnCP8Ihk9FoCpcS+La2/HP17WhN10VeVOHmrBgKIsNBagTH9UWUev/ytWVva vasDcLVMnPF4vgwrb7E8d4xX3iDgeUhk/rdXdb27veoL8X4hbSU4ylEK/KHqrvSzPtPA hdqV9yDNzCJ9mTJuAahZRUWWX1ZWJj/vMam6qEw6+SYQjXiZdm8PmQa8ssnymQqHskiU B0HLLCU6nNVwLOCSdcYWA9xhGYiB8RDB8ylqsNs15/qr7BncQAgbP6tdwesdT+vW4uXF +O7n9bAllRV3syFrlJElBmPgayDaXFPYjYOwfyst8jVVDC8n+7AtJUBHMvrxRfzSslSi DhcQ== X-Gm-Message-State: AOAM530lDBb5iwcZRRGN/7VaYZSk7OV+etyd8SY7f1OSOM4js1N3SyPZ HxvcCZ8mkh+zXTG7IK4S/hcCkZOrpGhmK/n1W/P+qw== X-Google-Smtp-Source: ABdhPJxNnnQdlQFuB7+3y73CUYctYTCx7OllMKSyzzBQc3b3rx+5Iec4/b2GFWHWWffvMDci2PzRhdxrQjg2pxqg8KM= X-Received: by 2002:a2e:7005:: with SMTP id l5mr10386180ljc.355.1631545859731; Mon, 13 Sep 2021 08:10:59 -0700 (PDT) MIME-Version: 1.0 References: <20210913123040.278031-1-aneesh.kumar@linux.ibm.com> In-Reply-To: <20210913123040.278031-1-aneesh.kumar@linux.ibm.com> From: Pasha Tatashin Date: Mon, 13 Sep 2021 11:10:23 -0400 Message-ID: Subject: Re: [PATCH] selftest/vm: Fix ksm selftest to run with different NUMA topologies To: "Aneesh Kumar K.V" Cc: linux-mm , Andrew Morton , Zhansaya Bagdauletkyzy , Tyler Hicks , Hugh Dickins , Shuah Khan Content-Type: text/plain; charset="UTF-8" X-Stat-Signature: iy5ox1hnfykwindyxqurtc8os6qup678 Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=soleen.com header.s=google header.b=O916g++a; dmarc=none; spf=pass (imf25.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.208.169 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 37A50B000181 X-HE-Tag: 1631545861-456163 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 Mon, Sep 13, 2021 at 8:32 AM Aneesh Kumar K.V wrote: > Hi Aneesh, Thank you for this fix. My comments below: > Platforms can have non-contiguous NUMA nodes like below Thanks for catching this. > +static unsigned long get_next_mem_node(unsigned long node) NUMA should be "int" not "unsigned long", especially as it is confusing with negative numbers used in get_first_mem_node(). Also, numa_max_node() returns int. > +{ > + > + long node_size; > + unsigned long i; > + unsigned long max_node = numa_max_node(); > + /* > + * start from node and find the next memory node > + */ > +restart: > + for (i = node + 1; i <= max_node; i++) { > + node_size = numa_node_size(i, NULL); > + if (node_size > 0) > + return i; > + } > + node = -1; > + goto restart; > +} I would rewrite the above without goto, and possibility of stacking in an infinite loop. Something like this should work: for (i = node + 1; i <= max_node + node; i++) { node_size = numa_node_size(i % (max_node + 1), NULL); if (node_size > 0) break; } return i % (max_node + 1); > + > +static unsigned long get_first_mem_node(void) > +{ > + return get_next_mem_node(-1); Next after the last node would make more sense: return get_next_mem_node(numa_max_node()); > +} > + > static int check_ksm_numa_merge(int mapping, int prot, int timeout, bool merge_across_nodes, > size_t page_size) > { > void *numa1_map_ptr, *numa2_map_ptr; > struct timespec start_time; > int page_count = 2; > + unsigned long first_node; Please use int. > > if (clock_gettime(CLOCK_MONOTONIC_RAW, &start_time)) { > perror("clock_gettime"); > @@ -370,7 +395,7 @@ static int check_ksm_numa_merge(int mapping, int prot, int timeout, bool merge_a > perror("NUMA support not enabled"); > return KSFT_SKIP; > } > - if (numa_max_node() < 1) { > + if (numa_num_configured_nodes() <= 1) { > printf("At least 2 NUMA nodes must be available\n"); > return KSFT_SKIP; > } > @@ -378,8 +403,9 @@ static int check_ksm_numa_merge(int mapping, int prot, int timeout, bool merge_a > return KSFT_FAIL; > > /* allocate 2 pages in 2 different NUMA nodes and fill them with the same data */ > - numa1_map_ptr = numa_alloc_onnode(page_size, 0); > - numa2_map_ptr = numa_alloc_onnode(page_size, 1); > + first_node = get_first_mem_node(); > + numa1_map_ptr = numa_alloc_onnode(page_size, first_node); > + numa2_map_ptr = numa_alloc_onnode(page_size, get_next_mem_node(first_node)); Thanks, Pasha