This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] misc: Use allocate_once in getmntent



On 22/08/2019 06:06, Florian Weimer wrote:
> * Adhemerval Zanella:
> 
>> On 21/08/2019 11:40, Florian Weimer wrote:
>>> Both the buffer and struct mntent are now allocated on the heap.
>>> This results in a slight reduction of RSS usage.
>>>
>>> 2019-08-21  Florian Weimer  <fweimer@redhat.com>
>>>
>>> 	* misc/mntent.c (struct mntent_buffer): Define.
>>> 	(mntent_buffer): Adjust type to void *.
>>> 	(allocate): Adjust for allocate_once.
>>> 	(deallocate): New function.
>>> 	(getmntent): Call allocate_once.
>>>
>>> diff --git a/misc/mntent.c b/misc/mntent.c
>>> index 980ea40967..8fae6064c6 100644
>>> --- a/misc/mntent.c
>>> +++ b/misc/mntent.c
>>> @@ -18,36 +18,41 @@
>>>  
>>>  #include <mntent.h>
>>>  #include <stdlib.h>
>>> -#include <libc-lock.h>
>>> +#include <allocate_once.h>
>>> +
>>> +struct mntent_buffer
>>> +{
>>> +  struct mntent m;
>>> +  char buffer[4096];
>>> +};
>>
>> The struct mntent is just 24 bytes for 32 bits or 40 bytes for 64 bits,
>> I would focus on optimizing the required buffer instead.
> 
> There are four byte for the __libc_once guard.
> 
> The main point for doing this is that this storage is always wasted,
> even if the interface is never called.  The change seems simple enough
> to do now, even if we replace it with something better afterwards (like
> storing the buffer in the FILE *, or otherwise associating it with it,
> or making it thread-local).
> 

Right, although a further optimization to reduce buffer would probably 
require two allocations (on for the mntent_buffer and another for the
buffer itself).  But I think it should be ok.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]