Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dbgmsg kstat #3728

Closed
wants to merge 1 commit into from
Closed

Conversation

behlendorf
Copy link
Contributor

Internally ZFS keeps a small log to facilitate debugging. By default
the log is disabled, to enable it set zfs_dbgmsg_enable=1. The contents
of the log can be accessed by reading the /proc/spl/kstat/zfs/dbgmsg file.
Writing 0 to this proc file clears the log.

$ echo 1 >/sys/module/zfs/parameters/zfs_dbgmsg_enable
$ echo 0 >/proc/spl/kstat/zfs/dbgmsg
$ zpool import tank
$ cat /proc/spl/kstat/zfs/dbgmsg
1 0 0x01 -1 0 2492357525542 2525836565501
timestamp message
1441141408 spa=tank async request task=1
1441141408 txg 70 open pool version 5000; software version 5000/5; ...
1441141409 spa=tank async request task=32
1441141409 txg 72 import pool version 5000; software version 5000/5; ...
1441141414 command: lt-zpool import tank

Signed-off-by: Brian Behlendorf [email protected]

@richardelling
Copy link
Contributor

LGTM, thanks!

@behlendorf
Copy link
Contributor Author

One thing I noticed right away while testing this is that dprintf() isn't setup to log to the zfs_dbgmsg log. It's probably worth updating __dprintf() so it does. It's also a bit odd having two debug log functions: zfs_dbgmsg() and dprintf(). @richardelling do you happen to know why there are two interfaces?

@dweeezil
Copy link
Contributor

dweeezil commented Sep 2, 2015

@behlendorf I noticed the same thing. I just started looking at this. The overall concept looks just fine to me, however.

@richardelling
Copy link
Contributor

@behlendorf I'm not sure of the history, good question for Matt

@kernelOfTruth
Copy link
Contributor

@richardelling wrong thread (issue) ? ;)

referencing: #3730

Internally ZFS keeps a small log to facilitate debugging.  By default
the log is disabled, to enable it set zfs_dbgmsg_enable=1.  The contents
of the log can be accessed by reading the /proc/spl/kstat/zfs/dbgmsg file.
Writing 0 to this proc file clears the log.

$ echo 1 >/sys/module/zfs/parameters/zfs_dbgmsg_enable
$ echo 0 >/proc/spl/kstat/zfs/dbgmsg
$ zpool import tank
$ cat /proc/spl/kstat/zfs/dbgmsg
1 0 0x01 -1 0 2492357525542 2525836565501
timestamp    message
1441141408   spa=tank async request task=1
1441141408   txg 70 open pool version 5000; software version 5000/5; ...
1441141409   spa=tank async request task=32
1441141409   txg 72 import pool version 5000; software version 5000/5; ...
1441141414   command: lt-zpool import tank

Note the zfs_dbgmsg() and dprintf() functions are both now mapped to
the same log.  As mentioned above the kernel debug log can be accessed
though the /proc/spl/kstat/zfs/dbgmsg kstat.  For user space consumers
log messages are immediately written to stdout after applying the
ZFS_DEBUG environment variable.

$ ZFS_DEBUG=on ./cmd/ztest/ztest -V

Signed-off-by: Brian Behlendorf <[email protected]>
@behlendorf
Copy link
Contributor Author

I've refreshed the patch to map the zfs_dbgmsg() function to __dprintf(). This way all dprintf() and zfs_dbgmsg() messages appear in the kstat file and the log is genuinely useful. I refrained from converting all the zfs_dbgmsg() call sites to dprintf() to minimize any future merge conflicts. However, after spending some time on this I don't see any compelling reason to preserve both interfaces. It only adds needless confusion and since dprintf() is by far more heavily used zfs_dbgmsg() should go.

@nedbass
Copy link
Contributor

nedbass commented Sep 4, 2015

LGTM and worked well in testing

@behlendorf behlendorf closed this in 3b36f83 Sep 4, 2015
@behlendorf
Copy link
Contributor Author

@nedbass thanks for the review and testing. I've merged this to master.

tomgarcia pushed a commit to tomgarcia/zfs that referenced this pull request Sep 11, 2015
Internally ZFS keeps a small log to facilitate debugging.  By default
the log is disabled, to enable it set zfs_dbgmsg_enable=1.  The contents
of the log can be accessed by reading the /proc/spl/kstat/zfs/dbgmsg file.
Writing 0 to this proc file clears the log.

