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).

sbool linux_rssFixedForZGC_verbose;

static long linux_rssFixedForZGC() {
  ret linux_rssFixedForZGC(processID_int());
}

static long linux_rssFixedForZGC(int pid) {
  S text = loadTextFile("/proc/" + pid + "/smaps");

  S range = null;
  new TreeMap<S, Long> rssByRange;
  for (S s : lines(text)) {
    S addr = regexpFirstGroupIC("^([0-9a-f]{1,16})-", s);
    if (addr != null) {
      addr = lpad(addr, 16, '0');
      //print("Have address: " + addr);
      S cleanedAddr = longToHex(parseUnsignedHexLong(addr) & ~((1L << 42)-1));
      //range = takeFirst(/*7*/6, addr);
      range = takeFirst(6, cleanedAddr);
      continue;
    } // else print("Not range: " + s);
    PairS p = parseColonProperty(s);
    if (eqic(pairA(p), "rss")) {
      long size = parseFirstLong(p.b);
      if (size != 0)
        rssByRange.put(range, getOrCreate_long(rssByRange, range) + size);
    }
  }
  if (linux_rssFixedForZGC_verbose)
    for (unpair S _range, long size : mapToPairs(rssByRange)) {
      print("Address range " + rpad(_range, 16, 'x') + ": " + toK(size) + " MB");
    }
  L<Long> offendingRanges = ll(
    toLong(rssByRange.get("000004")),
    toLong(rssByRange.get("000008")),
    toLong(rssByRange.get("000010")));
  
  long total = longSum(values(rssByRange));
  long offending = longMin(offendingRanges);
  long guess = total-offending*2 /*3*/; // seems 2 is the right one
  
  /* Bad fix (?) for this situation:
    Address range 000000xxxxxxxxxx: 1 MB
    Address range 000004xxxxxxxxxx: 2461 MB
    Address range 000008xxxxxxxxxx: 2476 MB
    Address range 000010xxxxxxxxxx: 2662 MB
    Address range 00007cxxxxxxxxxx: 648 MB
  */
  /*long high = toLong(rssByRange.get("00007c"));
  if (high < offending*2)
    guess += offending;*/
  
  ret guess*1024;
}

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: 221 / 341
Version history: 5 change(s)
Referenced in: [show references]