Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp2369891rdb; Mon, 12 Feb 2024 02:32:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IGZvMSt+cCpa8ffk9g5KMFibEuQyxnh74j3SXPMe2nvYa5vagu3LRmBOHCwBX5jn7DNjrqQ X-Received: by 2002:aa7:c3cf:0:b0:561:4020:1d4b with SMTP id l15-20020aa7c3cf000000b0056140201d4bmr4103000edr.42.1707733975015; Mon, 12 Feb 2024 02:32:55 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707733975; cv=pass; d=google.com; s=arc-20160816; b=t12W9WUu90gkgkolFMFYlwtmPusMeOKj38hK5W0dk8tFcqNqrFYE/Q2h2oMJ/U6zL6 0oxV8wNtWTNLPlMDuWuHxsJQAPOTgSIIGVFM6wCyPqOORehONYCN/mlYZ9QYDrdTAnHA UnYlH7+eQxAx0S75uFPor3BMs5x5mIxqrhjfzMZ2h3JZawF60+F1ibRca3uZIwnCDj/2 DiBEy5S1tdAvEcUZUw9IOs2+DG16UGI3llGpquMKazigiz10iG6PqkvAkJeavPsyUJZJ IPIzlPzYjwq+xGcJDoSIivuaXaeGrPVcE2q3adM6Wg02ee0PT6deekz6aJcp7TCp89yk EtLg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature :dkim-signature:dkim-signature:dkim-signature; bh=xEvukcfEXo+TJxamA0z62txjQmubKA5pKuuaq+G1gcE=; fh=rhn9V/HbctpFzvXMyOFPih60R/lGyb91OFCIkX5nZAk=; b=l7eA97dxz7OKA+if7ouEeHcjUi9fOh7u70U699uaFDejxbraOI7j9D84JePxNnA2Vi kH07vudO/PoC3N43IXPQ46erMMHnslo5YGQ9XdMrTjbesUS0T/QIOzMizvKlIO/cN0ue 9z+gJKcxwTLOLT0SxCGOicMstM1J2y82SPcOX8SGnGTYOKzlCJ+iDnmP9dv+K6KsNty2 Wm7Ck9Ci41wjEeiSZNtQJmHayCI1q7Zd/Ov0mcYZfj6cVYDaoy0gi3GrJTONcKESTR9w R0X0eCdBExQu0Attd4vokHq46JfWhAIekMcm+UYNmuGD5HPQusdgY8GYcA+DMhCa72mG 6/9w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=rvSUIlG3; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=bJ3WSxTo; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; arc=pass (i=1 spf=pass spfdomain=suse.cz dkim=pass dkdomain=suse.cz dkim=pass dkdomain=suse.cz); spf=pass (google.com: domain of linux-kernel+bounces-61317-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61317-linux.lists.archive=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=2; AJvYcCWWX0OCusVjv28rtbnMXtXve/5bNPhxcZF26fTiUVNeAvUQexD5UBlQ3eYLih2uJXqkvC3vgwWC6+lxVpb2Sk4mqhYyuCaPx+GD0rONdw== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id o8-20020aa7d3c8000000b00561b9400511si753126edr.307.2024.02.12.02.32.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 02:32:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-61317-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=rvSUIlG3; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=bJ3WSxTo; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; arc=pass (i=1 spf=pass spfdomain=suse.cz dkim=pass dkdomain=suse.cz dkim=pass dkdomain=suse.cz); spf=pass (google.com: domain of linux-kernel+bounces-61317-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61317-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 960DA1F214B4 for ; Mon, 12 Feb 2024 10:32:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1D91A2BAE7; Mon, 12 Feb 2024 10:32:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b="rvSUIlG3"; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b="gS0xYZ8n"; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b="bJ3WSxTo"; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b="aitiJqMK" Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 54DC428385 for ; Mon, 12 Feb 2024 10:32:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707733956; cv=none; b=okvA/jovW/fP2Z3bE/EqeXNQa/lz9aY4oKxwWOiYWP3280A+E7ulHLuhJfVCzFt3CqRWljQz2IRQa3Szaa8syNCniv+X2HheAtHRk5rHGgszSif32LdXD5E0hjF58PA+NB/ehc+wELbzN/tDpjVQnuxQ3sC9CcUTPk6VY7yzHCg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707733956; c=relaxed/simple; bh=ZL+iZTXbTE8pKIVyLeWG5D9ZrvCfW397REGv/VFxjtU=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=j4MYEQOldsRFVT3sMhBlLRSYOLbZ1UI4zmuq4hUuPrg5bSH4s571RI/Ws7OPWnA99FjxKEXLvf+9gKtR3GMSJpairxDt7QCNsZfuFpwgpub/+UUHNEG/kRTDGw3pLgn9zpiiNXOYCXwL4k1qw75eA9NSn2Kn0WxZxlbYcsRUab4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz; spf=pass smtp.mailfrom=suse.cz; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b=rvSUIlG3; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b=gS0xYZ8n; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b=bJ3WSxTo; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b=aitiJqMK; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.cz Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 9A3FF21F97; Mon, 12 Feb 2024 10:32:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1707733952; h=from:from:reply-to: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; bh=xEvukcfEXo+TJxamA0z62txjQmubKA5pKuuaq+G1gcE=; b=rvSUIlG3wHZ+3COtOGbqO+23go+XO6w3yhMJ+n/zeDPjJ3a8GPQMa9ORv4flGn5Y3443R+ 9E6dQJ5nqR/Tsyg6sKgnyw/WwEAszA/8wwq6eAlxFVSL+UoF/Amp+hHTZh8ahxdSS6NnDN yC6ndCQwTzNvDUuGTFGbs+uhtMMuEoo= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1707733952; h=from:from:reply-to: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; bh=xEvukcfEXo+TJxamA0z62txjQmubKA5pKuuaq+G1gcE=; b=gS0xYZ8nu4NnxKX23LSMEGS2YDbj9G+uPTKOzFEbShSEG21zAzGvD0mb39uLCxuzTPokZd Ps4VF5HExUHizHBA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1707733950; h=from:from:reply-to: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; bh=xEvukcfEXo+TJxamA0z62txjQmubKA5pKuuaq+G1gcE=; b=bJ3WSxTopjt6ssb4s+nb9jduq3Q+G2+W5DsPGN0cJFVf9m05dNVEvpZnZ6Sxjao6OnLf1c prcZzHw63KNYrngSDx7gphq22FDLy+ZqMZY9Rr6zNNurKcwXJV0D8xbwNLxATYOL94pw8R Ei6M/nb54mE6iskJYmy3wY/4/F0g32E= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1707733950; h=from:from:reply-to: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; bh=xEvukcfEXo+TJxamA0z62txjQmubKA5pKuuaq+G1gcE=; b=aitiJqMKKUrsvrkiDNzHvKT/QvhYUkSD7pXYx984PPeBi7fwYMS9rOR4o1aw7/V6GiPMy5 U2vPcQ4wTrmfNXBw== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 8838412FF7; Mon, 12 Feb 2024 10:32:30 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id EN7vIL7zyWU0FQAAD6G6ig (envelope-from ); Mon, 12 Feb 2024 10:32:30 +0000 Message-ID: <7f34e789-e01f-4929-a618-b73c04ebf4d2@suse.cz> Date: Mon, 12 Feb 2024 11:32:30 +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 2/2] mm: compaction: update the cc->nr_migratepages when allocating or freeing the freepages Content-Language: en-US To: Baolin Wang , akpm@linux-foundation.org, Zi Yan Cc: mgorman@techsingularity.net, linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <0773058df022fa701b78f9a6dfe3c501a1a77351.1705928395.git.baolin.wang@linux.alibaba.com> From: Vlastimil Babka In-Reply-To: <0773058df022fa701b78f9a6dfe3c501a1a77351.1705928395.git.baolin.wang@linux.alibaba.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Authentication-Results: smtp-out1.suse.de; none X-Spamd-Result: default: False [-0.09 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; XM_UA_NO_VERSION(0.01)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; RCPT_COUNT_FIVE(0.00)[6]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519]; DBL_BLOCKED_OPENRESOLVER(0.00)[alibaba.com:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; MID_RHS_MATCH_FROM(0.00)[] X-Spam-Level: X-Spam-Flag: NO X-Spam-Score: -0.09 On 1/22/24 14:01, Baolin Wang wrote: > Currently we will use 'cc->nr_freepages >= cc->nr_migratepages' comparison > to ensure that enough freepages are isolated in isolate_freepages(), however > it just decreases the cc->nr_freepages without updating cc->nr_migratepages > in compaction_alloc(), which will waste more CPU cycles and cause too many > freepages to be isolated. Hm yeah I guess this can happen with fast_isolate_freepages() if it returns with something but not all the freepages that are expected to be needed, and then we get to isolate_freepages() again. > So we should also update the cc->nr_migratepages when allocating or freeing > the freepages to avoid isolating excess freepages. And I can see fewer free > pages are scanned and isolated when running thpcompact on my Arm64 server: > k6.7 k6.7_patched > Ops Compaction pages isolated 120692036.00 118160797.00 > Ops Compaction migrate scanned 131210329.00 154093268.00 > Ops Compaction free scanned 1090587971.00 1080632536.00 > Ops Compact scan efficiency 12.03 14.26 > > Moreover, I did not see an obvious latency improvements, this is likely because > isolating freepages is not the bottleneck in the thpcompact test case. > k6.7 k6.7_patched > Amean fault-both-1 1089.76 ( 0.00%) 1080.16 * 0.88%* > Amean fault-both-3 1616.48 ( 0.00%) 1636.65 * -1.25%* > Amean fault-both-5 2266.66 ( 0.00%) 2219.20 * 2.09%* > Amean fault-both-7 2909.84 ( 0.00%) 2801.90 * 3.71%* > Amean fault-both-12 4861.26 ( 0.00%) 4733.25 * 2.63%* > Amean fault-both-18 7351.11 ( 0.00%) 6950.51 * 5.45%* > Amean fault-both-24 9059.30 ( 0.00%) 9159.99 * -1.11%* > Amean fault-both-30 10685.68 ( 0.00%) 11399.02 * -6.68%* > > Signed-off-by: Baolin Wang > --- > mm/compaction.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/mm/compaction.c b/mm/compaction.c > index 066b72b3471a..6c84e3a5b32b 100644 > --- a/mm/compaction.c > +++ b/mm/compaction.c > @@ -1779,6 +1779,7 @@ static struct folio *compaction_alloc(struct folio *src, unsigned long data) > dst = list_entry(cc->freepages.next, struct folio, lru); > list_del(&dst->lru); > cc->nr_freepages--; > + cc->nr_migratepages--; This is breaking the tracepoint TRACE_EVENT(mm_compaction_migratepages) which does __entry->nr_failed = cc->nr_migratepages - nr_succeeded; and is called after migrate_pages() finishes, so now this will underflow. Probably need to get a snapshot of cc->nr_migratepages before calling migrate_pages() and then feed that to the tracepoint instead of cc. > > return dst; > } > @@ -1794,6 +1795,7 @@ static void compaction_free(struct folio *dst, unsigned long data) > > list_add(&dst->lru, &cc->freepages); > cc->nr_freepages++; > + cc->nr_migratepages++; > } > > /* possible outcome of isolate_migratepages */