From owner-svn-src-all@FreeBSD.ORG Thu Oct 16 19:52:13 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 2FB90B0E; Thu, 16 Oct 2014 19:52:13 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 1CD6F6E0; Thu, 16 Oct 2014 19:52:13 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id s9GJqCgX045203; Thu, 16 Oct 2014 19:52:12 GMT (envelope-from imp@FreeBSD.org) Received: (from imp@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id s9GJqCf4045202; Thu, 16 Oct 2014 19:52:12 GMT (envelope-from imp@FreeBSD.org) Message-Id: <201410161952.s9GJqCf4045202@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: imp set sender to imp@FreeBSD.org using -f From: Warner Losh Date: Thu, 16 Oct 2014 19:52:12 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r273180 - head/sys/dev/mmc X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 16 Oct 2014 19:52:13 -0000 Author: imp Date: Thu Oct 16 19:52:12 2014 New Revision: 273180 URL: https://svnweb.freebsd.org/changeset/base/273180 Log: fwsectors and fwheads used to be somehwat arbitrary. However, they are used to align partitions in gpart. We also try to align partitions by stripe size when creating new media. Align these two concepts by making fwsectors the same as the stripe size. Select a sensible number of heads so we wind up with about 20 cylinders. This number was selected to keep the rounding effects to a few percent while keeping the number of cylinder groups low. Sadly, it is not possible to make these numbers match the numbers used by SD card readers. There apperas to be much variation between brands so there's no one universal number. These numbers are also not aligned to the stripe size, so some performance problems may still be present when SD cards are created this way. Also, these numbers will differ from the far less common SD to ATA adapters, which present a different, but more uniform, set of numbers that also happened to match the old defaults. Nothing should change for current users. Any suboptimal performance caused by misalignment will still be there. gpart will honor the partitions that aren't on proper boudnaries, but editing the partition tables may result in different alignments being used than before when editing things natively. Ideally, there'd be some way to override these values in the disk subsystem by the user for the USB adapter use case where all "native" notions of geometry disappear. This does not implement that. Modified: head/sys/dev/mmc/mmcsd.c Modified: head/sys/dev/mmc/mmcsd.c ============================================================================== --- head/sys/dev/mmc/mmcsd.c Thu Oct 16 19:27:26 2014 (r273179) +++ head/sys/dev/mmc/mmcsd.c Thu Oct 16 19:52:12 2014 (r273180) @@ -155,14 +155,36 @@ mmcsd_attach(device_t dev) d->d_dump = mmcsd_dump; d->d_name = "mmcsd"; d->d_drv1 = sc; - d->d_maxsize = 4*1024*1024; /* Maximum defined SD card AU size. */ d->d_sectorsize = mmc_get_sector_size(dev); + d->d_maxsize = mmc_get_max_data(dev) * d->d_sectorsize; d->d_mediasize = (off_t)mmc_get_media_size(dev) * d->d_sectorsize; d->d_stripeoffset = 0; d->d_stripesize = mmc_get_erase_sector(dev) * d->d_sectorsize; d->d_unit = device_get_unit(dev); d->d_flags = DISKFLAG_CANDELETE; d->d_delmaxsize = mmc_get_erase_sector(dev) * d->d_sectorsize * 1; /* conservative */ + /* + * The d_fw* values are fake. However, layout is aided by making the + * number of fwsectors equal to the erase sectors from the drive since + * we set the stripe size equal to that. We set fwheads such that there + * are ~20 cylinder groups since all values are somewhat arbitrary here + * and this gives good behavior with ffs without wasting too much + * space. Sadly, geom_part wants to round partitions to these + * values. While not bad, in and of itself, the values we present here + * will almost certainly be different then the values that USB SD + * adapters use and there's too much variation between brands to just + * use those values here. Also SD to ATA adapters favor traditional + * ata sizes, which are different again from the USB adapters (which + * favor SCSI values). This rounding leads to a loss of up to 5% of the + * usable space (usually much less, but that's why 20 was selected: to + * limit this effect at a few percent). gpart needs a way to override + * this behavior for situations like this, but doesn't provide + * one. Perhaps this behavior should be tunable as well, but maybe that + * belongs in the disk layer. These values will be much better than + * the default ones. + */ + d->d_fwsectors = mmc_get_erase_sector(dev); + d->d_fwheads = mmc_get_media_size(dev) / (d->d_fwsectors * 20); strlcpy(d->d_ident, mmc_get_card_sn_string(dev), sizeof(d->d_ident)); strlcpy(d->d_descr, mmc_get_card_id_string(dev), sizeof(d->d_descr));