Re: 6.0_BETA: Extreamly slow newfs_ext2fs on 60Gb USB stick

2012-03-06 Thread Aleksey Cheusov
On Fri, Mar 2, 2012 at 8:01 PM, Izumi Tsutsui tsut...@ceres.dti.ne.jp wrote:
 For a number of reasons I decided to use ext2 filesystem on 60Gb memory
 stick.
  :
 Unfortunately newfs_ext2fs works extreamly slowly

 newfs_ext2fs(8) was intended to prepare boot partitions for
 Linux based appliances (like cobalt) without GPLed tools,
 so its implementation is quite dumb and it doesn't have
 any I/O optimazations.
 ...

Your patch solved the problem. If it is good to commit, it would be
nice to see it in netbsd-6.

P.S. I'm sorry for doublepost. I forgot  to add the mailist to Cc.


Re: 6.0_BETA: Extreamly slow newfs_ext2fs on 60Gb USB stick

2012-03-06 Thread Izumi Tsutsui
cheusov@ wrote:

 On Fri, Mar 2, 2012 at 8:01 PM, Izumi Tsutsui tsut...@ceres.dti.ne.jp wrote:
  For a number of reasons I decided to use ext2 filesystem on 60Gb memory
  stick.
   :
  Unfortunately newfs_ext2fs works extreamly slowly
 
  newfs_ext2fs(8) was intended to prepare boot partitions for
  Linux based appliances (like cobalt) without GPLed tools,
  so its implementation is quite dumb and it doesn't have
  any I/O optimazations.
  ...
 
 Your patch solved the problem.

Committed. Thanks.

 If it is good to commit, it would be
 nice to see it in netbsd-6.

I'll send a pullup request later.

---
Izumi Tsutsui


Re: 6.0_BETA: Extreamly slow newfs_ext2fs on 60Gb USB stick

2012-03-02 Thread Izumi Tsutsui
 For a number of reasons I decided to use ext2 filesystem on 60Gb memory
 stick.
 :
 Unfortunately newfs_ext2fs works extreamly slowly

newfs_ext2fs(8) was intended to prepare boot partitions for
Linux based appliances (like cobalt) without GPLed tools,
so its implementation is quite dumb and it doesn't have
any I/O optimazations.

There are two possible problems:

 (1) newfs_ext2fs(8) has too many zero'ing ops to erase possible
 superblock backup leftovers
   - The attached patch (which makes newfs_ext2fs(8) zap fewer block)
  omits most write ops.

 (2) ext2fs has a fixed block group (cylinder group in FFS) size
 so large fs will have too many sparse block group structures
 to be initialized
   - Using REV1 (newfs_ext2fs -O 1) could reduce blocks
  superblock backups) to be written during initialization.

Trying mke2fs in e2fsprogs (available in pkgsrc) might also be worth.

---
Izumi Tsutsui


