Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp3649226rdb; Wed, 13 Sep 2023 20:25:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGRbIipUQmeRu7HIMk1QHKq5Ax6eEvS2DCTt4KGpfWdLtLfi5097/RRdeIPp6L7BiiaG/qn X-Received: by 2002:a62:cd08:0:b0:690:2ecd:a58c with SMTP id o8-20020a62cd08000000b006902ecda58cmr381786pfg.27.1694661910744; Wed, 13 Sep 2023 20:25:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694661910; cv=none; d=google.com; s=arc-20160816; b=PiljL7o0W43kogcHmTY9WnaEcVQHPIjW+ksBUx/r6xlPEEMD49IDufb3PbSmJhbtHY 3L4+BiL3EIRYVOg4vY5W2CEOVpGXzIAz/S+YDUzq5TElwtfX4EqVb2nDZnlqk8HBhJmG iOCqaRro8+AKyt6n7/VpwAiMMn/tx1WsA5mGj/P9rrALgu2EMNe+mQlJm8TBydXi1gLA 7n2KrhbQSjBsGPDzOr9PKBVNtUvd66XUvoaaYdXWynEGaRrPZrhD9ia3PIrsa+w8aVYo //uhbxrsSoLtQQKkS34oHnLro6IVueqhkUnwoK9XNT4t7epRGBUoi8rzMWfIYVenlwok q0Wg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature:dkim-signature; bh=3lN7bSKVF5Ye4MzDY2kf7YVJd7wa8KQ9puGZkU8cNug=; fh=hq15/A2Tslw9YA2204Su5Ecu43xpuzUCtL6/M8x+dIs=; b=s1fESIezjEeKzfSXkKImhBIj6SIEIsdSY7VK472ZcmbtZslWeF9QRrqN0RlggaeTDm iO43D62xtW4IN3PpVsY0wocXSyWTJES09vpDloUOmZm3gtF2iQwPNjcm74DgzLZB7KcW 5JLSmnaRfTl8/LhiPRWTrH3FzW207jqfoRY0rY9PiS7grCM/+3M1TisM3yAUebL4fCnj pUqSfpBPR1T1zIsaTnXLzjzyFDn+x2wU1seDHbnWSR++9WGCSpGTQ1GyH7odvshodS3J nqvGZ1RU/cXg1d0Ci0XBDD0QSaPzTydxyNd/cOOl0pr7L0uqG5PCg1sOuS0bl6q4Tkyb hZWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=tfquWEGb; dkim=neutral (no key) header.i=@suse.cz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id a71-20020a63904a000000b00577f59c8a16si582151pge.151.2023.09.13.20.25.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 20:25:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=tfquWEGb; dkim=neutral (no key) header.i=@suse.cz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 7910B822C60D; Wed, 13 Sep 2023 12:52:34 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231328AbjIMTwY (ORCPT + 99 others); Wed, 13 Sep 2023 15:52:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229642AbjIMTwX (ORCPT ); Wed, 13 Sep 2023 15:52:23 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 505C1B7 for ; Wed, 13 Sep 2023 12:52:19 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 03BAF218E3; Wed, 13 Sep 2023 19:52:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1694634738; 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=3lN7bSKVF5Ye4MzDY2kf7YVJd7wa8KQ9puGZkU8cNug=; b=tfquWEGbNzaMBuutCxOGon4c6Z4Z11vxMfYQGdhjLgyCbwC9kFZ8RrIKmZjOLWe8yrrGje 58QY9l/1fsW4YUXkKU2ySYBxweNWko2KKDHjxpLXdWSSWiOz11XwOhcNlVMyOwcVWbekKr Ubip/TpNiYAWFGAx1QL7TW29WE4wjVg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1694634738; 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=3lN7bSKVF5Ye4MzDY2kf7YVJd7wa8KQ9puGZkU8cNug=; b=zU+u4kIJebrTdhHmOFo9DkQOHnLA6gK6lkd/jxL5PDvs4PIp1nZaY8COsu9AY9nqpQjJDD 8BTbhk7+tVe4JkAA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id D6C8813440; Wed, 13 Sep 2023 19:52:17 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id dQi8M/ESAmUhdwAAMHmgww (envelope-from ); Wed, 13 Sep 2023 19:52:17 +0000 Message-ID: <5911bf29-b2a0-9016-7071-68334e7d680d@suse.cz> Date: Wed, 13 Sep 2023 21:52:17 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.14.0 Subject: Re: [PATCH 5/6] mm: page_alloc: fix freelist movement during block conversion Content-Language: en-US To: Johannes Weiner , Andrew Morton Cc: Mel Gorman , Miaohe Lin , Kefeng Wang , Zi Yan , linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20230911195023.247694-1-hannes@cmpxchg.org> <20230911195023.247694-6-hannes@cmpxchg.org> From: Vlastimil Babka In-Reply-To: <20230911195023.247694-6-hannes@cmpxchg.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Wed, 13 Sep 2023 12:52:34 -0700 (PDT) On 9/11/23 21:41, Johannes Weiner wrote: > Currently, page block type conversion during fallbacks, atomic > reservations and isolation can strand various amounts of free pages on > incorrect freelists. > > For example, fallback stealing moves free pages in the block to the > new type's freelists, but then may not actually claim the block for > that type if there aren't enough compatible pages already allocated. > > In all cases, free page moving might fail if the block straddles more > than one zone, in which case no free pages are moved at all, but the > block type is changed anyway. > > This is detrimental to type hygiene on the freelists. It encourages > incompatible page mixing down the line (ask for one type, get another) > and thus contributes to long-term fragmentation. > > Split the process into a proper transaction: check first if conversion > will happen, then try to move the free pages, and only if that was > successful convert the block to the new type. > > Signed-off-by: Johannes Weiner > @@ -1638,26 +1629,62 @@ static int move_freepages(struct zone *zone, > return pages_moved; > } > > -int move_freepages_block(struct zone *zone, struct page *page, > - int migratetype, int *num_movable) > +static bool prep_move_freepages_block(struct zone *zone, struct page *page, > + unsigned long *start_pfn, > + unsigned long *end_pfn, > + int *num_free, int *num_movable) > { > - unsigned long start_pfn, end_pfn, pfn; > - > - if (num_movable) > - *num_movable = 0; > + unsigned long pfn, start, end; > > pfn = page_to_pfn(page); > - start_pfn = pageblock_start_pfn(pfn); > - end_pfn = pageblock_end_pfn(pfn) - 1; > + start = pageblock_start_pfn(pfn); > + end = pageblock_end_pfn(pfn) - 1; > /* Do not cross zone boundaries */ > - if (!zone_spans_pfn(zone, start_pfn)) > - start_pfn = zone->zone_start_pfn; > - if (!zone_spans_pfn(zone, end_pfn)) > - return 0; > + if (!zone_spans_pfn(zone, start)) > + start = zone->zone_start_pfn; > + if (!zone_spans_pfn(zone, end)) > + return false; This brings me back to my previous suggestion - if we update the end, won't the whole "block straddles >1 zones" situation to check for go away? Hm or is it actually done because we have a problem by representing pageblock migratetype with multiple zones, since there's a single pageblock_bitmap entry per the respective pageblock range of pfn's, so one zone's migratetype could mess with other's? And now it matters if we want 100% match of freelist vs pageblock migratetype? (I think even before this series it could have mattered for MIGRATETYPE_ISOLATE, is it broken in those corner cases?) But in that case we might not be detecting the situation properly for the later of the two zones in a pageblock, because if start_pfn is not spanned we adjust it and continue? Hmm...