📄 rf_paritylogging.c
字号:
/* * Copyright (c) 1995 Carnegie-Mellon University. * All rights reserved. * * Author: William V. Courtright II * * Permission to use, copy, modify and distribute this software and * its documentation is hereby granted, provided that both the copyright * notice and this permission notice appear in all copies of the * software, derivative works or modified versions, and any portions * thereof, and that both notices appear in supporting documentation. * * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. * * Carnegie Mellon requests users of this software to return to * * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU * School of Computer Science * Carnegie Mellon University * Pittsburgh PA 15213-3890 * * any improvements or extensions that they make and grant Carnegie the * rights to redistribute these changes. *//* $Locker: $ * $Log: rf_paritylogging.c,v $ * Revision 1.41 1996/07/31 16:56:18 jimz * dataBytesPerStripe, sectorsPerDisk init arch-indep. * * Revision 1.40 1996/07/28 20:31:39 jimz * i386netbsd port * true/false fixup * * Revision 1.39 1996/07/18 22:57:14 jimz * port simulator to AIX * * Revision 1.38 1996/07/13 00:00:59 jimz * sanitized generalized reconstruction architecture * cleaned up head sep, rbuf problems * * Revision 1.37 1996/06/17 03:24:14 jimz * switch to new shutdown function typing * * Revision 1.36 1996/06/14 23:15:38 jimz * attempt to deal with thread GC problem * * Revision 1.35 1996/06/11 13:48:30 jimz * get it to compile in-kernel * * Revision 1.34 1996/06/11 10:16:35 jimz * Check return values on array configuration- back out if failed. * Reorder shutdown to avoid using deallocated resources. * Get rid of bogus join op in shutdown. * * Revision 1.33 1996/06/10 18:29:17 wvcii * fixed bug in rf_IdentifyStripeParityLogging * - added array initialization * * Revision 1.32 1996/06/10 11:55:47 jimz * Straightened out some per-array/not-per-array distinctions, fixed * a couple bugs related to confusion. Added shutdown lists. Removed * layout shutdown function (now subsumed by shutdown lists). * * Revision 1.31 1996/06/07 22:26:27 jimz * type-ify which_ru (RF_ReconUnitNum_t) * * Revision 1.30 1996/06/07 21:33:04 jimz * begin using consistent types for sector numbers, * stripe numbers, row+col numbers, recon unit numbers * * Revision 1.29 1996/06/05 18:06:02 jimz * Major code cleanup. The Great Renaming is now done. * Better modularity. Better typing. Fixed a bunch of * synchronization bugs. Made a lot of global stuff * per-desc or per-array. Removed dead code. * * Revision 1.28 1996/06/03 23:28:26 jimz * more bugfixes * check in tree to sync for IPDS runs with current bugfixes * there still may be a problem with threads in the script test * getting I/Os stuck- not trivially reproducible (runs ~50 times * in a row without getting stuck) * * Revision 1.27 1996/06/02 17:31:48 jimz * Moved a lot of global stuff into array structure, where it belongs. * Fixed up paritylogging, pss modules in this manner. Some general * code cleanup. Removed lots of dead code, some dead files. * * Revision 1.26 1996/05/31 22:26:54 jimz * fix a lot of mapping problems, memory allocation problems * found some weird lock issues, fixed 'em * more code cleanup * * Revision 1.25 1996/05/30 23:22:16 jimz * bugfixes of serialization, timing problems * more cleanup * * Revision 1.24 1996/05/27 18:56:37 jimz * more code cleanup * better typing * compiles in all 3 environments * * Revision 1.23 1996/05/24 22:17:04 jimz * continue code + namespace cleanup * typed a bunch of flags * * Revision 1.22 1996/05/24 01:59:45 jimz * another checkpoint in code cleanup for release * time to sync kernel tree * * Revision 1.21 1996/05/23 21:46:35 jimz * checkpoint in code cleanup (release prep) * lots of types, function names have been fixed * * Revision 1.20 1996/05/23 00:33:23 jimz * code cleanup: move all debug decls to rf_options.c, all extern * debug decls to rf_options.h, all debug vars preceded by rf_ * * Revision 1.19 1996/05/20 16:16:30 jimz * switch to rf_{mutex,cond}_{init,destroy} * * Revision 1.18 1996/05/18 19:51:34 jimz * major code cleanup- fix syntax, make some types consistent, * add prototypes, clean out dead code, et cetera * * Revision 1.17 1996/05/03 19:47:11 wvcii * added includes of new dag library * * Revision 1.16 1995/12/12 18:10:06 jimz * MIN -> RF_MIN, MAX -> RF_MAX, ASSERT -> RF_ASSERT * fix 80-column brain damage in comments * * Revision 1.15 1995/12/06 20:57:43 wvcii * added prototypes * reintegration of logs on shutdown now conditional on forceParityLogReint * * Revision 1.14 1995/11/30 16:06:42 wvcii * added copyright info * * Revision 1.13 1995/11/17 19:01:29 wvcii * added prototyping to MapParity * * Revision 1.12 1995/11/07 15:36:03 wvcii * changed ParityLoggingDagSelect prototype * function no longer returns numHdrSucc, numTermAnt * * Revision 1.11 1995/10/08 20:42:54 wvcii * lots of random debugging - debugging incomplete * * Revision 1.10 1995/09/07 01:26:55 jimz * Achive basic compilation in kernel. Kernel functionality * is not guaranteed at all, but it'll compile. Mostly. I hope. * * Revision 1.9 1995/09/06 19:21:17 wvcii * explicit shutdown (forced reintegration) for simulator version * * Revision 1.8 1995/07/08 18:19:16 rachad * Parity verifies can not be done in the simulator. * * Revision 1.7 1995/07/07 00:17:20 wvcii * this version free from deadlock, fails parity verification * * Revision 1.6 1995/06/23 13:39:59 robby * updeated to prototypes in rf_layout.h * * Revision 1.5 1995/06/09 13:14:56 wvcii * code is now nonblocking * * Revision 1.4 95/06/01 17:02:23 wvcii * code debug * * Revision 1.3 95/05/31 13:08:57 wvcii * code debug * * Revision 1.2 95/05/21 15:35:00 wvcii * code debug * * * *//* parity logging configuration, dag selection, and mapping is implemented here */#include "rf_archs.h"#if RF_INCLUDE_PARITYLOGGING > 0#include "rf_types.h"#include "rf_raid.h"#include "rf_dag.h"#include "rf_dagutils.h"#include "rf_dagfuncs.h"#include "rf_dagffrd.h"#include "rf_dagffwr.h"#include "rf_dagdegrd.h"#include "rf_dagdegwr.h"#include "rf_threadid.h"#include "rf_paritylog.h"#include "rf_paritylogDiskMgr.h"#include "rf_paritylogging.h"#include "rf_parityloggingdags.h"#include "rf_general.h"#include "rf_map.h"#include "rf_utils.h"#include "rf_shutdown.h"typedef struct RF_ParityLoggingConfigInfo_s { RF_RowCol_t **stripeIdentifier; /* filled in at config time & used by IdentifyStripe */} RF_ParityLoggingConfigInfo_t;static void FreeRegionInfo(RF_Raid_t *raidPtr, RF_RegionId_t regionID);static void rf_ShutdownParityLogging(RF_ThreadArg_t arg);static void rf_ShutdownParityLoggingRegionInfo(RF_ThreadArg_t arg);static void rf_ShutdownParityLoggingPool(RF_ThreadArg_t arg);static void rf_ShutdownParityLoggingRegionBufferPool(RF_ThreadArg_t arg);static void rf_ShutdownParityLoggingParityBufferPool(RF_ThreadArg_t arg);static void rf_ShutdownParityLoggingDiskQueue(RF_ThreadArg_t arg);int rf_ConfigureParityLogging( RF_ShutdownList_t **listp, RF_Raid_t *raidPtr, RF_Config_t *cfgPtr){ int i, j, startdisk, rc; RF_SectorCount_t totalLogCapacity, fragmentation, lastRegionCapacity; RF_SectorCount_t parityBufferCapacity, maxRegionParityRange; RF_RaidLayout_t *layoutPtr = &raidPtr->Layout; RF_ParityLoggingConfigInfo_t *info; RF_ParityLog_t *l, *next; caddr_t lHeapPtr; /* * We create multiple entries on the shutdown list here, since * this configuration routine is fairly complicated in and of * itself, and this makes backing out of a failed configuration * much simpler. */ raidPtr->numSectorsPerLog = RF_DEFAULT_NUM_SECTORS_PER_LOG; /* create a parity logging configuration structure */ RF_MallocAndAdd(info, sizeof(RF_ParityLoggingConfigInfo_t), (RF_ParityLoggingConfigInfo_t *), raidPtr->cleanupList); if (info == NULL) return(ENOMEM); layoutPtr->layoutSpecificInfo = (void *) info; RF_ASSERT(raidPtr->numRow == 1); /* the stripe identifier must identify the disks in each stripe, * IN THE ORDER THAT THEY APPEAR IN THE STRIPE. */ info->stripeIdentifier = rf_make_2d_array((raidPtr->numCol), (raidPtr->numCol), raidPtr->cleanupList); if (info->stripeIdentifier == NULL) return(ENOMEM); startdisk = 0; for (i=0; i<(raidPtr->numCol); i++) { for (j=0; j<(raidPtr->numCol); j++) { info->stripeIdentifier[i][j] = (startdisk + j) % (raidPtr->numCol - 1); } if ((--startdisk) < 0) startdisk = raidPtr->numCol-1-1; } /* fill in the remaining layout parameters */ layoutPtr->numStripe = layoutPtr->stripeUnitsPerDisk; layoutPtr->bytesPerStripeUnit = layoutPtr->sectorsPerStripeUnit << raidPtr->logBytesPerSector; layoutPtr->numParityCol = 1; layoutPtr->numParityLogCol = 1; layoutPtr->numDataCol = raidPtr->numCol - layoutPtr->numParityCol - layoutPtr->numParityLogCol; layoutPtr->dataSectorsPerStripe = layoutPtr->numDataCol * layoutPtr->sectorsPerStripeUnit; layoutPtr->dataStripeUnitsPerDisk = layoutPtr->stripeUnitsPerDisk; raidPtr->sectorsPerDisk = layoutPtr->stripeUnitsPerDisk * layoutPtr->sectorsPerStripeUnit; raidPtr->totalSectors = layoutPtr->stripeUnitsPerDisk * layoutPtr->numDataCol * layoutPtr->sectorsPerStripeUnit; /* configure parity log parameters parameter comment/constraints ---------------- ------------------- * numParityRegions all regions (except possibly last) of equal size * totalInCoreLogCapacity amount of memory in bytes available for in-core logs (default 1 MB) # numSectorsPerLog capacity of an in-core log in sectors (1 disk track) numParityLogs total number of in-core logs, should be at least numParityRegions regionLogCapacity size of a region log (except possibly last one) in sectors totalLogCapacity total amount of log space in sectors * denotes a user settable parameter. # logs are fixed to be the size of a disk track, value #defined in rf_paritylog.h */ totalLogCapacity = layoutPtr->stripeUnitsPerDisk * layoutPtr->sectorsPerStripeUnit * layoutPtr->numParityLogCol; raidPtr->regionLogCapacity = totalLogCapacity / rf_numParityRegions; if (rf_parityLogDebug) printf("bytes per sector %d\n", raidPtr->bytesPerSector); /* reduce fragmentation within a disk region by adjusting the number of regions in an attempt to allow an integral number of logs to fit into a disk region */ fragmentation = raidPtr->regionLogCapacity % raidPtr->numSectorsPerLog; if (fragmentation > 0) for (i = 1; i < (raidPtr->numSectorsPerLog / 2); i++) { if (((totalLogCapacity / (rf_numParityRegions + i)) % raidPtr->numSectorsPerLog) < fragmentation) { rf_numParityRegions++; raidPtr->regionLogCapacity = totalLogCapacity / rf_numParityRegions; fragmentation = raidPtr->regionLogCapacity % raidPtr->numSectorsPerLog; } if (((totalLogCapacity / (rf_numParityRegions - i)) % raidPtr->numSectorsPerLog) < fragmentation) { rf_numParityRegions--; raidPtr->regionLogCapacity = totalLogCapacity / rf_numParityRegions; fragmentation = raidPtr->regionLogCapacity % raidPtr->numSectorsPerLog; } } /* ensure integral number of regions per log */ raidPtr->regionLogCapacity = (raidPtr->regionLogCapacity / raidPtr->numSectorsPerLog) * raidPtr->numSectorsPerLog; raidPtr->numParityLogs = rf_totalInCoreLogCapacity / (raidPtr->bytesPerSector * raidPtr->numSectorsPerLog); /* to avoid deadlock, must ensure that enough logs exist for each region to have one simultaneously */ if (raidPtr->numParityLogs < rf_numParityRegions) raidPtr->numParityLogs = rf_numParityRegions; /* create region information structs */ RF_Malloc(raidPtr->regionInfo, (rf_numParityRegions * sizeof(RF_RegionInfo_t)), (RF_RegionInfo_t *)); if (raidPtr->regionInfo == NULL) return(ENOMEM); /* last region may not be full capacity */ lastRegionCapacity = raidPtr->regionLogCapacity; while ((rf_numParityRegions - 1) * raidPtr->regionLogCapacity + lastRegionCapacity > totalLogCapacity) lastRegionCapacity = lastRegionCapacity - raidPtr->numSectorsPerLog; raidPtr->regionParityRange = raidPtr->sectorsPerDisk / rf_numParityRegions; maxRegionParityRange = raidPtr->regionParityRange;/* i can't remember why this line is in the code -wvcii 6/30/95 *//* if (raidPtr->sectorsPerDisk % rf_numParityRegions > 0) regionParityRange++; */ /* build pool of unused parity logs */ RF_Malloc(raidPtr->parityLogBufferHeap, raidPtr->numParityLogs * raidPtr->numSectorsPerLog * raidPtr->bytesPerSector, (caddr_t)); if (raidPtr->parityLogBufferHeap == NULL) return(ENOMEM); lHeapPtr = raidPtr->parityLogBufferHeap; rc = rf_mutex_init(&raidPtr->parityLogPool.mutex); if (rc) { RF_ERRORMSG3("Unable to init mutex file %s line %d rc=%d\n", __FILE__, __LINE__, rc); RF_Free(raidPtr->parityLogBufferHeap, raidPtr->numParityLogs * raidPtr->numSectorsPerLog * raidPtr->bytesPerSector); return(ENOMEM); } for (i = 0; i < raidPtr->numParityLogs; i++)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -