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=-5.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=no 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 8BB92C433EF for ; Mon, 13 Sep 2021 18:37:00 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E21EC6044F for ; Mon, 13 Sep 2021 18:36:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org E21EC6044F 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 4204B6B006C; Mon, 13 Sep 2021 14:36:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3CF80900002; Mon, 13 Sep 2021 14:36:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 26FCF6B0072; Mon, 13 Sep 2021 14:36:59 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0248.hostedemail.com [216.40.44.248]) by kanga.kvack.org (Postfix) with ESMTP id 130046B006C for ; Mon, 13 Sep 2021 14:36:59 -0400 (EDT) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 9C18029325 for ; Mon, 13 Sep 2021 18:36:58 +0000 (UTC) X-FDA: 78583406916.07.0470B78 Received: from mail-lf1-f50.google.com (mail-lf1-f50.google.com [209.85.167.50]) by imf15.hostedemail.com (Postfix) with ESMTP id 4EFF4D000096 for ; Mon, 13 Sep 2021 18:36:58 +0000 (UTC) Received: by mail-lf1-f50.google.com with SMTP id h16so23040538lfk.10 for ; Mon, 13 Sep 2021 11:36:58 -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=8fHwSdHRenOL8e8gzml3WboPm3MpukdtGUzL7MVnDHQ=; b=C5eR7zeIonh+nOkfP7fcBeL9oXgmtkHxuoVYj+nBubxvn7/6/FyOZG/OVwsjyZzQCJ JyVbgcO3g6HGmeRVNkVWp3+H/pUJWbdBd0dCfdVjNhtXNr5H/XJ/pO2ARJz5arBpiIF5 1EaKi0GZrZrK+/IlGsx4obX8oeP31gWD298b5aqqt7X2dMuTmNSXFqDkO4p9PCdjJOJ8 9umo0Pi3SKQxHZcR5Wlt8J9JTJ9qlEWFO+yKkK9NOZWh2RllZSgOnO0I6IVVsXRzOVjN VXjjmVy+MqOjud0ueZtFkx9lrIiCqXTrNG2Z7PRh83lmKk2dXQcK77MFridZQt/n5/8f v44g== 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=8fHwSdHRenOL8e8gzml3WboPm3MpukdtGUzL7MVnDHQ=; b=yKYaU8L/jogq5HylbcAeflQxTzDKH6pJ0vQY8UOvG3IWxBkDTtcUOxtx+Fjo4b076V o8mUDhuUGNsp5EhSv/eJQwQzzwIrnY4b4M8jU5uNM0lTr0CLPR1foLWo3F9MugFnMwQT /rbMEV6iDgKuhmlCtg5dxJeL3UkdCjPoyvpMKUSZ0aubOIkhBWr1Ac7g13zINUr/aICK DcBy1tJioSmMrqcjB9HJftWHm7D4aVtXg+N1AChdyfFfwvcix70ayKlkIfwbbtyesXw1 Z2UjbQuJcjMCX5y3OCaGrBtwo9y+hn2iiHOYuD2hQuhybPKezp+8R5Qj8/BryKFArD0t AcPA== X-Gm-Message-State: AOAM531XvIliahzLRaKvLuN9D3ktqxWPkjENuSMCOqrHdrCcZbsuyEjQ +wE7ZcviKSePuiUaeyr4uilh9C+tsGrIsWdnTi9bLA== X-Google-Smtp-Source: ABdhPJycueTe9ynjGMM1P7J0IARTvLFqYZTFv3QNmKHZhWxfMnM56B6MDIoode6/F6/kcsmNQCR0Wesx4wDQApon4IE= X-Received: by 2002:a05:6512:32c9:: with SMTP id f9mr9915971lfg.249.1631558216538; Mon, 13 Sep 2021 11:36:56 -0700 (PDT) MIME-Version: 1.0 References: <20210913123040.278031-1-aneesh.kumar@linux.ibm.com> In-Reply-To: From: Pasha Tatashin Date: Mon, 13 Sep 2021 14:36:20 -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-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 4EFF4D000096 X-Stat-Signature: jwfj91r59dznifqot41ereo4xxd6g9e3 Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=soleen.com header.s=google header.b=C5eR7zeI; spf=pass (imf15.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.167.50 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com; dmarc=none X-HE-Tag: 1631558218-146295 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: > >> + 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. I understand, the above loop searches for the first node with memory, and returns it. It cannot end up in the infinite loop in case if there are bugs where numa_node_size() are zero for all nodes for example. Also, it does not have gotos. > > >> + > >> +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. It is useful in terms that get_next_mem_node() is supplied with real nodes. Also, it works better with the version of loop that I am proposing above: "max_node + node" when node == -1 does not yield the desired result. Thanks, Pasha