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 68DEDC5475B for ; Fri, 8 Mar 2024 15:33:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D6E4D8D000B; Fri, 8 Mar 2024 10:33:36 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D1E538D0002; Fri, 8 Mar 2024 10:33:36 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C0DA88D000B; Fri, 8 Mar 2024 10:33:36 -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 B21BE8D0002 for ; Fri, 8 Mar 2024 10:33:36 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 85E26807E8 for ; Fri, 8 Mar 2024 15:33:36 +0000 (UTC) X-FDA: 81874266432.22.532A188 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf17.hostedemail.com (Postfix) with ESMTP id 7398740013 for ; Fri, 8 Mar 2024 15:33:34 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=VPm7oqkC; spf=none (imf17.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709912014; a=rsa-sha256; cv=none; b=bZW0BOTkpN0bb+fl1BCV9y/K0YnCierBzRgpetiO+xOookKLGsUQjzhujIb4oLha4tnmXl 4JjYsPGKTPwwNO55PK/2ki1L8/PSSdFl3Aku5O6K7v7LkpvOvKGaoiqRDzC1L+Wzfs/bPd 0BSslhEQ6i+Bo8EixiMbykxIPaYt0pQ= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=VPm7oqkC; spf=none (imf17.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1709912014; 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=mEK3ZGe4lbLH8tMZGz/GWLZWHPbK0Ipnv+3589skWdg=; b=LpgR0LNERKNU4w4JAn1WhhlseTxuVVj/TwtUN9uSrPDLr89BENSxLZbtHeyUsHHeL7qdDz G/8VWTP3L5tAUvL0Lxa1kWBIknHEpG8P1xLJrdr7raU7d+KX+hVfv/2uf4Ba4Z0XseNb76 +6Z2AJuHzz+NOIQA11KSqDX8hmMJcYU= 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=mEK3ZGe4lbLH8tMZGz/GWLZWHPbK0Ipnv+3589skWdg=; b=VPm7oqkCuYsm/hfBEhPGqcJYWU M2Xk6BF/+qSMMo6DrhPAPAsXSoze7MaXF+SeCagfnQHG4ZZa1/whkY6mzQx98WXL/2hdl6sVHbEc8 QeC6a4JjTNJGEEZMkRYTWbIHYa8Ai++MFeRPjLUQ0qmF4iC4XO5du1upIXhgNciUZFM+9U9D/bB8N 68Jrs4bebtjfI0Gzi/pbT0AuVJag1+aIgWklvFo63ltA8q5YXiTk8bK263e5wPHAnSi3gw5KTFh4R RPSZpFetRoRuLTISJLH5aBqGp9CNDvYpjgW2e0l11TfnV5iuMjb9rkylwm3bZukXJIDpoMIeZtMGn QucAMD/w==; Received: from willy by casper.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1ricDy-0000000Bm6i-1mxV; Fri, 08 Mar 2024 15:33:30 +0000 Date: Fri, 8 Mar 2024 15:33:30 +0000 From: Matthew Wilcox To: Ryan Roberts Cc: Zi Yan , Andrew Morton , linux-mm@kvack.org, Yang Shi , Huang Ying Subject: Re: [PATCH v3 10/18] mm: Allow non-hugetlb large folios to be batch processed Message-ID: References: <85cc26ed-6386-4d6b-b680-1e5fba07843f@arm.com> <36bdda72-2731-440e-ad15-39b845401f50@arm.com> <03CE3A00-917C-48CC-8E1C-6A98713C817C@nvidia.com> <7415b36c-b5d3-4655-92e1-b303104bf4a9@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <7415b36c-b5d3-4655-92e1-b303104bf4a9@arm.com> X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 7398740013 X-Stat-Signature: ed98oac5kuzs8fzk5q6a77rj6gp6kzgi X-Rspam-User: X-HE-Tag: 1709912014-896024 X-HE-Meta: U2FsdGVkX1+I0rLKC2OpYZCPUTYq+/amxzxAXaJB1TTfDaoQK2gtUbNoMFwTaNvSjRS8HiswurQD0dK2KSe1ayi5JwlU8EiMop+EU4VnH0Xrg2zjLePtg6g/CfmRlnm0nsJuOQWY5PJ1hl4tY5SXTacnCOsqe2EKKZ4f0DhllgPihdYlrxJzZqtEoC+PXRq3FyaFgPLcxc78esgUpjbQs36k5Q4dynMsz7709LffMD8P5xuCYEumIm11Rxe3dujlsLL2Msxyf4jjWDRjEYtj8XYikebVl4pgBvdPy/FgP0RLe7OY0DIDSS3+ykvflhu/6KzvK9CD1jHzM1GfvzCKckSJ10othJ0mFbLY+5nXEAxNxQCPEOmsrYkLso3TfPgQ2cKVdv3dwNVQIYeBqStEoVOPPwTpoHQ7hPaajpfaOL1cGAwIj5icPl97eXwL0EjuX3AthcAVYxeWYWaR2Ex8KkMQrKKLH/GXW5AONyC64yGpB8SshEIL/54mEUqhHQ7+vx31l5Y280693AZ1UYDolTLuuFhARgSsNELoD9ueKr7YHjS9t3b5fdYCJ8K+XKrzbnhXeqr7cO1S+yXF/2Q1GarNOapOFMN548p8X/zsp5pTPmal5G3Dw37Ndkb5r1qG31WTqEWABXBiN+0jziC/9E2khr8FDO+1A7z+nck44AOj7qAiLQL+5ZQpWXMUUrIGAD0ntBkWzOTupARlJtfZbyb76G5evHFpdwAe8f+GaHtWZhImhBllD+WI77+u5hZi3KkNVs6odCGmpQXGRWs9vbQ2UQ5tXpbRX5wboxkVhK05Xrxp+TKu1aH3XGm1K5EwMrnI5PPGp7hwRa6JDxyG84JAz3Mib7LORxyZbJyEZh72xF7YXVL/4dElk1TexC5mK0A/kOMvZ6xuj8XgRl3kzoxZTvPVbOOuZ2tU3JD9UfurUvJZlLOttsTOJguIobAmNfGaN0+/kzCHVoY0BHd sS+7M8ot VFGxMlcWlMevGjCntRS9p0PyAsknYRID9wEiPxPtEUfSJkgulE76bFlj0JeojoSxZhK0PiHcPcTLWZy51dqWWvdnaVTseBwmPxsql2OkIiONdMPobPy2I/BJ+hfxrnhOi0wzkpIfJh5ZzvvkDuPY+udOSZnpkfoxxhO3k/Fc+v6vib4I= 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 Fri, Mar 08, 2024 at 12:09:38PM +0000, Ryan Roberts wrote: > On 08/03/2024 11:44, Ryan Roberts wrote: > > Dumping all the CPU back traces with gdb, all the cores (except one) are > > contending on the the deferred split lock. > > > > A couple of thoughts: > > > > - Since we are now taking a maximum of 15 folios into a batch, > > deferred_split_scan() is called much more often (in a tight loop from > > do_shrink_slab()). Could it be that we are just trying to take the lock so much > > more often now? I don't think it's quite that simple because we take the lock > > for every single folio when adding it to the queue, so the dequeing cost should > > still be a factor of 15 locks less. > > > > - do_shrink_slab() might be calling deferred_split_scan() in a tight loop with > > deferred_split_scan() returning 0 most of the time. If there are still folios on > > the deferred split list but deferred_split_scan() was unable to lock any folios > > then it will return 0, not SHRINK_STOP, so do_shrink_slab() will keep calling > > it, essentially live locking. Has your patch changed the duration of the folio > > being locked? I don't think so... > > > > - Ahh, perhaps its as simple as your fix has removed the code that removed the > > folio from the deferred split queue if it fails to get a reference? That could > > mean we end up returning 0 instead of SHRINK_STOP too. I'll have play. > > > > I tested the last idea by adding this back in: > > diff --git a/mm/huge_memory.c b/mm/huge_memory.c > index d46897d7ea7f..50b07362923a 100644 > --- a/mm/huge_memory.c > +++ b/mm/huge_memory.c > @@ -3327,8 +3327,12 @@ static unsigned long deferred_split_scan(struct shrinker > *shrink, > /* Take ref on all folios to avoid freeing them under us */ > list_for_each_entry_safe(folio, next, &ds_queue->split_queue, > _deferred_list) { > - if (!folio_try_get(folio)) > + if (!folio_try_get(folio)) { > + /* We lost race with folio_put() */ > + list_del_init(&folio->_deferred_list); > + ds_queue->split_queue_len--; > continue; > + } > if (folio_batch_add(&batch, folio) == 0) { > --sc->nr_to_scan; > break; > > The test now gets further than where it was previously getting live-locked, but If the deferred_split_lock contention comes back, we can fix split_huge_page_to_list() to only take the lock if the page is on the list. Right now, it takes it unconditionally which could be avoided. I'm not going to send a patch just yet to avoid confusion.