From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from m16.mail.126.com (m16.mail.126.com [117.135.210.8]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 53A87248167 for ; Wed, 15 Jan 2025 09:18:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=117.135.210.8 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736932706; cv=none; b=VpVjU+2zRdr0c+h6BpiG6x4USYHoFKLjOYyAOJZT4O6+h3SFQP+GgvqmTyWr6qhJ/cSEh0/Vux5gmBUInSQEUJgxhuUKFM7UpD6sUC7gQWF8655jWorNLjCgOGnFPsFgzJsSwo5nHcknfyxoQtQQ4/T9fXHTcvjZ4iaEVALKsms= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736932706; c=relaxed/simple; bh=Rb5Ff1xhqI3zHavbMCsV+WLsFu17G4uucZLRN34i17U=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=hVlFycoPsPIGLhRLCMsmN1HP1uYC+YGnOOzjr4RoD2T47IVhNm+SmYx1tRwGrc5UPseGgCwWIU58gPNE4mSsMUWq628zj0bkdyU6zAIT0pieCM+GbhM1R+sFE6Pq2DcQeBYGRFgMwwjkUgH+pMft0PBQnmelFV9rchgqpziV3BI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=126.com; spf=pass smtp.mailfrom=126.com; dkim=pass (1024-bit key) header.d=126.com header.i=@126.com header.b=QE3iCI5C; arc=none smtp.client-ip=117.135.210.8 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=126.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=126.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=126.com header.i=@126.com header.b="QE3iCI5C" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=126.com; s=s110527; h=Message-ID:Date:MIME-Version:Subject:From: Content-Type; bh=pq/5bG1rfrNfQiX1eubItDMA9TfIiO6JY4M8DEI/q1k=; b=QE3iCI5CmzBJr3NdCVHi1sWYmQGC5eZjXkSNV7kS1Qe3GIytdgt/KIG8GxoM67 ThF8SSJTsSLYU0S0C4Rn2+1o9EWcCy6XL+UNRIiJGrzQiHotBMeHHA8fxNDa6B6j EeKnUUrizp6yPN3yxcdRZg3BtUpwXUDnnRmIFuSuRRJlo= Received: from [172.19.20.199] (unknown []) by gzga-smtp-mtada-g0-0 (Coremail) with SMTP id _____wB31P0+fYdn0+MaBA--.26710S2; Wed, 15 Jan 2025 17:17:50 +0800 (CST) Message-ID: <0347ff02-eac4-4fa5-88c3-6d12988438d1@126.com> Date: Wed, 15 Jan 2025 17:17:50 +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 V3] mm: compaction: skip memory compaction when there are not enough migratable pages To: Vlastimil Babka , akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, 21cnbao@gmail.com, david@redhat.com, baolin.wang@linux.alibaba.com, hannes@cmpxchg.org, liuzixing@hygon.cn References: <1736335854-548-1-git-send-email-yangge1116@126.com> <39709cd7-0de6-4247-a70a-9f81fccbce6a@suse.cz> <1ada3f6d-72bb-46a4-9fef-0bf6a7b32e62@suse.cz> From: Ge Yang In-Reply-To: <1ada3f6d-72bb-46a4-9fef-0bf6a7b32e62@suse.cz> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-CM-TRANSID:_____wB31P0+fYdn0+MaBA--.26710S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxCrW3AF1kCr4DJrWUKF4xCrg_yoW5GF4Dpa yUWFsF9FZ5XF43Aw1vyw4vgF1Ykw4xGryUJrnaqryDuwsI9FyI9FWIyFWUCayUXr4ftFWj vFW0gFy7AFsIva7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jbPEfUUUUU= X-CM-SenderInfo: 51dqwwjhrrila6rslhhfrp/1tbifgvVG2eHcDbhdAAAsI 在 2025/1/14 20:51, Vlastimil Babka 写道: > On 1/14/25 13:24, Ge Yang wrote: >>> Hopefully also when done from the pin_user_pages_remote(..., FOLL_LONGTERM, >>> ...) context the allocation gfp_mask correctly lacks __GFP_MOVABLE? >> yes. >> I guess >>> it has to, otherwise it would allocate from the CMA pageblocks. >>> >>> Then I wonder if we could use the real allocation context to determine >>> watermarks, as __compaction_suitable() is passing ALLOC_CMA instead because >>> it's checking only for migration targets, which have to be CMA compatible by >>> definition. But we could use the real unmovable allocation context to have >>> __zone_watermark_unusable_free() subtract CMA pages, and thus we won't pass >>> the order-0 check anymore once the non-CMA part is exhausted. >>> >>> There's some risk that in some different scenario the compaction could in >>> fact migrate pages from the exhausted non-CMA part of the zone to the CMA >>> part and succeed, and we'll skip it instead. But that should be rare? >>> >> Below is the previous discussion: >> https://lore.kernel.org/lkml/1734436004-1212-1-git-send-email-yangge1116@126.com/ > > Right so Johannes had the same concern. > >>> Anyway given that concern I'm not sure about changing >>> __compaction_suitable() for every caller like this. We could (at least >>> initially) target this heuristic only for COMPACT_PRIO_ASYNC which is being >>> used for this THP opportunistic attempt. >>> >>> So for example: >>> - add a new bool flag to compact_control that is true for COMPACT_PRIO_ASYNC >>> - pass cc pointer to compaction_suit_allocation_order() >>> - in that function, add another check if the the new cc flag is true, >>> between the current zone_watermark_ok() and compaction_suitable() checks, >>> which works like __compaction_suitable() but uses alloc_flags (which should >>> not be ALLOC_CMA in our pinned allocation case) instead of ALLOC_CMA, return >>> COMPACT_SKIPPED if it fails. >>> >> I will send a new version of the patch based on the suggestions here. >> Thank you. > > Yeah that way should hopefully limit the concern sufficiently. Maybe we > could also add costly_order condition in addition to COMPACT_PRIO_ASYNC > condition to set the new compact_control flag. But only __GFP_NORETRY > allocations should be affected in the immediate "goto nopage" when > compaction is skipped, others will attempt with DEF_COMPACT_PRIORITY anyway > and won't fail without trying to compact-migrate the non-CMA pageblocks into > CMA pageblocks first, so it should be fine. Ok, thanks.