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 5666EC02180 for ; Mon, 13 Jan 2025 12:22:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D6E8C6B0089; Mon, 13 Jan 2025 07:22:02 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CF7766B008A; Mon, 13 Jan 2025 07:22:02 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B98DE6B008C; Mon, 13 Jan 2025 07:22:02 -0500 (EST) 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 95A876B0089 for ; Mon, 13 Jan 2025 07:22:02 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 4FD5E1401EA for ; Mon, 13 Jan 2025 12:22:02 +0000 (UTC) X-FDA: 83002340484.03.5B7618C Received: from out30-98.freemail.mail.aliyun.com (out30-98.freemail.mail.aliyun.com [115.124.30.98]) by imf11.hostedemail.com (Postfix) with ESMTP id 0EFFA40013 for ; Mon, 13 Jan 2025 12:21:58 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=mqshn1qe; spf=pass (imf11.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.98 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=linux.alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1736770920; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=AqdLE9pWgtC6vLETuurDn2hf9BpPaaIj2TMPbkY2bFk=; b=4i7eMzHsUiSAVKGtod46dvLkfOF7BDH5DVLMZSe0auy86DSVef93iqfUSUKPxZ07dV/fIN ANk9fpPg86+SbM9c/V7qaz+Xx9gnE3DNasDIOC2crbWjueMPi+WTC+5hlqowP2jw4DIW/u gMX+7dPcm4bDZA1pF+H/O2PFVE6osGE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736770920; a=rsa-sha256; cv=none; b=gm6FOkb3Oxg5MID27/YQpBf/cgOgm34AMp6gRvOzlTsuZUcj++hTBnzvBrrqCpIJyDxKB7 SOsgSv10PDLWoQgNDPe2kc+8jb/g70MaMZSyV5qBtQ2nGnM6a8ST66Ioi50iBHZcZ3XiEb 8feDVuGtO95aIdrJRrQizVY0BjFDSco= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=mqshn1qe; spf=pass (imf11.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.98 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=linux.alibaba.com DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1736770915; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=AqdLE9pWgtC6vLETuurDn2hf9BpPaaIj2TMPbkY2bFk=; b=mqshn1qeNYl4JEt5JdR2fmmXehz7tZFT7Ld/l6UZgJCbzSTo74/+jjSi/Z6jdF2Wrrdd9/dPSE/VWLmsO3q0tPM5WCoPH2SMxwZpik7iX8BnoxZ+DP1Xu57ZwT4dRoZ/jt8P2ltOFtgc3Ghdsji0X8UCo/OzkWrhtBaQaRNpt60= Received: from 30.15.242.227(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0WNYKcwU_1736770913 cluster:ay36) by smtp.aliyun-inc.com; Mon, 13 Jan 2025 20:21:54 +0800 Message-ID: <927b8efc-52ea-4f31-add5-62e721c32b90@linux.alibaba.com> Date: Mon, 13 Jan 2025 20:21:51 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v1 3/6] mm/migrate: don't call folio_putback_active_hugetlb() on dst hugetlb folio To: David Hildenbrand , linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, Andrew Morton , Muchun Song , "Matthew Wilcox (Oracle)" References: <20250110182149.746551-1-david@redhat.com> <20250110182149.746551-4-david@redhat.com> <09b71834-157b-4869-91f7-854be47b45e2@redhat.com> From: Baolin Wang In-Reply-To: <09b71834-157b-4869-91f7-854be47b45e2@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 0EFFA40013 X-Rspam-User: X-Rspamd-Server: rspam07 X-Stat-Signature: pj4961s4cx7dg1mqz4mdak6d59tzawsr X-HE-Tag: 1736770918-385131 X-HE-Meta: U2FsdGVkX19HWaOcK0fY5+vnMwG3qrYASAF/YLv4UF/RCu+Mhx+F7EjIq0GDx5obtB3quFLRPhsk9eAuOSzJaddiJyDNQp0DbBcYDAULvQLcIXC9oa7M85lIcueSxCgz6N6AZ5XoR7ERuKp17LKtnmrv8ineb4w4KX5SIXgSFs/bdjq5TzUmdGQMLSBRsKjLHIfMa4wW7Y5XFuGuJTCI8fPoJV7SO4Y6BwFrSqzegJYZzUuTrE2s/7zEbWJG2OtIllTs8iggm9vcBceTKdlfBcPyw3meg22VBBlgGgm+bRsJADYlhbLi5RaamgyP4aVReMVrh/Vpu71uiumc4Gcog1F+0WQkj+LMpMMiLzDsBPSmEZF4DMFK/TpD9U9ClC/WR15hYzmaRiz2Cxf7qFEM4P3VZjp9CH/aTEqrmxCJVNDcmuIYL/Drn1T6tiEidW18L9mY7Z9KTyAgaxEppcI7jX+XgFXEyBUkV57lwNA5MzS92EUvy8kGmoxnBYYKEHEFrU5M7sAklROU6ZjXIxiqc6phQG+Wl9OKReuSFVnbx/41U60rN74jxc5PIQdiuE8LQVTsWm17Nk7pTMJ4/dqbtB7TX4BbJ/u0wYXYFnS6PY2QCYO5gfCJwTMHsWErgtrQBLFBcq+T5kc4FvfqsG0ZSj7OJv9TUUH0quXbZw1NzFalt7WLAPalKJrEyjrigwh59bEjzTHLh9QkVmZ/waRIzBAm3ibf3BULPd6/JC9H6mEVNNZoY0gVF+k9NvgB90ev551RvQ3n0NVmjYezcbIvx0RPt5dLMqyYrjMZUgoR6O4byN3c7bspQJ9A7VJbzSJdALF/+8o+YzxH2wol1BuySVaIxYPknAOa36iOJWEn+Cu+x3s5tdLEIDXRCmcqUCQFQn2LVKSjWxQg3iPuz/07CONaEpogPIft+sCQHGTrSuM20S27pHqS4woXeotnj8+6uIfrPPrfUS2/oF0Zpqj 9STmh/bQ f93Fk1qU1Zdhe2tXkZIEwKsSgG00WRPW4MPsS8bZdibi9AFaHX7OoktqPne7x9I/lto4Vgo1jWOfFw+vrgyHwNoEoSmKbpHP37cyBAWTwLJ4jvke5nAy7L/6p72qnDxQzBy3zNJ0Punw7qwK1UosB7HfLizgUNHDugKN1Z0DsItQy9za8g/dAbXrgoTZQq1QZ9BEJuEhjvWHOonKHfcTTdUlbFYyoumW+l2H7TnKyCl7t9jl2NxsMSLLUAsiZ2yKeYsQq5toNjaolPNOJjrFjBQg3019yx01TMzj/Kxh5sCQimeDNiAOEtZ61LjZB9dUHDHyVpPP/TEUXn8xxYQXE2JRRI8QOja1p5uWWccXK2HFL6hXVBRNmOgCA/Q== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000003, 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 2025/1/13 17:50, David Hildenbrand wrote: > On 13.01.25 08:00, Baolin Wang wrote: >> >> >> On 2025/1/11 02:21, David Hildenbrand wrote: >>> We replaced a simple put_page() by a putback_active_hugepage() call in >>> commit 3aaa76e125c1 ("mm: migrate: hugetlb: putback destination hugepage >>> to active list"), to set the "active" flag on the dst hugetlb folio. >>> >>> Nowadays, we decoupled the "active" list from the flag, by calling the >>> flag "migratable". >>> >>> Calling "putback" on something that wasn't allocated is weird and not >>> future proof, especially if we might reach that path when migration >>> failed >>> and we just want to free the freshly allocated hugetlb folio. >>> >>> Let's simply set the "migratable" flag in move_hugetlb_state(), where we >>> know that allocation succeeded, and use simple folio_put() to return >>> our reference. >>> >>> Do we need the hugetlb_lock for setting that flag? Staring at other >>> users of folio_set_hugetlb_migratable(), it does not look like it. After >>> all, the dst folio should already be on the active list, and we are not >>> modifying that list. >>> >>> Signed-off-by: David Hildenbrand >>> --- >>>    mm/hugetlb.c | 5 +++++ >>>    mm/migrate.c | 8 ++++---- >>>    2 files changed, 9 insertions(+), 4 deletions(-) >>> >>> diff --git a/mm/hugetlb.c b/mm/hugetlb.c >>> index da98d671088d0..b24ccf8ecbf38 100644 >>> --- a/mm/hugetlb.c >>> +++ b/mm/hugetlb.c >>> @@ -7529,6 +7529,11 @@ void move_hugetlb_state(struct folio >>> *old_folio, struct folio *new_folio, int re >>>            } >>>            spin_unlock_irq(&hugetlb_lock); >>>        } >>> +    /* >>> +     * Our old folio is isolated and has "migratable" cleared until it >>> +     * is putback. As migration succeeded, set the new folio >>> "migratable". >>> +     */ >>> +    folio_set_hugetlb_migratable(new_folio); >>>    } >>>    static void hugetlb_unshare_pmds(struct vm_area_struct *vma, >>> diff --git a/mm/migrate.c b/mm/migrate.c >>> index 80887cadb2774..7e23e78f1e57b 100644 >>> --- a/mm/migrate.c >>> +++ b/mm/migrate.c >>> @@ -1542,14 +1542,14 @@ static int >>> unmap_and_move_huge_page(new_folio_t get_new_folio, >>>            list_move_tail(&src->lru, ret); >>>        /* >>> -     * If migration was not successful and there's a freeing >>> callback, use >>> -     * it.  Otherwise, put_page() will drop the reference grabbed >>> during >>> -     * isolation. >>> +     * If migration was not successful and there's a freeing callback, >>> +     * return the folio to that special allocator. Otherwise, simply >>> drop >>> +     * our additional reference. >>>         */ >>>        if (put_new_folio) >>>            put_new_folio(dst, private); >>>        else >>> -        folio_putback_active_hugetlb(dst); >>> +        folio_put(dst); >> > > Hi Baolin, > > thanks for the review! > >> IIUC, after the changes, so the 'dst' folio might not be added into the >> 'h->hugepage_activelist' list (if the 'dst' i:s temporarily allocated), >> Could this cause any side effects? > > Good point, so far I was under the assumption that the dst folio would > already be in the active list. > > alloc_migration_target() and friends call alloc_hugetlb_folio_nodemask(). > > > There are two cases: > > 1) We call dequeue_hugetlb_folio_nodemask() -> > dequeue_hugetlb_folio_node_exact() > where we add the folio to the hugepage_activelist. > > 2) We call alloc_migrate_hugetlb_folio() > > It indeed looks like we don't add them to the active list. So likely we > should do: > > > diff --git a/mm/hugetlb.c b/mm/hugetlb.c > index dca4f310617a2..c6463dd7a1fc8 100644 > --- a/mm/hugetlb.c > +++ b/mm/hugetlb.c > @@ -7546,7 +7546,10 @@ void move_hugetlb_state(struct folio *old_folio, > struct folio *new_folio, int re >          * Our old folio is isolated and has "migratable" cleared until it >          * is putback. As migration succeeded, set the new folio > "migratable". >          */ > +       spin_lock_irq(&hugetlb_lock); >         folio_set_hugetlb_migratable(new_folio); > +       list_move_tail(&new_folio->lru, > &(folio_hstate(new_folio))->hugepage_activelist); > +       spin_unlock_irq(&hugetlb_lock); >  } > >  static void hugetlb_unshare_pmds(struct vm_area_struct *vma, > > > move_hugetlb_state() also takes care of that "temporary" handling. LGTM. With the changes: Reviewed-by: Baolin Wang > (I wonder if in case 1) it was a problem that the folio was already on the > active list) Seems harmless, and putback_active_hugepage() did the same before.