Index: mke2fs.c
===
RCS file: /cvsroot/src/sbin/newfs_ext2fs/mke2fs.c,v
retrieving revision 1.14
diff -u -p -r1.14 mke2fs.c
--- mke2fs.c10 Sep 2010 15:51:20 -  1.14
+++ mke2fs.c2 Mar 2012 16:30:03 -
@@ -124,7 +124,7 @@ __RCSID($NetBSD: mke2fs.c,v 1.14 2010/0
 #include extern.h
 
 static void initcg(uint);
-static void zap_old_sblock(daddr_t);
+static void zap_old_sblock(int);
 static uint cgoverhead(uint);
 static int fsinit(const struct timeval *);
 static int makedir(struct ext2fs_direct *, int);
@@ -552,7 +552,7 @@ mke2fs(const char *fsys, int fi, int fo)
 
if (!Nflag) {
static const uint pbsize[] = { 1024, 2048, 4096, 0 };
-   uint pblock, epblock;
+   uint pblock;
/*
 * Validate the given file system size.
 * Verify that its last block can actually be accessed.
@@ -566,19 +566,23 @@ mke2fs(const char *fsys, int fi, int fo)
/*
 * Ensure there is nothing that looks like a filesystem
 * superblock anywhere other than where ours will be.
-* If fsck_ext2fs finds the wrong one all hell breaks loose!
 *
-* XXX: needs to check how fsck_ext2fs programs even
-*  on other OSes determine alternate superblocks
+* Ext2fs superblock is always placed at the same SBOFF,
+* so we just zap possible first backups.
 */
for (i = 0; pbsize[i] != 0; i++) {
-   epblock = (uint64_t)bcount * bsize / pbsize[i];
-   for (pblock = ((pbsize[i] == SBSIZE) ? 1 : 0);
-   pblock  epblock;
-   pblock += pbsize[i] * NBBY /* bpg */)
-   zap_old_sblock((daddr_t)pblock *
-   pbsize[i] / sectorsize);
+   pblock = (pbsize[i]  BBSIZE) ? 0 : 1;  /* 1st dblk */
+   pblock += pbsize[i] * NBBY; /* next bg */
+   /* zap first backup */
+   zap_old_sblock(pblock * pbsize[i]);
}
+   /*
+* Also zap possbile FFS magic leftover to prevent
+* kernel vfs_mountroot() and bootloadres from mis-recognizing
+* this file system as FFS.
+*/
+   zap_old_sblock(8192);   /* SBLOCK_UFS1 */
+   zap_old_sblock(65536);  /* SBLOCK_UFS2 */
}
 
if (verbosity = 3)
@@ -769,9 +773,9 @@ initcg(uint cylno)
  * Zap possible lingering old superblock data
  */
 static void
-zap_old_sblock(daddr_t sec)
+zap_old_sblock(int sblkoff)
 {
-   static daddr_t cg0_data;
+   static int cg0_data;
uint32_t oldfs[SBSIZE / sizeof(uint32_t)];
static const struct fsm {
uint32_t offset;
@@ -793,24 +797,25 @@ zap_old_sblock(daddr_t sec)
return;
 
/* don't override data before superblock */
-   if (sec  SBOFF / sectorsize)
+   if (sblkoff  SBOFF)
return;
 
if (cg0_data == 0) {
cg0_data =
((daddr_t)sblock.e2fs.e2fs_first_dblock + cgoverhead(0)) *
-   sblock.e2fs_bsize / sectorsize;
+   sblock.e2fs_bsize;
}
 
/* Ignore anything that is beyond our filesystem */
-   if (sec = fssize)
+   if (sblkoff / sectorsize = fssize)
return;
/* Zero anything inside our filesystem... */
-   if (sec = sblock.e2fs.e2fs_first_dblock * bsize / sectorsize) {
+   if (sblkoff = sblock.e2fs.e2fs_first_dblock * bsize) {
/* ...unless we will write that area anyway */
-   if (sec = cg0_data)
+   if (sblkoff = cg0_data)
/* assume iobuf is zero'ed here */
-   wtfs(sec, roundup(SBSIZE, sectorsize), 

6.0_BETA: Extreamly slow newfs_ext2fs on 60Gb USB stick

2012-03-01 Thread Aleksey Cheusov
For a number of reasons I decided to use ext2 filesystem on 60Gb memory
stick.

umass0 at uhub7 port 1 configuration 1 interface 0
umass0: JetFlash Mass Storage Device, rev 2.00/1.00, addr 2
umass0: using SCSI over Bulk-Only
scsibus0 at umass0: 2 targets, 1 lun per target
sd0 at scsibus0 target 0 lun 0: JetFlash, Transcend 64GB, 8.07 disk 
removable
sd0: fabricating a geometry
sd0: 61280 MB, 61280 cyl, 64 head, 32 sec, 512 bytes/sect x 125501440 
sectors
sd0: fabricating a geometry

Unfortunately newfs_ext2fs works extreamly slowly

work# time -p newfs_ext2fs -V4 /dev/rsd0e
/dev/rsd0e: 61276.0MB (125493248 sectors) block size 4096, fragment size 
4096
using 479 block groups of 128.0MB, 32768 blks, 16384 inodes.
super-block backups (for fsck_ext2fs -b #) at:
32768,65536,98304,   131072,   163840,   196608,   229376,   
262144,   294912,
...
real  4944.92
user 0.56
sys  4.59
work#

that is it worked almost an hour and a half.

ktruss(1) says most of the time newfs_ext2fs(8) does the following

...
29777  1 newfs_ext2fs pwrite(0x5, 0xbbaa, 0x400, 0, 0x400, 0x1) = 
1024

\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0
29777  1 newfs_ext2fs pwrite(0x5, 0xbbaa, 0x400, 0, 0x800400, 0x1) 
= 1024

\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0
29777  1 newfs_ext2fs pwrite(0x5, 0xbbaa, 0x400, 0, 0x1000400, 0x1) 
= 1024

\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0
29777  1 newfs_ext2fs pwrite(0x5, 0xbbaa, 0x400, 0, 0x1800400, 0x1) 
= 1024

\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0
...

It executes approximately 5 pwrite(2) syscalls per second.

On file image (newfs_ext2fs -F) creating fs takes about 40 seconds.
Raw write speed (dd of=/dev/rsd0e) on this memstick is about 15Mb/sec.

To me this looks like kernel bug in USB subsystem. Any clue?

dmesg output is in attachement

Copyright (c) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
2006, 2007, 2008, 2009, 2010, 2011, 2012
The NetBSD Foundation, Inc.  All rights reserved.
Copyright (c) 1982, 1986, 1989, 1991, 1993
The Regents of the University of California.  All rights reserved.

NetBSD 6.0_BETA (GENERIC) #0: Thu Feb 23 16:52:34 FET 2012

cheu...@work.imb.invention.com:/srv/obj-current/sys/arch/i386/compile/GENERIC
total memory = 2039 MB
avail memory = 1992 MB
timecounter: Timecounters tick every 10.000 msec
timecounter: Timecounter i8254 frequency 1193182 Hz quality 100
( )
mainbus0 (root)
cpu0 at mainbus0 apid 0: Intel(R) Pentium(R) 4 CPU 3.00GHz, id 0xf43
cpu1 at mainbus0 apid 1: Intel(R) Pentium(R) 4 CPU 3.00GHz, id 0xf43
ioapic0 at mainbus0 apid 2: pa 0xfec0, version 20, 24 pins
acpi0 at mainbus0: Intel ACPICA 20110623
acpi0: X/RSDT: OemId GBT   ,AWRDACPI,42302e31, AslId AWRD,01010101
acpi0: SCI interrupting at int 9
timecounter: Timecounter ACPI-Fast frequency 3579545 Hz quality 1000
acpibut0 at acpi0 (PWRB, PNP0C0C): ACPI Power Button
SYSR (PNP0C02) at acpi0 not configured
attimer1 at acpi0 (TMR, PNP0100): io 0x40-0x43 irq 0
pcppi1 at acpi0 (SPKR, PNP0800): io 0x61
midi0 at pcppi1: PC speaker
sysbeep0 at pcppi1
npx1 at acpi0 (COPR, PNP0C04): io 0xf0-0xff irq 13
npx1: reported by CPUID; using exception 16
pckbc1 at acpi0 (PS2K, PNP0303) (kbd port): io 0x60,0x64 irq 1
PMIO (PNP0C02) at acpi0 not configured
EXPL (PNP0C02) at acpi0 not configured
MEM (PNP0C01) at acpi0 not configured
FWH (INT0800) at acpi0 not configured
apm0 at acpi0: Power Management spec V1.2
attimer1: attached to pcppi1
pckbd0 at pckbc1 (kbd slot)
pckbc1: using irq 1 for kbd slot
wskbd0 at pckbd0: console keyboard
pms0 at pckbc1 (aux slot)
pckbc1: unable to establish interrupt for aux slot
wsmouse0 at pms0 mux 0
pci0 at mainbus0 bus 0: configuration mode 1
pci0: i/o space, memory space enabled, rd/line, rd/mult, wr/inv ok
pchb0 at pci0 dev 0 function 0: vendor 0x8086 product 0x2770 (rev. 0x02)
agp0 at pchb0: detected 7932k stolen memory
agp0: aperture at 0xd000, size 0x1000
vga1 at pci0 dev 2 function 0: vendor 0x8086 product 0x2772 (rev. 0x02)
wsdisplay0 at vga1 kbdmux 1: console (80x25, vt100 emulation), using wskbd0
wsmux1: connecting to wsdisplay0
i915drm0 at vga1: Intel i945G
i915drm0: AGP at 0xd000 256MB
i915drm0: Initialized i915 1.6.0 20080730
hdaudio0 at pci0 dev 27 function 0: HD Audio Controller
hdaudio0: interrupting at ioapic0 pin 16
hdafg0 at hdaudio0: Realtek ALC882
hdafg0: DAC00 10ch: Speaker [Jack], SPDIF Out [Jack]
hdafg0: DAC01 2ch: HP Out [Jack]
hdafg0: ADC02 2ch: CD [Built-In], Line In [Jack], Mic In [Jack]
hdafg0: DIG-In03 2ch: SPDIF In [Jack]
hdafg0: 10ch/2ch 44100Hz 48000Hz 96000Hz 192000Hz PCM16 PCM20 PCM24 AC3
audio0 at hdafg0: full duplex, playback, capture, independent
ppb0 at pci0 dev 28 function 0: vendor 0x8086 product