Skip to content
GitLab
  • Menu
Projects Groups Snippets
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
    • Switch to GitLab Next
  • Sign in / Register
  • P pg_proctab
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 2
    • Issues 2
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
    • Requirements
  • Merge requests 0
    • Merge requests 0
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages & Registries
    • Packages & Registries
    • Package Registry
    • Container Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • pg_proctab
  • pg_proctab
  • Merge requests
  • !4

Fix infinite loop in pg_diskusage

  • Review changes

  • Download
  • Email patches
  • Plain diff
Closed Daniel Farina requested to merge fdr/pg_proctab:fix-infinite-loop into master May 12, 2021
  • Overview 7
  • Commits 1
  • Changes 4

Fix infinite loop in pg_diskusage

Also, new fields added in Linux 4.18 and 5.7 are now scanned and returned. Some of the code formatting has been tweaked to match organization in Linux's genhd.c:diskstats_show code to ease comparison.

As new kernels have added fields to /proc/diskstats, the old parsing code would fail to scan. Not matching anything in the scan meant never making progress towards EOF. The result was an infinite loop until the tuplestore exhausted resources.

This is addressed several ways:

  1. Scanning terminates if there are no matched fields, i.e. no progress towards EOF. Checking for EOF is redundant.

  2. Because spaces and even adjacent format characters will consume newlines, a "HS" (Horizontal Space) macro is used to terminate fscanf matching should a newline character be found in-between scanned items. This is important on any system with fewer fields, such that scanning does not jump between lines as one record.

  3. In event there is more data on the line, i.e. Linux has added even more fields that are otherwise un-scanned, these are consumed up to the next newline and discarded.

Edited May 12, 2021 by Daniel Farina
Assignee
Assign to
Reviewer
Request review from
Time tracking
Source branch: fix-infinite-loop