coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

wc -c /proc /sys handling


From: Pádraig Brady
Subject: wc -c /proc /sys handling
Date: Mon, 21 Mar 2016 15:57:29 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0

I was wondering if we should not penalize all normal files,
to handle the /proc and /sys approximate st_size edge case?
I.E. only do the seek to last block of file + read() when st_size % PAGE_SIZE 
== 0 ?

I did a quick check of /proc and /sys sizes:

$ find /proc/ /sys/ -type f -printf "%p\t%s\n" 2>/dev/null |
  tr ' ' _ | sort -k2,2n | uniq -f1 -c

 121494 /proc/100/attr/current  0
      2 /sys/devices/pci0000:00/0000:00:1f.2/resource1  4
      2 /sys/devices/pci0000:00/0000:00:1f.2/resource0  8
      1 /sys/devices/pci0000:00/0000:00:16.0/resource0  16
      1 /sys/firmware/dmi/tables/smbios_entry_point     31
      2 /sys/devices/pci0000:00/0000:00:1f.2/resource4  32
    113 /sys/module/arc4/notes/.note.gnu.build-id       36
      1 /sys/firmware/acpi/tables/HPET  56
      1 /sys/firmware/acpi/tables/MCFG  60
      2 /sys/devices/pci0000:00/0000:00:02.0/resource4  64
      1 /sys/firmware/acpi/tables/APIC  114
      1 /sys/firmware/acpi/tables/OSFR  134
      1 /sys/devices/pnp0/00:01/nvram   242
      1 /sys/firmware/acpi/tables/FACP  244
     18 /proc/bus/pci/00/00.0   256
      1 /sys/firmware/acpi/tables/dynamic/SSDT6 281
      1 /sys/firmware/acpi/tables/SLIC  374
      1 /sys/kernel/notes       420
      1 /sys/firmware/acpi/tables/dynamic/SSDT5 771
      2 /sys/devices/pci0000:00/0000:00:1a.0/resource0  1024
      1 /sys/firmware/acpi/tables/SSDT1 1200
      1 /sys/firmware/acpi/tables/dynamic/SSDT4 1615
      1 /sys/devices/pci0000:00/0000:00:1f.2/resource5  2048
      1 /sys/firmware/acpi/tables/SSDT2 2316
      1 /sys/firmware/dmi/tables/DMI    2354
      1 /sys/firmware/acpi/tables/SSDT3 2454
  19610 /proc/bus/pci/00/1b.0   4096
      2 /sys/devices/pci0000:00/0000:00:1c.3/0000:09:00.0/resource0     8192
      3 /sys/devices/pci0000:00/0000:00:1b.0/resource0  16384
      1 /sys/devices/pci0000:00/0000:00:1c.1/0000:05:00.0/vpd   32768
      1 /sys/firmware/acpi/tables/DSDT  39630
      8 /sys/devices/pci0000:00/0000:00:1a.0/usb3/3-1/3-1.4/descriptors 65553
      1 /sys/devices/pci0000:00/0000:00:02.0/rom        131072
      1 /sys/devices/pci0000:00/0000:00:02.0/resource0  4194304
      2 /sys/devices/pci0000:00/0000:00:02.0/resource2  268435456
      1 /proc/kcore     140737477885952

In all cases where st_size % PAGE_SIZE != 0, it would be the same or better to 
take the st_size.
In most cases it was the same. There are a couple of cases with larger sizes 
where it would
have been better to take the st_size rather than reading, I.E.:

/sys/devices/pci0000:00/0000:00:1a.0/usb3/3-1/3-1.4/descriptors
  st_size = 65553, available bytes = 195, wc -c = 65552
/sys/devices/pci0000:00/0000:00:02.0/rom
  st_size = 131072, available bytes = 0, wc -c = 127007 (EINVAL)
/sys/devices/pci0000:00/0000:00:02.0/resource0
  st_size = 4194304, available bytes = 0, wc -c = 4191231 (EIO)

Also related to this is that we currently need read access to any file
we want to wc -c, whereas with this we wouldn't. Well we would for % PAGE_SIZE 
files,
but we probably should fall back to st_size on EPERM in any case?

cheers,
Pádraig



reply via email to

[Prev in Thread] Current Thread [Next in Thread]