From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.10]) (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 33CF33CD8A6 for ; Thu, 23 Apr 2026 05:57:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.10 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776923826; cv=none; b=KQISIAhmKJD3scJZdYsRq+6UcQLYOsiOfVfU4AdGyPXpLTHP/sk/WcwiWo6CJMNBuhwrgU4zNXENpxCtsHwKAr0/Vyd13XWRaukQMGcf1RbP8J5AA6moIxz/KmzxirPkYKixa87V9Awhpsu21jhlqx9eNtleGz9eJN96ZeTP/qg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776923826; c=relaxed/simple; bh=X0WxjIbHx5z6Rxp6kXcxclzwuMByqWEn9gesMvle8Ng=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=iFLG4uuSxNi9UJGvkxRHWph0ZJU0aQlpAYzFK8GQyZMoXD/0OYjStWBK97Opj4Qa0RfFu+ZKALd6rzBjgvEdMcdMPniveXy/xoUcQumslTGKWdaaBw3HYqf32ZH5FMSY05jMLOut+UFEusWNODgqODo+jcnPAIOX7iEhiiwk0gs= 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=lMtvwJYL; arc=none smtp.client-ip=192.198.163.10 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="lMtvwJYL" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1776923825; x=1808459825; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=X0WxjIbHx5z6Rxp6kXcxclzwuMByqWEn9gesMvle8Ng=; b=lMtvwJYLngxq31neFgfCDQ0T5ae01G+OggWXaRTYlfJSvmZJsf2RVE6c uzMcW14t4NvyDP7HUwV9xeAe1oDPoSyAUHHglDWlSBaiywYHTMGSHU8kT plYqQNganLgd/V3yJ85aY8M8a7cIJSv02H67FENcXfdz1j5YYU/8OpSY4 uCQQtlSiajABvX1Q27SU6ddc803Wr5bfzg0/XS408Mm9jJvXNxhAjdhVn dfzfUjkvxR+apb2g1D25W2qjDcQhD0laHpDUXOMFXyHW8WK1KK3EU96Ja U0ceTBJOgVtBeHe8bUtIyY8GE2IxkMDtX6S9hSHIVxUw8GnFUBclYLQ0r w==; X-CSE-ConnectionGUID: tWzFUi7oTCy3qWNqblSvow== X-CSE-MsgGUID: w+jZzISjRd6h7REdvo3lBQ== X-IronPort-AV: E=McAfee;i="6800,10657,11764"; a="89273758" X-IronPort-AV: E=Sophos;i="6.23,194,1770624000"; d="scan'208";a="89273758" Received: from fmviesa002.fm.intel.com ([10.60.135.142]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Apr 2026 22:57:02 -0700 X-CSE-ConnectionGUID: p8YasWqfSRiLJkJEpizvtQ== X-CSE-MsgGUID: 8WOmptFtRWWVyY54GAlCVA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,194,1770624000"; d="scan'208";a="255853890" Received: from gsse-cloud1.jf.intel.com ([10.54.39.91]) by fmviesa002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Apr 2026 22:57:02 -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 v2 1/5] mm: Introduce zone_appears_fragmented() Date: Wed, 22 Apr 2026 22:56:52 -0700 Message-Id: <20260423055656.1696379-2-matthew.brost@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260423055656.1696379-1-matthew.brost@intel.com> References: <20260423055656.1696379-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_appears_fragmented() 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 --- include/linux/vmstat.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h index 3c9c266cf782..568d9f4f1a1f 100644 --- a/include/linux/vmstat.h +++ b/include/linux/vmstat.h @@ -483,6 +483,19 @@ static inline const char *zone_stat_name(enum zone_stat_item item) return vmstat_text[item]; } +static inline bool zone_appears_fragmented(struct zone *zone) +{ + /* + * Simple heuristic: if the number of free pages is more than twice the + * high watermark, this strongly suggests that the zone is heavily + * fragmented when called from a shrinker. + */ + if (zone_page_state(zone, NR_FREE_PAGES) > high_wmark_pages(zone) * 2) + return true; + + return false; +} + #ifdef CONFIG_NUMA static inline const char *numa_stat_name(enum numa_stat_item item) { -- 2.34.1