[PATCH v5 4/7] malloc: Add Huge Page support for mmap()

Adhemerval Zanella adhemerval.zanella@linaro.org
Wed Dec 15 13:08:10 GMT 2021



On 15/12/2021 01:26, DJ Delorie wrote:
> 
> A few comment tweaks.
> One logic question.
> 
> Adhemerval Zanella via Libc-alpha <libc-alpha@sourceware.org> writes:
> 
>> @@ -2609,7 +2627,8 @@ sysmalloc (INTERNAL_SIZE_T nb, mstate av)
>>          }
>>        else if (!tried_mmap)
>>  	{
>> -	  /* We can at least try to use to mmap memory.  */
>> +	  /* We can at least try to use to mmap memory.  If new_heap fails
>> +	     it is unlikely that trying to allocage huge page will succeed.  */
> 
> s/allocage/allocate/

Ack.

> 
> "huge page" should either be "a huge page" or "huge pages"

Ack.

>> diff --git a/sysdeps/generic/malloc-hugepages.h b/sysdeps/generic/malloc-hugepages.h
>> +/* Return the support huge page size from the REQUESTED sizes on PAGESIZE
>> +   along with the required extra mmap flags on FLAGS,  Requesting the value
>> +   of 0 returns the default huge page size, otherwise the value will be
>> +   matched against the supported on by the system.  */
>> +void __malloc_hugepage_config (size_t requested, size_t *pagesize, int *flags)
>> +     attribute_hidden;
> 
> s/support/supported/
> s/supported on by/sizes supported by/
> 

Ack.

>> diff --git a/sysdeps/unix/sysv/linux/malloc-hugepages.c b/sysdeps/unix/sysv/linux/malloc-hugepages.c
>> index 7497e07260..120c78b42a 100644
>> --- a/sysdeps/unix/sysv/linux/malloc-hugepages.c
>> +++ b/sysdeps/unix/sysv/linux/malloc-hugepages.c
>> @@ -17,8 +17,10 @@
>>     not, see <https://www.gnu.org/licenses/>.  */
>>  
>>  #include <intprops.h>
>> +#include <dirent.h>
>>  #include <malloc-hugepages.h>
>>  #include <not-cancel.h>
>> +#include <sys/mman.h>
> 
> Ok.
> 
>> @@ -72,3 +74,128 @@ __malloc_thp_mode (void)
>> +static size_t
>> +malloc_default_hugepage_size (void)
>> +{
>> +  int fd = __open64_nocancel ("/proc/meminfo", O_RDONLY);
>> +  if (fd == -1)
>> +    return 0;
>> +
>> +  size_t hpsize = 0;
>> +
>> +  char buf[512];
>> +  off64_t off = 0;
>> +  while (1)
>> +    {
>> +      ssize_t r = __pread64_nocancel (fd, buf, sizeof (buf) - 1, off);
>> +      if (r < 0)
>> +	break;
>> +      buf[r - 1] = '\0';
> 
> This always overwrites the last byte of the file, shouldn't this be
> buf[r] ?

Yes, I have fixed it.

Is this patch ok with the above fix?


More information about the Libc-alpha mailing list