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 D0485C48BC4 for ; Mon, 19 Feb 2024 02:56:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3D4436B0088; Sun, 18 Feb 2024 21:56:08 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 35D1C6B0089; Sun, 18 Feb 2024 21:56:08 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1FDB86B008A; Sun, 18 Feb 2024 21:56:08 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 0A3D76B0088 for ; Sun, 18 Feb 2024 21:56:08 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 9DD9AC01D6 for ; Mon, 19 Feb 2024 02:56:07 +0000 (UTC) X-FDA: 81807039174.22.9D67D27 Received: from out30-119.freemail.mail.aliyun.com (out30-119.freemail.mail.aliyun.com [115.124.30.119]) by imf29.hostedemail.com (Postfix) with ESMTP id 35571120008 for ; Mon, 19 Feb 2024 02:56:03 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=tdd7OXHk; dmarc=pass (policy=none) header.from=linux.alibaba.com; spf=pass (imf29.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.119 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708311365; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=yQrlVUbCNycovOpvidI2cU4GO80wwX6nTyqP1bcvxIc=; b=XKm82Fpcp+mZOSzlJK5mDPTNtq9/d9gMxCRNJo585WyEOwgGmLkHdnoSNjqPIuv2gYaJnA e9Olr/BGd45N0mlZzmdg0fAt/6+IFILYojsYQGrpRu5C3vM3njDqLa32FrQ+CtzICv0seP spkA+yBz87oNT0LXmJVEWE5YfqsiW6E= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=tdd7OXHk; dmarc=pass (policy=none) header.from=linux.alibaba.com; spf=pass (imf29.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.119 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708311365; a=rsa-sha256; cv=none; b=GmPeZRMbLMpbOynAz4a0KVwFfj8ta7VknxuFY3FOGbVrxDZHsW6UZbidp3J8Zjs0xu0fpQ f32ZBx7iAZQe6SFfdhG2DTnFFHGn6k6sZKqnlAX95mtBggWMvB7u7Gh7pbrDE4/Xw0/Qme MqveQ2FgVzY4pIGXUZkwEICz/4SMxsY= DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1708311361; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=yQrlVUbCNycovOpvidI2cU4GO80wwX6nTyqP1bcvxIc=; b=tdd7OXHkApaxaC3pqeqoLoz/r76MzWKycPB6ghbRn2zgxFUN0MURkhZhVo7tls9L+J80+rJnkQRDm7sVwNJ+uQgAD5P10REufEhjJ8D4r2Vk85p0oi8trb+ApxOvt6AihnRZCDXXnV0sR54Z8xLMUqdFG78orQ9X/aSqkTjdX6k= 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 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 X-Rspamd-Queue-Id: 35571120008 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: y6scitq8ruatim5364ff3h71ehg1psck X-HE-Tag: 1708311363-491898 X-HE-Meta: U2FsdGVkX18WT73nW5MuXE/ZqqcBL4M07xNyGtCCyOLZ2b371afCCk92HjyoEMRAl0CLMpKJnbD1fa4nzM8UjNUrAEkc3Z2/b2VLR4iNJXeFSAiYLx/ppeusH35q680aV1tpZvLKl7JIuOxujdZYI/A/SIDevzaQcPgZhFKUesF23mHm5fke8H+hTNzJfiLeQG0lYnplYojqulm2LtL0s2vlsKrVHObUoxrI+NEforeVXC9ALRwNxDFEXFjeF+iPWsjMCSvZq/KMdQ4Ad5AVeaXf/qIjAjU1b6ELUpZE2Qnq8XV1tcI00R0U26oCx/KrLTQS5b1WVq3ZpI36s9QKGiRX5CgEJcXfusCxKbCZendJE3M7uqGKtir65O9XGpFq2MQvmkFPm8GnHT7pfNaOV9GjHy7VhKnUEL394rpej5Qayt9EnE1WahiFVpNS/Dc+HfkVvFqCvGjdJU+D+2iT6wJuK+IfN1VbaAxF8CUVqqjV6XkobrbPQaR7+6caO8y+75U1fsnHHoCveRDoM+ECjZ0TLYOouSRqCre5AnJf3+lDiwkcuwNnKCmr/C1XdCqPDTe8jcCpshOKlPBTV1zRuLpIZSfhV1qkqcaYmgYo9y76XOZxAGViul939qfGXdbqUxoH/YPPtUajX+r7eXYSGxqPRwlgPUu6nrxSj27J/8JZKwuC/sPfLf9WG6pDL7VVMnhCVmdPZWiCNo7KEIToq8IGwkkTPAEb8Kob+wDiwdu4n2hbKkxrqBZxVkMwYBGmXIZalCd6Ko+7mvMQXj2wrZCRwQcXQ6DKUuyENTIB2sCXhycezoA09LFBpYHRCGajQKPlVWLUYdQJVau4I4ARninBvr9SXGaTfiBIJtHhcLPtIY85nJE6C59oevbzytfH1sZALSph4nJUnMX8mrdgut/EVgFKCibmyw6D7HFro4yv2hBOd205bDKsrvibedSQ8SGja681nBuGTEJAzEr OrmaRitQ aVj9EFr5pesPwfN88l6E5ZaKe6th0uX8iXsYIRXmAPc2+JXTKdO23ACh+CFlkH42zArm63EoGgEz2wbl9KqlooPbU+NNQGREXjH/KwE0yEajxESUW2/hkMlDxfYLBmcF4igCHbYBu5ZajwfUoJnL15ahcnuv+AydC7GD4qdUv8Vqz+0bTt/6iLbvJwh+NDVY/8AsnD1rholEIwx6a6wMBkq8WQ0kA8Ba9myEqsABUXrKyoB4= 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 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