def mem_limiter(mem, domain_size):
    """Compute max chunk_size"""
    m0 = 26500.0
    m1 = 0.21
    m2 = 0.0315
    nx, ny = domain_size
    used_mem = m0 + m1 * nx * ny + m2 * nx * ny
    chunk_size = (1000.0 * mem - m0 - m1 * nx * ny) / (m2 * nx * ny)
    return max(1, int(chunk_size))
