svn commit: r252527 - head/sys/ufs/ffs
Author: mckusick Date: Tue Jul 2 21:07:08 2013 New Revision: 252527 URL: http://svnweb.freebsd.org/changeset/base/252527 Log: Make better use of metadata area by avoiding using it for data blocks that no should no longer immediately follow their indirect blocks. MFC after:2 weeks Modified: head/sys/ufs/ffs/ffs_alloc.c head/sys/ufs/ffs/ffs_balloc.c Modified: head/sys/ufs/ffs/ffs_alloc.c == --- head/sys/ufs/ffs/ffs_alloc.cTue Jul 2 20:25:58 2013 (r252526) +++ head/sys/ufs/ffs/ffs_alloc.cTue Jul 2 21:07:08 2013 (r252527) @@ -1710,7 +1710,7 @@ ffs_alloccgblk(ip, bp, bpref, size) cgp = (struct cg *)bp-b_data; blksfree = cg_blksfree(cgp); if (bpref == 0) { - bpref = cgp-cg_rotor; + bpref = cgbase(fs, cgp-cg_cgx) + cgp-cg_rotor + fs-fs_frag; } else if ((cgbpref = dtog(fs, bpref)) != cgp-cg_cgx) { /* map bpref to correct zone in this cg */ if (bpref cgdata(fs, cgbpref)) Modified: head/sys/ufs/ffs/ffs_balloc.c == --- head/sys/ufs/ffs/ffs_balloc.c Tue Jul 2 20:25:58 2013 (r252526) +++ head/sys/ufs/ffs/ffs_balloc.c Tue Jul 2 21:07:08 2013 (r252527) @@ -299,6 +299,10 @@ retry: continue; } UFS_LOCK(ump); + /* +* If parent indirect has just been allocated, try to cluster +* immediately following it. +*/ if (pref == 0) pref = ffs_blkpref_ufs1(ip, lbn, i - num - 1, (ufs1_daddr_t *)0); @@ -368,7 +372,14 @@ retry: */ if (nb == 0) { UFS_LOCK(ump); - if (pref == 0) + /* +* If allocating metadata at the front of the cylinder +* group and parent indirect block has just been allocated, +* then cluster next to it if it is the first indirect in +* the file. Otherwise it has been allocated in the metadata +* area, so we want to find our own place out in the data area. +*/ + if (pref == 0 || (lbn NDADDR fs-fs_metaspace != 0)) pref = ffs_blkpref_ufs1(ip, lbn, indirs[i].in_off, bap[0]); error = ffs_alloc(ip, lbn, pref, (int)fs-fs_bsize, @@ -850,6 +861,10 @@ retry: continue; } UFS_LOCK(ump); + /* +* If parent indirect has just been allocated, try to cluster +* immediately following it. +*/ if (pref == 0) pref = ffs_blkpref_ufs2(ip, lbn, i - num - 1, (ufs2_daddr_t *)0); @@ -920,7 +935,14 @@ retry: */ if (nb == 0) { UFS_LOCK(ump); - if (pref == 0) + /* +* If allocating metadata at the front of the cylinder +* group and parent indirect block has just been allocated, +* then cluster next to it if it is the first indirect in +* the file. Otherwise it has been allocated in the metadata +* area, so we want to find our own place out in the data area. +*/ + if (pref == 0 || (lbn NDADDR fs-fs_metaspace != 0)) pref = ffs_blkpref_ufs2(ip, lbn, indirs[i].in_off, bap[0]); error = ffs_alloc(ip, lbn, pref, (int)fs-fs_bsize, ___ svn-src-all@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/svn-src-all To unsubscribe, send any mail to svn-src-all-unsubscr...@freebsd.org
Re: svn commit: r252527 - head/sys/ufs/ffs
On Tue, 2 Jul 2013, Kirk McKusick wrote: Log: Make better use of metadata area by avoiding using it for data blocks that no should no longer immediately follow their indirect blocks. I use the following changes for allocation at the start of cylinder group. They seem to be related. % diff -u2 ffs_alloc.c~ ffs_alloc.c % --- ffs_alloc.c~ Sun Jun 20 12:53:30 2004 % +++ ffs_alloc.c Mon Jan 2 16:52:39 2012 % @@ -1010,5 +1062,6 @@ % * Select the desired position for the next block in a file. The file is % * logically divided into sections. The first section is composed of the % - * direct blocks. Each additional section contains fs_maxbpg blocks. % + * direct blocks and the next fs_maxbpg blocks. Each additional section % + * contains fs_maxbpg blocks. % * % * If no blocks have been allocated in the first section, the policy is to % @@ -1022,12 +1075,11 @@ % * continues until a cylinder group with greater than the average number % * of free blocks is found. If the allocation is for the first block in an % - * indirect block, the information on the previous allocation is unavailable; % + * indirect block or the previous block is a hole, then the information on % + * the previous allocation is unavailable; % * here a best guess is made based upon the logical block number being % * allocated. % * % * If a section is already partially allocated, the policy is to % - * contiguously allocate fs_maxcontig blocks. The end of one of these % - * contiguous blocks and the beginning of the next is laid out % - * contiguously if possible. % + * allocate blocks contiguously within the section if possible. % */ % ufs2_daddr_t IIRC, the comments were out of date before this change. Especially the final paragraph -- fs_maxcontig is not used for anything. % @@ -1039,12 +1091,18 @@ % { % struct fs *fs; % - int cg; % - int avgbfree, startcg; % + int avgbfree, cg, firstsection, newsection, startcg; BTW, I don't like changing the type of these variables to u_int in -current. This asks for new sign extension bugs to break the warnings about old ones. Even 16-bit signed int is almost large enough for cg, so it is far from necessary to change it from signed to unsigned to double its range. % % fs = ip-i_fs; % - if (indx % fs-fs_maxbpg == 0 || bap[indx - 1] == 0) { % - if (lbn NDADDR + NINDIR(fs)) { % + if (lbn NDADDR + fs-fs_maxbpg) { % + firstsection = 1; % + newsection = 0; % + } else { % + firstsection = 0; % + newsection = ((lbn - NDADDR) % fs-fs_maxbpg == 0); % + } % + if (indx == 0 || bap[indx - 1] == 0 || newsection) { % + if (firstsection) { % cg = ino_to_cg(fs, ip-i_number); % - return (fs-fs_fpg * cg + fs-fs_frag); % + return (cgdmin(fs, cg)); % } % /* % @@ -1052,8 +1110,17 @@ %* unused data blocks. %*/ % - if (indx == 0 || bap[indx - 1] == 0) % - startcg = % - ino_to_cg(fs, ip-i_number) + lbn / fs-fs_maxbpg; % - else % + if (indx == 0 || bap[indx - 1] == 0) { % + cg = ino_to_cg(fs, ip-i_number) + % + (lbn - NDADDR) / fs-fs_maxbpg; % + if (!newsection) { % + /* % + * Actually, use our best guess if the % + * section is not new. % + */ % + cg %= fs-fs_ncg; % + return (cgdmin(fs, cg)); % + } % + startcg = cg; % + } else % startcg = dtog(fs, bap[indx - 1]) + 1; % startcg %= fs-fs_ncg; % @@ -1062,16 +1129,13 @@ % if (fs-fs_cs(fs, cg).cs_nbfree = avgbfree) { % fs-fs_cgrotor = cg; % - return (fs-fs_fpg * cg + fs-fs_frag); % + return (cgdmin(fs, cg)); % } % for (cg = 0; cg = startcg; cg++) % if (fs-fs_cs(fs, cg).cs_nbfree = avgbfree) { % fs-fs_cgrotor = cg; % - return (fs-fs_fpg * cg + fs-fs_frag); % + return (cgdmin(fs, cg)); % } % return (0); % } % - /* % - * We just always try to lay things out contiguously. % - */ % return (bap[indx - 1] + fs-fs_frag); % } % @@ -1095,5 +1159,5 @@ % if (lbn NDADDR + NINDIR(fs)) { % cg = ino_to_cg(fs, ip-i_number); % - return (fs-fs_fpg * cg + fs-fs_frag); % + return (cgdmin(fs, cg)); % } % /* % @@