0

According to this answer Linux sysfs entries are limited to a page, which is 4 KiB on most architectures.

I’m currently working on a net/sched/ module (a fork of fq_codel with slightly changed behaviour to test something) and need to expose largish statistics to userspace. One of the KPIs is about 800 bytes, the other is expected to be 10–50 KiB or so (back-of-the-envelope, not fixed yet). The latter obviously won’t fit into sysfs.

The information is generated during operation but stored into a preallocated array, and userspace is expected to fetch it (and thus empty the array) twice per second or so. Raising that interval might be possible but increase system load by quite some amount.

What other ways of exposing such information to userspace exist that would fit my scenario?

mirabilos
  • 5,123
  • 2
  • 46
  • 72
  • You could create a file in debugfs, procfs... any way which accepts `file_operations` as a parameter. – Tsyvarev Jul 12 '21 at 17:29
  • @Tsyvarev and implement the entire buffering myself? Hrm, also an option… it seems I won’t get around writing much more code than I had first thought. – mirabilos Jul 12 '21 at 21:32
  • sysfs provides a bin attribute interface which does not have such limitation. https://elixir.bootlin.com/linux/latest/source/include/linux/sysfs.h#L91 – 0andriy Jul 12 '21 at 21:58
  • @0andriy interesting… it is **completely** undocumented, and nowhere it says ⓐ how to use it or ⓑ that it doesn’t have that limitation. – mirabilos Jul 13 '21 at 14:44
  • What do you mean by that? First of all, the source code is open, you may read it. Next, simple googling with **linux bin_attrs** gave me enough relevant links on the first page. LWN has an article dated by 2003 about it, for instance. – 0andriy Jul 13 '21 at 21:58
  • Yeah… documentation is something different, though. I saw the LWN article touching it, but that’s insufficient. – mirabilos Jul 14 '21 at 23:05

1 Answers1

1

How about relay interface (/Documentation/filesystems/relay.txt) to log large quantities of data from the kernelto userspace

mirabilos
  • 5,123
  • 2
  • 46
  • 72
tej parkash
  • 137
  • 2
  • That’s it! I managed to get it working ([kernel module](https://github.com/tarent/sch_jens/blob/32cc9c3c37810fcdbd62f3efd5e75b9d71bab6a0/sch_jens/sch_jens.c#L69) and [example client](https://github.com/tarent/sch_jens/blob/32cc9c3c37810fcdbd62f3efd5e75b9d71bab6a0/jens/jensdmp.c#L104), early debugging stages) with `*isglobal = 1;` but the documentation **and** examples are incomplete (tl;dr: you _must_ do a `poll` before `read` or you will read partial records or even EOF⚠). Thank you! – mirabilos Jul 21 '21 at 19:37