runtime: JIT_NewS_MP_FastPortable is slow for Orchard CMS benchmark on Linux-arm64

Orchard CMS is one of the most complicated benchmark in our test suite (way more complicated than TE benchmarks) so, presumably, it’s closer to real-world. Currently, ARM64 is twice slower than x64 (comparable HW) on it while for TE benchmark the same ARM64 hardware is typically 1.2-1.5x faster than that x64 AMD machine. The perf trace is pointing to JIT_NewS_MP_FastPortable: image

(sorted by ‘self’ aks exclusive time).

The annoted asm for it: image Or (output of bjdump -d):

000000000033fbf0 <_Z24JIT_NewS_MP_FastPortableP21CORINFO_CLASS_STRUCT_>:
  33fbf0:	a9bf7bfd 	stp	x29, x30, [sp, #-16]!
  33fbf4:	910003fd 	mov	x29, sp
  33fbf8:	aa0003e8 	mov	x8, x0
  33fbfc:	90001920 	adrp	x0, 663000 <_ZTV12EEJitManager+0x50>
  33fc00:	f947dc01 	ldr	x1, [x0, #4024]
  33fc04:	913ee000 	add	x0, x0, #0xfb8
  33fc08:	d63f0020 	blr	x1
  33fc0c:	d53bd049 	mrs	x9, tpidr_el0
  33fc10:	b940050a 	ldr	w10, [x8, #4]
  33fc14:	f8606929 	ldr	x9, [x9, x0]
  33fc18:	a945ad20 	ldp	x0, x11, [x9, #88]
  33fc1c:	cb00016b 	sub	x11, x11, x0
  33fc20:	eb0a017f 	cmp	x11, x10
  33fc24:	54000082 	b.cs	33fc34 <_Z24JIT_NewS_MP_FastPortableP21CORINFO_CLASS_STRUCT_+0x44>  // b.hs, b.nlast
  33fc28:	aa0803e0 	mov	x0, x8
  33fc2c:	a8c17bfd 	ldp	x29, x30, [sp], #16
  33fc30:	14000006 	b	33fc48 <_Z7JIT_NewP21CORINFO_CLASS_STRUCT_>
  33fc34:	8b0a000a 	add	x10, x0, x10
  33fc38:	f9002d2a 	str	x10, [x9, #88]
  33fc3c:	f9000008 	str	x8, [x0]
  33fc40:	a8c17bfd 	ldp	x29, x30, [sp], #16
  33fc44:	d65f03c0 	ret

If I read this correctly, we spend most of them time reading data from TLS (to get current allocator ?) - I’d expect to see time spent inside the fallback call to gc, but it’s not (if the trace is accurate). Another hint from the general trace is that we don’t really spend a lot of time in GC itself.

PS: what is blr x1 call ? I presume it should be part of the GetThread()

cc @mangod9 @kunalspathak

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 48 (48 by maintainers)

Most upvoted comments

@EgorBo I have a branch https://github.com/davidwrighton/runtime/tree/adjust_allocation_in_typesystem where I’ve done some tweaks that may increase the memory density of the MethodTable structures used by the runtime (you should be able to cherry pick the last two commits in the branch). In general, what the branch does is that it reduces the size of the Generic Dictionaries, which are allocated per MethodTable for some of the egregiously large cases like List<T> and Task<T>, and also segregates the allocation of MethodTable structures which are likely to be used for allocated objects so that they are slightly more likely to share a 4K page. I’m interested to know if that change has any impact on the Orchard CMS scenario. I don’t expect the change to have any meaningful impact on L1 cache hit rates, but I think there is some hope that it might impact TLB cache miss rates. Also, for these numbers do you know which TLB cache is being reported as hit/miss? These processors have multiple TLB caches, an L1, L2 and possibly L3, and your numbers were not reporting a specific one which is being missed. My understanding of TLB cache misses is that an L1 cache miss is bad, but not that impactful, but a last level cache miss on the TLB cache can cause a tremendous amount of work, as that will trigger a full page table walk, which is at least 5 memory loads.

I presume in many cases JIT knows in advance the size of an object it will need to allocate so maybe we can avoid that load and grab the size from the parameters? (e.g. new kind of an allocator - CORINFO_HELP_NEWSFAST_CONSTSIZE) cc @jkotas

This will move the potential cache miss from the allocation helper to potential cache miss on extra code and to a potential cache miss on the next method table use. I think that it is likely for the object MethodTable to be used for things like virtual calls after the object has been allocated. It is not obvious to me that it is a win on average to pass the size in an extra argument if it is done everywhere.

If we want to go in this direction, it may be more profitable to inline the allocation helper as “no GC region” for very hot code. You will inline the size, but also avoid the call overhead and fuse the size as immediate into the instruction. There is more code size overhead, but it may be ok if it is done only for very hot code. It matches what we do in the inlining heuristics for the very hot code.

hmm, yeah this is interesting. We should compare with constant throughput as well, so we can check whether the GC throughput is different which might point to slow memory accesses.

So I decided to quickly introduce a new helper CORINFO_HELP_NEWSFAST_CONST - my ugly branch.

After I sent my binaries to crank and collected a new profile I no longer see that helper in the cache misses: image

Unfortunately, the RPS didn’t improve much. So I am going to look at x64 now.

Looking at this data, its very suspicious around the memory access patterns for MethodTable. Tomorrow, I’ll put together a change which isolates MethodTable into its own heap, and keeps most of the ancillary data structures allocated on the high frequency heap. I’ve also identified that we have a subpar algorithm guessing how many dictionary entry slots we need for a type. Currently, its guessing that we need 50 Dictionary entry slots for List<T>, but it looks like we actually only need something like 8-10 of them. This is wasting about 300 bytes of address space for each MethodTable. Now, this isn’t necessarily a problem that would impact the cache miss rates, but it will increase the TLB miss rate. However, if this also causes the typical allocation size for something like a specific instantiation of List<T> to happen to be about a power of 2 in size, it would also increase the cache miss rate, as it will induce false sharing which would be exacerbated by having fewer ways in the L1/L2 cache on arm64 vs x64.

These are both problems that will impact performance on Arm more than X64, as the TLB cache size on X64 platforms is typically quite a bit larger as well.

I’ll try this week to build tweak to our type loader to attempt to address some of the TLB problems. I hope to have something tomorrow or the day after.

@EgorBo - can we have the same list of types for x64. If not too difficult, mostly as a datapoint.

I expect to see the same distribution. Although if we see, for example, way fewer Task`T, it could be something.

@EgorBo could you also get a drill down of the TLB-miss and TLB-access data? 704K TLB misses is a LOT for only 10M memory accesses. Also, the perf c2c data on the equivalent Intel platform would be really valuable here just to help us understand if we’re just guessing here around costs or not. If we need to there are options for increasing the memory density of the MethodTable structures, where we move less commonly accessed data to more remote locations.

(if prof is confused by symbols, tailcalling, sampling rate…).

That was my theory as well (as I mentioned in the description), but I don’t see any other pieces of GC in the profile.

Could it be interesting to rerun tests while forcing the same DOTNET_GCgen0size?

These are already with the same DOTNET_GCgen0size (otherwise, GC Heap size is 5Gb on arm64 and 20Gb on x64).