From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1942622CF20 for ; Mon, 13 Jan 2025 12:26:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736771200; cv=none; b=TrlX1v6ZAC9E82M3NYTqL1bFrR2Sot5d/Hs8S51R4UpK5SQn8Jk9z8M0XsF757JS7+CtXYvyridJ1+CzmbD2J3FQzDnazmD9udBMh/rH2GIfVk16J1JpBKh+Dh8e7TWAiV7wdLgf0iGlmegbxbVm89m0wchCk3Xbhb0XXOwqUsM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736771200; c=relaxed/simple; bh=+7S+ZGHIurDKjXDd3rme24YsJs01F19RSulEwUIw23w=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=Vb2KZQxX/n9we97mucclU94yCwhBiA/77Je95CVbNr/NyhIt4uXbTibkSWUCECKrShkpHLEfE2/46UQVbfvKZoqBC9Z8uC/nvRi+Q+MsVnVXFf8sp3mBYkjRBA730NRHC28/N/QZRzrg1jYsys180OM2Ujp/MrhMabmaPvd0d9A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=cjdQoxdX; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="cjdQoxdX" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736771197; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=bCDzVQTq08Z2rq3y8qpq7h5Lin/5W2tmH6464yypIRo=; b=cjdQoxdXueHfGa2WOrvsuYFWCqDc5o+Cuel3lS8bzCtEZyGmM8zpUSQWv5a8AMdKMPY2Aj yQO4J7D4YtKaqngojl4lEvm/8JVIWpGXhoMhHRA7TjaR3IVq5Z2CyS7BPqGyUvYcBjtL9C K1Hg6/9PfGYVdOYVIctfHiAvE+/3rzc= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-593-t8_Wcg3INW2jEgzSYFe8vA-1; Mon, 13 Jan 2025 07:26:36 -0500 X-MC-Unique: t8_Wcg3INW2jEgzSYFe8vA-1 X-Mimecast-MFC-AGG-ID: t8_Wcg3INW2jEgzSYFe8vA Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-388d1f6f3b2so1964346f8f.0 for ; Mon, 13 Jan 2025 04:26:36 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736771195; x=1737375995; h=content-transfer-encoding:in-reply-to:organization:autocrypt :content-language:from:references:cc:to:subject:user-agent :mime-version:date:message-id:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=bCDzVQTq08Z2rq3y8qpq7h5Lin/5W2tmH6464yypIRo=; b=cZfss/VbYyxeBr/s0pWW5FGsQXtPqmN0dnebtWbqMaV65Lew//5ZvGR9vPyowdVhXm AnZistMc9JWHvZ6KVRwp6FuvIvqnpQzNnlU59Yt6YNwQFS/UGy/mz1+QqzaQnOBGaIWg N8zKVtXU4/4hVigE/eKN+qeh/mCFjizBjZ9mFTJhbnfpuLyk9DfwXop0O7aJbUDbRlut w12MU0lmxQjvpUsS7jLdGFevYliOc/no03rTWGTeZJPll4EjVa19jEV6/hZKhNZpWG6u QTlZcIvdmrGDujZWtXG5b5S/nREj8M+A4L4zLEJT2FtiWDP2y2wox7/z1HISj6QI9tdh N35Q== X-Forwarded-Encrypted: i=1; AJvYcCUWbotuvLnZLWbMVpTgdJwMv361HPQyn85j/LeKEaWH5uReWZUBpNUzbb059xqdKRnM7vz3Wyy1ODrlBcY=@vger.kernel.org X-Gm-Message-State: AOJu0YydJ8TZoG8h7ffROoE83EAliw7rJApxOgY33Nru9NNp0inSa5XE vi/xgngJX24D+HAuHB970AjeCYCF0SZdTjVFwi/X8INtZFroB4sw62WhXxP3EJ+Qvn7Vau8FSn2 u4s0YFGY9YJFbYSJ7TWRp/Ev7f6BRNQIgCi56V1Cg6nNZLbAdLwV0QslX4BZGVg== X-Gm-Gg: ASbGncsyz+qytH4wpeDyFn2+eo5PBRDGyegHbPcBZAAV2fDaqM5PkrGhbHrA2YwP6MH sjFmuzBtyktNl/1dtIgOZxXWHEJF6VHOzNQuLet8NvwwdolJ4Uw/MPL6xY/sm7axXFG98lTDIg6 sU6uzyFGU11Ba9Qp2hntBOKsYwNgnO0DLwcl2GvqoCHbt3+iYtg2HZN5/eMAL6N4x4oCbCiB5Ij HAP8o5J5zbtzxhEb+YwDxUDwDhT7tjui3w7aQMJW5U9jtlLcx3EIFXia75LoNict27r2wMFXSKK /V9JVl/pZP3XLhs= X-Received: by 2002:a05:6000:1847:b0:385:f060:b7fc with SMTP id ffacd0b85a97d-38a8730a60cmr19384649f8f.25.1736771195300; Mon, 13 Jan 2025 04:26:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IHCXHgDMio2ejjCUbL+E/oVW9WC8dbjjaMMxw6H4JoaBhp2qRu6/FhPQgpF9ejljzj0AdMzDw== X-Received: by 2002:a05:6000:1847:b0:385:f060:b7fc with SMTP id ffacd0b85a97d-38a8730a60cmr19384618f8f.25.1736771194876; Mon, 13 Jan 2025 04:26:34 -0800 (PST) Received: from ?IPV6:2a09:80c0:192:0:5dac:bf3d:c41:c3e7? ([2a09:80c0:192:0:5dac:bf3d:c41:c3e7]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38a8e37d0casm12124570f8f.11.2025.01.13.04.26.32 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 13 Jan 2025 04:26:33 -0800 (PST) Message-ID: <6ddbb98b-0819-415b-80b4-6bfe6d343461@redhat.com> Date: Mon, 13 Jan 2025 13:26:32 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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: Baolin Wang , 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> <927b8efc-52ea-4f31-add5-62e721c32b90@linux.alibaba.com> From: David Hildenbrand Content-Language: en-US Autocrypt: addr=david@redhat.com; keydata= xsFNBFXLn5EBEAC+zYvAFJxCBY9Tr1xZgcESmxVNI/0ffzE/ZQOiHJl6mGkmA1R7/uUpiCjJ dBrn+lhhOYjjNefFQou6478faXE6o2AhmebqT4KiQoUQFV4R7y1KMEKoSyy8hQaK1umALTdL QZLQMzNE74ap+GDK0wnacPQFpcG1AE9RMq3aeErY5tujekBS32jfC/7AnH7I0v1v1TbbK3Gp XNeiN4QroO+5qaSr0ID2sz5jtBLRb15RMre27E1ImpaIv2Jw8NJgW0k/D1R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QJ3xajVH32Ms6t1trDQmPx2iP5+7iDsb7OKAb5eOS8h+BEBDeq 3ecsQDv0fFJOA9ag5O3LLNk+3x3q7e0uo06XMaY7UHS341ozXUUI7wC7iKfoUTv03iO9El5f XpNMx/YrIMduZ2+nd9Di7o5+KIwlb2mAB9sTNHdMrXesX8eBL6T9b+MZJk+mZuPxKNVfEQMQ a5SxUEADIPQTPNvBewdeI80yeOCrN+Zzwy/Mrx9EPeu59Y5vSJOx/z6OUImD/GhX7Xvkt3kq Er5KTrJz3++B6SH9pum9PuoE/k+nntJkNMmQpR4MCBaV/J9gIOPGodDKnjdng+mXliF3Ptu6 3oxc2RCyGzTlxyMwuc2U5Q7KtUNTdDe8T0uE+9b8BLMVQDDfJjqY0VVqSUwImzTDLX9S4g/8 kC4HRcclk8hpyhY2jKGluZO0awwTIMgVEzmTyBphDg/Gx7dZU1Xf8HFuE+UZ5UDHDTnwgv7E th6RC9+WrhDNspZ9fJjKWRbveQgUFCpe1sa77LAw+XFrKmBHXp9ZVIe90RMe2tRL06BGiRZr jPrnvUsUUsjRoRNJjKKA/REq+sAnhkNPPZ/NNMjaZ5b8Tovi8C0tmxiCHaQYqj7G2rgnT0kt WNyWQQ== Organization: Red Hat In-Reply-To: <927b8efc-52ea-4f31-add5-62e721c32b90@linux.alibaba.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 13.01.25 13:21, Baolin Wang wrote: > > > 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 > Thanks! > >> (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. Yes, I think as we free it, we'll put it automatically back to the freelist using enqueue_hugetlb_folio(). I suspect the temporary-active-although-not-active is no real problem. -- Cheers, David / dhildenb