$ echo 1 >/sys/module/zfs/parameters/zfs_dbgmsg_enable
$ echo 0 >/proc/spl/kstat/zfs/dbgmsg
$ zpool import tank
$ cat /proc/spl/kstat/zfs/dbgmsg
1 0 0x01 -1 0 2492357525542 2525836565501
timestamp    message
1441141408   spa=tank async request task=1
1441141408   txg 70 open pool version 5000; software version 5000/5; ...
1441141409   spa=tank async request task=32
1441141409   txg 72 import pool version 5000; software version 5000/5; ...
1441141414   command: lt-zpool import tank

Note the zfs_dbgmsg() and dprintf() functions are both now mapped to
the same log.  As mentioned above the kernel debug log can be accessed
though the /proc/spl/kstat/zfs/dbgmsg kstat.  For user space consumers
log messages are immediately written to stdout after applying the
ZFS_DEBUG environment variable.

$ ZFS_DEBUG=on ./cmd/ztest/ztest -V

Signed-off-by: Brian Behlendorf <[email protected]>
Signed-off-by: Ned Bass <[email protected]>
Closes openzfs#3728
ryao pushed a commit to ClusterHQ/zfs that referenced this pull request Sep 16, 2015
Internally ZFS keeps a small log to facilitate debugging.  By default
the log is disabled, to enable it set zfs_dbgmsg_enable=1.  The contents
of the log can be accessed by reading the /proc/spl/kstat/zfs/dbgmsg file.
Writing 0 to this proc file clears the log.

$ echo 1 >/sys/module/zfs/parameters/zfs_dbgmsg_enable
$ echo 0 >/proc/spl/kstat/zfs/dbgmsg
$ zpool import tank
$ cat /proc/spl/kstat/zfs/dbgmsg
1 0 0x01 -1 0 2492357525542 2525836565501
timestamp    message
1441141408   spa=tank async request task=1
1441141408   txg 70 open pool version 5000; software version 5000/5; ...
1441141409   spa=tank async request task=32
1441141409   txg 72 import pool version 5000; software version 5000/5; ...
1441141414   command: lt-zpool import tank

Note the zfs_dbgmsg() and dprintf() functions are both now mapped to
the same log.  As mentioned above the kernel debug log can be accessed
though the /proc/spl/kstat/zfs/dbgmsg kstat.  For user space consumers
log messages are immediately written to stdout after applying the
ZFS_DEBUG environment variable.

$ ZFS_DEBUG=on ./cmd/ztest/ztest -V

Signed-off-by: Brian Behlendorf <[email protected]>
Signed-off-by: Ned Bass <[email protected]>
Closes openzfs#3728
@gaurkuma
Copy link
Contributor

gaurkuma commented Dec 5, 2016

@behlendorf

I have a question regarding the debug infrastructure. It is definitely good and much needed but are they any plans on further improving it. Following are the issues i see with the current infra:

  1. There is no log level support. I think it is very much needed. Even today most of the log messages seen are the txg moving through different states.
  2. In a multi-pool environment, there is no way to tell from which pool the messages cropped up. We can add pool name as an arg or make this log pool specific by placing it under the pool directory. If there are logs which are common to all pools e.g. arc they can be maintained under /kstat/zfs
  3. Wherein, i understand most of the places we rely on error counters, it may still be beneficial to log when we land up in error scenarios.
  4. Use of dprintfs is very limited today and dtrace doesnt seem to work unless we change the Licence type from CDDL to GPL. We need more logs based on verbosity to debug intricate issues.
  5. No Rate Limiting - An error message for e.g. unable to allocate a buffer from ARC when the dirty data in ARC reaches 50%, can easily fill up the log.

We are thinking of having logs based on the layers like DMU, ARC, ZIO, SPA, ZPL that can be enabled based on an exposed parameter (probably reuse zfs_flags for this purpose). We would like to know your thoughts since we do not want to deviate too much that merging with later releases becomes a problem for us. On the other hand, this may not be a bad time to rework debug infra since the no. of logs are quite limited.

@behlendorf behlendorf deleted the zfs-debugmsgs branch April 19, 2021 19:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants