PR# 14572 Potential improvements to `add_core'
Problem Report Summary
Submitter: prestoat2000
Category: Runtime
Priority: Medium
Date: 2008/07/09
Class: Bug
Severity: Non-critical
Number: 14572
Release: 6.2.73753
Confidential: No
Status: Open
Responsible:
Environment: Mozilla/5.0 (X11; U; SunOS sun4u; en-US; rv:1.8.1.9) Gecko/20071111 Firefox/2.0.0.9
Solaris 10 on SPARC
Synopsis: Potential improvements to `add_core'
Description
Based on code inspection only, it looks like `add_core' (in malloc.c) could be improved a bit. It seems to me that this routine is trying to achieve several things: 1. Add enough to requested number of bytes to allow for chunk overhead and Eiffel object overhead. 2. Make sure that at least `eif_chunk_size' bytes are allocated. 3. Make sure that space not including size of "struct chunk" is a multiple of ALIGNMAX. 4. Allocate an integral number of OS pages. The current implementation does not achieve all of these objectives. If `eif_chunk_size' is not a multiple of OS page size (it may have been set by user and the code in main.c only ensures that the value is a multiple of ALIGNMAX), it is not rounded up to next page boundary. Also, size of "struct chunk" is added a second time. Here are my suggestions for improvement: A. Add minimum necessary padding to definition of "struct chunk" to guarantee that its size is a multiple of ALIGNMAX. Add a check to runtime_validation.c to guarantee that this constraint is always met. This removes the need for the code: /* Size of chunk has to be added, otherwise the remaining space * might not be a multiple of ALIGNMAX. */ asked += sizeof(struct chunk); B. After increasing `asked' by "sizeof(struct chunk) + OVERHEAD" and making sure `asked' is at least `eif_chunk_size', make sure `asked' is a multiple of ALIGNMAX (whether asked <= eif_chunk_size or not): mod = asked % ALIGNMAX; if (mod != 0) { asked += ALIGNMAX - mod; } C. We now have an `asked' value that satisfies 1, 2 and 3 above. Now compute `allocated' as minimum number of OS pages to allocate to accomodate `asked': allocated = asked; mod = allocated % PAGESIZE_VALUE; if (mod != 0) { allocated += (PAGESIZE_VALUE - mod); } D. Local `allocated' now has amount to allocate (multiple of OS page size). Increase `asked' to largest value that is a multiple of ALIGNMAX but is <= `allocated': if (asked < allocated) { n = (allocated - asked) / ALIGNMAX; asked += (n * ALIGNMAX); } E. Call `eif_malloc' with `allocated'. Figure out how to do memory accounting most appropriately, using `asked' and `allocated'. Maybe memory accounting does not need any changes.
To Reproduce
Problem Report Interactions