Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

54
LINES

< > BotCompany Repo | #1025548 // linux_rssFixedForZGC - returns pessimistic (possibly too high) guess

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (3325L/21K).

1  
sbool linux_rssFixedForZGC_verbose;
2  
3  
static long linux_rssFixedForZGC() {
4  
  ret linux_rssFixedForZGC(processID_int());
5  
}
6  
7  
static long linux_rssFixedForZGC(int pid) {
8  
  S text = loadTextFile("/proc/" + pid + "/smaps");
9  
10  
  S range = null;
11  
  new TreeMap<S, Long> rssByRange;
12  
  for (S s : lines(text)) {
13  
    S addr = regexpFirstGroupIC("^([0-9a-f]{1,16})-", s);
14  
    if (addr != null) {
15  
      addr = lpad(addr, 16, '0');
16  
      //print("Have address: " + addr);
17  
      S cleanedAddr = longToHex(parseUnsignedHexLong(addr) & ~((1L << 42)-1));
18  
      //range = takeFirst(/*7*/6, addr);
19  
      range = takeFirst(6, cleanedAddr);
20  
      continue;
21  
    } // else print("Not range: " + s);
22  
    PairS p = parseColonProperty(s);
23  
    if (eqic(pairA(p), "rss")) {
24  
      long size = parseFirstLong(p.b);
25  
      if (size != 0)
26  
        rssByRange.put(range, getOrCreate_long(rssByRange, range) + size);
27  
    }
28  
  }
29  
  if (linux_rssFixedForZGC_verbose)
30  
    for (unpair S _range, long size : mapToPairs(rssByRange)) {
31  
      print("Address range " + rpad(_range, 16, 'x') + ": " + toK(size) + " MB");
32  
    }
33  
  L<Long> offendingRanges = ll(
34  
    toLong(rssByRange.get("000004")),
35  
    toLong(rssByRange.get("000008")),
36  
    toLong(rssByRange.get("000010")));
37  
  
38  
  long total = longSum(values(rssByRange));
39  
  long offending = longMin(offendingRanges);
40  
  long guess = total-offending*2 /*3*/; // seems 2 is the right one
41  
  
42  
  /* Bad fix (?) for this situation:
43  
    Address range 000000xxxxxxxxxx: 1 MB
44  
    Address range 000004xxxxxxxxxx: 2461 MB
45  
    Address range 000008xxxxxxxxxx: 2476 MB
46  
    Address range 000010xxxxxxxxxx: 2662 MB
47  
    Address range 00007cxxxxxxxxxx: 648 MB
48  
  */
49  
  /*long high = toLong(rssByRange.get("00007c"));
50  
  if (high < offending*2)
51  
    guess += offending;*/
52  
  
53  
  ret guess*1024;
54  
}

Author comment

Began life as a copy of #1025541

download  show line numbers  debug dex  old transpilations   

Travelled to 6 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1025548
Snippet name: linux_rssFixedForZGC - returns pessimistic (possibly too high) guess
Eternal ID of this version: #1025548/6
Text MD5: 488fb9f3663e3969efda3ca92cd54e17
Transpilation MD5: ada4e3bae5b75edb7703e6a2c3d86a99
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-10-03 15:20:51
Source code size: 1821 bytes / 54 lines
Pitched / IR pitched: No / No
Views / Downloads: 159 / 265
Version history: 5 change(s)
Referenced in: [show references]