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=-12.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 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 401E6C433FE for ; Mon, 13 Sep 2021 16:31:40 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E2D7E60EB4 for ; Mon, 13 Sep 2021 16:31:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org E2D7E60EB4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.ibm.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 7E6666B009B; Mon, 13 Sep 2021 12:31:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7957E6B009C; Mon, 13 Sep 2021 12:31:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 63DF96B009D; Mon, 13 Sep 2021 12:31:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0135.hostedemail.com [216.40.44.135]) by kanga.kvack.org (Postfix) with ESMTP id 53D8C6B009B for ; Mon, 13 Sep 2021 12:31:39 -0400 (EDT) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id EDF5C82499B9 for ; Mon, 13 Sep 2021 16:31:38 +0000 (UTC) X-FDA: 78583091076.26.795208B Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by imf29.hostedemail.com (Postfix) with ESMTP id 395309000264 for ; Mon, 13 Sep 2021 16:31:37 +0000 (UTC) Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.0.43) with SMTP id 18DFfduP006997; Mon, 13 Sep 2021 12:31:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=subject : to : cc : references : from : message-id : date : mime-version : in-reply-to : content-type : content-transfer-encoding; s=pp1; bh=7XkNwVJShWCFptPS11ewhafzTyHm7WQVKsUMO5y32Dg=; b=B6kYX6vGGFJj7g7YGgjNfYrY0vGd1+LZXfXYZpTtHuQuLge7UuMvE8AXfapgCUtLGNU9 XtWmW8P0E1BkYUd7nGstjSJzAIENYtsGRF4WQshUDQ2taISharAE6OLJJRYMIdkuZ8q0 cWg1RlRnEauTtY+NGuziK8DmBXL2tsDTOk7oas3wCFLznisnIJcAHso2DKzaG+pc2jNq PF9Uz5xlH5e9B3yBAgSP25nz8gdmMjTRyqeZFEoUkqQJcMBw7kzF8o1oH8uPOtlYjLVE Y2pZJKYLcKQokGHVu7EvzKppngpzySCcddC3Aayn9fcpZuXk2LkgBDvDDGoWGur2EHIv qw== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3b23h9urp9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 13 Sep 2021 12:31:35 -0400 Received: from m0098399.ppops.net (m0098399.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 18DDJ52u028176; Mon, 13 Sep 2021 12:31:35 -0400 Received: from ppma03fra.de.ibm.com (6b.4a.5195.ip4.static.sl-reverse.com [149.81.74.107]) by mx0a-001b2d01.pphosted.com with ESMTP id 3b23h9urmw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 13 Sep 2021 12:31:35 -0400 Received: from pps.filterd (ppma03fra.de.ibm.com [127.0.0.1]) by ppma03fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 18DGK6Gi030975; Mon, 13 Sep 2021 16:31:32 GMT Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by ppma03fra.de.ibm.com with ESMTP id 3b0m3923mh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 13 Sep 2021 16:31:32 +0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 18DGVU7k45416762 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 13 Sep 2021 16:31:30 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5711911C04C; Mon, 13 Sep 2021 16:31:30 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 649A311C052; Mon, 13 Sep 2021 16:31:28 +0000 (GMT) Received: from [9.43.86.25] (unknown [9.43.86.25]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 13 Sep 2021 16:31:28 +0000 (GMT) Subject: Re: [PATCH] selftest/vm: Fix ksm selftest to run with different NUMA topologies To: Pasha Tatashin Cc: linux-mm , Andrew Morton , Zhansaya Bagdauletkyzy , Tyler Hicks , Hugh Dickins , Shuah Khan References: <20210913123040.278031-1-aneesh.kumar@linux.ibm.com> From: "Aneesh Kumar K.V" Message-ID: Date: Mon, 13 Sep 2021 22:01:27 +0530 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 X-Proofpoint-GUID: 2YzgjvZbcOTnMwihUatAqfvvM1WXCI-O X-Proofpoint-ORIG-GUID: VQD7pHfTrSUTHnK0w6ufTnySogzrsmGe X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.182.1,Aquarius:18.0.687,Hydra:6.0.235,FMLib:17.0.607.475 definitions=2020-10-13_15,2020-10-13_02,2020-04-07_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 clxscore=1015 impostorscore=0 adultscore=0 suspectscore=0 phishscore=0 bulkscore=0 mlxscore=0 mlxlogscore=999 malwarescore=0 spamscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2109030001 definitions=main-2109130047 X-Stat-Signature: e9m1fx6w5abwzphgknp9dwdwy1k194tb Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=B6kYX6vG; dmarc=pass (policy=none) header.from=ibm.com; spf=pass (imf29.hostedemail.com: domain of aneesh.kumar@linux.ibm.com designates 148.163.156.1 as permitted sender) smtp.mailfrom=aneesh.kumar@linux.ibm.com X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 395309000264 X-HE-Tag: 1631550697-661006 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 9/13/21 8:40 PM, Pasha Tatashin wrote: > 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. > sure will update. >> +{ >> + >> + 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); > I didn't quiet follow this. not all nodes can have memory and node numbers are discontiguous. >> + >> +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()); > > Yes, that would work, but is that really useful? We would essentially skip the for loop in first iteration set node = -1 internally and do the for loop again. >> +} >> + >> 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 > -aneesh