File: decrease-numblocks.patch

package info (click to toggle)
mbuffer 20230301%2Bds1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,096 kB
  • sloc: ansic: 4,321; sh: 3,418; makefile: 160
file content (19 lines) | stat: -rw-r--r-- 733 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Description: Do not try to allocate more than the available memory.
Forwarded: no
Author: Peter Pentchev <roam@ringlet.net>
Last-Update: 2020-11-04

--- a/mbuffer.c
+++ b/mbuffer.c
@@ -1041,6 +1041,11 @@
 		Blocksize = PgSz;
 		debugmsg("Blocksize set to physical page size of %ld bytes\n",PgSz);
 		Numblocks = NumP/50;
+		if ((Blocksize * (long long)Numblocks) > (long long)SSIZE_MAX) {
+			debugmsg("Cannot allocate that many blocks (%lld * %lld > %lld)\n", (long long)Blocksize, (long long)Numblocks, (long long)SSIZE_MAX);
+			while ((Blocksize * (long long)Numblocks) > (long long)SSIZE_MAX)
+				Numblocks >>= 1;
+		}
 		long mxsemv = maxSemValue();
 		while ((Numblocks > mxsemv) || (Numblocks > 200)) {
 			Numblocks >>= 1;