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 76C96C282DE for ; Thu, 13 Mar 2025 16:44:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9EDA1280004; Thu, 13 Mar 2025 12:44:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 99A9E280001; Thu, 13 Mar 2025 12:44:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8146B280004; Thu, 13 Mar 2025 12:44:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 5F2DC280001 for ; Thu, 13 Mar 2025 12:44:39 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 42E16160252 for ; Thu, 13 Mar 2025 16:44:41 +0000 (UTC) X-FDA: 83217101562.20.50F60AA Received: from olivedrab.birch.relay.mailchannels.net (olivedrab.birch.relay.mailchannels.net [23.83.209.135]) by imf14.hostedemail.com (Postfix) with ESMTP id B19F210000A for ; Thu, 13 Mar 2025 16:44:38 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=stgolabs.net header.s=dreamhost header.b=YvvdCLc1; dmarc=none; spf=pass (imf14.hostedemail.com: domain of dave@stgolabs.net designates 23.83.209.135 as permitted sender) smtp.mailfrom=dave@stgolabs.net; arc=reject ("signature check failed: fail, {[1] = sig:mailchannels.net:reject}") ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1741884279; a=rsa-sha256; cv=fail; b=SSnmlibXykAUxl7++E+IzOkUBfRKj2y/gGIbEgx30a/r46mmefD+UIRvuoAqFnshO/K6xw xtBbr06zyGbscPqpnYf7Ve3QVmaSSBBj3wrNidSRAF5Fnwz6HXbWU+7D5xbiuu3tklv9yA 7vWYXN4hRjc7ncVqwey+Spd+9YEEDP8= ARC-Authentication-Results: i=2; imf14.hostedemail.com; dkim=pass header.d=stgolabs.net header.s=dreamhost header.b=YvvdCLc1; dmarc=none; spf=pass (imf14.hostedemail.com: domain of dave@stgolabs.net designates 23.83.209.135 as permitted sender) smtp.mailfrom=dave@stgolabs.net; arc=reject ("signature check failed: fail, {[1] = sig:mailchannels.net:reject}") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1741884279; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=uET1fL+vCM9Q2BqQovUvW0LaxkIi96OCoOTgYKD4kNs=; b=nIPDimqSwiotQR/yByf+ktQHVFcKqAnGEBLyNSHHJATlv5Hp+eVtusQDnmhlweMeuzPrrV ddxN+UDijDxOMMH+arxJv3/42P6c02Q19WdbmBLCOYxuAkDkjma66seaHyXbDUMi3WW3Xc HN8niLnECuxjiJOTti4/qGF1v0Ie1YA= X-Sender-Id: dreamhost|x-authsender|dave@stgolabs.net Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 204AA8433A1; Thu, 13 Mar 2025 16:44:37 +0000 (UTC) Received: from pdx1-sub0-mail-a241.dreamhost.com (trex-7.trex.outbound.svc.cluster.local [100.118.31.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 5FF688441F3; Thu, 13 Mar 2025 16:44:36 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1741884276; a=rsa-sha256; cv=none; b=NFNwA8IysWNTBAWbs4AnydZW/HDE/aECf9A+3YdbaYBpSP/4QJ7HhnIkq39/P1CvakGLRp 0Fq+4Zadkmo3OqsrnNmscr3VB8lDlnFopKhM0t5E95e0k0yCVfZgNNk+CW8Ov63FCeMU92 x/c94abK4mdz1GWH/PRv+ziVt0WpRZN7WYMSDsww8eetJ1+xE/cm6/Qpf+WRZF6voZlR6d V2yTj6+hWnc84dso5g8UjuW5cX7E/ZGx+SRPYLyChAG27q/RduccTKd0z9vVPBWLxyI/op cpvjuUGr9F+f2pSsgxPLhJx87x2G+HfYm3Er+sUvBobnxYgnRd7yyPMyONSxng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1741884276; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=3xRmJGFN7nrPOW2BDqB1Q2ynnG49HTel0YdgzfldMH0=; b=1cnzCh9xxyW+R3Jf7B+iBxvIuoyUtA5qXLCDk0NWf0y3efgCvdsOXa25H1gZAGzeAdfx3p uo057OVICdfqXK6sWwFkjfpggnGxbGWAvY7q+BO6GlGvnj00m1zS2L2wyAfIwz7LMSfhRq dRPWHgWR+G30gLiv8xegh/ArPc8kRt87ktDAZ0Og5aygi5URtsmZb3YEExDWhMEoFJYP25 y9bhvEYdXHI099QTFUng8q0Y2T5oellIaqpnLQLUFa57ASixy6Vzo4LhA2OBBDDt5XZ7I7 bQt8nmWR+/ng6X8AS72MeySsZT2yxh8rwWtj71wPgCj+Ckcb9r4MW2hhn2pvpQ== ARC-Authentication-Results: i=1; rspamd-7788c767f-sjpjk; auth=pass smtp.auth=dreamhost smtp.mailfrom=dave@stgolabs.net X-Sender-Id: dreamhost|x-authsender|dave@stgolabs.net X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|dave@stgolabs.net X-MailChannels-Auth-Id: dreamhost X-Juvenile-Bubble: 7187a1e518e2522e_1741884276939_2886769575 X-MC-Loop-Signature: 1741884276938:356853382 X-MC-Ingress-Time: 1741884276938 Received: from pdx1-sub0-mail-a241.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.118.31.6 (trex/7.0.2); Thu, 13 Mar 2025 16:44:36 +0000 Received: from offworld (ip72-199-50-187.sd.sd.cox.net [72.199.50.187]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: dave@stgolabs.net) by pdx1-sub0-mail-a241.dreamhost.com (Postfix) with ESMTPSA id 4ZDCyV0NvbzGN; Thu, 13 Mar 2025 09:44:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=stgolabs.net; s=dreamhost; t=1741884276; bh=uET1fL+vCM9Q2BqQovUvW0LaxkIi96OCoOTgYKD4kNs=; h=Date:From:To:Cc:Subject:Content-Type; b=YvvdCLc1kVsaBV6jfPuOqoT1z0NXccBok/ZWrKs2pZoBMyobB7YXqhMQGUUgdgCmP jddpF+H+hCHV9hlsySR7Y1gB8UjCy7mqCZEArYUDqcm72k+4YhRy4oVEG6K1j631UI 5KnOU7pEqZTTqbtWIEPoYoDe6SyEINiME18debvKgWpVUZ+I8CS3NmRCOMYiLyAZqF aBYaECdLnxafRckV04c35NZnfM+BwQ6/2722+XOLfq2mjtpchJWR6MLSJd7ZPOcVjl mSu9ko0HC/YvVbNshqiyVg1QXghLkNfxVcups9r0eIvc5ATiy0AJsOf/os4T0GZQc2 av840qcTFr8TA== Date: Thu, 13 Mar 2025 09:44:30 -0700 From: Davidlohr Bueso To: Bharata B Rao Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, AneeshKumar.KizhakeVeetil@arm.com, Hasan.Maruf@amd.com, Jonathan.Cameron@huawei.com, Michael.Day@amd.com, akpm@linux-foundation.org, dave.hansen@intel.com, david@redhat.com, feng.tang@intel.com, gourry@gourry.net, hannes@cmpxchg.org, honggyu.kim@sk.com, hughd@google.com, jhubbard@nvidia.com, k.shutemov@gmail.com, kbusch@meta.com, kmanaouil.dev@gmail.com, leesuyeon0506@gmail.com, leillc@google.com, liam.howlett@oracle.com, mgorman@techsingularity.net, mingo@redhat.com, nadav.amit@gmail.com, nphamcs@gmail.com, peterz@infradead.org, raghavendra.kt@amd.com, riel@surriel.com, rientjes@google.com, rppt@kernel.org, shivankg@amd.com, shy828301@gmail.com, sj@kernel.org, vbabka@suse.cz, weixugc@google.com, willy@infradead.org, ying.huang@linux.alibaba.com, ziy@nvidia.com, yuanchu@google.com, hyeonggon.yoo@sk.com Subject: Re: [RFC PATCH 2/4] mm: kpromoted: Hot page info collection and promotion daemon Message-ID: <20250313164430.bzkfyqmx6a5dj7d2@offworld> Mail-Followup-To: Bharata B Rao , linux-kernel@vger.kernel.org, linux-mm@kvack.org, AneeshKumar.KizhakeVeetil@arm.com, Hasan.Maruf@amd.com, Jonathan.Cameron@huawei.com, Michael.Day@amd.com, akpm@linux-foundation.org, dave.hansen@intel.com, david@redhat.com, feng.tang@intel.com, gourry@gourry.net, hannes@cmpxchg.org, honggyu.kim@sk.com, hughd@google.com, jhubbard@nvidia.com, k.shutemov@gmail.com, kbusch@meta.com, kmanaouil.dev@gmail.com, leesuyeon0506@gmail.com, leillc@google.com, liam.howlett@oracle.com, mgorman@techsingularity.net, mingo@redhat.com, nadav.amit@gmail.com, nphamcs@gmail.com, peterz@infradead.org, raghavendra.kt@amd.com, riel@surriel.com, rientjes@google.com, rppt@kernel.org, shivankg@amd.com, shy828301@gmail.com, sj@kernel.org, vbabka@suse.cz, weixugc@google.com, willy@infradead.org, ying.huang@linux.alibaba.com, ziy@nvidia.com, yuanchu@google.com, hyeonggon.yoo@sk.com References: <20250306054532.221138-1-bharata@amd.com> <20250306054532.221138-3-bharata@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20250306054532.221138-3-bharata@amd.com> User-Agent: NeoMutt/20220429 X-Rspamd-Server: rspam07 X-Rspam-User: X-Stat-Signature: ehfcyzf4d13t6qk8311ahuq1dsaghjxr X-Rspamd-Queue-Id: B19F210000A X-HE-Tag: 1741884278-95535 X-HE-Meta: U2FsdGVkX19/HFfJKFjOqha8twn+YgLJqEkkgT3RoVRYIO3C2sk2qMd+T1iy7a3KZABtBPunTpQyHHxZbzhA8PjvMtCrXJM498BxB8NmfzlehevdAawFhzHIdnmNqIO6WWN98kmo0zoBC3pV5yiSMlJ89AK547s5zY4zITaG+dhZwSlEoac5oRBpwadK40vqdP1d49jYzHW3+aAMFoYrVAGRRbMsUFtHTYV6JPn7US8sk887cxuUz8DJcRTOjG1d5810eLEIy7cVupMBX9Hw44MLd4fXZKqmYuQVG+AJL84UU+kaU5o69AxY9P5TpONwQBUyrCT3dIjcMN1lcNCZLdM9tC/XexB/x+hFMiyJyUtttuYt/RiwO9YlswTOLravXhLmTs7zXQJ2sqDUFD2ILOg+hzPMMW24YqCfgTJfCZz5mBet19WLT2/lSbblTX2foIBygCRHNX9oiyeCdd/O4/RwzndP9W9TvKtO7IcV/G4550+FdpOfPKAb/iz6W7eECCHHudryMfIhMDEoOJk3EDHUj2CruvhebQ857emMetMgulpb+LwbxEWLM1Cr+gfisjcrDo3+lA5FFXW/NfiNz92IhTdkgw9lZ2JRiAtb4/fM3tIduVqszqVLS4uKgfSIwsfBfz59GQqWCIxXru/jCKE1lvM8oHflnHhbR4U9VMoIHrFXz8sKGqAmEkjyYVyYTqWczm+fPwhhN16q3ldKc9k8Mlpf5r6LgjgJbmUfdFHEmMMFwq5B+VijiRfgEjh/XDOpyp3U8VGAPuu9u8Et2iV/LSyo2AXgkas5XburdyItP+wSyv3SoRrbFxU02Yxq7IYjdqoa5rQEXKNvjeiAZHKYzrcInXmgHtdJmenh/JKZsviJZMeQK0rSfJ3JKjeSwl9amCcqSa/UAZcB1W12tgWymq3Phe0PmVfdbfLYsfwZZHY6WRXuoHzborNAuXR0Nt+EBFh4Z3SbEzLHu15 1982RYWE 2KUHchF/Vp5nE6w+HgYuUvIcPxEJRDTCCyTebzGNjgaK6J3juNgweegnrVwMI3zGVdEjhtckldfzHjO4MhImGCcLaJ09TLGiDcp5FwcaP2Saz42iT6r7tg85eMaZJpAe91wVmw3n9DGandZFkAxeZ2QpLT0g++GYzXpriNLltecF34rGGitAFHEcBpx/t6L1zpKfnm9fv6ZEzWR9AmGsraSnJ9JCCz5zxgm1ijoryJ59ZVxgzURPAuvaseMSs3XIk68VhN/5miAT4+UMgQ9v0KoxM8w86TfHWM/Uppp4WkQhQaOI5xiuKdq5SZp9QEXg6YdB4lQSPppiNR/t9DddJa+bxlVd098TLFO1+pzx9hJ6XTEQ03eKaSkEqf3C3TIcSHeN+7PKkY5uzxoeXUcL2sfqsho5MuraONqw+NjUrWmh6jyf1WPZ8P9VYJQ== 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: List-Subscribe: List-Unsubscribe: On Thu, 06 Mar 2025, Bharata B Rao wrote: >+static int page_should_be_promoted(struct page_hotness_info *phi) >+{ >+ struct page *page = pfn_to_online_page(phi->pfn); >+ unsigned long now = jiffies; >+ struct folio *folio; >+ >+ if (!page || is_zone_device_page(page)) >+ return false; >+ >+ folio = page_folio(page); >+ if (!folio_test_lru(folio)) { >+ count_vm_event(KPROMOTED_MIG_NON_LRU); >+ return false; >+ } >+ if (folio_nid(folio) == phi->hot_node) { >+ count_vm_event(KPROMOTED_MIG_RIGHT_NODE); >+ return false; >+ } How about using the LRU age itself: if (folio_test_active()) return true; >+ >+ /* If the page was hot a while ago, don't promote */ >+ if ((now - phi->last_update) > 2 * msecs_to_jiffies(KPROMOTED_FREQ_WINDOW)) { >+ count_vm_event(KPROMOTED_MIG_COLD_OLD); >+ return false; >+ } >+ >+ /* If the page hasn't been accessed enough number of times, don't promote */ >+ if (phi->frequency < KPRMOTED_FREQ_THRESHOLD) { >+ count_vm_event(KPROMOTED_MIG_COLD_NOT_ACCESSED); >+ return false; >+ } >+ return true; >+} ... >+static int kpromoted(void *p) >+{ >+ pg_data_t *pgdat = (pg_data_t *)p; >+ struct task_struct *tsk = current; >+ long timeout = msecs_to_jiffies(KPROMOTE_DELAY); >+ >+ const struct cpumask *cpumask = cpumask_of_node(pgdat->node_id); >+ >+ if (!cpumask_empty(cpumask)) >+ set_cpus_allowed_ptr(tsk, cpumask); Explicit cpumasks are not needed if you use kthread_create_on_node(). See https://web.git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/?id=c6a566f6c1b4d5dff659acd221f95a72923f4085 >+ >+ while (!kthread_should_stop()) { >+ wait_event_timeout(pgdat->kpromoted_wait, >+ kpromoted_work_requested(pgdat), timeout); >+ kpromoted_do_work(pgdat); >+ } >+ return 0; >+} >+ >+static void kpromoted_run(int nid) >+{ >+ pg_data_t *pgdat = NODE_DATA(nid); >+ >+ if (pgdat->kpromoted) >+ return; >+ >+ pgdat->kpromoted = kthread_run(kpromoted, pgdat, "kpromoted%d", nid); >+ if (IS_ERR(pgdat->kpromoted)) { >+ pr_err("Failed to start kpromoted on node %d\n", nid); >+ pgdat->kpromoted = NULL; >+ } >+} >+