Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp906304rdb; Sun, 18 Feb 2024 18:56:11 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUl4dLanJrqamwnVaA1yvutvez6bFqy847VjUCMcVi0VaCmSLWaUmIB//DrJt+7UdqYgMBnZB1rgAHSlUj+NqNSKbGNeDWau3ZluZwAJg== X-Google-Smtp-Source: AGHT+IEZP+TULxQhH5qc/FvAUg1QIY/zxAYuQ4HiEhflAbtZqadw4aWTiFp5d6xdAQP3nCCxwowu X-Received: by 2002:a05:622a:13d1:b0:42d:e87a:9645 with SMTP id p17-20020a05622a13d100b0042de87a9645mr8241140qtk.47.1708311371170; Sun, 18 Feb 2024 18:56:11 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708311371; cv=pass; d=google.com; s=arc-20160816; b=eAge1dtqHtp/VAliTMBRNLi49fuG8/rLbcKy6eJFWS34hksg3+Kk1/rOGs9Qyo7q69 8oPcFlpAKqAr0b4AQMU/lJxdtZUdIk5w3Jl4/XAJQx9D6xENDrVw7bdIq57OCZo0eNCl +SSO4YcBeiPxmf6A8Sl2+zoX46JuaHBS9N19eVkKoRZA6eL4J41fx7DqHBZCy5UQhdC2 HMXO571DGPFxNvhRgPtwvsjDMnnKTumnD+dH4HAFuMey17C099elj0fs7BE1q3V4L7NE uo36yi3BuotuJmdECsATkSXMRadxtc3fRykDKE13gh19t+JLeyZXblqiAfkC79UiynsE EhaQ== 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:subject :user-agent:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:date:message-id:dkim-signature; bh=yQrlVUbCNycovOpvidI2cU4GO80wwX6nTyqP1bcvxIc=; fh=olsDqbN+K2ozpGuXR1ZiIYPbeGlcJN8nYQv+yuVeCr0=; b=HGXpBlXPd3+uu5MFHU458siK3OFRTs7JL+5WX103LUvTTSr4bSuPWjyFmr4oEK/62Q mmdysbjacxHmFgX4hZ2s6GTpQSB8SYxxDCjAyZ4GRDYkuqkM/euoWHQtclsJz67ziYbJ lEem95Y4hPevhy5G/TdrWyuRilO+rNt8J1TMc0rR8/mzSDCHtm1LcumVb8PnaEpS6TbO /KzzFfODeVor0w0JQtyl5IAXpFfyFd/pVlavWLJ2YPxYOYqDIp6iDU+dXu3EsBn61QRt v939vsDVDsUVCdyXiLq0SWZBbR/nJ0ySxIyLt8PYVnDHT2vNrGFHhXswMNcSuGrD2NPw 5ZKA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.alibaba.com header.s=default header.b="mA8/dNu+"; arc=pass (i=1 spf=pass spfdomain=linux.alibaba.com dkim=pass dkdomain=linux.alibaba.com dmarc=pass fromdomain=linux.alibaba.com); spf=pass (google.com: domain of linux-kernel+bounces-70665-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70665-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.alibaba.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id a2-20020a05620a02e200b00787303e45d9si5430217qko.376.2024.02.18.18.56.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Feb 2024 18:56:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-70665-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.alibaba.com header.s=default header.b="mA8/dNu+"; arc=pass (i=1 spf=pass spfdomain=linux.alibaba.com dkim=pass dkdomain=linux.alibaba.com dmarc=pass fromdomain=linux.alibaba.com); spf=pass (google.com: domain of linux-kernel+bounces-70665-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70665-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.alibaba.com 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id E8B5A1C2105D for ; Mon, 19 Feb 2024 02:56:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 48E7023BD; Mon, 19 Feb 2024 02:56:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="mA8/dNu+" Received: from out30-130.freemail.mail.aliyun.com (out30-130.freemail.mail.aliyun.com [115.124.30.130]) (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 DDD611FC8 for ; Mon, 19 Feb 2024 02:56:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.130 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708311365; cv=none; b=B1wvf3iGqjmjRYZ5JNwUm/VHNTQXoIBx8bzJHe8/nlk2Zz80wwimuUd3P+1kY+NhwDT7Lf/FK9pFsQePEPUd6vH6Zd8NyJcGAWpe6DCc73jbmJTR4bfHPo0SEB7dqgGjfZ9jWhdX71oBSW7uux5ogIU9cX2Jx7hwLISK2HYrBUA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708311365; c=relaxed/simple; bh=9I3/khzFwIbdzXjPtuKVOdiJu0VzmQlOsKemxYS09TE=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=jz6U0X/BdO12knZBT5mix85ScoWCjji3IlyUqOT7TBeN0aNvhI0nJhCW8o/Olc/wjgc8RURJq3pyhWlB5D5Luc+FXoy+9CahAf9Qb6bxc9+WDOqhaNOujUmBHxYZg6TKqG6F1fC1Ixe/XKBd7cUVMmZE+Euls+lr2IyUX+fyzYw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=mA8/dNu+; arc=none smtp.client-ip=115.124.30.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1708311360; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=yQrlVUbCNycovOpvidI2cU4GO80wwX6nTyqP1bcvxIc=; b=mA8/dNu+PbaXczsmCXl1lKeRVO5+gN6ORC0Cs1wz4PURyYKrBTtrRzGZvzh9VsLBNQqf24X/m39ePItXdBJMPmvMz2TMYFkD3L0D9nm4+y+E7qI/SXGm1N1VNAVqI7hy4J86DgSzxthWwtmVA+llH34zEkJqJan0/FQuuF3zExU= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R181e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046050;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0W0mvt6V_1708311359; Received: from 30.97.56.48(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0W0mvt6V_1708311359) by smtp.aliyun-inc.com; Mon, 19 Feb 2024 10:56:00 +0800 Message-ID: <83bc1070-2eb4-4fac-aecf-9cc407003ca2@linux.alibaba.com> Date: Mon, 19 Feb 2024 10:55:59 +0800 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 1/2] mm: compaction: limit the suitable target page order to be less than cc->order To: Zi Yan , Vlastimil Babka Cc: akpm@linux-foundation.org, mgorman@techsingularity.net, linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20c8fa7c-62ae-4e48-aaec-8b512519cee9@suse.cz> <5277627F-6791-46A1-AFC2-54FBF0DABF1A@nvidia.com> From: Baolin Wang In-Reply-To: <5277627F-6791-46A1-AFC2-54FBF0DABF1A@nvidia.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 2024/2/12 23:00, Zi Yan wrote: > On 12 Feb 2024, at 4:13, Vlastimil Babka wrote: > >> On 1/22/24 14:01, Baolin Wang wrote: >>> It can not improve the fragmentation if we isolate the target free pages >>> exceeding cc->order, especially when the cc->order is less than pageblock_order. >>> For example, suppose the pageblock_order is MAX_ORDER (size is 4M) and cc->order >>> is 2M THP size, we should not isolate other 2M free pages to be the migration >>> target, which can not improve the fragmentation. >>> >>> Moreover this is also applicable for large folio compaction. >> >> So why not Cc: Zi Yan? (done) >> > > Thanks. > > Hi Baolin, > > How often do you see this happening? This is theoretically analyzed from the code inspection. >>> Signed-off-by: Baolin Wang >> >> I doubt this will make much difference, because if such a larger order free >> page exists, we shouldn't have a reason to be compacting for a lower order >> in the first place? > > Unless kswapd gets us such a free block in the background right after > get_page_from_freelist() and before compaction finishes in the allocation > slow path. > > If this happens often and cc->order is not -1, it might be better to stop > compaction and get_page_from_freelist() to save cycles on unnecessary pfn > scanning. For completeness, when cc->order == -1, the logic does not change. Yes, this is one possible case. There are also some other concurrent scenarios, such as when compaction is running (after compaction_suitable()), at the same time, other applications release a large folio to the free list. In this case, the free large folio scanning should also be avoided. >>> --- >>> mm/compaction.c | 4 +++- >>> 1 file changed, 3 insertions(+), 1 deletion(-) >>> >>> diff --git a/mm/compaction.c b/mm/compaction.c >>> index 27ada42924d5..066b72b3471a 100644 >>> --- a/mm/compaction.c >>> +++ b/mm/compaction.c >>> @@ -1346,12 +1346,14 @@ static bool suitable_migration_target(struct compact_control *cc, >>> { >>> /* If the page is a large free page, then disallow migration */ >>> if (PageBuddy(page)) { >>> + int order = cc->order > 0 ? cc->order : pageblock_order; >>> + >>> /* >>> * We are checking page_order without zone->lock taken. But >>> * the only small danger is that we skip a potentially suitable >>> * pageblock, so it's not worth to check order for valid range. >>> */ >>> - if (buddy_order_unsafe(page) >= pageblock_order) >>> + if (buddy_order_unsafe(page) >= order) >>> return false; >>> } >>> > > > -- > Best Regards, > Yan, Zi