@@ -231,14 +231,66 @@ function runtest(::Type{TestRecord}, f, name, init_code, color)
231231    end 
232232end 
233233
234+ @static  if  Sys. isapple ()
235+ 
236+ mutable struct  VmStatistics64
237+ 	free_count:: UInt32 
238+ 	active_count:: UInt32 
239+ 	inactive_count:: UInt32 
240+ 	wire_count:: UInt32 
241+ 	zero_fill_count:: UInt64 
242+ 	reactivations:: UInt64 
243+ 	pageins:: UInt64 
244+ 	pageouts:: UInt64 
245+ 	faults:: UInt64 
246+ 	cow_faults:: UInt64 
247+ 	lookups:: UInt64 
248+ 	hits:: UInt64 
249+ 	purges:: UInt64 
250+ 	purgeable_count:: UInt32 
251+ 
252+ 	speculative_count:: UInt32 
253+ 
254+ 	decompressions:: UInt64 
255+ 	compressions:: UInt64 
256+ 	swapins:: UInt64 
257+ 	swapouts:: UInt64 
258+ 	compressor_page_count:: UInt32 
259+ 	throttled_count:: UInt32 
260+ 	external_page_count:: UInt32 
261+ 	internal_page_count:: UInt32 
262+ 	total_uncompressed_pages_in_compressor:: UInt64 
263+ 
264+ 	VmStatistics64 () =  new (0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 )
265+ end 
266+ 
267+ 
268+ function  available_memory ()
269+ 	vms =  Ref {VmStatistics64} (VmStatistics64 ())
270+ 	mach_host_self =  @ccall  mach_host_self ():: UInt32 
271+ 	count =  UInt32 (sizeof (VmStatistics64) ÷  sizeof (Int32))
272+ 	ref_count =  Ref (count)
273+ 	@ccall  host_statistics64 (mach_host_self:: UInt32 , 4 :: Int64 , pointer_from_objref (vms[]):: Ptr{Int64} , ref_count:: Ref{UInt32} ):: Int64 
274+ 
275+ 	page_size =  Int (@ccall  sysconf (29 :: UInt32 ):: UInt32 )
276+ 
277+ 	return  (Int (vms[]. free_count) +  Int (vms[]. inactive_count)) *  page_size
278+ end 
279+ 
280+ else 
281+ 
282+ available_memory () =  Sys. free_memory ()
283+ 
284+ end 
285+ 
234286#  This is an internal function, not to be used by end users.  The keyword
235287#  arguments are only for testing purposes.
236288""" 
237289    default_njobs() 
238290
239291Determine default number of parallel jobs. 
240292""" 
241- function  default_njobs (; cpu_threads =  Sys. CPU_THREADS, free_memory =  Sys . free_memory ())
293+ function  default_njobs (; cpu_threads =  Sys. CPU_THREADS, free_memory =  available_memory ())
242294    jobs =  cpu_threads
243295    memory_jobs =  Int64 (free_memory) ÷  (2  *  2 ^ 30 )
244296    return  max (1 , min (jobs, memory_jobs))
0 commit comments