Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp937610rdb; Fri, 2 Feb 2024 08:24:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IFqlPg2ju0TfQlAmMXG+MMy7h+x3NE3eB+pTQ34NVJ+b0G3aPDPzAsq9xCgoOczRGV3hilN X-Received: by 2002:a17:90a:db8d:b0:296:4177:6404 with SMTP id h13-20020a17090adb8d00b0029641776404mr1951362pjv.11.1706891059427; Fri, 02 Feb 2024 08:24:19 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706891059; cv=pass; d=google.com; s=arc-20160816; b=yW7XTaw8bQRtMusYSidErgl8EOZo2smQJTdbCTZocnuFbYWEiGtOh8KtvibkOP41fj BRmr3H+FTQdwkacCkjbH7VXnbSiblP/vgz5u11jcc9V1SJhkOmS/DJ947zrXr7B9jYL2 wGboJK7Q7rBjRuf5xD+FICoWptCWPwA149mRBP0c6+AnyKp5BwTdjz7DJnHA6Yt0a5D0 XXIS6BJoHF0IVS/6rRLnihLXuxPRcFMODiyqTOg9X9vtPVzZ83y+GnCe2ZZrQ8g8J5jF e02PjFetnPwrIrOYuDh7kmxD5tkgxQM8uS0zlEDZoIr7OGYuCnFgQ8vpbxqxiaxWtSgM +okg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:reply-to:references:in-reply-to :message-id:date:subject:cc:to:from:feedback-id:dkim-signature :dkim-signature; bh=b0LGZXB2atC7cRDxeVKB29tfMJXHfhbupvuqzgL5H0w=; fh=4404S3yF3QaJHT5FCO8PivmAL787qtq2I8tx/4Q1BPU=; b=Lu6+ENoorv1Z5x3SkgLjGIwAt/8dRO7PWebDJbNOSMpJm1eKTMO3+ysgfBvkrtM7xm IpEr6qDXTSDjLtpAB/ffH+Ym1A8aauhvjKbANQT1c/wDeh1ruNvvf25hTN6MCGl7OFgt gTd06sUmQfeNAWbBZNJLwFP3Lo6LiyNGGHX7rk7lrn7AtP658n8j9UcwWYWX706wSfxf 4o4pNJNzUxmoMNOb3ky5sBj6L5eP4tUpvQUmqzIG4FOJ+GCMHQbfSD4h4sHrF6zendIt c8D3bwf2wcWaidO+i5k99aoFEdLcNwttfEIhthtkM5+ingVapfVEBlyzhB1aiUfDRQYu CDRA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@sent.com header.s=fm3 header.b=w9AwuLYZ; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=jITQjR9f; arc=pass (i=1 spf=pass spfdomain=sent.com dkim=pass dkdomain=sent.com dkim=pass dkdomain=messagingengine.com dmarc=pass fromdomain=sent.com); spf=pass (google.com: domain of linux-kernel+bounces-50118-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50118-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sent.com X-Forwarded-Encrypted: i=1; AJvYcCUsllWA8jp961Zk8w+vxBigZCygxsONDGkMtwqnTDzBVirmvWZIf3/6jJ06jVlhnoPcOy9eD8NnHOZ8AXbhBOETB41e+3t/4kxmp+r9hA== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id kb4-20020a17090ae7c400b002964f60e7d0si162368pjb.121.2024.02.02.08.24.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 08:24:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-50118-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=@sent.com header.s=fm3 header.b=w9AwuLYZ; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=jITQjR9f; arc=pass (i=1 spf=pass spfdomain=sent.com dkim=pass dkdomain=sent.com dkim=pass dkdomain=messagingengine.com dmarc=pass fromdomain=sent.com); spf=pass (google.com: domain of linux-kernel+bounces-50118-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50118-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sent.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 sv.mirrors.kernel.org (Postfix) with ESMTPS id E79A9296C91 for ; Fri, 2 Feb 2024 16:16:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E87E71474D4; Fri, 2 Feb 2024 16:16:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sent.com header.i=@sent.com header.b="w9AwuLYZ"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="jITQjR9f" Received: from out2-smtp.messagingengine.com (out2-smtp.messagingengine.com [66.111.4.26]) (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 BEC4B14198F for ; Fri, 2 Feb 2024 16:16:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=66.111.4.26 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706890579; cv=none; b=TTa9twik41BK5bT6TtsJZsP7UN59yqUkOCMR0jak0vNPckXwYBaFytda6dRKo5xZ//F6tcT/pLrvvEMa1AwLiFtP2P5pq4cMPEjSQtGLglTMKYoS+ad0XhWfs1o9PkhrMo14Z8OffyM52DOURI2pI7nYgJCA+M+000VBsPvOC/U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706890579; c=relaxed/simple; bh=CHBuBJuhamNrP6U0fj4Mt2MwBKcPu0swmlgl3BSB8TE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=hcIG0Gr5CjCPh4r/9O/Yg2uPKRrouwyeOZJfefEWTQ9vmUEJrW9yhiMGHHo9b1ERP8qLl6/nqVKbSz+wNWFTRDBZFno0MSsQJPnF3JjClUTYrN6vGC7iSoQUVUErKk1ZrAgpej9nEFMoUR3FbbN5OvDpdUfL1Bu68wEilaEPD6Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sent.com; spf=pass smtp.mailfrom=sent.com; dkim=pass (2048-bit key) header.d=sent.com header.i=@sent.com header.b=w9AwuLYZ; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=jITQjR9f; arc=none smtp.client-ip=66.111.4.26 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sent.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sent.com Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id BE2FD5C0080; Fri, 2 Feb 2024 11:16:16 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Fri, 02 Feb 2024 11:16:16 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sent.com; h=cc :cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:reply-to:subject:subject:to:to; s=fm3; t= 1706890576; x=1706976976; bh=b0LGZXB2atC7cRDxeVKB29tfMJXHfhbupvu qzgL5H0w=; b=w9AwuLYZjR/BP+cqnv3LMOCFQHBsCSwi895LQemcBc+Vo5ZToOt HCHtnMIu+rwnyKxCfClEPDT0/5F+CkwVbcGInCTjWeCWmRjStV7xls7XKOArtfsI w5V3vmmkw+KiHx2VdkyMZ0QacA6O+hqiEA/i4E9XOJ9z+Q/x3xQMDQ8arvA/lk0g BqHpu1wNeN9kn2L6C96cJ1thlhPyVv97m93rRRo8gewh7pXpNJHfVbnhc94d+/OT 8eny1dAyhp8oVMCHXdhdF/yxvyNKMP/6aOC8MZKzfU4jhN/6nuOWJw7hUSqswAT0 if8thmyelZ6EE/eBsHrgVEmiLME2G476qSA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:reply-to:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1706890576; x=1706976976; bh=b0LGZXB2atC7cRDxeVKB29tfMJXHfhbupvu qzgL5H0w=; b=jITQjR9fZ4vUH7jpIKUSGUf69CmGaNlTyKWC7zCok4dJZu5NM+M tfqbsksM2p0nTWynjXbTfU3uIPh+tzf0SEH3sdEbK6yLqYCUcsSri81slnPWg0Vl +tv7SmGQ6GXwLg/uEogMGAdWcRQ2uUpLFNRY5TeNJYaKuyqHrI9LDFZyoAHDTJrv laJlFvAREQb49Osr7ozT8+HHU7Do0nEFj3n2Ks80KnGAxDm5blkXMdpNaQpb5tkl znMVFC71CcxwrGQpSwLwE8Et4YppV1zGIp7VMnNW8+rHy1e+kLti4NGDKwzC/JLD oTrbPSupWq5z6Db9SfEWk+3EevvpLfpHAYw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrfedugedgkeehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgjfhhrgggtgfesthekredtredtjeenucfhrhhomhepkghi ucgjrghnuceoiihirdihrghnsehsvghnthdrtghomheqnecuggftrfgrthhtvghrnhepje ekteekffelleekudfftdefvddtjeejuedtuedtteegjefgvedtfedujeekieevnecuvehl uhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepiihirdihrghnse hsvghnthdrtghomh X-ME-Proxy: Feedback-ID: iccd040f4:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 2 Feb 2024 11:16:15 -0500 (EST) From: Zi Yan To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Zi Yan , "Huang, Ying" , Ryan Roberts , Andrew Morton , "Matthew Wilcox (Oracle)" , David Hildenbrand , "Yin, Fengwei" , Yu Zhao , Vlastimil Babka , "Kirill A . Shutemov" , Johannes Weiner , Baolin Wang , Kemeng Shi , Mel Gorman , Rohan Puri , Mcgrof Chamberlain , Adam Manzanares , "Vishal Moola (Oracle)" Subject: [PATCH v3 1/3] mm/compaction: enable compacting >0 order folios. Date: Fri, 2 Feb 2024 11:15:52 -0500 Message-ID: <20240202161554.565023-2-zi.yan@sent.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240202161554.565023-1-zi.yan@sent.com> References: <20240202161554.565023-1-zi.yan@sent.com> Reply-To: Zi Yan 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="utf-8" Content-Transfer-Encoding: 8bit From: Zi Yan migrate_pages() supports >0 order folio migration and during compaction, even if compaction_alloc() cannot provide >0 order free pages, migrate_pages() can split the source page and try to migrate the base pages from the split. It can be a baseline and start point for adding support for compacting >0 order folios. Suggested-by: Huang Ying Signed-off-by: Zi Yan --- mm/compaction.c | 43 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/mm/compaction.c b/mm/compaction.c index 4add68d40e8d..e43e898d2c77 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -816,6 +816,21 @@ static bool too_many_isolated(struct compact_control *cc) return too_many; } +/* + * 1. if the page order is larger than or equal to target_order (i.e., + * cc->order and when it is not -1 for global compaction), skip it since + * target_order already indicates no free page with larger than target_order + * exists and later migrating it will most likely fail; + * + * 2. compacting > pageblock_order pages does not improve memory fragmentation, + * skip them; + */ +static bool skip_isolation_on_order(int order, int target_order) +{ + return (target_order != -1 && order >= target_order) || + order >= pageblock_order; +} + /** * isolate_migratepages_block() - isolate all migrate-able pages within * a single pageblock @@ -1010,7 +1025,7 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, /* * Regardless of being on LRU, compound pages such as THP and * hugetlbfs are not to be compacted unless we are attempting - * an allocation much larger than the huge page size (eg CMA). + * an allocation larger than the compound page size. * We can potentially save a lot of iterations if we skip them * at once. The check is racy, but we can consider only valid * values and the only danger is skipping too much. @@ -1018,11 +1033,18 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, if (PageCompound(page) && !cc->alloc_contig) { const unsigned int order = compound_order(page); - if (likely(order <= MAX_PAGE_ORDER)) { - low_pfn += (1UL << order) - 1; - nr_scanned += (1UL << order) - 1; + /* + * Skip based on page order and compaction target order + * and skip hugetlbfs pages. + */ + if (skip_isolation_on_order(order, cc->order) || + PageHuge(page)) { + if (order <= MAX_PAGE_ORDER) { + low_pfn += (1UL << order) - 1; + nr_scanned += (1UL << order) - 1; + } + goto isolate_fail; } - goto isolate_fail; } /* @@ -1165,10 +1187,11 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, } /* - * folio become large since the non-locked check, - * and it's on LRU. + * Check LRU folio order under the lock */ - if (unlikely(folio_test_large(folio) && !cc->alloc_contig)) { + if (unlikely(skip_isolation_on_order(folio_order(folio), + cc->order) && + !cc->alloc_contig)) { low_pfn += folio_nr_pages(folio) - 1; nr_scanned += folio_nr_pages(folio) - 1; folio_set_lru(folio); @@ -1786,6 +1809,10 @@ static struct folio *compaction_alloc(struct folio *src, unsigned long data) struct compact_control *cc = (struct compact_control *)data; struct folio *dst; + /* this makes migrate_pages() split the source page and retry */ + if (folio_test_large(src) > 0) + return NULL; + if (list_empty(&cc->freepages)) { isolate_freepages(cc); -- 2.43.0