notgiven688 / webminerpool

Complete sources for a monero webminer.
262 stars 174 forks source link

Safari | iOS mobile memory issue #114

Closed PiTi2k5 closed 5 years ago

PiTi2k5 commented 5 years ago

Hi @notgiven688 following memory issue on safari and iOS mobiles. On MAC OS/iOS javascript log

Safari MAC OS --> start mining with 1 or 2 or more threads --> hashes > 8000 h/s --> memory errors iOS iPhone5s | iPhone7 --> start mining with 1-2 threads --> mininig runs fine, until i increase the threads to 3 or more than same error with 8000+ h/s and memory errors begins By the way the call navigator.hardwareConcurrency get always the return of 2 on apple devices and not the real threads, there are an extra javascript file for estimate the cpu cores but doesnt help for memory issue.

I tested the miner on Android and it was the same issue on increase the threads (hashing was rising about x1000), Samsung S8 --> start mining with 7 threads (navigator.hardwareConcurrency -1 works) --> mining runs fine, until i increase the threads Now i have an workaround on Android kill all workers with deleteAllWorkers(); and than call addWorkers(threads); with new max threads it runs fine, but workaround doesnt help on apple devices

I have tryed various build parameters with groth memory and so on, but it doesnt fix iOS issue, safari was run with 2 threads but same issue with increase threads

PiTi2k5 commented 5 years ago

I have tried some older webassembly builds from me with current algo support based on https://github.com/notgiven688/webminerpool/commit/aac0cb5399addb618cb97253d9fdcd85c3a77334#diff-d12a9eda097fab130bdf601fe779f4f7

This build is running fine on apple devices and mobiles without workarounds

notgiven688 commented 5 years ago

I will check this soon.

notgiven688 commented 5 years ago

@PiTi2k5

I have tryed various build parameters with groth memory and so on

Did you try to increase TOTAL_MEMORY=67108864 ?

PiTi2k5 commented 5 years ago

Yes, have tryed various optimations without -O3 with -O1/-O2 and without that -O parameter, groth mem, wasm build with wasm file output without inline

TARGET = prog LIBS = -lm

CC = emcc -O3 -s SINGLE_FILE=1 -s NO_FILESYSTEM=1 -s 'EXTRA_EXPORTED_RUNTIME_METHODS=["ccall", "cwrap"]' --llvm-lto 1 -s TOTAL_MEMORY=67108864 -s WASM=1 -s "BINARYEN_TRAP_MODE='allow'" -s EXPORTED_FUNCTIONS="['_has']" --shell-file html_template/shell_minimal.html CFLAGS = -Wall

-s ASSERTIONS=1

-s SINGLE_FILE=1

-s LEGACY_VM_SUPPORT=1

.PHONY: default all clean

default: $(TARGET) all: default

OBJECTS = $(patsubst %.c, %.o, $(wildcard .c)) HEADERS = $(wildcard .h)

%.o: %.c $(HEADERS) $(CC) $(CFLAGS) -c $< -o $@

.PRECIOUS: $(TARGET) $(OBJECTS)

$(TARGET): $(OBJECTS) $(CC) $(OBJECTS) -Wall $(LIBS) -o cn.html

clean: -rm -f *.o -rm -f $(TARGET)

PiTi2k5 commented 5 years ago

By the way this bug doesnt exist on pure xmr mining or cn-lite on MAC OS Safari, only on some other algo/variants (CN Half or CN Pico). And on iOS all algos are bugged with high hashrate/mem allocate issue.

Error: Out of bounds memory access (evaluating 'Module["asm"]["_has"].apply(null,arguments)') Cannot enlarge memory arrays. Either (1) compile with -s TOTAL_MEMORY=X with X higher than the current value 67108864, (2) compile with -s ALLOW_MEMORY_GROWTH=1 which allows increasing the size at runtime, or (3) if you want malloc to return NULL (0) instead of this abort, compile with -s ABORTING_MALLOC=0

On this build https://www.crypto-webminer.com/Download/cryptonight.c based on your old prefork https://github.com/notgiven688/webminerpool/commit/aac0cb5399addb618cb97253d9fdcd85c3a77334#diff-d12a9eda097fab130bdf601fe779f4f7 with new algo implemantions all devices running fine except some iPhones they need an thread locking 1-2 threads

PiTi2k5 commented 5 years ago

The only different from old version and new version is the struct constructors. Maybe other mem allocation that can not be handled by apple? It is not the first time that they bugged the webkit :D on iOS 10-10.2 they have bugged the whole wasm

struct cry_ctx { uint8_t long_state[MEMORY] attribute((aligned(16))); union cn_slow_hash_state state; uint8_t text[INIT_SIZE_BYTE] attribute((aligned(16))); uint8_t a[AES_BLOCK_SIZE] attribute((aligned(16))); uint8_t b[AES_BLOCK_SIZE] attribute((aligned(16))); uint8_t c[AES_BLOCK_SIZE] attribute((aligned(16))); uint8_t d[AES_BLOCK_SIZE] attribute((aligned(16))); uint8_t e[AES_BLOCK_SIZE] attribute((aligned(16))); uint8_t a1[AES_BLOCK_SIZE] attribute((aligned(16))); oaes_ctx *aes_ctx; };

void cry(void output, const void input, size_t len, int algo, int variant, int height) { struct cry_ctx ctx = (struct cry_ctx )malloc(sizeof(struct cry_ctx)); cry_ctx(output, input, len, algo, ctx, variant, height); free(ctx); }

PiTi2k5 commented 5 years ago

Apple specific issue, can only be fixed with struct ctx and fixed threads on iOS mobiles