Received: by 2002:ab2:620c:0:b0:1ef:ffd0:ce49 with SMTP id o12csp1616294lqt; Wed, 20 Mar 2024 09:03:14 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWrH8xIeUNyqPBCrRk6SuUmoz481qQpoXduKNwHYbDFba2BjJyu765Lywg/H8vMhd3MFsDD0Vvu9OttSA3pBn4RnpHFfrm1sI6xiauRXA== X-Google-Smtp-Source: AGHT+IE75l7FvsICel1tUGH+5GNo/OKgFMd6wEhMNvhJjugR4tWlBqcaugX3MonFocewY4OUtkR0 X-Received: by 2002:a05:6e02:1102:b0:366:46d1:ccc3 with SMTP id u2-20020a056e02110200b0036646d1ccc3mr6433200ilk.29.1710950594431; Wed, 20 Mar 2024 09:03:14 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710950594; cv=pass; d=google.com; s=arc-20160816; b=ZQF44IUz5px/80R236kbdIWUhMCWomK/f+UfNqvn09ztL2lmJBoU0q1ggIi6vExRe5 wgfU4r+1nssCqKBxz6K5hzMbkjhWbwvon5kVIwXEWiE5XL5okGfyMTGiC8L4G+d4Sz1v kf9+/ytD0YGloKh/gw/EYDO239iFaN7ctBEsXqExSy/5qgrHhRCyg7aax1isGq7xtF8L a9soCcv8iQP4bt1wvxdNZE9uqQOybzzm/5246BuqSA1f0D5sFxzbOpNRfn/RPvTnVTbU OW3dyPcsqegwe+YP510+oIp5ZPcTdvrzaaMoNBteUrShhKbjZ8TC3jDwyyxrvDprjlZB iL0g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=ml4jVPHJCd5/UtmiBCSa0uU8hAgWpRkM7OQMSO//QPw=; fh=9ZzXolrl6a1SqpUUCb15SbEk7085S9qfIgUIMxfISEc=; b=jzTJRZYNWjYkL7VLKtANU0TA/gUHpsldNJWVkMh6KrtgpRncx4fozIrkyStBWucXgj Ixd9ETaRb2w1LV0CF+tXij42g6Gz9JpgaVzDejSVF6TKeg4FgIh1apC9Xxs+FwrLHVZe VyKFWCJrYgEF4vokxOLs/wEED0KjGm7jK25yXP4fUY4j3l1/NIEGioKKMZqMEMXGFuX6 o65hIwVuOYAmyfzUne6+CFiOxrM6bbbAgQ/zpmk9CL3Xofiqmhad+lDF5F97yFg0aQAg hRjbVgRzGXQqMDYYBlY+//V0GdEki76pYBfy3y32Cv7bVL4FcudUnwh+tj0jieZqwlqN gL1g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=hdwhtcHV; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-109138-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-109138-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id g15-20020a056e02198f00b00365bcfcdc2csi5870637ilf.2.2024.03.20.09.03.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Mar 2024 09:03:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-109138-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=hdwhtcHV; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-109138-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-109138-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 18BDE2835C9 for ; Wed, 20 Mar 2024 16:03:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E31235466C; Wed, 20 Mar 2024 16:03:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="hdwhtcHV" Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (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 6C83123B0 for ; Wed, 20 Mar 2024 16:03:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710950586; cv=none; b=Yu9Dn5hW/bTOQcpZlt7dG1yZ8Y4F5EGYx7Muw5DNoTeUrzi/k8LauCG2wmp+K7EqelSYWyhFmMZ86cOucqDimJpzSheujW+H+2hdKP6GFgUVr5+T2sJ9ePnv7K9Py3AFtgwBQ5gmByB/vVuKAxcrViUyDHkRsYwY2fdSE+yOipU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710950586; c=relaxed/simple; bh=xNPkEPkfgiwAJOBWBG40pqctHi9CWeXTwkz2p5MGIZo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=P3I3dzrvJO7wNpUKnLeW+JHznLXg2jv3qQBL4pBM/zZoM5BA1WDQIEl4isxDR/RTMTWeUSY+Wt4NGEQEzNnOBx98FBl2LhXg9cXaIAeiWLqWeRfljQzcMCztAuhaVeHd4lQzqgcRNkXcFX98osvpXmyv2vKE4+IepyKJKJfApEE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=hdwhtcHV; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=ml4jVPHJCd5/UtmiBCSa0uU8hAgWpRkM7OQMSO//QPw=; b=hdwhtcHVAOejkXQy/AyeOX7Zwa PdFKdvvIW1Ufr9GkUMjCix7l0d1UFk4Y61Jdxz/vMrMHf6bcqt8eYN7lKGNEx8FrwgYsFGNkUveGu 7uudldc9YTIK+8k+m5HefHNVWy8fQJrPgZLTRA6a8a7GTwjl3aBmGIG4l6ugjJcrtdSZAxqFeM52a gXI4xyPZCw9Lkj1Yok2qxdBTyPrywZog9QP8y43gkl55ewAocO+v5RedA8ti08XPzXDJBNBl2WNs0 QTCfH8krpMK7aB9prrBKFWQRoLe8avTG5dgyHXkup74ZYrINIQAcUeE5u/aN+iO4yG0rd7NIWwl4U xXGK/uFA==; Received: from willy by casper.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1rmyOt-00000004e56-2Rq5; Wed, 20 Mar 2024 16:02:47 +0000 Date: Wed, 20 Mar 2024 16:02:47 +0000 From: Matthew Wilcox To: Zi Yan Cc: linux-mm@kvack.org, Andrew Morton , Yang Shi , Huang Ying , "Kirill A . Shutemov" , Ryan Roberts , Baolin Wang , "Yin, Fengwei" , SeongJae Park , linux-kernel@vger.kernel.org Subject: Re: [PATCH v4] mm/migrate: split source folio if it is on deferred split list Message-ID: References: <20240320014511.306128-1-zi.yan@sent.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240320014511.306128-1-zi.yan@sent.com> On Tue, Mar 19, 2024 at 09:45:11PM -0400, Zi Yan wrote: > +++ b/mm/migrate.c > @@ -1654,25 +1654,65 @@ static int migrate_pages_batch(struct list_head *from, > > /* > * Large folio migration might be unsupported or > - * the allocation might be failed so we should retry > - * on the same folio with the large folio split > + * the folio is on deferred split list so we should > + * retry on the same folio with the large folio split > * to normal folios. > * > * Split folios are put in split_folios, and > * we will migrate them after the rest of the > * list is processed. > */ > - if (!thp_migration_supported() && is_thp) { > - nr_failed++; > - stats->nr_thp_failed++; > - if (!try_split_folio(folio, split_folios)) { > - stats->nr_thp_split++; > - stats->nr_split++; > + if (is_thp) { > + bool is_on_deferred_list = false; > + > +#ifdef CONFIG_TRANSPARENT_HUGEPAGE > + /* > + * Check without taking split_queue_lock to > + * reduce locking overheads. The worst case is > + * that if the folio is put on the deferred > + * split list after the check, it will be > + * migrated and not put back on the list. > + * The migrated folio will not be split > + * via shrinker during memory pressure. > + */ > + if (!data_race(list_empty(&folio->_deferred_list))) { > + struct deferred_split *ds_queue; > + unsigned long flags; > + > + ds_queue = > + get_deferred_split_queue(folio); > + spin_lock_irqsave(&ds_queue->split_queue_lock, > + flags); > + /* > + * Only check if the folio is on > + * deferred split list without removing > + * it. Since the folio can be on > + * deferred_split_scan() local list and > + * removing it can cause the local list > + * corruption. Folio split process > + * below can handle it with the help of > + * folio_ref_freeze(). > + */ > + is_on_deferred_list = > + !list_empty(&folio->_deferred_list); > + spin_unlock_irqrestore(&ds_queue->split_queue_lock, > + flags); > + } > +#endif > + if (!thp_migration_supported() || > + is_on_deferred_list) { > + nr_failed++; > + stats->nr_thp_failed++; > + if (!try_split_folio(folio, > + split_folios)) { > + stats->nr_thp_split++; > + stats->nr_split++; > + continue; > + } > + stats->nr_failed_pages += nr_pages; > + list_move_tail(&folio->lru, ret_folios); > continue; > } > - stats->nr_failed_pages += nr_pages; > - list_move_tail(&folio->lru, ret_folios); > - continue; > } I don't think we need to try quite this hard. I don't think we need to take the lock to be certain if it's on the deferred list -- is there anything preventing the folio being added to the deferred list after we drop the lock? I also don't think we should account this as a thp split since those are treated by callers as failures. So maybe this? +++ b/mm/migrate.c @@ -1652,6 +1652,17 @@ static int migrate_pages_batch(struct list_head *from, cond_resched(); + /* + * The rare folio on the deferred split list should + * be split now. It should not count as a failure. + */ + if (nr_pages > 2 && + !list_empty(&folio->_deferred_list)) { + if (try_split_folio(folio, from) == 0) { + is_large = is_thp = false; + nr_pages = 1; + } + } /* * Large folio migration might be unsupported or * the allocation might be failed so we should retry