<commit_before>#include "internal/numa.h"
#include "internal/pumadomain.h"
#include "internal/pumanode.h"
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <stdbool.h>

#include <errno.h>

static void bind_to_domain(void* ptr, size_t size, int domain)
{
#if !defined(NNUMA)
	numa_tonode_memory(ptr, size, domain);
#endif

	(void)ptr;(void)size;(void)domain;
}

void* numalloc_on_node(size_t psize, int domain)
{
	void* ret;
#if PUMA_NODEPAGES > 1 || defined(NNUMA)
	int status = posix_memalign(&ret, psize, psize);

#ifndef NNUMA
	bind_to_domain(ret, psize, domain);
#endif // NNUMA
	
	assert(status == 0 || (printf("status = %d\n", status), false)); (void)status;
#else
	numa_set_bind_policy(1);
	numa_set_strict(1);
	ret = numa_alloc_onnode(psize, domain);
#endif

	assert(ret == (struct pumaNode*)((size_t)ret & ~((pumaPageSize * PUMA_NODEPAGES) - 1)));

	return ret;
}

void nufree(void* ptr, size_t size)
{
#if PUMA_NODEPAGES > 1 || defined(NNUMA)
	free(ptr);
#else
	numa_free(ptr, size);
#endif
}<commit_msg>Moved to manual numa domain management<commit_after>#include "internal/numa.h"
#include "internal/pumadomain.h"
#include "internal/pumanode.h"
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <stdbool.h>

#include <errno.h>

void* numalloc_on_node(size_t psize, int domain)
{
	void* ret;

	int status = posix_memalign(&ret, psize, psize);
	assert(status == 0 || (printf("status = %d\n", status), false)); (void)status;

#ifndef NNUMA
	int maxnode = numa_max_node();
	size_t numBuckets = (1 + maxnode / sizeof(unsigned long));
	unsigned long nodemask[numBuckets];

	memset(nodemask, 0, numBuckets * sizeof(unsigned long));

	size_t bucket = domain / sizeof(unsigned long);
	size_t i = domain % sizeof(unsigned long);

	nodemask[bucket] = (unsigned long)1 << ((sizeof(unsigned long) * 8) - (i + 1));

	size_t numPages = psize / pumaPageSize;

	/*	Fault the pages in. */
	for(size_t p = 0; p < numPages; ++p)
		*1(char*)(ret + p * pumaPageSize) = 0;

	mbind(ret, psize, MPOL_BIND, nodemask, maxnode + 1,
			MPOL_MF_STRICT | MPOL_MF_MOVE);

#endif // NNUMA
	

	assert(ret == (struct pumaNode*)((size_t)ret & ~((pumaPageSize * PUMA_NODEPAGES) - 1)));

	return ret;
}

void nufree(void* ptr, size_t size)
{
	free(ptr);
}
{'fraction_non_alphanumeric': 0.1621153012570438, 'fraction_numerical': 0.007368877329865626, 'mean_word_length': 5.237837837837838, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3056534', 'n_tokens_mistral': 978, 'n_tokens_neox': 937, 'n_words': 213}