From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.18]) (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 9992023BD17 for ; Thu, 30 Apr 2026 19:18:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777576698; cv=none; b=mHCRQg4I3MksbwBmz5tipVfrKz5P+oMiCbMZApbANVic/FLM15xJBU/cJqq6GPLkGIMOWNOkNnts0EMkEaKnqK8tlS3XbX2WM7slgaZKAx+BpkWOqEEy7YliwylD8IPl9zcVIyeLPnKMCUL7Tbw0ZfoBz/y4gIeafiwwVevbOXs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777576698; c=relaxed/simple; bh=GHkxm0wYYb4SrQQJzp26BvqDgj5d1MTHLdsthOQOpLE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=E9P94cvWvZ9sW55j/8OspZVy960H3vAU05U2QotPvSBjmZxRpEvrzbWF6lCPXYCR0YfKufsMmKLC+1EmCNDkW66DpT+joCO+nl58mJZz+KM9V1rU881tSOIk//rNbAPs64ANgPgIeTVIEwGezDA5I/vKODOfd8k8c4IsqRriRdA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=ZuwbVmiO; arc=none smtp.client-ip=192.198.163.18 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="ZuwbVmiO" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1777576697; x=1809112697; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=GHkxm0wYYb4SrQQJzp26BvqDgj5d1MTHLdsthOQOpLE=; b=ZuwbVmiOUIpO69BgCwiHn47dwtixdMYSEmDheSwlHgJaBrpxy4E0roXs zAkYgTMTLJYTHztsSnfBw2COVXvteXobwFZbPTc8nOqVJn6GNMDsy97JA U7daLUzNCX6OIq0QncpuaVPJI2gxPj+vb9Za5iwTS3KRyx3D92ju7wMj7 Yhyw/0VWlAWhGx5QZQ5fHZ1uFX7LOudrmAR2ubwZ+/VWZ00FIVh8wO5c3 JXVhETJv3GCiLEYr92o6HmuhHN/eSYDQy8dFCi7kr+Iz53Czbiq+HPEVG QlobqARjoU1pvNdj8Bg5p5U0yZP2+ctRLtGvryXloP85uGcyBDK2tvd/t Q==; X-CSE-ConnectionGUID: 8MrZ6U7ZSg+2mYcbL6T/vg== X-CSE-MsgGUID: XMZHfRPKROqTiITWJama7A== X-IronPort-AV: E=McAfee;i="6800,10657,11772"; a="77706746" X-IronPort-AV: E=Sophos;i="6.23,208,1770624000"; d="scan'208";a="77706746" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by fmvoesa112.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Apr 2026 12:18:14 -0700 X-CSE-ConnectionGUID: md5b2HFPSdm+DLB6+IWNBA== X-CSE-MsgGUID: eTWfpT+ETRezIfA8iUbD8A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,208,1770624000"; d="scan'208";a="233801145" Received: from gsse-cloud1.jf.intel.com ([10.54.39.91]) by orviesa010-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Apr 2026 12:18:14 -0700 From: Matthew Brost To: intel-xe@lists.freedesktop.org, dri-devel@lists.freedesktop.org Cc: =?UTF-8?q?Thomas=20Hellstr=C3=B6m?= , Andrew Morton , David Hildenbrand , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 2/6] mm: Introduce zone_maybe_fragmented_in_shrinker() Date: Thu, 30 Apr 2026 12:18:05 -0700 Message-Id: <20260430191809.2142544-3-matthew.brost@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260430191809.2142544-1-matthew.brost@intel.com> References: <20260430191809.2142544-1-matthew.brost@intel.com> 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 Introduce zone_maybe_fragmented_in_shrinker() as a lightweight helper to allow subsystems to make coarse decisions about reclaim behavior in the presence of likely fragmentation. The helper implements a simple heuristic: if the number of free pages in a zone exceeds twice the high watermark, the zone is considered to have ample free memory and allocation failures are more likely due to fragmentation than overall memory pressure. This is intentionally imprecise and is not meant to replace the core MM compaction or fragmentation accounting logic. Instead, it provides a cheap signal for callers (e.g., shrinkers) that wish to avoid overly aggressive reclaim when sufficient free memory exists but high-order allocations may still fail. No functional changes; this is a preparatory helper for future users. Cc: Thomas Hellström Cc: Andrew Morton Cc: David Hildenbrand Cc: Lorenzo Stoakes Cc: "Liam R. Howlett" Cc: Vlastimil Babka Cc: Mike Rapoport Cc: Suren Baghdasaryan Cc: Michal Hocko Cc: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Matthew Brost --- v3: s/zone_appear_fragmented/zone_maybe_fragmented_in_shrinker (David Hildenbrand) --- include/linux/vmstat.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h index 3c9c266cf782..1ad48f70c9d9 100644 --- a/include/linux/vmstat.h +++ b/include/linux/vmstat.h @@ -483,6 +483,18 @@ static inline const char *zone_stat_name(enum zone_stat_item item) return vmstat_text[item]; } +static inline bool zone_maybe_fragmented_in_shrinker(struct zone *zone) +{ + /* + * Simple heuristic: if the number of free pages is more than twice the + * high watermark, this may suggest that the zone is heavily fragmented. + * When called from a shrinker, aggressively evicting memory in this case + * may do more harm to overall system performance than good. + */ + return zone_page_state(zone, NR_FREE_PAGES) > + high_wmark_pages(zone) * 2; +} + #ifdef CONFIG_NUMA static inline const char *numa_stat_name(enum numa_stat_item item) { -- 2.34.1