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 0C313C7EE2C for ; Mon, 29 May 2023 09:58:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 63EA4900003; Mon, 29 May 2023 05:58:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5EDAD900002; Mon, 29 May 2023 05:58:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 48E85900003; Mon, 29 May 2023 05:58:07 -0400 (EDT) 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 36DF5900002 for ; Mon, 29 May 2023 05:58:07 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id ECAB7C02A1 for ; Mon, 29 May 2023 09:58:06 +0000 (UTC) X-FDA: 80842841772.06.2EC36AC Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by imf27.hostedemail.com (Postfix) with ESMTP id E4CBC4000E for ; Mon, 29 May 2023 09:58:04 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=PPzlHT0r; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=YHmoj+1Y; spf=pass (imf27.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.29 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1685354285; 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=KBY/iJ08Nu3iXyfntMKOqtt/CWtCEdUoszCM6hJfmPg=; b=Yglr/Dc0vZBc7dBmDnQSQaXqSnExP4VecHnaxut1w3/UVhRp5Nu2bV1rgjl/sAg5Vl4lF2 6sGgj0Cdiva37lgGrzBdc11pRFLIs5YvjY+E6Xjb6decBs5PbYuOjE518EK1/RzSQSubnu QSWx+ZWe+wVyA4gB4PQCiO5T8ivYDew= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1685354285; a=rsa-sha256; cv=none; b=7ko2wVP49Tsu9nxpo7MLPAyuBKkqYI6JYG5iXF0rXz5IQjgyAtDtnIqMTRiGDM8LoPrBjX 9dhQb7ZExIzwalViRT6YTj4KMjX6X9bNrh3KLV+uyFlpDsIQqMjURsTBjkggEnVnDYEHjS HUVfVbiAmdD5dyEkM3Eh9kM77+2sEWM= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=PPzlHT0r; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=YHmoj+1Y; spf=pass (imf27.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.29 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none 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-out2.suse.de (Postfix) with ESMTPS id 2E35C1FE51; Mon, 29 May 2023 09:58:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1685354283; 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=KBY/iJ08Nu3iXyfntMKOqtt/CWtCEdUoszCM6hJfmPg=; b=PPzlHT0r6UKDru+neNsxLvxs2sWPhhkxdjZfwOARBuxmZs20PghVw3RWh0y9NwX1ZW0kW1 VjYY9elMVj+RD8KOIiKQuT0n0jYETvPye71bZnzZOIc1qGH9Q54tu3NSbmIA+lz/MXG2JQ dfxGCJ4ZwbIfv9gfWLAc9nkGehiAH+I= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1685354283; 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=KBY/iJ08Nu3iXyfntMKOqtt/CWtCEdUoszCM6hJfmPg=; b=YHmoj+1YiTKT0ypOg2WeZQS1k2xqgwAfZch8QUH0s5hWVLxu0FQrOv7SBy2TZJUex4LInk E3rlaS6PW5bcqIAA== 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 114FA1332D; Mon, 29 May 2023 09:58:03 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 8COHAyt3dGTJcQAAMHmgww (envelope-from ); Mon, 29 May 2023 09:58:03 +0000 Message-ID: <266b9815-104e-864c-688f-955581954e48@suse.cz> Date: Mon, 29 May 2023 11:58:02 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.2 Subject: Re: [PATCH 1/5] mm: compaction: remove compaction result helpers To: Johannes Weiner , Andrew Morton Cc: Mel Gorman , Michal Hocko , linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@fb.com References: <20230519123959.77335-1-hannes@cmpxchg.org> <20230519123959.77335-2-hannes@cmpxchg.org> Content-Language: en-US From: Vlastimil Babka In-Reply-To: <20230519123959.77335-2-hannes@cmpxchg.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: E4CBC4000E X-Rspam-User: X-Stat-Signature: teocdso9yktyqpswsuzwdfpenzh5xck7 X-Rspamd-Server: rspam03 X-HE-Tag: 1685354284-14241 X-HE-Meta: U2FsdGVkX1++h0jnSwQs8W+hP/+i4pqJXn2wETV9p51LjKx/lROMvoM1+dE6nwzs5MTGeu9s9ndDXCi5UEf5DICYA3eN6Jq8fEHGpw11/EJuJyDNFCtBGBfAV1UmlC/disBL4k4M3mIsQ6/Q2541WhBbqm039t/bAo5+pAfVy5tkYVtYRuhKuHZf9ZJKqwUR5rqUDDjNf+ALBhI6ffxBIVDc9k+zH4Ad0p+stx3NcrmAQIobe9r11UtDOQ41wqQF+xNVlC7e0l0E335y/JDYy5H6mzNZWnwfacIfXypiaFLPFZEhx1/+/ivBDLd/m9Nld6BXOeGhkqRL5pbN5Rqb+DTQPJ2qHMLkpEyyOmAjLzln6skCWBWPlewXnyIrxewDdKYcYkZSVyirbZl5OHDqVtxn2SD7HSR2lgQlw0wFFDs6G3bOwWCwXfYdH057dRhzTr1Q6uyuuQwLNJjRPHghMNHmSoWoXzTNeH56u8Vjhhv1c4Jl9d9TsUAeU/LPW9/+1xLXitG9PQxk4A9SY+5/2MQJXpfYZu92pwolONTEuO3x6WmM9fxr/B/A03cRNgdGtgU7D8u+V07wgtutb25PYBBpNmNgBHa4o836AW8ul/rGjXXfH9ChkCcawVooOWta60Rl8RejYoyZzyEVxo4IrQ4u9rkkW5UZzcYf4rTHdjzseghGMZcs9oBBf9RZcj8Qj/opNt7IyVZzxzMh6SCFITAfJtOZIYOhqMRyfAykIN3H2E9bzf0bVkDGRbf/gIiwXzNftu+8VPu62BGVNsV7QHtfF2+V8DVU7O5LnfZv27Mh/EY0+yftmOfqn5ItY64jrMLsp+DPPQcWjNiECfArHX/FADR2LhmqMiNdNbXhxH1GCJZ33lQYK0+kzMRpk/p63yTtmTIipaPOaPkkbr98GWjTk90ATqYG6Sp0e2LxWtudfpfwf5sZOmqlqqAPLMaoKQk2hNWbpruW3Guup3v Ff7JAU0I z63DpqFavzgpAWZy1aBiZ2rLjqEncRlBzzXEAQhTbM6KfbW85vS/TpFi3Mr+I2Pfq9Xt1e6tmvE1Y2yPeSrwPNJwF9MD42c4sF3ccs25Eg6crgaQa/kcXpPUkJzYYIMRV7Y/83s0j4mgBzMZEdGyu7dRlvQOkD9JeEuaGR7wFbOyf1pDTNaASguvQ7Hl9kUty74bpzXrvOF/83O+OHy/x+4Cl+v5O3KXH2HS5IBAooLdIMaR6Cqv7oyDNMrhtNbFaE2IH 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: On 5/19/23 14:39, Johannes Weiner wrote: > The compaction result helpers encode quirks that are specific to the > allocator's retry logic. E.g. COMPACT_SUCCESS and COMPACT_COMPLETE > actually represent failures that should be retried upon, and so on. I > frequently found myself pulling up the helper implementation in order > to understand and work on the retry logic. They're not quite clean > abstractions; rather they split the retry logic into two locations. > > Remove the helpers and inline the checks. Then comment on the result > interpretations directly where the decision making happens. > > Signed-off-by: Johannes Weiner Since the usage of helpers never proliferated outside of should_compact_retry() with the exception of tracepoint, I guess it makes sense to remove them. Acked-by: Vlastimil Babka > --- > include/linux/compaction.h | 92 ---------------------------------- > include/trace/events/mmflags.h | 4 +- > mm/page_alloc.c | 30 ++++++----- > 3 files changed, 19 insertions(+), 107 deletions(-) > > diff --git a/include/linux/compaction.h b/include/linux/compaction.h > index a6e512cfb670..1f0328a2ba48 100644 > --- a/include/linux/compaction.h > +++ b/include/linux/compaction.h > @@ -95,78 +95,6 @@ extern enum compact_result compaction_suitable(struct zone *zone, int order, > extern void compaction_defer_reset(struct zone *zone, int order, > bool alloc_success); > > -/* Compaction has made some progress and retrying makes sense */ > -static inline bool compaction_made_progress(enum compact_result result) > -{ > - /* > - * Even though this might sound confusing this in fact tells us > - * that the compaction successfully isolated and migrated some > - * pageblocks. > - */ > - if (result == COMPACT_SUCCESS) > - return true; > - > - return false; > -} > - > -/* Compaction has failed and it doesn't make much sense to keep retrying. */ > -static inline bool compaction_failed(enum compact_result result) > -{ > - /* All zones were scanned completely and still not result. */ > - if (result == COMPACT_COMPLETE) > - return true; > - > - return false; > -} > - > -/* Compaction needs reclaim to be performed first, so it can continue. */ > -static inline bool compaction_needs_reclaim(enum compact_result result) > -{ > - /* > - * Compaction backed off due to watermark checks for order-0 > - * so the regular reclaim has to try harder and reclaim something. > - */ > - if (result == COMPACT_SKIPPED) > - return true; > - > - return false; > -} > - > -/* > - * Compaction has backed off for some reason after doing some work or none > - * at all. It might be throttling or lock contention. Retrying might be still > - * worthwhile, but with a higher priority if allowed. > - */ > -static inline bool compaction_withdrawn(enum compact_result result) > -{ > - /* > - * If compaction is deferred for high-order allocations, it is > - * because sync compaction recently failed. If this is the case > - * and the caller requested a THP allocation, we do not want > - * to heavily disrupt the system, so we fail the allocation > - * instead of entering direct reclaim. > - */ > - if (result == COMPACT_DEFERRED) > - return true; > - > - /* > - * If compaction in async mode encounters contention or blocks higher > - * priority task we back off early rather than cause stalls. > - */ > - if (result == COMPACT_CONTENDED) > - return true; > - > - /* > - * Page scanners have met but we haven't scanned full zones so this > - * is a back off in fact. > - */ > - if (result == COMPACT_PARTIAL_SKIPPED) > - return true; > - > - return false; > -} > - > - > bool compaction_zonelist_suitable(struct alloc_context *ac, int order, > int alloc_flags); > > @@ -185,26 +113,6 @@ static inline enum compact_result compaction_suitable(struct zone *zone, int ord > return COMPACT_SKIPPED; > } > > -static inline bool compaction_made_progress(enum compact_result result) > -{ > - return false; > -} > - > -static inline bool compaction_failed(enum compact_result result) > -{ > - return false; > -} > - > -static inline bool compaction_needs_reclaim(enum compact_result result) > -{ > - return false; > -} > - > -static inline bool compaction_withdrawn(enum compact_result result) > -{ > - return true; > -} > - > static inline void kcompactd_run(int nid) > { > } > diff --git a/include/trace/events/mmflags.h b/include/trace/events/mmflags.h > index b63e7c0fbbe5..1478b9dd05fa 100644 > --- a/include/trace/events/mmflags.h > +++ b/include/trace/events/mmflags.h > @@ -223,8 +223,8 @@ IF_HAVE_VM_SOFTDIRTY(VM_SOFTDIRTY, "softdirty" ) \ > #define compact_result_to_feedback(result) \ > ({ \ > enum compact_result __result = result; \ > - (compaction_failed(__result)) ? COMPACTION_FAILED : \ > - (compaction_withdrawn(__result)) ? COMPACTION_WITHDRAWN : COMPACTION_PROGRESS; \ > + (__result == COMPACT_COMPLETE) ? COMPACTION_FAILED : \ > + (__result == COMPACT_SUCCESS) ? COMPACTION_PROGRESS : COMPACTION_WITHDRAWN; \ > }) > > #define COMPACTION_FEEDBACK \ > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > index 47421bedc12b..5a84a0bebc37 100644 > --- a/mm/page_alloc.c > +++ b/mm/page_alloc.c > @@ -3768,35 +3768,39 @@ should_compact_retry(struct alloc_context *ac, int order, int alloc_flags, > if (fatal_signal_pending(current)) > return false; > > - if (compaction_made_progress(compact_result)) > + /* > + * Compaction managed to coalesce some page blocks, but the > + * allocation failed presumably due to a race. Retry some. > + */ > + if (compact_result == COMPACT_SUCCESS) > (*compaction_retries)++; > > /* > - * compaction considers all the zone as desperately out of memory > - * so it doesn't really make much sense to retry except when the > + * All zones were scanned completely and still no result. It > + * doesn't really make much sense to retry except when the > * failure could be caused by insufficient priority > */ > - if (compaction_failed(compact_result)) > + if (compact_result == COMPACT_COMPLETE) > goto check_priority; > > /* > - * compaction was skipped because there are not enough order-0 pages > - * to work with, so we retry only if it looks like reclaim can help. > + * Compaction was skipped due to a lack of free order-0 > + * migration targets. Continue if reclaim can help. > */ > - if (compaction_needs_reclaim(compact_result)) { > + if (compact_result == COMPACT_SKIPPED) { > ret = compaction_zonelist_suitable(ac, order, alloc_flags); > goto out; > } > > /* > - * make sure the compaction wasn't deferred or didn't bail out early > - * due to locks contention before we declare that we should give up. > - * But the next retry should use a higher priority if allowed, so > - * we don't just keep bailing out endlessly. > + * If compaction backed due to being deferred, due to > + * contended locks in async mode, or due to scanners meeting > + * after a partial scan, retry with increased priority. > */ > - if (compaction_withdrawn(compact_result)) { > + if (compact_result == COMPACT_DEFERRED || > + compact_result == COMPACT_CONTENDED || > + compact_result == COMPACT_PARTIAL_SKIPPED) > goto check_priority; > - } > > /* > * !costly requests are much more important than __GFP_RETRY_MAYFAIL