Justin Erenkrantz wrote:
[...]

- Why do we want an independent per-thread SMS? Because it now removes the requirement for locking. A thread may not be reentrant upon
itself - executing in two places at once. It's a thread with one flow
of control. Memory allocation without the need for locking should be a good thing. In order to scale well with threads, I believe httpd requires independent (thread-local free list) per-thread SMS.
- Does merely having a per-thread SMS (and its associated thread-local free list) necessitate a break from its parent SMS (i.e. independent)?
Yes, I believe so. If we were to assume that the per-thread SMS had a parent/child relationship to the per-process SMS, then we must now have locking. By design, a SMS must allocate memory from its parent.
Since the parent SMS would now be reentrant (as the parent, it has spawned multiple threads that are executing in parallel all asking it for memory), the parent SMS must acquire a lock before allocating memory. This lock is the very thing we are trying to avoid in the first place. Also, when a parent/child relationship exists between two SMS, the parent may clean up the child's SMS when it is destroyed.
- However, for reasons described above, it is impossible for the parent
to clean up its children threads forcibly. The only thing the parent can do is wait for the thread to exit on its own behalf (via
apr_thread_join). The parent may only make hints (such as workers_may_exit in threaded MPM) to the thread that it should exit.
- So, would having an independent per-thread SMS break any assumptions
in APR or httpd? I don't think so. Why? I believe that the thread
is a logical breaking-off point for memory allocation. If we were to
assume a thread were to create a SMS when it begins, all subsequent
processing in that thread will use this SMS. When this independent
per-thread SMS is destroyed (as the thread is exiting - remember we
have assumed that the thread must exit voluntarily), the memory is
reclaimed. All descriptors or sockets opened during that threads'
life is now returned to the OS.


I really think we need a hybrid model that splits the two roles
of a parent in the SMS design.  One of my messages in the archives
talks about this in more detail, but the basic idea is:
 * The parent pool should control the cleanup of its children
   to ensure timely resource release (important for memory, but
   even more important for file descriptors).  In the case of
   an httpd with a high request volume, this cleanup needs to
   happen for a request and all its subrequests right after
   the response is sent; otherwise we
 * But the parent doesn't need to be where the children go
   to get blocks when they need more memory; instead, they
   should call directly to the most efficient source of memory
   that's suitable for the application (e.g., a per-thread SMS).

--Brian




Reply via email to