<commit_before>#include <stdlib.h>
#include <string.h>
#include <kernel/heapmgr.H>
#include <kernel/pagemgr.H>

void* malloc(size_t s)
{
    if (s > HeapManager::MAX_ALLOC_SIZE)
    {
	size_t pages = (s+8) / PageManager::PAGESIZE;
	void* v = PageManager::allocatePage(pages);
	size_t* len = (size_t*)v;
	*len = pages << 8;
	len++;
	return len;
    }
    else
	return HeapManager::allocate(s);
}

void free(void* p)
{
    if (NULL == p) return;

    size_t* len = (size_t*)p;
    len--;

    if ((*len) > 0xff)
    {
	PageManager::freePage(len, (*len) >> 8);
    }
    else
    {
	HeapManager::free(p);
    }
}<commit_msg>Fix page rounding issue in malloc.<commit_after>#include <stdlib.h>
#include <string.h>
#include <kernel/heapmgr.H>
#include <kernel/pagemgr.H>

void* malloc(size_t s)
{
    if (s > HeapManager::MAX_ALLOC_SIZE)
    {
	size_t pages = (s + 8 + (PageManager::PAGESIZE - 1)) 
                     / PageManager::PAGESIZE;
	void* v = PageManager::allocatePage(pages);
	size_t* len = (size_t*)v;
	*len = pages << 8;
	len++;
	return len;
    }
    else
	return HeapManager::allocate(s);
}

void free(void* p)
{
    if (NULL == p) return;

    size_t* len = (size_t*)p;
    len--;

    if ((*len) > 0xff)
    {
	PageManager::freePage(len, (*len) >> 8);
    }
    else
    {
	HeapManager::free(p);
    }
}
{'fraction_non_alphanumeric': 0.17691723614274868, 'fraction_numerical': 0.00683371298405467, 'mean_word_length': 3.018292682926829, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 19, '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': '183026', 'n_tokens_mistral': 562, 'n_tokens_neox': 534, 'n_words': 112}