From: wkendall@sgi.com
To: xfs@oss.sgi.com
Subject: [PATCH v2 5/9] xfsrestore: cleanup node allocation
Date: Fri, 05 Nov 2010 11:35:05 -0500 [thread overview]
Message-ID: <20101105163643.987306372@sgi.com> (raw)
In-Reply-To: 20101105163500.747192954@sgi.com
[-- Attachment #1: node_alloc_cleanup --]
[-- Type: text/plain, Size: 6667 bytes --]
Simplify the node allocation code. The current code takes some
number of nodes from a new segment and links them into the
freelist whenever the freelist is depleted. There's no reason
to put the new nodes on the freelist, we can just allocate the
next available new node as needed. This also saves a trip through
win_map/win_unmap if there are no nodes on the freelist (the
common case).
Signed-off-by: Bill Kendall <wkendall@sgi.com>
---
restore/node.c | 144 +++++++++++++++------------------------------------------
1 file changed, 39 insertions(+), 105 deletions(-)
Index: xfsdump-kernel.org/restore/node.c
===================================================================
--- xfsdump-kernel.org.orig/restore/node.c
+++ xfsdump-kernel.org/restore/node.c
@@ -111,10 +111,6 @@ extern size_t pgmask;
*/
#define NODESPERSEGMIN 1000000
-/* how many nodes to place on free list at a time
- */
-#define VIRGSACRMAX 8192 /* fudged: 8192 48 byte nodes (24 or 96 pages) */
-
/* a node is identified internally by its index into the backing store.
* this index is the offset of the node into the segmented portion of
* backing store (follows the abstraction header page) divided by the
@@ -380,72 +376,41 @@ node_alloc( void )
nix_t nix;
u_char_t *p;
nh_t nh;
- register nix_t *linkagep;
#ifdef NODECHK
- register u_char_t *hkpp;
- register u_char_t gen;
- register u_char_t unq;
+ u_char_t *hkpp;
+ u_char_t gen = 0;
+ u_char_t unq;
#endif /* NODECHK */
- /* if free list is depleted, map in a new window at the
- * end of backing store. put all nodes on free list.
- * initialize the gen count to the node index, and the unique
- * pattern to the free pattern.
- */
- if ( node_hdrp->nh_freenix == NIX_NULL ) {
- nix_t virgbegnix; /* abs. nix of first node in virg seg */
- nix_t virgendnix; /* abs. nix of next node after last */
- nix_t sacrcnt; /* how many virgins to put on free list */
- nix_t sacrnix;
-
- ASSERT( node_hdrp->nh_virgrelnix
- <
- ( nix_t )node_hdrp->nh_nodesperseg );
- virgbegnix = OFF2NIX( node_hdrp->nh_virgsegreloff )
- +
- node_hdrp->nh_virgrelnix;
- virgendnix =
- OFF2NIX( ( node_hdrp->nh_virgsegreloff
- +
- ( off64_t )node_hdrp->nh_segsz ) );
-#ifdef TREE_DEBUG
- mlog(MLOG_DEBUG | MLOG_TREE,
- "node_alloc(): create freelist - "
- "virg_begin=%lld virg_end=%lld\n",
- virgbegnix, virgendnix);
-#endif
- ASSERT( virgendnix > virgbegnix );
- sacrcnt = min( VIRGSACRMAX, virgendnix - virgbegnix );
- ASSERT( sacrcnt >= 1 );
- p = 0; /* keep lint happy */
- win_map( NIX2OFF( virgbegnix ), ( void ** )&p );
+ /* if there's a node available on the free list, use it.
+ * otherwise get the next one from the current virgin segment,
+ * or allocate a new virgin segment if the current one is depleted.
+ */
+ if ( node_hdrp->nh_freenix != NIX_NULL ) {
+ nix_t *linkagep;
+ off64_t off;
+
+ nix = node_hdrp->nh_freenix;
+
+ off = NIX2OFF( nix );
+ win_map( off, ( void ** )&p );
if (p == NULL)
- return NH_NULL;
- node_hdrp->nh_freenix = virgbegnix;
- for ( sacrnix = virgbegnix
- ;
- sacrnix < virgbegnix + sacrcnt - 1
- ;
- p += node_hdrp->nh_nodesz, sacrnix++ ) {
- linkagep = ( nix_t * )p;
- *linkagep = sacrnix + 1;
-#ifdef NODECHK
- hkpp = p + node_hdrp->nh_nodehkix;
- gen = ( u_char_t )sacrnix;
- *hkpp = ( u_char_t )HKPMKHKP( ( size_t )gen,
- NODEUNQFREE );
-#endif /* NODECHK */
- }
- linkagep = ( nix_t * )p;
- *linkagep = NIX_NULL;
+ return NH_NULL;
#ifdef NODECHK
hkpp = p + node_hdrp->nh_nodehkix;
- gen = ( u_char_t )sacrnix;
- *hkpp = HKPMKHKP( gen, NODEUNQFREE );
+ gen = ( u_char_t )( HKPGETGEN( *p ) + ( u_char_t )1 );
+ unq = HKPGETUNQ( *hkpp );
+ ASSERT( unq != NODEUNQALCD );
+ ASSERT( unq == NODEUNQFREE );
#endif /* NODECHK */
- node_hdrp->nh_virgrelnix += sacrcnt;
- win_unmap( node_hdrp->nh_virgsegreloff, ( void ** )&p );
+ /* adjust the free list */
+ linkagep = ( nix_t * )p;
+ node_hdrp->nh_freenix = *linkagep;
+
+ win_unmap( off, ( void ** )&p );
+
+ } else {
if ( node_hdrp->nh_virgrelnix
>=
( nix_t )node_hdrp->nh_nodesperseg ) {
@@ -468,14 +433,11 @@ node_alloc( void )
mlog( MLOG_DEBUG,
"pre-growing new node array segment at %lld "
"size %lld\n",
- node_hdrp->nh_firstsegoff
- +
- node_hdrp->nh_virgsegreloff
- +
- ( off64_t )node_hdrp->nh_segsz,
+ node_hdrp->nh_firstsegoff +
+ node_hdrp->nh_virgsegreloff,
( off64_t )node_hdrp->nh_segsz );
rval = ftruncate64( node_fd,
- node_hdrp->nh_firstsegoff
+ node_hdrp->nh_firstsegoff
+
node_hdrp->nh_virgsegreloff
+
@@ -484,60 +446,32 @@ node_alloc( void )
mlog( MLOG_NORMAL | MLOG_WARNING | MLOG_TREE, _(
"unable to autogrow node segment %llu: "
"%s (%d)\n"),
- node_hdrp->nh_virgsegreloff
- /
- ( off64_t )node_hdrp->nh_segsz,
+ OFF2NIX(node_hdrp->nh_virgsegreloff),
strerror( errno ),
errno );
}
}
- }
- /* map in window containing node at top of free list,
- * and adjust free list.
- */
- nix = node_hdrp->nh_freenix;
-#ifdef TREE_DEBUG
- mlog(MLOG_DEBUG | MLOG_TREE,
- "node_alloc(): win_map(%llu) and get head from node freelist\n",
- NIX2OFF(nix));
-#endif
- win_map( NIX2OFF( nix ), ( void ** )&p );
- if (p == NULL)
- return NH_NULL;
-#ifdef NODECHK
- hkpp = p + node_hdrp->nh_nodehkix;
- unq = HKPGETUNQ( *hkpp );
- ASSERT( unq != NODEUNQALCD );
- ASSERT( unq == NODEUNQFREE );
-#endif /* NODECHK */
- linkagep = ( nix_t * )p;
- node_hdrp->nh_freenix = *linkagep;
-
- /* clean the node
- */
- memset( ( void * )p, 0, node_hdrp->nh_nodesz );
+ nix = OFF2NIX( node_hdrp->nh_virgsegreloff )
+ +
+ node_hdrp->nh_virgrelnix++;
+ }
/* build a handle for node
*/
ASSERT( nix <= NIX_MAX );
#ifdef NODECHK
+ win_map( NIX2OFF( nix ), ( void ** )&p );
+ if (p == NULL)
+ abort();
hkpp = p + ( int )node_hdrp->nh_nodehkix;
- gen = ( u_char_t )( HKPGETGEN( *p ) + ( u_char_t )1 );
nh = HDLMKHDL( gen, nix );
*hkpp = HKPMKHKP( gen, NODEUNQALCD );
+ win_unmap( NIX2OFF( nix ), ( void ** )&p );
#else /* NODECHK */
nh = ( nh_t )nix;
#endif /* NODECHK */
- /* unmap window
- */
-#ifdef TREE_DEBUG
- mlog(MLOG_DEBUG | MLOG_TREE,
- "node_alloc(): win_unmap(%llu)\n", NIX2OFF(nix));
-#endif
- win_unmap( NIX2OFF( nix ), ( void ** )&p );
-
return nh;
}
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
next prev parent reply other threads:[~2010-11-05 16:35 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-11-05 16:35 [PATCH v2 0/9] xfsrestore dirent limitations and scaling issues wkendall
2010-11-05 16:35 ` [PATCH v2 1/9] xfsrestore: turn off NODECHK wkendall
2010-11-12 23:23 ` Alex Elder
2010-11-05 16:35 ` [PATCH v2 2/9] xfsrestore: change nrh_t from 32 to 64 bits wkendall
2010-11-12 23:24 ` Alex Elder
2010-11-05 16:35 ` [PATCH v2 3/9] xfsrestore: cache path lookups wkendall
2010-11-12 23:25 ` Alex Elder
2010-11-05 16:35 ` [PATCH v2 4/9] xfsrestore: mmap dirent names for faster lookups wkendall
2010-11-12 23:25 ` Alex Elder
2010-11-15 21:51 ` Bill Kendall
2010-11-05 16:35 ` wkendall [this message]
2010-11-15 20:38 ` [PATCH v2 5/9] xfsrestore: cleanup node allocation Alex Elder
2010-11-15 21:36 ` Bill Kendall
2010-11-05 16:35 ` [PATCH v2 6/9] xfsrestore: fix node table setup wkendall
2010-11-15 20:38 ` Alex Elder
2010-11-15 21:30 ` Bill Kendall
2010-11-05 16:35 ` [PATCH v2 7/9] xfsrestore: make node lookup more efficient wkendall
2010-11-15 20:38 ` Alex Elder
2010-11-15 22:06 ` Bill Kendall
2010-11-05 16:35 ` [PATCH v2 8/9] xfsrestore: remove nix_t wkendall
2010-11-12 23:25 ` Alex Elder
2010-11-05 16:35 ` [PATCH v2 9/9] xfsrestore: check for compatible xfsrestore wkendall
2010-11-12 23:25 ` Alex Elder
2010-11-12 23:25 ` [PATCH v2 0/9] xfsrestore dirent limitations and scaling issues Alex Elder
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20101105163643.987306372@sgi.com \
--to=wkendall@sgi.com \
--cc=xfs@oss.sgi.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox