jfs_extent.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  1. /*
  2. * Copyright (C) International Business Machines Corp., 2000-2004
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
  12. * the GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. */
  18. #include <linux/fs.h>
  19. #include <linux/quotaops.h>
  20. #include "jfs_incore.h"
  21. #include "jfs_inode.h"
  22. #include "jfs_superblock.h"
  23. #include "jfs_dmap.h"
  24. #include "jfs_extent.h"
  25. #include "jfs_debug.h"
  26. /*
  27. * forward references
  28. */
  29. static int extBalloc(struct inode *, s64, s64 *, s64 *);
  30. #ifdef _NOTYET
  31. static int extBrealloc(struct inode *, s64, s64, s64 *, s64 *);
  32. #endif
  33. static s64 extRoundDown(s64 nb);
  34. #define DPD(a) (printk("(a): %d\n",(a)))
  35. #define DPC(a) (printk("(a): %c\n",(a)))
  36. #define DPL1(a) \
  37. { \
  38. if ((a) >> 32) \
  39. printk("(a): %x%08x ",(a)); \
  40. else \
  41. printk("(a): %x ",(a) << 32); \
  42. }
  43. #define DPL(a) \
  44. { \
  45. if ((a) >> 32) \
  46. printk("(a): %x%08x\n",(a)); \
  47. else \
  48. printk("(a): %x\n",(a) << 32); \
  49. }
  50. #define DPD1(a) (printk("(a): %d ",(a)))
  51. #define DPX(a) (printk("(a): %08x\n",(a)))
  52. #define DPX1(a) (printk("(a): %08x ",(a)))
  53. #define DPS(a) (printk("%s\n",(a)))
  54. #define DPE(a) (printk("\nENTERING: %s\n",(a)))
  55. #define DPE1(a) (printk("\nENTERING: %s",(a)))
  56. #define DPS1(a) (printk(" %s ",(a)))
  57. /*
  58. * NAME: extAlloc()
  59. *
  60. * FUNCTION: allocate an extent for a specified page range within a
  61. * file.
  62. *
  63. * PARAMETERS:
  64. * ip - the inode of the file.
  65. * xlen - requested extent length.
  66. * pno - the starting page number with the file.
  67. * xp - pointer to an xad. on entry, xad describes an
  68. * extent that is used as an allocation hint if the
  69. * xaddr of the xad is non-zero. on successful exit,
  70. * the xad describes the newly allocated extent.
  71. * abnr - bool indicating whether the newly allocated extent
  72. * should be marked as allocated but not recorded.
  73. *
  74. * RETURN VALUES:
  75. * 0 - success
  76. * -EIO - i/o error.
  77. * -ENOSPC - insufficient disk resources.
  78. */
  79. int
  80. extAlloc(struct inode *ip, s64 xlen, s64 pno, xad_t * xp, bool abnr)
  81. {
  82. struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
  83. s64 nxlen, nxaddr, xoff, hint, xaddr = 0;
  84. int rc;
  85. int xflag;
  86. /* This blocks if we are low on resources */
  87. txBeginAnon(ip->i_sb);
  88. /* Avoid race with jfs_commit_inode() */
  89. mutex_lock(&JFS_IP(ip)->commit_mutex);
  90. /* validate extent length */
  91. if (xlen > MAXXLEN)
  92. xlen = MAXXLEN;
  93. /* get the page's starting extent offset */
  94. xoff = pno << sbi->l2nbperpage;
  95. /* check if an allocation hint was provided */
  96. if ((hint = addressXAD(xp))) {
  97. /* get the size of the extent described by the hint */
  98. nxlen = lengthXAD(xp);
  99. /* check if the hint is for the portion of the file
  100. * immediately previous to the current allocation
  101. * request and if hint extent has the same abnr
  102. * value as the current request. if so, we can
  103. * extend the hint extent to include the current
  104. * extent if we can allocate the blocks immediately
  105. * following the hint extent.
  106. */
  107. if (offsetXAD(xp) + nxlen == xoff &&
  108. abnr == ((xp->flag & XAD_NOTRECORDED) ? true : false))
  109. xaddr = hint + nxlen;
  110. /* adjust the hint to the last block of the extent */
  111. hint += (nxlen - 1);
  112. }
  113. /* allocate the disk blocks for the extent. initially, extBalloc()
  114. * will try to allocate disk blocks for the requested size (xlen).
  115. * if this fails (xlen contiguous free blocks not avaliable), it'll
  116. * try to allocate a smaller number of blocks (producing a smaller
  117. * extent), with this smaller number of blocks consisting of the
  118. * requested number of blocks rounded down to the next smaller
  119. * power of 2 number (i.e. 16 -> 8). it'll continue to round down
  120. * and retry the allocation until the number of blocks to allocate
  121. * is smaller than the number of blocks per page.
  122. */
  123. nxlen = xlen;
  124. if ((rc = extBalloc(ip, hint ? hint : INOHINT(ip), &nxlen, &nxaddr))) {
  125. mutex_unlock(&JFS_IP(ip)->commit_mutex);
  126. return (rc);
  127. }
  128. /* Allocate blocks to quota. */
  129. if (vfs_dq_alloc_block(ip, nxlen)) {
  130. dbFree(ip, nxaddr, (s64) nxlen);
  131. mutex_unlock(&JFS_IP(ip)->commit_mutex);
  132. return -EDQUOT;
  133. }
  134. /* determine the value of the extent flag */
  135. xflag = abnr ? XAD_NOTRECORDED : 0;
  136. /* if we can extend the hint extent to cover the current request,
  137. * extend it. otherwise, insert a new extent to
  138. * cover the current request.
  139. */
  140. if (xaddr && xaddr == nxaddr)
  141. rc = xtExtend(0, ip, xoff, (int) nxlen, 0);
  142. else
  143. rc = xtInsert(0, ip, xflag, xoff, (int) nxlen, &nxaddr, 0);
  144. /* if the extend or insert failed,
  145. * free the newly allocated blocks and return the error.
  146. */
  147. if (rc) {
  148. dbFree(ip, nxaddr, nxlen);
  149. vfs_dq_free_block(ip, nxlen);
  150. mutex_unlock(&JFS_IP(ip)->commit_mutex);
  151. return (rc);
  152. }
  153. /* set the results of the extent allocation */
  154. XADaddress(xp, nxaddr);
  155. XADlength(xp, nxlen);
  156. XADoffset(xp, xoff);
  157. xp->flag = xflag;
  158. mark_inode_dirty(ip);
  159. mutex_unlock(&JFS_IP(ip)->commit_mutex);
  160. /*
  161. * COMMIT_SyncList flags an anonymous tlock on page that is on
  162. * sync list.
  163. * We need to commit the inode to get the page written disk.
  164. */
  165. if (test_and_clear_cflag(COMMIT_Synclist,ip))
  166. jfs_commit_inode(ip, 0);
  167. return (0);
  168. }
  169. #ifdef _NOTYET
  170. /*
  171. * NAME: extRealloc()
  172. *
  173. * FUNCTION: extend the allocation of a file extent containing a
  174. * partial back last page.
  175. *
  176. * PARAMETERS:
  177. * ip - the inode of the file.
  178. * cp - cbuf for the partial backed last page.
  179. * xlen - request size of the resulting extent.
  180. * xp - pointer to an xad. on successful exit, the xad
  181. * describes the newly allocated extent.
  182. * abnr - bool indicating whether the newly allocated extent
  183. * should be marked as allocated but not recorded.
  184. *
  185. * RETURN VALUES:
  186. * 0 - success
  187. * -EIO - i/o error.
  188. * -ENOSPC - insufficient disk resources.
  189. */
  190. int extRealloc(struct inode *ip, s64 nxlen, xad_t * xp, bool abnr)
  191. {
  192. struct super_block *sb = ip->i_sb;
  193. s64 xaddr, xlen, nxaddr, delta, xoff;
  194. s64 ntail, nextend, ninsert;
  195. int rc, nbperpage = JFS_SBI(sb)->nbperpage;
  196. int xflag;
  197. /* This blocks if we are low on resources */
  198. txBeginAnon(ip->i_sb);
  199. mutex_lock(&JFS_IP(ip)->commit_mutex);
  200. /* validate extent length */
  201. if (nxlen > MAXXLEN)
  202. nxlen = MAXXLEN;
  203. /* get the extend (partial) page's disk block address and
  204. * number of blocks.
  205. */
  206. xaddr = addressXAD(xp);
  207. xlen = lengthXAD(xp);
  208. xoff = offsetXAD(xp);
  209. /* if the extend page is abnr and if the request is for
  210. * the extent to be allocated and recorded,
  211. * make the page allocated and recorded.
  212. */
  213. if ((xp->flag & XAD_NOTRECORDED) && !abnr) {
  214. xp->flag = 0;
  215. if ((rc = xtUpdate(0, ip, xp)))
  216. goto exit;
  217. }
  218. /* try to allocated the request number of blocks for the
  219. * extent. dbRealloc() first tries to satisfy the request
  220. * by extending the allocation in place. otherwise, it will
  221. * try to allocate a new set of blocks large enough for the
  222. * request. in satisfying a request, dbReAlloc() may allocate
  223. * less than what was request but will always allocate enough
  224. * space as to satisfy the extend page.
  225. */
  226. if ((rc = extBrealloc(ip, xaddr, xlen, &nxlen, &nxaddr)))
  227. goto exit;
  228. /* Allocat blocks to quota. */
  229. if (vfs_dq_alloc_block(ip, nxlen)) {
  230. dbFree(ip, nxaddr, (s64) nxlen);
  231. mutex_unlock(&JFS_IP(ip)->commit_mutex);
  232. return -EDQUOT;
  233. }
  234. delta = nxlen - xlen;
  235. /* check if the extend page is not abnr but the request is abnr
  236. * and the allocated disk space is for more than one page. if this
  237. * is the case, there is a miss match of abnr between the extend page
  238. * and the one or more pages following the extend page. as a result,
  239. * two extents will have to be manipulated. the first will be that
  240. * of the extent of the extend page and will be manipulated thru
  241. * an xtExtend() or an xtTailgate(), depending upon whether the
  242. * disk allocation occurred as an inplace extension. the second
  243. * extent will be manipulated (created) through an xtInsert() and
  244. * will be for the pages following the extend page.
  245. */
  246. if (abnr && (!(xp->flag & XAD_NOTRECORDED)) && (nxlen > nbperpage)) {
  247. ntail = nbperpage;
  248. nextend = ntail - xlen;
  249. ninsert = nxlen - nbperpage;
  250. xflag = XAD_NOTRECORDED;
  251. } else {
  252. ntail = nxlen;
  253. nextend = delta;
  254. ninsert = 0;
  255. xflag = xp->flag;
  256. }
  257. /* if we were able to extend the disk allocation in place,
  258. * extend the extent. otherwise, move the extent to a
  259. * new disk location.
  260. */
  261. if (xaddr == nxaddr) {
  262. /* extend the extent */
  263. if ((rc = xtExtend(0, ip, xoff + xlen, (int) nextend, 0))) {
  264. dbFree(ip, xaddr + xlen, delta);
  265. vfs_dq_free_block(ip, nxlen);
  266. goto exit;
  267. }
  268. } else {
  269. /*
  270. * move the extent to a new location:
  271. *
  272. * xtTailgate() accounts for relocated tail extent;
  273. */
  274. if ((rc = xtTailgate(0, ip, xoff, (int) ntail, nxaddr, 0))) {
  275. dbFree(ip, nxaddr, nxlen);
  276. vfs_dq_free_block(ip, nxlen);
  277. goto exit;
  278. }
  279. }
  280. /* check if we need to also insert a new extent */
  281. if (ninsert) {
  282. /* perform the insert. if it fails, free the blocks
  283. * to be inserted and make it appear that we only did
  284. * the xtExtend() or xtTailgate() above.
  285. */
  286. xaddr = nxaddr + ntail;
  287. if (xtInsert (0, ip, xflag, xoff + ntail, (int) ninsert,
  288. &xaddr, 0)) {
  289. dbFree(ip, xaddr, (s64) ninsert);
  290. delta = nextend;
  291. nxlen = ntail;
  292. xflag = 0;
  293. }
  294. }
  295. /* set the return results */
  296. XADaddress(xp, nxaddr);
  297. XADlength(xp, nxlen);
  298. XADoffset(xp, xoff);
  299. xp->flag = xflag;
  300. mark_inode_dirty(ip);
  301. exit:
  302. mutex_unlock(&JFS_IP(ip)->commit_mutex);
  303. return (rc);
  304. }
  305. #endif /* _NOTYET */
  306. /*
  307. * NAME: extHint()
  308. *
  309. * FUNCTION: produce an extent allocation hint for a file offset.
  310. *
  311. * PARAMETERS:
  312. * ip - the inode of the file.
  313. * offset - file offset for which the hint is needed.
  314. * xp - pointer to the xad that is to be filled in with
  315. * the hint.
  316. *
  317. * RETURN VALUES:
  318. * 0 - success
  319. * -EIO - i/o error.
  320. */
  321. int extHint(struct inode *ip, s64 offset, xad_t * xp)
  322. {
  323. struct super_block *sb = ip->i_sb;
  324. int nbperpage = JFS_SBI(sb)->nbperpage;
  325. s64 prev;
  326. int rc = 0;
  327. s64 xaddr;
  328. int xlen;
  329. int xflag;
  330. /* init the hint as "no hint provided" */
  331. XADaddress(xp, 0);
  332. /* determine the starting extent offset of the page previous
  333. * to the page containing the offset.
  334. */
  335. prev = ((offset & ~POFFSET) >> JFS_SBI(sb)->l2bsize) - nbperpage;
  336. /* if the offset is in the first page of the file, no hint provided.
  337. */
  338. if (prev < 0)
  339. goto out;
  340. rc = xtLookup(ip, prev, nbperpage, &xflag, &xaddr, &xlen, 0);
  341. if ((rc == 0) && xlen) {
  342. if (xlen != nbperpage) {
  343. jfs_error(ip->i_sb, "extHint: corrupt xtree");
  344. rc = -EIO;
  345. }
  346. XADaddress(xp, xaddr);
  347. XADlength(xp, xlen);
  348. XADoffset(xp, prev);
  349. /*
  350. * only preserve the abnr flag within the xad flags
  351. * of the returned hint.
  352. */
  353. xp->flag = xflag & XAD_NOTRECORDED;
  354. } else
  355. rc = 0;
  356. out:
  357. return (rc);
  358. }
  359. /*
  360. * NAME: extRecord()
  361. *
  362. * FUNCTION: change a page with a file from not recorded to recorded.
  363. *
  364. * PARAMETERS:
  365. * ip - inode of the file.
  366. * cp - cbuf of the file page.
  367. *
  368. * RETURN VALUES:
  369. * 0 - success
  370. * -EIO - i/o error.
  371. * -ENOSPC - insufficient disk resources.
  372. */
  373. int extRecord(struct inode *ip, xad_t * xp)
  374. {
  375. int rc;
  376. txBeginAnon(ip->i_sb);
  377. mutex_lock(&JFS_IP(ip)->commit_mutex);
  378. /* update the extent */
  379. rc = xtUpdate(0, ip, xp);
  380. mutex_unlock(&JFS_IP(ip)->commit_mutex);
  381. return rc;
  382. }
  383. #ifdef _NOTYET
  384. /*
  385. * NAME: extFill()
  386. *
  387. * FUNCTION: allocate disk space for a file page that represents
  388. * a file hole.
  389. *
  390. * PARAMETERS:
  391. * ip - the inode of the file.
  392. * cp - cbuf of the file page represent the hole.
  393. *
  394. * RETURN VALUES:
  395. * 0 - success
  396. * -EIO - i/o error.
  397. * -ENOSPC - insufficient disk resources.
  398. */
  399. int extFill(struct inode *ip, xad_t * xp)
  400. {
  401. int rc, nbperpage = JFS_SBI(ip->i_sb)->nbperpage;
  402. s64 blkno = offsetXAD(xp) >> ip->i_blkbits;
  403. // assert(ISSPARSE(ip));
  404. /* initialize the extent allocation hint */
  405. XADaddress(xp, 0);
  406. /* allocate an extent to fill the hole */
  407. if ((rc = extAlloc(ip, nbperpage, blkno, xp, false)))
  408. return (rc);
  409. assert(lengthPXD(xp) == nbperpage);
  410. return (0);
  411. }
  412. #endif /* _NOTYET */
  413. /*
  414. * NAME: extBalloc()
  415. *
  416. * FUNCTION: allocate disk blocks to form an extent.
  417. *
  418. * initially, we will try to allocate disk blocks for the
  419. * requested size (nblocks). if this fails (nblocks
  420. * contiguous free blocks not avaliable), we'll try to allocate
  421. * a smaller number of blocks (producing a smaller extent), with
  422. * this smaller number of blocks consisting of the requested
  423. * number of blocks rounded down to the next smaller power of 2
  424. * number (i.e. 16 -> 8). we'll continue to round down and
  425. * retry the allocation until the number of blocks to allocate
  426. * is smaller than the number of blocks per page.
  427. *
  428. * PARAMETERS:
  429. * ip - the inode of the file.
  430. * hint - disk block number to be used as an allocation hint.
  431. * *nblocks - pointer to an s64 value. on entry, this value specifies
  432. * the desired number of block to be allocated. on successful
  433. * exit, this value is set to the number of blocks actually
  434. * allocated.
  435. * blkno - pointer to a block address that is filled in on successful
  436. * return with the starting block number of the newly
  437. * allocated block range.
  438. *
  439. * RETURN VALUES:
  440. * 0 - success
  441. * -EIO - i/o error.
  442. * -ENOSPC - insufficient disk resources.
  443. */
  444. static int
  445. extBalloc(struct inode *ip, s64 hint, s64 * nblocks, s64 * blkno)
  446. {
  447. struct jfs_inode_info *ji = JFS_IP(ip);
  448. struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
  449. s64 nb, nblks, daddr, max;
  450. int rc, nbperpage = sbi->nbperpage;
  451. struct bmap *bmp = sbi->bmap;
  452. int ag;
  453. /* get the number of blocks to initially attempt to allocate.
  454. * we'll first try the number of blocks requested unless this
  455. * number is greater than the maximum number of contiguous free
  456. * blocks in the map. in that case, we'll start off with the
  457. * maximum free.
  458. */
  459. max = (s64) 1 << bmp->db_maxfreebud;
  460. if (*nblocks >= max && *nblocks > nbperpage)
  461. nb = nblks = (max > nbperpage) ? max : nbperpage;
  462. else
  463. nb = nblks = *nblocks;
  464. /* try to allocate blocks */
  465. while ((rc = dbAlloc(ip, hint, nb, &daddr)) != 0) {
  466. /* if something other than an out of space error,
  467. * stop and return this error.
  468. */
  469. if (rc != -ENOSPC)
  470. return (rc);
  471. /* decrease the allocation request size */
  472. nb = min(nblks, extRoundDown(nb));
  473. /* give up if we cannot cover a page */
  474. if (nb < nbperpage)
  475. return (rc);
  476. }
  477. *nblocks = nb;
  478. *blkno = daddr;
  479. if (S_ISREG(ip->i_mode) && (ji->fileset == FILESYSTEM_I)) {
  480. ag = BLKTOAG(daddr, sbi);
  481. spin_lock_irq(&ji->ag_lock);
  482. if (ji->active_ag == -1) {
  483. atomic_inc(&bmp->db_active[ag]);
  484. ji->active_ag = ag;
  485. } else if (ji->active_ag != ag) {
  486. atomic_dec(&bmp->db_active[ji->active_ag]);
  487. atomic_inc(&bmp->db_active[ag]);
  488. ji->active_ag = ag;
  489. }
  490. spin_unlock_irq(&ji->ag_lock);
  491. }
  492. return (0);
  493. }
  494. #ifdef _NOTYET
  495. /*
  496. * NAME: extBrealloc()
  497. *
  498. * FUNCTION: attempt to extend an extent's allocation.
  499. *
  500. * Initially, we will try to extend the extent's allocation
  501. * in place. If this fails, we'll try to move the extent
  502. * to a new set of blocks. If moving the extent, we initially
  503. * will try to allocate disk blocks for the requested size
  504. * (newnblks). if this fails (new contiguous free blocks not
  505. * avaliable), we'll try to allocate a smaller number of
  506. * blocks (producing a smaller extent), with this smaller
  507. * number of blocks consisting of the requested number of
  508. * blocks rounded down to the next smaller power of 2
  509. * number (i.e. 16 -> 8). We'll continue to round down and
  510. * retry the allocation until the number of blocks to allocate
  511. * is smaller than the number of blocks per page.
  512. *
  513. * PARAMETERS:
  514. * ip - the inode of the file.
  515. * blkno - starting block number of the extents current allocation.
  516. * nblks - number of blocks within the extents current allocation.
  517. * newnblks - pointer to a s64 value. on entry, this value is the
  518. * the new desired extent size (number of blocks). on
  519. * successful exit, this value is set to the extent's actual
  520. * new size (new number of blocks).
  521. * newblkno - the starting block number of the extents new allocation.
  522. *
  523. * RETURN VALUES:
  524. * 0 - success
  525. * -EIO - i/o error.
  526. * -ENOSPC - insufficient disk resources.
  527. */
  528. static int
  529. extBrealloc(struct inode *ip,
  530. s64 blkno, s64 nblks, s64 * newnblks, s64 * newblkno)
  531. {
  532. int rc;
  533. /* try to extend in place */
  534. if ((rc = dbExtend(ip, blkno, nblks, *newnblks - nblks)) == 0) {
  535. *newblkno = blkno;
  536. return (0);
  537. } else {
  538. if (rc != -ENOSPC)
  539. return (rc);
  540. }
  541. /* in place extension not possible.
  542. * try to move the extent to a new set of blocks.
  543. */
  544. return (extBalloc(ip, blkno, newnblks, newblkno));
  545. }
  546. #endif /* _NOTYET */
  547. /*
  548. * NAME: extRoundDown()
  549. *
  550. * FUNCTION: round down a specified number of blocks to the next
  551. * smallest power of 2 number.
  552. *
  553. * PARAMETERS:
  554. * nb - the inode of the file.
  555. *
  556. * RETURN VALUES:
  557. * next smallest power of 2 number.
  558. */
  559. static s64 extRoundDown(s64 nb)
  560. {
  561. int i;
  562. u64 m, k;
  563. for (i = 0, m = (u64) 1 << 63; i < 64; i++, m >>= 1) {
  564. if (m & nb)
  565. break;
  566. }
  567. i = 63 - i;
  568. k = (u64) 1 << i;
  569. k = ((k - 1) & nb) ? k : k >> 1;
  570. return (k);
  571. }