Bug 101341 - Limiting the data size doesn't work
Summary: Limiting the data size doesn't work
Status: RESOLVED INVALID
Alias: None
Product: Memory Management
Classification: Unclassified
Component: Other (show other bugs)
Hardware: x86-64 Linux
: P1 normal
Assignee: Andrew Morton
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-07-11 17:21 UTC by sworddragon2
Modified: 2015-11-02 17:17 UTC (History)
1 user (show)

See Also:
Kernel Version: 4.1.0-040100rc7
Subsystem:
Regression: No
Bisected commit-id:


Attachments
This program logs brk state. (628 bytes, text/plain)
2015-10-01 16:10 UTC, Piotr Kwapuliński
Details

Description sworddragon2 2015-07-11 17:21:50 UTC
Initially I have reported this issue on Launchpad ( https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1463627 ) but they requested me to forward it to here.
Comment 1 Piotr Kwapuliński 2015-09-21 15:38:15 UTC
glibc malloc uses internally mmap and brk. "ulimit -d" is used only by brk and sbrk. Consider using "ulimit -v" which imposes a limit on a virtual memory size (not resident). It is used by mmap, brk and mremap (also stack expansion).
Comment 2 sworddragon2 2015-09-24 12:59:37 UTC
After executing "ulimit -d 8192" and executing the testcase in the same terminal the column DATA of process viewer like top and htop grows to ~2 GiB ("ulimit -s" shows 8192).
Comment 3 Piotr Kwapuliński 2015-09-25 20:44:37 UTC
Did you try "ulimit -v 8192" as suggested previously. It seems to be closer to what you expect.
Comment 4 sworddragon2 2015-09-26 22:00:34 UTC
I'm trying to limit the program break to force glibc using mmap if the program break is out of memory while having no restrictions on the memory consumption (so limiting the virtual memory would not work here). While trying to do this I have just noticed that limiting the program break seems not to work.
Comment 5 Piotr Kwapuliński 2015-10-01 16:10:35 UTC
Created attachment 189191 [details]
This program logs brk state.
Comment 6 Piotr Kwapuliński 2015-10-01 16:16:47 UTC
Please run the program memlog.c (from attachment 189191 [details] above) in a process having the "ulimit -d 8192" set. It is based on a program from:
https://bugs.launchpad.net/ubuntu/+source/glibc/+bug/1462853
I've just added the logging possibility. Please attach the resulting mem.log.
Comment 7 sworddragon2 2015-10-01 19:52:57 UTC
Here is the log: http://www.file-upload.net/download-10946174/mem.log.html
Comment 8 Piotr Kwapuliński 2015-10-01 20:07:39 UTC
The log shows that the process heap is in fact limited by "ulimit -d 8192". When malloc reaches the heap limit it creates the new memory region for the remaining memory. The new memory region is not under the process data limit since it has not been allocated via brk/sbrk. The top's DATA column includes both the heap and the additional memory region.
Comment 9 sworddragon2 2015-10-01 20:17:56 UTC
Thanks for the information. I think I figured out the problem: The manpage of htop descibes the DATA column as the data segment size + stack size while the manpage of top descibes it as anything except the code size. I'm reporting it then to htop and marking this ticket as invalid.
Comment 10 sworddragon2 2015-10-28 04:05:46 UTC
The author of htop noticed that the manpage of proc(5) shows at "/proc/[pid]/statm" that the data column is calculated with "data + stack". Isn't that then wrong too?
Comment 11 Piotr Kwapuliński 2015-10-30 17:29:42 UTC
It works as documented. The /proc/[pid]/status:VmData excludes the stack.
Comment 12 sworddragon2 2015-10-31 07:40:57 UTC
To clarify: data + stack means data segment size + stack size? On executing my original testcase and limiting the data segment size and stack size with ulimit to 8 MiB I'm getting the number 529681 for the 6th column of the related statm file (which would mean that the 6th column shown in the statm file is not the data segment size + stack size).
Comment 13 Piotr Kwapuliński 2015-11-02 17:17:07 UTC
No, the "data" is not a "data segment size".

Note You need to log in before you can comment on or make changes to this bug.